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

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: Fixed bad math substitution, performance improvements still roughly the same 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 = 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 522 // If there is a transformation from the impl thread then it should be at
526 // start of the combinedTransform, but we don't want it to affect the conten tsScale. 523 // the start of the combinedTransform, but we don't want it to affect the
527 combinedTransform = layer->implTransform() * combinedTransform; 524 // computation of contentsScale above.
525 // Note Carefully: this is Concat, not Preconcat (implTransform * combinedTr ansform).
danakj 2012/12/04 18:27:43 nit: carefully lowercase
526 combinedTransform.ConcatTransform(layer->implTransform());
528 527
529 if (layer->fixedToContainerLayer()) { 528 if (layer->fixedToContainerLayer()) {
530 // Special case: this layer is a composited fixed-position layer; we nee d to 529 // 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 530 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer
532 // fixed correctly. 531 // fixed correctly.
533 combinedTransform = currentScrollCompensationMatrix * combinedTransform; 532 // Note Carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform).
danakj 2012/12/04 18:27:43 same
533 combinedTransform.ConcatTransform(currentScrollCompensationMatrix);
534 } 534 }
535 535
536 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless 536 // 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. 537 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms.
538 gfx::Transform drawTransform = combinedTransform; 538 gfx::Transform drawTransform = combinedTransform;
539 // M[draw] = M[parent] * LT * S[layer2content] 539 // M[draw] = M[parent] * LT * S[layer2content]
540 drawTransform.Scale(1.0 / layer->contentsScaleX(), 1.0 / layer->contentsScal eY()); 540 drawTransform.Scale(1.0 / layer->contentsScaleX(), 1.0 / layer->contentsScal eY());
541 541
542 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space. 542 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space.
543 gfx::Transform layerScreenSpaceTransform = fullHierarchyMatrix; 543 gfx::Transform layerScreenSpaceTransform = fullHierarchyMatrix;
(...skipping 15 matching lines...) Expand all
559 // Check back-face visibility before continuing with this surface and it s subtree 559 // Check back-face visibility before continuing with this surface and it s subtree
560 if (!layer->doubleSided() && transformToParentIsKnown(layer) && isSurfac eBackFaceVisible(layer, combinedTransform)) 560 if (!layer->doubleSided() && transformToParentIsKnown(layer) && isSurfac eBackFaceVisible(layer, combinedTransform))
561 return; 561 return;
562 562
563 if (!layer->renderSurface()) 563 if (!layer->renderSurface())
564 layer->createRenderSurface(); 564 layer->createRenderSurface();
565 565
566 RenderSurfaceType* renderSurface = layer->renderSurface(); 566 RenderSurfaceType* renderSurface = layer->renderSurface();
567 renderSurface->clearLayerLists(); 567 renderSurface->clearLayerLists();
568 568
569 // The owning layer's draw transform has a scale from content to layer s pace which we need to undo and 569 // 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. 570 // space which do not want; so here we use the combinedTransform
danakj 2012/12/04 18:27:43 nit: "which do not want"
571 drawTransform.Scale(layer->contentsScaleX(), layer->contentsScaleY()); 571 // instead of the drawTransform. However, we do need to add a different
572 drawTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / renderSurfac eSublayerScale.y()); 572 // scale factor that accounts for the surface's pixel dimensions.
573 renderSurface->setDrawTransform(drawTransform); 573 combinedTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / renderSu rfaceSublayerScale.y());
danakj 2012/12/04 18:27:43 changing the combinedTransform makes me a bit unco
shawnsingh 2012/12/04 18:31:39 I think this is most likely going to be a non-issu
danakj 2012/12/04 18:32:48 Thanks for the reassurance. :)
574 renderSurface->setDrawTransform(combinedTransform);
574 575
575 // The origin of the new surface is the upper left corner of the layer. 576 // 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.
576 gfx::Transform layerDrawTransform; 578 gfx::Transform layerDrawTransform;
577 layerDrawTransform.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSu blayerScale.y()); 579 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); 580 layer->setDrawTransform(layerDrawTransform);
580 581
581 // Inside the surface's subtree, we scale everything to the owning layer 's scale. 582 // Inside the surface's subtree, we scale everything to the owning layer 's scale.
582 // The sublayer matrix transforms centered layer rects into target 583 // The sublayer matrix transforms centered layer rects into target
583 // surface content space. 584 // surface content space.
584 sublayerMatrix.MakeIdentity(); 585 DCHECK(sublayerMatrix.IsIdentity());
585 sublayerMatrix.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSublay erScale.y()); 586 sublayerMatrix.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSublay erScale.y());
586 587
587 // The opacity value is moved from the layer to its surface, so that the entire subtree properly inherits opacity. 588 // The opacity value is moved from the layer to its surface, so that the entire subtree properly inherits opacity.
588 renderSurface->setDrawOpacity(drawOpacity); 589 renderSurface->setDrawOpacity(drawOpacity);
589 renderSurface->setDrawOpacityIsAnimating(drawOpacityIsAnimating); 590 renderSurface->setDrawOpacityIsAnimating(drawOpacityIsAnimating);
590 layer->setDrawOpacity(1); 591 layer->setDrawOpacity(1);
591 layer->setDrawOpacityIsAnimating(false); 592 layer->setDrawOpacityIsAnimating(false);
592 593
593 renderSurface->setTargetSurfaceTransformsAreAnimating(animatingTransform ToTarget); 594 renderSurface->setTargetSurfaceTransformsAreAnimating(animatingTransform ToTarget);
594 renderSurface->setScreenSpaceTransformsAreAnimating(animatingTransformTo Screen); 595 renderSurface->setScreenSpaceTransformsAreAnimating(animatingTransformTo Screen);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 clipRectForSubtree.Intersect(rectInTargetSpace); 663 clipRectForSubtree.Intersect(rectInTargetSpace);
663 } else 664 } else
664 clipRectForSubtree = rectInTargetSpace; 665 clipRectForSubtree = rectInTargetSpace;
665 } 666 }
666 667
667 // Flatten to 2D if the layer doesn't preserve 3D. 668 // Flatten to 2D if the layer doesn't preserve 3D.
668 if (!layer->preserves3D()) 669 if (!layer->preserves3D())
669 MathUtil::flattenTransformTo2d(sublayerMatrix); 670 MathUtil::flattenTransformTo2d(sublayerMatrix);
670 671
671 // Apply the sublayer transform at the center of the layer. 672 // Apply the sublayer transform at the center of the layer.
672 sublayerMatrix.Translate(0.5 * bounds.width(), 0.5 * bounds.height()); 673 if (!layer->sublayerTransform().IsIdentity()) {
673 sublayerMatrix.PreconcatTransform(layer->sublayerTransform()); 674 sublayerMatrix.Translate(0.5 * bounds.width(), 0.5 * bounds.height());
674 sublayerMatrix.Translate(-0.5 * bounds.width(), -0.5 * bounds.height()); 675 sublayerMatrix.PreconcatTransform(layer->sublayerTransform());
676 sublayerMatrix.Translate(-0.5 * bounds.width(), -0.5 * bounds.height());
677 }
675 678
676 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList); 679 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList);
677 680
678 // Any layers that are appended after this point are in the layer's subtree and should be included in the sorting process. 681 // 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(); 682 unsigned sortingStartIndex = descendants.size();
680 683
681 if (!layerShouldBeSkipped(layer)) 684 if (!layerShouldBeSkipped(layer))
682 descendants.push_back(layer); 685 descendants.push_back(layer);
683 686
684 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; 687 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)); 757 clippedContentRect.set_height(std::min(clippedContentRect.height(), maxT extureSize));
755 758
756 if (clippedContentRect.IsEmpty()) 759 if (clippedContentRect.IsEmpty())
757 renderSurface->clearLayerLists(); 760 renderSurface->clearLayerLists();
758 761
759 renderSurface->setContentRect(clippedContentRect); 762 renderSurface->setContentRect(clippedContentRect);
760 763
761 // The owning layer's screenSpaceTransform has a scale from content to l ayer space which we need to undo and 764 // 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. 765 // replace with a scale from the surface's subtree into layer space.
763 gfx::Transform screenSpaceTransform = layer->screenSpaceTransform(); 766 gfx::Transform screenSpaceTransform = layer->screenSpaceTransform();
764 screenSpaceTransform.Scale(layer->contentsScaleX(), layer->contentsScale Y()); 767 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); 768 renderSurface->setScreenSpaceTransform(screenSpaceTransform);
767 769
768 if (layer->replicaLayer()) { 770 if (layer->replicaLayer()) {
769 gfx::Transform surfaceOriginToReplicaOriginTransform; 771 gfx::Transform surfaceOriginToReplicaOriginTransform;
770 surfaceOriginToReplicaOriginTransform.Scale(renderSurfaceSublayerSca le.x(), renderSurfaceSublayerScale.y()); 772 surfaceOriginToReplicaOriginTransform.Scale(renderSurfaceSublayerSca le.x(), renderSurfaceSublayerScale.y());
771 surfaceOriginToReplicaOriginTransform.Translate(layer->replicaLayer( )->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.width(), 773 surfaceOriginToReplicaOriginTransform.Translate(layer->replicaLayer( )->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.width(),
772 layer->replicaLayer( )->position().y() + layer->replicaLayer()->anchorPoint().y() * bounds.height()); 774 layer->replicaLayer( )->position().y() + layer->replicaLayer()->anchorPoint().y() * bounds.height());
773 surfaceOriginToReplicaOriginTransform.PreconcatTransform(layer->repl icaLayer()->transform()); 775 surfaceOriginToReplicaOriginTransform.PreconcatTransform(layer->repl icaLayer()->transform());
774 surfaceOriginToReplicaOriginTransform.Translate(-layer->replicaLayer ()->anchorPoint().x() * bounds.width(), -layer->replicaLayer()->anchorPoint().y( ) * bounds.height()); 776 surfaceOriginToReplicaOriginTransform.Translate(-layer->replicaLayer ()->anchorPoint().x() * bounds.width(), -layer->replicaLayer()->anchorPoint().y( ) * bounds.height());
775 surfaceOriginToReplicaOriginTransform.Scale(1 / renderSurfaceSublaye rScale.x(), 1 / renderSurfaceSublayerScale.y()); 777 surfaceOriginToReplicaOriginTransform.Scale(1 / renderSurfaceSublaye rScale.x(), 1 / renderSurfaceSublayerScale.y());
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 995
994 foundLayer = currentLayer; 996 foundLayer = currentLayer;
995 break; 997 break;
996 } 998 }
997 999
998 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. 1000 // 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; 1001 return foundLayer;
1000 } 1002 }
1001 1003
1002 } // namespace cc 1004 } // 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