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 #include "cc/trees/layer_tree_host_common.h"
9 #include "base/debug/trace_event.h"
10 #include "cc/base/math_util.h"
11 #include "cc/layers/heads_up_display_layer_impl.h"
12 #include "cc/layers/layer.h"
13 #include "cc/layers/layer_impl.h"
14 #include "cc/layers/layer_iterator.h"
15 #include "cc/layers/render_surface.h"
16 #include "cc/layers/render_surface_impl.h"
17 #include "cc/trees/layer_sorter.h"
18 #include "cc/trees/layer_tree_impl.h"
19 #include "ui/gfx/rect_conversions.h"
20 #include "ui/gfx/transform.h"
24 ScrollAndScaleSet::ScrollAndScaleSet() {}
26 ScrollAndScaleSet::~ScrollAndScaleSet() {}
28 static void SortLayers(LayerList::iterator forst
,
29 LayerList::iterator end
,
34 static void SortLayers(LayerImplList::iterator first
,
35 LayerImplList::iterator end
,
36 LayerSorter
* layer_sorter
) {
38 TRACE_EVENT0("cc", "LayerTreeHostCommon::SortLayers");
39 layer_sorter
->Sort(first
, end
);
42 template <typename LayerType
>
43 static gfx::Vector2dF
GetEffectiveScrollDelta(LayerType
* layer
) {
44 gfx::Vector2dF scroll_delta
= layer
->ScrollDelta();
45 // The scroll parent's scroll delta is the amount we've scrolled on the
46 // compositor thread since the commit for this layer tree's source frame.
47 // we last reported to the main thread. I.e., it's the discrepancy between
48 // a scroll parent's scroll delta and offset, so we must add it here.
49 if (layer
->scroll_parent())
50 scroll_delta
+= layer
->scroll_parent()->ScrollDelta();
54 template <typename LayerType
>
55 static gfx::Vector2dF
GetEffectiveTotalScrollOffset(LayerType
* layer
) {
56 gfx::Vector2dF offset
= layer
->TotalScrollOffset();
57 // The scroll parent's total scroll offset (scroll offset + scroll delta)
58 // can't be used because its scroll offset has already been applied to the
59 // scroll children's positions by the main thread layer positioning code.
60 if (layer
->scroll_parent())
61 offset
+= layer
->scroll_parent()->ScrollDelta();
65 inline gfx::Rect
CalculateVisibleRectWithCachedLayerRect(
66 const gfx::Rect
& target_surface_rect
,
67 const gfx::Rect
& layer_bound_rect
,
68 const gfx::Rect
& layer_rect_in_target_space
,
69 const gfx::Transform
& transform
) {
70 if (layer_rect_in_target_space
.IsEmpty())
73 // Is this layer fully contained within the target surface?
74 if (target_surface_rect
.Contains(layer_rect_in_target_space
))
75 return layer_bound_rect
;
77 // If the layer doesn't fill up the entire surface, then find the part of
78 // the surface rect where the layer could be visible. This avoids trying to
79 // project surface rect points that are behind the projection point.
80 gfx::Rect minimal_surface_rect
= target_surface_rect
;
81 minimal_surface_rect
.Intersect(layer_rect_in_target_space
);
83 if (minimal_surface_rect
.IsEmpty())
86 // Project the corners of the target surface rect into the layer space.
87 // This bounding rectangle may be larger than it needs to be (being
88 // axis-aligned), but is a reasonable filter on the space to consider.
89 // Non-invertible transforms will create an empty rect here.
91 gfx::Transform
surface_to_layer(gfx::Transform::kSkipInitialization
);
92 if (!transform
.GetInverse(&surface_to_layer
)) {
93 // Because we cannot use the surface bounds to determine what portion of
94 // the layer is visible, we must conservatively assume the full layer is
96 return layer_bound_rect
;
99 gfx::Rect layer_rect
= MathUtil::ProjectEnclosingClippedRect(
100 surface_to_layer
, minimal_surface_rect
);
101 layer_rect
.Intersect(layer_bound_rect
);
105 gfx::Rect
LayerTreeHostCommon::CalculateVisibleRect(
106 const gfx::Rect
& target_surface_rect
,
107 const gfx::Rect
& layer_bound_rect
,
108 const gfx::Transform
& transform
) {
109 gfx::Rect layer_in_surface_space
=
110 MathUtil::MapEnclosingClippedRect(transform
, layer_bound_rect
);
111 return CalculateVisibleRectWithCachedLayerRect(
112 target_surface_rect
, layer_bound_rect
, layer_in_surface_space
, transform
);
115 template <typename LayerType
>
116 static LayerType
* NextTargetSurface(LayerType
* layer
) {
117 return layer
->parent() ? layer
->parent()->render_target() : 0;
120 // Given two layers, this function finds their respective render targets and,
121 // computes a change of basis translation. It does this by accumulating the
122 // translation components of the draw transforms of each target between the
123 // ancestor and descendant. These transforms must be 2D translations, and this
124 // requirement is enforced at every step.
125 template <typename LayerType
>
126 static gfx::Vector2dF
ComputeChangeOfBasisTranslation(
127 const LayerType
& ancestor_layer
,
128 const LayerType
& descendant_layer
) {
129 DCHECK(descendant_layer
.HasAncestor(&ancestor_layer
));
130 const LayerType
* descendant_target
= descendant_layer
.render_target();
131 DCHECK(descendant_target
);
132 const LayerType
* ancestor_target
= ancestor_layer
.render_target();
133 DCHECK(ancestor_target
);
135 gfx::Vector2dF translation
;
136 for (const LayerType
* target
= descendant_target
; target
!= ancestor_target
;
137 target
= NextTargetSurface(target
)) {
138 const gfx::Transform
& trans
= target
->render_surface()->draw_transform();
139 // Ensure that this translation is truly 2d.
140 DCHECK(trans
.IsIdentityOrTranslation());
141 DCHECK_EQ(0.f
, trans
.matrix().get(2, 3));
142 translation
+= trans
.To2dTranslation();
148 enum TranslateRectDirection
{
149 TranslateRectDirectionToAncestor
,
150 TranslateRectDirectionToDescendant
153 template <typename LayerType
>
154 static gfx::Rect
TranslateRectToTargetSpace(const LayerType
& ancestor_layer
,
155 const LayerType
& descendant_layer
,
156 const gfx::Rect
& rect
,
157 TranslateRectDirection direction
) {
158 gfx::Vector2dF translation
= ComputeChangeOfBasisTranslation
<LayerType
>(
159 ancestor_layer
, descendant_layer
);
160 if (direction
== TranslateRectDirectionToDescendant
)
161 translation
.Scale(-1.f
);
162 return gfx::ToEnclosingRect(
163 gfx::RectF(rect
.origin() + translation
, rect
.size()));
166 // Attempts to update the clip rects for the given layer. If the layer has a
167 // clip_parent, it may not inherit its immediate ancestor's clip.
168 template <typename LayerType
>
169 static void UpdateClipRectsForClipChild(
170 const LayerType
* layer
,
171 gfx::Rect
* clip_rect_in_parent_target_space
,
172 bool* subtree_should_be_clipped
) {
173 // If the layer has no clip_parent, or the ancestor is the same as its actual
174 // parent, then we don't need special clip rects. Bail now and leave the out
175 // parameters untouched.
176 const LayerType
* clip_parent
= layer
->scroll_parent();
179 clip_parent
= layer
->clip_parent();
181 if (!clip_parent
|| clip_parent
== layer
->parent())
184 // The root layer is never a clip child.
185 DCHECK(layer
->parent());
187 // Grab the cached values.
188 *clip_rect_in_parent_target_space
= clip_parent
->clip_rect();
189 *subtree_should_be_clipped
= clip_parent
->is_clipped();
191 // We may have to project the clip rect into our parent's target space. Note,
192 // it must be our parent's target space, not ours. For one, we haven't
193 // computed our transforms, so we couldn't put it in our space yet even if we
194 // wanted to. But more importantly, this matches the expectations of
195 // CalculateDrawPropertiesInternal. If we, say, create a render surface, these
196 // clip rects will want to be in its target space, not ours.
197 if (clip_parent
== layer
->clip_parent()) {
198 *clip_rect_in_parent_target_space
= TranslateRectToTargetSpace
<LayerType
>(
201 *clip_rect_in_parent_target_space
,
202 TranslateRectDirectionToDescendant
);
204 // If we're being clipped by our scroll parent, we must translate through
205 // our common ancestor. This happens to be our parent, so it is sufficent to
206 // translate from our clip parent's space to the space of its ancestor (our
208 *clip_rect_in_parent_target_space
=
209 TranslateRectToTargetSpace
<LayerType
>(*layer
->parent(),
211 *clip_rect_in_parent_target_space
,
212 TranslateRectDirectionToAncestor
);
216 // We collect an accumulated drawable content rect per render surface.
217 // Typically, a layer will contribute to only one surface, the surface
218 // associated with its render target. Clip children, however, may affect
219 // several surfaces since there may be several surfaces between the clip child
222 // NB: we accumulate the layer's *clipped* drawable content rect.
223 template <typename LayerType
>
224 struct AccumulatedSurfaceState
{
225 explicit AccumulatedSurfaceState(LayerType
* render_target
)
226 : render_target(render_target
) {}
228 // The accumulated drawable content rect for the surface associated with the
229 // given |render_target|.
230 gfx::Rect drawable_content_rect
;
232 // The target owning the surface. (We hang onto the target rather than the
233 // surface so that we can DCHECK that the surface's draw transform is simply
234 // a translation when |render_target| reports that it has no unclipped
236 LayerType
* render_target
;
239 template <typename LayerType
>
240 void UpdateAccumulatedSurfaceState(
242 const gfx::Rect
& drawable_content_rect
,
243 std::vector
<AccumulatedSurfaceState
<LayerType
> >*
244 accumulated_surface_state
) {
245 if (IsRootLayer(layer
))
248 // We will apply our drawable content rect to the accumulated rects for all
249 // surfaces between us and |render_target| (inclusive). This is either our
250 // clip parent's target if we are a clip child, or else simply our parent's
251 // target. We use our parent's target because we're either the owner of a
252 // render surface and we'll want to add our rect to our *surface's* target, or
253 // we're not and our target is the same as our parent's. In both cases, the
254 // parent's target gives us what we want.
255 LayerType
* render_target
= layer
->clip_parent()
256 ? layer
->clip_parent()->render_target()
257 : layer
->parent()->render_target();
259 // If the layer owns a surface, then the content rect is in the wrong space.
260 // Instead, we will use the surface's DrawableContentRect which is in target
261 // space as required.
262 gfx::Rect target_rect
= drawable_content_rect
;
263 if (layer
->render_surface()) {
265 gfx::ToEnclosedRect(layer
->render_surface()->DrawableContentRect());
268 if (render_target
->is_clipped()) {
269 gfx::Rect clip_rect
= render_target
->clip_rect();
270 // If the layer has a clip parent, the clip rect may be in the wrong space,
271 // so we'll need to transform it before it is applied.
272 if (layer
->clip_parent()) {
273 clip_rect
= TranslateRectToTargetSpace
<LayerType
>(
274 *layer
->clip_parent(),
277 TranslateRectDirectionToDescendant
);
279 target_rect
.Intersect(clip_rect
);
282 // We must have at least one entry in the vector for the root.
283 DCHECK_LT(0ul, accumulated_surface_state
->size());
285 typedef typename
std::vector
<AccumulatedSurfaceState
<LayerType
> >
286 AccumulatedSurfaceStateVector
;
287 typedef typename
AccumulatedSurfaceStateVector::reverse_iterator
288 AccumulatedSurfaceStateIterator
;
289 AccumulatedSurfaceStateIterator current_state
=
290 accumulated_surface_state
->rbegin();
292 // Add this rect to the accumulated content rect for all surfaces until we
293 // reach the target surface.
294 bool found_render_target
= false;
295 for (; current_state
!= accumulated_surface_state
->rend(); ++current_state
) {
296 current_state
->drawable_content_rect
.Union(target_rect
);
298 // If we've reached |render_target| our work is done and we can bail.
299 if (current_state
->render_target
== render_target
) {
300 found_render_target
= true;
304 // Transform rect from the current target's space to the next.
305 LayerType
* current_target
= current_state
->render_target
;
306 DCHECK(current_target
->render_surface());
307 const gfx::Transform
& current_draw_transform
=
308 current_target
->render_surface()->draw_transform();
310 // If we have unclipped descendants, the draw transform is a translation.
311 DCHECK(current_target
->num_unclipped_descendants() == 0 ||
312 current_draw_transform
.IsIdentityOrTranslation());
314 target_rect
= gfx::ToEnclosingRect(
315 MathUtil::MapClippedRect(current_draw_transform
, target_rect
));
318 // It is an error to not reach |render_target|. If this happens, it means that
319 // either the clip parent is not an ancestor of the clip child or the surface
320 // state vector is empty, both of which should be impossible.
321 DCHECK(found_render_target
);
324 template <typename LayerType
> static inline bool IsRootLayer(LayerType
* layer
) {
325 return !layer
->parent();
328 template <typename LayerType
>
329 static inline bool LayerIsInExisting3DRenderingContext(LayerType
* layer
) {
330 return layer
->is_3d_sorted() && layer
->parent() &&
331 layer
->parent()->is_3d_sorted();
334 template <typename LayerType
>
335 static bool IsRootLayerOfNewRenderingContext(LayerType
* layer
) {
337 return !layer
->parent()->is_3d_sorted() && layer
->is_3d_sorted();
339 return layer
->is_3d_sorted();
342 template <typename LayerType
>
343 static bool IsLayerBackFaceVisible(LayerType
* layer
) {
344 // The current W3C spec on CSS transforms says that backface visibility should
345 // be determined differently depending on whether the layer is in a "3d
346 // rendering context" or not. For Chromium code, we can determine whether we
347 // are in a 3d rendering context by checking if the parent preserves 3d.
349 if (LayerIsInExisting3DRenderingContext(layer
))
350 return layer
->draw_transform().IsBackFaceVisible();
352 // In this case, either the layer establishes a new 3d rendering context, or
353 // is not in a 3d rendering context at all.
354 return layer
->transform().IsBackFaceVisible();
357 template <typename LayerType
>
358 static bool IsSurfaceBackFaceVisible(LayerType
* layer
,
359 const gfx::Transform
& draw_transform
) {
360 if (LayerIsInExisting3DRenderingContext(layer
))
361 return draw_transform
.IsBackFaceVisible();
363 if (IsRootLayerOfNewRenderingContext(layer
))
364 return layer
->transform().IsBackFaceVisible();
366 // If the render_surface is not part of a new or existing rendering context,
367 // then the layers that contribute to this surface will decide back-face
368 // visibility for themselves.
372 template <typename LayerType
>
373 static inline bool LayerClipsSubtree(LayerType
* layer
) {
374 return layer
->masks_to_bounds() || layer
->mask_layer();
377 template <typename LayerType
>
378 static gfx::Rect
CalculateVisibleContentRect(
380 const gfx::Rect
& clip_rect_of_target_surface_in_target_space
,
381 const gfx::Rect
& layer_rect_in_target_space
) {
382 DCHECK(layer
->render_target());
384 // Nothing is visible if the layer bounds are empty.
385 if (!layer
->DrawsContent() || layer
->content_bounds().IsEmpty() ||
386 layer
->drawable_content_rect().IsEmpty())
389 // Compute visible bounds in target surface space.
390 gfx::Rect visible_rect_in_target_surface_space
=
391 layer
->drawable_content_rect();
393 if (!layer
->render_target()->render_surface()->clip_rect().IsEmpty()) {
394 // The |layer| L has a target T which owns a surface Ts. The surface Ts
397 // In this case the target surface Ts does clip the layer L that contributes
398 // to it. So, we have to convert the clip rect of Ts from the target space
399 // of Ts (that is the space of TsT), to the current render target's space
400 // (that is the space of T). This conversion is done outside this function
401 // so that it can be cached instead of computing it redundantly for every
403 visible_rect_in_target_surface_space
.Intersect(
404 clip_rect_of_target_surface_in_target_space
);
407 if (visible_rect_in_target_surface_space
.IsEmpty())
410 return CalculateVisibleRectWithCachedLayerRect(
411 visible_rect_in_target_surface_space
,
412 gfx::Rect(layer
->content_bounds()),
413 layer_rect_in_target_space
,
414 layer
->draw_transform());
417 static inline bool TransformToParentIsKnown(LayerImpl
* layer
) { return true; }
419 static inline bool TransformToParentIsKnown(Layer
* layer
) {
420 return !layer
->TransformIsAnimating();
423 static inline bool TransformToScreenIsKnown(LayerImpl
* layer
) { return true; }
425 static inline bool TransformToScreenIsKnown(Layer
* layer
) {
426 return !layer
->screen_space_transform_is_animating();
429 template <typename LayerType
>
430 static bool LayerShouldBeSkipped(LayerType
* layer
, bool layer_is_drawn
) {
431 // Layers can be skipped if any of these conditions are met.
432 // - is not drawn due to it or one of its ancestors being hidden (or having
433 // no copy requests).
434 // - does not draw content.
436 // - has empty bounds
437 // - the layer is not double-sided, but its back face is visible.
439 // Some additional conditions need to be computed at a later point after the
440 // recursion is finished.
441 // - the intersection of render_surface content and layer clip_rect is empty
442 // - the visible_content_rect is empty
444 // Note, if the layer should not have been drawn due to being fully
445 // transparent, we would have skipped the entire subtree and never made it
446 // into this function, so it is safe to omit this check here.
451 if (!layer
->DrawsContent() || layer
->bounds().IsEmpty())
454 LayerType
* backface_test_layer
= layer
;
455 if (layer
->use_parent_backface_visibility()) {
456 DCHECK(layer
->parent());
457 DCHECK(!layer
->parent()->use_parent_backface_visibility());
458 backface_test_layer
= layer
->parent();
461 // The layer should not be drawn if (1) it is not double-sided and (2) the
462 // back of the layer is known to be facing the screen.
463 if (!backface_test_layer
->double_sided() &&
464 TransformToScreenIsKnown(backface_test_layer
) &&
465 IsLayerBackFaceVisible(backface_test_layer
))
471 template <typename LayerType
>
472 static bool HasInvertibleOrAnimatedTransform(LayerType
* layer
) {
473 return layer
->transform_is_invertible() || layer
->TransformIsAnimating();
476 static inline bool SubtreeShouldBeSkipped(LayerImpl
* layer
,
477 bool layer_is_drawn
) {
478 // If the layer transform is not invertible, it should not be drawn.
479 // TODO(ajuma): Correctly process subtrees with singular transform for the
480 // case where we may animate to a non-singular transform and wish to
482 if (!HasInvertibleOrAnimatedTransform(layer
))
485 // When we need to do a readback/copy of a layer's output, we can not skip
486 // it or any of its ancestors.
487 if (layer
->draw_properties().layer_or_descendant_has_copy_request
)
490 // If the layer is not drawn, then skip it and its subtree.
494 // If layer is on the pending tree and opacity is being animated then
495 // this subtree can't be skipped as we need to create, prioritize and
496 // include tiles for this layer when deciding if tree can be activated.
497 if (layer
->layer_tree_impl()->IsPendingTree() && layer
->OpacityIsAnimating())
500 // The opacity of a layer always applies to its children (either implicitly
501 // via a render surface or explicitly if the parent preserves 3D), so the
502 // entire subtree can be skipped if this layer is fully transparent.
503 return !layer
->opacity();
506 static inline bool SubtreeShouldBeSkipped(Layer
* layer
, bool layer_is_drawn
) {
507 // If the layer transform is not invertible, it should not be drawn.
508 if (!layer
->transform_is_invertible() && !layer
->TransformIsAnimating())
511 // When we need to do a readback/copy of a layer's output, we can not skip
512 // it or any of its ancestors.
513 if (layer
->draw_properties().layer_or_descendant_has_copy_request
)
516 // If the layer is not drawn, then skip it and its subtree.
520 // If the opacity is being animated then the opacity on the main thread is
521 // unreliable (since the impl thread may be using a different opacity), so it
522 // should not be trusted.
523 // In particular, it should not cause the subtree to be skipped.
524 // Similarly, for layers that might animate opacity using an impl-only
525 // animation, their subtree should also not be skipped.
526 return !layer
->opacity() && !layer
->OpacityIsAnimating() &&
527 !layer
->OpacityCanAnimateOnImplThread();
530 static inline void SavePaintPropertiesLayer(LayerImpl
* layer
) {}
532 static inline void SavePaintPropertiesLayer(Layer
* layer
) {
533 layer
->SavePaintProperties();
535 if (layer
->mask_layer())
536 layer
->mask_layer()->SavePaintProperties();
537 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
538 layer
->replica_layer()->mask_layer()->SavePaintProperties();
541 template <typename LayerType
>
542 static bool SubtreeShouldRenderToSeparateSurface(
544 bool axis_aligned_with_respect_to_parent
) {
546 // A layer and its descendants should render onto a new RenderSurfaceImpl if
547 // any of these rules hold:
550 // The root layer owns a render surface, but it never acts as a contributing
551 // surface to another render target. Compositor features that are applied via
552 // a contributing surface can not be applied to the root layer. In order to
553 // use these effects, another child of the root would need to be introduced
554 // in order to act as a contributing surface to the root layer's surface.
555 bool is_root
= IsRootLayer(layer
);
557 // If the layer uses a mask.
558 if (layer
->mask_layer()) {
563 // If the layer has a reflection.
564 if (layer
->replica_layer()) {
569 // If the layer uses a CSS filter.
570 if (!layer
->filters().IsEmpty() || !layer
->background_filters().IsEmpty()) {
575 int num_descendants_that_draw_content
=
576 layer
->draw_properties().num_descendants_that_draw_content
;
578 // If the layer flattens its subtree, but it is treated as a 3D object by its
579 // parent (i.e. parent participates in a 3D rendering context).
580 if (LayerIsInExisting3DRenderingContext(layer
) &&
581 layer
->should_flatten_transform() &&
582 num_descendants_that_draw_content
> 0) {
583 TRACE_EVENT_INSTANT0(
585 "LayerTreeHostCommon::SubtreeShouldRenderToSeparateSurface flattening",
586 TRACE_EVENT_SCOPE_THREAD
);
591 // If the layer has blending.
592 // TODO(rosca): this is temporary, until blending is implemented for other
593 // types of quads than RenderPassDrawQuad. Layers having descendants that draw
594 // content will still create a separate rendering surface.
595 if (!layer
->uses_default_blend_mode()) {
596 TRACE_EVENT_INSTANT0(
598 "LayerTreeHostCommon::SubtreeShouldRenderToSeparateSurface blending",
599 TRACE_EVENT_SCOPE_THREAD
);
604 // If the layer clips its descendants but it is not axis-aligned with respect
606 bool layer_clips_external_content
=
607 LayerClipsSubtree(layer
) || layer
->HasDelegatedContent();
608 if (layer_clips_external_content
&& !axis_aligned_with_respect_to_parent
&&
609 num_descendants_that_draw_content
> 0) {
610 TRACE_EVENT_INSTANT0(
612 "LayerTreeHostCommon::SubtreeShouldRenderToSeparateSurface clipping",
613 TRACE_EVENT_SCOPE_THREAD
);
618 // If the layer has some translucency and does not have a preserves-3d
619 // transform style. This condition only needs a render surface if two or more
620 // layers in the subtree overlap. But checking layer overlaps is unnecessarily
621 // costly so instead we conservatively create a surface whenever at least two
622 // layers draw content for this subtree.
623 bool at_least_two_layers_in_subtree_draw_content
=
624 num_descendants_that_draw_content
> 0 &&
625 (layer
->DrawsContent() || num_descendants_that_draw_content
> 1);
627 if (layer
->opacity() != 1.f
&& layer
->should_flatten_transform() &&
628 at_least_two_layers_in_subtree_draw_content
) {
629 TRACE_EVENT_INSTANT0(
631 "LayerTreeHostCommon::SubtreeShouldRenderToSeparateSurface opacity",
632 TRACE_EVENT_SCOPE_THREAD
);
637 // The root layer should always have a render_surface.
642 // These are allowed on the root surface, as they don't require the surface to
643 // be used as a contributing surface in order to apply correctly.
646 // If the layer has isolation.
647 // TODO(rosca): to be optimized - create separate rendering surface only when
648 // the blending descendants might have access to the content behind this layer
649 // (layer has transparent background or descendants overflow).
650 // https://code.google.com/p/chromium/issues/detail?id=301738
651 if (layer
->is_root_for_isolated_group()) {
652 TRACE_EVENT_INSTANT0(
654 "LayerTreeHostCommon::SubtreeShouldRenderToSeparateSurface isolation",
655 TRACE_EVENT_SCOPE_THREAD
);
660 if (layer
->force_render_surface())
663 // If we'll make a copy of the layer's contents.
664 if (layer
->HasCopyRequest())
670 // This function returns a translation matrix that can be applied on a vector
671 // that's in the layer's target surface coordinate, while the position offset is
672 // specified in some ancestor layer's coordinate.
673 gfx::Transform
ComputeSizeDeltaCompensation(
675 LayerImpl
* container
,
676 const gfx::Vector2dF
& position_offset
) {
677 gfx::Transform result_transform
;
679 // To apply a translate in the container's layer space,
680 // the following steps need to be done:
681 // Step 1a. transform from target surface space to the container's target
683 // Step 1b. transform from container's target surface space to the
684 // container's layer space
685 // Step 2. apply the compensation
686 // Step 3. transform back to target surface space
688 gfx::Transform target_surface_space_to_container_layer_space
;
690 LayerImpl
* container_target_surface
= container
->render_target();
691 for (LayerImpl
* current_target_surface
= NextTargetSurface(layer
);
692 current_target_surface
&&
693 current_target_surface
!= container_target_surface
;
694 current_target_surface
= NextTargetSurface(current_target_surface
)) {
695 // Note: Concat is used here to convert the result coordinate space from
696 // current render surface to the next render surface.
697 target_surface_space_to_container_layer_space
.ConcatTransform(
698 current_target_surface
->render_surface()->draw_transform());
701 gfx::Transform container_layer_space_to_container_target_surface_space
=
702 container
->draw_transform();
703 container_layer_space_to_container_target_surface_space
.Scale(
704 container
->contents_scale_x(), container
->contents_scale_y());
706 gfx::Transform container_target_surface_space_to_container_layer_space
;
707 if (container_layer_space_to_container_target_surface_space
.GetInverse(
708 &container_target_surface_space_to_container_layer_space
)) {
709 // Note: Again, Concat is used to conver the result coordinate space from
710 // the container render surface to the container layer.
711 target_surface_space_to_container_layer_space
.ConcatTransform(
712 container_target_surface_space_to_container_layer_space
);
716 gfx::Transform container_layer_space_to_target_surface_space
;
717 if (target_surface_space_to_container_layer_space
.GetInverse(
718 &container_layer_space_to_target_surface_space
)) {
719 result_transform
.PreconcatTransform(
720 container_layer_space_to_target_surface_space
);
722 // TODO(shawnsingh): A non-invertible matrix could still make meaningful
723 // projection. For example ScaleZ(0) is non-invertible but the layer is
725 return gfx::Transform();
729 result_transform
.Translate(position_offset
.x(), position_offset
.y());
732 result_transform
.PreconcatTransform(
733 target_surface_space_to_container_layer_space
);
735 return result_transform
;
738 void ApplyPositionAdjustment(
741 const gfx::Transform
& scroll_compensation
,
742 gfx::Transform
* combined_transform
) {}
743 void ApplyPositionAdjustment(
745 LayerImpl
* container
,
746 const gfx::Transform
& scroll_compensation
,
747 gfx::Transform
* combined_transform
) {
748 if (!layer
->position_constraint().is_fixed_position())
751 // Special case: this layer is a composited fixed-position layer; we need to
752 // explicitly compensate for all ancestors' nonzero scroll_deltas to keep
753 // this layer fixed correctly.
754 // Note carefully: this is Concat, not Preconcat
755 // (current_scroll_compensation * combined_transform).
756 combined_transform
->ConcatTransform(scroll_compensation
);
758 // For right-edge or bottom-edge anchored fixed position layers,
759 // the layer should relocate itself if the container changes its size.
760 bool fixed_to_right_edge
=
761 layer
->position_constraint().is_fixed_to_right_edge();
762 bool fixed_to_bottom_edge
=
763 layer
->position_constraint().is_fixed_to_bottom_edge();
764 gfx::Vector2dF position_offset
= container
->FixedContainerSizeDelta();
765 position_offset
.set_x(fixed_to_right_edge
? position_offset
.x() : 0);
766 position_offset
.set_y(fixed_to_bottom_edge
? position_offset
.y() : 0);
767 if (position_offset
.IsZero())
770 // Note: Again, this is Concat. The compensation matrix will be applied on
771 // the vector in target surface space.
772 combined_transform
->ConcatTransform(
773 ComputeSizeDeltaCompensation(layer
, container
, position_offset
));
776 gfx::Transform
ComputeScrollCompensationForThisLayer(
777 LayerImpl
* scrolling_layer
,
778 const gfx::Transform
& parent_matrix
,
779 const gfx::Vector2dF
& scroll_delta
) {
780 // For every layer that has non-zero scroll_delta, we have to compute a
781 // transform that can undo the scroll_delta translation. In particular, we
782 // want this matrix to premultiply a fixed-position layer's parent_matrix, so
783 // we design this transform in three steps as follows. The steps described
784 // here apply from right-to-left, so Step 1 would be the right-most matrix:
786 // Step 1. transform from target surface space to the exact space where
787 // scroll_delta is actually applied.
788 // -- this is inverse of parent_matrix
789 // Step 2. undo the scroll_delta
790 // -- this is just a translation by scroll_delta.
791 // Step 3. transform back to target surface space.
792 // -- this transform is the parent_matrix
794 // These steps create a matrix that both start and end in target surface
795 // space. So this matrix can pre-multiply any fixed-position layer's
796 // draw_transform to undo the scroll_deltas -- as long as that fixed position
797 // layer is fixed onto the same render_target as this scrolling_layer.
800 gfx::Transform scroll_compensation_for_this_layer
= parent_matrix
; // Step 3
801 scroll_compensation_for_this_layer
.Translate(
803 scroll_delta
.y()); // Step 2
805 gfx::Transform
inverse_parent_matrix(gfx::Transform::kSkipInitialization
);
806 if (!parent_matrix
.GetInverse(&inverse_parent_matrix
)) {
807 // TODO(shawnsingh): Either we need to handle uninvertible transforms
808 // here, or DCHECK that the transform is invertible.
810 scroll_compensation_for_this_layer
.PreconcatTransform(
811 inverse_parent_matrix
); // Step 1
812 return scroll_compensation_for_this_layer
;
815 gfx::Transform
ComputeScrollCompensationMatrixForChildren(
816 Layer
* current_layer
,
817 const gfx::Transform
& current_parent_matrix
,
818 const gfx::Transform
& current_scroll_compensation
,
819 const gfx::Vector2dF
& scroll_delta
) {
820 // The main thread (i.e. Layer) does not need to worry about scroll
821 // compensation. So we can just return an identity matrix here.
822 return gfx::Transform();
825 gfx::Transform
ComputeScrollCompensationMatrixForChildren(
827 const gfx::Transform
& parent_matrix
,
828 const gfx::Transform
& current_scroll_compensation_matrix
,
829 const gfx::Vector2dF
& scroll_delta
) {
830 // "Total scroll compensation" is the transform needed to cancel out all
831 // scroll_delta translations that occurred since the nearest container layer,
832 // even if there are render_surfaces in-between.
834 // There are some edge cases to be aware of, that are not explicit in the
836 // - A layer that is both a fixed-position and container should not be its
837 // own container, instead, that means it is fixed to an ancestor, and is a
838 // container for any fixed-position descendants.
839 // - A layer that is a fixed-position container and has a render_surface
840 // should behave the same as a container without a render_surface, the
841 // render_surface is irrelevant in that case.
842 // - A layer that does not have an explicit container is simply fixed to the
843 // viewport. (i.e. the root render_surface.)
844 // - If the fixed-position layer has its own render_surface, then the
845 // render_surface is the one who gets fixed.
847 // This function needs to be called AFTER layers create their own
851 // Scroll compensation restarts from identity under two possible conditions:
852 // - the current layer is a container for fixed-position descendants
853 // - the current layer is fixed-position itself, so any fixed-position
854 // descendants are positioned with respect to this layer. Thus, any
855 // fixed position descendants only need to compensate for scrollDeltas
856 // that occur below this layer.
857 bool current_layer_resets_scroll_compensation_for_descendants
=
858 layer
->IsContainerForFixedPositionLayers() ||
859 layer
->position_constraint().is_fixed_position();
861 // Avoid the overheads (including stack allocation and matrix
862 // initialization/copy) if we know that the scroll compensation doesn't need
863 // to be reset or adjusted.
864 if (!current_layer_resets_scroll_compensation_for_descendants
&&
865 scroll_delta
.IsZero() && !layer
->render_surface())
866 return current_scroll_compensation_matrix
;
868 // Start as identity matrix.
869 gfx::Transform next_scroll_compensation_matrix
;
871 // If this layer does not reset scroll compensation, then it inherits the
872 // existing scroll compensations.
873 if (!current_layer_resets_scroll_compensation_for_descendants
)
874 next_scroll_compensation_matrix
= current_scroll_compensation_matrix
;
876 // If the current layer has a non-zero scroll_delta, then we should compute
877 // its local scroll compensation and accumulate it to the
878 // next_scroll_compensation_matrix.
879 if (!scroll_delta
.IsZero()) {
880 gfx::Transform scroll_compensation_for_this_layer
=
881 ComputeScrollCompensationForThisLayer(
882 layer
, parent_matrix
, scroll_delta
);
883 next_scroll_compensation_matrix
.PreconcatTransform(
884 scroll_compensation_for_this_layer
);
887 // If the layer created its own render_surface, we have to adjust
888 // next_scroll_compensation_matrix. The adjustment allows us to continue
889 // using the scroll compensation on the next surface.
890 // Step 1 (right-most in the math): transform from the new surface to the
891 // original ancestor surface
892 // Step 2: apply the scroll compensation
893 // Step 3: transform back to the new surface.
894 if (layer
->render_surface() &&
895 !next_scroll_compensation_matrix
.IsIdentity()) {
896 gfx::Transform
inverse_surface_draw_transform(
897 gfx::Transform::kSkipInitialization
);
898 if (!layer
->render_surface()->draw_transform().GetInverse(
899 &inverse_surface_draw_transform
)) {
900 // TODO(shawnsingh): Either we need to handle uninvertible transforms
901 // here, or DCHECK that the transform is invertible.
903 next_scroll_compensation_matrix
=
904 inverse_surface_draw_transform
* next_scroll_compensation_matrix
*
905 layer
->render_surface()->draw_transform();
908 return next_scroll_compensation_matrix
;
911 template <typename LayerType
>
912 static inline void CalculateContentsScale(
914 float contents_scale
,
915 float device_scale_factor
,
916 float page_scale_factor
,
917 float maximum_animation_contents_scale
,
918 bool animating_transform_to_screen
) {
919 layer
->CalculateContentsScale(contents_scale
,
922 maximum_animation_contents_scale
,
923 animating_transform_to_screen
,
924 &layer
->draw_properties().contents_scale_x
,
925 &layer
->draw_properties().contents_scale_y
,
926 &layer
->draw_properties().content_bounds
);
928 LayerType
* mask_layer
= layer
->mask_layer();
930 mask_layer
->CalculateContentsScale(
934 maximum_animation_contents_scale
,
935 animating_transform_to_screen
,
936 &mask_layer
->draw_properties().contents_scale_x
,
937 &mask_layer
->draw_properties().contents_scale_y
,
938 &mask_layer
->draw_properties().content_bounds
);
941 LayerType
* replica_mask_layer
=
942 layer
->replica_layer() ? layer
->replica_layer()->mask_layer() : NULL
;
943 if (replica_mask_layer
) {
944 replica_mask_layer
->CalculateContentsScale(
948 maximum_animation_contents_scale
,
949 animating_transform_to_screen
,
950 &replica_mask_layer
->draw_properties().contents_scale_x
,
951 &replica_mask_layer
->draw_properties().contents_scale_y
,
952 &replica_mask_layer
->draw_properties().content_bounds
);
956 static inline void UpdateLayerContentsScale(
958 bool can_adjust_raster_scale
,
959 float ideal_contents_scale
,
960 float device_scale_factor
,
961 float page_scale_factor
,
962 float maximum_animation_contents_scale
,
963 bool animating_transform_to_screen
) {
964 CalculateContentsScale(layer
,
965 ideal_contents_scale
,
968 maximum_animation_contents_scale
,
969 animating_transform_to_screen
);
972 static inline void UpdateLayerContentsScale(
974 bool can_adjust_raster_scale
,
975 float ideal_contents_scale
,
976 float device_scale_factor
,
977 float page_scale_factor
,
978 float maximum_animation_contents_scale
,
979 bool animating_transform_to_screen
) {
980 if (can_adjust_raster_scale
) {
981 float ideal_raster_scale
=
982 ideal_contents_scale
/ (device_scale_factor
* page_scale_factor
);
984 bool need_to_set_raster_scale
= layer
->raster_scale_is_unknown();
986 // If we've previously saved a raster_scale but the ideal changes, things
987 // are unpredictable and we should just use 1.
988 if (!need_to_set_raster_scale
&& layer
->raster_scale() != 1.f
&&
989 ideal_raster_scale
!= layer
->raster_scale()) {
990 ideal_raster_scale
= 1.f
;
991 need_to_set_raster_scale
= true;
994 if (need_to_set_raster_scale
) {
995 bool use_and_save_ideal_scale
=
996 ideal_raster_scale
>= 1.f
&& !animating_transform_to_screen
;
997 if (use_and_save_ideal_scale
)
998 layer
->set_raster_scale(ideal_raster_scale
);
1002 float raster_scale
= 1.f
;
1003 if (!layer
->raster_scale_is_unknown())
1004 raster_scale
= layer
->raster_scale();
1006 gfx::Size old_content_bounds
= layer
->content_bounds();
1007 float old_contents_scale_x
= layer
->contents_scale_x();
1008 float old_contents_scale_y
= layer
->contents_scale_y();
1010 float contents_scale
= raster_scale
* device_scale_factor
* page_scale_factor
;
1011 CalculateContentsScale(layer
,
1013 device_scale_factor
,
1015 maximum_animation_contents_scale
,
1016 animating_transform_to_screen
);
1018 if (layer
->content_bounds() != old_content_bounds
||
1019 layer
->contents_scale_x() != old_contents_scale_x
||
1020 layer
->contents_scale_y() != old_contents_scale_y
)
1021 layer
->SetNeedsPushProperties();
1024 static inline void CalculateAnimationContentsScale(
1026 bool ancestor_is_animating_scale
,
1027 float ancestor_maximum_animation_contents_scale
,
1028 const gfx::Transform
& parent_transform
,
1029 const gfx::Transform
& combined_transform
,
1030 bool* combined_is_animating_scale
,
1031 float* combined_maximum_animation_contents_scale
) {
1032 *combined_is_animating_scale
= false;
1033 *combined_maximum_animation_contents_scale
= 0.f
;
1036 static inline void CalculateAnimationContentsScale(
1038 bool ancestor_is_animating_scale
,
1039 float ancestor_maximum_animation_contents_scale
,
1040 const gfx::Transform
& ancestor_transform
,
1041 const gfx::Transform
& combined_transform
,
1042 bool* combined_is_animating_scale
,
1043 float* combined_maximum_animation_contents_scale
) {
1044 if (ancestor_is_animating_scale
&&
1045 ancestor_maximum_animation_contents_scale
== 0.f
) {
1046 // We've already failed to compute a maximum animated scale at an
1047 // ancestor, so we'll continue to fail.
1048 *combined_maximum_animation_contents_scale
= 0.f
;
1049 *combined_is_animating_scale
= true;
1053 if (!combined_transform
.IsScaleOrTranslation()) {
1054 // Computing maximum animated scale in the presence of
1055 // non-scale/translation transforms isn't supported.
1056 *combined_maximum_animation_contents_scale
= 0.f
;
1057 *combined_is_animating_scale
= true;
1061 // We currently only support computing maximum scale for combinations of
1062 // scales and translations. We treat all non-translations as potentially
1063 // affecting scale. Animations that include non-translation/scale components
1064 // will cause the computation of MaximumScale below to fail.
1065 bool layer_is_animating_scale
=
1066 !layer
->layer_animation_controller()->HasOnlyTranslationTransforms();
1068 if (!layer_is_animating_scale
&& !ancestor_is_animating_scale
) {
1069 *combined_maximum_animation_contents_scale
= 0.f
;
1070 *combined_is_animating_scale
= false;
1074 // We don't attempt to accumulate animation scale from multiple nodes,
1075 // because of the risk of significant overestimation. For example, one node
1076 // may be increasing scale from 1 to 10 at the same time as a descendant is
1077 // decreasing scale from 10 to 1. Naively combining these scales would produce
1079 if (layer_is_animating_scale
&& ancestor_is_animating_scale
) {
1080 *combined_maximum_animation_contents_scale
= 0.f
;
1081 *combined_is_animating_scale
= true;
1085 // At this point, we know either the layer or an ancestor, but not both,
1086 // is animating scale.
1087 *combined_is_animating_scale
= true;
1088 if (!layer_is_animating_scale
) {
1089 gfx::Vector2dF layer_transform_scales
=
1090 MathUtil::ComputeTransform2dScaleComponents(layer
->transform(), 0.f
);
1091 *combined_maximum_animation_contents_scale
=
1092 ancestor_maximum_animation_contents_scale
*
1093 std::max(layer_transform_scales
.x(), layer_transform_scales
.y());
1097 float layer_maximum_animated_scale
= 0.f
;
1098 if (!layer
->layer_animation_controller()->MaximumScale(
1099 &layer_maximum_animated_scale
)) {
1100 *combined_maximum_animation_contents_scale
= 0.f
;
1103 gfx::Vector2dF ancestor_transform_scales
=
1104 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform
, 0.f
);
1105 *combined_maximum_animation_contents_scale
=
1106 layer_maximum_animated_scale
*
1107 std::max(ancestor_transform_scales
.x(), ancestor_transform_scales
.y());
1110 template <typename LayerType
>
1111 static inline typename
LayerType::RenderSurfaceType
* CreateOrReuseRenderSurface(
1113 if (!layer
->render_surface()) {
1114 layer
->CreateRenderSurface();
1115 return layer
->render_surface();
1118 layer
->render_surface()->ClearLayerLists();
1119 return layer
->render_surface();
1122 template <typename LayerTypePtr
>
1123 static inline void MarkLayerWithRenderSurfaceLayerListId(
1125 int current_render_surface_layer_list_id
) {
1126 layer
->draw_properties().last_drawn_render_surface_layer_list_id
=
1127 current_render_surface_layer_list_id
;
1130 template <typename LayerTypePtr
>
1131 static inline void MarkMasksWithRenderSurfaceLayerListId(
1133 int current_render_surface_layer_list_id
) {
1134 if (layer
->mask_layer()) {
1135 MarkLayerWithRenderSurfaceLayerListId(layer
->mask_layer(),
1136 current_render_surface_layer_list_id
);
1138 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer()) {
1139 MarkLayerWithRenderSurfaceLayerListId(layer
->replica_layer()->mask_layer(),
1140 current_render_surface_layer_list_id
);
1144 template <typename LayerListType
>
1145 static inline void MarkLayerListWithRenderSurfaceLayerListId(
1146 LayerListType
* layer_list
,
1147 int current_render_surface_layer_list_id
) {
1148 for (typename
LayerListType::iterator it
= layer_list
->begin();
1149 it
!= layer_list
->end();
1151 MarkLayerWithRenderSurfaceLayerListId(*it
,
1152 current_render_surface_layer_list_id
);
1153 MarkMasksWithRenderSurfaceLayerListId(*it
,
1154 current_render_surface_layer_list_id
);
1158 template <typename LayerType
>
1159 static inline void RemoveSurfaceForEarlyExit(
1160 LayerType
* layer_to_remove
,
1161 typename
LayerType::RenderSurfaceListType
* render_surface_layer_list
) {
1162 DCHECK(layer_to_remove
->render_surface());
1163 // Technically, we know that the layer we want to remove should be
1164 // at the back of the render_surface_layer_list. However, we have had
1165 // bugs before that added unnecessary layers here
1166 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes
1167 // things to crash. So here we proactively remove any additional
1168 // layers from the end of the list.
1169 while (render_surface_layer_list
->back() != layer_to_remove
) {
1170 MarkLayerListWithRenderSurfaceLayerListId(
1171 &render_surface_layer_list
->back()->render_surface()->layer_list(), 0);
1172 MarkLayerWithRenderSurfaceLayerListId(render_surface_layer_list
->back(), 0);
1174 render_surface_layer_list
->back()->ClearRenderSurfaceLayerList();
1175 render_surface_layer_list
->pop_back();
1177 DCHECK_EQ(render_surface_layer_list
->back(), layer_to_remove
);
1178 MarkLayerListWithRenderSurfaceLayerListId(
1179 &layer_to_remove
->render_surface()->layer_list(), 0);
1180 MarkLayerWithRenderSurfaceLayerListId(layer_to_remove
, 0);
1181 render_surface_layer_list
->pop_back();
1182 layer_to_remove
->ClearRenderSurfaceLayerList();
1185 struct PreCalculateMetaInformationRecursiveData
{
1186 bool layer_or_descendant_has_copy_request
;
1187 int num_unclipped_descendants
;
1189 PreCalculateMetaInformationRecursiveData()
1190 : layer_or_descendant_has_copy_request(false),
1191 num_unclipped_descendants(0) {}
1193 void Merge(const PreCalculateMetaInformationRecursiveData
& data
) {
1194 layer_or_descendant_has_copy_request
|=
1195 data
.layer_or_descendant_has_copy_request
;
1196 num_unclipped_descendants
+=
1197 data
.num_unclipped_descendants
;
1201 // Recursively walks the layer tree to compute any information that is needed
1202 // before doing the main recursion.
1203 template <typename LayerType
>
1204 static void PreCalculateMetaInformation(
1206 PreCalculateMetaInformationRecursiveData
* recursive_data
) {
1207 bool has_delegated_content
= layer
->HasDelegatedContent();
1208 int num_descendants_that_draw_content
= 0;
1210 layer
->draw_properties().sorted_for_recursion
= false;
1211 layer
->draw_properties().has_child_with_a_scroll_parent
= false;
1213 if (!HasInvertibleOrAnimatedTransform(layer
)) {
1214 // Layers with singular transforms should not be drawn, the whole subtree
1219 if (has_delegated_content
) {
1220 // Layers with delegated content need to be treated as if they have as
1221 // many children as the number of layers they own delegated quads for.
1222 // Since we don't know this number right now, we choose one that acts like
1223 // infinity for our purposes.
1224 num_descendants_that_draw_content
= 1000;
1227 if (layer
->clip_parent())
1228 recursive_data
->num_unclipped_descendants
++;
1230 for (size_t i
= 0; i
< layer
->children().size(); ++i
) {
1231 LayerType
* child_layer
=
1232 LayerTreeHostCommon::get_layer_as_raw_ptr(layer
->children(), i
);
1234 PreCalculateMetaInformationRecursiveData data_for_child
;
1235 PreCalculateMetaInformation(child_layer
, &data_for_child
);
1237 num_descendants_that_draw_content
+= child_layer
->DrawsContent() ? 1 : 0;
1238 num_descendants_that_draw_content
+=
1239 child_layer
->draw_properties().num_descendants_that_draw_content
;
1241 if (child_layer
->scroll_parent())
1242 layer
->draw_properties().has_child_with_a_scroll_parent
= true;
1243 recursive_data
->Merge(data_for_child
);
1246 if (layer
->clip_children()) {
1247 int num_clip_children
= layer
->clip_children()->size();
1248 DCHECK_GE(recursive_data
->num_unclipped_descendants
, num_clip_children
);
1249 recursive_data
->num_unclipped_descendants
-= num_clip_children
;
1252 if (layer
->HasCopyRequest())
1253 recursive_data
->layer_or_descendant_has_copy_request
= true;
1255 layer
->draw_properties().num_descendants_that_draw_content
=
1256 num_descendants_that_draw_content
;
1257 layer
->draw_properties().num_unclipped_descendants
=
1258 recursive_data
->num_unclipped_descendants
;
1259 layer
->draw_properties().layer_or_descendant_has_copy_request
=
1260 recursive_data
->layer_or_descendant_has_copy_request
;
1263 static void RoundTranslationComponents(gfx::Transform
* transform
) {
1264 transform
->matrix().set(0, 3, MathUtil::Round(transform
->matrix().get(0, 3)));
1265 transform
->matrix().set(1, 3, MathUtil::Round(transform
->matrix().get(1, 3)));
1268 template <typename LayerType
>
1269 struct SubtreeGlobals
{
1270 LayerSorter
* layer_sorter
;
1271 int max_texture_size
;
1272 float device_scale_factor
;
1273 float page_scale_factor
;
1274 const LayerType
* page_scale_application_layer
;
1275 bool can_adjust_raster_scales
;
1276 bool can_render_to_separate_surface
;
1279 template<typename LayerType
>
1280 struct DataForRecursion
{
1281 // The accumulated sequence of transforms a layer will use to determine its
1282 // own draw transform.
1283 gfx::Transform parent_matrix
;
1285 // The accumulated sequence of transforms a layer will use to determine its
1286 // own screen-space transform.
1287 gfx::Transform full_hierarchy_matrix
;
1289 // The transform that removes all scrolling that may have occurred between a
1290 // fixed-position layer and its container, so that the layer actually does
1292 gfx::Transform scroll_compensation_matrix
;
1294 // The ancestor that would be the container for any fixed-position / sticky
1296 LayerType
* fixed_container
;
1298 // This is the normal clip rect that is propagated from parent to child.
1299 gfx::Rect clip_rect_in_target_space
;
1301 // When the layer's children want to compute their visible content rect, they
1302 // want to know what their target surface's clip rect will be. BUT - they
1303 // want to know this clip rect represented in their own target space. This
1304 // requires inverse-projecting the surface's clip rect from the surface's
1305 // render target space down to the surface's own space. Instead of computing
1306 // this value redundantly for each child layer, it is computed only once
1307 // while dealing with the parent layer, and then this precomputed value is
1308 // passed down the recursion to the children that actually use it.
1309 gfx::Rect clip_rect_of_target_surface_in_target_space
;
1311 // The maximum amount by which this layer will be scaled during the lifetime
1312 // of currently running animations.
1313 float maximum_animation_contents_scale
;
1315 bool ancestor_is_animating_scale
;
1316 bool ancestor_clips_subtree
;
1317 typename
LayerType::RenderSurfaceType
*
1318 nearest_occlusion_immune_ancestor_surface
;
1319 bool in_subtree_of_page_scale_application_layer
;
1320 bool subtree_can_use_lcd_text
;
1321 bool subtree_is_visible_from_ancestor
;
1324 template <typename LayerType
>
1325 static LayerType
* GetChildContainingLayer(const LayerType
& parent
,
1327 for (LayerType
* ancestor
= layer
; ancestor
; ancestor
= ancestor
->parent()) {
1328 if (ancestor
->parent() == &parent
)
1335 template <typename LayerType
>
1336 static void AddScrollParentChain(std::vector
<LayerType
*>* out
,
1337 const LayerType
& parent
,
1339 // At a high level, this function walks up the chain of scroll parents
1340 // recursively, and once we reach the end of the chain, we add the child
1341 // of |parent| containing each scroll ancestor as we unwind. The result is
1342 // an ordering of parent's children that ensures that scroll parents are
1343 // visited before their descendants.
1344 // Take for example this layer tree:
1346 // + stacking_context
1347 // + scroll_child (1)
1348 // + scroll_parent_graphics_layer (*)
1349 // | + scroll_parent_scrolling_layer
1350 // | + scroll_parent_scrolling_content_layer (2)
1351 // + scroll_grandparent_graphics_layer (**)
1352 // + scroll_grandparent_scrolling_layer
1353 // + scroll_grandparent_scrolling_content_layer (3)
1355 // The scroll child is (1), its scroll parent is (2) and its scroll
1356 // grandparent is (3). Note, this doesn't mean that (2)'s scroll parent is
1357 // (3), it means that (*)'s scroll parent is (3). We don't want our list to
1358 // look like [ (3), (2), (1) ], even though that does have the ancestor chain
1359 // in the right order. Instead, we want [ (**), (*), (1) ]. That is, only want
1360 // (1)'s siblings in the list, but we want them to appear in such an order
1361 // that the scroll ancestors get visited in the correct order.
1363 // So our first task at this step of the recursion is to determine the layer
1364 // that we will potentionally add to the list. That is, the child of parent
1365 // containing |layer|.
1366 LayerType
* child
= GetChildContainingLayer(parent
, layer
);
1367 if (child
->draw_properties().sorted_for_recursion
)
1370 if (LayerType
* scroll_parent
= child
->scroll_parent())
1371 AddScrollParentChain(out
, parent
, scroll_parent
);
1373 out
->push_back(child
);
1374 child
->draw_properties().sorted_for_recursion
= true;
1377 template <typename LayerType
>
1378 static bool SortChildrenForRecursion(std::vector
<LayerType
*>* out
,
1379 const LayerType
& parent
) {
1380 out
->reserve(parent
.children().size());
1381 bool order_changed
= false;
1382 for (size_t i
= 0; i
< parent
.children().size(); ++i
) {
1383 LayerType
* current
=
1384 LayerTreeHostCommon::get_layer_as_raw_ptr(parent
.children(), i
);
1386 if (current
->draw_properties().sorted_for_recursion
) {
1387 order_changed
= true;
1391 AddScrollParentChain(out
, parent
, current
);
1394 DCHECK_EQ(parent
.children().size(), out
->size());
1395 return order_changed
;
1398 template <typename LayerType
>
1399 static void GetNewDescendantsStartIndexAndCount(LayerType
* layer
,
1400 size_t* start_index
,
1402 *start_index
= layer
->draw_properties().index_of_first_descendants_addition
;
1403 *count
= layer
->draw_properties().num_descendants_added
;
1406 template <typename LayerType
>
1407 static void GetNewRenderSurfacesStartIndexAndCount(LayerType
* layer
,
1408 size_t* start_index
,
1410 *start_index
= layer
->draw_properties()
1411 .index_of_first_render_surface_layer_list_addition
;
1412 *count
= layer
->draw_properties().num_render_surfaces_added
;
1415 // We need to extract a list from the the two flavors of RenderSurfaceListType
1416 // for use in the sorting function below.
1417 static LayerList
* GetLayerListForSorting(RenderSurfaceLayerList
* rsll
) {
1418 return &rsll
->AsLayerList();
1421 static LayerImplList
* GetLayerListForSorting(LayerImplList
* layer_list
) {
1425 template <typename LayerType
, typename GetIndexAndCountType
>
1426 static void SortLayerListContributions(
1427 const LayerType
& parent
,
1428 typename
LayerType::LayerListType
* unsorted
,
1429 size_t start_index_for_all_contributions
,
1430 GetIndexAndCountType get_index_and_count
) {
1431 typename
LayerType::LayerListType buffer
;
1432 for (size_t i
= 0; i
< parent
.children().size(); ++i
) {
1434 LayerTreeHostCommon::get_layer_as_raw_ptr(parent
.children(), i
);
1436 size_t start_index
= 0;
1438 get_index_and_count(child
, &start_index
, &count
);
1439 for (size_t j
= start_index
; j
< start_index
+ count
; ++j
)
1440 buffer
.push_back(unsorted
->at(j
));
1443 DCHECK_EQ(buffer
.size(),
1444 unsorted
->size() - start_index_for_all_contributions
);
1446 for (size_t i
= 0; i
< buffer
.size(); ++i
)
1447 (*unsorted
)[i
+ start_index_for_all_contributions
] = buffer
[i
];
1450 // Recursively walks the layer tree starting at the given node and computes all
1451 // the necessary transformations, clip rects, render surfaces, etc.
1452 template <typename LayerType
>
1453 static void CalculateDrawPropertiesInternal(
1455 const SubtreeGlobals
<LayerType
>& globals
,
1456 const DataForRecursion
<LayerType
>& data_from_ancestor
,
1457 typename
LayerType::RenderSurfaceListType
* render_surface_layer_list
,
1458 typename
LayerType::LayerListType
* layer_list
,
1459 std::vector
<AccumulatedSurfaceState
<LayerType
> >* accumulated_surface_state
,
1460 int current_render_surface_layer_list_id
) {
1461 // This function computes the new matrix transformations recursively for this
1462 // layer and all its descendants. It also computes the appropriate render
1464 // Some important points to remember:
1466 // 0. Here, transforms are notated in Matrix x Vector order, and in words we
1467 // describe what the transform does from left to right.
1469 // 1. In our terminology, the "layer origin" refers to the top-left corner of
1470 // a layer, and the positive Y-axis points downwards. This interpretation is
1471 // valid because the orthographic projection applied at draw time flips the Y
1472 // axis appropriately.
1474 // 2. The anchor point, when given as a PointF object, is specified in "unit
1475 // layer space", where the bounds of the layer map to [0, 1]. However, as a
1476 // Transform object, the transform to the anchor point is specified in "layer
1477 // space", where the bounds of the layer map to [bounds.width(),
1478 // bounds.height()].
1480 // 3. Definition of various transforms used:
1481 // M[parent] is the parent matrix, with respect to the nearest render
1482 // surface, passed down recursively.
1484 // M[root] is the full hierarchy, with respect to the root, passed down
1487 // Tr[origin] is the translation matrix from the parent's origin to
1488 // this layer's origin.
1490 // Tr[origin2anchor] is the translation from the layer's origin to its
1493 // Tr[origin2center] is the translation from the layer's origin to its
1496 // M[layer] is the layer's matrix (applied at the anchor point)
1498 // S[layer2content] is the ratio of a layer's content_bounds() to its
1501 // Some composite transforms can help in understanding the sequence of
1503 // composite_layer_transform = Tr[origin2anchor] * M[layer] *
1504 // Tr[origin2anchor].inverse()
1506 // 4. When a layer (or render surface) is drawn, it is drawn into a "target
1507 // render surface". Therefore the draw transform does not necessarily
1508 // transform from screen space to local layer space. Instead, the draw
1509 // transform is the transform between the "target render surface space" and
1510 // local layer space. Note that render surfaces, except for the root, also
1511 // draw themselves into a different target render surface, and so their draw
1512 // transform and origin transforms are also described with respect to the
1515 // Using these definitions, then:
1517 // The draw transform for the layer is:
1518 // M[draw] = M[parent] * Tr[origin] * composite_layer_transform *
1519 // S[layer2content] = M[parent] * Tr[layer->position() + anchor] *
1520 // M[layer] * Tr[anchor2origin] * S[layer2content]
1522 // Interpreting the math left-to-right, this transforms from the
1523 // layer's render surface to the origin of the layer in content space.
1525 // The screen space transform is:
1526 // M[screenspace] = M[root] * Tr[origin] * composite_layer_transform *
1528 // = M[root] * Tr[layer->position() + anchor] * M[layer]
1529 // * Tr[anchor2origin] * S[layer2content]
1531 // Interpreting the math left-to-right, this transforms from the root
1532 // render surface's content space to the origin of the layer in content
1535 // The transform hierarchy that is passed on to children (i.e. the child's
1536 // parent_matrix) is:
1537 // M[parent]_for_child = M[parent] * Tr[origin] *
1538 // composite_layer_transform
1539 // = M[parent] * Tr[layer->position() + anchor] *
1540 // M[layer] * Tr[anchor2origin]
1542 // and a similar matrix for the full hierarchy with respect to the
1545 // Finally, note that the final matrix used by the shader for the layer is P *
1546 // M[draw] * S . This final product is computed in drawTexturedQuad(), where:
1547 // P is the projection matrix
1548 // S is the scale adjustment (to scale up a canonical quad to the
1551 // When a render surface has a replica layer, that layer's transform is used
1552 // to draw a second copy of the surface. gfx::Transforms named here are
1553 // relative to the surface, unless they specify they are relative to the
1556 // We will denote a scale by device scale S[deviceScale]
1558 // The render surface draw transform to its target surface origin is:
1559 // M[surfaceDraw] = M[owningLayer->Draw]
1561 // The render surface origin transform to its the root (screen space) origin
1563 // M[surface2root] = M[owningLayer->screenspace] *
1564 // S[deviceScale].inverse()
1566 // The replica draw transform to its target surface origin is:
1567 // M[replicaDraw] = S[deviceScale] * M[surfaceDraw] *
1568 // Tr[replica->position() + replica->anchor()] * Tr[replica] *
1569 // Tr[origin2anchor].inverse() * S[contents_scale].inverse()
1571 // The replica draw transform to the root (screen space) origin is:
1572 // M[replica2root] = M[surface2root] * Tr[replica->position()] *
1573 // Tr[replica] * Tr[origin2anchor].inverse()
1576 // It makes no sense to have a non-unit page_scale_factor without specifying
1577 // which layer roots the subtree the scale is applied to.
1578 DCHECK(globals
.page_scale_application_layer
||
1579 (globals
.page_scale_factor
== 1.f
));
1581 DataForRecursion
<LayerType
> data_for_children
;
1582 typename
LayerType::RenderSurfaceType
*
1583 nearest_occlusion_immune_ancestor_surface
=
1584 data_from_ancestor
.nearest_occlusion_immune_ancestor_surface
;
1585 data_for_children
.in_subtree_of_page_scale_application_layer
=
1586 data_from_ancestor
.in_subtree_of_page_scale_application_layer
;
1587 data_for_children
.subtree_can_use_lcd_text
=
1588 data_from_ancestor
.subtree_can_use_lcd_text
;
1590 // Layers that are marked as hidden will hide themselves and their subtree.
1591 // Exception: Layers with copy requests, whether hidden or not, must be drawn
1592 // anyway. In this case, we will inform their subtree they are visible to get
1593 // the right results.
1594 const bool layer_is_visible
=
1595 data_from_ancestor
.subtree_is_visible_from_ancestor
&&
1596 !layer
->hide_layer_and_subtree();
1597 const bool layer_is_drawn
= layer_is_visible
|| layer
->HasCopyRequest();
1599 // The root layer cannot skip CalcDrawProperties.
1600 if (!IsRootLayer(layer
) && SubtreeShouldBeSkipped(layer
, layer_is_drawn
)) {
1601 if (layer
->render_surface())
1602 layer
->ClearRenderSurfaceLayerList();
1606 // We need to circumvent the normal recursive flow of information for clip
1607 // children (they don't inherit their direct ancestor's clip information).
1608 // This is unfortunate, and would be unnecessary if we were to formally
1609 // separate the clipping hierarchy from the layer hierarchy.
1610 bool ancestor_clips_subtree
= data_from_ancestor
.ancestor_clips_subtree
;
1611 gfx::Rect ancestor_clip_rect_in_target_space
=
1612 data_from_ancestor
.clip_rect_in_target_space
;
1614 // Update our clipping state. If we have a clip parent we will need to pull
1615 // from the clip state cache rather than using the clip state passed from our
1616 // immediate ancestor.
1617 UpdateClipRectsForClipChild
<LayerType
>(
1618 layer
, &ancestor_clip_rect_in_target_space
, &ancestor_clips_subtree
);
1620 // As this function proceeds, these are the properties for the current
1621 // layer that actually get computed. To avoid unnecessary copies
1622 // (particularly for matrices), we do computations directly on these values
1624 DrawProperties
<LayerType
>& layer_draw_properties
= layer
->draw_properties();
1626 gfx::Rect clip_rect_in_target_space
;
1627 bool layer_or_ancestor_clips_descendants
= false;
1629 // This value is cached on the stack so that we don't have to inverse-project
1630 // the surface's clip rect redundantly for every layer. This value is the
1631 // same as the target surface's clip rect, except that instead of being
1632 // described in the target surface's target's space, it is described in the
1633 // current render target's space.
1634 gfx::Rect clip_rect_of_target_surface_in_target_space
;
1636 float accumulated_draw_opacity
= layer
->opacity();
1637 bool animating_opacity_to_target
= layer
->OpacityIsAnimating();
1638 bool animating_opacity_to_screen
= animating_opacity_to_target
;
1639 if (layer
->parent()) {
1640 accumulated_draw_opacity
*= layer
->parent()->draw_opacity();
1641 animating_opacity_to_target
|= layer
->parent()->draw_opacity_is_animating();
1642 animating_opacity_to_screen
|=
1643 layer
->parent()->screen_space_opacity_is_animating();
1646 bool animating_transform_to_target
= layer
->TransformIsAnimating();
1647 bool animating_transform_to_screen
= animating_transform_to_target
;
1648 if (layer
->parent()) {
1649 animating_transform_to_target
|=
1650 layer
->parent()->draw_transform_is_animating();
1651 animating_transform_to_screen
|=
1652 layer
->parent()->screen_space_transform_is_animating();
1654 gfx::Point3F transform_origin
= layer
->transform_origin();
1655 gfx::Vector2dF scroll_offset
= GetEffectiveTotalScrollOffset(layer
);
1656 gfx::PointF position
= layer
->position() - scroll_offset
;
1657 gfx::Transform combined_transform
= data_from_ancestor
.parent_matrix
;
1658 if (!layer
->transform().IsIdentity()) {
1659 // LT = Tr[origin] * Tr[origin2transformOrigin]
1660 combined_transform
.Translate3d(position
.x() + transform_origin
.x(),
1661 position
.y() + transform_origin
.y(),
1662 transform_origin
.z());
1663 // LT = Tr[origin] * Tr[origin2origin] * M[layer]
1664 combined_transform
.PreconcatTransform(layer
->transform());
1665 // LT = Tr[origin] * Tr[origin2origin] * M[layer] *
1666 // Tr[transformOrigin2origin]
1667 combined_transform
.Translate3d(
1668 -transform_origin
.x(), -transform_origin
.y(), -transform_origin
.z());
1670 combined_transform
.Translate(position
.x(), position
.y());
1673 gfx::Vector2dF effective_scroll_delta
= GetEffectiveScrollDelta(layer
);
1674 if (!animating_transform_to_target
&& layer
->scrollable() &&
1675 combined_transform
.IsScaleOrTranslation()) {
1676 // Align the scrollable layer's position to screen space pixels to avoid
1677 // blurriness. To avoid side-effects, do this only if the transform is
1679 gfx::Vector2dF previous_translation
= combined_transform
.To2dTranslation();
1680 RoundTranslationComponents(&combined_transform
);
1681 gfx::Vector2dF current_translation
= combined_transform
.To2dTranslation();
1683 // This rounding changes the scroll delta, and so must be included
1684 // in the scroll compensation matrix. The scaling converts from physical
1685 // coordinates to the scroll delta's CSS coordinates (using the parent
1686 // matrix instead of combined transform since scrolling is applied before
1687 // the layer's transform). For example, if we have a total scale factor of
1688 // 3.0, then 1 physical pixel is only 1/3 of a CSS pixel.
1689 gfx::Vector2dF parent_scales
= MathUtil::ComputeTransform2dScaleComponents(
1690 data_from_ancestor
.parent_matrix
, 1.f
);
1691 effective_scroll_delta
-=
1692 gfx::ScaleVector2d(current_translation
- previous_translation
,
1693 1.f
/ parent_scales
.x(),
1694 1.f
/ parent_scales
.y());
1697 // Apply adjustment from position constraints.
1698 ApplyPositionAdjustment(layer
, data_from_ancestor
.fixed_container
,
1699 data_from_ancestor
.scroll_compensation_matrix
, &combined_transform
);
1701 bool combined_is_animating_scale
= false;
1702 float combined_maximum_animation_contents_scale
= 0.f
;
1703 if (globals
.can_adjust_raster_scales
) {
1704 CalculateAnimationContentsScale(
1706 data_from_ancestor
.ancestor_is_animating_scale
,
1707 data_from_ancestor
.maximum_animation_contents_scale
,
1708 data_from_ancestor
.parent_matrix
,
1710 &combined_is_animating_scale
,
1711 &combined_maximum_animation_contents_scale
);
1713 data_for_children
.ancestor_is_animating_scale
= combined_is_animating_scale
;
1714 data_for_children
.maximum_animation_contents_scale
=
1715 combined_maximum_animation_contents_scale
;
1717 // Compute the 2d scale components of the transform hierarchy up to the target
1718 // surface. From there, we can decide on a contents scale for the layer.
1719 float layer_scale_factors
= globals
.device_scale_factor
;
1720 if (data_from_ancestor
.in_subtree_of_page_scale_application_layer
)
1721 layer_scale_factors
*= globals
.page_scale_factor
;
1722 gfx::Vector2dF combined_transform_scales
=
1723 MathUtil::ComputeTransform2dScaleComponents(
1725 layer_scale_factors
);
1727 float ideal_contents_scale
=
1728 globals
.can_adjust_raster_scales
1729 ? std::max(combined_transform_scales
.x(),
1730 combined_transform_scales
.y())
1731 : layer_scale_factors
;
1732 UpdateLayerContentsScale(
1734 globals
.can_adjust_raster_scales
,
1735 ideal_contents_scale
,
1736 globals
.device_scale_factor
,
1737 data_from_ancestor
.in_subtree_of_page_scale_application_layer
1738 ? globals
.page_scale_factor
1740 combined_maximum_animation_contents_scale
,
1741 animating_transform_to_screen
);
1743 // The draw_transform that gets computed below is effectively the layer's
1744 // draw_transform, unless the layer itself creates a render_surface. In that
1745 // case, the render_surface re-parents the transforms.
1746 layer_draw_properties
.target_space_transform
= combined_transform
;
1747 // M[draw] = M[parent] * LT * S[layer2content]
1748 layer_draw_properties
.target_space_transform
.Scale(
1749 SK_MScalar1
/ layer
->contents_scale_x(),
1750 SK_MScalar1
/ layer
->contents_scale_y());
1752 // The layer's screen_space_transform represents the transform between root
1753 // layer's "screen space" and local content space.
1754 layer_draw_properties
.screen_space_transform
=
1755 data_from_ancestor
.full_hierarchy_matrix
;
1756 if (layer
->should_flatten_transform())
1757 layer_draw_properties
.screen_space_transform
.FlattenTo2d();
1758 layer_draw_properties
.screen_space_transform
.PreconcatTransform
1759 (layer_draw_properties
.target_space_transform
);
1761 // Adjusting text AA method during animation may cause repaints, which in-turn
1763 bool adjust_text_aa
=
1764 !animating_opacity_to_screen
&& !animating_transform_to_screen
;
1765 // To avoid color fringing, LCD text should only be used on opaque layers with
1766 // just integral translation.
1767 bool layer_can_use_lcd_text
=
1768 data_from_ancestor
.subtree_can_use_lcd_text
&&
1769 accumulated_draw_opacity
== 1.f
&&
1770 layer_draw_properties
.target_space_transform
.
1771 IsIdentityOrIntegerTranslation();
1773 gfx::RectF
content_rect(layer
->content_bounds());
1775 // full_hierarchy_matrix is the matrix that transforms objects between screen
1776 // space (except projection matrix) and the most recent RenderSurfaceImpl's
1777 // space. next_hierarchy_matrix will only change if this layer uses a new
1778 // RenderSurfaceImpl, otherwise remains the same.
1779 data_for_children
.full_hierarchy_matrix
=
1780 data_from_ancestor
.full_hierarchy_matrix
;
1782 // If the subtree will scale layer contents by the transform hierarchy, then
1783 // we should scale things into the render surface by the transform hierarchy
1784 // to take advantage of that.
1785 gfx::Vector2dF render_surface_sublayer_scale
=
1786 globals
.can_adjust_raster_scales
1787 ? combined_transform_scales
1788 : gfx::Vector2dF(layer_scale_factors
, layer_scale_factors
);
1790 bool render_to_separate_surface
;
1791 if (globals
.can_render_to_separate_surface
) {
1792 render_to_separate_surface
= SubtreeShouldRenderToSeparateSurface(
1793 layer
, combined_transform
.Preserves2dAxisAlignment());
1795 render_to_separate_surface
= IsRootLayer(layer
);
1797 if (render_to_separate_surface
) {
1798 // Check back-face visibility before continuing with this surface and its
1800 if (!layer
->double_sided() && TransformToParentIsKnown(layer
) &&
1801 IsSurfaceBackFaceVisible(layer
, combined_transform
)) {
1802 layer
->ClearRenderSurfaceLayerList();
1806 typename
LayerType::RenderSurfaceType
* render_surface
=
1807 CreateOrReuseRenderSurface(layer
);
1809 if (IsRootLayer(layer
)) {
1810 // The root layer's render surface size is predetermined and so the root
1811 // layer can't directly support non-identity transforms. It should just
1812 // forward top-level transforms to the rest of the tree.
1813 data_for_children
.parent_matrix
= combined_transform
;
1815 // The root surface does not contribute to any other surface, it has no
1817 layer
->render_surface()->set_contributes_to_drawn_surface(false);
1819 // The owning layer's draw transform has a scale from content to layer
1820 // space which we do not want; so here we use the combined_transform
1821 // instead of the draw_transform. However, we do need to add a different
1822 // scale factor that accounts for the surface's pixel dimensions.
1823 combined_transform
.Scale(1.0 / render_surface_sublayer_scale
.x(),
1824 1.0 / render_surface_sublayer_scale
.y());
1825 render_surface
->SetDrawTransform(combined_transform
);
1827 // The owning layer's transform was re-parented by the surface, so the
1828 // layer's new draw_transform only needs to scale the layer to surface
1830 layer_draw_properties
.target_space_transform
.MakeIdentity();
1831 layer_draw_properties
.target_space_transform
.
1832 Scale(render_surface_sublayer_scale
.x() / layer
->contents_scale_x(),
1833 render_surface_sublayer_scale
.y() / layer
->contents_scale_y());
1835 // Inside the surface's subtree, we scale everything to the owning layer's
1836 // scale. The sublayer matrix transforms layer rects into target surface
1837 // content space. Conceptually, all layers in the subtree inherit the
1838 // scale at the point of the render surface in the transform hierarchy,
1839 // but we apply it explicitly to the owning layer and the remainder of the
1840 // subtree independently.
1841 DCHECK(data_for_children
.parent_matrix
.IsIdentity());
1842 data_for_children
.parent_matrix
.Scale(render_surface_sublayer_scale
.x(),
1843 render_surface_sublayer_scale
.y());
1845 // Even if the |layer_is_drawn|, it only contributes to a drawn surface
1846 // when the |layer_is_visible|.
1847 layer
->render_surface()->set_contributes_to_drawn_surface(
1851 // The opacity value is moved from the layer to its surface, so that the
1852 // entire subtree properly inherits opacity.
1853 render_surface
->SetDrawOpacity(accumulated_draw_opacity
);
1854 render_surface
->SetDrawOpacityIsAnimating(animating_opacity_to_target
);
1855 animating_opacity_to_target
= false;
1856 layer_draw_properties
.opacity
= 1.f
;
1857 layer_draw_properties
.opacity_is_animating
= animating_opacity_to_target
;
1858 layer_draw_properties
.screen_space_opacity_is_animating
=
1859 animating_opacity_to_screen
;
1861 render_surface
->SetTargetSurfaceTransformsAreAnimating(
1862 animating_transform_to_target
);
1863 render_surface
->SetScreenSpaceTransformsAreAnimating(
1864 animating_transform_to_screen
);
1865 animating_transform_to_target
= false;
1866 layer_draw_properties
.target_space_transform_is_animating
=
1867 animating_transform_to_target
;
1868 layer_draw_properties
.screen_space_transform_is_animating
=
1869 animating_transform_to_screen
;
1871 // Update the aggregate hierarchy matrix to include the transform of the
1872 // newly created RenderSurfaceImpl.
1873 data_for_children
.full_hierarchy_matrix
.PreconcatTransform(
1874 render_surface
->draw_transform());
1876 if (layer
->mask_layer()) {
1877 DrawProperties
<LayerType
>& mask_layer_draw_properties
=
1878 layer
->mask_layer()->draw_properties();
1879 mask_layer_draw_properties
.render_target
= layer
;
1880 mask_layer_draw_properties
.visible_content_rect
=
1881 gfx::Rect(layer
->content_bounds());
1884 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer()) {
1885 DrawProperties
<LayerType
>& replica_mask_draw_properties
=
1886 layer
->replica_layer()->mask_layer()->draw_properties();
1887 replica_mask_draw_properties
.render_target
= layer
;
1888 replica_mask_draw_properties
.visible_content_rect
=
1889 gfx::Rect(layer
->content_bounds());
1892 // Ignore occlusion from outside the surface when surface contents need to
1893 // be fully drawn. Layers with copy-request need to be complete.
1894 // We could be smarter about layers with replica and exclude regions
1895 // where both layer and the replica are occluded, but this seems like an
1896 // overkill. The same is true for layers with filters that move pixels.
1897 // TODO(senorblanco): make this smarter for the SkImageFilter case (check
1898 // for pixel-moving filters)
1899 if (layer
->HasCopyRequest() ||
1900 layer
->has_replica() ||
1901 layer
->filters().HasReferenceFilter() ||
1902 layer
->filters().HasFilterThatMovesPixels()) {
1903 nearest_occlusion_immune_ancestor_surface
= render_surface
;
1905 render_surface
->SetNearestOcclusionImmuneAncestor(
1906 nearest_occlusion_immune_ancestor_surface
);
1908 layer_or_ancestor_clips_descendants
= false;
1909 bool subtree_is_clipped_by_surface_bounds
= false;
1910 if (ancestor_clips_subtree
) {
1911 // It may be the layer or the surface doing the clipping of the subtree,
1912 // but in either case, we'll be clipping to the projected clip rect of our
1914 gfx::Transform
inverse_surface_draw_transform(
1915 gfx::Transform::kSkipInitialization
);
1916 if (!render_surface
->draw_transform().GetInverse(
1917 &inverse_surface_draw_transform
)) {
1918 // TODO(shawnsingh): Either we need to handle uninvertible transforms
1919 // here, or DCHECK that the transform is invertible.
1922 gfx::Rect projected_surface_rect
= MathUtil::ProjectEnclosingClippedRect(
1923 inverse_surface_draw_transform
, ancestor_clip_rect_in_target_space
);
1925 if (layer_draw_properties
.num_unclipped_descendants
> 0) {
1926 // If we have unclipped descendants, we cannot count on the render
1927 // surface's bounds clipping our subtree: the unclipped descendants
1928 // could cause us to expand our bounds. In this case, we must rely on
1929 // layer clipping for correctess. NB: since we can only encounter
1930 // translations between a clip child and its clip parent, clipping is
1931 // guaranteed to be exact in this case.
1932 layer_or_ancestor_clips_descendants
= true;
1933 clip_rect_in_target_space
= projected_surface_rect
;
1935 // The new render_surface here will correctly clip the entire subtree.
1936 // So, we do not need to continue propagating the clipping state further
1937 // down the tree. This way, we can avoid transforming clip rects from
1938 // ancestor target surface space to current target surface space that
1939 // could cause more w < 0 headaches. The render surface clip rect is
1940 // expressed in the space where this surface draws, i.e. the same space
1941 // as clip_rect_from_ancestor_in_ancestor_target_space.
1942 render_surface
->SetClipRect(ancestor_clip_rect_in_target_space
);
1943 clip_rect_of_target_surface_in_target_space
= projected_surface_rect
;
1944 subtree_is_clipped_by_surface_bounds
= true;
1948 DCHECK(layer
->render_surface());
1949 DCHECK(!layer
->parent() || layer
->parent()->render_target() ==
1950 accumulated_surface_state
->back().render_target
);
1952 accumulated_surface_state
->push_back(
1953 AccumulatedSurfaceState
<LayerType
>(layer
));
1955 render_surface
->SetIsClipped(subtree_is_clipped_by_surface_bounds
);
1956 if (!subtree_is_clipped_by_surface_bounds
) {
1957 render_surface
->SetClipRect(gfx::Rect());
1958 clip_rect_of_target_surface_in_target_space
=
1959 data_from_ancestor
.clip_rect_of_target_surface_in_target_space
;
1962 // If the new render surface is drawn translucent or with a non-integral
1963 // translation then the subtree that gets drawn on this render surface
1964 // cannot use LCD text.
1965 data_for_children
.subtree_can_use_lcd_text
= layer_can_use_lcd_text
;
1967 render_surface_layer_list
->push_back(layer
);
1969 DCHECK(layer
->parent());
1971 // Note: layer_draw_properties.target_space_transform is computed above,
1972 // before this if-else statement.
1973 layer_draw_properties
.target_space_transform_is_animating
=
1974 animating_transform_to_target
;
1975 layer_draw_properties
.screen_space_transform_is_animating
=
1976 animating_transform_to_screen
;
1977 layer_draw_properties
.opacity
= accumulated_draw_opacity
;
1978 layer_draw_properties
.opacity_is_animating
= animating_opacity_to_target
;
1979 layer_draw_properties
.screen_space_opacity_is_animating
=
1980 animating_opacity_to_screen
;
1981 data_for_children
.parent_matrix
= combined_transform
;
1983 layer
->ClearRenderSurface();
1985 // Layers without render_surfaces directly inherit the ancestor's clip
1987 layer_or_ancestor_clips_descendants
= ancestor_clips_subtree
;
1988 if (ancestor_clips_subtree
) {
1989 clip_rect_in_target_space
=
1990 ancestor_clip_rect_in_target_space
;
1993 // The surface's cached clip rect value propagates regardless of what
1994 // clipping goes on between layers here.
1995 clip_rect_of_target_surface_in_target_space
=
1996 data_from_ancestor
.clip_rect_of_target_surface_in_target_space
;
1998 // Layers that are not their own render_target will render into the target
1999 // of their nearest ancestor.
2000 layer_draw_properties
.render_target
= layer
->parent()->render_target();
2004 layer_draw_properties
.can_use_lcd_text
= layer_can_use_lcd_text
;
2006 gfx::Rect rect_in_target_space
= ToEnclosingRect(
2007 MathUtil::MapClippedRect(layer
->draw_transform(), content_rect
));
2009 if (LayerClipsSubtree(layer
)) {
2010 layer_or_ancestor_clips_descendants
= true;
2011 if (ancestor_clips_subtree
&& !layer
->render_surface()) {
2012 // A layer without render surface shares the same target as its ancestor.
2013 clip_rect_in_target_space
=
2014 ancestor_clip_rect_in_target_space
;
2015 clip_rect_in_target_space
.Intersect(rect_in_target_space
);
2017 clip_rect_in_target_space
= rect_in_target_space
;
2021 // Tell the layer the rect that it's clipped by. In theory we could use a
2022 // tighter clip rect here (drawable_content_rect), but that actually does not
2023 // reduce how much would be drawn, and instead it would create unnecessary
2024 // changes to scissor state affecting GPU performance. Our clip information
2025 // is used in the recursion below, so we must set it beforehand.
2026 layer_draw_properties
.is_clipped
= layer_or_ancestor_clips_descendants
;
2027 if (layer_or_ancestor_clips_descendants
) {
2028 layer_draw_properties
.clip_rect
= clip_rect_in_target_space
;
2030 // Initialize the clip rect to a safe value that will not clip the
2031 // layer, just in case clipping is still accidentally used.
2032 layer_draw_properties
.clip_rect
= rect_in_target_space
;
2035 typename
LayerType::LayerListType
& descendants
=
2036 (layer
->render_surface() ? layer
->render_surface()->layer_list()
2039 // Any layers that are appended after this point are in the layer's subtree
2040 // and should be included in the sorting process.
2041 size_t sorting_start_index
= descendants
.size();
2043 if (!LayerShouldBeSkipped(layer
, layer_is_drawn
)) {
2044 MarkLayerWithRenderSurfaceLayerListId(layer
,
2045 current_render_surface_layer_list_id
);
2046 descendants
.push_back(layer
);
2049 // Any layers that are appended after this point may need to be sorted if we
2050 // visit the children out of order.
2051 size_t render_surface_layer_list_child_sorting_start_index
=
2052 render_surface_layer_list
->size();
2053 size_t layer_list_child_sorting_start_index
= descendants
.size();
2055 if (!layer
->children().empty()) {
2056 if (layer
== globals
.page_scale_application_layer
) {
2057 data_for_children
.parent_matrix
.Scale(
2058 globals
.page_scale_factor
,
2059 globals
.page_scale_factor
);
2060 data_for_children
.in_subtree_of_page_scale_application_layer
= true;
2063 // Flatten to 2D if the layer doesn't preserve 3D.
2064 if (layer
->should_flatten_transform())
2065 data_for_children
.parent_matrix
.FlattenTo2d();
2067 data_for_children
.scroll_compensation_matrix
=
2068 ComputeScrollCompensationMatrixForChildren(
2070 data_from_ancestor
.parent_matrix
,
2071 data_from_ancestor
.scroll_compensation_matrix
,
2072 effective_scroll_delta
);
2073 data_for_children
.fixed_container
=
2074 layer
->IsContainerForFixedPositionLayers() ?
2075 layer
: data_from_ancestor
.fixed_container
;
2077 data_for_children
.clip_rect_in_target_space
= clip_rect_in_target_space
;
2078 data_for_children
.clip_rect_of_target_surface_in_target_space
=
2079 clip_rect_of_target_surface_in_target_space
;
2080 data_for_children
.ancestor_clips_subtree
=
2081 layer_or_ancestor_clips_descendants
;
2082 data_for_children
.nearest_occlusion_immune_ancestor_surface
=
2083 nearest_occlusion_immune_ancestor_surface
;
2084 data_for_children
.subtree_is_visible_from_ancestor
= layer_is_drawn
;
2087 std::vector
<LayerType
*> sorted_children
;
2088 bool child_order_changed
= false;
2089 if (layer_draw_properties
.has_child_with_a_scroll_parent
)
2090 child_order_changed
= SortChildrenForRecursion(&sorted_children
, *layer
);
2092 for (size_t i
= 0; i
< layer
->children().size(); ++i
) {
2093 // If one of layer's children has a scroll parent, then we may have to
2094 // visit the children out of order. The new order is stored in
2095 // sorted_children. Otherwise, we'll grab the child directly from the
2096 // layer's list of children.
2098 layer_draw_properties
.has_child_with_a_scroll_parent
2099 ? sorted_children
[i
]
2100 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer
->children(), i
);
2102 child
->draw_properties().index_of_first_descendants_addition
=
2104 child
->draw_properties().index_of_first_render_surface_layer_list_addition
=
2105 render_surface_layer_list
->size();
2107 CalculateDrawPropertiesInternal
<LayerType
>(
2111 render_surface_layer_list
,
2113 accumulated_surface_state
,
2114 current_render_surface_layer_list_id
);
2115 if (child
->render_surface() &&
2116 !child
->render_surface()->layer_list().empty() &&
2117 !child
->render_surface()->content_rect().IsEmpty()) {
2118 // This child will contribute its render surface, which means
2119 // we need to mark just the mask layer (and replica mask layer)
2121 MarkMasksWithRenderSurfaceLayerListId(
2122 child
, current_render_surface_layer_list_id
);
2123 descendants
.push_back(child
);
2126 child
->draw_properties().num_descendants_added
=
2127 descendants
.size() -
2128 child
->draw_properties().index_of_first_descendants_addition
;
2129 child
->draw_properties().num_render_surfaces_added
=
2130 render_surface_layer_list
->size() -
2131 child
->draw_properties()
2132 .index_of_first_render_surface_layer_list_addition
;
2135 // Add the unsorted layer list contributions, if necessary.
2136 if (child_order_changed
) {
2137 SortLayerListContributions(
2139 GetLayerListForSorting(render_surface_layer_list
),
2140 render_surface_layer_list_child_sorting_start_index
,
2141 &GetNewRenderSurfacesStartIndexAndCount
<LayerType
>);
2143 SortLayerListContributions(
2146 layer_list_child_sorting_start_index
,
2147 &GetNewDescendantsStartIndexAndCount
<LayerType
>);
2150 // Compute the total drawable_content_rect for this subtree (the rect is in
2151 // target surface space).
2152 gfx::Rect local_drawable_content_rect_of_subtree
=
2153 accumulated_surface_state
->back().drawable_content_rect
;
2154 if (layer
->render_surface()) {
2155 DCHECK(accumulated_surface_state
->back().render_target
== layer
);
2156 accumulated_surface_state
->pop_back();
2159 if (layer
->render_surface() && !IsRootLayer(layer
) &&
2160 layer
->render_surface()->layer_list().empty()) {
2161 RemoveSurfaceForEarlyExit(layer
, render_surface_layer_list
);
2165 // Compute the layer's drawable content rect (the rect is in target surface
2167 layer_draw_properties
.drawable_content_rect
= rect_in_target_space
;
2168 if (layer_or_ancestor_clips_descendants
) {
2169 layer_draw_properties
.drawable_content_rect
.Intersect(
2170 clip_rect_in_target_space
);
2172 if (layer
->DrawsContent()) {
2173 local_drawable_content_rect_of_subtree
.Union(
2174 layer_draw_properties
.drawable_content_rect
);
2177 // Compute the layer's visible content rect (the rect is in content space).
2178 layer_draw_properties
.visible_content_rect
= CalculateVisibleContentRect(
2179 layer
, clip_rect_of_target_surface_in_target_space
, rect_in_target_space
);
2181 // Compute the remaining properties for the render surface, if the layer has
2183 if (IsRootLayer(layer
)) {
2184 // The root layer's surface's content_rect is always the entire viewport.
2185 DCHECK(layer
->render_surface());
2186 layer
->render_surface()->SetContentRect(
2187 ancestor_clip_rect_in_target_space
);
2188 } else if (layer
->render_surface()) {
2189 typename
LayerType::RenderSurfaceType
* render_surface
=
2190 layer
->render_surface();
2191 gfx::Rect clipped_content_rect
= local_drawable_content_rect_of_subtree
;
2193 // Don't clip if the layer is reflected as the reflection shouldn't be
2194 // clipped. If the layer is animating, then the surface's transform to
2195 // its target is not known on the main thread, and we should not use it
2197 if (!layer
->replica_layer() && TransformToParentIsKnown(layer
)) {
2198 // Note, it is correct to use data_from_ancestor.ancestor_clips_subtree
2199 // here, because we are looking at this layer's render_surface, not the
2201 if (render_surface
->is_clipped() && !clipped_content_rect
.IsEmpty()) {
2202 gfx::Rect surface_clip_rect
= LayerTreeHostCommon::CalculateVisibleRect(
2203 render_surface
->clip_rect(),
2204 clipped_content_rect
,
2205 render_surface
->draw_transform());
2206 clipped_content_rect
.Intersect(surface_clip_rect
);
2210 // The RenderSurfaceImpl backing texture cannot exceed the maximum supported
2212 clipped_content_rect
.set_width(
2213 std::min(clipped_content_rect
.width(), globals
.max_texture_size
));
2214 clipped_content_rect
.set_height(
2215 std::min(clipped_content_rect
.height(), globals
.max_texture_size
));
2217 if (clipped_content_rect
.IsEmpty()) {
2218 RemoveSurfaceForEarlyExit(layer
, render_surface_layer_list
);
2222 // Layers having a non-default blend mode will blend with the content
2223 // inside its parent's render target. This render target should be
2224 // either root_for_isolated_group, or the root of the layer tree.
2225 // Otherwise, this layer will use an incomplete backdrop, limited to its
2226 // render target and the blending result will be incorrect.
2227 DCHECK(layer
->uses_default_blend_mode() || IsRootLayer(layer
) ||
2228 !layer
->parent()->render_target() ||
2229 IsRootLayer(layer
->parent()->render_target()) ||
2230 layer
->parent()->render_target()->is_root_for_isolated_group());
2232 render_surface
->SetContentRect(clipped_content_rect
);
2234 // The owning layer's screen_space_transform has a scale from content to
2235 // layer space which we need to undo and replace with a scale from the
2236 // surface's subtree into layer space.
2237 gfx::Transform screen_space_transform
= layer
->screen_space_transform();
2238 screen_space_transform
.Scale(
2239 layer
->contents_scale_x() / render_surface_sublayer_scale
.x(),
2240 layer
->contents_scale_y() / render_surface_sublayer_scale
.y());
2241 render_surface
->SetScreenSpaceTransform(screen_space_transform
);
2243 if (layer
->replica_layer()) {
2244 gfx::Transform surface_origin_to_replica_origin_transform
;
2245 surface_origin_to_replica_origin_transform
.Scale(
2246 render_surface_sublayer_scale
.x(), render_surface_sublayer_scale
.y());
2247 surface_origin_to_replica_origin_transform
.Translate(
2248 layer
->replica_layer()->position().x() +
2249 layer
->replica_layer()->transform_origin().x(),
2250 layer
->replica_layer()->position().y() +
2251 layer
->replica_layer()->transform_origin().y());
2252 surface_origin_to_replica_origin_transform
.PreconcatTransform(
2253 layer
->replica_layer()->transform());
2254 surface_origin_to_replica_origin_transform
.Translate(
2255 -layer
->replica_layer()->transform_origin().x(),
2256 -layer
->replica_layer()->transform_origin().y());
2257 surface_origin_to_replica_origin_transform
.Scale(
2258 1.0 / render_surface_sublayer_scale
.x(),
2259 1.0 / render_surface_sublayer_scale
.y());
2261 // Compute the replica's "originTransform" that maps from the replica's
2262 // origin space to the target surface origin space.
2263 gfx::Transform replica_origin_transform
=
2264 layer
->render_surface()->draw_transform() *
2265 surface_origin_to_replica_origin_transform
;
2266 render_surface
->SetReplicaDrawTransform(replica_origin_transform
);
2268 // Compute the replica's "screen_space_transform" that maps from the
2269 // replica's origin space to the screen's origin space.
2270 gfx::Transform replica_screen_space_transform
=
2271 layer
->render_surface()->screen_space_transform() *
2272 surface_origin_to_replica_origin_transform
;
2273 render_surface
->SetReplicaScreenSpaceTransform(
2274 replica_screen_space_transform
);
2278 SavePaintPropertiesLayer(layer
);
2280 // If neither this layer nor any of its children were added, early out.
2281 if (sorting_start_index
== descendants
.size()) {
2282 DCHECK(!layer
->render_surface() || IsRootLayer(layer
));
2286 // If preserves-3d then sort all the descendants in 3D so that they can be
2287 // drawn from back to front. If the preserves-3d property is also set on the
2288 // parent then skip the sorting as the parent will sort all the descendants
2290 if (globals
.layer_sorter
&& descendants
.size() && layer
->is_3d_sorted() &&
2291 !LayerIsInExisting3DRenderingContext(layer
)) {
2292 SortLayers(descendants
.begin() + sorting_start_index
,
2294 globals
.layer_sorter
);
2297 UpdateAccumulatedSurfaceState
<LayerType
>(
2298 layer
, local_drawable_content_rect_of_subtree
, accumulated_surface_state
);
2300 if (layer
->HasContributingDelegatedRenderPasses()) {
2301 layer
->render_target()->render_surface()->
2302 AddContributingDelegatedRenderPassLayer(layer
);
2306 template <typename LayerType
, typename RenderSurfaceLayerListType
>
2307 static void ProcessCalcDrawPropsInputs(
2308 const LayerTreeHostCommon::CalcDrawPropsInputs
<LayerType
,
2309 RenderSurfaceLayerListType
>&
2311 SubtreeGlobals
<LayerType
>* globals
,
2312 DataForRecursion
<LayerType
>* data_for_recursion
) {
2313 DCHECK(inputs
.root_layer
);
2314 DCHECK(IsRootLayer(inputs
.root_layer
));
2315 DCHECK(inputs
.render_surface_layer_list
);
2317 gfx::Transform identity_matrix
;
2319 // The root layer's render_surface should receive the device viewport as the
2320 // initial clip rect.
2321 gfx::Rect
device_viewport_rect(inputs
.device_viewport_size
);
2323 gfx::Vector2dF device_transform_scale_components
=
2324 MathUtil::ComputeTransform2dScaleComponents(inputs
.device_transform
, 1.f
);
2325 // Not handling the rare case of different x and y device scale.
2326 float device_transform_scale
=
2327 std::max(device_transform_scale_components
.x(),
2328 device_transform_scale_components
.y());
2330 gfx::Transform scaled_device_transform
= inputs
.device_transform
;
2331 scaled_device_transform
.Scale(inputs
.device_scale_factor
,
2332 inputs
.device_scale_factor
);
2334 globals
->layer_sorter
= NULL
;
2335 globals
->max_texture_size
= inputs
.max_texture_size
;
2336 globals
->device_scale_factor
=
2337 inputs
.device_scale_factor
* device_transform_scale
;
2338 globals
->page_scale_factor
= inputs
.page_scale_factor
;
2339 globals
->page_scale_application_layer
= inputs
.page_scale_application_layer
;
2340 globals
->can_render_to_separate_surface
=
2341 inputs
.can_render_to_separate_surface
;
2342 globals
->can_adjust_raster_scales
= inputs
.can_adjust_raster_scales
;
2344 data_for_recursion
->parent_matrix
= scaled_device_transform
;
2345 data_for_recursion
->full_hierarchy_matrix
= identity_matrix
;
2346 data_for_recursion
->scroll_compensation_matrix
= identity_matrix
;
2347 data_for_recursion
->fixed_container
= inputs
.root_layer
;
2348 data_for_recursion
->clip_rect_in_target_space
= device_viewport_rect
;
2349 data_for_recursion
->clip_rect_of_target_surface_in_target_space
=
2350 device_viewport_rect
;
2351 data_for_recursion
->maximum_animation_contents_scale
= 0.f
;
2352 data_for_recursion
->ancestor_is_animating_scale
= false;
2353 data_for_recursion
->ancestor_clips_subtree
= true;
2354 data_for_recursion
->nearest_occlusion_immune_ancestor_surface
= NULL
;
2355 data_for_recursion
->in_subtree_of_page_scale_application_layer
= false;
2356 data_for_recursion
->subtree_can_use_lcd_text
= inputs
.can_use_lcd_text
;
2357 data_for_recursion
->subtree_is_visible_from_ancestor
= true;
2360 void LayerTreeHostCommon::CalculateDrawProperties(
2361 CalcDrawPropsMainInputs
* inputs
) {
2362 LayerList dummy_layer_list
;
2363 SubtreeGlobals
<Layer
> globals
;
2364 DataForRecursion
<Layer
> data_for_recursion
;
2365 ProcessCalcDrawPropsInputs(*inputs
, &globals
, &data_for_recursion
);
2367 PreCalculateMetaInformationRecursiveData recursive_data
;
2368 PreCalculateMetaInformation(inputs
->root_layer
, &recursive_data
);
2369 std::vector
<AccumulatedSurfaceState
<Layer
> > accumulated_surface_state
;
2370 CalculateDrawPropertiesInternal
<Layer
>(
2374 inputs
->render_surface_layer_list
,
2376 &accumulated_surface_state
,
2377 inputs
->current_render_surface_layer_list_id
);
2379 // The dummy layer list should not have been used.
2380 DCHECK_EQ(0u, dummy_layer_list
.size());
2381 // A root layer render_surface should always exist after
2382 // CalculateDrawProperties.
2383 DCHECK(inputs
->root_layer
->render_surface());
2386 void LayerTreeHostCommon::CalculateDrawProperties(
2387 CalcDrawPropsImplInputs
* inputs
) {
2388 LayerImplList dummy_layer_list
;
2389 SubtreeGlobals
<LayerImpl
> globals
;
2390 DataForRecursion
<LayerImpl
> data_for_recursion
;
2391 ProcessCalcDrawPropsInputs(*inputs
, &globals
, &data_for_recursion
);
2393 LayerSorter layer_sorter
;
2394 globals
.layer_sorter
= &layer_sorter
;
2396 PreCalculateMetaInformationRecursiveData recursive_data
;
2397 PreCalculateMetaInformation(inputs
->root_layer
, &recursive_data
);
2398 std::vector
<AccumulatedSurfaceState
<LayerImpl
> >
2399 accumulated_surface_state
;
2400 CalculateDrawPropertiesInternal
<LayerImpl
>(
2404 inputs
->render_surface_layer_list
,
2406 &accumulated_surface_state
,
2407 inputs
->current_render_surface_layer_list_id
);
2409 // The dummy layer list should not have been used.
2410 DCHECK_EQ(0u, dummy_layer_list
.size());
2411 // A root layer render_surface should always exist after
2412 // CalculateDrawProperties.
2413 DCHECK(inputs
->root_layer
->render_surface());