Fix build break
[chromium-blink-merge.git] / cc / trees / layer_tree_host_common.h
blob8c15d20f2230c09c128339cfdee173e0ada70516
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_
8 #include <vector>
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"
18 namespace cc {
20 class LayerImpl;
21 class Layer;
23 class CC_EXPORT LayerTreeHostCommon {
24 public:
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(
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,
36 LayerList* render_surface_layer_list);
37 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,
44 LayerImplList* render_surface_layer_list,
45 bool update_tile_priorities);
47 // Performs hit testing for a given render_surface_layer_list.
48 static LayerImpl* FindLayerThatIsHitByPoint(
49 gfx::PointF screen_space_point,
50 const LayerImplList& render_surface_layer_list);
52 static LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
53 gfx::PointF screen_space_point,
54 const LayerImplList& render_surface_layer_list);
56 static bool LayerHasTouchEventHandlersAt(gfx::PointF screen_space_point,
57 LayerImpl* layer_impl);
59 template <typename LayerType>
60 static bool RenderSurfaceContributesToTarget(LayerType*,
61 int target_surface_layer_id);
63 template <class Function, typename LayerType>
64 static void CallFunctionForSubtree(LayerType* root_layer);
66 // 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);
71 static Layer* get_child_as_raw_ptr(
72 const LayerList& children,
73 size_t index) {
74 return children[index].get();
77 static LayerImpl* get_child_as_raw_ptr(
78 const OwnedLayerImplList& children,
79 size_t index) {
80 return children[index];
83 struct ScrollUpdateInfo {
84 int layer_id;
85 gfx::Vector2d scroll_delta;
89 struct CC_EXPORT ScrollAndScaleSet {
90 ScrollAndScaleSet();
91 ~ScrollAndScaleSet();
93 std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls;
94 float page_scale_delta;
97 template <typename LayerType>
98 bool 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:
104 // (1) The layer actually has a render surface, and
105 // (2) The layer's render surface is not the same as the target surface.
107 // Otherwise, the layer just contributes itself to the target surface.
109 return layer->render_surface() && layer->id() != target_surface_layer_id;
112 template <typename LayerType>
113 LayerType* LayerTreeHostCommon::FindLayerInSubtree(LayerType* root_layer,
114 int layer_id) {
115 if (root_layer->id() == layer_id)
116 return root_layer;
118 if (root_layer->mask_layer() && root_layer->mask_layer()->id() == layer_id)
119 return root_layer->mask_layer();
121 if (root_layer->replica_layer() &&
122 root_layer->replica_layer()->id() == layer_id)
123 return root_layer->replica_layer();
125 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;
130 return NULL;
133 template <class Function, typename LayerType>
134 void LayerTreeHostCommon::CallFunctionForSubtree(LayerType* root_layer) {
135 Function()(root_layer);
137 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);
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));
151 } // namespace cc
153 #endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_