diff --git a/experimental/graphite/src/Buffer.h b/experimental/graphite/src/Buffer.h index c7d35afe7e..a109aed310 100644 --- a/experimental/graphite/src/Buffer.h +++ b/experimental/graphite/src/Buffer.h @@ -8,12 +8,12 @@ #ifndef skgpu_Buffer_DEFINED #define skgpu_Buffer_DEFINED +#include "experimental/graphite/src/Resource.h" #include "experimental/graphite/src/ResourceTypes.h" -#include "include/core/SkRefCnt.h" namespace skgpu { -class Buffer : public SkRefCnt { +class Buffer : public Resource { public: size_t size() const { return fSize; } @@ -23,8 +23,8 @@ public: bool isMapped() const { return fMapPtr; } protected: - Buffer(size_t size, BufferType type, PrioritizeGpuReads prioritizeGpuReads) - : fSize(size), fType(type), fPrioritizeGpuReads(prioritizeGpuReads) {} + Buffer(const Gpu* gpu, size_t size, BufferType type, PrioritizeGpuReads prioritizeGpuReads) + : Resource(gpu), fSize(size), fType(type), fPrioritizeGpuReads(prioritizeGpuReads) {} void* fMapPtr = nullptr; diff --git a/experimental/graphite/src/CommandBuffer.cpp b/experimental/graphite/src/CommandBuffer.cpp index d3df4ac9c4..4f5bc5dd90 100644 --- a/experimental/graphite/src/CommandBuffer.cpp +++ b/experimental/graphite/src/CommandBuffer.cpp @@ -18,12 +18,20 @@ namespace skgpu { CommandBuffer::CommandBuffer() {} +CommandBuffer::~CommandBuffer() { + this->releaseResources(); +} + void CommandBuffer::releaseResources() { TRACE_EVENT0("skia.gpu", TRACE_FUNC); fTrackedResources.reset(); } +void CommandBuffer::trackResource(sk_sp resource) { + fTrackedResources.push_back(std::move(resource)); +} + bool CommandBuffer::beginRenderPass(const RenderPassDesc& renderPassDesc, sk_sp colorTexture, sk_sp resolveTexture, diff --git a/experimental/graphite/src/CommandBuffer.h b/experimental/graphite/src/CommandBuffer.h index fd83511051..7feec065d4 100644 --- a/experimental/graphite/src/CommandBuffer.h +++ b/experimental/graphite/src/CommandBuffer.h @@ -22,6 +22,7 @@ namespace skgpu { class Buffer; class Gpu; class GraphicsPipeline; +class Resource; class Texture; class TextureProxy; @@ -57,17 +58,13 @@ struct RenderPassDesc { class CommandBuffer : public SkRefCnt, private DrawDispatcher { public: - ~CommandBuffer() override { - this->releaseResources(); - } + ~CommandBuffer() override; #ifdef SK_DEBUG bool hasWork() { return fHasWork; } #endif - void trackResource(sk_sp resource) { - fTrackedResources.push_back(std::move(resource)); - } + void trackResource(sk_sp resource); bool beginRenderPass(const RenderPassDesc&, sk_sp colorTexture, @@ -186,7 +183,7 @@ private: #endif inline static constexpr int kInitialTrackedResourcesCount = 32; - SkSTArray> fTrackedResources; + SkSTArray> fTrackedResources; }; } // namespace skgpu diff --git a/experimental/graphite/src/GraphicsPipeline.cpp b/experimental/graphite/src/GraphicsPipeline.cpp index 1e5064325d..03afb0cb8b 100644 --- a/experimental/graphite/src/GraphicsPipeline.cpp +++ b/experimental/graphite/src/GraphicsPipeline.cpp @@ -9,7 +9,7 @@ namespace skgpu { -GraphicsPipeline::GraphicsPipeline() { +GraphicsPipeline::GraphicsPipeline(const Gpu* gpu) : Resource(gpu) { } GraphicsPipeline::~GraphicsPipeline() { diff --git a/experimental/graphite/src/GraphicsPipeline.h b/experimental/graphite/src/GraphicsPipeline.h index 3480d00a05..41d35e669b 100644 --- a/experimental/graphite/src/GraphicsPipeline.h +++ b/experimental/graphite/src/GraphicsPipeline.h @@ -8,7 +8,7 @@ #ifndef skgpu_GraphicsPipeline_DEFINED #define skgpu_GraphicsPipeline_DEFINED -#include "include/core/SkRefCnt.h" +#include "experimental/graphite/src/Resource.h" namespace skgpu { @@ -22,12 +22,12 @@ namespace skgpu { * A GraphicsPipeline is created from the combination of a GraphicsPipelineDesc (representing draw * specific configuration) and a RenderPassDesc (representing the target of the draw). */ -class GraphicsPipeline : public SkRefCnt { +class GraphicsPipeline : public Resource { public: ~GraphicsPipeline() override; protected: - GraphicsPipeline(); + GraphicsPipeline(const Gpu*); private: }; diff --git a/experimental/graphite/src/Resource.cpp b/experimental/graphite/src/Resource.cpp new file mode 100644 index 0000000000..974d952cc9 --- /dev/null +++ b/experimental/graphite/src/Resource.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "experimental/graphite/src/Resource.h" + +namespace skgpu { + +Resource::Resource(const Gpu* gpu) : fGpu(gpu) {} + +Resource::~Resource() { + // The cache should have released or destroyed this resource. + SkASSERT(this->wasDestroyed()); +} + +void Resource::notifyARefCntIsZero(LastRemovedRef removedRef) const { + // TODO: Eventually we'll go through the cache to release the resource, but for now we just do + // this immediately. + SkASSERT(removedRef == LastRemovedRef::kUsageRef); + Resource* mutableThis = const_cast(this); + mutableThis->freeGpuData(); +} + +void Resource::freeGpuData() { + SkASSERT(fGpu); + this->onFreeGpuData(); + fGpu = nullptr; + delete this; +} + +} // namespace skgpu + diff --git a/experimental/graphite/src/Resource.h b/experimental/graphite/src/Resource.h new file mode 100644 index 0000000000..2ed74400df --- /dev/null +++ b/experimental/graphite/src/Resource.h @@ -0,0 +1,144 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef skgpu_Resource_DEFINED +#define skgpu_Resource_DEFINED + +#include "include/private/SkNoncopyable.h" + +#include + +namespace skgpu { + +class Gpu; + +/** + * Base class for Resource. Provides the hooks for resources to interact with the cache. + * Separated out as a base class to isolate the ref-cnting behavior and provide friendship without + * exposing all of Resource. + * + * AFTER the ref count reaches zero DERIVED::notifyARefCntIsZero() will be called. + */ +template class ResourceRef : public SkNoncopyable { +public: + // Adds a usage ref to the resource. Named ref so we can easily manage usage refs with sk_sp. + void ref() const { + // Only the cache should be able to add the first usage ref to a resource. + SkASSERT(this->hasUsageRef()); + // No barrier required. + (void)fUsageRefCnt.fetch_add(+1, std::memory_order_relaxed); + } + + // This enum is used to notify the ResourceCache which type of ref just dropped to zero. + enum class LastRemovedRef { + kUsageRef, + kCommandBufferRef, + }; + + // Removes a usage ref from the resource + void unref() const { + SkASSERT(this->hasUsageRef()); + // A release here acts in place of all releases we "should" have been doing in ref(). + if (1 == fUsageRefCnt.fetch_add(-1, std::memory_order_acq_rel)) { + this->notifyARefIsZero(LastRemovedRef::kUsageRef); + } + } + + // Adds a command buffer ref to the resource + void refCommandBuffer() const { + // No barrier required. + (void)fCommandBufferRefCnt.fetch_add(+1, std::memory_order_relaxed); + } + + // Removes a command buffer ref from the resource + void unrefCommandBuffer() const { + SkASSERT(this->hasCommandBufferRef()); + // A release here acts in place of all releases we "should" have been doing in ref(). + if (1 == fCommandBufferRefCnt.fetch_add(-1, std::memory_order_acq_rel)) { + this->notifyARefIsZero(LastRemovedRef::kCommandBufferUsage); + } + } + +protected: + ResourceRef() : fUsageRefCnt(1), fCommandBufferRefCnt(0) {} + + bool hasUsageRef() const { + if (0 == fUsageRefCnt.load(std::memory_order_acquire)) { + // The acquire barrier is only really needed if we return true. It + // prevents code conditioned on the result of hasUsageRef() from running until previous + // owners are all totally done calling unref(). + return false; + } + return true; + } + + bool hasCommandBufferRef() const { + if (0 == fCommandBufferRefCnt.load(std::memory_order_acquire)) { + // The acquire barrier is only really needed if we return true. It + // prevents code conditioned on the result of hasCommandBufferRef() from running + // until previous owners are all totally done calling unrefCommandBuffer(). + return false; + } + return true; + } + + // Privileged method that allows going from ref count = 0 to ref count = 1. + void addInitialUsageRef() const { + SkASSERT(!this->hasUsageRef()); + // No barrier required. + (void)fUsageRefCnt.fetch_add(+1, std::memory_order_relaxed); + } + +private: + void notifyARefIsZero(LastRemovedRef removedRef) const { + static_cast(this)->notifyARefCntIsZero(removedRef); + } + + mutable std::atomic fUsageRefCnt; + mutable std::atomic fCommandBufferRefCnt; +}; + +/** + * Base class for objects that can be kept in the ResourceCache. + */ +class Resource : public ResourceRef { +public: + /** + * Tests whether a object has been abandoned or released. All objects will be in this state + * after their creating Context is destroyed or abandoned. + * + * @return true if the object has been released or abandoned, + * false otherwise. + */ + bool wasDestroyed() const { return fGpu == nullptr; } + +protected: + Resource(const Gpu*); + virtual ~Resource(); + + /** Overridden to free GPU resources in the backend API. */ + virtual void onFreeGpuData() = 0; + +private: + friend class ResourceRef; // to access notifyARefCntIsZero. + + void notifyARefCntIsZero(LastRemovedRef removedRef) const; + + /** + * Frees the object in the underlying 3D API. + */ + void freeGpuData(); + + // This is not ref'ed but abandon() or release() will be called before the Gpu object is + // destroyed. Those calls set will this to nullptr. + const Gpu* fGpu; +}; + +} // namespace skgpu + +#endif // skgpu_Resource_DEFINED + diff --git a/experimental/graphite/src/Texture.cpp b/experimental/graphite/src/Texture.cpp index 0f7a092de1..a9ac295169 100644 --- a/experimental/graphite/src/Texture.cpp +++ b/experimental/graphite/src/Texture.cpp @@ -9,8 +9,8 @@ namespace skgpu { -Texture::Texture(SkISize dimensions, const TextureInfo& info, Ownership ownership) - : fDimensions(dimensions), fInfo(info), fOwnership(ownership) {} +Texture::Texture(const Gpu* gpu, SkISize dimensions, const TextureInfo& info, Ownership ownership) + : Resource(gpu), fDimensions(dimensions), fInfo(info), fOwnership(ownership) {} Texture::~Texture() {} diff --git a/experimental/graphite/src/Texture.h b/experimental/graphite/src/Texture.h index 9a197f6681..7824243588 100644 --- a/experimental/graphite/src/Texture.h +++ b/experimental/graphite/src/Texture.h @@ -9,13 +9,13 @@ #define skgpu_Texture_DEFINED #include "experimental/graphite/include/TextureInfo.h" +#include "experimental/graphite/src/Resource.h" #include "experimental/graphite/src/ResourceTypes.h" -#include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" namespace skgpu { -class Texture : public SkRefCnt { +class Texture : public Resource { public: ~Texture() override; @@ -26,7 +26,7 @@ public: const TextureInfo& textureInfo() const { return fInfo; } protected: - Texture(SkISize dimensions, const TextureInfo& info, Ownership); + Texture(const Gpu*, SkISize dimensions, const TextureInfo& info, Ownership); Ownership ownership() const { return fOwnership; } diff --git a/experimental/graphite/src/mtl/MtlBlitCommandEncoder.h b/experimental/graphite/src/mtl/MtlBlitCommandEncoder.h index fdc38cc7a9..f476596bd4 100644 --- a/experimental/graphite/src/mtl/MtlBlitCommandEncoder.h +++ b/experimental/graphite/src/mtl/MtlBlitCommandEncoder.h @@ -8,6 +8,7 @@ #ifndef skgpu_MtlBlitCommandEncoder_DEFINED #define skgpu_MtlBlitCommandEncoder_DEFINED +#include "experimental/graphite/src/Resource.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/ports/SkCFObject.h" @@ -19,13 +20,14 @@ namespace skgpu::mtl { /** * Wraps a MTLBlitCommandEncoder object */ -class BlitCommandEncoder : public SkRefCnt { +class BlitCommandEncoder : public Resource { public: - static sk_sp Make(id commandBuffer) { + static sk_sp Make(const skgpu::Gpu* gpu, + id commandBuffer) { // Adding a retain here to keep our own ref separate from the autorelease pool sk_cfp> encoder = sk_ret_cfp>([commandBuffer blitCommandEncoder]); - return sk_sp(new BlitCommandEncoder(std::move(encoder))); + return sk_sp(new BlitCommandEncoder(gpu, std::move(encoder))); } void pushDebugGroup(NSString* string) { @@ -61,8 +63,12 @@ public: } private: - BlitCommandEncoder(sk_cfp> encoder) - : fCommandEncoder(std::move(encoder)) {} + BlitCommandEncoder(const skgpu::Gpu* gpu, sk_cfp> encoder) + : Resource(gpu), fCommandEncoder(std::move(encoder)) {} + + void onFreeGpuData() override { + fCommandEncoder.reset(); + } sk_cfp> fCommandEncoder; }; diff --git a/experimental/graphite/src/mtl/MtlBuffer.h b/experimental/graphite/src/mtl/MtlBuffer.h index fd80cbca40..330af9e029 100644 --- a/experimental/graphite/src/mtl/MtlBuffer.h +++ b/experimental/graphite/src/mtl/MtlBuffer.h @@ -8,9 +8,9 @@ #ifndef skgpu_MtlBuffer_DEFINED #define skgpu_MtlBuffer_DEFINED -#include "experimental/graphite/src/Buffer.h" - #include "experimental/graphite/include/mtl/MtlTypes.h" +#include "experimental/graphite/src/Buffer.h" +#include "include/core/SkRefCnt.h" #import @@ -25,11 +25,13 @@ public: id mtlBuffer() const { return fBuffer.get(); } private: - Buffer(size_t size, BufferType type, PrioritizeGpuReads, sk_cfp>); + Buffer(const Gpu*, size_t size, BufferType type, PrioritizeGpuReads, sk_cfp>); void onMap() override; void onUnmap() override; + void onFreeGpuData() override; + sk_cfp> fBuffer; }; diff --git a/experimental/graphite/src/mtl/MtlBuffer.mm b/experimental/graphite/src/mtl/MtlBuffer.mm index 7d4c8bd335..2264294823 100644 --- a/experimental/graphite/src/mtl/MtlBuffer.mm +++ b/experimental/graphite/src/mtl/MtlBuffer.mm @@ -55,14 +55,15 @@ sk_sp Buffer::Make(const Gpu* gpu, (*buffer).label = kBufferTypeNames[(int)type]; #endif - return sk_sp(new Buffer(size, type, prioritizeGpuReads, std::move(buffer))); + return sk_sp(new Buffer(gpu, size, type, prioritizeGpuReads, std::move(buffer))); } -Buffer::Buffer(size_t size, +Buffer::Buffer(const Gpu* gpu, + size_t size, BufferType type, PrioritizeGpuReads prioritizeGpuReads, sk_cfp> buffer) - : skgpu::Buffer(size, type, prioritizeGpuReads) + : skgpu::Buffer(gpu, size, type, prioritizeGpuReads) , fBuffer(std::move(buffer)) {} void Buffer::onMap() { @@ -87,5 +88,9 @@ void Buffer::onUnmap() { fMapPtr = nullptr; } +void Buffer::onFreeGpuData() { + fBuffer.reset(); +} + } // namespace skgpu::mtl diff --git a/experimental/graphite/src/mtl/MtlCommandBuffer.mm b/experimental/graphite/src/mtl/MtlCommandBuffer.mm index 3197f28b5a..b21765439a 100644 --- a/experimental/graphite/src/mtl/MtlCommandBuffer.mm +++ b/experimental/graphite/src/mtl/MtlCommandBuffer.mm @@ -163,7 +163,8 @@ bool CommandBuffer::onBeginRenderPass(const RenderPassDesc& renderPassDesc, SkASSERT(!depthStencilInfo.fTextureInfo.isValid()); } - fActiveRenderCommandEncoder = RenderCommandEncoder::Make(fCommandBuffer.get(), + fActiveRenderCommandEncoder = RenderCommandEncoder::Make(fGpu, + fCommandBuffer.get(), descriptor.get()); this->trackResource(fActiveRenderCommandEncoder); @@ -188,7 +189,7 @@ BlitCommandEncoder* CommandBuffer::getBlitCommandEncoder() { } #endif - fActiveBlitCommandEncoder = BlitCommandEncoder::Make(fCommandBuffer.get()); + fActiveBlitCommandEncoder = BlitCommandEncoder::Make(fGpu, fCommandBuffer.get()); if (!fActiveBlitCommandEncoder) { return nullptr; diff --git a/experimental/graphite/src/mtl/MtlGraphicsPipeline.h b/experimental/graphite/src/mtl/MtlGraphicsPipeline.h index c98a7afd67..644e18cf56 100644 --- a/experimental/graphite/src/mtl/MtlGraphicsPipeline.h +++ b/experimental/graphite/src/mtl/MtlGraphicsPipeline.h @@ -9,7 +9,7 @@ #define skgpu_MtlGraphicsPipeline_DEFINED #include "experimental/graphite/src/GraphicsPipeline.h" - +#include "include/core/SkRefCnt.h" #include "include/ports/SkCFObject.h" #include @@ -40,17 +40,21 @@ public: size_t instanceStride() const { return fInstanceStride; } private: - GraphicsPipeline(sk_cfp> pso, + GraphicsPipeline(const skgpu::Gpu* gpu, + sk_cfp> pso, id dss, uint32_t refValue, size_t vertexStride, size_t instanceStride) - : fPipelineState(std::move(pso)) + : skgpu::GraphicsPipeline(gpu) + , fPipelineState(std::move(pso)) , fDepthStencilState(dss) , fStencilReferenceValue(refValue) , fVertexStride(vertexStride) , fInstanceStride(instanceStride) {} + void onFreeGpuData() override; + sk_cfp> fPipelineState; id fDepthStencilState; uint32_t fStencilReferenceValue; diff --git a/experimental/graphite/src/mtl/MtlGraphicsPipeline.mm b/experimental/graphite/src/mtl/MtlGraphicsPipeline.mm index 3096a99d14..348477fe38 100644 --- a/experimental/graphite/src/mtl/MtlGraphicsPipeline.mm +++ b/experimental/graphite/src/mtl/MtlGraphicsPipeline.mm @@ -411,11 +411,16 @@ sk_sp GraphicsPipeline::Make(const Gpu* gpu, id dss = resourceProvider->findOrCreateCompatibleDepthStencilState( depthStencilSettings); - return sk_sp(new GraphicsPipeline(std::move(pso), + return sk_sp(new GraphicsPipeline(gpu, + std::move(pso), dss, depthStencilSettings.fStencilReferenceValue, desc.renderStep()->vertexStride(), desc.renderStep()->instanceStride())); } +void GraphicsPipeline::onFreeGpuData() { + fPipelineState.reset(); +} + } // namespace skgpu::mtl diff --git a/experimental/graphite/src/mtl/MtlRenderCommandEncoder.h b/experimental/graphite/src/mtl/MtlRenderCommandEncoder.h index 52a40462f5..7e8edebf28 100644 --- a/experimental/graphite/src/mtl/MtlRenderCommandEncoder.h +++ b/experimental/graphite/src/mtl/MtlRenderCommandEncoder.h @@ -8,6 +8,7 @@ #ifndef skgpu_MtlRenderCommandEncoder_DEFINED #define skgpu_MtlRenderCommandEncoder_DEFINED +#include "experimental/graphite/src/Resource.h" #include "include/core/SkRefCnt.h" #include "include/ports/SkCFObject.h" @@ -18,14 +19,15 @@ namespace skgpu::mtl { /** * Wraps a MTLRenderCommandEncoder object and associated tracked state */ -class RenderCommandEncoder : public SkRefCnt { +class RenderCommandEncoder : public Resource { public: - static sk_sp Make(id commandBuffer, + static sk_sp Make(const Gpu* gpu, + id commandBuffer, MTLRenderPassDescriptor* descriptor) { // Adding a retain here to keep our own ref separate from the autorelease pool sk_cfp> encoder = sk_ret_cfp([commandBuffer renderCommandEncoderWithDescriptor:descriptor]); - return sk_sp(new RenderCommandEncoder(std::move(encoder))); + return sk_sp(new RenderCommandEncoder(gpu, std::move(encoder))); } void setLabel(NSString* label) { @@ -240,8 +242,12 @@ public: } private: - RenderCommandEncoder(sk_cfp> encoder) - : fCommandEncoder(std::move(encoder)) {} + RenderCommandEncoder(const Gpu* gpu, sk_cfp> encoder) + : Resource(gpu), fCommandEncoder(std::move(encoder)) {} + + void onFreeGpuData() override { + fCommandEncoder.reset(); + } sk_cfp> fCommandEncoder; diff --git a/experimental/graphite/src/mtl/MtlResourceProvider.mm b/experimental/graphite/src/mtl/MtlResourceProvider.mm index 84c21eb1b1..72ace12f0d 100644 --- a/experimental/graphite/src/mtl/MtlResourceProvider.mm +++ b/experimental/graphite/src/mtl/MtlResourceProvider.mm @@ -47,7 +47,10 @@ sk_sp ResourceProvider::createWrappedTexture(const BackendTextur return nullptr; } sk_cfp> mtlTexture = sk_ret_cfp((id)mtlHandleTexture); - return Texture::MakeWrapped(texture.dimensions(), texture.info(), std::move(mtlTexture)); + return Texture::MakeWrapped(this->mtlGpu(), + texture.dimensions(), + texture.info(), + std::move(mtlTexture)); } sk_sp ResourceProvider::createBuffer(size_t size, diff --git a/experimental/graphite/src/mtl/MtlTexture.h b/experimental/graphite/src/mtl/MtlTexture.h index 64880397c5..aee173236b 100644 --- a/experimental/graphite/src/mtl/MtlTexture.h +++ b/experimental/graphite/src/mtl/MtlTexture.h @@ -9,6 +9,7 @@ #define skgpu_MtlTexture_DEFINED #include "experimental/graphite/src/Texture.h" +#include "include/core/SkRefCnt.h" #import @@ -22,11 +23,12 @@ public: SkISize dimensions, const skgpu::TextureInfo&); - static sk_sp Make(const Gpu* gpu, + static sk_sp Make(const Gpu*, SkISize dimensions, const skgpu::TextureInfo&); - static sk_sp MakeWrapped(SkISize dimensions, + static sk_sp MakeWrapped(const Gpu*, + SkISize dimensions, const skgpu::TextureInfo&, sk_cfp>); @@ -35,11 +37,14 @@ public: id mtlTexture() const { return fTexture.get(); } private: - Texture(SkISize dimensions, + Texture(const Gpu* gpu, + SkISize dimensions, const skgpu::TextureInfo& info, sk_cfp>, Ownership); + void onFreeGpuData() override; + sk_cfp> fTexture; }; diff --git a/experimental/graphite/src/mtl/MtlTexture.mm b/experimental/graphite/src/mtl/MtlTexture.mm index 589cc77a91..2b3bdd0799 100644 --- a/experimental/graphite/src/mtl/MtlTexture.mm +++ b/experimental/graphite/src/mtl/MtlTexture.mm @@ -77,11 +77,12 @@ sk_cfp> Texture::MakeMtlTexture(const Gpu* gpu, return texture; } -Texture::Texture(SkISize dimensions, +Texture::Texture(const Gpu* gpu, + SkISize dimensions, const skgpu::TextureInfo& info, sk_cfp> texture, Ownership ownership) - : skgpu::Texture(dimensions, info, ownership) + : skgpu::Texture(gpu, dimensions, info, ownership) , fTexture(std::move(texture)) {} sk_sp Texture::Make(const Gpu* gpu, @@ -91,13 +92,26 @@ sk_sp Texture::Make(const Gpu* gpu, if (!texture) { return nullptr; } - return sk_sp(new Texture(dimensions, info, std::move(texture), Ownership::kOwned)); + return sk_sp(new Texture(gpu, + dimensions, + info, + std::move(texture), + Ownership::kOwned)); } -sk_sp Texture::MakeWrapped(SkISize dimensions, +sk_sp Texture::MakeWrapped(const Gpu* gpu, + SkISize dimensions, const skgpu::TextureInfo& info, sk_cfp> texture) { - return sk_sp(new Texture(dimensions, info, std::move(texture), Ownership::kWrapped)); + return sk_sp(new Texture(gpu, + dimensions, + info, + std::move(texture), + Ownership::kWrapped)); +} + +void Texture::onFreeGpuData() { + fTexture.reset(); } } // namespace skgpu::mtl diff --git a/gn/graphite.gni b/gn/graphite.gni index 9f4ce6cfbe..487933b7a6 100644 --- a/gn/graphite.gni +++ b/gn/graphite.gni @@ -62,6 +62,8 @@ skia_graphite_sources = [ "$_src/RenderPassTask.cpp", "$_src/RenderPassTask.h", "$_src/Renderer.h", + "$_src/Resource.cpp", + "$_src/Resource.h", "$_src/ResourceProvider.cpp", "$_src/ResourceProvider.h", "$_src/ResourceTypes.h",