diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrGpuResourcePriv.h | 2 | ||||
-rw-r--r-- | src/gpu/GrOnFlushResourceProvider.cpp | 19 | ||||
-rw-r--r-- | src/gpu/GrOnFlushResourceProvider.h | 4 | ||||
-rw-r--r-- | src/gpu/GrResourceProvider.cpp | 19 | ||||
-rw-r--r-- | src/gpu/GrResourceProvider.h | 13 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRPathProcessor.cpp | 24 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRPathProcessor.h | 5 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp | 4 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCoverageCountingPathRenderer.h | 4 |
9 files changed, 62 insertions, 32 deletions
diff --git a/src/gpu/GrGpuResourcePriv.h b/src/gpu/GrGpuResourcePriv.h index a1e207d77c..affc753f9b 100644 --- a/src/gpu/GrGpuResourcePriv.h +++ b/src/gpu/GrGpuResourcePriv.h @@ -16,6 +16,8 @@ */ class GrGpuResource::ResourcePriv { public: + SkDEBUGCODE(bool hasPendingIO_debugOnly() const { return fResource->internalHasPendingIO(); }) + /** * Sets a unique key for the resource. If the resource was previously cached as scratch it will * be converted to a uniquely-keyed resource. If the key is invalid then this is equivalent to diff --git a/src/gpu/GrOnFlushResourceProvider.cpp b/src/gpu/GrOnFlushResourceProvider.cpp index c9fc77ed48..e3b5eebefc 100644 --- a/src/gpu/GrOnFlushResourceProvider.cpp +++ b/src/gpu/GrOnFlushResourceProvider.cpp @@ -88,19 +88,14 @@ sk_sp<GrBuffer> GrOnFlushResourceProvider::makeBuffer(GrBufferType intendedType, data)); } -sk_sp<GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(const GrUniqueKey& key, - GrBufferType intendedType, - size_t size, const void* data) { +sk_sp<const GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(GrBufferType intendedType, + size_t size, + const void* data, + const GrUniqueKey& key) { GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider(); - sk_sp<GrBuffer> buffer(rp->findByUniqueKey<GrBuffer>(key)); - if (!buffer) { - buffer.reset(rp->createBuffer(size, intendedType, kStatic_GrAccessPattern, 0, data)); - if (!buffer) { - return nullptr; - } - SkASSERT(buffer->sizeInBytes() == size); // rp shouldn't bin and/or cache static buffers. - buffer->resourcePriv().setUniqueKey(key); - } + sk_sp<const GrBuffer> buffer = rp->findOrMakeStaticBuffer(intendedType, size, data, key); + // Static buffers should never have pending IO. + SkASSERT(!buffer->resourcePriv().hasPendingIO_debugOnly()); return buffer; } diff --git a/src/gpu/GrOnFlushResourceProvider.h b/src/gpu/GrOnFlushResourceProvider.h index e16bb57aef..f4e4459738 100644 --- a/src/gpu/GrOnFlushResourceProvider.h +++ b/src/gpu/GrOnFlushResourceProvider.h @@ -83,8 +83,8 @@ public: sk_sp<GrBuffer> makeBuffer(GrBufferType, size_t, const void* data = nullptr); // Either finds and refs, or creates a static GPU buffer with the given data. - sk_sp<GrBuffer> findOrMakeStaticBuffer(const GrUniqueKey&, GrBufferType, - size_t, const void* data); + sk_sp<const GrBuffer> findOrMakeStaticBuffer(GrBufferType, size_t, const void* data, + const GrUniqueKey&); const GrCaps* caps() const; diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index 8b36badb35..7fef3508eb 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -312,6 +312,25 @@ sk_sp<GrTextureProxy> GrResourceProvider::findOrCreateProxyByUniqueKey(const GrU return this->isAbandoned() ? nullptr : fCache->findOrCreateProxyByUniqueKey(key, origin); } +sk_sp<const GrBuffer> GrResourceProvider::findOrMakeStaticBuffer(GrBufferType intendedType, + size_t size, + const void* data, + const GrUniqueKey& key) { + if (auto buffer = this->findByUniqueKey<GrBuffer>(key)) { + return buffer; + } + if (auto buffer = this->createBuffer(size, intendedType, kStatic_GrAccessPattern, 0, + data)) { + // We shouldn't bin and/or cachestatic buffers. + SkASSERT(buffer->sizeInBytes() == size); + SkASSERT(!buffer->resourcePriv().getScratchKey().isValid()); + SkASSERT(!buffer->resourcePriv().hasPendingIO_debugOnly()); + buffer->resourcePriv().setUniqueKey(key); + return sk_sp<const GrBuffer>(buffer); + } + return nullptr; +} + sk_sp<const GrBuffer> GrResourceProvider::createPatternedIndexBuffer(const uint16_t* pattern, int patternSize, int reps, diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index 4cd34da143..f7f7850b31 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -133,6 +133,19 @@ public: static const uint32_t kMinScratchTextureSize; /** + * Either finds and refs, or creates a static buffer with the given parameters and contents. + * + * @param intendedType hint to the graphics subsystem about what the buffer will be used for. + * @param size minimum size of buffer to return. + * @param data optional data with which to initialize the buffer. + * @param key Key to be assigned to the buffer. + * + * @return The buffer if successful, otherwise nullptr. + */ + sk_sp<const GrBuffer> findOrMakeStaticBuffer(GrBufferType intendedType, size_t size, + const void* data, const GrUniqueKey& key); + + /** * Either finds and refs, or creates an index buffer with a repeating pattern for drawing * contiguous vertices of a repeated mesh. If the return is non-null, the caller owns a ref on * the returned GrBuffer. diff --git a/src/gpu/ccpr/GrCCPRPathProcessor.cpp b/src/gpu/ccpr/GrCCPRPathProcessor.cpp index c99a0100e9..2f0c023bb6 100644 --- a/src/gpu/ccpr/GrCCPRPathProcessor.cpp +++ b/src/gpu/ccpr/GrCCPRPathProcessor.cpp @@ -36,6 +36,12 @@ static constexpr float kOctoEdgeNorms[8 * 4] = { GR_DECLARE_STATIC_UNIQUE_KEY(gVertexBufferKey); +sk_sp<const GrBuffer> GrCCPRPathProcessor::FindVertexBuffer(GrOnFlushResourceProvider* onFlushRP) { + GR_DEFINE_STATIC_UNIQUE_KEY(gVertexBufferKey); + return onFlushRP->findOrMakeStaticBuffer(kVertex_GrBufferType, sizeof(kOctoEdgeNorms), + kOctoEdgeNorms, gVertexBufferKey); +} + // Index buffer for the octagon defined above. static uint16_t kOctoIndices[GrCCPRPathProcessor::kPerInstanceIndexCount] = { 0, 4, 2, @@ -48,6 +54,12 @@ static uint16_t kOctoIndices[GrCCPRPathProcessor::kPerInstanceIndexCount] = { GR_DECLARE_STATIC_UNIQUE_KEY(gIndexBufferKey); +sk_sp<const GrBuffer> GrCCPRPathProcessor::FindIndexBuffer(GrOnFlushResourceProvider* onFlushRP) { + GR_DEFINE_STATIC_UNIQUE_KEY(gIndexBufferKey); + return onFlushRP->findOrMakeStaticBuffer(kIndex_GrBufferType, sizeof(kOctoIndices), + kOctoIndices, gIndexBufferKey); +} + GrCCPRPathProcessor::GrCCPRPathProcessor(GrResourceProvider* rp, sk_sp<GrTextureProxy> atlas, SkPath::FillType fillType, const GrShaderCaps& shaderCaps) : INHERITED(kGrCCPRPathProcessor_ClassID) @@ -190,15 +202,3 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { f->codeAppendf("%s = half4(1 - abs(t - 1));", args.fOutputCoverage); } } - -sk_sp<GrBuffer> GrCCPRPathProcessor::FindOrMakeIndexBuffer(GrOnFlushResourceProvider* onFlushRP) { - GR_DEFINE_STATIC_UNIQUE_KEY(gIndexBufferKey); - return onFlushRP->findOrMakeStaticBuffer(gIndexBufferKey, kIndex_GrBufferType, - sizeof(kOctoIndices), kOctoIndices); -} - -sk_sp<GrBuffer> GrCCPRPathProcessor::FindOrMakeVertexBuffer(GrOnFlushResourceProvider* onFlushRP) { - GR_DEFINE_STATIC_UNIQUE_KEY(gVertexBufferKey); - return onFlushRP->findOrMakeStaticBuffer(gVertexBufferKey, kVertex_GrBufferType, - sizeof(kOctoEdgeNorms), kOctoEdgeNorms); -} diff --git a/src/gpu/ccpr/GrCCPRPathProcessor.h b/src/gpu/ccpr/GrCCPRPathProcessor.h index 7ad314e1d6..97daefe991 100644 --- a/src/gpu/ccpr/GrCCPRPathProcessor.h +++ b/src/gpu/ccpr/GrCCPRPathProcessor.h @@ -27,8 +27,6 @@ class GrShaderCaps; class GrCCPRPathProcessor : public GrGeometryProcessor { public: static constexpr int kPerInstanceIndexCount = 6 * 3; - static sk_sp<GrBuffer> FindOrMakeIndexBuffer(GrOnFlushResourceProvider*); - static sk_sp<GrBuffer> FindOrMakeVertexBuffer(GrOnFlushResourceProvider*); enum class InstanceAttribs { kDevBounds, @@ -54,6 +52,9 @@ public: GR_STATIC_ASSERT(4 * 16 == sizeof(Instance)); + static sk_sp<const GrBuffer> FindIndexBuffer(GrOnFlushResourceProvider*); + static sk_sp<const GrBuffer> FindVertexBuffer(GrOnFlushResourceProvider*); + GrCCPRPathProcessor(GrResourceProvider*, sk_sp<GrTextureProxy> atlas, SkPath::FillType, const GrShaderCaps&); diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp index 937fd4824b..a239569b3e 100644 --- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp +++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp @@ -324,13 +324,13 @@ void GrCoverageCountingPathRenderer::preFlush(GrOnFlushResourceProvider* onFlush } // Allocate GPU buffers. - fPerFlushIndexBuffer = GrCCPRPathProcessor::FindOrMakeIndexBuffer(onFlushRP); + fPerFlushIndexBuffer = GrCCPRPathProcessor::FindIndexBuffer(onFlushRP); if (!fPerFlushIndexBuffer) { SkDebugf("WARNING: failed to allocate ccpr path index buffer.\n"); return; } - fPerFlushVertexBuffer = GrCCPRPathProcessor::FindOrMakeVertexBuffer(onFlushRP); + fPerFlushVertexBuffer = GrCCPRPathProcessor::FindVertexBuffer(onFlushRP); if (!fPerFlushVertexBuffer) { SkDebugf("WARNING: failed to allocate ccpr path vertex buffer.\n"); return; diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.h b/src/gpu/ccpr/GrCoverageCountingPathRenderer.h index 1d08f381a2..8446af6266 100644 --- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.h +++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.h @@ -217,8 +217,8 @@ private: std::map<uint32_t, RTPendingPaths> fRTPendingPathsMap; SkDEBUGCODE(int fPendingDrawOpsCount = 0;) - sk_sp<GrBuffer> fPerFlushIndexBuffer; - sk_sp<GrBuffer> fPerFlushVertexBuffer; + sk_sp<const GrBuffer> fPerFlushIndexBuffer; + sk_sp<const GrBuffer> fPerFlushVertexBuffer; sk_sp<GrBuffer> fPerFlushInstanceBuffer; GrSTAllocator<4, GrCCPRAtlas> fPerFlushAtlases; bool fPerFlushResourcesAreValid; |