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

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilder.cpp

Issue 2112753002: Snap paint offset paint property to pixel boundaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More unit tests for simple snapping and fixed position Created 4 years, 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/paint/PaintPropertyTreeBuilder.h" 5 #include "core/paint/PaintPropertyTreeBuilder.h"
6 6
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/frame/LocalFrame.h" 8 #include "core/frame/LocalFrame.h"
9 #include "core/frame/Settings.h" 9 #include "core/frame/Settings.h"
10 #include "core/layout/LayoutInline.h" 10 #include "core/layout/LayoutInline.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (object.isBoxModelObject()) { 70 if (object.isBoxModelObject()) {
71 // TODO(trchen): Eliminate PaintLayer dependency. 71 // TODO(trchen): Eliminate PaintLayer dependency.
72 PaintLayer* layer = toLayoutBoxModelObject(object).layer(); 72 PaintLayer* layer = toLayoutBoxModelObject(object).layer();
73 if (!layer || !layer->paintsWithTransform(GlobalPaintNormalPhase)) 73 if (!layer || !layer->paintsWithTransform(GlobalPaintNormalPhase))
74 return; 74 return;
75 } 75 }
76 76
77 if (context.paintOffset == LayoutPoint()) 77 if (context.paintOffset == LayoutPoint())
78 return; 78 return;
79 79
80 // We should use the same subpixel paint offset values for snapping regardle ss of whether a
81 // transform is present. If there is a transform we round the paint offset b ut keep around
82 // the residual fractional component for the transformed content to paint wi th.
83 // In spv1 this was called "subpixel accumulation". For more information, se e
84 // PaintLayer::subpixelAccumulation() and PaintLayerPainter::paintFragmentBy ApplyingTransform.
85 IntPoint roundedPaintOffset = roundedIntPoint(context.paintOffset);
86 LayoutPoint fractionalPaintOffset = LayoutPoint(context.paintOffset - rounde dPaintOffset);
87
80 RefPtr<TransformPaintPropertyNode> paintOffsetTranslation = TransformPaintPr opertyNode::create( 88 RefPtr<TransformPaintPropertyNode> paintOffsetTranslation = TransformPaintPr opertyNode::create(
81 TransformationMatrix().translate(context.paintOffset.x(), context.paintO ffset.y()), 89 TransformationMatrix().translate(roundedPaintOffset.x(), roundedPaintOff set.y()),
82 FloatPoint3D(), context.currentTransform); 90 FloatPoint3D(), context.currentTransform);
83 context.currentTransform = paintOffsetTranslation.get(); 91 context.currentTransform = paintOffsetTranslation.get();
84 context.paintOffset = LayoutPoint(); 92 context.paintOffset = fractionalPaintOffset;
85 object.getMutableForPainting().ensureObjectPaintProperties().setPaintOffsetT ranslation(paintOffsetTranslation.release()); 93 object.getMutableForPainting().ensureObjectPaintProperties().setPaintOffsetT ranslation(paintOffsetTranslation.release());
86 } 94 }
87 95
88 static FloatPoint3D transformOrigin(const LayoutBox& box) 96 static FloatPoint3D transformOrigin(const LayoutBox& box)
89 { 97 {
90 const ComputedStyle& style = box.styleRef(); 98 const ComputedStyle& style = box.styleRef();
91 FloatSize borderBoxSize(box.size()); 99 FloatSize borderBoxSize(box.size());
92 return FloatPoint3D( 100 return FloatPoint3D(
93 floatValueForLength(style.transformOriginX(), borderBoxSize.width()), 101 floatValueForLength(style.transformOriginX(), borderBoxSize.width()),
94 floatValueForLength(style.transformOriginY(), borderBoxSize.height()), 102 floatValueForLength(style.transformOriginY(), borderBoxSize.height()),
95 style.transformOriginZ()); 103 style.transformOriginZ());
96 } 104 }
97 105
98 void PaintPropertyTreeBuilder::updateTransform(const LayoutObject& object, Paint PropertyTreeBuilderContext& context) 106 void PaintPropertyTreeBuilder::updateTransform(const LayoutObject& object, Paint PropertyTreeBuilderContext& context)
99 { 107 {
100 if (object.isSVG() && !object.isSVGRoot()) { 108 if (object.isSVG() && !object.isSVGRoot()) {
101 // SVG does not use paint offset internally and the root should have alr eady accounted for 109 // SVG does not use paint offset internally.
102 // any paint offset in the root's svgLocalToBorderBox transform.
103 DCHECK(context.paintOffset == LayoutPoint()); 110 DCHECK(context.paintOffset == LayoutPoint());
104 111
105 // FIXME(pdr): Check for the presence of a transform instead of the valu e. Checking for an 112 // FIXME(pdr): Check for the presence of a transform instead of the valu e. Checking for an
106 // identity matrix will cause the property tree structure to change duri ng animations if 113 // identity matrix will cause the property tree structure to change duri ng animations if
107 // the animation passes through the identity matrix. 114 // the animation passes through the identity matrix.
108 // FIXME(pdr): Refactor this so all non-root SVG objects use the same tr ansform function. 115 // FIXME(pdr): Refactor this so all non-root SVG objects use the same tr ansform function.
109 const AffineTransform& transform = object.isSVGForeignObject() ? object. localSVGTransform() : object.localToSVGParentTransform(); 116 const AffineTransform& transform = object.isSVGForeignObject() ? object. localSVGTransform() : object.localToSVGParentTransform();
110 if (transform.isIdentity()) 117 if (transform.isIdentity())
111 return; 118 return;
112 119
113 // The origin is included in the local transform, so use an empty origin . 120 // The origin is included in the local transform, so use an empty origin .
114 RefPtr<TransformPaintPropertyNode> svgTransform = TransformPaintProperty Node::create( 121 RefPtr<TransformPaintPropertyNode> svgTransform = TransformPaintProperty Node::create(
115 transform, FloatPoint3D(0, 0, 0), context.currentTransform); 122 transform, FloatPoint3D(0, 0, 0), context.currentTransform);
116 context.currentTransform = svgTransform.get(); 123 context.currentTransform = svgTransform.get();
117 object.getMutableForPainting().ensureObjectPaintProperties().setTransfor m(svgTransform.release()); 124 object.getMutableForPainting().ensureObjectPaintProperties().setTransfor m(svgTransform.release());
118 return; 125 return;
119 } 126 }
120 127
121 const ComputedStyle& style = object.styleRef(); 128 const ComputedStyle& style = object.styleRef();
122 if (!object.isBox() || !style.hasTransform()) 129 if (!object.isBox() || !style.hasTransform())
123 return; 130 return;
124 ASSERT(context.paintOffset == LayoutPoint());
125 131
126 TransformationMatrix matrix; 132 TransformationMatrix matrix;
127 style.applyTransform(matrix, toLayoutBox(object).size(), ComputedStyle::Excl udeTransformOrigin, 133 style.applyTransform(matrix, toLayoutBox(object).size(), ComputedStyle::Excl udeTransformOrigin,
128 ComputedStyle::IncludeMotionPath, ComputedStyle::IncludeIndependentTrans formProperties); 134 ComputedStyle::IncludeMotionPath, ComputedStyle::IncludeIndependentTrans formProperties);
129 RefPtr<TransformPaintPropertyNode> transformNode = TransformPaintPropertyNod e::create( 135 RefPtr<TransformPaintPropertyNode> transformNode = TransformPaintPropertyNod e::create(
130 matrix, transformOrigin(toLayoutBox(object)), context.currentTransform); 136 matrix, transformOrigin(toLayoutBox(object)), context.currentTransform);
131 context.currentTransform = transformNode.get(); 137 context.currentTransform = transformNode.get();
132 object.getMutableForPainting().ensureObjectPaintProperties().setTransform(tr ansformNode.release()); 138 object.getMutableForPainting().ensureObjectPaintProperties().setTransform(tr ansformNode.release());
133 } 139 }
134 140
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 updateOverflowClip(object, context); 406 updateOverflowClip(object, context);
401 // TODO(trchen): Insert flattening transform here, as specified by 407 // TODO(trchen): Insert flattening transform here, as specified by
402 // http://www.w3.org/TR/css3-transforms/#transform-style-property 408 // http://www.w3.org/TR/css3-transforms/#transform-style-property
403 updatePerspective(object, context); 409 updatePerspective(object, context);
404 updateSvgLocalToBorderBoxTransform(object, context); 410 updateSvgLocalToBorderBoxTransform(object, context);
405 updateScrollTranslation(object, context); 411 updateScrollTranslation(object, context);
406 updateOutOfFlowContext(object, context); 412 updateOutOfFlowContext(object, context);
407 } 413 }
408 414
409 } // namespace blink 415 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698