| 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/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 "platform/graphics/paint/ScopedPaintChunkProperties.h" | |
| 18 #include "wtf/Optional.h" | 17 #include "wtf/Optional.h" |
| 19 | 18 |
| 20 namespace blink { | 19 namespace blink { |
| 21 | 20 |
| 22 void SVGRootPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintO
ffset) | 21 void SVGRootPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintO
ffset) |
| 23 { | 22 { |
| 24 // Pixel-snap to match BoxPainter's alignment. | 23 // Pixel-snap to match BoxPainter's alignment. |
| 25 const IntRect adjustedRect = pixelSnappedIntRect(paintOffset, m_layoutSVGRoo
t.size()); | 24 const IntRect adjustedRect = pixelSnappedIntRect(paintOffset, m_layoutSVGRoo
t.size()); |
| 26 | 25 |
| 27 // An empty viewport disables rendering. | 26 // An empty viewport disables rendering. |
| 28 if (adjustedRect.isEmpty()) | 27 if (adjustedRect.isEmpty()) |
| 29 return; | 28 return; |
| 30 | 29 |
| 31 // SVG outlines are painted during PaintPhaseForeground. | 30 // SVG outlines are painted during PaintPhaseForeground. |
| 32 if (shouldPaintSelfOutline(paintInfo.phase)) | 31 if (shouldPaintSelfOutline(paintInfo.phase)) |
| 33 return; | 32 return; |
| 34 | 33 |
| 35 // An empty viewBox also disables rendering. | 34 // An empty viewBox also disables rendering. |
| 36 // (http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute) | 35 // (http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute) |
| 37 SVGSVGElement* svg = toSVGSVGElement(m_layoutSVGRoot.node()); | 36 SVGSVGElement* svg = toSVGSVGElement(m_layoutSVGRoot.node()); |
| 38 ASSERT(svg); | 37 ASSERT(svg); |
| 39 if (svg->hasEmptyViewBox()) | 38 if (svg->hasEmptyViewBox()) |
| 40 return; | 39 return; |
| 41 | 40 |
| 42 PaintInfo paintInfoBeforeFiltering(paintInfo); | 41 PaintInfo paintInfoBeforeFiltering(paintInfo); |
| 43 | 42 |
| 44 Optional<ScopedPaintChunkProperties> propertyScope; | |
| 45 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { | |
| 46 const auto* objectProperties = m_layoutSVGRoot.objectPaintProperties(); | |
| 47 // If a transform exists, we can rely on a paint layer existing to apply
it. | |
| 48 DCHECK(!objectProperties || !objectProperties->transform() || m_layoutSV
GRoot.hasLayer()); | |
| 49 if (objectProperties && objectProperties->svgLocalToBorderBoxTransform()
) { | |
| 50 auto& paintController = paintInfoBeforeFiltering.context.getPaintCon
troller(); | |
| 51 PaintChunkProperties properties(paintController.currentPaintChunkPro
perties()); | |
| 52 properties.transform = objectProperties->svgLocalToBorderBoxTransfor
m(); | |
| 53 propertyScope.emplace(paintController, properties); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 // Apply initial viewport clip. | 43 // Apply initial viewport clip. |
| 58 Optional<ClipRecorder> clipRecorder; | 44 Optional<ClipRecorder> clipRecorder; |
| 59 if (m_layoutSVGRoot.shouldApplyViewportClip()) { | 45 if (m_layoutSVGRoot.shouldApplyViewportClip()) { |
| 60 // TODO(pdr): Clip the paint info cull rect here. | 46 // TODO(pdr): Clip the paint info cull rect here. |
| 61 clipRecorder.emplace(paintInfoBeforeFiltering.context, m_layoutSVGRoot,
paintInfoBeforeFiltering.displayItemTypeForClipping(), pixelSnappedIntRect(m_lay
outSVGRoot.overflowClipRect(paintOffset))); | 47 clipRecorder.emplace(paintInfoBeforeFiltering.context, m_layoutSVGRoot,
paintInfoBeforeFiltering.displayItemTypeForClipping(), pixelSnappedIntRect(m_lay
outSVGRoot.overflowClipRect(paintOffset))); |
| 62 } | 48 } |
| 63 | 49 |
| 64 // Convert from container offsets (html layoutObjects) to a relative transfo
rm (svg layoutObjects). | 50 // Convert from container offsets (html layoutObjects) to a relative transfo
rm (svg layoutObjects). |
| 65 // Transform from our paint container's coordinate system to our local coord
s. | 51 // Transform from our paint container's coordinate system to our local coord
s. |
| 66 AffineTransform paintOffsetToBorderBox = | 52 AffineTransform paintOffsetToBorderBox = |
| 67 AffineTransform::translation(adjustedRect.x(), adjustedRect.y()); | 53 AffineTransform::translation(adjustedRect.x(), adjustedRect.y()); |
| 68 // Compensate for size snapping. | 54 // Compensate for size snapping. |
| 69 paintOffsetToBorderBox.scale( | 55 paintOffsetToBorderBox.scale( |
| 70 adjustedRect.width() / m_layoutSVGRoot.size().width().toFloat(), | 56 adjustedRect.width() / m_layoutSVGRoot.size().width().toFloat(), |
| 71 adjustedRect.height() / m_layoutSVGRoot.size().height().toFloat()); | 57 adjustedRect.height() / m_layoutSVGRoot.size().height().toFloat()); |
| 72 paintOffsetToBorderBox.multiply(m_layoutSVGRoot.localToBorderBoxTransform())
; | 58 paintOffsetToBorderBox.multiply(m_layoutSVGRoot.localToBorderBoxTransform())
; |
| 73 | 59 |
| 74 paintInfoBeforeFiltering.updateCullRect(paintOffsetToBorderBox); | 60 paintInfoBeforeFiltering.updateCullRect(paintOffsetToBorderBox); |
| 75 TransformRecorder transformRecorder(paintInfoBeforeFiltering.context, m_layo
utSVGRoot, paintOffsetToBorderBox); | 61 SVGTransformContext transformContext(paintInfoBeforeFiltering.context, m_lay
outSVGRoot, paintOffsetToBorderBox); |
| 76 | 62 |
| 77 SVGPaintContext paintContext(m_layoutSVGRoot, paintInfoBeforeFiltering); | 63 SVGPaintContext paintContext(m_layoutSVGRoot, paintInfoBeforeFiltering); |
| 78 if (paintContext.paintInfo().phase == PaintPhaseForeground && !paintContext.
applyClipMaskAndFilterIfNecessary()) | 64 if (paintContext.paintInfo().phase == PaintPhaseForeground && !paintContext.
applyClipMaskAndFilterIfNecessary()) |
| 79 return; | 65 return; |
| 80 | 66 |
| 81 BoxPainter(m_layoutSVGRoot).paint(paintContext.paintInfo(), LayoutPoint()); | 67 BoxPainter(m_layoutSVGRoot).paint(paintContext.paintInfo(), LayoutPoint()); |
| 82 | 68 |
| 83 PaintTiming& timing = PaintTiming::from(m_layoutSVGRoot.node()->document().t
opDocument()); | 69 PaintTiming& timing = PaintTiming::from(m_layoutSVGRoot.node()->document().t
opDocument()); |
| 84 timing.markFirstContentfulPaint(); | 70 timing.markFirstContentfulPaint(); |
| 85 } | 71 } |
| 86 | 72 |
| 87 } // namespace blink | 73 } // namespace blink |
| OLD | NEW |