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

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: initialCssScale 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
« no previous file with comments | « cc/CCLayerTreeHostCommon.h ('k') | cc/CCLayerTreeHostCommonTest.cpp » ('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 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // The adjustment allows us to continue using the scrollCompensation on the next surface. 326 // The adjustment allows us to continue using the scrollCompensation on the next surface.
327 // Step 1 (right-most in the math): transform from the new surface to the o riginal ancestor surface 327 // Step 1 (right-most in the math): transform from the new surface to the o riginal ancestor surface
328 // Step 2: apply the scroll compensation 328 // Step 2: apply the scroll compensation
329 // Step 3: transform back to the new surface. 329 // Step 3: transform back to the new surface.
330 if (layer->renderSurface() && !nextScrollCompensationMatrix.isIdentity()) 330 if (layer->renderSurface() && !nextScrollCompensationMatrix.isIdentity())
331 nextScrollCompensationMatrix = layer->renderSurface()->drawTransform().i nverse() * nextScrollCompensationMatrix * layer->renderSurface()->drawTransform( ); 331 nextScrollCompensationMatrix = layer->renderSurface()->drawTransform().i nverse() * nextScrollCompensationMatrix * layer->renderSurface()->drawTransform( );
332 332
333 return nextScrollCompensationMatrix; 333 return nextScrollCompensationMatrix;
334 } 334 }
335 335
336 // There is no contentsScale on impl thread.
337 static inline void updateLayerContentsScale(CCLayerImpl*, const WebTransformatio nMatrix&, float, float) { }
338
339 static inline void updateLayerContentsScale(LayerChromium* layer, const WebTrans formationMatrix& combinedTransform, float deviceScaleFactor, float pageScaleFact or)
340 {
341 float cssScale = layer->initialCssScale();
342 if (!cssScale) {
343 WebTransformationMatrix flatTransform = combinedTransform;
enne (OOO) 2012/10/02 19:13:18 Do you want the combinedTransform here or the scre
344 CCMathUtil::flattenTransformTo2d(flatTransform);
345
346 bool clipped;
347 FloatPoint origin = CCMathUtil::mapPoint(flatTransform, FloatPoint(0, 0) , clipped);
348 FloatPoint xScale = CCMathUtil::mapPoint(flatTransform, FloatPoint(1, 0) , clipped);
349 FloatPoint yScale = CCMathUtil::mapPoint(flatTransform, FloatPoint(0, 1) , clipped);
350 float combinedScale = fmaxf(CCMathUtil::distanceBetweenPoints(xScale, or igin), CCMathUtil::distanceBetweenPoints(yScale, origin));
351 cssScale = combinedScale / deviceScaleFactor;
352 if (!layer->boundsContainPageScale())
353 cssScale /= pageScaleFactor;
354 layer->setInitialCssScale(cssScale);
355 }
356
357 float contentsScale = cssScale * deviceScaleFactor;
358 if (!layer->boundsContainPageScale())
359 contentsScale *= pageScaleFactor;
360 layer->setContentsScale(contentsScale);
361
362 LayerChromium* maskLayer = layer->maskLayer();
363 if (maskLayer)
364 maskLayer->setContentsScale(contentsScale);
365
366 LayerChromium* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLaye r()->maskLayer() : 0;
367 if (replicaMaskLayer)
368 replicaMaskLayer->setContentsScale(contentsScale);
369 }
370
336 // Should be called just before the recursive calculateDrawTransformsInternal(). 371 // Should be called just before the recursive calculateDrawTransformsInternal().
337 template<typename LayerType, typename LayerList> 372 template<typename LayerType, typename LayerList>
338 void setupRootLayerAndSurfaceForRecursion(LayerType* rootLayer, LayerList& rende rSurfaceLayerList, const IntSize& deviceViewportSize) 373 void setupRootLayerAndSurfaceForRecursion(LayerType* rootLayer, LayerList& rende rSurfaceLayerList, const IntSize& deviceViewportSize)
339 { 374 {
340 if (!rootLayer->renderSurface()) 375 if (!rootLayer->renderSurface())
341 rootLayer->createRenderSurface(); 376 rootLayer->createRenderSurface();
342 377
343 rootLayer->renderSurface()->setContentRect(IntRect(IntPoint::zero(), deviceV iewportSize)); 378 rootLayer->renderSurface()->setContentRect(IntRect(IntPoint::zero(), deviceV iewportSize));
344 rootLayer->renderSurface()->clearLayerLists(); 379 rootLayer->renderSurface()->clearLayerLists();
345 380
346 ASSERT(renderSurfaceLayerList.isEmpty()); 381 ASSERT(renderSurfaceLayerList.isEmpty());
347 renderSurfaceLayerList.append(rootLayer); 382 renderSurfaceLayerList.append(rootLayer);
348 } 383 }
349 384
350 // 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
351 // necessary transformations, clipRects, render surfaces, etc. 386 // necessary transformations, clipRects, render surfaces, etc.
352 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter> 387 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter>
353 static void calculateDrawTransformsInternal(LayerType* layer, LayerType* rootLay er, const WebTransformationMatrix& parentMatrix, 388 static void calculateDrawTransformsInternal(LayerType* layer, LayerType* rootLay er, const WebTransformationMatrix& parentMatrix,
354 const WebTransformationMatrix& fullHierarchyMatrix, const WebTransformationM atrix& currentScrollCompensationMatrix, 389 const WebTransformationMatrix& fullHierarchyMatrix, const WebTransformationM atrix& currentScrollCompensationMatrix,
355 const IntRect& clipRectFromAncestor, bool ancestorClipsSubtree, 390 const IntRect& clipRectFromAncestor, bool ancestorClipsSubtree,
356 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, 391 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList,
357 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, IntRe ct& drawableContentRectOfSubtree) 392 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, IntRect& drawableContentRectOfSubtree)
enne (OOO) 2012/10/02 19:13:18 How about an input struct to this function?
358 { 393 {
359 // This function computes the new matrix transformations recursively for thi s 394 // This function computes the new matrix transformations recursively for thi s
360 // 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.
361 // Some important points to remember: 396 // Some important points to remember:
362 // 397 //
363 // 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
364 // the transform does from left to right. 399 // the transform does from left to right.
365 // 400 //
366 // 1. In our terminology, the "layer origin" refers to the top-left corner o f a layer, and the 401 // 1. In our terminology, the "layer origin" refers to the top-left corner o f a layer, and the
367 // positive Y-axis points downwards. This interpretation is valid because the orthographic 402 // positive Y-axis points downwards. This interpretation is valid because the orthographic
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 WebTransformationMatrix combinedTransform = parentMatrix; 515 WebTransformationMatrix combinedTransform = parentMatrix;
481 combinedTransform.multiply(layerLocalTransform); 516 combinedTransform.multiply(layerLocalTransform);
482 517
483 if (layer->fixedToContainerLayer()) { 518 if (layer->fixedToContainerLayer()) {
484 // Special case: this layer is a composited fixed-position layer; we nee d to 519 // Special case: this layer is a composited fixed-position layer; we nee d to
485 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer 520 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer
486 // fixed correctly. 521 // fixed correctly.
487 combinedTransform = currentScrollCompensationMatrix * combinedTransform; 522 combinedTransform = currentScrollCompensationMatrix * combinedTransform;
488 } 523 }
489 524
525 // The layer's contentsSize is determined from the combinedTransform, which then informs the
526 // layer's drawTransform.
527 updateLayerContentsScale(layer, combinedTransform, deviceScaleFactor, pageSc aleFactor);
528
490 // 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
491 // 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.
492 WebTransformationMatrix drawTransform = combinedTransform; 531 WebTransformationMatrix drawTransform = combinedTransform;
493 // M[draw] = M[parent] * LT * Tr[anchor2center] * Tr[center2origin] 532 // M[draw] = M[parent] * LT * Tr[anchor2center] * Tr[center2origin]
494 drawTransform.translate(-layer->bounds().width() / 2.0, -layer->bounds().hei ght() / 2.0); 533 drawTransform.translate(-layer->bounds().width() / 2.0, -layer->bounds().hei ght() / 2.0);
495 if (!layer->contentBounds().isEmpty() && !layer->bounds().isEmpty()) { 534 if (!layer->contentBounds().isEmpty() && !layer->bounds().isEmpty()) {
496 // M[draw] = M[parent] * LT * Tr[anchor2origin] * S[layer2content] 535 // M[draw] = M[parent] * LT * Tr[anchor2origin] * S[layer2content]
497 drawTransform.scaleNonUniform(layer->bounds().width() / static_cast<doub le>(layer->contentBounds().width()), 536 drawTransform.scaleNonUniform(layer->bounds().width() / static_cast<doub le>(layer->contentBounds().width()),
498 layer->bounds().height() / static_cast<dou ble>(layer->contentBounds().height())); 537 layer->bounds().height() / static_cast<dou ble>(layer->contentBounds().height()));
499 } 538 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 descendants.append(layer); 679 descendants.append(layer);
641 680
642 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; 681 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);;
643 682
644 IntRect accumulatedDrawableContentRectOfChildren; 683 IntRect accumulatedDrawableContentRectOfChildren;
645 for (size_t i = 0; i < layer->children().size(); ++i) { 684 for (size_t i = 0; i < layer->children().size(); ++i) {
646 LayerType* child = CCLayerTreeHostCommon::getChildAsRawPtr(layer->childr en(), i); 685 LayerType* child = CCLayerTreeHostCommon::getChildAsRawPtr(layer->childr en(), i);
647 IntRect drawableContentRectOfChildSubtree; 686 IntRect drawableContentRectOfChildSubtree;
648 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, rootLayer, sublayerMatrix, nextHierarchyMatrix, nextScrollC ompensationMatrix, 687 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, rootLayer, sublayerMatrix, nextHierarchyMatrix, nextScrollC ompensationMatrix,
649 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels, 688 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels,
650 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, drawableContentRectOfChildSubtree); 689 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree);
651 if (!drawableContentRectOfChildSubtree.isEmpty()) { 690 if (!drawableContentRectOfChildSubtree.isEmpty()) {
652 accumulatedDrawableContentRectOfChildren.unite(drawableContentRectOf ChildSubtree); 691 accumulatedDrawableContentRectOfChildren.unite(drawableContentRectOf ChildSubtree);
653 if (child->renderSurface()) 692 if (child->renderSurface())
654 descendants.append(child); 693 descendants.append(child);
655 } 694 }
656 } 695 }
657 696
658 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space) 697 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space)
659 IntRect localDrawableContentRectOfSubtree = accumulatedDrawableContentRectOf Children; 698 IntRect localDrawableContentRectOfSubtree = accumulatedDrawableContentRectOf Children;
660 if (layer->drawsContent()) 699 if (layer->drawsContent())
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 LayerType* replicaMaskLayer = it->replicaLayer() ? it->replicaLayer( )->maskLayer() : 0; 814 LayerType* replicaMaskLayer = it->replicaLayer() ? it->replicaLayer( )->maskLayer() : 0;
776 if (replicaMaskLayer) 815 if (replicaMaskLayer)
777 replicaMaskLayer->setVisibleContentRect(IntRect(IntPoint(), it-> contentBounds())); 816 replicaMaskLayer->setVisibleContentRect(IntRect(IntPoint(), it-> contentBounds()));
778 } else if (it.representsItself()) { 817 } else if (it.representsItself()) {
779 IntRect visibleContentRect = calculateVisibleContentRect(*it); 818 IntRect visibleContentRect = calculateVisibleContentRect(*it);
780 it->setVisibleContentRect(visibleContentRect); 819 it->setVisibleContentRect(visibleContentRect);
781 } 820 }
782 } 821 }
783 } 822 }
784 823
785 void CCLayerTreeHostCommon::calculateDrawTransforms(LayerChromium* rootLayer, co nst IntSize& deviceViewportSize, float deviceScaleFactor, int maxTextureSize, Ve ctor<RefPtr<LayerChromium> >& renderSurfaceLayerList) 824 void CCLayerTreeHostCommon::calculateDrawTransforms(LayerChromium* rootLayer, co nst IntSize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSize, Vector<RefPtr<LayerChromium> >& renderSurfaceLayerList)
786 { 825 {
787 IntRect totalDrawableContentRect; 826 IntRect totalDrawableContentRect;
788 WebTransformationMatrix identityMatrix; 827 WebTransformationMatrix identityMatrix;
789 WebTransformationMatrix deviceScaleTransform; 828 WebTransformationMatrix deviceScaleTransform;
790 deviceScaleTransform.scale(deviceScaleFactor); 829 deviceScaleTransform.scale(deviceScaleFactor);
791 830
792 setupRootLayerAndSurfaceForRecursion<LayerChromium, Vector<RefPtr<LayerChrom ium> > >(rootLayer, renderSurfaceLayerList, deviceViewportSize); 831 setupRootLayerAndSurfaceForRecursion<LayerChromium, Vector<RefPtr<LayerChrom ium> > >(rootLayer, renderSurfaceLayerList, deviceViewportSize);
793 832
794 cc::calculateDrawTransformsInternal<LayerChromium, Vector<RefPtr<LayerChromi um> >, RenderSurfaceChromium, void>(rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, 833 cc::calculateDrawTransformsInternal<LayerChromium, Vector<RefPtr<LayerChromi um> >, RenderSurfaceChromium, void>(rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
795 rootLayer->renderSurface()->contentRect (), true, 0, renderSurfaceLayerList, 834 rootLayer->renderSurface()->contentRect(), t rue, 0, renderSurfaceLayerList,
796 rootLayer->renderSurface()->layerList() , 0, maxTextureSize, deviceScaleFactor, totalDrawableContentRect); 835 rootLayer->renderSurface()->layerList(), 0, maxTextureSize, deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
797 } 836 }
798 837
799 void CCLayerTreeHostCommon::calculateDrawTransforms(CCLayerImpl* rootLayer, cons t IntSize& deviceViewportSize, float deviceScaleFactor, CCLayerSorter* layerSort er, int maxTextureSize, Vector<CCLayerImpl*>& renderSurfaceLayerList) 838 void CCLayerTreeHostCommon::calculateDrawTransforms(CCLayerImpl* rootLayer, cons t IntSize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, C CLayerSorter* layerSorter, int maxTextureSize, Vector<CCLayerImpl*>& renderSurfa ceLayerList)
800 { 839 {
801 IntRect totalDrawableContentRect; 840 IntRect totalDrawableContentRect;
802 WebTransformationMatrix identityMatrix; 841 WebTransformationMatrix identityMatrix;
803 WebTransformationMatrix deviceScaleTransform; 842 WebTransformationMatrix deviceScaleTransform;
804 deviceScaleTransform.scale(deviceScaleFactor); 843 deviceScaleTransform.scale(deviceScaleFactor);
805 844
806 setupRootLayerAndSurfaceForRecursion<CCLayerImpl, Vector<CCLayerImpl*> >(roo tLayer, renderSurfaceLayerList, deviceViewportSize); 845 setupRootLayerAndSurfaceForRecursion<CCLayerImpl, Vector<CCLayerImpl*> >(roo tLayer, renderSurfaceLayerList, deviceViewportSize);
807 846
808 cc::calculateDrawTransformsInternal<CCLayerImpl, Vector<CCLayerImpl*>, CCRen derSurface, CCLayerSorter>(rootLayer, rootLayer, deviceScaleTransform, identityM atrix, identityMatrix, 847 cc::calculateDrawTransformsInternal<CCLayerImpl, Vector<CCLayerImpl*>, CCRen derSurface, CCLayerSorter>(rootLayer, rootLayer, deviceScaleTransform, identityM atrix, identityMatrix,
809 rootLayer->renderSurface()->contentRect(), true, 0, renderSurfaceLayerList, 848 rootLayer->renderSurface()->contentRect(), true, 0, r enderSurfaceLayerList,
810 rootLayer->renderSurface()->layerList(), layerSo rter, maxTextureSize, deviceScaleFactor, totalDrawableContentRect); 849 rootLayer->renderSurface()->layerList(), layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
811 } 850 }
812 851
813 void CCLayerTreeHostCommon::calculateVisibleRects(Vector<RefPtr<LayerChromium> > & renderSurfaceLayerList) 852 void CCLayerTreeHostCommon::calculateVisibleRects(Vector<RefPtr<LayerChromium> > & renderSurfaceLayerList)
814 { 853 {
815 calculateVisibleRectsInternal<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium>(renderSurfaceLayerList); 854 calculateVisibleRectsInternal<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium>(renderSurfaceLayerList);
816 } 855 }
817 856
818 void CCLayerTreeHostCommon::calculateVisibleRects(Vector<CCLayerImpl*>& renderSu rfaceLayerList) 857 void CCLayerTreeHostCommon::calculateVisibleRects(Vector<CCLayerImpl*>& renderSu rfaceLayerList)
819 { 858 {
820 calculateVisibleRectsInternal<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSur face>(renderSurfaceLayerList); 859 calculateVisibleRectsInternal<CCLayerImpl, Vector<CCLayerImpl*>, CCRenderSur face>(renderSurfaceLayerList);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 924
886 foundLayer = currentLayer; 925 foundLayer = currentLayer;
887 break; 926 break;
888 } 927 }
889 928
890 // This can potentially return 0, which means the viewportPoint did not succ essfully hit test any layers, not even the root layer. 929 // This can potentially return 0, which means the viewportPoint did not succ essfully hit test any layers, not even the root layer.
891 return foundLayer; 930 return foundLayer;
892 } 931 }
893 932
894 } // namespace cc 933 } // namespace cc
OLDNEW
« no previous file with comments | « cc/CCLayerTreeHostCommon.h ('k') | cc/CCLayerTreeHostCommonTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698