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

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: 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 pixel align transformed content to reduce aliasing by pixel snapping t he paint offset
81 // transform. Any residual paint offset continues through to children. See t he equivalent spv1
82 // code in PaintLayerPainter::paintFragmentByApplyingTransform.
83 IntPoint roundedPaintOffset = roundedIntPoint(context.paintOffset);
84 LayoutPoint subpixelPaintOffset = LayoutPoint(context.paintOffset - roundedP aintOffset);
85
80 RefPtr<TransformPaintPropertyNode> paintOffsetTranslation = TransformPaintPr opertyNode::create( 86 RefPtr<TransformPaintPropertyNode> paintOffsetTranslation = TransformPaintPr opertyNode::create(
81 TransformationMatrix().translate(context.paintOffset.x(), context.paintO ffset.y()), 87 TransformationMatrix().translate(roundedPaintOffset.x(), roundedPaintOff set.y()),
82 FloatPoint3D(), context.currentTransform); 88 FloatPoint3D(), context.currentTransform);
83 context.currentTransform = paintOffsetTranslation.get(); 89 context.currentTransform = paintOffsetTranslation.get();
84 context.paintOffset = LayoutPoint(); 90 context.paintOffset = subpixelPaintOffset;
85 object.getMutableForPainting().ensureObjectPaintProperties().setPaintOffsetT ranslation(paintOffsetTranslation.release()); 91 object.getMutableForPainting().ensureObjectPaintProperties().setPaintOffsetT ranslation(paintOffsetTranslation.release());
86 } 92 }
87 93
88 static FloatPoint3D transformOrigin(const LayoutBox& box) 94 static FloatPoint3D transformOrigin(const LayoutBox& box)
89 { 95 {
90 const ComputedStyle& style = box.styleRef(); 96 const ComputedStyle& style = box.styleRef();
91 FloatSize borderBoxSize(box.size()); 97 FloatSize borderBoxSize(box.size());
92 return FloatPoint3D( 98 return FloatPoint3D(
93 floatValueForLength(style.transformOriginX(), borderBoxSize.width()), 99 floatValueForLength(style.transformOriginX(), borderBoxSize.width()),
94 floatValueForLength(style.transformOriginY(), borderBoxSize.height()), 100 floatValueForLength(style.transformOriginY(), borderBoxSize.height()),
95 style.transformOriginZ()); 101 style.transformOriginZ());
96 } 102 }
97 103
98 void PaintPropertyTreeBuilder::updateTransform(const LayoutObject& object, Paint PropertyTreeBuilderContext& context) 104 void PaintPropertyTreeBuilder::updateTransform(const LayoutObject& object, Paint PropertyTreeBuilderContext& context)
99 { 105 {
100 if (object.isSVG() && !object.isSVGRoot()) { 106 if (object.isSVG() && !object.isSVGRoot()) {
101 // SVG does not use paint offset internally and the root should have alr eady accounted for
102 // any paint offset in the root's svgLocalToBorderBox transform.
103 DCHECK(context.paintOffset == LayoutPoint());
104
105 // FIXME(pdr): Check for the presence of a transform instead of the valu e. Checking for an 107 // 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 108 // identity matrix will cause the property tree structure to change duri ng animations if
107 // the animation passes through the identity matrix. 109 // the animation passes through the identity matrix.
108 // FIXME(pdr): Refactor this so all non-root SVG objects use the same tr ansform function. 110 // 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(); 111 const AffineTransform& transform = object.isSVGForeignObject() ? object. localSVGTransform() : object.localToSVGParentTransform();
110 if (transform.isIdentity()) 112 if (transform.isIdentity())
111 return; 113 return;
112 114
113 // The origin is included in the local transform, so use an empty origin . 115 // The origin is included in the local transform, so use an empty origin .
114 RefPtr<TransformPaintPropertyNode> svgTransform = TransformPaintProperty Node::create( 116 RefPtr<TransformPaintPropertyNode> svgTransform = TransformPaintProperty Node::create(
115 transform, FloatPoint3D(0, 0, 0), context.currentTransform); 117 transform, FloatPoint3D(0, 0, 0), context.currentTransform);
116 context.currentTransform = svgTransform.get(); 118 context.currentTransform = svgTransform.get();
117 object.getMutableForPainting().ensureObjectPaintProperties().setTransfor m(svgTransform.release()); 119 object.getMutableForPainting().ensureObjectPaintProperties().setTransfor m(svgTransform.release());
118 return; 120 return;
119 } 121 }
120 122
121 const ComputedStyle& style = object.styleRef(); 123 const ComputedStyle& style = object.styleRef();
122 if (!object.isBox() || !style.hasTransform()) 124 if (!object.isBox() || !style.hasTransform())
123 return; 125 return;
124 ASSERT(context.paintOffset == LayoutPoint());
125 126
126 TransformationMatrix matrix; 127 TransformationMatrix matrix;
127 style.applyTransform(matrix, toLayoutBox(object).size(), ComputedStyle::Excl udeTransformOrigin, 128 style.applyTransform(matrix, toLayoutBox(object).size(), ComputedStyle::Excl udeTransformOrigin,
128 ComputedStyle::IncludeMotionPath, ComputedStyle::IncludeIndependentTrans formProperties); 129 ComputedStyle::IncludeMotionPath, ComputedStyle::IncludeIndependentTrans formProperties);
129 RefPtr<TransformPaintPropertyNode> transformNode = TransformPaintPropertyNod e::create( 130 RefPtr<TransformPaintPropertyNode> transformNode = TransformPaintPropertyNod e::create(
130 matrix, transformOrigin(toLayoutBox(object)), context.currentTransform); 131 matrix, transformOrigin(toLayoutBox(object)), context.currentTransform);
131 context.currentTransform = transformNode.get(); 132 context.currentTransform = transformNode.get();
132 object.getMutableForPainting().ensureObjectPaintProperties().setTransform(tr ansformNode.release()); 133 object.getMutableForPainting().ensureObjectPaintProperties().setTransform(tr ansformNode.release());
133 } 134 }
134 135
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 updateOverflowClip(object, context); 401 updateOverflowClip(object, context);
401 // TODO(trchen): Insert flattening transform here, as specified by 402 // TODO(trchen): Insert flattening transform here, as specified by
402 // http://www.w3.org/TR/css3-transforms/#transform-style-property 403 // http://www.w3.org/TR/css3-transforms/#transform-style-property
403 updatePerspective(object, context); 404 updatePerspective(object, context);
404 updateSvgLocalToBorderBoxTransform(object, context); 405 updateSvgLocalToBorderBoxTransform(object, context);
405 updateScrollTranslation(object, context); 406 updateScrollTranslation(object, context);
406 updateOutOfFlowContext(object, context); 407 updateOutOfFlowContext(object, context);
407 } 408 }
408 409
409 } // namespace blink 410 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698