Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_common.h
blob53ac758e7395d5ad0b1dafc32a6590220b04d2c1
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 <limits>
9 #include <vector>
11 #include "base/bind.h"
12 #include "base/memory/ref_counted.h"
13 #include "cc/base/cc_export.h"
14 #include "cc/base/scoped_ptr_vector.h"
15 #include "cc/layers/layer_lists.h"
16 #include "cc/trees/property_tree.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/vector2d.h"
19 #include "ui/gfx/transform.h"
21 namespace cc {
23 class LayerImpl;
24 class Layer;
25 class SwapPromise;
26 class PropertyTrees;
28 class CC_EXPORT LayerTreeHostCommon {
29 public:
30 static gfx::Rect CalculateVisibleRect(const gfx::Rect& target_surface_rect,
31 const gfx::Rect& layer_bound_rect,
32 const gfx::Transform& transform);
34 template <typename LayerType, typename RenderSurfaceLayerListType>
35 struct CalcDrawPropsInputs {
36 public:
37 CalcDrawPropsInputs(LayerType* root_layer,
38 const gfx::Size& device_viewport_size,
39 const gfx::Transform& device_transform,
40 float device_scale_factor,
41 float page_scale_factor,
42 const LayerType* page_scale_layer,
43 const gfx::Vector2dF& elastic_overscroll,
44 const LayerType* elastic_overscroll_application_layer,
45 int max_texture_size,
46 bool can_use_lcd_text,
47 bool layers_always_allowed_lcd_text,
48 bool can_render_to_separate_surface,
49 bool can_adjust_raster_scales,
50 bool verify_property_trees,
51 RenderSurfaceLayerListType* render_surface_layer_list,
52 int current_render_surface_layer_list_id,
53 PropertyTrees* property_trees)
54 : root_layer(root_layer),
55 device_viewport_size(device_viewport_size),
56 device_transform(device_transform),
57 device_scale_factor(device_scale_factor),
58 page_scale_factor(page_scale_factor),
59 page_scale_layer(page_scale_layer),
60 elastic_overscroll(elastic_overscroll),
61 elastic_overscroll_application_layer(
62 elastic_overscroll_application_layer),
63 max_texture_size(max_texture_size),
64 can_use_lcd_text(can_use_lcd_text),
65 layers_always_allowed_lcd_text(layers_always_allowed_lcd_text),
66 can_render_to_separate_surface(can_render_to_separate_surface),
67 can_adjust_raster_scales(can_adjust_raster_scales),
68 verify_property_trees(verify_property_trees),
69 render_surface_layer_list(render_surface_layer_list),
70 current_render_surface_layer_list_id(
71 current_render_surface_layer_list_id),
72 property_trees(property_trees) {}
74 LayerType* root_layer;
75 gfx::Size device_viewport_size;
76 gfx::Transform device_transform;
77 float device_scale_factor;
78 float page_scale_factor;
79 const LayerType* page_scale_layer;
80 gfx::Vector2dF elastic_overscroll;
81 const LayerType* elastic_overscroll_application_layer;
82 int max_texture_size;
83 bool can_use_lcd_text;
84 bool layers_always_allowed_lcd_text;
85 bool can_render_to_separate_surface;
86 bool can_adjust_raster_scales;
87 bool verify_property_trees;
88 RenderSurfaceLayerListType* render_surface_layer_list;
89 int current_render_surface_layer_list_id;
90 PropertyTrees* property_trees;
93 template <typename LayerType, typename RenderSurfaceLayerListType>
94 struct CalcDrawPropsInputsForTesting
95 : public CalcDrawPropsInputs<LayerType, RenderSurfaceLayerListType> {
96 CalcDrawPropsInputsForTesting(
97 LayerType* root_layer,
98 const gfx::Size& device_viewport_size,
99 const gfx::Transform& device_transform,
100 RenderSurfaceLayerListType* render_surface_layer_list);
101 CalcDrawPropsInputsForTesting(
102 LayerType* root_layer,
103 const gfx::Size& device_viewport_size,
104 RenderSurfaceLayerListType* render_surface_layer_list);
107 typedef CalcDrawPropsInputs<Layer, RenderSurfaceLayerList>
108 CalcDrawPropsMainInputs;
109 typedef CalcDrawPropsInputsForTesting<Layer, RenderSurfaceLayerList>
110 CalcDrawPropsMainInputsForTesting;
111 static void UpdateRenderSurfaces(Layer* root_layer,
112 bool can_render_to_separate_surface,
113 const gfx::Transform& transform,
114 bool preserves_2d_axis_alignment);
115 static void UpdateRenderSurface(Layer* layer,
116 bool can_render_to_separate_surface,
117 gfx::Transform* transform,
118 bool* animation_preserves_axis_alignment);
119 static void CalculateDrawProperties(CalcDrawPropsMainInputs* inputs);
120 static void PreCalculateMetaInformation(Layer* root_layer);
121 static void PreCalculateMetaInformationForTesting(LayerImpl* root_layer);
122 static void PreCalculateMetaInformationForTesting(Layer* root_layer);
124 typedef CalcDrawPropsInputs<LayerImpl, LayerImplList> CalcDrawPropsImplInputs;
125 typedef CalcDrawPropsInputsForTesting<LayerImpl, LayerImplList>
126 CalcDrawPropsImplInputsForTesting;
127 static void CalculateDrawProperties(CalcDrawPropsImplInputs* inputs);
128 static void CalculateDrawProperties(
129 CalcDrawPropsImplInputsForTesting* inputs);
131 template <typename LayerType>
132 static bool RenderSurfaceContributesToTarget(LayerType*,
133 int target_surface_layer_id);
135 template <typename LayerType, typename Function>
136 static void CallFunctionForSubtree(LayerType* layer,
137 const Function& function);
139 // Returns a layer with the given id if one exists in the subtree starting
140 // from the given root layer (including mask and replica layers).
141 template <typename LayerType>
142 static LayerType* FindLayerInSubtree(LayerType* root_layer, int layer_id);
144 static Layer* get_layer_as_raw_ptr(const LayerList& layers, size_t index) {
145 return layers[index].get();
148 static LayerImpl* get_layer_as_raw_ptr(const OwnedLayerImplList& layers,
149 size_t index) {
150 return layers[index];
153 static LayerImpl* get_layer_as_raw_ptr(const LayerImplList& layers,
154 size_t index) {
155 return layers[index];
158 struct ScrollUpdateInfo {
159 int layer_id;
160 // TODO(miletus): Use ScrollOffset once LayerTreeHost/Blink fully supports
161 // franctional scroll offset.
162 gfx::Vector2d scroll_delta;
166 struct CC_EXPORT ScrollAndScaleSet {
167 ScrollAndScaleSet();
168 ~ScrollAndScaleSet();
170 std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls;
171 float page_scale_delta;
172 gfx::Vector2dF elastic_overscroll_delta;
173 float top_controls_delta;
174 ScopedPtrVector<SwapPromise> swap_promises;
177 template <typename LayerType>
178 bool LayerTreeHostCommon::RenderSurfaceContributesToTarget(
179 LayerType* layer,
180 int target_surface_layer_id) {
181 // A layer will either contribute its own content, or its render surface's
182 // content, to the target surface. The layer contributes its surface's content
183 // when both the following are true:
184 // (1) The layer actually has a render surface and rendering into that
185 // surface, and
186 // (2) The layer's render surface is not the same as the target surface.
188 // Otherwise, the layer just contributes itself to the target surface.
190 return layer->render_target() == layer &&
191 layer->id() != target_surface_layer_id;
194 template <typename LayerType>
195 LayerType* LayerTreeHostCommon::FindLayerInSubtree(LayerType* root_layer,
196 int layer_id) {
197 if (!root_layer)
198 return NULL;
200 if (root_layer->id() == layer_id)
201 return root_layer;
203 if (root_layer->mask_layer() && root_layer->mask_layer()->id() == layer_id)
204 return root_layer->mask_layer();
206 if (root_layer->replica_layer() &&
207 root_layer->replica_layer()->id() == layer_id)
208 return root_layer->replica_layer();
210 for (size_t i = 0; i < root_layer->children().size(); ++i) {
211 if (LayerType* found = FindLayerInSubtree(
212 get_layer_as_raw_ptr(root_layer->children(), i), layer_id))
213 return found;
215 return NULL;
218 template <typename LayerType, typename Function>
219 void LayerTreeHostCommon::CallFunctionForSubtree(LayerType* layer,
220 const Function& function) {
221 function(layer);
223 if (LayerType* mask_layer = layer->mask_layer())
224 function(mask_layer);
225 if (LayerType* replica_layer = layer->replica_layer()) {
226 function(replica_layer);
227 if (LayerType* mask_layer = replica_layer->mask_layer())
228 function(mask_layer);
231 for (size_t i = 0; i < layer->children().size(); ++i) {
232 CallFunctionForSubtree(get_layer_as_raw_ptr(layer->children(), i),
233 function);
237 CC_EXPORT PropertyTrees* GetPropertyTrees(Layer* layer);
238 CC_EXPORT PropertyTrees* GetPropertyTrees(LayerImpl* layer);
240 template <typename LayerType, typename RenderSurfaceLayerListType>
241 LayerTreeHostCommon::CalcDrawPropsInputsForTesting<LayerType,
242 RenderSurfaceLayerListType>::
243 CalcDrawPropsInputsForTesting(
244 LayerType* root_layer,
245 const gfx::Size& device_viewport_size,
246 const gfx::Transform& device_transform,
247 RenderSurfaceLayerListType* render_surface_layer_list)
248 : CalcDrawPropsInputs<LayerType, RenderSurfaceLayerListType>(
249 root_layer,
250 device_viewport_size,
251 device_transform,
252 1.f,
253 1.f,
254 NULL,
255 gfx::Vector2dF(),
256 NULL,
257 std::numeric_limits<int>::max() / 2,
258 false,
259 false,
260 true,
261 false,
262 false,
263 render_surface_layer_list,
265 GetPropertyTrees(root_layer)) {
266 DCHECK(root_layer);
267 DCHECK(render_surface_layer_list);
270 template <typename LayerType, typename RenderSurfaceLayerListType>
271 LayerTreeHostCommon::CalcDrawPropsInputsForTesting<LayerType,
272 RenderSurfaceLayerListType>::
273 CalcDrawPropsInputsForTesting(
274 LayerType* root_layer,
275 const gfx::Size& device_viewport_size,
276 RenderSurfaceLayerListType* render_surface_layer_list)
277 : CalcDrawPropsInputs<LayerType, RenderSurfaceLayerListType>(
278 root_layer,
279 device_viewport_size,
280 gfx::Transform(),
281 1.f,
282 1.f,
283 NULL,
284 gfx::Vector2dF(),
285 NULL,
286 std::numeric_limits<int>::max() / 2,
287 false,
288 false,
289 true,
290 false,
291 false,
292 render_surface_layer_list,
294 GetPropertyTrees(root_layer)) {
295 DCHECK(root_layer);
296 DCHECK(render_surface_layer_list);
299 } // namespace cc
301 #endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_