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

Side by Side Diff: cc/CCLayerTreeHostCommon.cpp

Issue 10915313: cc: Apply the layer's initial CSS scale to the contentsScale to render text at the right resolution. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove extra header Created 8 years, 3 months 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 5
6 #include "config.h" 6 #include "config.h"
7 7
8 #include "CCLayerTreeHostCommon.h" 8 #include "CCLayerTreeHostCommon.h"
9 9
10 #include "CCLayerImpl.h" 10 #include "CCLayerImpl.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // The adjustment allows us to continue using the scrollCompensation on the next surface. 318 // The adjustment allows us to continue using the scrollCompensation on the next surface.
319 // Step 1 (right-most in the math): transform from the new surface to the o riginal ancestor surface 319 // Step 1 (right-most in the math): transform from the new surface to the o riginal ancestor surface
320 // Step 2: apply the scroll compensation 320 // Step 2: apply the scroll compensation
321 // Step 3: transform back to the new surface. 321 // Step 3: transform back to the new surface.
322 if (layer->renderSurface() && !nextScrollCompensationMatrix.isIdentity()) 322 if (layer->renderSurface() && !nextScrollCompensationMatrix.isIdentity())
323 nextScrollCompensationMatrix = layer->renderSurface()->drawTransform().i nverse() * nextScrollCompensationMatrix * layer->renderSurface()->drawTransform( ); 323 nextScrollCompensationMatrix = layer->renderSurface()->drawTransform().i nverse() * nextScrollCompensationMatrix * layer->renderSurface()->drawTransform( );
324 324
325 return nextScrollCompensationMatrix; 325 return nextScrollCompensationMatrix;
326 } 326 }
327 327
328 // There is no contentsScale on impl thread.
329 static inline void updateLayerContentsScale(CCLayerImpl*, float, float) { }
330
331 static inline void updateLayerContentsScale(LayerChromium* layer, float combined Scale, float pageScaleFactor)
332 {
333 if (layer->transformIsAnimating())
334 return;
335
336 float contentsScale = combinedScale;
337
338 // FIXME: Remove this when pageScaleFactor is applied in the compositor and becomes part of the parentTransform during the tree walk.
339 if (!layer->boundsContainPageScale())
340 contentsScale *= pageScaleFactor;
341
342 layer->setContentsScale(contentsScale);
343
344 LayerChromium* maskLayer = layer->maskLayer();
345 if (maskLayer)
346 maskLayer->setContentsScale(contentsScale);
347
348 LayerChromium* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLaye r()->maskLayer() : 0;
349 if (replicaMaskLayer)
350 replicaMaskLayer->setContentsScale(contentsScale);
351 }
352
328 // Should be called just before the recursive calculateDrawTransformsInternal(). 353 // Should be called just before the recursive calculateDrawTransformsInternal().
329 template<typename LayerType, typename LayerList> 354 template<typename LayerType, typename LayerList>
330 void setupRootLayerAndSurfaceForRecursion(LayerType* rootLayer, LayerList& rende rSurfaceLayerList, const IntSize& deviceViewportSize) 355 void setupRootLayerAndSurfaceForRecursion(LayerType* rootLayer, LayerList& rende rSurfaceLayerList, const IntSize& deviceViewportSize)
331 { 356 {
332 if (!rootLayer->renderSurface()) 357 if (!rootLayer->renderSurface())
333 rootLayer->createRenderSurface(); 358 rootLayer->createRenderSurface();
334 359
335 rootLayer->renderSurface()->setContentRect(IntRect(IntPoint::zero(), deviceV iewportSize)); 360 rootLayer->renderSurface()->setContentRect(IntRect(IntPoint::zero(), deviceV iewportSize));
336 rootLayer->renderSurface()->clearLayerList(); 361 rootLayer->renderSurface()->clearLayerList();
337 362
338 ASSERT(renderSurfaceLayerList.isEmpty()); 363 ASSERT(renderSurfaceLayerList.isEmpty());
339 renderSurfaceLayerList.append(rootLayer); 364 renderSurfaceLayerList.append(rootLayer);
340 } 365 }
341 366
342 // Recursively walks the layer tree starting at the given node and computes all the 367 // Recursively walks the layer tree starting at the given node and computes all the
343 // necessary transformations, clipRects, render surfaces, etc. 368 // necessary transformations, clipRects, render surfaces, etc.
344 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter> 369 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter>
345 static void calculateDrawTransformsInternal(LayerType* layer, LayerType* rootLay er, const WebTransformationMatrix& parentMatrix, 370 static void calculateDrawTransformsInternal(LayerType* layer, LayerType* rootLay er, const WebTransformationMatrix& parentMatrix,
346 const WebTransformationMatrix& fullHierarchyMatrix, const WebTransformationM atrix& currentScrollCompensationMatrix, 371 const WebTransformationMatrix& fullHierarchyMatrix, const WebTransformationM atrix& currentScrollCompensationMatrix,
347 const IntRect& clipRectFromAncestor, bool ancestorClipsSubtree, 372 const IntRect& clipRectFromAncestor, bool ancestorClipsSubtree,
348 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, 373 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList,
349 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, IntRe ct& drawableContentRectOfSubtree) 374 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, IntRect& drawableContentRectOfSubtree)
350 { 375 {
351 // This function computes the new matrix transformations recursively for thi s 376 // This function computes the new matrix transformations recursively for thi s
352 // layer and all its descendants. It also computes the appropriate render su rfaces. 377 // layer and all its descendants. It also computes the appropriate render su rfaces.
353 // Some important points to remember: 378 // Some important points to remember:
354 // 379 //
355 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what 380 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what
356 // the transform does from left to right. 381 // the transform does from left to right.
357 // 382 //
358 // 1. In our terminology, the "layer origin" refers to the top-left corner o f a layer, and the 383 // 1. In our terminology, the "layer origin" refers to the top-left corner o f a layer, and the
359 // positive Y-axis points downwards. This interpretation is valid because the orthographic 384 // positive Y-axis points downwards. This interpretation is valid because the orthographic
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 WebTransformationMatrix combinedTransform = parentMatrix; 497 WebTransformationMatrix combinedTransform = parentMatrix;
473 combinedTransform.multiply(layerLocalTransform); 498 combinedTransform.multiply(layerLocalTransform);
474 499
475 if (layer->fixedToContainerLayer()) { 500 if (layer->fixedToContainerLayer()) {
476 // Special case: this layer is a composited fixed-position layer; we nee d to 501 // Special case: this layer is a composited fixed-position layer; we nee d to
477 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer 502 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer
478 // fixed correctly. 503 // fixed correctly.
479 combinedTransform = currentScrollCompensationMatrix * combinedTransform; 504 combinedTransform = currentScrollCompensationMatrix * combinedTransform;
480 } 505 }
481 506
507 // The layer's contentsSize is determined from the combinedTransform, which then informs the
508 // layer's drawTransform.
509 float combinedScale = 1;
510 if (!layer->transformIsAnimating()) {
511 WebTransformationMatrix flatTransform = combinedTransform;
512 CCMathUtil::flattenTransformTo2d(flatTransform);
513
514 bool clipped;
515 FloatPoint origin = CCMathUtil::mapPoint(flatTransform, FloatPoint(0, 0) , clipped);
516 FloatPoint xScale = CCMathUtil::mapPoint(flatTransform, FloatPoint(1, 0) , clipped);
517 FloatPoint yScale = CCMathUtil::mapPoint(flatTransform, FloatPoint(0, 1) , clipped);
518 combinedScale = fmaxf(CCMathUtil::distanceBetweenPoints(xScale, origin), CCMathUtil::distanceBetweenPoints(yScale, origin));
519 }
520 updateLayerContentsScale(layer, combinedScale, pageScaleFactor);
521
482 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless 522 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless
483 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms. 523 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms.
484 WebTransformationMatrix drawTransform = combinedTransform; 524 WebTransformationMatrix drawTransform = combinedTransform;
485 // M[draw] = M[parent] * LT * Tr[anchor2center] * Tr[center2origin] 525 // M[draw] = M[parent] * LT * Tr[anchor2center] * Tr[center2origin]
486 drawTransform.translate(-layer->bounds().width() / 2.0, -layer->bounds().hei ght() / 2.0); 526 drawTransform.translate(-layer->bounds().width() / 2.0, -layer->bounds().hei ght() / 2.0);
487 if (!layer->contentBounds().isEmpty() && !layer->bounds().isEmpty()) { 527 if (!layer->contentBounds().isEmpty() && !layer->bounds().isEmpty()) {
488 // M[draw] = M[parent] * LT * Tr[anchor2origin] * S[layer2content] 528 // M[draw] = M[parent] * LT * Tr[anchor2origin] * S[layer2content]
489 drawTransform.scaleNonUniform(layer->bounds().width() / static_cast<doub le>(layer->contentBounds().width()), 529 drawTransform.scaleNonUniform(layer->bounds().width() / static_cast<doub le>(layer->contentBounds().width()),
490 layer->bounds().height() / static_cast<dou ble>(layer->contentBounds().height())); 530 layer->bounds().height() / static_cast<dou ble>(layer->contentBounds().height()));
491 } 531 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 descendants.append(layer); 672 descendants.append(layer);
633 673
634 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; 674 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);;
635 675
636 IntRect accumulatedDrawableContentRectOfChildren; 676 IntRect accumulatedDrawableContentRectOfChildren;
637 for (size_t i = 0; i < layer->children().size(); ++i) { 677 for (size_t i = 0; i < layer->children().size(); ++i) {
638 LayerType* child = layer->children()[i].get(); 678 LayerType* child = layer->children()[i].get();
639 IntRect drawableContentRectOfChildSubtree; 679 IntRect drawableContentRectOfChildSubtree;
640 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, rootLayer, sublayerMatrix, nextHierarchyMatrix, nextScrollC ompensationMatrix, 680 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, rootLayer, sublayerMatrix, nextHierarchyMatrix, nextScrollC ompensationMatrix,
641 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels, 681 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels,
642 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, drawableContentRectOfChildSubtree); 682 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree);
643 if (!drawableContentRectOfChildSubtree.isEmpty()) { 683 if (!drawableContentRectOfChildSubtree.isEmpty()) {
644 accumulatedDrawableContentRectOfChildren.unite(drawableContentRectOf ChildSubtree); 684 accumulatedDrawableContentRectOfChildren.unite(drawableContentRectOf ChildSubtree);
645 if (child->renderSurface()) 685 if (child->renderSurface())
646 descendants.append(child); 686 descendants.append(child);
647 } 687 }
648 } 688 }
649 689
650 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space) 690 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space)
651 IntRect localDrawableContentRectOfSubtree = accumulatedDrawableContentRectOf Children; 691 IntRect localDrawableContentRectOfSubtree = accumulatedDrawableContentRectOf Children;
652 if (layer->drawsContent()) 692 if (layer->drawsContent())
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 LayerType* replicaMaskLayer = it->replicaLayer() ? it->replicaLayer( )->maskLayer() : 0; 806 LayerType* replicaMaskLayer = it->replicaLayer() ? it->replicaLayer( )->maskLayer() : 0;
767 if (replicaMaskLayer) 807 if (replicaMaskLayer)
768 replicaMaskLayer->setVisibleContentRect(IntRect(IntPoint(), it-> contentBounds())); 808 replicaMaskLayer->setVisibleContentRect(IntRect(IntPoint(), it-> contentBounds()));
769 } else if (it.representsItself()) { 809 } else if (it.representsItself()) {
770 IntRect visibleContentRect = calculateVisibleContentRect(*it); 810 IntRect visibleContentRect = calculateVisibleContentRect(*it);
771 it->setVisibleContentRect(visibleContentRect); 811 it->setVisibleContentRect(visibleContentRect);
772 } 812 }
773 } 813 }
774 } 814 }
775 815
776 void CCLayerTreeHostCommon::calculateDrawTransforms(LayerChromium* rootLayer, co nst IntSize& deviceViewportSize, float deviceScaleFactor, int maxTextureSize, Ve ctor<RefPtr<LayerChromium> >& renderSurfaceLayerList) 816 void CCLayerTreeHostCommon::calculateDrawTransforms(LayerChromium* rootLayer, co nst IntSize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSize, Vector<RefPtr<LayerChromium> >& renderSurfaceLayerList)
777 { 817 {
778 IntRect totalDrawableContentRect; 818 IntRect totalDrawableContentRect;
779 WebTransformationMatrix identityMatrix; 819 WebTransformationMatrix identityMatrix;
780 WebTransformationMatrix deviceScaleTransform; 820 WebTransformationMatrix deviceScaleTransform;
781 deviceScaleTransform.scale(deviceScaleFactor); 821 deviceScaleTransform.scale(deviceScaleFactor);
782 822
783 setupRootLayerAndSurfaceForRecursion<LayerChromium, Vector<RefPtr<LayerChrom ium> > >(rootLayer, renderSurfaceLayerList, deviceViewportSize); 823 setupRootLayerAndSurfaceForRecursion<LayerChromium, Vector<RefPtr<LayerChrom ium> > >(rootLayer, renderSurfaceLayerList, deviceViewportSize);
784 824
785 cc::calculateDrawTransformsInternal<LayerChromium, Vector<RefPtr<LayerChromi um> >, RenderSurfaceChromium, void>(rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, 825 cc::calculateDrawTransformsInternal<LayerChromium, Vector<RefPtr<LayerChromi um> >, RenderSurfaceChromium, void>(rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
786 rootLayer->renderSurface()->contentRect (), true, 0, renderSurfaceLayerList, 826 rootLayer->renderSurface()->contentRect(), t rue, 0, renderSurfaceLayerList,
787 rootLayer->renderSurface()->layerList() , 0, maxTextureSize, deviceScaleFactor, totalDrawableContentRect); 827 rootLayer->renderSurface()->layerList(), 0, maxTextureSize, deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
788 } 828 }
789 829
790 void CCLayerTreeHostCommon::calculateDrawTransforms(CCLayerImpl* rootLayer, cons t IntSize& deviceViewportSize, float deviceScaleFactor, CCLayerSorter* layerSort er, int maxTextureSize, Vector<CCLayerImpl*>& renderSurfaceLayerList) 830 void CCLayerTreeHostCommon::calculateDrawTransforms(CCLayerImpl* rootLayer, cons t IntSize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, C CLayerSorter* layerSorter, int maxTextureSize, Vector<CCLayerImpl*>& renderSurfa ceLayerList)
791 { 831 {
792 IntRect totalDrawableContentRect; 832 IntRect totalDrawableContentRect;
793 WebTransformationMatrix identityMatrix; 833 WebTransformationMatrix identityMatrix;
794 WebTransformationMatrix deviceScaleTransform; 834 WebTransformationMatrix deviceScaleTransform;
795 deviceScaleTransform.scale(deviceScaleFactor); 835 deviceScaleTransform.scale(deviceScaleFactor);
796 836
797 setupRootLayerAndSurfaceForRecursion<CCLayerImpl, Vector<CCLayerImpl*> >(roo tLayer, renderSurfaceLayerList, deviceViewportSize); 837 setupRootLayerAndSurfaceForRecursion<CCLayerImpl, Vector<CCLayerImpl*> >(roo tLayer, renderSurfaceLayerList, deviceViewportSize);
798 838
799 cc::calculateDrawTransformsInternal<CCLayerImpl, Vector<CCLayerImpl*>, CCRen derSurface, CCLayerSorter>(rootLayer, rootLayer, deviceScaleTransform, identityM atrix, identityMatrix, 839 cc::calculateDrawTransformsInternal<CCLayerImpl, Vector<CCLayerImpl*>, CCRen derSurface, CCLayerSorter>(rootLayer, rootLayer, deviceScaleTransform, identityM atrix, identityMatrix,
800 rootLayer->renderSurface()->contentRect(), true, 0, renderSurfaceLayerList, 840 rootLayer->renderSurface()->contentRect(), true, 0, r enderSurfaceLayerList,
801 rootLayer->renderSurface()->layerList(), layerSo rter, maxTextureSize, deviceScaleFactor, totalDrawableContentRect); 841 rootLayer->renderSurface()->layerList(), layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
802 } 842 }
803 843
804 void CCLayerTreeHostCommon::calculateVisibleRects(Vector<RefPtr<LayerChromium> > & renderSurfaceLayerList) 844 void CCLayerTreeHostCommon::calculateVisibleRects(Vector<RefPtr<LayerChromium> > & renderSurfaceLayerList)
805 { 845 {
806 calculateVisibleRectsInternal<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium>(renderSurfaceLayerList); 846 calculateVisibleRectsInternal<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium>(renderSurfaceLayerList);
807 } 847 }
808 848
809 void CCLayerTreeHostCommon::calculateVisibleRects(Vector<CCLayerImpl*>& renderSu rfaceLayerList) 849 void CCLayerTreeHostCommon::calculateVisibleRects(Vector<CCLayerImpl*>& renderSu rfaceLayerList)
810 { 850 {
811 calculateVisibleRectsInternal<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSur face>(renderSurfaceLayerList); 851 calculateVisibleRectsInternal<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSur face>(renderSurfaceLayerList);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 916
877 foundLayer = currentLayer; 917 foundLayer = currentLayer;
878 break; 918 break;
879 } 919 }
880 920
881 // This can potentially return 0, which means the viewportPoint did not succ essfully hit test any layers, not even the root layer. 921 // This can potentially return 0, which means the viewportPoint did not succ essfully hit test any layers, not even the root layer.
882 return foundLayer; 922 return foundLayer;
883 } 923 }
884 924
885 } // namespace cc 925 } // namespace cc
OLDNEW
« no previous file with comments | « cc/CCLayerTreeHostCommon.h ('k') | cc/CCLayerTreeHostCommonTest.cpp » ('j') | cc/CCMathUtil.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698