| 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/SVGShapePainter.h" | 5 #include "core/paint/SVGShapePainter.h" |
| 6 | 6 |
| 7 #include "core/layout/svg/LayoutSVGResourceMarker.h" | 7 #include "core/layout/svg/LayoutSVGResourceMarker.h" |
| 8 #include "core/layout/svg/LayoutSVGShape.h" | 8 #include "core/layout/svg/LayoutSVGShape.h" |
| 9 #include "core/layout/svg/SVGLayoutSupport.h" | 9 #include "core/layout/svg/SVGLayoutSupport.h" |
| 10 #include "core/layout/svg/SVGMarkerData.h" | 10 #include "core/layout/svg/SVGMarkerData.h" |
| 11 #include "core/layout/svg/SVGResources.h" | 11 #include "core/layout/svg/SVGResources.h" |
| 12 #include "core/layout/svg/SVGResourcesCache.h" | 12 #include "core/layout/svg/SVGResourcesCache.h" |
| 13 #include "core/paint/FloatClipRecorder.h" | 13 #include "core/paint/FloatClipRecorder.h" |
| 14 #include "core/paint/LayoutObjectDrawingRecorder.h" | 14 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 15 #include "core/paint/ObjectPainter.h" | 15 #include "core/paint/ObjectPainter.h" |
| 16 #include "core/paint/PaintInfo.h" | 16 #include "core/paint/PaintInfo.h" |
| 17 #include "core/paint/SVGContainerPainter.h" | 17 #include "core/paint/SVGContainerPainter.h" |
| 18 #include "core/paint/SVGPaintContext.h" | 18 #include "core/paint/SVGPaintContext.h" |
| 19 #include "core/paint/TransformRecorder.h" | 19 #include "core/paint/TransformRecorder.h" |
| 20 #include "platform/graphics/GraphicsContextStateSaver.h" | 20 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 21 #include "platform/graphics/paint/SkPictureBuilder.h" | 21 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 22 #include "third_party/skia/include/core/SkPaint.h" | 22 #include "third_party/skia/include/core/SkPaint.h" |
| 23 #include "third_party/skia/include/core/SkPicture.h" | 23 #include "skia/ext/cdl_picture.h" |
| 24 #include "wtf/Optional.h" | 24 #include "wtf/Optional.h" |
| 25 | 25 |
| 26 namespace blink { | 26 namespace blink { |
| 27 | 27 |
| 28 static bool setupNonScalingStrokeContext( | 28 static bool setupNonScalingStrokeContext( |
| 29 AffineTransform& strokeTransform, | 29 AffineTransform& strokeTransform, |
| 30 GraphicsContextStateSaver& stateSaver) { | 30 GraphicsContextStateSaver& stateSaver) { |
| 31 if (!strokeTransform.isInvertible()) | 31 if (!strokeTransform.isInvertible()) |
| 32 return false; | 32 return false; |
| 33 | 33 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 paintContext.paintInfo().context, m_layoutSVGShape, | 69 paintContext.paintInfo().context, m_layoutSVGShape, |
| 70 paintContext.paintInfo().phase, boundingBox); | 70 paintContext.paintInfo().phase, boundingBox); |
| 71 const SVGComputedStyle& svgStyle = m_layoutSVGShape.style()->svgStyle(); | 71 const SVGComputedStyle& svgStyle = m_layoutSVGShape.style()->svgStyle(); |
| 72 | 72 |
| 73 bool shouldAntiAlias = svgStyle.shapeRendering() != SR_CRISPEDGES && | 73 bool shouldAntiAlias = svgStyle.shapeRendering() != SR_CRISPEDGES && |
| 74 svgStyle.shapeRendering() != SR_OPTIMIZESPEED; | 74 svgStyle.shapeRendering() != SR_OPTIMIZESPEED; |
| 75 | 75 |
| 76 for (int i = 0; i < 3; i++) { | 76 for (int i = 0; i < 3; i++) { |
| 77 switch (svgStyle.paintOrderType(i)) { | 77 switch (svgStyle.paintOrderType(i)) { |
| 78 case PT_FILL: { | 78 case PT_FILL: { |
| 79 SkPaint fillPaint; | 79 CdlPaint fillPaint; |
| 80 if (!SVGPaintContext::paintForLayoutObject( | 80 if (!SVGPaintContext::paintForLayoutObject( |
| 81 paintContext.paintInfo(), m_layoutSVGShape.styleRef(), | 81 paintContext.paintInfo(), m_layoutSVGShape.styleRef(), |
| 82 m_layoutSVGShape, ApplyToFillMode, fillPaint)) | 82 m_layoutSVGShape, ApplyToFillMode, fillPaint)) |
| 83 break; | 83 break; |
| 84 fillPaint.setAntiAlias(shouldAntiAlias); | 84 fillPaint.setAntiAlias(shouldAntiAlias); |
| 85 fillShape(paintContext.paintInfo().context, fillPaint, | 85 fillShape(paintContext.paintInfo().context, fillPaint, |
| 86 fillRuleFromStyle(paintContext.paintInfo(), svgStyle)); | 86 fillRuleFromStyle(paintContext.paintInfo(), svgStyle)); |
| 87 break; | 87 break; |
| 88 } | 88 } |
| 89 case PT_STROKE: | 89 case PT_STROKE: |
| 90 if (svgStyle.hasVisibleStroke()) { | 90 if (svgStyle.hasVisibleStroke()) { |
| 91 GraphicsContextStateSaver stateSaver( | 91 GraphicsContextStateSaver stateSaver( |
| 92 paintContext.paintInfo().context, false); | 92 paintContext.paintInfo().context, false); |
| 93 AffineTransform nonScalingTransform; | 93 AffineTransform nonScalingTransform; |
| 94 const AffineTransform* additionalPaintServerTransform = 0; | 94 const AffineTransform* additionalPaintServerTransform = 0; |
| 95 | 95 |
| 96 if (m_layoutSVGShape.hasNonScalingStroke()) { | 96 if (m_layoutSVGShape.hasNonScalingStroke()) { |
| 97 nonScalingTransform = | 97 nonScalingTransform = |
| 98 m_layoutSVGShape.nonScalingStrokeTransform(); | 98 m_layoutSVGShape.nonScalingStrokeTransform(); |
| 99 if (!setupNonScalingStrokeContext(nonScalingTransform, | 99 if (!setupNonScalingStrokeContext(nonScalingTransform, |
| 100 stateSaver)) | 100 stateSaver)) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 // Non-scaling stroke needs to reset the transform back to the | 103 // Non-scaling stroke needs to reset the transform back to the |
| 104 // host transform. | 104 // host transform. |
| 105 additionalPaintServerTransform = &nonScalingTransform; | 105 additionalPaintServerTransform = &nonScalingTransform; |
| 106 } | 106 } |
| 107 | 107 |
| 108 SkPaint strokePaint; | 108 CdlPaint strokePaint; |
| 109 if (!SVGPaintContext::paintForLayoutObject( | 109 if (!SVGPaintContext::paintForLayoutObject( |
| 110 paintContext.paintInfo(), m_layoutSVGShape.styleRef(), | 110 paintContext.paintInfo(), m_layoutSVGShape.styleRef(), |
| 111 m_layoutSVGShape, ApplyToStrokeMode, strokePaint, | 111 m_layoutSVGShape, ApplyToStrokeMode, strokePaint, |
| 112 additionalPaintServerTransform)) | 112 additionalPaintServerTransform)) |
| 113 break; | 113 break; |
| 114 strokePaint.setAntiAlias(shouldAntiAlias); | 114 strokePaint.setAntiAlias(shouldAntiAlias); |
| 115 | 115 |
| 116 StrokeData strokeData; | 116 StrokeData strokeData; |
| 117 SVGLayoutSupport::applyStrokeStyleToStrokeData( | 117 SVGLayoutSupport::applyStrokeStyleToStrokeData( |
| 118 strokeData, m_layoutSVGShape.styleRef(), m_layoutSVGShape, | 118 strokeData, m_layoutSVGShape.styleRef(), m_layoutSVGShape, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 ~PathWithTemporaryWindingRule() { m_path.setFillType(m_savedFillType); } | 151 ~PathWithTemporaryWindingRule() { m_path.setFillType(m_savedFillType); } |
| 152 | 152 |
| 153 const SkPath& getSkPath() const { return m_path; } | 153 const SkPath& getSkPath() const { return m_path; } |
| 154 | 154 |
| 155 private: | 155 private: |
| 156 SkPath& m_path; | 156 SkPath& m_path; |
| 157 SkPath::FillType m_savedFillType; | 157 SkPath::FillType m_savedFillType; |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 void SVGShapePainter::fillShape(GraphicsContext& context, | 160 void SVGShapePainter::fillShape(GraphicsContext& context, |
| 161 const SkPaint& paint, | 161 const CdlPaint& paint, |
| 162 SkPath::FillType fillType) { | 162 SkPath::FillType fillType) { |
| 163 switch (m_layoutSVGShape.geometryCodePath()) { | 163 switch (m_layoutSVGShape.geometryCodePath()) { |
| 164 case RectGeometryFastPath: | 164 case RectGeometryFastPath: |
| 165 context.drawRect(m_layoutSVGShape.objectBoundingBox(), paint); | 165 context.drawRect(m_layoutSVGShape.objectBoundingBox(), paint); |
| 166 break; | 166 break; |
| 167 case EllipseGeometryFastPath: | 167 case EllipseGeometryFastPath: |
| 168 context.drawOval(m_layoutSVGShape.objectBoundingBox(), paint); | 168 context.drawOval(m_layoutSVGShape.objectBoundingBox(), paint); |
| 169 break; | 169 break; |
| 170 default: { | 170 default: { |
| 171 PathWithTemporaryWindingRule pathWithWinding(m_layoutSVGShape.path(), | 171 PathWithTemporaryWindingRule pathWithWinding(m_layoutSVGShape.path(), |
| 172 fillType); | 172 fillType); |
| 173 context.drawPath(pathWithWinding.getSkPath(), paint); | 173 context.drawPath(pathWithWinding.getSkPath(), paint); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 void SVGShapePainter::strokeShape(GraphicsContext& context, | 178 void SVGShapePainter::strokeShape(GraphicsContext& context, |
| 179 const SkPaint& paint) { | 179 const CdlPaint& paint) { |
| 180 if (!m_layoutSVGShape.style()->svgStyle().hasVisibleStroke()) | 180 if (!m_layoutSVGShape.style()->svgStyle().hasVisibleStroke()) |
| 181 return; | 181 return; |
| 182 | 182 |
| 183 switch (m_layoutSVGShape.geometryCodePath()) { | 183 switch (m_layoutSVGShape.geometryCodePath()) { |
| 184 case RectGeometryFastPath: | 184 case RectGeometryFastPath: |
| 185 context.drawRect(m_layoutSVGShape.objectBoundingBox(), paint); | 185 context.drawRect(m_layoutSVGShape.objectBoundingBox(), paint); |
| 186 break; | 186 break; |
| 187 case EllipseGeometryFastPath: | 187 case EllipseGeometryFastPath: |
| 188 context.drawOval(m_layoutSVGShape.objectBoundingBox(), paint); | 188 context.drawOval(m_layoutSVGShape.objectBoundingBox(), paint); |
| 189 break; | 189 break; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 marker.markerTransformation(position.origin, position.angle, | 246 marker.markerTransformation(position.origin, position.angle, |
| 247 strokeWidth)); | 247 strokeWidth)); |
| 248 Optional<FloatClipRecorder> clipRecorder; | 248 Optional<FloatClipRecorder> clipRecorder; |
| 249 if (SVGLayoutSupport::isOverflowHidden(&marker)) | 249 if (SVGLayoutSupport::isOverflowHidden(&marker)) |
| 250 clipRecorder.emplace(paintInfo.context, marker, paintInfo.phase, | 250 clipRecorder.emplace(paintInfo.context, marker, paintInfo.phase, |
| 251 marker.viewport()); | 251 marker.viewport()); |
| 252 SVGContainerPainter(marker).paint(paintInfo); | 252 SVGContainerPainter(marker).paint(paintInfo); |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace blink | 255 } // namespace blink |
| OLD | NEW |