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

Side by Side Diff: cc/layer_tree_host_common.cc

Issue 12407002: Align physical pixels of scrolled layers (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 | « cc/layer_tree_host_common.h ('k') | 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 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 !childLayer->drawProperties().descendants_can_clip_selves || 533 !childLayer->drawProperties().descendants_can_clip_selves ||
534 sublayerTransformPreventsClip || 534 sublayerTransformPreventsClip ||
535 !childLayer->transform().IsPositiveScaleOrTranslation()) 535 !childLayer->transform().IsPositiveScaleOrTranslation())
536 descendantsCanClipSelves = false; 536 descendantsCanClipSelves = false;
537 } 537 }
538 538
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 // Small calculation errors may result near-integer scales like 1.00001.
544 // Round them to simplify the transform and avoid blurriness.
545 static void roundNearIntegerScales(gfx::Transform* transform)
546 {
547 const double kErrorThreshold = 0.0001;
548 if (transform->IsScaleOrTranslation() && !transform->IsIdentityOrTranslation ()) {
549 double scaleX = transform->matrix().getDouble(0, 0);
550 double roundedScaleX = round(scaleX);
551 if (std::abs(scaleX - roundedScaleX) < kErrorThreshold)
Sami 2013/03/05 11:28:34 I'm wondering if it'd be better to only do this fo
Xianzhu 2013/03/05 17:26:08 I'm not sure. Considering the case of (scalex, sca
552 transform->matrix().setDouble(0, 0, roundedScaleX);
553
554 double scaleY = transform->matrix().getDouble(1, 1);
555 double roundedScaleY = round(scaleY);
556 if (std::abs(scaleY - roundedScaleY) < kErrorThreshold)
557 transform->matrix().setDouble(1, 1, roundedScaleY);
558 }
559 }
560
561 static void roundTranslates(gfx::Transform* transform)
562 {
563 transform->matrix().setDouble(0, 3, round(transform->matrix().getDouble(0, 3 )));
564 transform->matrix().setDouble(1, 3, round(transform->matrix().getDouble(1, 3 )));
565 }
566
543 // Recursively walks the layer tree starting at the given node and computes all the 567 // Recursively walks the layer tree starting at the given node and computes all the
544 // necessary transformations, clipRects, render surfaces, etc. 568 // necessary transformations, clipRects, render surfaces, etc.
545 template<typename LayerType, typename LayerList, typename RenderSurfaceType> 569 template<typename LayerType, typename LayerList, typename RenderSurfaceType>
546 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, 570 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix,
547 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, 571 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix,
548 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree, 572 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree,
549 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, 573 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList,
550 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText, 574 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText,
551 gfx::Rect& drawableContentRectOfSubtree, bool updateTilePriorities) 575 gfx::Rect& drawableContentRectOfSubtree, bool updateTilePriorities)
552 { 576 {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 // fixed correctly. 724 // fixed correctly.
701 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform). 725 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform).
702 combinedTransform.ConcatTransform(currentScrollCompensationMatrix); 726 combinedTransform.ConcatTransform(currentScrollCompensationMatrix);
703 } 727 }
704 728
705 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless 729 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless
706 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms. 730 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms.
707 layerDrawProperties.target_space_transform = combinedTransform; 731 layerDrawProperties.target_space_transform = combinedTransform;
708 // M[draw] = M[parent] * LT * S[layer2content] 732 // M[draw] = M[parent] * LT * S[layer2content]
709 layerDrawProperties.target_space_transform.Scale(1.0 / layer->contentsScaleX (), 1.0 / layer->contentsScaleY()); 733 layerDrawProperties.target_space_transform.Scale(1.0 / layer->contentsScaleX (), 1.0 / layer->contentsScaleY());
734 roundNearIntegerScales(&layerDrawProperties.target_space_transform);
shawnsingh 2013/03/05 05:29:45 (1) It might be a problem that this value is used
Sami 2013/03/05 11:28:34 One problem I can think of is that rounding can mo
Xianzhu 2013/03/05 17:26:08 roundNearIntegerScales() sets back the expected va
Xianzhu 2013/03/05 17:26:08 Will try to round position to screen space pixel,
Xianzhu 2013/03/05 23:03:14 Sorry, I didn't get your point when posting the re
710 735
711 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space. 736 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space.
712 layerDrawProperties.screen_space_transform = fullHierarchyMatrix; 737 layerDrawProperties.screen_space_transform = fullHierarchyMatrix;
713 if (!layer->preserves3D()) 738 if (!layer->preserves3D())
714 layerDrawProperties.screen_space_transform.FlattenTo2d(); 739 layerDrawProperties.screen_space_transform.FlattenTo2d();
715 layerDrawProperties.screen_space_transform.PreconcatTransform(layerDrawPrope rties.target_space_transform); 740 layerDrawProperties.screen_space_transform.PreconcatTransform(layerDrawPrope rties.target_space_transform);
741 roundNearIntegerScales(&layerDrawProperties.screen_space_transform);
742
743 // Round the translation in simple transforms if translation is merely cause d by the scroll offset,
744 // so that the pixels of the layer and the target space can be aligned.
745 LayerType* scrollLayer = LayerTreeHostCommon::findScrollLayerForContentLayer (layer);
746 if (scrollLayer) {
Sami 2013/03/05 11:28:34 Would it be simpler to do this for all scrollable
Xianzhu 2013/03/05 17:26:08 If the scrollable layer is the content layer itsel
Xianzhu 2013/03/05 23:03:14 I was wrong about this. Actually position() is non
Xianzhu 2013/03/05 23:03:14 Done. Slightly different: now rounds the translati
747 gfx::Vector2dF scrollPosition = scrollLayer->scrollOffset() + scrollLaye r->scrollDelta();
748 if (position.x() == -scrollPosition.x() && position.y() == -scrollPositi on.y()) {
749 if (layerDrawProperties.target_space_transform.IsIdentityOrTranslati on())
750 roundTranslates(&layerDrawProperties.target_space_transform);
751 if (layerDrawProperties.screen_space_transform.IsIdentityOrTranslati on())
752 roundTranslates(&layerDrawProperties.screen_space_transform);
753 }
754 }
716 755
717 // 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.
718 bool adjustTextAA = !animatingOpacityToScreen && !animatingTransformToScreen ; 757 bool adjustTextAA = !animatingOpacityToScreen && !animatingTransformToScreen ;
719 // 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.
720 bool layerCanUseLCDText = subtreeCanUseLCDText && 759 bool layerCanUseLCDText = subtreeCanUseLCDText &&
721 (accumulatedDrawOpacity == 1.0) && 760 (accumulatedDrawOpacity == 1.0) &&
722 layerDrawProperties.target_space_transform.IsIdent ityOrIntegerTranslation(); 761 layerDrawProperties.target_space_transform.IsIdent ityOrIntegerTranslation();
723 762
724 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds()); 763 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds());
725 764
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 1241
1203 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up 1242 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up
1204 // the parents to ensure that the layer was not clipped in such a way that the 1243 // the parents to ensure that the layer was not clipped in such a way that the
1205 // hit point actually should not hit the layer. 1244 // hit point actually should not hit the layer.
1206 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) 1245 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl))
1207 return false; 1246 return false;
1208 1247
1209 return true; 1248 return true;
1210 } 1249 }
1211 } // namespace cc 1250 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_host_common.h ('k') | cc/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698