diff options
Diffstat (limited to 'src/gpu/gl')
-rw-r--r-- | src/gpu/gl/GrGLPath.cpp | 42 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPath.h | 5 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathRange.cpp | 53 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathRange.h | 8 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathRendering.cpp | 8 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathRendering.h | 5 |
6 files changed, 56 insertions, 65 deletions
diff --git a/src/gpu/gl/GrGLPath.cpp b/src/gpu/gl/GrGLPath.cpp index ed5a31d9d2..05460187ef 100644 --- a/src/gpu/gl/GrGLPath.cpp +++ b/src/gpu/gl/GrGLPath.cpp @@ -8,6 +8,7 @@ #include "GrGLPath.h" #include "GrGLPathRendering.h" #include "GrGLGpu.h" +#include "GrStyle.h" namespace { inline GrGLubyte verb_to_gl_path_cmd(SkPath::Verb verb) { @@ -251,9 +252,7 @@ void GrGLPath::InitPathObjectPathData(GrGLGpu* gpu, SkAssertResult(init_path_object_for_general_path<false>(gpu, pathID, skPath)); } -void GrGLPath::InitPathObjectStroke(GrGLGpu* gpu, GrGLuint pathID, const GrStrokeInfo& stroke) { - SkASSERT(stroke.needToApply()); - SkASSERT(!stroke.isDashed()); +void GrGLPath::InitPathObjectStroke(GrGLGpu* gpu, GrGLuint pathID, const SkStrokeRec& stroke) { SkASSERT(!stroke.isHairlineStyle()); GR_GL_CALL(gpu->glInterface(), PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stroke.getWidth()))); @@ -270,8 +269,8 @@ void GrGLPath::InitPathObjectEmptyPath(GrGLGpu* gpu, GrGLuint pathID) { GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, 0, nullptr, 0, GR_GL_FLOAT, nullptr)); } -GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStrokeInfo& origStroke) - : INHERITED(gpu, origSkPath, origStroke), +GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStyle& style) + : INHERITED(gpu, origSkPath, style), fPathID(gpu->glPathRendering()->genPaths(1)) { if (origSkPath.isEmpty()) { @@ -281,21 +280,21 @@ GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStrokeInfo& o } else { const SkPath* skPath = &origSkPath; SkTLazy<SkPath> tmpPath; - const GrStrokeInfo* stroke = &origStroke; - GrStrokeInfo tmpStroke(SkStrokeRec::kFill_InitStyle); + SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); - if (stroke->isDashed()) { + if (style.pathEffect()) { // Skia stroking and NVPR stroking differ with respect to dashing // pattern. - // Convert a dashing to either a stroke or a fill. - if (stroke->applyDashToPath(tmpPath.init(), &tmpStroke, *skPath)) { + // Convert a dashing (or other path effect) to either a stroke or a fill. + if (style.applyPathEffectToPath(tmpPath.init(), &stroke, *skPath, SK_Scalar1)) { skPath = tmpPath.get(); - stroke = &tmpStroke; } + } else { + stroke = style.strokeRec(); } bool didInit = false; - if (stroke->needToApply() && stroke->getCap() != SkPaint::kButt_Cap) { + if (stroke.needToApply() && stroke.getCap() != SkPaint::kButt_Cap) { // Skia stroking and NVPR stroking differ with respect to stroking // end caps of empty subpaths. // Convert stroke to fill if path contains empty subpaths. @@ -304,10 +303,9 @@ GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStrokeInfo& o if (!tmpPath.isValid()) { tmpPath.init(); } - SkAssertResult(stroke->applyToPath(tmpPath.get(), *skPath)); + SkAssertResult(stroke.applyToPath(tmpPath.get(), *skPath)); skPath = tmpPath.get(); - tmpStroke.setFillStyle(); - stroke = &tmpStroke; + stroke.setFillStyle(); } } @@ -315,18 +313,16 @@ GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStrokeInfo& o InitPathObjectPathData(gpu, fPathID, *skPath); } - fShouldStroke = stroke->needToApply(); - fShouldFill = stroke->isFillStyle() || - stroke->getStyle() == SkStrokeRec::kStrokeAndFill_Style; + fShouldStroke = stroke.needToApply(); + fShouldFill = stroke.isFillStyle() || + stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style; fFillType = convert_skpath_filltype(skPath->getFillType()); fBounds = skPath->getBounds(); - + SkScalar radius = stroke.getInflationRadius(); + fBounds.outset(radius, radius); if (fShouldStroke) { - InitPathObjectStroke(gpu, fPathID, *stroke); - - // FIXME: try to account for stroking, without rasterizing the stroke. - fBounds.outset(stroke->getWidth(), stroke->getWidth()); + InitPathObjectStroke(gpu, fPathID, stroke); } } diff --git a/src/gpu/gl/GrGLPath.h b/src/gpu/gl/GrGLPath.h index 1ef1346133..ddcee533ee 100644 --- a/src/gpu/gl/GrGLPath.h +++ b/src/gpu/gl/GrGLPath.h @@ -12,6 +12,7 @@ #include "gl/GrGLTypes.h" class GrGLGpu; +class GrStyle; /** * Currently this represents a path built using GL_NV_path_rendering. If we @@ -27,12 +28,12 @@ public: static void InitPathObjectPathData(GrGLGpu*, GrGLuint pathID, const SkPath&); - static void InitPathObjectStroke(GrGLGpu* gpu, GrGLuint pathID, const GrStrokeInfo& stroke); + static void InitPathObjectStroke(GrGLGpu*, GrGLuint pathID, const SkStrokeRec&); static void InitPathObjectEmptyPath(GrGLGpu*, GrGLuint pathID); - GrGLPath(GrGLGpu* gpu, const SkPath& path, const GrStrokeInfo& stroke); + GrGLPath(GrGLGpu*, const SkPath&, const GrStyle&); GrGLuint pathID() const { return fPathID; } bool shouldStroke() const { return fShouldStroke; } diff --git a/src/gpu/gl/GrGLPathRange.cpp b/src/gpu/gl/GrGLPathRange.cpp index 6ed7bcc425..da1e9fe709 100644 --- a/src/gpu/gl/GrGLPathRange.cpp +++ b/src/gpu/gl/GrGLPathRange.cpp @@ -10,9 +10,9 @@ #include "GrGLPathRendering.h" #include "GrGLGpu.h" -GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const GrStrokeInfo& stroke) +GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const GrStyle& style) : INHERITED(gpu, pathGenerator), - fStroke(stroke), + fStyle(style), fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())), fGpuMemorySize(0) { this->init(); @@ -23,9 +23,9 @@ GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, GrGLuint basePathID, int numPaths, size_t gpuMemorySize, - const GrStrokeInfo& stroke) + const GrStyle& style) : INHERITED(gpu, numPaths), - fStroke(stroke), + fStyle(style), fBasePathID(basePathID), fGpuMemorySize(gpuMemorySize) { this->init(); @@ -33,19 +33,20 @@ GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, } void GrGLPathRange::init() { + const SkStrokeRec& stroke = fStyle.strokeRec(); // Must force fill: // * dashing: NVPR stroke dashing is different to Skia. // * end caps: NVPR stroking degenerate contours with end caps is different to Skia. - bool forceFill = fStroke.isDashed() || - (fStroke.needToApply() && fStroke.getCap() != SkPaint::kButt_Cap); + bool forceFill = fStyle.pathEffect() || + (stroke.needToApply() && stroke.getCap() != SkPaint::kButt_Cap); if (forceFill) { fShouldStroke = false; fShouldFill = true; } else { - fShouldStroke = fStroke.needToApply(); - fShouldFill = fStroke.isFillStyle() || - fStroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style; + fShouldStroke = stroke.needToApply(); + fShouldFill = stroke.isFillStyle() || + stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style; } } @@ -54,7 +55,6 @@ void GrGLPathRange::onInitPath(int index, const SkPath& origSkPath) const { if (nullptr == gpu) { return; } - // Make sure the path at this index hasn't been initted already. SkDEBUGCODE( GrGLboolean isPath; @@ -65,32 +65,25 @@ void GrGLPathRange::onInitPath(int index, const SkPath& origSkPath) const { GrGLPath::InitPathObjectEmptyPath(gpu, fBasePathID + index); } else if (fShouldStroke) { GrGLPath::InitPathObjectPathData(gpu, fBasePathID + index, origSkPath); - GrGLPath::InitPathObjectStroke(gpu, fBasePathID + index, fStroke); + GrGLPath::InitPathObjectStroke(gpu, fBasePathID + index, fStyle.strokeRec()); } else { const SkPath* skPath = &origSkPath; SkTLazy<SkPath> tmpPath; - const GrStrokeInfo* stroke = &fStroke; - GrStrokeInfo tmpStroke(SkStrokeRec::kFill_InitStyle); - - // Dashing must be applied to the path. However, if dashing is present, - // we must convert all the paths to fills. The GrStrokeInfo::applyDash leaves - // simple paths as strokes but converts other paths to fills. - // Thus we must stroke the strokes here, so that all paths in the - // path range are using the same style. - if (fStroke.isDashed()) { - if (!stroke->applyDashToPath(tmpPath.init(), &tmpStroke, *skPath)) { + if (!fStyle.isSimpleFill()) { + SkStrokeRec::InitStyle fill; + // The path effect must be applied to the path. However, if a path effect is present, + // we must convert all the paths to fills. The path effect application may leave + // simple paths as strokes but converts other paths to fills. + // Thus we must stroke the strokes here, so that all paths in the + // path range are using the same style. + if (!fStyle.applyToPath(tmpPath.init(), &fill, *skPath, SK_Scalar1)) { return; } + // We shouldn't have allowed hairlines or arbitrary path effect styles to get here + // so after application we better have a filled path. + SkASSERT(SkStrokeRec::kFill_InitStyle == fill); skPath = tmpPath.get(); - stroke = &tmpStroke; - } - if (stroke->needToApply()) { - if (!tmpPath.isValid()) { - tmpPath.init(); - } - if (!stroke->applyToPath(tmpPath.get(), *tmpPath.get())) { - return; - } + } GrGLPath::InitPathObjectPathData(gpu, fBasePathID + index, *skPath); } diff --git a/src/gpu/gl/GrGLPathRange.h b/src/gpu/gl/GrGLPathRange.h index ed9766d958..7d920105a0 100644 --- a/src/gpu/gl/GrGLPathRange.h +++ b/src/gpu/gl/GrGLPathRange.h @@ -9,7 +9,7 @@ #define GrGLPathRange_DEFINED #include "../GrPathRange.h" -#include "GrStrokeInfo.h" +#include "GrStyle.h" #include "gl/GrGLTypes.h" class GrGLGpu; @@ -26,7 +26,7 @@ public: * Initialize a GL path range from a PathGenerator. This class will allocate * the GPU path objects and initialize them lazily. */ - GrGLPathRange(GrGLGpu*, PathGenerator*, const GrStrokeInfo&); + GrGLPathRange(GrGLGpu*, PathGenerator*, const GrStyle&); /** * Initialize a GL path range from an existing range of pre-initialized GPU @@ -37,7 +37,7 @@ public: GrGLuint basePathID, int numPaths, size_t gpuMemorySize, - const GrStrokeInfo&); + const GrStyle&); GrGLuint basePathID() const { return fBasePathID; } @@ -54,7 +54,7 @@ private: void init(); size_t onGpuMemorySize() const override { return fGpuMemorySize; } - const GrStrokeInfo fStroke; + const GrStyle fStyle; GrGLuint fBasePathID; mutable size_t fGpuMemorySize; bool fShouldStroke; diff --git a/src/gpu/gl/GrGLPathRendering.cpp b/src/gpu/gl/GrGLPathRendering.cpp index 0ecf58a8e1..5616f9d58a 100644 --- a/src/gpu/gl/GrGLPathRendering.cpp +++ b/src/gpu/gl/GrGLPathRendering.cpp @@ -106,13 +106,13 @@ void GrGLPathRendering::resetContext() { fHWPathStencilSettings.invalidate(); } -GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const GrStrokeInfo& stroke) { - return new GrGLPath(this->gpu(), inPath, stroke); +GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const GrStyle& style) { + return new GrGLPath(this->gpu(), inPath, style); } GrPathRange* GrGLPathRendering::createPathRange(GrPathRange::PathGenerator* pathGenerator, - const GrStrokeInfo& stroke) { - return new GrGLPathRange(this->gpu(), pathGenerator, stroke); + const GrStyle& style) { + return new GrGLPathRange(this->gpu(), pathGenerator, style); } void GrGLPathRendering::onStencilPath(const StencilPathArgs& args, const GrPath* path) { diff --git a/src/gpu/gl/GrGLPathRendering.h b/src/gpu/gl/GrGLPathRendering.h index b39c866c6f..8fb699deb3 100644 --- a/src/gpu/gl/GrGLPathRendering.h +++ b/src/gpu/gl/GrGLPathRendering.h @@ -16,6 +16,7 @@ class GrGLNameAllocator; class GrGLGpu; +class GrStyle; /** * This class wraps the NV_path_rendering extension and manages its various @@ -33,9 +34,9 @@ public: virtual ~GrGLPathRendering(); // GrPathRendering implementations. - GrPath* createPath(const SkPath&, const GrStrokeInfo&) override; + GrPath* createPath(const SkPath&, const GrStyle&) override; virtual GrPathRange* createPathRange(GrPathRange::PathGenerator*, - const GrStrokeInfo&) override; + const GrStyle&) override; /* Called when the 3D context state is unknown. */ void resetContext(); |