Chromium Code Reviews| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/SVGShapePainter.h" | 6 #include "core/paint/SVGShapePainter.h" |
| 7 | 7 |
| 8 #include "core/layout/svg/LayoutSVGPath.h" | 8 #include "core/layout/svg/LayoutSVGPath.h" |
| 9 #include "core/layout/svg/LayoutSVGResourceMarker.h" | 9 #include "core/layout/svg/LayoutSVGResourceMarker.h" |
| 10 #include "core/layout/svg/LayoutSVGShape.h" | 10 #include "core/layout/svg/LayoutSVGShape.h" |
| 11 #include "core/layout/svg/SVGLayoutSupport.h" | 11 #include "core/layout/svg/SVGLayoutSupport.h" |
| 12 #include "core/layout/svg/SVGMarkerData.h" | 12 #include "core/layout/svg/SVGMarkerData.h" |
| 13 #include "core/layout/svg/SVGResources.h" | 13 #include "core/layout/svg/SVGResources.h" |
| 14 #include "core/layout/svg/SVGResourcesCache.h" | 14 #include "core/layout/svg/SVGResourcesCache.h" |
| 15 #include "core/paint/LayoutObjectDrawingRecorder.h" | 15 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 16 #include "core/paint/ObjectPainter.h" | 16 #include "core/paint/ObjectPainter.h" |
| 17 #include "core/paint/PaintInfo.h" | 17 #include "core/paint/PaintInfo.h" |
| 18 #include "core/paint/SVGContainerPainter.h" | 18 #include "core/paint/SVGContainerPainter.h" |
| 19 #include "core/paint/SVGPaintContext.h" | 19 #include "core/paint/SVGPaintContext.h" |
| 20 #include "core/paint/ScopeRecorder.h" | |
| 20 #include "core/paint/TransformRecorder.h" | 21 #include "core/paint/TransformRecorder.h" |
| 21 #include "platform/graphics/paint/DisplayItemListContextRecorder.h" | 22 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 22 #include "third_party/skia/include/core/SkPaint.h" | 23 #include "third_party/skia/include/core/SkPaint.h" |
| 23 #include "third_party/skia/include/core/SkPicture.h" | 24 #include "third_party/skia/include/core/SkPicture.h" |
| 24 | 25 |
| 25 namespace blink { | 26 namespace blink { |
| 26 | 27 |
| 27 static bool setupNonScalingStrokeContext(AffineTransform& strokeTransform, Graph icsContextStateSaver& stateSaver) | 28 static bool setupNonScalingStrokeContext(AffineTransform& strokeTransform, Graph icsContextStateSaver& stateSaver) |
| 28 { | 29 { |
| 29 if (!strokeTransform.isInvertible()) | 30 if (!strokeTransform.isInvertible()) |
| 30 return false; | 31 return false; |
| 31 | 32 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 strokePaint.setAntiAlias(shouldAntiAlias); | 94 strokePaint.setAntiAlias(shouldAntiAlias); |
| 94 | 95 |
| 95 StrokeData strokeData; | 96 StrokeData strokeData; |
| 96 SVGLayoutSupport::applyStrokeStyleToStrokeData(strok eData, m_layoutSVGShape.styleRef(), m_layoutSVGShape); | 97 SVGLayoutSupport::applyStrokeStyleToStrokeData(strok eData, m_layoutSVGShape.styleRef(), m_layoutSVGShape); |
| 97 strokeData.setupPaint(&strokePaint); | 98 strokeData.setupPaint(&strokePaint); |
| 98 | 99 |
| 99 strokeShape(paintContext.paintInfo().context, stroke Paint); | 100 strokeShape(paintContext.paintInfo().context, stroke Paint); |
| 100 } | 101 } |
| 101 break; | 102 break; |
| 102 case PT_MARKERS: | 103 case PT_MARKERS: |
| 103 paintMarkers(paintContext.paintInfo()); | 104 paintMarkers(paintContext.paintInfo(), boundingBox); |
| 104 break; | 105 break; |
| 105 default: | 106 default: |
| 106 ASSERT_NOT_REACHED(); | 107 ASSERT_NOT_REACHED(); |
| 107 break; | 108 break; |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 default: | 171 default: |
| 171 ASSERT(m_layoutSVGShape.hasPath()); | 172 ASSERT(m_layoutSVGShape.hasPath()); |
| 172 Path* usePath = &m_layoutSVGShape.path(); | 173 Path* usePath = &m_layoutSVGShape.path(); |
| 173 if (m_layoutSVGShape.hasNonScalingStroke()) | 174 if (m_layoutSVGShape.hasNonScalingStroke()) |
| 174 usePath = m_layoutSVGShape.nonScalingStrokePath(usePath, m_layoutSVG Shape.nonScalingStrokeTransform()); | 175 usePath = m_layoutSVGShape.nonScalingStrokePath(usePath, m_layoutSVG Shape.nonScalingStrokeTransform()); |
| 175 context->drawPath(usePath->skPath(), paint); | 176 context->drawPath(usePath->skPath(), paint); |
| 176 strokeZeroLengthLineCaps(context, paint); | 177 strokeZeroLengthLineCaps(context, paint); |
| 177 } | 178 } |
| 178 } | 179 } |
| 179 | 180 |
| 180 void SVGShapePainter::paintMarkers(const PaintInfo& paintInfo) | 181 void SVGShapePainter::paintMarkers(const PaintInfo& paintInfo, const FloatRect& boundingBox) |
| 181 { | 182 { |
| 182 const Vector<MarkerPosition>* markerPositions = m_layoutSVGShape.markerPosit ions(); | 183 const Vector<MarkerPosition>* markerPositions = m_layoutSVGShape.markerPosit ions(); |
| 183 if (!markerPositions || markerPositions->isEmpty()) | 184 if (!markerPositions || markerPositions->isEmpty()) |
| 184 return; | 185 return; |
| 185 | 186 |
| 186 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject( &m_layoutSVGShape); | 187 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject( &m_layoutSVGShape); |
| 187 if (!resources) | 188 if (!resources) |
| 188 return; | 189 return; |
| 189 | 190 |
| 190 LayoutSVGResourceMarker* markerStart = resources->markerStart(); | 191 LayoutSVGResourceMarker* markerStart = resources->markerStart(); |
| 191 LayoutSVGResourceMarker* markerMid = resources->markerMid(); | 192 LayoutSVGResourceMarker* markerMid = resources->markerMid(); |
| 192 LayoutSVGResourceMarker* markerEnd = resources->markerEnd(); | 193 LayoutSVGResourceMarker* markerEnd = resources->markerEnd(); |
| 193 if (!markerStart && !markerMid && !markerEnd) | 194 if (!markerStart && !markerMid && !markerEnd) |
| 194 return; | 195 return; |
| 195 | 196 |
| 196 float strokeWidth = m_layoutSVGShape.strokeWidth(); | 197 float strokeWidth = m_layoutSVGShape.strokeWidth(); |
| 197 unsigned size = markerPositions->size(); | 198 unsigned size = markerPositions->size(); |
| 199 SkPictureBuilder pictureBuilder(boundingBox); | |
| 200 PaintInfo markersPaintInfo(paintInfo); | |
| 201 markersPaintInfo.context = &pictureBuilder.context(); | |
|
pdr.
2015/06/02 21:47:52
Lets refactor this just a little. We don't really
| |
| 198 for (unsigned i = 0; i < size; ++i) { | 202 for (unsigned i = 0; i < size; ++i) { |
| 203 ScopeRecorder scopeRecorder(*markersPaintInfo.context, m_layoutSVGShape) ; | |
| 199 if (LayoutSVGResourceMarker* marker = SVGMarkerData::markerForType((*mar kerPositions)[i].type, markerStart, markerMid, markerEnd)) | 204 if (LayoutSVGResourceMarker* marker = SVGMarkerData::markerForType((*mar kerPositions)[i].type, markerStart, markerMid, markerEnd)) |
| 200 paintMarker(paintInfo, *marker, (*markerPositions)[i], strokeWidth); | 205 paintMarker(markersPaintInfo, *marker, (*markerPositions)[i], stroke Width); |
| 201 } | 206 } |
| 207 pictureBuilder.endRecording()->playback(paintInfo.context->canvas()); | |
| 202 } | 208 } |
| 203 | 209 |
| 204 void SVGShapePainter::paintMarker(const PaintInfo& paintInfo, LayoutSVGResourceM arker& marker, const MarkerPosition& position, float strokeWidth) | 210 void SVGShapePainter::paintMarker(const PaintInfo& paintInfo, LayoutSVGResourceM arker& marker, const MarkerPosition& position, float strokeWidth) |
| 205 { | 211 { |
| 206 // An empty viewBox disables rendering. | 212 // An empty viewBox disables rendering. |
| 207 SVGMarkerElement* markerElement = toSVGMarkerElement(marker.element()); | 213 SVGMarkerElement* markerElement = toSVGMarkerElement(marker.element()); |
| 208 ASSERT(markerElement); | 214 ASSERT(markerElement); |
| 209 if (markerElement->hasAttribute(SVGNames::viewBoxAttr) && markerElement->vie wBox()->currentValue()->isValid() && markerElement->viewBox()->currentValue()->v alue().isEmpty()) | 215 if (markerElement->hasAttribute(SVGNames::viewBoxAttr) && markerElement->vie wBox()->currentValue()->isValid() && markerElement->viewBox()->currentValue()->v alue().isEmpty()) |
| 210 return; | 216 return; |
| 211 | 217 |
| 218 PaintInfo markerPaintInfo(paintInfo); | |
| 219 markerPaintInfo.rect = LayoutRect::infiniteIntRect(); | |
| 212 { | 220 { |
| 213 DisplayItemListContextRecorder contextRecorder(*paintInfo.context); | |
| 214 PaintInfo markerPaintInfo(paintInfo); | |
| 215 markerPaintInfo.context = &contextRecorder.context(); | |
| 216 | |
| 217 // It's expensive to track the transformed paint cull rect for each | |
| 218 // marker so just disable culling. The shape paint call will already be | |
| 219 // culled if it is outside the paint info cull rect. | |
| 220 markerPaintInfo.rect = LayoutRect::infiniteIntRect(); | |
| 221 | |
| 222 TransformRecorder transformRecorder(*markerPaintInfo.context, marker, ma rker.markerTransformation(position.origin, position.angle, strokeWidth)); | 221 TransformRecorder transformRecorder(*markerPaintInfo.context, marker, ma rker.markerTransformation(position.origin, position.angle, strokeWidth)); |
| 223 OwnPtr<FloatClipRecorder> clipRecorder; | 222 OwnPtr<FloatClipRecorder> clipRecorder; |
| 224 if (SVGLayoutSupport::isOverflowHidden(&marker)) | 223 if (SVGLayoutSupport::isOverflowHidden(&marker)) |
| 225 clipRecorder = adoptPtr(new FloatClipRecorder(*markerPaintInfo.conte xt, marker, markerPaintInfo.phase, marker.viewport())); | 224 clipRecorder = adoptPtr(new FloatClipRecorder(*markerPaintInfo.conte xt, marker, markerPaintInfo.phase, marker.viewport())); |
| 226 | 225 |
| 227 SVGContainerPainter(marker).paint(markerPaintInfo); | 226 SVGContainerPainter(marker).paint(markerPaintInfo); |
| 228 } | 227 } |
| 229 } | 228 } |
| 230 | 229 |
| 231 void SVGShapePainter::strokeZeroLengthLineCaps(GraphicsContext* context, const S kPaint& strokePaint) | 230 void SVGShapePainter::strokeZeroLengthLineCaps(GraphicsContext* context, const S kPaint& strokePaint) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 253 // This open-codes LayoutSVGShape::nonScalingStrokePath, because the | 252 // This open-codes LayoutSVGShape::nonScalingStrokePath, because the |
| 254 // requirements here differ (we have a temporary path that we can | 253 // requirements here differ (we have a temporary path that we can |
| 255 // mutate.) | 254 // mutate.) |
| 256 if (m_layoutSVGShape.hasNonScalingStroke()) | 255 if (m_layoutSVGShape.hasNonScalingStroke()) |
| 257 tempPath.transform(nonScalingTransform); | 256 tempPath.transform(nonScalingTransform); |
| 258 context->drawPath(tempPath.skPath(), fillPaint); | 257 context->drawPath(tempPath.skPath(), fillPaint); |
| 259 } | 258 } |
| 260 } | 259 } |
| 261 | 260 |
| 262 } // namespace blink | 261 } // namespace blink |
| OLD | NEW |