blob: 8c15d20f2230c09c128339cfdee173e0ada70516 [file] [log] [blame]
[email protected]cd57cc5a2012-10-12 22:43:411// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]0fb25002012-10-12 07:20:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]cd57cc5a2012-10-12 22:43:414
[email protected]556fd292013-03-18 08:03:045#ifndef CC_TREES_LAYER_TREE_HOST_COMMON_H_
6#define CC_TREES_LAYER_TREE_HOST_COMMON_H_
[email protected]cd57cc5a2012-10-12 22:43:417
[email protected]bf691c22013-03-26 21:15:068#include <vector>
9
[email protected]cd57cc5a2012-10-12 22:43:4110#include "base/memory/ref_counted.h"
[email protected]681ccff2013-03-18 06:13:5211#include "cc/base/cc_export.h"
12#include "cc/base/scoped_ptr_vector.h"
[email protected]50761e92013-03-29 20:51:2813#include "cc/layers/layer_lists.h"
[email protected]aad0a0072012-11-01 18:15:5814#include "ui/gfx/rect.h"
[email protected]c8686a02012-11-27 08:29:0015#include "ui/gfx/transform.h"
[email protected]c9c1ebe2012-11-05 20:46:1316#include "ui/gfx/vector2d.h"
[email protected]cd57cc5a2012-10-12 22:43:4117
18namespace cc {
19
[email protected]96baf3e2012-10-22 23:09:5520class LayerImpl;
[email protected]96baf3e2012-10-22 23:09:5521class Layer;
[email protected]cd57cc5a2012-10-12 22:43:4122
[email protected]52347c842012-11-02 21:06:2023class CC_EXPORT LayerTreeHostCommon {
[email protected]6ba914122013-03-22 16:26:3924 public:
25 static gfx::Rect CalculateVisibleRect(gfx::Rect target_surface_rect,
26 gfx::Rect layer_bound_rect,
27 const gfx::Transform& transform);
[email protected]cd57cc5a2012-10-12 22:43:4128
[email protected]6ba914122013-03-22 16:26:3929 static void CalculateDrawProperties(
30 Layer* root_layer,
31 gfx::Size device_viewport_size,
32 float device_scale_factor,
33 float page_scale_factor,
34 int max_texture_size,
35 bool can_use_lcd_text,
[email protected]50761e92013-03-29 20:51:2836 LayerList* render_surface_layer_list);
[email protected]6ba914122013-03-22 16:26:3937 static void CalculateDrawProperties(
38 LayerImpl* root_layer,
39 gfx::Size device_viewport_size,
40 float device_scale_factor,
41 float page_scale_factor,
42 int max_texture_size,
43 bool can_use_lcd_text,
[email protected]50761e92013-03-29 20:51:2844 LayerImplList* render_surface_layer_list,
[email protected]6ba914122013-03-22 16:26:3945 bool update_tile_priorities);
[email protected]cd57cc5a2012-10-12 22:43:4146
[email protected]6ba914122013-03-22 16:26:3947 // Performs hit testing for a given render_surface_layer_list.
48 static LayerImpl* FindLayerThatIsHitByPoint(
49 gfx::PointF screen_space_point,
[email protected]50761e92013-03-29 20:51:2850 const LayerImplList& render_surface_layer_list);
[email protected]cd57cc5a2012-10-12 22:43:4151
[email protected]6ba914122013-03-22 16:26:3952 static LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
53 gfx::PointF screen_space_point,
[email protected]50761e92013-03-29 20:51:2854 const LayerImplList& render_surface_layer_list);
[email protected]2f1acc262012-11-16 21:42:2255
[email protected]6ba914122013-03-22 16:26:3956 static bool LayerHasTouchEventHandlersAt(gfx::PointF screen_space_point,
57 LayerImpl* layer_impl);
[email protected]35d2edd22012-12-13 02:19:0558
[email protected]6ba914122013-03-22 16:26:3959 template <typename LayerType>
60 static bool RenderSurfaceContributesToTarget(LayerType*,
61 int target_surface_layer_id);
[email protected]cd57cc5a2012-10-12 22:43:4162
[email protected]6ba914122013-03-22 16:26:3963 template <class Function, typename LayerType>
64 static void CallFunctionForSubtree(LayerType* root_layer);
[email protected]4c9bb952013-01-27 05:41:1865
[email protected]6ba914122013-03-22 16:26:3966 // Returns a layer with the given id if one exists in the subtree starting
67 // from the given root layer (including mask and replica layers).
68 template <typename LayerType>
69 static LayerType* FindLayerInSubtree(LayerType* root_layer, int layer_id);
[email protected]cd57cc5a2012-10-12 22:43:4170
[email protected]6ba914122013-03-22 16:26:3971 static Layer* get_child_as_raw_ptr(
[email protected]50761e92013-03-29 20:51:2872 const LayerList& children,
[email protected]6ba914122013-03-22 16:26:3973 size_t index) {
74 return children[index].get();
75 }
[email protected]cd57cc5a2012-10-12 22:43:4176
[email protected]6ba914122013-03-22 16:26:3977 static LayerImpl* get_child_as_raw_ptr(
[email protected]50761e92013-03-29 20:51:2878 const OwnedLayerImplList& children,
[email protected]6ba914122013-03-22 16:26:3979 size_t index) {
80 return children[index];
81 }
[email protected]cd57cc5a2012-10-12 22:43:4182
[email protected]6ba914122013-03-22 16:26:3983 struct ScrollUpdateInfo {
84 int layer_id;
85 gfx::Vector2d scroll_delta;
86 };
[email protected]cd57cc5a2012-10-12 22:43:4187};
88
[email protected]52347c842012-11-02 21:06:2089struct CC_EXPORT ScrollAndScaleSet {
[email protected]6ba914122013-03-22 16:26:3990 ScrollAndScaleSet();
91 ~ScrollAndScaleSet();
[email protected]cd57cc5a2012-10-12 22:43:4192
[email protected]6ba914122013-03-22 16:26:3993 std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls;
94 float page_scale_delta;
[email protected]cd57cc5a2012-10-12 22:43:4195};
96
[email protected]6ba914122013-03-22 16:26:3997template <typename LayerType>
98bool LayerTreeHostCommon::RenderSurfaceContributesToTarget(
99 LayerType* layer,
100 int target_surface_layer_id) {
101 // A layer will either contribute its own content, or its render surface's
102 // content, to the target surface. The layer contributes its surface's content
103 // when both the following are true:
[email protected]ed511b8d2013-03-25 03:29:29104 // (1) The layer actually has a render surface, and
105 // (2) The layer's render surface is not the same as the target surface.
[email protected]6ba914122013-03-22 16:26:39106 //
107 // Otherwise, the layer just contributes itself to the target surface.
[email protected]cd57cc5a2012-10-12 22:43:41108
[email protected]6ba914122013-03-22 16:26:39109 return layer->render_surface() && layer->id() != target_surface_layer_id;
[email protected]cd57cc5a2012-10-12 22:43:41110}
111
[email protected]6ba914122013-03-22 16:26:39112template <typename LayerType>
113LayerType* LayerTreeHostCommon::FindLayerInSubtree(LayerType* root_layer,
114 int layer_id) {
115 if (root_layer->id() == layer_id)
116 return root_layer;
[email protected]cd57cc5a2012-10-12 22:43:41117
[email protected]6ba914122013-03-22 16:26:39118 if (root_layer->mask_layer() && root_layer->mask_layer()->id() == layer_id)
119 return root_layer->mask_layer();
[email protected]cd57cc5a2012-10-12 22:43:41120
[email protected]6ba914122013-03-22 16:26:39121 if (root_layer->replica_layer() &&
122 root_layer->replica_layer()->id() == layer_id)
123 return root_layer->replica_layer();
[email protected]cd57cc5a2012-10-12 22:43:41124
[email protected]6ba914122013-03-22 16:26:39125 for (size_t i = 0; i < root_layer->children().size(); ++i) {
126 if (LayerType* found = FindLayerInSubtree(
127 get_child_as_raw_ptr(root_layer->children(), i), layer_id))
128 return found;
129 }
130 return NULL;
[email protected]cd57cc5a2012-10-12 22:43:41131}
132
[email protected]6ba914122013-03-22 16:26:39133template <class Function, typename LayerType>
134void LayerTreeHostCommon::CallFunctionForSubtree(LayerType* root_layer) {
135 Function()(root_layer);
[email protected]4c9bb952013-01-27 05:41:18136
[email protected]ed511b8d2013-03-25 03:29:29137 if (LayerType* mask_layer = root_layer->mask_layer())
138 Function()(mask_layer);
139 if (LayerType* replica_layer = root_layer->replica_layer()) {
140 Function()(replica_layer);
141 if (LayerType* mask_layer = replica_layer->mask_layer())
142 Function()(mask_layer);
[email protected]6ba914122013-03-22 16:26:39143 }
144
145 for (size_t i = 0; i < root_layer->children().size(); ++i) {
146 CallFunctionForSubtree<Function>(
147 get_child_as_raw_ptr(root_layer->children(), i));
148 }
[email protected]4c9bb952013-01-27 05:41:18149}
150
[email protected]e17f3072012-10-26 22:15:34151} // namespace cc
[email protected]cd57cc5a2012-10-12 22:43:41152
[email protected]556fd292013-03-18 08:03:04153#endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_