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

Side by Side Diff: cc/layer_tree_host_common.cc

Issue 12541006: Use LCD text if the transform IsAlmostIdentityAndIntegerTranslation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | « no previous file | cc/layer_tree_host_common_unittest.cc » ('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 #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 "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/heads_up_display_layer_impl.h" 10 #include "cc/heads_up_display_layer_impl.h"
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 layer->drawProperties().num_descendants_that_draw_content = numDescendantsTh atDrawContent; 539 layer->drawProperties().num_descendants_that_draw_content = numDescendantsTh atDrawContent;
540 layer->drawProperties().descendants_can_clip_selves = descendantsCanClipSelv es; 540 layer->drawProperties().descendants_can_clip_selves = descendantsCanClipSelv es;
541 } 541 }
542 542
543 static void roundTranslationComponents(gfx::Transform* transform) 543 static void roundTranslationComponents(gfx::Transform* transform)
544 { 544 {
545 transform->matrix().setDouble(0, 3, MathUtil::Round(transform->matrix().getD ouble(0, 3))); 545 transform->matrix().setDouble(0, 3, MathUtil::Round(transform->matrix().getD ouble(0, 3)));
546 transform->matrix().setDouble(1, 3, MathUtil::Round(transform->matrix().getD ouble(1, 3))); 546 transform->matrix().setDouble(1, 3, MathUtil::Round(transform->matrix().getD ouble(1, 3)));
547 } 547 }
548 548
549 static void roundAlmostIntegerComponent(SkMatrix44* matrix, int i, int j)
550 {
551 const double kErrorThreshold = 0.0001;
552 double d = matrix->getDouble(i, j);
553 double rounded = MathUtil::Round(d);
554 double error = std::abs(rounded - d);
555 if (error > 0 && error < kErrorThreshold)
556 matrix->setDouble(i, j, rounded);
557 }
558
559 // Tiny errors caused by multiple multiplications and divisions on mixed double
560 // and float operands may result almost-integer scales and translations like
561 // 1.00001. Round them so that some transform can be identity as expected.
562 static void roundAlmostIntegerScalesAndTranslationComponents(gfx::Transform* tra nsform)
563 {
564 if (transform->IsScaleOrTranslation() && !transform->IsIdentityOrTranslation ()) {
Ian Vollick 2013/03/07 21:18:36 Unless I'm reading this wrong, it looks like we'll
565 SkMatrix44* matrix = &transform->matrix();
566 roundAlmostIntegerComponent(matrix, 0, 0);
567 roundAlmostIntegerComponent(matrix, 1, 1);
568 roundAlmostIntegerComponent(matrix, 0, 3);
569 roundAlmostIntegerComponent(matrix, 1, 3);
570 }
571 }
572
549 // Recursively walks the layer tree starting at the given node and computes all the 573 // Recursively walks the layer tree starting at the given node and computes all the
550 // necessary transformations, clipRects, render surfaces, etc. 574 // necessary transformations, clipRects, render surfaces, etc.
551 template<typename LayerType, typename LayerList, typename RenderSurfaceType> 575 template<typename LayerType, typename LayerList, typename RenderSurfaceType>
552 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, 576 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix,
553 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, 577 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix,
554 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree, 578 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree,
555 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, 579 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList,
556 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText, 580 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText,
557 gfx::Rect& drawableContentRectOfSubtree, bool updateTilePriorities) 581 gfx::Rect& drawableContentRectOfSubtree, bool updateTilePriorities)
558 { 582 {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // fixed correctly. 736 // fixed correctly.
713 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform). 737 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform).
714 combinedTransform.ConcatTransform(currentScrollCompensationMatrix); 738 combinedTransform.ConcatTransform(currentScrollCompensationMatrix);
715 } 739 }
716 740
717 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless 741 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless
718 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms. 742 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms.
719 layerDrawProperties.target_space_transform = combinedTransform; 743 layerDrawProperties.target_space_transform = combinedTransform;
720 // M[draw] = M[parent] * LT * S[layer2content] 744 // M[draw] = M[parent] * LT * S[layer2content]
721 layerDrawProperties.target_space_transform.Scale(1.0 / layer->contentsScaleX (), 1.0 / layer->contentsScaleY()); 745 layerDrawProperties.target_space_transform.Scale(1.0 / layer->contentsScaleX (), 1.0 / layer->contentsScaleY());
746 // Eliminate the tiny errors in scales and translations to prevent the error s from propagating,
747 // to prevent bluriness and ensures LCDText working as expected.
748 roundAlmostIntegerScalesAndTranslationComponents(&layerDrawProperties.target _space_transform);
enne (OOO) 2013/03/07 19:05:34 Is it ok to round the draw transform but not the s
Xianzhu 2013/03/07 19:38:17 I think the rounding will reflect in screen_space_
shawnsingh 2013/03/07 20:13:36 I agree with Xianzhu, it should be OK with respect
Ian Vollick 2013/03/07 21:18:36 I'd considered tackling this sort of rounding, too
722 749
723 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space. 750 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space.
724 layerDrawProperties.screen_space_transform = fullHierarchyMatrix; 751 layerDrawProperties.screen_space_transform = fullHierarchyMatrix;
725 if (!layer->preserves3D()) 752 if (!layer->preserves3D())
726 layerDrawProperties.screen_space_transform.FlattenTo2d(); 753 layerDrawProperties.screen_space_transform.FlattenTo2d();
727 layerDrawProperties.screen_space_transform.PreconcatTransform(layerDrawPrope rties.target_space_transform); 754 layerDrawProperties.screen_space_transform.PreconcatTransform(layerDrawPrope rties.target_space_transform);
728 755
729 // Adjusting text AA method during animation may cause repaints, which in-tu rn causes jank. 756 // Adjusting text AA method during animation may cause repaints, which in-tu rn causes jank.
730 bool adjustTextAA = !animatingOpacityToScreen && !animatingTransformToScreen ; 757 bool adjustTextAA = !animatingOpacityToScreen && !animatingTransformToScreen ;
731 // To avoid color fringing, LCD text should only be used on opaque layers wi th just integral translation. 758 // To avoid color fringing, LCD text should only be used on opaque layers wi th just integral translation.
(...skipping 25 matching lines...) Expand all
757 // space which we do not want; so here we use the combinedTransform 784 // space which we do not want; so here we use the combinedTransform
758 // instead of the drawTransform. However, we do need to add a different 785 // instead of the drawTransform. However, we do need to add a different
759 // scale factor that accounts for the surface's pixel dimensions. 786 // scale factor that accounts for the surface's pixel dimensions.
760 combinedTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / renderSu rfaceSublayerScale.y()); 787 combinedTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / renderSu rfaceSublayerScale.y());
761 renderSurface->setDrawTransform(combinedTransform); 788 renderSurface->setDrawTransform(combinedTransform);
762 789
763 // The owning layer's transform was re-parented by the surface, so the l ayer's new drawTransform 790 // The owning layer's transform was re-parented by the surface, so the l ayer's new drawTransform
764 // only needs to scale the layer to surface space. 791 // only needs to scale the layer to surface space.
765 layerDrawProperties.target_space_transform.MakeIdentity(); 792 layerDrawProperties.target_space_transform.MakeIdentity();
766 layerDrawProperties.target_space_transform.Scale(renderSurfaceSublayerSc ale.x() / layer->contentsScaleX(), renderSurfaceSublayerScale.y() / layer->conte ntsScaleY()); 793 layerDrawProperties.target_space_transform.Scale(renderSurfaceSublayerSc ale.x() / layer->contentsScaleX(), renderSurfaceSublayerScale.y() / layer->conte ntsScaleY());
794 // Eliminate the tiny errors in scales and translations to prevent the e rrors from propagating,
795 // to prevent bluriness and to ensure LCDText working as expected.
796 roundAlmostIntegerScalesAndTranslationComponents(&layerDrawProperties.ta rget_space_transform);
enne (OOO) 2013/03/07 19:05:34 I don't understand what this change does. The LCD
Xianzhu 2013/03/07 19:38:17 Based on the exisiting code, we enable LCD text on
enne (OOO) 2013/03/07 20:19:36 What you say is correct. However, we enable LCD t
767 797
768 // Inside the surface's subtree, we scale everything to the owning layer 's scale. 798 // Inside the surface's subtree, we scale everything to the owning layer 's scale.
769 // The sublayer matrix transforms layer rects into target 799 // The sublayer matrix transforms layer rects into target
770 // surface content space. 800 // surface content space.
771 DCHECK(sublayerMatrix.IsIdentity()); 801 DCHECK(sublayerMatrix.IsIdentity());
772 sublayerMatrix.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSublay erScale.y()); 802 sublayerMatrix.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSublay erScale.y());
773 803
774 // The opacity value is moved from the layer to its surface, so that the entire subtree properly inherits opacity. 804 // The opacity value is moved from the layer to its surface, so that the entire subtree properly inherits opacity.
775 renderSurface->setDrawOpacity(accumulatedDrawOpacity); 805 renderSurface->setDrawOpacity(accumulatedDrawOpacity);
776 renderSurface->setDrawOpacityIsAnimating(animatingOpacityToTarget); 806 renderSurface->setDrawOpacityIsAnimating(animatingOpacityToTarget);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 1244
1215 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up 1245 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up
1216 // the parents to ensure that the layer was not clipped in such a way that the 1246 // the parents to ensure that the layer was not clipped in such a way that the
1217 // hit point actually should not hit the layer. 1247 // hit point actually should not hit the layer.
1218 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) 1248 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl))
1219 return false; 1249 return false;
1220 1250
1221 return true; 1251 return true;
1222 } 1252 }
1223 } // namespace cc 1253 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698