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

Side by Side Diff: cc/layer_tree_host_common.cc

Issue 11280271: Tighten the matrix usage in cc/layer_tree_host_common.cpp (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | 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 "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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 bool animatingTransformToScreen = animatingTransformToTarget; 500 bool animatingTransformToScreen = animatingTransformToTarget;
501 if (layer->parent()) { 501 if (layer->parent()) {
502 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating( ); 502 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating( );
503 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni mating(); 503 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni mating();
504 } 504 }
505 505
506 gfx::Size bounds = layer->bounds(); 506 gfx::Size bounds = layer->bounds();
507 gfx::PointF anchorPoint = layer->anchorPoint(); 507 gfx::PointF anchorPoint = layer->anchorPoint();
508 gfx::PointF position = layer->position() - layer->scrollDelta(); 508 gfx::PointF position = layer->position() - layer->scrollDelta();
509 509
510 gfx::Transform layerLocalTransform; 510 gfx::Transform combinedTransform = layer->implTransform() * parentMatrix;
511 // LT = Tr[origin] * Tr[origin2anchor] 511 // LT = Tr[origin] * Tr[origin2anchor]
512 layerLocalTransform.Translate3d(position.x() + anchorPoint.x() * bounds.widt h(), position.y() + anchorPoint.y() * bounds.height(), layer->anchorPointZ()); 512 combinedTransform.Translate3d(position.x() + anchorPoint.x() * bounds.width( ), position.y() + anchorPoint.y() * bounds.height(), layer->anchorPointZ());
513 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] 513 // LT = Tr[origin] * Tr[origin2anchor] * M[layer]
514 layerLocalTransform.PreconcatTransform(layer->transform()); 514 combinedTransform.PreconcatTransform(layer->transform());
515 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin] 515 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin]
516 layerLocalTransform.Translate3d(-anchorPoint.x() * bounds.width(), -anchorPo int.y() * bounds.height(), -layer->anchorPointZ()); 516 combinedTransform.Translate3d(-anchorPoint.x() * bounds.width(), -anchorPoin t.y() * bounds.height(), -layer->anchorPointZ());
517
518 gfx::Transform combinedTransform = parentMatrix;
519 combinedTransform.PreconcatTransform(layerLocalTransform);
520 517
521 // The layer's contentsSize is determined from the combinedTransform, which then informs the 518 // The layer's contentsSize is determined from the combinedTransform, which then informs the
522 // layer's drawTransform. 519 // layer's drawTransform.
523 updateLayerContentsScale(layer, combinedTransform, deviceScaleFactor, pageSc aleFactor, animatingTransformToScreen); 520 updateLayerContentsScale(layer, combinedTransform, deviceScaleFactor, pageSc aleFactor, animatingTransformToScreen);
524 521
525 // If there is a tranformation from the impl thread then it should be at the
526 // start of the combinedTransform, but we don't want it to affect the conten tsScale.
danakj 2012/12/03 18:24:40 implTransform should not affect the contentsScale.
shawnsingh 2012/12/03 19:37:06 Yes, I was planning to ask you about this before l
danakj 2012/12/03 19:56:28 updateLayerContentsScale wants the combinedTransfo
527 combinedTransform = layer->implTransform() * combinedTransform;
528
529 if (layer->fixedToContainerLayer()) { 522 if (layer->fixedToContainerLayer()) {
530 // Special case: this layer is a composited fixed-position layer; we nee d to 523 // Special case: this layer is a composited fixed-position layer; we nee d to
531 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer 524 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer
532 // fixed correctly. 525 // fixed correctly.
533 combinedTransform = currentScrollCompensationMatrix * combinedTransform; 526 combinedTransform = currentScrollCompensationMatrix * combinedTransform;
534 } 527 }
535 528
536 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless 529 // 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. 530 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms.
538 gfx::Transform drawTransform = combinedTransform; 531 gfx::Transform drawTransform = combinedTransform;
(...skipping 20 matching lines...) Expand all
559 // Check back-face visibility before continuing with this surface and it s subtree 552 // Check back-face visibility before continuing with this surface and it s subtree
560 if (!layer->doubleSided() && transformToParentIsKnown(layer) && isSurfac eBackFaceVisible(layer, combinedTransform)) 553 if (!layer->doubleSided() && transformToParentIsKnown(layer) && isSurfac eBackFaceVisible(layer, combinedTransform))
561 return; 554 return;
562 555
563 if (!layer->renderSurface()) 556 if (!layer->renderSurface())
564 layer->createRenderSurface(); 557 layer->createRenderSurface();
565 558
566 RenderSurfaceType* renderSurface = layer->renderSurface(); 559 RenderSurfaceType* renderSurface = layer->renderSurface();
567 renderSurface->clearLayerLists(); 560 renderSurface->clearLayerLists();
568 561
569 // The owning layer's draw transform has a scale from content to layer s pace which we need to undo and 562 // The owning layer's draw transform has a scale from content to layer
570 // replace with a scale from the surface's subtree into layer space. 563 // space which do not want; so here we use the combinedTransform
571 drawTransform.Scale(layer->contentsScaleX(), layer->contentsScaleY()); 564 // instead of the drawTransform. However, we do need to add a different
572 drawTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / renderSurfac eSublayerScale.y()); 565 // scale factor that accounts for the surface's pixel dimensions.
573 renderSurface->setDrawTransform(drawTransform); 566 combinedTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / renderSu rfaceSublayerScale.y());
567 renderSurface->setDrawTransform(combinedTransform);
574 568
575 // The origin of the new surface is the upper left corner of the layer. 569 // The owning layer's transform was re-parented by the surface, so the l ayer's new drawTransform
570 // only needs to scale the layer to surface space.
576 gfx::Transform layerDrawTransform; 571 gfx::Transform layerDrawTransform;
577 layerDrawTransform.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSu blayerScale.y()); 572 layerDrawTransform.Scale(renderSurfaceSublayerScale.x() / layer->content sScaleX(), renderSurfaceSublayerScale.y() / layer->contentsScaleY());
578 layerDrawTransform.Scale(1.0 / layer->contentsScaleX(), 1.0 / layer->con tentsScaleY());
579 layer->setDrawTransform(layerDrawTransform); 573 layer->setDrawTransform(layerDrawTransform);
580 574
581 // Inside the surface's subtree, we scale everything to the owning layer 's scale. 575 // Inside the surface's subtree, we scale everything to the owning layer 's scale.
582 // The sublayer matrix transforms centered layer rects into target 576 // The sublayer matrix transforms centered layer rects into target
583 // surface content space. 577 // surface content space.
584 sublayerMatrix.MakeIdentity(); 578 DCHECK(sublayerMatrix.IsIdentity());
585 sublayerMatrix.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSublay erScale.y()); 579 sublayerMatrix.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSublay erScale.y());
586 580
587 // The opacity value is moved from the layer to its surface, so that the entire subtree properly inherits opacity. 581 // The opacity value is moved from the layer to its surface, so that the entire subtree properly inherits opacity.
588 renderSurface->setDrawOpacity(drawOpacity); 582 renderSurface->setDrawOpacity(drawOpacity);
589 renderSurface->setDrawOpacityIsAnimating(drawOpacityIsAnimating); 583 renderSurface->setDrawOpacityIsAnimating(drawOpacityIsAnimating);
590 layer->setDrawOpacity(1); 584 layer->setDrawOpacity(1);
591 layer->setDrawOpacityIsAnimating(false); 585 layer->setDrawOpacityIsAnimating(false);
592 586
593 renderSurface->setTargetSurfaceTransformsAreAnimating(animatingTransform ToTarget); 587 renderSurface->setTargetSurfaceTransformsAreAnimating(animatingTransform ToTarget);
594 renderSurface->setScreenSpaceTransformsAreAnimating(animatingTransformTo Screen); 588 renderSurface->setScreenSpaceTransformsAreAnimating(animatingTransformTo Screen);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 clipRectForSubtree.Intersect(rectInTargetSpace); 656 clipRectForSubtree.Intersect(rectInTargetSpace);
663 } else 657 } else
664 clipRectForSubtree = rectInTargetSpace; 658 clipRectForSubtree = rectInTargetSpace;
665 } 659 }
666 660
667 // Flatten to 2D if the layer doesn't preserve 3D. 661 // Flatten to 2D if the layer doesn't preserve 3D.
668 if (!layer->preserves3D()) 662 if (!layer->preserves3D())
669 MathUtil::flattenTransformTo2d(sublayerMatrix); 663 MathUtil::flattenTransformTo2d(sublayerMatrix);
670 664
671 // Apply the sublayer transform at the center of the layer. 665 // Apply the sublayer transform at the center of the layer.
672 sublayerMatrix.Translate(0.5 * bounds.width(), 0.5 * bounds.height()); 666 if (!layer->sublayerTransform().IsIdentity()) {
673 sublayerMatrix.PreconcatTransform(layer->sublayerTransform()); 667 sublayerMatrix.Translate(0.5 * bounds.width(), 0.5 * bounds.height());
674 sublayerMatrix.Translate(-0.5 * bounds.width(), -0.5 * bounds.height()); 668 sublayerMatrix.PreconcatTransform(layer->sublayerTransform());
669 sublayerMatrix.Translate(-0.5 * bounds.width(), -0.5 * bounds.height());
670 }
675 671
676 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList); 672 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList);
677 673
678 // Any layers that are appended after this point are in the layer's subtree and should be included in the sorting process. 674 // Any layers that are appended after this point are in the layer's subtree and should be included in the sorting process.
679 unsigned sortingStartIndex = descendants.size(); 675 unsigned sortingStartIndex = descendants.size();
680 676
681 if (!layerShouldBeSkipped(layer)) 677 if (!layerShouldBeSkipped(layer))
682 descendants.push_back(layer); 678 descendants.push_back(layer);
683 679
684 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; 680 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 clippedContentRect.set_height(std::min(clippedContentRect.height(), maxT extureSize)); 750 clippedContentRect.set_height(std::min(clippedContentRect.height(), maxT extureSize));
755 751
756 if (clippedContentRect.IsEmpty()) 752 if (clippedContentRect.IsEmpty())
757 renderSurface->clearLayerLists(); 753 renderSurface->clearLayerLists();
758 754
759 renderSurface->setContentRect(clippedContentRect); 755 renderSurface->setContentRect(clippedContentRect);
760 756
761 // The owning layer's screenSpaceTransform has a scale from content to l ayer space which we need to undo and 757 // The owning layer's screenSpaceTransform has a scale from content to l ayer space which we need to undo and
762 // replace with a scale from the surface's subtree into layer space. 758 // replace with a scale from the surface's subtree into layer space.
763 gfx::Transform screenSpaceTransform = layer->screenSpaceTransform(); 759 gfx::Transform screenSpaceTransform = layer->screenSpaceTransform();
764 screenSpaceTransform.Scale(layer->contentsScaleX(), layer->contentsScale Y()); 760 screenSpaceTransform.Scale(layer->contentsScaleX() / renderSurfaceSublay erScale.x(), layer->contentsScaleY() / renderSurfaceSublayerScale.y());
765 screenSpaceTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / rende rSurfaceSublayerScale.y());
766 renderSurface->setScreenSpaceTransform(screenSpaceTransform); 761 renderSurface->setScreenSpaceTransform(screenSpaceTransform);
767 762
768 if (layer->replicaLayer()) { 763 if (layer->replicaLayer()) {
769 gfx::Transform surfaceOriginToReplicaOriginTransform; 764 gfx::Transform surfaceOriginToReplicaOriginTransform;
770 surfaceOriginToReplicaOriginTransform.Scale(renderSurfaceSublayerSca le.x(), renderSurfaceSublayerScale.y()); 765 surfaceOriginToReplicaOriginTransform.Scale(renderSurfaceSublayerSca le.x(), renderSurfaceSublayerScale.y());
771 surfaceOriginToReplicaOriginTransform.Translate(layer->replicaLayer( )->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.width(), 766 surfaceOriginToReplicaOriginTransform.Translate(layer->replicaLayer( )->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.width(),
772 layer->replicaLayer( )->position().y() + layer->replicaLayer()->anchorPoint().y() * bounds.height()); 767 layer->replicaLayer( )->position().y() + layer->replicaLayer()->anchorPoint().y() * bounds.height());
773 surfaceOriginToReplicaOriginTransform.PreconcatTransform(layer->repl icaLayer()->transform()); 768 surfaceOriginToReplicaOriginTransform.PreconcatTransform(layer->repl icaLayer()->transform());
774 surfaceOriginToReplicaOriginTransform.Translate(-layer->replicaLayer ()->anchorPoint().x() * bounds.width(), -layer->replicaLayer()->anchorPoint().y( ) * bounds.height()); 769 surfaceOriginToReplicaOriginTransform.Translate(-layer->replicaLayer ()->anchorPoint().x() * bounds.width(), -layer->replicaLayer()->anchorPoint().y( ) * bounds.height());
775 surfaceOriginToReplicaOriginTransform.Scale(1 / renderSurfaceSublaye rScale.x(), 1 / renderSurfaceSublayerScale.y()); 770 surfaceOriginToReplicaOriginTransform.Scale(1 / renderSurfaceSublaye rScale.x(), 1 / renderSurfaceSublayerScale.y());
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 988
994 foundLayer = currentLayer; 989 foundLayer = currentLayer;
995 break; 990 break;
996 } 991 }
997 992
998 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. 993 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer.
999 return foundLayer; 994 return foundLayer;
1000 } 995 }
1001 996
1002 } // namespace cc 997 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698