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

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: Align scrollable layer 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 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 almost-integer scales like 1.00001.
enne (OOO) 2013/03/05 23:46:28 Where is this calculation error introduced?
Xianzhu 2013/03/06 00:26:13 I observed the near 1 scales in content transforma
544 // Round them so that some transform can be identity as expected.
545 static void roundAlmostIntegerScales(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)
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 // The layer's contentsSize is determined from the combinedTransform, which then informs the 711 // The layer's contentsSize is determined from the combinedTransform, which then informs the
688 // layer's drawTransform. 712 // layer's drawTransform.
689 updateLayerContentsScale(layer, combinedTransform, deviceScaleFactor, pageSc aleFactor, animatingTransformToScreen); 713 updateLayerContentsScale(layer, combinedTransform, deviceScaleFactor, pageSc aleFactor, animatingTransformToScreen);
690 714
691 // If there is a transformation from the impl thread then it should be at 715 // If there is a transformation from the impl thread then it should be at
692 // the start of the combinedTransform, but we don't want it to affect the 716 // the start of the combinedTransform, but we don't want it to affect the
693 // computation of contentsScale above. 717 // computation of contentsScale above.
694 // Note carefully: this is Concat, not Preconcat (implTransform * combinedTr ansform). 718 // Note carefully: this is Concat, not Preconcat (implTransform * combinedTr ansform).
695 combinedTransform.ConcatTransform(layer->implTransform()); 719 combinedTransform.ConcatTransform(layer->implTransform());
696 720
721 if (layer->scrollable() && combinedTransform.IsScaleOrTranslation() && layer ->transform().IsIdentity()) {
enne (OOO) 2013/03/05 23:46:28 Why is it so important that layer->transform().IsI
Xianzhu 2013/03/06 00:26:13 I think for example if the layer itself has a non-
enne (OOO) 2013/03/06 00:40:17 I still don't follow what the case you're trying t
722 // Align the scrollable layer's position to screen space pixels to avoid blurriness.
723 // To avoid side-effects, do this only if the transform is simple.
724 roundTranslates(&combinedTransform);
725 }
726
697 if (layer->fixedToContainerLayer()) { 727 if (layer->fixedToContainerLayer()) {
698 // Special case: this layer is a composited fixed-position layer; we nee d to 728 // Special case: this layer is a composited fixed-position layer; we nee d to
699 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer 729 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer
700 // fixed correctly. 730 // fixed correctly.
701 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform). 731 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform).
702 combinedTransform.ConcatTransform(currentScrollCompensationMatrix); 732 combinedTransform.ConcatTransform(currentScrollCompensationMatrix);
703 } 733 }
704 734
705 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless 735 // 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. 736 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms.
707 layerDrawProperties.target_space_transform = combinedTransform; 737 layerDrawProperties.target_space_transform = combinedTransform;
708 // M[draw] = M[parent] * LT * S[layer2content] 738 // M[draw] = M[parent] * LT * S[layer2content]
709 layerDrawProperties.target_space_transform.Scale(1.0 / layer->contentsScaleX (), 1.0 / layer->contentsScaleY()); 739 layerDrawProperties.target_space_transform.Scale(1.0 / layer->contentsScaleX (), 1.0 / layer->contentsScaleY());
740 roundAlmostIntegerScales(&layerDrawProperties.target_space_transform);
enne (OOO) 2013/03/05 23:46:28 As you've already rounded combinedTransform above,
Xianzhu 2013/03/06 00:26:13 This is to meet the condition of layerCanUseLCDTex
710 741
711 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space. 742 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space.
712 layerDrawProperties.screen_space_transform = fullHierarchyMatrix; 743 layerDrawProperties.screen_space_transform = fullHierarchyMatrix;
713 if (!layer->preserves3D()) 744 if (!layer->preserves3D())
714 layerDrawProperties.screen_space_transform.FlattenTo2d(); 745 layerDrawProperties.screen_space_transform.FlattenTo2d();
715 layerDrawProperties.screen_space_transform.PreconcatTransform(layerDrawPrope rties.target_space_transform); 746 layerDrawProperties.screen_space_transform.PreconcatTransform(layerDrawPrope rties.target_space_transform);
747 roundAlmostIntegerScales(&layerDrawProperties.screen_space_transform);
enne (OOO) 2013/03/05 23:46:28 Is this rounding necessary? As Shawn points out, i
Xianzhu 2013/03/06 00:26:13 Will remove.
716 748
717 // Adjusting text AA method during animation may cause repaints, which in-tu rn causes jank. 749 // Adjusting text AA method during animation may cause repaints, which in-tu rn causes jank.
718 bool adjustTextAA = !animatingOpacityToScreen && !animatingTransformToScreen ; 750 bool adjustTextAA = !animatingOpacityToScreen && !animatingTransformToScreen ;
719 // To avoid color fringing, LCD text should only be used on opaque layers wi th just integral translation. 751 // To avoid color fringing, LCD text should only be used on opaque layers wi th just integral translation.
720 bool layerCanUseLCDText = subtreeCanUseLCDText && 752 bool layerCanUseLCDText = subtreeCanUseLCDText &&
721 (accumulatedDrawOpacity == 1.0) && 753 (accumulatedDrawOpacity == 1.0) &&
722 layerDrawProperties.target_space_transform.IsIdent ityOrIntegerTranslation(); 754 layerDrawProperties.target_space_transform.IsIdent ityOrIntegerTranslation();
723 755
724 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds()); 756 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds());
725 757
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 1234
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 1235 // 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 1236 // 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. 1237 // hit point actually should not hit the layer.
1206 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) 1238 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl))
1207 return false; 1239 return false;
1208 1240
1209 return true; 1241 return true;
1210 } 1242 }
1211 } // namespace cc 1243 } // 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