diff --git a/experimental/graphite/src/ResourceProvider.cpp b/experimental/graphite/src/ResourceProvider.cpp index 14ab220271..81b9a5365a 100644 --- a/experimental/graphite/src/ResourceProvider.cpp +++ b/experimental/graphite/src/ResourceProvider.cpp @@ -99,19 +99,41 @@ sk_sp ResourceProvider::findOrCreateDepthStencilAttachment(SkISize dime // stomping on each other's data. fGpu->caps()->buildKeyForTexture(dimensions, info, kType, Shareable::kYes, &key); + return this->findOrCreateTextureWithKey(dimensions, info, key); +} + +sk_sp ResourceProvider::findOrCreateDiscardableMSAAAttachment(SkISize dimensions, + const TextureInfo& info) { + SkASSERT(info.isValid()); + + static const ResourceType kType = GraphiteResourceKey::GenerateResourceType(); + + GraphiteResourceKey key; + // We always make discardable msaa attachments shareable. Between any render pass we discard + // the values of the MSAA texture. Thus it is safe to be used by multiple different render + // passes without worry of stomping on each other's data. It is the callings code responsiblity + // to populate the discardable MSAA texture with data at the start of the render pass. + fGpu->caps()->buildKeyForTexture(dimensions, info, kType, Shareable::kYes, &key); + + return this->findOrCreateTextureWithKey(dimensions, info, key); +} + +sk_sp ResourceProvider::findOrCreateTextureWithKey(SkISize dimensions, + const TextureInfo& info, + const GraphiteResourceKey& key) { if (Resource* resource = fResourceCache->findAndRefResource(key)) { return sk_sp(static_cast(resource)); } - auto stencil = this->createTexture(dimensions, info); - if (!stencil) { + auto tex = this->createTexture(dimensions, info); + if (!tex) { return nullptr; } - stencil->setKey(key); - fResourceCache->insertResource(stencil.get()); + tex->setKey(key); + fResourceCache->insertResource(tex.get()); - return stencil; + return tex; } sk_sp ResourceProvider::findOrCreateCompatibleSampler(const SkSamplingOptions& smplOptions, diff --git a/experimental/graphite/src/ResourceProvider.h b/experimental/graphite/src/ResourceProvider.h index 360abfaa64..993b464cd9 100644 --- a/experimental/graphite/src/ResourceProvider.h +++ b/experimental/graphite/src/ResourceProvider.h @@ -27,6 +27,7 @@ class Caps; class GlobalCache; class Gpu; class GraphicsPipeline; +class GraphiteResourceKey; class ResourceCache; class Sampler; class SingleOwner; @@ -48,6 +49,9 @@ public: sk_sp findOrCreateDepthStencilAttachment(SkISize dimensions, const TextureInfo&); + sk_sp findOrCreateDiscardableMSAAAttachment(SkISize dimensions, + const TextureInfo&); + sk_sp findOrCreateBuffer(size_t size, BufferType type, PrioritizeGpuReads); sk_sp findOrCreateCompatibleSampler(const SkSamplingOptions&, @@ -71,6 +75,10 @@ private: SkTileMode xTileMode, SkTileMode yTileMode) = 0; + sk_sp findOrCreateTextureWithKey(SkISize dimensions, + const TextureInfo& info, + const GraphiteResourceKey& key); + class GraphicsPipelineCache { public: GraphicsPipelineCache(ResourceProvider* resourceProvider);