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

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

Issue 2128463002: Pixel snap SVG's root border box to local transform [spv2] (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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/SVGRootPainter.h" 5 #include "core/paint/SVGRootPainter.h"
6 6
7 #include "core/layout/svg/LayoutSVGRoot.h" 7 #include "core/layout/svg/LayoutSVGRoot.h"
8 #include "core/layout/svg/SVGLayoutSupport.h" 8 #include "core/layout/svg/SVGLayoutSupport.h"
9 #include "core/paint/BoxPainter.h" 9 #include "core/paint/BoxPainter.h"
10 #include "core/paint/ObjectPaintProperties.h" 10 #include "core/paint/ObjectPaintProperties.h"
11 #include "core/paint/PaintInfo.h" 11 #include "core/paint/PaintInfo.h"
12 #include "core/paint/PaintTiming.h" 12 #include "core/paint/PaintTiming.h"
13 #include "core/paint/SVGPaintContext.h" 13 #include "core/paint/SVGPaintContext.h"
14 #include "core/paint/TransformRecorder.h" 14 #include "core/paint/TransformRecorder.h"
15 #include "core/svg/SVGSVGElement.h" 15 #include "core/svg/SVGSVGElement.h"
16 #include "platform/graphics/paint/ClipRecorder.h" 16 #include "platform/graphics/paint/ClipRecorder.h"
17 #include "wtf/Optional.h" 17 #include "wtf/Optional.h"
18 18
19 namespace blink { 19 namespace blink {
20 20
21 IntRect SVGRootPainter::pixelSnappedSize(const LayoutPoint& paintOffset) const
22 {
23 return pixelSnappedIntRect(paintOffset, m_layoutSVGRoot.size());
24 }
25
26 AffineTransform SVGRootPainter::snappedPaintOffsetToBorderBox(const LayoutPoint& paintOffset) const
27 {
28 const IntRect snappedSize = pixelSnappedSize(paintOffset);
29 AffineTransform paintOffsetToBorderBox =
30 AffineTransform::translation(snappedSize.x(), snappedSize.y());
31 paintOffsetToBorderBox.scale(
32 snappedSize.width() / m_layoutSVGRoot.size().width().toFloat(),
33 snappedSize.height() / m_layoutSVGRoot.size().height().toFloat());
34 paintOffsetToBorderBox.multiply(m_layoutSVGRoot.localToBorderBoxTransform()) ;
35 return paintOffsetToBorderBox;
36 }
37
21 void SVGRootPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintO ffset) 38 void SVGRootPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintO ffset)
22 { 39 {
23 // Pixel-snap to match BoxPainter's alignment.
24 const IntRect adjustedRect = pixelSnappedIntRect(paintOffset, m_layoutSVGRoo t.size());
25
26 // An empty viewport disables rendering. 40 // An empty viewport disables rendering.
27 if (adjustedRect.isEmpty()) 41 if (pixelSnappedSize(paintOffset).isEmpty())
28 return; 42 return;
29 43
30 // SVG outlines are painted during PaintPhaseForeground. 44 // SVG outlines are painted during PaintPhaseForeground.
31 if (shouldPaintSelfOutline(paintInfo.phase)) 45 if (shouldPaintSelfOutline(paintInfo.phase))
32 return; 46 return;
33 47
34 // An empty viewBox also disables rendering. 48 // An empty viewBox also disables rendering.
35 // (http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute) 49 // (http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute)
36 SVGSVGElement* svg = toSVGSVGElement(m_layoutSVGRoot.node()); 50 SVGSVGElement* svg = toSVGSVGElement(m_layoutSVGRoot.node());
37 ASSERT(svg); 51 ASSERT(svg);
38 if (svg->hasEmptyViewBox()) 52 if (svg->hasEmptyViewBox())
39 return; 53 return;
40 54
41 PaintInfo paintInfoBeforeFiltering(paintInfo); 55 PaintInfo paintInfoBeforeFiltering(paintInfo);
42 56
43 // Apply initial viewport clip. 57 // Apply initial viewport clip.
44 Optional<ClipRecorder> clipRecorder; 58 Optional<ClipRecorder> clipRecorder;
45 if (m_layoutSVGRoot.shouldApplyViewportClip()) { 59 if (m_layoutSVGRoot.shouldApplyViewportClip()) {
46 // TODO(pdr): Clip the paint info cull rect here. 60 // TODO(pdr): Clip the paint info cull rect here.
47 clipRecorder.emplace(paintInfoBeforeFiltering.context, m_layoutSVGRoot, paintInfoBeforeFiltering.displayItemTypeForClipping(), pixelSnappedIntRect(m_lay outSVGRoot.overflowClipRect(paintOffset))); 61 clipRecorder.emplace(paintInfoBeforeFiltering.context, m_layoutSVGRoot, paintInfoBeforeFiltering.displayItemTypeForClipping(), pixelSnappedIntRect(m_lay outSVGRoot.overflowClipRect(paintOffset)));
48 } 62 }
49 63
50 // Convert from container offsets (html layoutObjects) to a relative transfo rm (svg layoutObjects). 64 AffineTransform paintOffsetToBorderBox = snappedPaintOffsetToBorderBox(paint Offset);
51 // Transform from our paint container's coordinate system to our local coord s.
52 AffineTransform paintOffsetToBorderBox =
53 AffineTransform::translation(adjustedRect.x(), adjustedRect.y());
54 // Compensate for size snapping.
55 paintOffsetToBorderBox.scale(
56 adjustedRect.width() / m_layoutSVGRoot.size().width().toFloat(),
57 adjustedRect.height() / m_layoutSVGRoot.size().height().toFloat());
58 paintOffsetToBorderBox.multiply(m_layoutSVGRoot.localToBorderBoxTransform()) ;
59
60 paintInfoBeforeFiltering.updateCullRect(paintOffsetToBorderBox); 65 paintInfoBeforeFiltering.updateCullRect(paintOffsetToBorderBox);
61 SVGTransformContext transformContext(paintInfoBeforeFiltering.context, m_lay outSVGRoot, paintOffsetToBorderBox); 66 SVGTransformContext transformContext(paintInfoBeforeFiltering.context, m_lay outSVGRoot, paintOffsetToBorderBox);
62 67
63 SVGPaintContext paintContext(m_layoutSVGRoot, paintInfoBeforeFiltering); 68 SVGPaintContext paintContext(m_layoutSVGRoot, paintInfoBeforeFiltering);
64 if (paintContext.paintInfo().phase == PaintPhaseForeground && !paintContext. applyClipMaskAndFilterIfNecessary()) 69 if (paintContext.paintInfo().phase == PaintPhaseForeground && !paintContext. applyClipMaskAndFilterIfNecessary())
65 return; 70 return;
66 71
67 BoxPainter(m_layoutSVGRoot).paint(paintContext.paintInfo(), LayoutPoint()); 72 BoxPainter(m_layoutSVGRoot).paint(paintContext.paintInfo(), LayoutPoint());
68 73
69 PaintTiming& timing = PaintTiming::from(m_layoutSVGRoot.node()->document().t opDocument()); 74 PaintTiming& timing = PaintTiming::from(m_layoutSVGRoot.node()->document().t opDocument());
70 timing.markFirstContentfulPaint(); 75 timing.markFirstContentfulPaint();
71 } 76 }
72 77
73 } // namespace blink 78 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698