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

Side by Side Diff: cc/layer_tree_host_common.cc

Issue 11280263: Organize internal properties of cc/ layer types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed all feedback so far Created 8 years 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 | Annotate | Revision Log
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 "cc/layer_tree_host_common.h" 5 #include "cc/layer_tree_host_common.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "cc/layer.h" 9 #include "cc/layer.h"
10 #include "cc/layer_impl.h" 10 #include "cc/layer_impl.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 static inline bool subtreeShouldBeSkipped(Layer* layer) 205 static inline bool subtreeShouldBeSkipped(Layer* layer)
206 { 206 {
207 // If the opacity is being animated then the opacity on the main thread is u nreliable 207 // If the opacity is being animated then the opacity on the main thread is u nreliable
208 // (since the impl thread may be using a different opacity), so it should no t be trusted. 208 // (since the impl thread may be using a different opacity), so it should no t be trusted.
209 // In particular, it should not cause the subtree to be skipped. 209 // In particular, it should not cause the subtree to be skipped.
210 return !layer->opacity() && !layer->opacityIsAnimating(); 210 return !layer->opacity() && !layer->opacityIsAnimating();
211 } 211 }
212 212
213 // Called on each layer that could be drawn after all information from 213 // Called on each layer that could be drawn after all information from
214 // calcDrawTransforms has been updated on that layer. May have some false 214 // calcDrawProperties has been updated on that layer. May have some false
215 // positives (e.g. layers get this called on them but don't actually get drawn). 215 // positives (e.g. layers get this called on them but don't actually get drawn).
216 static inline void markLayerAsUpdated(LayerImpl* layer) 216 static inline void markLayerAsUpdated(LayerImpl* layer)
217 { 217 {
218 layer->didUpdateTransforms(); 218 layer->didUpdateTransforms();
219 } 219 }
220 220
221 static inline void markLayerAsUpdated(Layer* layer) 221 static inline void markLayerAsUpdated(Layer* layer)
222 { 222 {
223 } 223 }
224 224
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 maskLayer->setContentsScale(contentsScale); 384 maskLayer->setContentsScale(contentsScale);
385 385
386 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas kLayer() : 0; 386 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas kLayer() : 0;
387 if (replicaMaskLayer) 387 if (replicaMaskLayer)
388 replicaMaskLayer->setContentsScale(contentsScale); 388 replicaMaskLayer->setContentsScale(contentsScale);
389 } 389 }
390 390
391 // Recursively walks the layer tree starting at the given node and computes all the 391 // Recursively walks the layer tree starting at the given node and computes all the
392 // necessary transformations, clipRects, render surfaces, etc. 392 // necessary transformations, clipRects, render surfaces, etc.
393 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter> 393 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter>
394 static void calculateDrawTransformsInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, 394 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix,
395 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, 395 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix,
396 const gfx::Rect& clipRectFromAncestor, bool ancestorClipsSubtree, 396 const gfx::Rect& clipRectFromAncestor, bool ancestorClipsSubtree,
397 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, 397 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList,
398 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree) 398 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree)
399 { 399 {
400 // This function computes the new matrix transformations recursively for thi s 400 // This function computes the new matrix transformations recursively for thi s
401 // layer and all its descendants. It also computes the appropriate render su rfaces. 401 // layer and all its descendants. It also computes the appropriate render su rfaces.
402 // Some important points to remember: 402 // Some important points to remember:
403 // 403 //
404 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what 404 // 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
475 // The replica draw transform to its target surface origin is: 475 // The replica draw transform to its target surface origin is:
476 // M[replicaDraw] = S[deviceScale] * M[surfaceDraw] * Tr[replica->pos ition() + replica->anchor()] * Tr[replica] * Tr[origin2anchor].inverse() * S[con tentsScale].inverse() 476 // M[replicaDraw] = S[deviceScale] * M[surfaceDraw] * Tr[replica->pos ition() + replica->anchor()] * Tr[replica] * Tr[origin2anchor].inverse() * S[con tentsScale].inverse()
477 // 477 //
478 // The replica draw transform to the root (screen space) origin is: 478 // The replica draw transform to the root (screen space) origin is:
479 // M[replica2root] = M[surface2root] * Tr[replica->position()] * Tr[r eplica] * Tr[origin2anchor].inverse() 479 // M[replica2root] = M[surface2root] * Tr[replica->position()] * Tr[r eplica] * Tr[origin2anchor].inverse()
480 // 480 //
481 481
482 // If we early-exit anywhere in this function, the drawableContentRect of th is subtree should be considered empty. 482 // If we early-exit anywhere in this function, the drawableContentRect of th is subtree should be considered empty.
483 drawableContentRectOfSubtree = gfx::Rect(); 483 drawableContentRectOfSubtree = gfx::Rect();
484 484
485 // The root layer cannot skip calcDrawTransforms. 485 // The root layer cannot skip calcDrawProperties.
486 if (!isRootLayer(layer) && subtreeShouldBeSkipped(layer)) 486 if (!isRootLayer(layer) && subtreeShouldBeSkipped(layer))
487 return; 487 return;
488 488
489 // As this function proceeds, these are the properties for the current
490 // layer that actually get computed. To avoid unnecessary copies
491 // (particularly for matrices), we do computations directly on these values
492 // when possible.
493 DrawProperties<LayerType, RenderSurfaceType>& layerDrawProperties = layer->d rawProperties();
494
489 gfx::Rect clipRectForSubtree; 495 gfx::Rect clipRectForSubtree;
490 bool subtreeShouldBeClipped = false; 496 bool subtreeShouldBeClipped = false;
491 497
492 float drawOpacity = layer->opacity(); 498 float accumulatedDrawOpacity = layer->opacity();
493 bool drawOpacityIsAnimating = layer->opacityIsAnimating(); 499 bool drawOpacityIsAnimating = layer->opacityIsAnimating();
494 if (layer->parent()) { 500 if (layer->parent()) {
495 drawOpacity *= layer->parent()->drawOpacity(); 501 accumulatedDrawOpacity *= layer->parent()->drawOpacity();
496 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating(); 502 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating();
497 } 503 }
498 504
499 bool animatingTransformToTarget = layer->transformIsAnimating(); 505 bool animatingTransformToTarget = layer->transformIsAnimating();
500 bool animatingTransformToScreen = animatingTransformToTarget; 506 bool animatingTransformToScreen = animatingTransformToTarget;
501 if (layer->parent()) { 507 if (layer->parent()) {
502 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating( ); 508 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating( );
503 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni mating(); 509 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni mating();
504 } 510 }
505 511
(...skipping 22 matching lines...) Expand all
528 if (layer->fixedToContainerLayer()) { 534 if (layer->fixedToContainerLayer()) {
529 // Special case: this layer is a composited fixed-position layer; we nee d to 535 // Special case: this layer is a composited fixed-position layer; we nee d to
530 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer 536 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer
531 // fixed correctly. 537 // fixed correctly.
532 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform). 538 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform).
533 combinedTransform.ConcatTransform(currentScrollCompensationMatrix); 539 combinedTransform.ConcatTransform(currentScrollCompensationMatrix);
534 } 540 }
535 541
536 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless 542 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless
537 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms. 543 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms.
538 gfx::Transform drawTransform = combinedTransform; 544 layerDrawProperties.target_space_transform = combinedTransform;
539 // M[draw] = M[parent] * LT * S[layer2content] 545 // M[draw] = M[parent] * LT * S[layer2content]
540 drawTransform.Scale(1.0 / layer->contentsScaleX(), 1.0 / layer->contentsScal eY()); 546 layerDrawProperties.target_space_transform.Scale(1.0 / layer->contentsScaleX (), 1.0 / layer->contentsScaleY());
541 547
542 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space. 548 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space.
543 gfx::Transform layerScreenSpaceTransform = fullHierarchyMatrix; 549 layerDrawProperties.screen_space_transform = fullHierarchyMatrix;
544 if (!layer->preserves3D()) 550 if (!layer->preserves3D())
545 MathUtil::flattenTransformTo2d(layerScreenSpaceTransform); 551 MathUtil::flattenTransformTo2d(layerDrawProperties.screen_space_transfor m);
546 layerScreenSpaceTransform.PreconcatTransform(drawTransform); 552 layerDrawProperties.screen_space_transform.PreconcatTransform(layerDrawPrope rties.target_space_transform);
547 layer->setScreenSpaceTransform(layerScreenSpaceTransform);
548 553
549 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds()); 554 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds());
550 555
551 // fullHierarchyMatrix is the matrix that transforms objects between screen space (except projection matrix) and the most recent RenderSurfaceImpl's space. 556 // fullHierarchyMatrix is the matrix that transforms objects between screen space (except projection matrix) and the most recent RenderSurfaceImpl's space.
552 // nextHierarchyMatrix will only change if this layer uses a new RenderSurfa ceImpl, otherwise remains the same. 557 // nextHierarchyMatrix will only change if this layer uses a new RenderSurfa ceImpl, otherwise remains the same.
553 gfx::Transform nextHierarchyMatrix = fullHierarchyMatrix; 558 gfx::Transform nextHierarchyMatrix = fullHierarchyMatrix;
554 gfx::Transform sublayerMatrix; 559 gfx::Transform sublayerMatrix;
555 560
556 gfx::Vector2dF renderSurfaceSublayerScale = MathUtil::computeTransform2dScal eComponents(combinedTransform); 561 gfx::Vector2dF renderSurfaceSublayerScale = MathUtil::computeTransform2dScal eComponents(combinedTransform);
557 562
(...skipping 10 matching lines...) Expand all
568 573
569 // The owning layer's draw transform has a scale from content to layer 574 // The owning layer's draw transform has a scale from content to layer
570 // space which we do not want; so here we use the combinedTransform 575 // space which we do not want; so here we use the combinedTransform
571 // instead of the drawTransform. However, we do need to add a different 576 // instead of the drawTransform. However, we do need to add a different
572 // scale factor that accounts for the surface's pixel dimensions. 577 // scale factor that accounts for the surface's pixel dimensions.
573 combinedTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / renderSu rfaceSublayerScale.y()); 578 combinedTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / renderSu rfaceSublayerScale.y());
574 renderSurface->setDrawTransform(combinedTransform); 579 renderSurface->setDrawTransform(combinedTransform);
575 580
576 // The owning layer's transform was re-parented by the surface, so the l ayer's new drawTransform 581 // The owning layer's transform was re-parented by the surface, so the l ayer's new drawTransform
577 // only needs to scale the layer to surface space. 582 // only needs to scale the layer to surface space.
578 gfx::Transform layerDrawTransform; 583 layerDrawProperties.target_space_transform.MakeIdentity();
579 layerDrawTransform.Scale(renderSurfaceSublayerScale.x() / layer->content sScaleX(), renderSurfaceSublayerScale.y() / layer->contentsScaleY()); 584 layerDrawProperties.target_space_transform.Scale(renderSurfaceSublayerSc ale.x() / layer->contentsScaleX(), renderSurfaceSublayerScale.y() / layer->conte ntsScaleY());
580 layer->setDrawTransform(layerDrawTransform);
581 585
582 // Inside the surface's subtree, we scale everything to the owning layer 's scale. 586 // Inside the surface's subtree, we scale everything to the owning layer 's scale.
583 // The sublayer matrix transforms centered layer rects into target 587 // The sublayer matrix transforms centered layer rects into target
584 // surface content space. 588 // surface content space.
585 DCHECK(sublayerMatrix.IsIdentity()); 589 DCHECK(sublayerMatrix.IsIdentity());
586 sublayerMatrix.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSublay erScale.y()); 590 sublayerMatrix.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSublay erScale.y());
587 591
588 // The opacity value is moved from the layer to its surface, so that the entire subtree properly inherits opacity. 592 // The opacity value is moved from the layer to its surface, so that the entire subtree properly inherits opacity.
589 renderSurface->setDrawOpacity(drawOpacity); 593 renderSurface->setDrawOpacity(accumulatedDrawOpacity);
590 renderSurface->setDrawOpacityIsAnimating(drawOpacityIsAnimating); 594 renderSurface->setDrawOpacityIsAnimating(drawOpacityIsAnimating);
591 layer->setDrawOpacity(1); 595 layerDrawProperties.opacity = 1;
592 layer->setDrawOpacityIsAnimating(false); 596 layerDrawProperties.opacity_is_animating = false;
593 597
594 renderSurface->setTargetSurfaceTransformsAreAnimating(animatingTransform ToTarget); 598 renderSurface->setTargetSurfaceTransformsAreAnimating(animatingTransform ToTarget);
595 renderSurface->setScreenSpaceTransformsAreAnimating(animatingTransformTo Screen); 599 renderSurface->setScreenSpaceTransformsAreAnimating(animatingTransformTo Screen);
596 animatingTransformToTarget = false; 600 animatingTransformToTarget = false;
597 layer->setDrawTransformIsAnimating(animatingTransformToTarget); 601 layerDrawProperties.target_space_transform_is_animating = animatingTrans formToTarget;
598 layer->setScreenSpaceTransformIsAnimating(animatingTransformToScreen); 602 layerDrawProperties.screen_space_transform_is_animating = animatingTrans formToScreen;
599 603
600 // Update the aggregate hierarchy matrix to include the transform of the 604 // Update the aggregate hierarchy matrix to include the transform of the
601 // newly created RenderSurfaceImpl. 605 // newly created RenderSurfaceImpl.
602 nextHierarchyMatrix.PreconcatTransform(renderSurface->drawTransform()); 606 nextHierarchyMatrix.PreconcatTransform(renderSurface->drawTransform());
603 607
604 // The new renderSurface here will correctly clip the entire subtree. So , we do 608 // The new renderSurface here will correctly clip the entire subtree. So , we do
605 // not need to continue propagating the clipping state further down the tree. This 609 // not need to continue propagating the clipping state further down the tree. This
606 // way, we can avoid transforming clipRects from ancestor target surface space to 610 // way, we can avoid transforming clipRects from ancestor target surface space to
607 // current target surface space that could cause more w < 0 headaches. 611 // current target surface space that could cause more w < 0 headaches.
608 subtreeShouldBeClipped = false; 612 subtreeShouldBeClipped = false;
609 613
610 if (layer->maskLayer()) { 614 if (layer->maskLayer()) {
611 layer->maskLayer()->setRenderTarget(layer); 615 DrawProperties<LayerType, RenderSurfaceType>& maskLayerDrawPropertie s = layer->maskLayer()->drawProperties();
612 layer->maskLayer()->setVisibleContentRect(gfx::Rect(gfx::Point(), la yer->contentBounds())); 616 maskLayerDrawProperties.render_target = layer;
617 maskLayerDrawProperties.visible_content_rect = gfx::Rect(gfx::Point( ), layer->contentBounds());
613 } 618 }
614 619
615 if (layer->replicaLayer() && layer->replicaLayer()->maskLayer()) { 620 if (layer->replicaLayer() && layer->replicaLayer()->maskLayer()) {
616 layer->replicaLayer()->maskLayer()->setRenderTarget(layer); 621 DrawProperties<LayerType, RenderSurfaceType>& replicaMaskDrawPropert ies = layer->replicaLayer()->maskLayer()->drawProperties();
617 layer->replicaLayer()->maskLayer()->setVisibleContentRect(gfx::Rect( gfx::Point(), layer->contentBounds())); 622 replicaMaskDrawProperties.render_target = layer;
623 replicaMaskDrawProperties.visible_content_rect = gfx::Rect(gfx::Poin t(), layer->contentBounds());
618 } 624 }
619 625
620 // FIXME: make this smarter for the SkImageFilter case (check for 626 // FIXME: make this smarter for the SkImageFilter case (check for
621 // pixel-moving filters) 627 // pixel-moving filters)
622 if (layer->filters().hasFilterThatMovesPixels() || layer->filter()) 628 if (layer->filters().hasFilterThatMovesPixels() || layer->filter())
623 nearestAncestorThatMovesPixels = renderSurface; 629 nearestAncestorThatMovesPixels = renderSurface;
624 630
625 // The render surface clipRect is expressed in the space where this surf ace draws, i.e. the same space as clipRectFromAncestor. 631 // The render surface clipRect is expressed in the space where this surf ace draws, i.e. the same space as clipRectFromAncestor.
626 renderSurface->setIsClipped(ancestorClipsSubtree); 632 renderSurface->setIsClipped(ancestorClipsSubtree);
627 if (ancestorClipsSubtree) 633 if (ancestorClipsSubtree)
628 renderSurface->setClipRect(clipRectFromAncestor); 634 renderSurface->setClipRect(clipRectFromAncestor);
629 else 635 else
630 renderSurface->setClipRect(gfx::Rect()); 636 renderSurface->setClipRect(gfx::Rect());
631 637
632 renderSurface->setNearestAncestorThatMovesPixels(nearestAncestorThatMove sPixels); 638 renderSurface->setNearestAncestorThatMovesPixels(nearestAncestorThatMove sPixels);
633 639
634 renderSurfaceLayerList.push_back(layer); 640 renderSurfaceLayerList.push_back(layer);
635 } else { 641 } else {
636 DCHECK(layer->parent()); 642 DCHECK(layer->parent());
637 643
638 layer->setDrawTransform(drawTransform); 644 // Note: layerDrawProperties.target_space_transform is computed above,
639 layer->setDrawTransformIsAnimating(animatingTransformToTarget); 645 // before this if-else statement.
640 layer->setScreenSpaceTransformIsAnimating(animatingTransformToScreen); 646 layerDrawProperties.target_space_transform_is_animating = animatingTrans formToTarget;
647 layerDrawProperties.screen_space_transform_is_animating = animatingTrans formToScreen;
648 layerDrawProperties.opacity = accumulatedDrawOpacity;
649 layerDrawProperties.opacity_is_animating = drawOpacityIsAnimating;
641 sublayerMatrix = combinedTransform; 650 sublayerMatrix = combinedTransform;
642 651
643 layer->setDrawOpacity(drawOpacity);
644 layer->setDrawOpacityIsAnimating(drawOpacityIsAnimating);
645
646 layer->clearRenderSurface(); 652 layer->clearRenderSurface();
647 653
648 // Layers without renderSurfaces directly inherit the ancestor's clip st atus. 654 // Layers without renderSurfaces directly inherit the ancestor's clip st atus.
649 subtreeShouldBeClipped = ancestorClipsSubtree; 655 subtreeShouldBeClipped = ancestorClipsSubtree;
650 if (ancestorClipsSubtree) 656 if (ancestorClipsSubtree)
651 clipRectForSubtree = clipRectFromAncestor; 657 clipRectForSubtree = clipRectFromAncestor;
652 658
653 // Layers that are not their own renderTarget will render into the targe t of their nearest ancestor. 659 // Layers that are not their own renderTarget will render into the targe t of their nearest ancestor.
654 layer->setRenderTarget(layer->parent()->renderTarget()); 660 layerDrawProperties.render_target = layer->parent()->renderTarget();
655 } 661 }
656 662
657 gfx::Rect rectInTargetSpace = ToEnclosingRect(MathUtil::mapClippedRect(layer ->drawTransform(), contentRect)); 663 gfx::Rect rectInTargetSpace = ToEnclosingRect(MathUtil::mapClippedRect(layer ->drawTransform(), contentRect));
658 664
659 if (layerClipsSubtree(layer)) { 665 if (layerClipsSubtree(layer)) {
660 subtreeShouldBeClipped = true; 666 subtreeShouldBeClipped = true;
661 if (ancestorClipsSubtree && !layer->renderSurface()) { 667 if (ancestorClipsSubtree && !layer->renderSurface()) {
662 clipRectForSubtree = clipRectFromAncestor; 668 clipRectForSubtree = clipRectFromAncestor;
663 clipRectForSubtree.Intersect(rectInTargetSpace); 669 clipRectForSubtree.Intersect(rectInTargetSpace);
664 } else 670 } else
(...skipping 18 matching lines...) Expand all
683 689
684 if (!layerShouldBeSkipped(layer)) 690 if (!layerShouldBeSkipped(layer))
685 descendants.push_back(layer); 691 descendants.push_back(layer);
686 692
687 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; 693 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);;
688 694
689 gfx::Rect accumulatedDrawableContentRectOfChildren; 695 gfx::Rect accumulatedDrawableContentRectOfChildren;
690 for (size_t i = 0; i < layer->children().size(); ++i) { 696 for (size_t i = 0; i < layer->children().size(); ++i) {
691 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i); 697 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i);
692 gfx::Rect drawableContentRectOfChildSubtree; 698 gfx::Rect drawableContentRectOfChildSubtree;
693 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensation Matrix, 699 calculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensation Matrix,
694 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels, 700 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels,
695 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree); 701 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree);
696 if (!drawableContentRectOfChildSubtree.IsEmpty()) { 702 if (!drawableContentRectOfChildSubtree.IsEmpty()) {
697 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf ChildSubtree); 703 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf ChildSubtree);
698 if (child->renderSurface()) 704 if (child->renderSurface())
699 descendants.push_back(child); 705 descendants.push_back(child);
700 } 706 }
701 } 707 }
702 708
703 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space) 709 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space)
704 gfx::Rect localDrawableContentRectOfSubtree = accumulatedDrawableContentRect OfChildren; 710 gfx::Rect localDrawableContentRectOfSubtree = accumulatedDrawableContentRect OfChildren;
705 if (layer->drawsContent()) 711 if (layer->drawsContent())
706 localDrawableContentRectOfSubtree.Union(rectInTargetSpace); 712 localDrawableContentRectOfSubtree.Union(rectInTargetSpace);
707 if (subtreeShouldBeClipped) 713 if (subtreeShouldBeClipped)
708 localDrawableContentRectOfSubtree.Intersect(clipRectForSubtree); 714 localDrawableContentRectOfSubtree.Intersect(clipRectForSubtree);
709 715
710 // Compute the layer's drawable content rect (the rect is in targetSurface s pace) 716 // Compute the layer's drawable content rect (the rect is in targetSurface s pace)
711 gfx::Rect drawableContentRectOfLayer = rectInTargetSpace; 717 layerDrawProperties.drawable_content_rect = rectInTargetSpace;
712 if (subtreeShouldBeClipped) 718 if (subtreeShouldBeClipped)
713 drawableContentRectOfLayer.Intersect(clipRectForSubtree); 719 layerDrawProperties.drawable_content_rect.Intersect(clipRectForSubtree);
714 layer->setDrawableContentRect(drawableContentRectOfLayer);
715 720
716 // Tell the layer the rect that is clipped by. In theory we could use a 721 // Tell the layer the rect that is clipped by. In theory we could use a
717 // tighter clipRect here (drawableContentRect), but that actually does not 722 // tighter clipRect here (drawableContentRect), but that actually does not
718 // reduce how much would be drawn, and instead it would create unnecessary 723 // reduce how much would be drawn, and instead it would create unnecessary
719 // changes to scissor state affecting GPU performance. 724 // changes to scissor state affecting GPU performance.
720 layer->setIsClipped(subtreeShouldBeClipped); 725 layerDrawProperties.is_clipped = subtreeShouldBeClipped;
721 if (subtreeShouldBeClipped) 726 if (subtreeShouldBeClipped)
722 layer->setClipRect(clipRectForSubtree); 727 layerDrawProperties.clip_rect = clipRectForSubtree;
723 else { 728 else {
724 // Initialize the clipRect to a safe value that will not clip the 729 // Initialize the clipRect to a safe value that will not clip the
725 // layer, just in case clipping is still accidentally used. 730 // layer, just in case clipping is still accidentally used.
726 layer->setClipRect(rectInTargetSpace); 731 layerDrawProperties.clip_rect = rectInTargetSpace;
727 } 732 }
728 733
729 // Compute the layer's visible content rect (the rect is in content space) 734 // Compute the layer's visible content rect (the rect is in content space)
730 gfx::Rect visibleContentRectOfLayer = calculateVisibleContentRect(layer); 735 layerDrawProperties.visible_content_rect = calculateVisibleContentRect(layer );
731 layer->setVisibleContentRect(visibleContentRectOfLayer);
732 736
733 // Compute the remaining properties for the render surface, if the layer has one. 737 // Compute the remaining properties for the render surface, if the layer has one.
734 if (isRootLayer(layer)) { 738 if (isRootLayer(layer)) {
735 // The root layer's surface's contentRect is always the entire viewport. 739 // The root layer's surface's contentRect is always the entire viewport.
736 DCHECK(layer->renderSurface()); 740 DCHECK(layer->renderSurface());
737 layer->renderSurface()->setContentRect(clipRectFromAncestor); 741 layer->renderSurface()->setContentRect(clipRectFromAncestor);
738 } else if (layer->renderSurface() && !isRootLayer(layer)) { 742 } else if (layer->renderSurface() && !isRootLayer(layer)) {
739 RenderSurfaceType* renderSurface = layer->renderSurface(); 743 RenderSurfaceType* renderSurface = layer->renderSurface();
740 gfx::Rect clippedContentRect = localDrawableContentRectOfSubtree; 744 gfx::Rect clippedContentRect = localDrawableContentRectOfSubtree;
741 745
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 821
818 if (layer->renderSurface()) 822 if (layer->renderSurface())
819 drawableContentRectOfSubtree = gfx::ToEnclosingRect(layer->renderSurface ()->drawableContentRect()); 823 drawableContentRectOfSubtree = gfx::ToEnclosingRect(layer->renderSurface ()->drawableContentRect());
820 else 824 else
821 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree; 825 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree;
822 826
823 if (layer->hasContributingDelegatedRenderPasses()) 827 if (layer->hasContributingDelegatedRenderPasses())
824 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa ssLayer(layer); 828 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa ssLayer(layer);
825 } 829 }
826 830
827 void LayerTreeHostCommon::calculateDrawTransforms(Layer* rootLayer, const gfx::S ize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int max TextureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) 831 void LayerTreeHostCommon::calculateDrawProperties(Layer* rootLayer, const gfx::S ize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int max TextureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList)
828 { 832 {
829 gfx::Rect totalDrawableContentRect; 833 gfx::Rect totalDrawableContentRect;
830 gfx::Transform identityMatrix; 834 gfx::Transform identityMatrix;
831 gfx::Transform deviceScaleTransform; 835 gfx::Transform deviceScaleTransform;
832 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); 836 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor);
833 std::vector<scoped_refptr<Layer> > dummyLayerList; 837 std::vector<scoped_refptr<Layer> > dummyLayerList;
834 838
835 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. 839 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect.
836 bool subtreeShouldBeClipped = true; 840 bool subtreeShouldBeClipped = true;
837 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); 841 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize);
838 842
839 // This function should have received a root layer. 843 // This function should have received a root layer.
840 DCHECK(isRootLayer(rootLayer)); 844 DCHECK(isRootLayer(rootLayer));
841 845
842 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>( 846 cc::calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>(
843 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, 847 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
844 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, 848 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList,
845 dummyLayerList, 0, maxTextureSize, 849 dummyLayerList, 0, maxTextureSize,
846 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); 850 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
847 851
848 // The dummy layer list should not have been used. 852 // The dummy layer list should not have been used.
849 DCHECK(dummyLayerList.size() == 0); 853 DCHECK(dummyLayerList.size() == 0);
850 // A root layer renderSurface should always exist after calculateDrawTransfo rms. 854 // A root layer renderSurface should always exist after calculateDrawPropert ies.
851 DCHECK(rootLayer->renderSurface()); 855 DCHECK(rootLayer->renderSurface());
852 } 856 }
853 857
854 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac eLayerList) 858 void LayerTreeHostCommon::calculateDrawProperties(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac eLayerList)
855 { 859 {
856 gfx::Rect totalDrawableContentRect; 860 gfx::Rect totalDrawableContentRect;
857 gfx::Transform identityMatrix; 861 gfx::Transform identityMatrix;
858 gfx::Transform deviceScaleTransform; 862 gfx::Transform deviceScaleTransform;
859 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); 863 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor);
860 std::vector<LayerImpl*> dummyLayerList; 864 std::vector<LayerImpl*> dummyLayerList;
861 865
862 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. 866 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect.
863 bool subtreeShouldBeClipped = true; 867 bool subtreeShouldBeClipped = true;
864 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); 868 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize);
865 869
866 // This function should have received a root layer. 870 // This function should have received a root layer.
867 DCHECK(isRootLayer(rootLayer)); 871 DCHECK(isRootLayer(rootLayer));
868 872
869 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>( 873 cc::calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>(
870 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, 874 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
871 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, 875 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList,
872 dummyLayerList, layerSorter, maxTextureSize, 876 dummyLayerList, layerSorter, maxTextureSize,
873 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); 877 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
874 878
875 // The dummy layer list should not have been used. 879 // The dummy layer list should not have been used.
876 DCHECK(dummyLayerList.size() == 0); 880 DCHECK(dummyLayerList.size() == 0);
877 // A root layer renderSurface should always exist after calculateDrawTransfo rms. 881 // A root layer renderSurface should always exist after calculateDrawPropert ies.
878 DCHECK(rootLayer->renderSurface()); 882 DCHECK(rootLayer->renderSurface());
879 } 883 }
880 884
881 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) 885 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect)
882 { 886 {
883 // If the transform is not invertible, then assume that this point doesn't h it this rect. 887 // If the transform is not invertible, then assume that this point doesn't h it this rect.
884 if (!localSpaceToScreenSpaceTransform.IsInvertible()) 888 if (!localSpaceToScreenSpaceTransform.IsInvertible())
885 return false; 889 return false;
886 890
887 // Transform the hit test point from screen space to the local space of the given rect. 891 // Transform the hit test point from screen space to the local space of the given rect.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 999
996 foundLayer = currentLayer; 1000 foundLayer = currentLayer;
997 break; 1001 break;
998 } 1002 }
999 1003
1000 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. 1004 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer.
1001 return foundLayer; 1005 return foundLayer;
1002 } 1006 }
1003 1007
1004 } // namespace cc 1008 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698