Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: cc/layer_tree_host_common.cc

Issue 11017044: Remove root layer specialness in calculateDrawTransforms (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added assertion that rounding does not affect exact coverage testing Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "cc/layer_tree_host_common.h" 7 #include "cc/layer_tree_host_common.h"
8 8
9 #include "FloatQuad.h" 9 #include "FloatQuad.h"
10 #include "IntRect.h" 10 #include "IntRect.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // Project the corners of the target surface rect into the layer space. 46 // Project the corners of the target surface rect into the layer space.
47 // This bounding rectangle may be larger than it needs to be (being 47 // This bounding rectangle may be larger than it needs to be (being
48 // axis-aligned), but is a reasonable filter on the space to consider. 48 // axis-aligned), but is a reasonable filter on the space to consider.
49 // Non-invertible transforms will create an empty rect here. 49 // Non-invertible transforms will create an empty rect here.
50 const WebTransformationMatrix surfaceToLayer = transform.inverse(); 50 const WebTransformationMatrix surfaceToLayer = transform.inverse();
51 IntRect layerRect = enclosingIntRect(MathUtil::projectClippedRect(surfaceToL ayer, FloatRect(minimalSurfaceRect))); 51 IntRect layerRect = enclosingIntRect(MathUtil::projectClippedRect(surfaceToL ayer, FloatRect(minimalSurfaceRect)));
52 layerRect.intersect(layerBoundRect); 52 layerRect.intersect(layerBoundRect);
53 return layerRect; 53 return layerRect;
54 } 54 }
55 55
56 template <typename LayerType>
57 static inline bool isRootLayer(LayerType* layer)
58 {
59 return !layer->parent();
60 }
61
56 template<typename LayerType> 62 template<typename LayerType>
57 static inline bool layerIsInExisting3DRenderingContext(LayerType* layer) 63 static inline bool layerIsInExisting3DRenderingContext(LayerType* layer)
58 { 64 {
59 // According to current W3C spec on CSS transforms, a layer is part of an es tablished 65 // According to current W3C spec on CSS transforms, a layer is part of an es tablished
60 // 3d rendering context if its parent has transform-style of preserves-3d. 66 // 3d rendering context if its parent has transform-style of preserves-3d.
61 return layer->parent() && layer->parent()->preserves3D(); 67 return layer->parent() && layer->parent()->preserves3D();
62 } 68 }
63 69
64 template<typename LayerType> 70 template<typename LayerType>
65 static bool layerIsRootOfNewRenderingContext(LayerType* layer) 71 static bool isRootLayerOfNewRenderingContext(LayerType* layer)
66 { 72 {
67 // According to current W3C spec on CSS transforms (Section 6.1), a layer is the 73 // According to current W3C spec on CSS transforms (Section 6.1), a layer is the
68 // beginning of 3d rendering context if its parent does not have transform-s tyle: 74 // beginning of 3d rendering context if its parent does not have transform-s tyle:
69 // preserve-3d, but this layer itself does. 75 // preserve-3d, but this layer itself does.
70 if (layer->parent()) 76 if (layer->parent())
71 return !layer->parent()->preserves3D() && layer->preserves3D(); 77 return !layer->parent()->preserves3D() && layer->preserves3D();
72 78
73 return layer->preserves3D(); 79 return layer->preserves3D();
74 } 80 }
75 81
(...skipping 12 matching lines...) Expand all
88 // a 3d rendering context at all. 94 // a 3d rendering context at all.
89 return layer->transform().isBackFaceVisible(); 95 return layer->transform().isBackFaceVisible();
90 } 96 }
91 97
92 template<typename LayerType> 98 template<typename LayerType>
93 static bool isSurfaceBackFaceVisible(LayerType* layer, const WebTransformationMa trix& drawTransform) 99 static bool isSurfaceBackFaceVisible(LayerType* layer, const WebTransformationMa trix& drawTransform)
94 { 100 {
95 if (layerIsInExisting3DRenderingContext(layer)) 101 if (layerIsInExisting3DRenderingContext(layer))
96 return drawTransform.isBackFaceVisible(); 102 return drawTransform.isBackFaceVisible();
97 103
98 if (layerIsRootOfNewRenderingContext(layer)) 104 if (isRootLayerOfNewRenderingContext(layer))
99 return layer->transform().isBackFaceVisible(); 105 return layer->transform().isBackFaceVisible();
100 106
101 // If the renderSurface is not part of a new or existing rendering context, then the 107 // If the renderSurface is not part of a new or existing rendering context, then the
102 // layers that contribute to this surface will decide back-face visibility f or themselves. 108 // layers that contribute to this surface will decide back-face visibility f or themselves.
103 return false; 109 return false;
104 } 110 }
105 111
106 template<typename LayerType> 112 template<typename LayerType>
107 static inline bool layerClipsSubtree(LayerType* layer) 113 static inline bool layerClipsSubtree(LayerType* layer)
108 { 114 {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 { 217 {
212 // If the opacity is being animated then the opacity on the main thread is u nreliable 218 // If the opacity is being animated then the opacity on the main thread is u nreliable
213 // (since the impl thread may be using a different opacity), so it should no t be trusted. 219 // (since the impl thread may be using a different opacity), so it should no t be trusted.
214 // In particular, it should not cause the subtree to be skipped. 220 // In particular, it should not cause the subtree to be skipped.
215 return !layer->opacity() && !layer->opacityIsAnimating(); 221 return !layer->opacity() && !layer->opacityIsAnimating();
216 } 222 }
217 223
218 template<typename LayerType> 224 template<typename LayerType>
219 static bool subtreeShouldRenderToSeparateSurface(LayerType* layer, bool axisAlig nedWithRespectToParent) 225 static bool subtreeShouldRenderToSeparateSurface(LayerType* layer, bool axisAlig nedWithRespectToParent)
220 { 226 {
221 // The root layer has a special render surface that is set up externally, so
222 // it shouldn't be treated as a surface in this code.
223 if (!layer->parent())
224 return false;
225
226 // Cache this value, because otherwise it walks the entire subtree several t imes.
227 bool descendantDrawsContent = layer->descendantDrawsContent();
228
229 // 227 //
230 // A layer and its descendants should render onto a new RenderSurfaceImpl if any of these rules hold: 228 // A layer and its descendants should render onto a new RenderSurfaceImpl if any of these rules hold:
231 // 229 //
232 230
231 // The root layer should always have a renderSurface.
232 if (isRootLayer(layer))
233 return true;
234
233 // If we force it. 235 // If we force it.
234 if (layer->forceRenderSurface()) 236 if (layer->forceRenderSurface())
235 return true; 237 return true;
236 238
237 // If the layer uses a mask. 239 // If the layer uses a mask.
238 if (layer->maskLayer()) 240 if (layer->maskLayer())
239 return true; 241 return true;
240 242
241 // If the layer has a reflection. 243 // If the layer has a reflection.
242 if (layer->replicaLayer()) 244 if (layer->replicaLayer())
243 return true; 245 return true;
244 246
245 // If the layer uses a CSS filter. 247 // If the layer uses a CSS filter.
246 if (!layer->filters().isEmpty() || !layer->backgroundFilters().isEmpty() || layer->filter()) 248 if (!layer->filters().isEmpty() || !layer->backgroundFilters().isEmpty() || layer->filter())
247 return true; 249 return true;
248 250
251 // Cache this value, because otherwise it walks the entire subtree several t imes.
252 bool descendantDrawsContent = layer->descendantDrawsContent();
253
249 // If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), b ut it is 254 // If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), b ut it is
250 // treated as a 3D object by its parent (i.e. parent does preserve-3d). 255 // treated as a 3D object by its parent (i.e. parent does preserve-3d).
251 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && d escendantDrawsContent) 256 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && d escendantDrawsContent)
252 return true; 257 return true;
253 258
254 // If the layer clips its descendants but it is not axis-aligned with respec t to its parent. 259 // If the layer clips its descendants but it is not axis-aligned with respec t to its parent.
255 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && descendan tDrawsContent) 260 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && descendan tDrawsContent)
256 return true; 261 return true;
257 262
258 // If the layer has opacity != 1 and does not have a preserves-3d transform style. 263 // If the layer has opacity != 1 and does not have a preserves-3d transform style.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 WebTransformationMatrix computeScrollCompensationMatrixForChildren(LayerImpl* la yer, const WebTransformationMatrix& parentMatrix, const WebTransformationMatrix& currentScrollCompensationMatrix) 305 WebTransformationMatrix computeScrollCompensationMatrixForChildren(LayerImpl* la yer, const WebTransformationMatrix& parentMatrix, const WebTransformationMatrix& currentScrollCompensationMatrix)
301 { 306 {
302 // "Total scroll compensation" is the transform needed to cancel out all scr ollDelta translations that 307 // "Total scroll compensation" is the transform needed to cancel out all scr ollDelta translations that
303 // occurred since the nearest container layer, even if there are renderSurfa ces in-between. 308 // occurred since the nearest container layer, even if there are renderSurfa ces in-between.
304 // 309 //
305 // There are some edge cases to be aware of, that are not explicit in the co de: 310 // There are some edge cases to be aware of, that are not explicit in the co de:
306 // - A layer that is both a fixed-position and container should not be its own container, instead, that means 311 // - A layer that is both a fixed-position and container should not be its own container, instead, that means
307 // it is fixed to an ancestor, and is a container for any fixed-position descendants. 312 // it is fixed to an ancestor, and is a container for any fixed-position descendants.
308 // - A layer that is a fixed-position container and has a renderSurface sho uld behave the same as a container 313 // - A layer that is a fixed-position container and has a renderSurface sho uld behave the same as a container
309 // without a renderSurface, the renderSurface is irrelevant in that case. 314 // without a renderSurface, the renderSurface is irrelevant in that case.
310 // - A layer that does not have an explicit container is simply fixed to th e viewport 315 // - A layer that does not have an explicit container is simply fixed to th e viewport.
311 // (i.e. the root renderSurface, and it would still compensate for root l ayer's scrollDelta). 316 // (i.e. the root renderSurface.)
312 // - If the fixed-position layer has its own renderSurface, then the render Surface is 317 // - If the fixed-position layer has its own renderSurface, then the render Surface is
313 // the one who gets fixed. 318 // the one who gets fixed.
314 // 319 //
315 // This function needs to be called AFTER layers create their own renderSurf aces. 320 // This function needs to be called AFTER layers create their own renderSurf aces.
316 // 321 //
317 322
318 // Avoid the overheads (including stack allocation and matrix initialization /copy) if we know that the scroll compensation doesn't need to be reset or adjus ted. 323 // Avoid the overheads (including stack allocation and matrix initialization /copy) if we know that the scroll compensation doesn't need to be reset or adjus ted.
319 if (!layer->isContainerForFixedPositionLayers() && layer->scrollDelta().isZe ro() && !layer->renderSurface()) 324 if (!layer->isContainerForFixedPositionLayers() && layer->scrollDelta().isZe ro() && !layer->renderSurface())
320 return currentScrollCompensationMatrix; 325 return currentScrollCompensationMatrix;
321 326
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 375
371 Layer* maskLayer = layer->maskLayer(); 376 Layer* maskLayer = layer->maskLayer();
372 if (maskLayer) 377 if (maskLayer)
373 maskLayer->setContentsScale(contentsScale); 378 maskLayer->setContentsScale(contentsScale);
374 379
375 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas kLayer() : 0; 380 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas kLayer() : 0;
376 if (replicaMaskLayer) 381 if (replicaMaskLayer)
377 replicaMaskLayer->setContentsScale(contentsScale); 382 replicaMaskLayer->setContentsScale(contentsScale);
378 } 383 }
379 384
380 // Should be called just before the recursive calculateDrawTransformsInternal().
381 template<typename LayerType, typename LayerList>
382 void setupRootLayerAndSurfaceForRecursion(LayerType* rootLayer, LayerList& rende rSurfaceLayerList, const IntSize& deviceViewportSize)
383 {
384 if (!rootLayer->renderSurface())
385 rootLayer->createRenderSurface();
386
387 rootLayer->renderSurface()->setContentRect(IntRect(IntPoint::zero(), deviceV iewportSize));
388 rootLayer->renderSurface()->clearLayerLists();
389
390 DCHECK(renderSurfaceLayerList.empty());
391 renderSurfaceLayerList.push_back(rootLayer);
392 }
393
394 // Recursively walks the layer tree starting at the given node and computes all the 385 // Recursively walks the layer tree starting at the given node and computes all the
395 // necessary transformations, clipRects, render surfaces, etc. 386 // necessary transformations, clipRects, render surfaces, etc.
396 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter> 387 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter>
397 static void calculateDrawTransformsInternal(LayerType* layer, LayerType* rootLay er, const WebTransformationMatrix& parentMatrix, 388 static void calculateDrawTransformsInternal(LayerType* layer, const WebTransform ationMatrix& parentMatrix,
398 const WebTransformationMatrix& fullHierarchyMatrix, const WebTransformationM atrix& currentScrollCompensationMatrix, 389 const WebTransformationMatrix& fullHierarchyMatrix, const WebTransformationM atrix& currentScrollCompensationMatrix,
399 const IntRect& clipRectFromAncestor, bool ancestorClipsSubtree, 390 const IntRect& clipRectFromAncestor, bool ancestorClipsSubtree,
400 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, 391 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList,
401 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, IntRect& drawableContentRectOfSubtree) 392 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, IntRect& drawableContentRectOfSubtree)
402 { 393 {
403 // This function computes the new matrix transformations recursively for thi s 394 // This function computes the new matrix transformations recursively for thi s
404 // layer and all its descendants. It also computes the appropriate render su rfaces. 395 // layer and all its descendants. It also computes the appropriate render su rfaces.
405 // Some important points to remember: 396 // Some important points to remember:
406 // 397 //
407 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what 398 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // The replica draw transform to its target surface origin is: 469 // The replica draw transform to its target surface origin is:
479 // M[replicaDraw] = S[deviceScale] * M[surfaceDraw] * Tr[replica->pos ition() + replica->anchor()] * Tr[replica] * Tr[origin2anchor].inverse() * S[con tentsScale].inverse() 470 // M[replicaDraw] = S[deviceScale] * M[surfaceDraw] * Tr[replica->pos ition() + replica->anchor()] * Tr[replica] * Tr[origin2anchor].inverse() * S[con tentsScale].inverse()
480 // 471 //
481 // The replica draw transform to the root (screen space) origin is: 472 // The replica draw transform to the root (screen space) origin is:
482 // M[replica2root] = M[surface2root] * Tr[replica->position()] * Tr[r eplica] * Tr[origin2anchor].inverse() 473 // M[replica2root] = M[surface2root] * Tr[replica->position()] * Tr[r eplica] * Tr[origin2anchor].inverse()
483 // 474 //
484 475
485 // If we early-exit anywhere in this function, the drawableContentRect of th is subtree should be considered empty. 476 // If we early-exit anywhere in this function, the drawableContentRect of th is subtree should be considered empty.
486 drawableContentRectOfSubtree = IntRect(); 477 drawableContentRectOfSubtree = IntRect();
487 478
488 if (subtreeShouldBeSkipped(layer)) 479 // The root layer cannot skip calcDrawTransforms.
480 if (!isRootLayer(layer) && subtreeShouldBeSkipped(layer))
489 return; 481 return;
490 482
491 IntRect clipRectForSubtree; 483 IntRect clipRectForSubtree;
492 bool subtreeShouldBeClipped = false; 484 bool subtreeShouldBeClipped = false;
493 485
494 float drawOpacity = layer->opacity(); 486 float drawOpacity = layer->opacity();
495 bool drawOpacityIsAnimating = layer->opacityIsAnimating(); 487 bool drawOpacityIsAnimating = layer->opacityIsAnimating();
496 if (layer->parent() && layer->parent()->preserves3D()) { 488 if (layer->parent() && layer->parent()->preserves3D()) {
497 drawOpacity *= layer->parent()->drawOpacity(); 489 drawOpacity *= layer->parent()->drawOpacity();
498 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating(); 490 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 // The render surface clipRect is expressed in the space where this surf ace draws, i.e. the same space as clipRectFromAncestor. 627 // The render surface clipRect is expressed in the space where this surf ace draws, i.e. the same space as clipRectFromAncestor.
636 if (ancestorClipsSubtree) 628 if (ancestorClipsSubtree)
637 renderSurface->setClipRect(clipRectFromAncestor); 629 renderSurface->setClipRect(clipRectFromAncestor);
638 else 630 else
639 renderSurface->setClipRect(IntRect()); 631 renderSurface->setClipRect(IntRect());
640 632
641 renderSurface->setNearestAncestorThatMovesPixels(nearestAncestorThatMove sPixels); 633 renderSurface->setNearestAncestorThatMovesPixels(nearestAncestorThatMove sPixels);
642 634
643 renderSurfaceLayerList.push_back(layer); 635 renderSurfaceLayerList.push_back(layer);
644 } else { 636 } else {
637 DCHECK(layer->parent());
638
645 layer->setDrawTransform(drawTransform); 639 layer->setDrawTransform(drawTransform);
646 layer->setDrawTransformIsAnimating(animatingTransformToTarget); 640 layer->setDrawTransformIsAnimating(animatingTransformToTarget);
647 layer->setScreenSpaceTransformIsAnimating(animatingTransformToScreen); 641 layer->setScreenSpaceTransformIsAnimating(animatingTransformToScreen);
648 sublayerMatrix = combinedTransform; 642 sublayerMatrix = combinedTransform;
649 643
650 layer->setDrawOpacity(drawOpacity); 644 layer->setDrawOpacity(drawOpacity);
651 layer->setDrawOpacityIsAnimating(drawOpacityIsAnimating); 645 layer->setDrawOpacityIsAnimating(drawOpacityIsAnimating);
652 646
653 if (layer != rootLayer) { 647 layer->clearRenderSurface();
654 DCHECK(layer->parent());
655 layer->clearRenderSurface();
656 648
657 // Layers without renderSurfaces directly inherit the ancestor's cli p status. 649 // Layers without renderSurfaces directly inherit the ancestor's clip st atus.
658 subtreeShouldBeClipped = ancestorClipsSubtree; 650 subtreeShouldBeClipped = ancestorClipsSubtree;
659 if (ancestorClipsSubtree) 651 if (ancestorClipsSubtree)
660 clipRectForSubtree = clipRectFromAncestor; 652 clipRectForSubtree = clipRectFromAncestor;
661 653
662 // Layers that are not their own renderTarget will render into the t arget of their nearest ancestor. 654 // Layers that are not their own renderTarget will render into the targe t of their nearest ancestor.
663 layer->setRenderTarget(layer->parent()->renderTarget()); 655 layer->setRenderTarget(layer->parent()->renderTarget());
664 } else {
665 // FIXME: This root layer special case code should eventually go awa y. https://bugs.webkit.org/show_bug.cgi?id=92290
666 DCHECK(!layer->parent());
667 DCHECK(layer->renderSurface());
668 DCHECK(ancestorClipsSubtree);
669 layer->renderSurface()->setClipRect(clipRectFromAncestor);
670 subtreeShouldBeClipped = false;
671 }
672 } 656 }
673 657
674 IntRect rectInTargetSpace = enclosingIntRect(MathUtil::mapClippedRect(layer- >drawTransform(), contentRect)); 658 IntRect rectInTargetSpace = enclosingIntRect(MathUtil::mapClippedRect(layer- >drawTransform(), contentRect));
675 659
676 if (layerClipsSubtree(layer)) { 660 if (layerClipsSubtree(layer)) {
677 subtreeShouldBeClipped = true; 661 subtreeShouldBeClipped = true;
678 if (ancestorClipsSubtree && !layer->renderSurface()) { 662 if (ancestorClipsSubtree && !layer->renderSurface()) {
679 clipRectForSubtree = clipRectFromAncestor; 663 clipRectForSubtree = clipRectFromAncestor;
680 clipRectForSubtree.intersect(rectInTargetSpace); 664 clipRectForSubtree.intersect(rectInTargetSpace);
681 } else 665 } else
(...skipping 16 matching lines...) Expand all
698 682
699 if (!layerShouldBeSkipped(layer)) 683 if (!layerShouldBeSkipped(layer))
700 descendants.push_back(layer); 684 descendants.push_back(layer);
701 685
702 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; 686 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);;
703 687
704 IntRect accumulatedDrawableContentRectOfChildren; 688 IntRect accumulatedDrawableContentRectOfChildren;
705 for (size_t i = 0; i < layer->children().size(); ++i) { 689 for (size_t i = 0; i < layer->children().size(); ++i) {
706 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i); 690 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i);
707 IntRect drawableContentRectOfChildSubtree; 691 IntRect drawableContentRectOfChildSubtree;
708 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, rootLayer, sublayerMatrix, nextHierarchyMatrix, nextScrollC ompensationMatrix, 692 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensation Matrix,
709 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels, 693 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels,
710 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree); 694 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree);
711 if (!drawableContentRectOfChildSubtree.isEmpty()) { 695 if (!drawableContentRectOfChildSubtree.isEmpty()) {
712 accumulatedDrawableContentRectOfChildren.unite(drawableContentRectOf ChildSubtree); 696 accumulatedDrawableContentRectOfChildren.unite(drawableContentRectOf ChildSubtree);
713 if (child->renderSurface()) 697 if (child->renderSurface())
714 descendants.push_back(child); 698 descendants.push_back(child);
715 } 699 }
716 } 700 }
717 701
718 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space) 702 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space)
719 IntRect localDrawableContentRectOfSubtree = accumulatedDrawableContentRectOf Children; 703 IntRect localDrawableContentRectOfSubtree = accumulatedDrawableContentRectOf Children;
720 if (layer->drawsContent()) 704 if (layer->drawsContent())
721 localDrawableContentRectOfSubtree.unite(rectInTargetSpace); 705 localDrawableContentRectOfSubtree.unite(rectInTargetSpace);
722 if (subtreeShouldBeClipped) 706 if (subtreeShouldBeClipped)
723 localDrawableContentRectOfSubtree.intersect(clipRectForSubtree); 707 localDrawableContentRectOfSubtree.intersect(clipRectForSubtree);
724 708
725 // Compute the layer's drawable content rect (the rect is in targetSurface s pace) 709 // Compute the layer's drawable content rect (the rect is in targetSurface s pace)
726 IntRect drawableContentRectOfLayer = rectInTargetSpace; 710 IntRect drawableContentRectOfLayer = rectInTargetSpace;
727 if (subtreeShouldBeClipped) 711 if (subtreeShouldBeClipped)
728 drawableContentRectOfLayer.intersect(clipRectForSubtree); 712 drawableContentRectOfLayer.intersect(clipRectForSubtree);
729 layer->setDrawableContentRect(drawableContentRectOfLayer); 713 layer->setDrawableContentRect(drawableContentRectOfLayer);
730 714
731 // Compute the layer's visible content rect (the rect is in content space) 715 // Compute the layer's visible content rect (the rect is in content space)
732 IntRect visibleContentRectOfLayer = calculateVisibleContentRect(layer); 716 IntRect visibleContentRectOfLayer = calculateVisibleContentRect(layer);
733 layer->setVisibleContentRect(visibleContentRectOfLayer); 717 layer->setVisibleContentRect(visibleContentRectOfLayer);
734 718
735 // Compute the remaining properties for the render surface, if the layer has one. 719 // Compute the remaining properties for the render surface, if the layer has one.
736 if (layer->renderSurface() && layer != rootLayer) { 720 if (isRootLayer(layer)) {
721 // The root layer's surface's contentRect is always the entire viewport.
722 DCHECK(layer->renderSurface());
723 layer->renderSurface()->setContentRect(clipRectFromAncestor);
724 } else if (layer->renderSurface() && !isRootLayer(layer)) {
737 RenderSurfaceType* renderSurface = layer->renderSurface(); 725 RenderSurfaceType* renderSurface = layer->renderSurface();
738 IntRect clippedContentRect = localDrawableContentRectOfSubtree; 726 IntRect clippedContentRect = localDrawableContentRectOfSubtree;
739 727
740 // Don't clip if the layer is reflected as the reflection shouldn't be 728 // Don't clip if the layer is reflected as the reflection shouldn't be
741 // clipped. If the layer is animating, then the surface's transform to 729 // clipped. If the layer is animating, then the surface's transform to
742 // its target is not known on the main thread, and we should not use it 730 // its target is not known on the main thread, and we should not use it
743 // to clip. 731 // to clip.
744 if (!layer->replicaLayer() && transformToParentIsKnown(layer)) { 732 if (!layer->replicaLayer() && transformToParentIsKnown(layer)) {
745 // Note, it is correct to use ancestorClipsSubtree here, because we are looking at this layer's renderSurface, not the layer itself. 733 // Note, it is correct to use ancestorClipsSubtree here, because we are looking at this layer's renderSurface, not the layer itself.
746 if (ancestorClipsSubtree && !clippedContentRect.isEmpty()) { 734 if (ancestorClipsSubtree && !clippedContentRect.isEmpty()) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 if (layer->hasContributingDelegatedRenderPasses()) 811 if (layer->hasContributingDelegatedRenderPasses())
824 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa ssLayer(layer); 812 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa ssLayer(layer);
825 } 813 }
826 814
827 void LayerTreeHostCommon::calculateDrawTransforms(Layer* rootLayer, const IntSiz e& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTe xtureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) 815 void LayerTreeHostCommon::calculateDrawTransforms(Layer* rootLayer, const IntSiz e& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTe xtureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList)
828 { 816 {
829 IntRect totalDrawableContentRect; 817 IntRect totalDrawableContentRect;
830 WebTransformationMatrix identityMatrix; 818 WebTransformationMatrix identityMatrix;
831 WebTransformationMatrix deviceScaleTransform; 819 WebTransformationMatrix deviceScaleTransform;
832 deviceScaleTransform.scale(deviceScaleFactor); 820 deviceScaleTransform.scale(deviceScaleFactor);
821 std::vector<scoped_refptr<Layer> > dummyLayerList;
833 822
834 setupRootLayerAndSurfaceForRecursion<Layer, std::vector<scoped_refptr<Layer> > >(rootLayer, renderSurfaceLayerList, deviceViewportSize); 823 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect.
824 bool subtreeShouldBeClipped = true;
825 IntRect deviceViewportRect(IntPoint::zero(), deviceViewportSize);
826
827 // This function should have received a root layer.
828 DCHECK(isRootLayer(rootLayer));
835 829
836 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>( 830 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>(
837 rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatr ix, 831 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
838 rootLayer->renderSurface()->contentRect(), true, 0, renderSurfaceLayerLi st, 832 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList,
839 rootLayer->renderSurface()->layerList(), 0, maxTextureSize, 833 dummyLayerList, 0, maxTextureSize,
840 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); 834 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
835
836 // The dummy layer list should not have been used.
837 DCHECK(dummyLayerList.size() == 0);
838 // A root layer renderSurface should always exist after calculateDrawTransfo rms.
839 DCHECK(rootLayer->renderSurface());
841 } 840 }
842 841
843 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const In tSize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Layer Sorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfaceL ayerList) 842 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const In tSize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Layer Sorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfaceL ayerList)
844 { 843 {
845 IntRect totalDrawableContentRect; 844 IntRect totalDrawableContentRect;
846 WebTransformationMatrix identityMatrix; 845 WebTransformationMatrix identityMatrix;
847 WebTransformationMatrix deviceScaleTransform; 846 WebTransformationMatrix deviceScaleTransform;
848 deviceScaleTransform.scale(deviceScaleFactor); 847 deviceScaleTransform.scale(deviceScaleFactor);
848 std::vector<LayerImpl*> dummyLayerList;
849 849
850 setupRootLayerAndSurfaceForRecursion<LayerImpl, std::vector<LayerImpl*> >(ro otLayer, renderSurfaceLayerList, deviceViewportSize); 850 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect.
851 bool subtreeShouldBeClipped = true;
852 IntRect deviceViewportRect(IntPoint::zero(), deviceViewportSize);
853
854 // This function should have received a root layer.
855 DCHECK(isRootLayer(rootLayer));
851 856
852 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>( 857 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>(
853 rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatr ix, 858 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
854 rootLayer->renderSurface()->contentRect(), true, 0, renderSurfaceLayerLi st, 859 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList,
855 rootLayer->renderSurface()->layerList(), layerSorter, maxTextureSize, 860 dummyLayerList, layerSorter, maxTextureSize,
856 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); 861 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
862
863 // The dummy layer list should not have been used.
864 DCHECK(dummyLayerList.size() == 0);
865 // A root layer renderSurface should always exist after calculateDrawTransfo rms.
866 DCHECK(rootLayer->renderSurface());
857 } 867 }
858 868
859 static bool pointHitsRect(const IntPoint& screenSpacePoint, const WebTransformat ionMatrix& localSpaceToScreenSpaceTransform, FloatRect localSpaceRect) 869 static bool pointHitsRect(const IntPoint& screenSpacePoint, const WebTransformat ionMatrix& localSpaceToScreenSpaceTransform, FloatRect localSpaceRect)
860 { 870 {
861 // If the transform is not invertible, then assume that this point doesn't h it this rect. 871 // If the transform is not invertible, then assume that this point doesn't h it this rect.
862 if (!localSpaceToScreenSpaceTransform.isInvertible()) 872 if (!localSpaceToScreenSpaceTransform.isInvertible())
863 return false; 873 return false;
864 874
865 // Transform the hit test point from screen space to the local space of the given rect. 875 // Transform the hit test point from screen space to the local space of the given rect.
866 bool clipped = false; 876 bool clipped = false;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 931
922 foundLayer = currentLayer; 932 foundLayer = currentLayer;
923 break; 933 break;
924 } 934 }
925 935
926 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. 936 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer.
927 return foundLayer; 937 return foundLayer;
928 } 938 }
929 939
930 } // namespace cc 940 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698