diff options
author | Ben Wagner <bungeman@google.com> | 2018-03-29 11:46:24 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-29 17:18:05 +0000 |
commit | 3746ac21df90e44ed1ed9ec2f1e4694fbcd1d840 (patch) | |
tree | de1fff31711fa4c41e849d0281c8a2c5b400db88 /src/gpu | |
parent | c3bc425bd4d630f4c6b69f38473fc69b77a1d5b9 (diff) |
Remove path ranges from gpu.
These appear to have been added to handle glyph paths with nvpr and no
longer appear to be used.
Change-Id: Id75e2e85ab837a5808e7641873d217c844cd827c
Reviewed-on: https://skia-review.googlesource.com/117103
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrGpu.h | 1 | ||||
-rw-r--r-- | src/gpu/GrPathRange.cpp | 55 | ||||
-rw-r--r-- | src/gpu/GrPathRange.h | 153 | ||||
-rw-r--r-- | src/gpu/GrPathRendering.cpp | 49 | ||||
-rw-r--r-- | src/gpu/GrPathRendering.h | 32 | ||||
-rw-r--r-- | src/gpu/GrResourceCache.cpp | 1 | ||||
-rw-r--r-- | src/gpu/GrResourceProvider.h | 3 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathRange.cpp | 110 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathRange.h | 66 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathRendering.cpp | 72 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathRendering.h | 11 | ||||
-rw-r--r-- | src/gpu/ops/GrDrawPathOp.cpp | 148 | ||||
-rw-r--r-- | src/gpu/ops/GrDrawPathOp.h | 113 |
13 files changed, 1 insertions, 813 deletions
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 87d93ac4e4..31870dc833 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -28,7 +28,6 @@ struct GrContextOptions; class GrGLContext; class GrMesh; class GrPath; -class GrPathRange; class GrPathRenderer; class GrPathRendererChain; class GrPathRendering; diff --git a/src/gpu/GrPathRange.cpp b/src/gpu/GrPathRange.cpp deleted file mode 100644 index 8ed4fd62a7..0000000000 --- a/src/gpu/GrPathRange.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "GrPathRange.h" -#include "SkPath.h" - -GrPathRange::GrPathRange(GrGpu* gpu, - PathGenerator* pathGenerator) - : INHERITED(gpu), - fPathGenerator(SkRef(pathGenerator)), - fNumPaths(fPathGenerator->getNumPaths()) { - const int numGroups = (fNumPaths + kPathsPerGroup - 1) / kPathsPerGroup; - fGeneratedPaths.reset((numGroups + 7) / 8); // 1 bit per path group. - memset(&fGeneratedPaths.front(), 0, fGeneratedPaths.count()); -} - -GrPathRange::GrPathRange(GrGpu* gpu, - int numPaths) - : INHERITED(gpu), - fNumPaths(numPaths) { -} - -void GrPathRange::loadPathsIfNeeded(const void* indices, PathIndexType indexType, int count) const { - switch (indexType) { - case kU8_PathIndexType: - return this->loadPathsIfNeeded(reinterpret_cast<const uint8_t*>(indices), count); - case kU16_PathIndexType: - return this->loadPathsIfNeeded(reinterpret_cast<const uint16_t*>(indices), count); - case kU32_PathIndexType: - return this->loadPathsIfNeeded(reinterpret_cast<const uint32_t*>(indices), count); - default: - SK_ABORT("Unknown path index type"); - } -} - -#ifdef SK_DEBUG - -void GrPathRange::assertPathsLoaded(const void* indices, PathIndexType indexType, int count) const { - switch (indexType) { - case kU8_PathIndexType: - return this->assertPathsLoaded(reinterpret_cast<const uint8_t*>(indices), count); - case kU16_PathIndexType: - return this->assertPathsLoaded(reinterpret_cast<const uint16_t*>(indices), count); - case kU32_PathIndexType: - return this->assertPathsLoaded(reinterpret_cast<const uint32_t*>(indices), count); - default: - SK_ABORT("Unknown path index type"); - } -} - -#endif diff --git a/src/gpu/GrPathRange.h b/src/gpu/GrPathRange.h deleted file mode 100644 index 39779a7008..0000000000 --- a/src/gpu/GrPathRange.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrPathRange_DEFINED -#define GrPathRange_DEFINED - -#include "GrGpuResource.h" -#include "SkPath.h" -#include "SkRefCnt.h" -#include "SkTArray.h" - -class SkDescriptor; - -/** - * Represents a contiguous range of GPU path objects. - * This object is immutable with the exception that individual paths may be - * initialized lazily. - */ - -class GrPathRange : public GrGpuResource { -public: - - - enum PathIndexType { - kU8_PathIndexType, //!< uint8_t - kU16_PathIndexType, //!< uint16_t - kU32_PathIndexType, //!< uint32_t - - kLast_PathIndexType = kU32_PathIndexType - }; - - static inline int PathIndexSizeInBytes(PathIndexType type) { - GR_STATIC_ASSERT(0 == kU8_PathIndexType); - GR_STATIC_ASSERT(1 == kU16_PathIndexType); - GR_STATIC_ASSERT(2 == kU32_PathIndexType); - GR_STATIC_ASSERT(kU32_PathIndexType == kLast_PathIndexType); - - return 1 << type; - } - - /** - * Class that generates the paths for a specific range. - */ - class PathGenerator : public SkRefCnt { - public: - virtual int getNumPaths() = 0; - virtual void generatePath(int index, SkPath* out) = 0; -#ifdef SK_DEBUG - virtual bool isEqualTo(const SkDescriptor&) const { return false; } -#endif - virtual ~PathGenerator() {} - }; - - /** - * Initialize a lazy-loaded path range. This class will generate an SkPath and call - * onInitPath() for each path within the range before it is drawn for the first time. - */ - GrPathRange(GrGpu*, PathGenerator*); - - /** - * Initialize an eager-loaded path range. The subclass is responsible for ensuring all - * the paths are initialized up front. - */ - GrPathRange(GrGpu*, int numPaths); - - int getNumPaths() const { return fNumPaths; } - const PathGenerator* getPathGenerator() const { return fPathGenerator.get(); } - - void loadPathsIfNeeded(const void* indices, PathIndexType, int count) const; - - template<typename IndexType> void loadPathsIfNeeded(const IndexType* indices, int count) const { - if (!fPathGenerator) { - return; - } - - bool didLoadPaths = false; - - for (int i = 0; i < count; ++i) { - SkASSERT(indices[i] < static_cast<uint32_t>(fNumPaths)); - - const int groupIndex = indices[i] / kPathsPerGroup; - const int groupByte = groupIndex / 8; - const uint8_t groupBit = 1 << (groupIndex % 8); - - const bool hasPath = SkToBool(fGeneratedPaths[groupByte] & groupBit); - if (!hasPath) { - // We track which paths are loaded in groups of kPathsPerGroup. To - // mark a path as loaded we need to load the entire group. - const int groupFirstPath = groupIndex * kPathsPerGroup; - const int groupLastPath = SkTMin(groupFirstPath + kPathsPerGroup, fNumPaths) - 1; - - SkPath path; - for (int pathIdx = groupFirstPath; pathIdx <= groupLastPath; ++pathIdx) { - fPathGenerator->generatePath(pathIdx, &path); - this->onInitPath(pathIdx, path); - } - - fGeneratedPaths[groupByte] |= groupBit; - didLoadPaths = true; - } - } - - if (didLoadPaths) { - this->didChangeGpuMemorySize(); - } - } - -#ifdef SK_DEBUG - void assertPathsLoaded(const void* indices, PathIndexType, int count) const; - - template<typename IndexType> void assertPathsLoaded(const IndexType* indices, int count) const { - if (!fPathGenerator) { - return; - } - - for (int i = 0; i < count; ++i) { - SkASSERT(indices[i] < static_cast<uint32_t>(fNumPaths)); - - const int groupIndex = indices[i] / kPathsPerGroup; - const int groupByte = groupIndex / 8; - const uint8_t groupBit = 1 << (groupIndex % 8); - - SkASSERT(fGeneratedPaths[groupByte] & groupBit); - } - } - - virtual bool isEqualTo(const SkDescriptor& desc) const { - return nullptr != fPathGenerator.get() && fPathGenerator->isEqualTo(desc); - } -#endif -protected: - // Initialize a path in the range before drawing. This is only called when - // fPathGenerator is non-null. The child class need not call didChangeGpuMemorySize(), - // GrPathRange will take care of that after the call is complete. - virtual void onInitPath(int index, const SkPath&) const = 0; - -private: - enum { - kPathsPerGroup = 16 // Paths get tracked in groups of 16 for lazy loading. - }; - - mutable sk_sp<PathGenerator> fPathGenerator; - mutable SkTArray<uint8_t, true /*MEM_COPY*/> fGeneratedPaths; - const int fNumPaths; - - typedef GrGpuResource INHERITED; -}; - -#endif diff --git a/src/gpu/GrPathRendering.cpp b/src/gpu/GrPathRendering.cpp index b16ff91ef2..2da1d2fb31 100644 --- a/src/gpu/GrPathRendering.cpp +++ b/src/gpu/GrPathRendering.cpp @@ -12,7 +12,6 @@ #include "SkGlyph.h" #include "SkMatrix.h" #include "SkTypeface.h" -#include "GrPathRange.h" const GrUserStencilSettings& GrPathRendering::GetStencilPassSettings(FillType fill) { switch (fill) { @@ -45,33 +44,6 @@ const GrUserStencilSettings& GrPathRendering::GetStencilPassSettings(FillType fi } } -class GlyphGenerator : public GrPathRange::PathGenerator { -public: - GlyphGenerator(const SkTypeface& typeface, const SkScalerContextEffects& effects, - const SkDescriptor& desc) - : fScalerContext(typeface.createScalerContext(effects, &desc)) -#ifdef SK_DEBUG - , fDesc(desc.copy()) -#endif - {} - - int getNumPaths() override { - return fScalerContext->getGlyphCount(); - } - - void generatePath(int glyphID, SkPath* out) override { - fScalerContext->getPath(glyphID, out); - } -#ifdef SK_DEBUG - bool isEqualTo(const SkDescriptor& desc) const override { return *fDesc == desc; } -#endif -private: - const std::unique_ptr<SkScalerContext> fScalerContext; -#ifdef SK_DEBUG - const std::unique_ptr<SkDescriptor> fDesc; -#endif -}; - void GrPathRendering::stencilPath(const StencilPathArgs& args, const GrPath* path) { fGpu->handleDirtyContext(); this->onStencilPath(args, path); @@ -88,24 +60,3 @@ void GrPathRendering::drawPath(const GrPipeline& pipeline, } this->onDrawPath(pipeline, primProc, stencilPassSettings, path); } - -void GrPathRendering::drawPaths(const GrPipeline& pipeline, - const GrPrimitiveProcessor& primProc, - // Cover pass settings in pipeline. - const GrStencilSettings& stencilPassSettings, - const GrPathRange* pathRange, - const void* indices, - PathIndexType indexType, - const float transformValues[], - PathTransformType transformType, - int count) { - fGpu->handleDirtyContext(); - if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*fGpu->caps())) { - fGpu->xferBarrier(pipeline.renderTarget(), barrierType); - } -#ifdef SK_DEBUG - pathRange->assertPathsLoaded(indices, indexType, count); -#endif - this->onDrawPaths(pipeline, primProc, stencilPassSettings, pathRange, indices, indexType, - transformValues, transformType, count); -} diff --git a/src/gpu/GrPathRendering.h b/src/gpu/GrPathRendering.h index e3d9731130..0a1abc1057 100644 --- a/src/gpu/GrPathRendering.h +++ b/src/gpu/GrPathRendering.h @@ -9,7 +9,6 @@ #define GrPathRendering_DEFINED #include "SkPath.h" -#include "GrPathRange.h" #include "GrPipeline.h" class GrGpu; @@ -36,8 +35,6 @@ class GrPathRendering { public: virtual ~GrPathRendering() { } - typedef GrPathRange::PathIndexType PathIndexType; - enum PathTransformType { kNone_PathTransformType, //!< [] kTranslateX_PathTransformType, //!< [kMTransX] @@ -90,16 +87,6 @@ public: */ virtual sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) = 0; - /** - * Creates a range of gpu paths with a common style. - * - * @param PathGenerator class that generates SkPath objects for each path in the range. - * @param GrStyle the common style applied to each path in the range. Styles with non-dash - * path effects are not allowed. - * @return a new path range. - */ - virtual sk_sp<GrPathRange> createPathRange(GrPathRange::PathGenerator*, const GrStyle&) = 0; - /** None of these params are optional, pointers used just to avoid making copies. */ struct StencilPathArgs { StencilPathArgs(bool useHWAA, @@ -127,16 +114,6 @@ public: const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline. const GrPath* path); - void drawPaths(const GrPipeline& pipeline, - const GrPrimitiveProcessor& primProc, - const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline. - const GrPathRange* pathRange, - const void* indices, - PathIndexType indexType, - const float transformValues[], - PathTransformType transformType, - int count); - protected: GrPathRendering(GrGpu* gpu) : fGpu(gpu) { } @@ -145,15 +122,6 @@ protected: const GrPrimitiveProcessor&, const GrStencilSettings&, const GrPath*) = 0; - virtual void onDrawPaths(const GrPipeline&, - const GrPrimitiveProcessor&, - const GrStencilSettings&, - const GrPathRange*, - const void* indices, - PathIndexType, - const float transformValues[], - PathTransformType, - int count) = 0; GrGpu* fGpu; private: diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index d2eb91c0e8..8e41ba69a7 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -414,7 +414,6 @@ void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t fla } void GrResourceCache::didChangeGpuMemorySize(const GrGpuResource* resource, size_t oldSize) { - // SkASSERT(!fPurging); GrPathRange increases size during flush. :( SkASSERT(resource); SkASSERT(this->isInCache(resource)); diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index 1e7cff26e2..e1d85f92e4 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -10,7 +10,6 @@ #include "GrBuffer.h" #include "GrContextOptions.h" -#include "GrPathRange.h" #include "GrResourceCache.h" #include "SkImageInfoPriv.h" #include "SkScalerContext.h" @@ -165,7 +164,7 @@ public: static int QuadCountOfQuadBuffer(); /** - * Factories for GrPath and GrPathRange objects. It's an error to call these if path rendering + * Factories for GrPath objects. It's an error to call these if path rendering * is not supported. */ sk_sp<GrPath> createPath(const SkPath&, const GrStyle&); diff --git a/src/gpu/gl/GrGLPathRange.cpp b/src/gpu/gl/GrGLPathRange.cpp deleted file mode 100644 index da1e9fe709..0000000000 --- a/src/gpu/gl/GrGLPathRange.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "GrGLPathRange.h" -#include "GrGLPath.h" -#include "GrGLPathRendering.h" -#include "GrGLGpu.h" - -GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const GrStyle& style) - : INHERITED(gpu, pathGenerator), - fStyle(style), - fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())), - fGpuMemorySize(0) { - this->init(); - this->registerWithCache(SkBudgeted::kYes); -} - -GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, - GrGLuint basePathID, - int numPaths, - size_t gpuMemorySize, - const GrStyle& style) - : INHERITED(gpu, numPaths), - fStyle(style), - fBasePathID(basePathID), - fGpuMemorySize(gpuMemorySize) { - this->init(); - this->registerWithCache(SkBudgeted::kYes); -} - -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 = fStyle.pathEffect() || - (stroke.needToApply() && stroke.getCap() != SkPaint::kButt_Cap); - - if (forceFill) { - fShouldStroke = false; - fShouldFill = true; - } else { - fShouldStroke = stroke.needToApply(); - fShouldFill = stroke.isFillStyle() || - stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style; - } -} - -void GrGLPathRange::onInitPath(int index, const SkPath& origSkPath) const { - GrGLGpu* gpu = static_cast<GrGLGpu*>(this->getGpu()); - if (nullptr == gpu) { - return; - } - // Make sure the path at this index hasn't been initted already. - SkDEBUGCODE( - GrGLboolean isPath; - GR_GL_CALL_RET(gpu->glInterface(), isPath, IsPath(fBasePathID + index))); - SkASSERT(GR_GL_FALSE == isPath); - - if (origSkPath.isEmpty()) { - GrGLPath::InitPathObjectEmptyPath(gpu, fBasePathID + index); - } else if (fShouldStroke) { - GrGLPath::InitPathObjectPathData(gpu, fBasePathID + index, origSkPath); - GrGLPath::InitPathObjectStroke(gpu, fBasePathID + index, fStyle.strokeRec()); - } else { - const SkPath* skPath = &origSkPath; - SkTLazy<SkPath> tmpPath; - 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(); - - } - GrGLPath::InitPathObjectPathData(gpu, fBasePathID + index, *skPath); - } - // TODO: Use a better approximation for the individual path sizes. - fGpuMemorySize += 100; -} - -void GrGLPathRange::onRelease() { - SkASSERT(this->getGpu()); - - if (0 != fBasePathID) { - static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fBasePathID, - this->getNumPaths()); - fBasePathID = 0; - } - - INHERITED::onRelease(); -} - -void GrGLPathRange::onAbandon() { - fBasePathID = 0; - - INHERITED::onAbandon(); -} diff --git a/src/gpu/gl/GrGLPathRange.h b/src/gpu/gl/GrGLPathRange.h deleted file mode 100644 index 7d920105a0..0000000000 --- a/src/gpu/gl/GrGLPathRange.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrGLPathRange_DEFINED -#define GrGLPathRange_DEFINED - -#include "../GrPathRange.h" -#include "GrStyle.h" -#include "gl/GrGLTypes.h" - -class GrGLGpu; - -/** - * Currently this represents a range of GL_NV_path_rendering Path IDs. If we - * support other GL path extensions then this would have to have a type enum - * and/or be subclassed. - */ - -class GrGLPathRange : public GrPathRange { -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 GrStyle&); - - /** - * Initialize a GL path range from an existing range of pre-initialized GPU - * path objects. This class assumes ownership of the GPU path objects and - * will delete them when done. - */ - GrGLPathRange(GrGLGpu*, - GrGLuint basePathID, - int numPaths, - size_t gpuMemorySize, - const GrStyle&); - - GrGLuint basePathID() const { return fBasePathID; } - - bool shouldStroke() const { return fShouldStroke; } - bool shouldFill() const { return fShouldFill; } - -protected: - void onInitPath(int index, const SkPath&) const override; - - void onRelease() override; - void onAbandon() override; - -private: - void init(); - size_t onGpuMemorySize() const override { return fGpuMemorySize; } - - const GrStyle fStyle; - GrGLuint fBasePathID; - mutable size_t fGpuMemorySize; - bool fShouldStroke; - bool fShouldFill; - - typedef GrPathRange INHERITED; -}; - -#endif diff --git a/src/gpu/gl/GrGLPathRendering.cpp b/src/gpu/gl/GrGLPathRendering.cpp index 8ff9da0d33..45bc018487 100644 --- a/src/gpu/gl/GrGLPathRendering.cpp +++ b/src/gpu/gl/GrGLPathRendering.cpp @@ -10,7 +10,6 @@ #include "gl/GrGLGpu.h" #include "GrGLPath.h" -#include "GrGLPathRange.h" #include "GrGLPathRendering.h" #include "SkStream.h" @@ -23,25 +22,6 @@ // implementation. The call has a result value, and thus waiting for the call completion is needed. static const GrGLsizei kPathIDPreallocationAmount = 65536; -static const GrGLenum gIndexType2GLType[] = { - GR_GL_UNSIGNED_BYTE, - GR_GL_UNSIGNED_SHORT, - GR_GL_UNSIGNED_INT -}; - -GR_STATIC_ASSERT(0 == GrPathRange::kU8_PathIndexType); -GR_STATIC_ASSERT(1 == GrPathRange::kU16_PathIndexType); -GR_STATIC_ASSERT(2 == GrPathRange::kU32_PathIndexType); -GR_STATIC_ASSERT(GrPathRange::kU32_PathIndexType == GrPathRange::kLast_PathIndexType); - -static const GrGLenum gXformType2GLType[] = { - GR_GL_NONE, - GR_GL_TRANSLATE_X, - GR_GL_TRANSLATE_Y, - GR_GL_TRANSLATE_2D, - GR_GL_TRANSPOSE_AFFINE_2D -}; - GR_STATIC_ASSERT(0 == GrPathRendering::kNone_PathTransformType); GR_STATIC_ASSERT(1 == GrPathRendering::kTranslateX_PathTransformType); GR_STATIC_ASSERT(2 == GrPathRendering::kTranslateY_PathTransformType); @@ -50,13 +30,6 @@ GR_STATIC_ASSERT(4 == GrPathRendering::kAffine_PathTransformType); GR_STATIC_ASSERT(GrPathRendering::kAffine_PathTransformType == GrPathRendering::kLast_PathTransformType); #ifdef SK_DEBUG -static const GrGLenum gXformType2ComponentCount[] = { - 0, - 1, - 1, - 2, - 6 -}; static void verify_floats(const float* floats, int count) { for (int i = 0; i < count; ++i) { @@ -109,11 +82,6 @@ sk_sp<GrPath> GrGLPathRendering::createPath(const SkPath& inPath, const GrStyle& return sk_make_sp<GrGLPath>(this->gpu(), inPath, style); } -sk_sp<GrPathRange> GrGLPathRendering::createPathRange(GrPathRange::PathGenerator* pathGenerator, - const GrStyle& style) { - return sk_make_sp<GrGLPathRange>(this->gpu(), pathGenerator, style); -} - void GrGLPathRendering::onStencilPath(const StencilPathArgs& args, const GrPath* path) { GrGLGpu* gpu = this->gpu(); SkASSERT(gpu->caps()->shaderCaps()->pathRenderingSupport()); @@ -171,46 +139,6 @@ void GrGLPathRendering::onDrawPath(const GrPipeline& pipeline, } } -void GrGLPathRendering::onDrawPaths(const GrPipeline& pipeline, - const GrPrimitiveProcessor& primProc, - const GrStencilSettings& stencilPassSettings, - const GrPathRange* pathRange, const void* indices, - PathIndexType indexType, const float transformValues[], - PathTransformType transformType, int count) { - SkDEBUGCODE(verify_floats(transformValues, gXformType2ComponentCount[transformType] * count)); - - if (!this->gpu()->flushGLState(pipeline, primProc, false)) { - return; - } - this->flushPathStencilSettings(stencilPassSettings); - SkASSERT(!fHWPathStencilSettings.isTwoSided()); - - - const GrGLPathRange* glPathRange = static_cast<const GrGLPathRange*>(pathRange); - - GrGLenum fillMode = - gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.front().fPassOp); - GrGLint writeMask = fHWPathStencilSettings.front().fWriteMask; - - if (glPathRange->shouldStroke()) { - if (glPathRange->shouldFill()) { - GL_CALL(StencilFillPathInstanced( - count, gIndexType2GLType[indexType], indices, glPathRange->basePathID(), - fillMode, writeMask, gXformType2GLType[transformType], - transformValues)); - } - GL_CALL(StencilThenCoverStrokePathInstanced( - count, gIndexType2GLType[indexType], indices, glPathRange->basePathID(), - 0xffff, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, - gXformType2GLType[transformType], transformValues)); - } else { - GL_CALL(StencilThenCoverFillPathInstanced( - count, gIndexType2GLType[indexType], indices, glPathRange->basePathID(), - fillMode, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_BOXES, - gXformType2GLType[transformType], transformValues)); - } -} - void GrGLPathRendering::setProgramPathFragmentInputTransform(GrGLuint program, GrGLint location, GrGLenum genMode, GrGLint components, const SkMatrix& matrix) { diff --git a/src/gpu/gl/GrGLPathRendering.h b/src/gpu/gl/GrGLPathRendering.h index 5b03435d7c..0c1d19286b 100644 --- a/src/gpu/gl/GrGLPathRendering.h +++ b/src/gpu/gl/GrGLPathRendering.h @@ -36,8 +36,6 @@ public: // GrPathRendering implementations. sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) override; - virtual sk_sp<GrPathRange> createPathRange(GrPathRange::PathGenerator*, - const GrStyle&) override; /* Called when the 3D context state is unknown. */ void resetContext(); @@ -71,15 +69,6 @@ protected: const GrPrimitiveProcessor&, const GrStencilSettings&, const GrPath*) override; - void onDrawPaths(const GrPipeline&, - const GrPrimitiveProcessor&, - const GrStencilSettings&, - const GrPathRange*, - const void* indices, - PathIndexType, - const float transformValues[], - PathTransformType, - int count) override; private: /** * Mark certain functionality as not supported. diff --git a/src/gpu/ops/GrDrawPathOp.cpp b/src/gpu/ops/GrDrawPathOp.cpp index 7b7d394f20..b79654c6ca 100644 --- a/src/gpu/ops/GrDrawPathOp.cpp +++ b/src/gpu/ops/GrDrawPathOp.cpp @@ -75,154 +75,6 @@ void GrDrawPathOp::onExecute(GrOpFlushState* state) { ////////////////////////////////////////////////////////////////////////////// -SkString GrDrawPathRangeOp::dumpInfo() const { - SkString string; - string.printf("RANGE: 0x%p COUNTS: [", fPathRange.get()); - for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) { - string.appendf("%d, ", iter.get()->fInstanceData->count()); - } - string.remove(string.size() - 2, 2); - string.append("]"); - string.append(INHERITED::dumpInfo()); - return string; -} - -GrDrawPathRangeOp::GrDrawPathRangeOp(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x, - SkScalar y, GrPaint&& paint, GrPathRendering::FillType fill, - GrAAType aaType, GrPathRange* range, - const InstanceData* instanceData, const SkRect& bounds) - : INHERITED(ClassID(), viewMatrix, std::move(paint), fill, aaType) - , fPathRange(range) - , fTotalPathCount(instanceData->count()) - , fScale(scale) { - fDraws.addToHead()->set(instanceData, x, y); - this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo); -} - -static void pre_translate_transform_values(const float* xforms, - GrPathRendering::PathTransformType type, int count, - SkScalar x, SkScalar y, float* dst); - -bool GrDrawPathRangeOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { - GrDrawPathRangeOp* that = t->cast<GrDrawPathRangeOp>(); - if (this->fPathRange.get() != that->fPathRange.get() || - this->transformType() != that->transformType() || this->fScale != that->fScale || - this->color() != that->color() || !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { - return false; - } - if (this->processors() != that->processors()) { - return false; - } - if (this->pipelineSRGBFlags() != that->pipelineSRGBFlags()) { - return false; - } - switch (fDraws.head()->fInstanceData->transformType()) { - case GrPathRendering::kNone_PathTransformType: - if (this->fDraws.head()->fX != that->fDraws.head()->fX || - this->fDraws.head()->fY != that->fDraws.head()->fY) { - return false; - } - break; - case GrPathRendering::kTranslateX_PathTransformType: - if (this->fDraws.head()->fY != that->fDraws.head()->fY) { - return false; - } - break; - case GrPathRendering::kTranslateY_PathTransformType: - if (this->fDraws.head()->fX != that->fDraws.head()->fX) { - return false; - } - break; - default: - break; - } - // TODO: Check some other things here. (winding, opaque, pathProc color, vm, ...) - // Try to combine this call with the previous DrawPaths. We do this by stenciling all the - // paths together and then covering them in a single pass. This is not equivalent to two - // separate draw calls, so we can only do it if there is no blending (no overlap would also - // work). Note that it's also possible for overlapping paths to cancel each other's winding - // numbers, and we only partially account for this by not allowing even/odd paths to be - // combined. (Glyphs in the same font tend to wind the same direction so it works out OK.) - - if (GrPathRendering::kWinding_FillType != this->fillType() || - GrPathRendering::kWinding_FillType != that->fillType()) { - return false; - } - if (!this->processorAnalysis().canCombineOverlappedStencilAndCover()) { - return false; - } - fTotalPathCount += that->fTotalPathCount; - while (Draw* head = that->fDraws.head()) { - Draw* draw = fDraws.addToTail(); - draw->fInstanceData.reset(head->fInstanceData.release()); - draw->fX = head->fX; - draw->fY = head->fY; - that->fDraws.popHead(); - } - this->joinBounds(*that); - return true; -} - -void GrDrawPathRangeOp::onExecute(GrOpFlushState* state) { - const Draw& head = *fDraws.head(); - - SkMatrix drawMatrix(this->viewMatrix()); - drawMatrix.preScale(fScale, fScale); - drawMatrix.preTranslate(head.fX, head.fY); - - SkMatrix localMatrix; - localMatrix.setScale(fScale, fScale); - localMatrix.preTranslate(head.fX, head.fY); - - sk_sp<GrPathProcessor> pathProc( - GrPathProcessor::Create(this->color(), drawMatrix, localMatrix)); - - GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(), - state->detachAppliedClip()); - GrStencilSettings stencil; - init_stencil_pass_settings(*state, this->fillType(), &stencil); - if (fDraws.count() == 1) { - const InstanceData& instances = *head.fInstanceData; - state->gpu()->pathRendering()->drawPaths(pipeline, - *pathProc, - stencil, - fPathRange.get(), - instances.indices(), - GrPathRange::kU16_PathIndexType, - instances.transformValues(), - instances.transformType(), - instances.count()); - } else { - int floatsPerTransform = GrPathRendering::PathTransformSize(this->transformType()); - SkAutoSTMalloc<4096, float> transformStorage(floatsPerTransform * fTotalPathCount); - SkAutoSTMalloc<2048, uint16_t> indexStorage(fTotalPathCount); - int idx = 0; - for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) { - const Draw& draw = *iter.get(); - const InstanceData& instances = *draw.fInstanceData; - memcpy(&indexStorage[idx], instances.indices(), instances.count() * sizeof(uint16_t)); - pre_translate_transform_values(instances.transformValues(), this->transformType(), - instances.count(), draw.fX - head.fX, draw.fY - head.fY, - &transformStorage[floatsPerTransform * idx]); - idx += instances.count(); - - // TODO: Support mismatched transform types if we start using more types other than 2D. - SkASSERT(instances.transformType() == this->transformType()); - } - SkASSERT(idx == fTotalPathCount); - - state->gpu()->pathRendering()->drawPaths(pipeline, - *pathProc, - stencil, - fPathRange.get(), - indexStorage, - GrPathRange::kU16_PathIndexType, - transformStorage, - this->transformType(), - fTotalPathCount); - } -} - inline void pre_translate_transform_values(const float* xforms, GrPathRendering::PathTransformType type, int count, SkScalar x, SkScalar y, float* dst) { diff --git a/src/gpu/ops/GrDrawPathOp.h b/src/gpu/ops/GrDrawPathOp.h index 7b1072eea4..665c3da743 100644 --- a/src/gpu/ops/GrDrawPathOp.h +++ b/src/gpu/ops/GrDrawPathOp.h @@ -106,117 +106,4 @@ private: typedef GrDrawPathOpBase INHERITED; }; -// Template this if we decide to support index types other than 16bit -class GrDrawPathRangeOp final : public GrDrawPathOpBase { -public: - typedef GrPathRendering::PathTransformType TransformType; - - DEFINE_OP_CLASS_ID - - struct InstanceData : private ::SkNoncopyable { - public: - static InstanceData* Alloc(TransformType transformType, int reserveCnt) { - int transformSize = GrPathRendering::PathTransformSize(transformType); - uint8_t* ptr = (uint8_t*)sk_malloc_throw(Align32(sizeof(InstanceData)) + - Align32(reserveCnt * sizeof(uint16_t)) + - reserveCnt * transformSize * sizeof(float)); - InstanceData* instanceData = (InstanceData*)ptr; - instanceData->fIndices = (uint16_t*)&ptr[Align32(sizeof(InstanceData))]; - instanceData->fTransformValues = (float*)&ptr[Align32(sizeof(InstanceData)) + - Align32(reserveCnt * sizeof(uint16_t))]; - instanceData->fTransformType = transformType; - instanceData->fInstanceCount = 0; - instanceData->fRefCnt = 1; - SkDEBUGCODE(instanceData->fReserveCnt = reserveCnt); - return instanceData; - } - - // Overload this method if we start using other transform types. - void append(uint16_t index, float x, float y) { - SkASSERT(GrPathRendering::kTranslate_PathTransformType == fTransformType); - SkASSERT(fInstanceCount < fReserveCnt); - fIndices[fInstanceCount] = index; - fTransformValues[2 * fInstanceCount] = x; - fTransformValues[2 * fInstanceCount + 1] = y; - ++fInstanceCount; - } - - TransformType transformType() const { return fTransformType; } - int count() const { return fInstanceCount; } - - const uint16_t* indices() const { return fIndices; } - uint16_t* indices() { return fIndices; } - - const float* transformValues() const { return fTransformValues; } - float* transformValues() { return fTransformValues; } - - void ref() const { ++fRefCnt; } - - void unref() const { - if (0 == --fRefCnt) { - sk_free(const_cast<InstanceData*>(this)); - } - } - - private: - static int Align32(int sizeInBytes) { return (sizeInBytes + 3) & ~3; } - - InstanceData() {} - ~InstanceData() {} - - uint16_t* fIndices; - float* fTransformValues; - TransformType fTransformType; - int fInstanceCount; - mutable int fRefCnt; - SkDEBUGCODE(int fReserveCnt;) - }; - - static std::unique_ptr<GrDrawOp> Make(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x, - SkScalar y, GrPaint&& paint, - GrPathRendering::FillType fill, GrAAType aaType, - GrPathRange* range, const InstanceData* instanceData, - const SkRect& bounds) { - return std::unique_ptr<GrDrawOp>(new GrDrawPathRangeOp(viewMatrix, scale, x, y, - std::move(paint), fill, aaType, - range, instanceData, bounds)); - } - - const char* name() const override { return "DrawPathRange"; } - - SkString dumpInfo() const override; - -private: - GrDrawPathRangeOp(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x, SkScalar y, - GrPaint&& paint, GrPathRendering::FillType fill, GrAAType aaType, - GrPathRange* range, const InstanceData* instanceData, const SkRect& bounds); - - TransformType transformType() const { return fDraws.head()->fInstanceData->transformType(); } - - bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override; - - void onExecute(GrOpFlushState* state) override; - - struct Draw { - void set(const InstanceData* instanceData, SkScalar x, SkScalar y) { - fInstanceData.reset(SkRef(instanceData)); - fX = x; - fY = y; - } - - sk_sp<const InstanceData> fInstanceData; - SkScalar fX, fY; - }; - - typedef GrPendingIOResource<const GrPathRange, kRead_GrIOType> PendingPathRange; - typedef SkTLList<Draw, 4> DrawList; - - PendingPathRange fPathRange; - DrawList fDraws; - int fTotalPathCount; - SkScalar fScale; - - typedef GrDrawPathOpBase INHERITED; -}; - #endif |