| OLD | NEW |
| 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/BoxClipper.h" |
| 9 #include "core/paint/BoxPainter.h" | 10 #include "core/paint/BoxPainter.h" |
| 10 #include "core/paint/ObjectPaintProperties.h" | 11 #include "core/paint/ObjectPaintProperties.h" |
| 11 #include "core/paint/PaintInfo.h" | 12 #include "core/paint/PaintInfo.h" |
| 12 #include "core/paint/PaintTiming.h" | 13 #include "core/paint/PaintTiming.h" |
| 13 #include "core/paint/SVGPaintContext.h" | 14 #include "core/paint/SVGPaintContext.h" |
| 14 #include "core/paint/TransformRecorder.h" | 15 #include "core/paint/TransformRecorder.h" |
| 15 #include "core/svg/SVGSVGElement.h" | 16 #include "core/svg/SVGSVGElement.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 | 21 IntRect SVGRootPainter::pixelSnappedSize(const LayoutPoint& paintOffset) const |
| 22 { | 22 { |
| 23 return pixelSnappedIntRect(paintOffset, m_layoutSVGRoot.size()); | 23 return pixelSnappedIntRect(paintOffset, m_layoutSVGRoot.size()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 AffineTransform SVGRootPainter::transformToPixelSnappedBorderBox(const LayoutPoi
nt& paintOffset) const | 26 AffineTransform SVGRootPainter::transformToPixelSnappedBorderBox(const LayoutPoi
nt& paintOffset) const |
| 27 { | 27 { |
| 28 const IntRect snappedSize = pixelSnappedSize(paintOffset); | 28 const IntRect snappedSize = pixelSnappedSize(paintOffset); |
| 29 AffineTransform paintOffsetToBorderBox = | 29 AffineTransform paintOffsetToBorderBox = |
| 30 AffineTransform::translation(snappedSize.x(), snappedSize.y()); | 30 AffineTransform::translation(snappedSize.x(), snappedSize.y()); |
| 31 LayoutSize size = m_layoutSVGRoot.size(); | 31 LayoutSize size = m_layoutSVGRoot.size(); |
| 32 if (!size.isEmpty()) { | 32 if (!size.isEmpty()) { |
| 33 paintOffsetToBorderBox.scale( | 33 paintOffsetToBorderBox.scale( |
| 34 snappedSize.width() / size.width().toFloat(), | 34 snappedSize.width() / size.width().toFloat(), |
| 35 snappedSize.height() / size.height().toFloat()); | 35 snappedSize.height() / size.height().toFloat()); |
| 36 } | 36 } |
| 37 paintOffsetToBorderBox.multiply(m_layoutSVGRoot.localToBorderBoxTransform())
; | 37 paintOffsetToBorderBox.multiply(m_layoutSVGRoot.localToBorderBoxTransform())
; |
| 38 return paintOffsetToBorderBox; | 38 return paintOffsetToBorderBox; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void SVGRootPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintO
ffset) | 41 void SVGRootPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint
& paintOffset) |
| 42 { | 42 { |
| 43 // An empty viewport disables rendering. | 43 // An empty viewport disables rendering. |
| 44 if (pixelSnappedSize(paintOffset).isEmpty()) | 44 if (pixelSnappedSize(paintOffset).isEmpty()) |
| 45 return; | 45 return; |
| 46 | 46 |
| 47 // SVG outlines are painted during PaintPhaseForeground. | 47 // SVG outlines are painted during PaintPhaseForeground. |
| 48 if (shouldPaintSelfOutline(paintInfo.phase)) | 48 if (shouldPaintSelfOutline(paintInfo.phase)) |
| 49 return; | 49 return; |
| 50 | 50 |
| 51 // An empty viewBox also disables rendering. | 51 // An empty viewBox also disables rendering. |
| 52 // (http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute) | 52 // (http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute) |
| 53 SVGSVGElement* svg = toSVGSVGElement(m_layoutSVGRoot.node()); | 53 SVGSVGElement* svg = toSVGSVGElement(m_layoutSVGRoot.node()); |
| 54 ASSERT(svg); | 54 ASSERT(svg); |
| 55 if (svg->hasEmptyViewBox()) | 55 if (svg->hasEmptyViewBox()) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 PaintInfo paintInfoBeforeFiltering(paintInfo); | |
| 59 | |
| 60 // Apply initial viewport clip. | 58 // Apply initial viewport clip. |
| 61 Optional<ClipRecorder> clipRecorder; | 59 Optional<BoxClipper> boxClipper; |
| 62 if (m_layoutSVGRoot.shouldApplyViewportClip()) { | 60 if (m_layoutSVGRoot.shouldApplyViewportClip()) { |
| 63 // TODO(pdr): Clip the paint info cull rect here. | 61 // TODO(pdr): Clip the paint info cull rect here. |
| 64 clipRecorder.emplace(paintInfoBeforeFiltering.context, m_layoutSVGRoot,
paintInfoBeforeFiltering.displayItemTypeForClipping(), pixelSnappedIntRect(m_lay
outSVGRoot.overflowClipRect(paintOffset))); | 62 boxClipper.emplace(m_layoutSVGRoot, paintInfo, paintOffset, ForceContent
sClip); |
| 65 } | 63 } |
| 66 | 64 |
| 65 PaintInfo paintInfoBeforeFiltering(paintInfo); |
| 67 AffineTransform transformToBorderBox = transformToPixelSnappedBorderBox(pain
tOffset); | 66 AffineTransform transformToBorderBox = transformToPixelSnappedBorderBox(pain
tOffset); |
| 68 paintInfoBeforeFiltering.updateCullRect(transformToBorderBox); | 67 paintInfoBeforeFiltering.updateCullRect(transformToBorderBox); |
| 69 SVGTransformContext transformContext(paintInfoBeforeFiltering.context, m_lay
outSVGRoot, transformToBorderBox); | 68 SVGTransformContext transformContext(paintInfoBeforeFiltering.context, m_lay
outSVGRoot, transformToBorderBox); |
| 70 | 69 |
| 71 SVGPaintContext paintContext(m_layoutSVGRoot, paintInfoBeforeFiltering); | 70 SVGPaintContext paintContext(m_layoutSVGRoot, paintInfoBeforeFiltering); |
| 72 if (paintContext.paintInfo().phase == PaintPhaseForeground && !paintContext.
applyClipMaskAndFilterIfNecessary()) | 71 if (paintContext.paintInfo().phase == PaintPhaseForeground && !paintContext.
applyClipMaskAndFilterIfNecessary()) |
| 73 return; | 72 return; |
| 74 | 73 |
| 75 BoxPainter(m_layoutSVGRoot).paint(paintContext.paintInfo(), LayoutPoint()); | 74 BoxPainter(m_layoutSVGRoot).paint(paintContext.paintInfo(), LayoutPoint()); |
| 76 | 75 |
| 77 PaintTiming& timing = PaintTiming::from(m_layoutSVGRoot.node()->document().t
opDocument()); | 76 PaintTiming& timing = PaintTiming::from(m_layoutSVGRoot.node()->document().t
opDocument()); |
| 78 timing.markFirstContentfulPaint(); | 77 timing.markFirstContentfulPaint(); |
| 79 } | 78 } |
| 80 | 79 |
| 81 } // namespace blink | 80 } // namespace blink |
| OLD | NEW |