Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_common.h
blob62b17b6bcf9f82f165e9ff20b927944374f88ff8
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 Layer* page_scale_application_layer,
35 int max_texture_size,
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,
44 int max_texture_size,
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,
75 size_t index) {
76 return children[index].get();
79 static LayerImpl* get_child_as_raw_ptr(
80 const OwnedLayerImplList& children,
81 size_t index) {
82 return children[index];
85 struct ScrollUpdateInfo {
86 int layer_id;
87 gfx::Vector2d scroll_delta;
91 struct CC_EXPORT ScrollAndScaleSet {
92 ScrollAndScaleSet();
93 ~ScrollAndScaleSet();
95 std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls;
96 float page_scale_delta;
99 template <typename LayerType>
100 bool LayerTreeHostCommon::RenderSurfaceContributesToTarget(
101 LayerType* layer,
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,
116 int layer_id) {
117 if (root_layer->id() == layer_id)
118 return root_layer;
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))
130 return found;
132 return NULL;
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));
153 } // namespace cc
155 #endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_