1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_TREES_LAYER_TREE_HOST_COMMON_H_
6 #define CC_TREES_LAYER_TREE_HOST_COMMON_H_
10 #include "base/memory/ref_counted.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/base/scoped_ptr_vector.h"
13 #include "cc/layers/layer_lists.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/transform.h"
16 #include "ui/gfx/vector2d.h"
23 class CC_EXPORT LayerTreeHostCommon
{
25 static gfx::Rect
CalculateVisibleRect(gfx::Rect target_surface_rect
,
26 gfx::Rect layer_bound_rect
,
27 const gfx::Transform
& transform
);
29 static void CalculateDrawProperties(
31 gfx::Size device_viewport_size
,
32 float device_scale_factor
,
33 float page_scale_factor
,
34 Layer
* page_scale_application_layer
,
36 bool can_use_lcd_text
,
37 LayerList
* render_surface_layer_list
);
38 static void CalculateDrawProperties(
39 LayerImpl
* root_layer
,
40 gfx::Size device_viewport_size
,
41 float device_scale_factor
,
42 float page_scale_factor
,
43 LayerImpl
* page_scale_application_layer
,
45 bool can_use_lcd_text
,
46 LayerImplList
* render_surface_layer_list
,
47 bool update_tile_priorities
);
49 // Performs hit testing for a given render_surface_layer_list.
50 static LayerImpl
* FindLayerThatIsHitByPoint(
51 gfx::PointF screen_space_point
,
52 const LayerImplList
& render_surface_layer_list
);
54 static LayerImpl
* FindLayerThatIsHitByPointInTouchHandlerRegion(
55 gfx::PointF screen_space_point
,
56 const LayerImplList
& render_surface_layer_list
);
58 static bool LayerHasTouchEventHandlersAt(gfx::PointF screen_space_point
,
59 LayerImpl
* layer_impl
);
61 template <typename LayerType
>
62 static bool RenderSurfaceContributesToTarget(LayerType
*,
63 int target_surface_layer_id
);
65 template <class Function
, typename LayerType
>
66 static void CallFunctionForSubtree(LayerType
* root_layer
);
68 // Returns a layer with the given id if one exists in the subtree starting
69 // from the given root layer (including mask and replica layers).
70 template <typename LayerType
>
71 static LayerType
* FindLayerInSubtree(LayerType
* root_layer
, int layer_id
);
73 static Layer
* get_child_as_raw_ptr(
74 const LayerList
& children
,
76 return children
[index
].get();
79 static LayerImpl
* get_child_as_raw_ptr(
80 const OwnedLayerImplList
& children
,
82 return children
[index
];
85 struct ScrollUpdateInfo
{
87 gfx::Vector2d scroll_delta
;
91 struct CC_EXPORT ScrollAndScaleSet
{
95 std::vector
<LayerTreeHostCommon::ScrollUpdateInfo
> scrolls
;
96 float page_scale_delta
;
99 template <typename LayerType
>
100 bool LayerTreeHostCommon::RenderSurfaceContributesToTarget(
102 int target_surface_layer_id
) {
103 // A layer will either contribute its own content, or its render surface's
104 // content, to the target surface. The layer contributes its surface's content
105 // when both the following are true:
106 // (1) The layer actually has a render surface, and
107 // (2) The layer's render surface is not the same as the target surface.
109 // Otherwise, the layer just contributes itself to the target surface.
111 return layer
->render_surface() && layer
->id() != target_surface_layer_id
;
114 template <typename LayerType
>
115 LayerType
* LayerTreeHostCommon::FindLayerInSubtree(LayerType
* root_layer
,
117 if (root_layer
->id() == layer_id
)
120 if (root_layer
->mask_layer() && root_layer
->mask_layer()->id() == layer_id
)
121 return root_layer
->mask_layer();
123 if (root_layer
->replica_layer() &&
124 root_layer
->replica_layer()->id() == layer_id
)
125 return root_layer
->replica_layer();
127 for (size_t i
= 0; i
< root_layer
->children().size(); ++i
) {
128 if (LayerType
* found
= FindLayerInSubtree(
129 get_child_as_raw_ptr(root_layer
->children(), i
), layer_id
))
135 template <class Function
, typename LayerType
>
136 void LayerTreeHostCommon::CallFunctionForSubtree(LayerType
* root_layer
) {
137 Function()(root_layer
);
139 if (LayerType
* mask_layer
= root_layer
->mask_layer())
140 Function()(mask_layer
);
141 if (LayerType
* replica_layer
= root_layer
->replica_layer()) {
142 Function()(replica_layer
);
143 if (LayerType
* mask_layer
= replica_layer
->mask_layer())
144 Function()(mask_layer
);
147 for (size_t i
= 0; i
< root_layer
->children().size(); ++i
) {
148 CallFunctionForSubtree
<Function
>(
149 get_child_as_raw_ptr(root_layer
->children(), i
));
155 #endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_