Move texture release proc to GrSurface so that render targets can also have releases.
Bug: skia: Change-Id: I65e7872057110295376ad76e0656a47bca3f712d Reviewed-on: https://skia-review.googlesource.com/c/188633 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
69e7808169
commit
2d35a1c875
@ -45,6 +45,20 @@ public:
|
||||
|
||||
virtual GrBackendFormat backendFormat() const = 0;
|
||||
|
||||
void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) {
|
||||
this->onSetRelease(releaseHelper);
|
||||
fReleaseHelper = std::move(releaseHelper);
|
||||
}
|
||||
|
||||
// These match the definitions in SkImage, from whence they came.
|
||||
// TODO: Remove Chrome's need to call this on a GrTexture
|
||||
typedef void* ReleaseCtx;
|
||||
typedef void (*ReleaseProc)(ReleaseCtx);
|
||||
void setRelease(ReleaseProc proc, ReleaseCtx ctx) {
|
||||
sk_sp<GrReleaseProcHelper> helper(new GrReleaseProcHelper(proc, ctx));
|
||||
this->setRelease(std::move(helper));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the texture associated with the surface, may be null.
|
||||
*/
|
||||
@ -107,7 +121,10 @@ protected:
|
||||
, fSurfaceFlags(GrInternalSurfaceFlags::kNone) {
|
||||
}
|
||||
|
||||
~GrSurface() override {}
|
||||
~GrSurface() override {
|
||||
// check that invokeReleaseProc has been called (if needed)
|
||||
SkASSERT(!fReleaseHelper);
|
||||
}
|
||||
|
||||
void onRelease() override;
|
||||
void onAbandon() override;
|
||||
@ -115,10 +132,18 @@ protected:
|
||||
private:
|
||||
const char* getResourceType() const override { return "Surface"; }
|
||||
|
||||
GrPixelConfig fConfig;
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
GrInternalSurfaceFlags fSurfaceFlags;
|
||||
virtual void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) = 0;
|
||||
void invokeReleaseProc() {
|
||||
// Depending on the ref count of fReleaseHelper this may or may not actually trigger the
|
||||
// ReleaseProc to be called.
|
||||
fReleaseHelper.reset();
|
||||
}
|
||||
|
||||
GrPixelConfig fConfig;
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
GrInternalSurfaceFlags fSurfaceFlags;
|
||||
sk_sp<GrReleaseProcHelper> fReleaseHelper;
|
||||
|
||||
typedef GrGpuResource INHERITED;
|
||||
};
|
||||
|
@ -49,17 +49,6 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) = 0;
|
||||
|
||||
// These match the definitions in SkImage, from whence they came.
|
||||
// TODO: Either move Chrome over to new api or remove their need to call this on GrTexture
|
||||
typedef void* ReleaseCtx;
|
||||
typedef void (*ReleaseProc)(ReleaseCtx);
|
||||
void setRelease(ReleaseProc proc, ReleaseCtx ctx) {
|
||||
sk_sp<GrReleaseProcHelper> helper(new GrReleaseProcHelper(proc, ctx));
|
||||
this->setRelease(std::move(helper));
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a proc on this texture. It will be called when the texture becomes "idle". Idle is
|
||||
* defined to mean that the texture has no refs or pending IOs and that GPU I/O operations on
|
||||
|
@ -177,9 +177,11 @@ bool GrSurface::hasPendingIO() const {
|
||||
}
|
||||
|
||||
void GrSurface::onRelease() {
|
||||
this->invokeReleaseProc();
|
||||
this->INHERITED::onRelease();
|
||||
}
|
||||
|
||||
void GrSurface::onAbandon() {
|
||||
this->invokeReleaseProc();
|
||||
this->INHERITED::onAbandon();
|
||||
}
|
||||
|
@ -95,6 +95,8 @@ private:
|
||||
|
||||
size_t onGpuMemorySize() const override;
|
||||
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
|
||||
|
||||
int msaaSamples() const;
|
||||
// The number total number of samples, including both MSAA and resolve texture samples.
|
||||
int totalSamples() const;
|
||||
|
@ -91,13 +91,11 @@ void GrGLTexture::onRelease() {
|
||||
}
|
||||
fID = 0;
|
||||
}
|
||||
this->invokeReleaseProc();
|
||||
INHERITED::onRelease();
|
||||
}
|
||||
|
||||
void GrGLTexture::onAbandon() {
|
||||
fID = 0;
|
||||
this->invokeReleaseProc();
|
||||
INHERITED::onAbandon();
|
||||
}
|
||||
|
||||
|
@ -64,10 +64,7 @@ public:
|
||||
|
||||
GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus);
|
||||
|
||||
~GrGLTexture() override {
|
||||
// check that invokeReleaseProc has been called (if needed)
|
||||
SkASSERT(!fReleaseHelper);
|
||||
}
|
||||
~GrGLTexture() override {}
|
||||
|
||||
GrBackendTexture getBackendTexture() const override;
|
||||
|
||||
@ -78,10 +75,6 @@ public:
|
||||
fNonSamplerParams.invalidate();
|
||||
}
|
||||
|
||||
void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
|
||||
fReleaseHelper = std::move(releaseHelper);
|
||||
}
|
||||
|
||||
void setIdleProc(IdleProc proc, void* context) override {
|
||||
fIdleProc = proc;
|
||||
fIdleProcContext = context;
|
||||
@ -131,11 +124,7 @@ protected:
|
||||
bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override;
|
||||
|
||||
private:
|
||||
void invokeReleaseProc() {
|
||||
// Depending on the ref count of fReleaseHelper this may or may not actually trigger the
|
||||
// ReleaseProc to be called.
|
||||
fReleaseHelper.reset();
|
||||
}
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
|
||||
|
||||
void removedLastRefOrPendingIO() override {
|
||||
if (fIdleProc) {
|
||||
@ -148,7 +137,6 @@ private:
|
||||
SamplerParams fSamplerParams;
|
||||
NonSamplerParams fNonSamplerParams;
|
||||
GrGpu::ResetTimestamp fParamsTimestamp;
|
||||
sk_sp<GrReleaseProcHelper> fReleaseHelper;
|
||||
IdleProc* fIdleProc = nullptr;
|
||||
void* fIdleProcContext = nullptr;
|
||||
GrGLuint fID;
|
||||
|
@ -66,6 +66,8 @@ private:
|
||||
GrMipMapsStatus);
|
||||
|
||||
size_t onGpuMemorySize() const override;
|
||||
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
|
||||
};
|
||||
|
||||
#ifdef SK_BUILD_FOR_WIN
|
||||
|
@ -43,9 +43,6 @@ public:
|
||||
}
|
||||
|
||||
void textureParamsModified() override {}
|
||||
void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
|
||||
fReleaseHelper = std::move(releaseHelper);
|
||||
}
|
||||
|
||||
void setIdleProc(IdleProc proc, void* context) override {
|
||||
fIdleProc = proc;
|
||||
@ -62,12 +59,10 @@ protected:
|
||||
, fInfo(info) {}
|
||||
|
||||
void onRelease() override {
|
||||
this->invokeReleaseProc();
|
||||
INHERITED::onRelease();
|
||||
}
|
||||
|
||||
void onAbandon() override {
|
||||
this->invokeReleaseProc();
|
||||
INHERITED::onAbandon();
|
||||
}
|
||||
|
||||
@ -86,11 +81,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
void invokeReleaseProc() {
|
||||
// Depending on the ref count of fReleaseHelper this may or may not actually trigger the
|
||||
// ReleaseProc to be called.
|
||||
fReleaseHelper.reset();
|
||||
}
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
|
||||
|
||||
GrMockTextureInfo fInfo;
|
||||
sk_sp<GrReleaseProcHelper> fReleaseHelper;
|
||||
@ -148,6 +139,8 @@ protected:
|
||||
: GrSurface(gpu, desc), INHERITED(gpu, desc), fInfo(info) {}
|
||||
|
||||
private:
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
|
||||
|
||||
GrMockRenderTargetInfo fInfo;
|
||||
|
||||
typedef GrRenderTarget INHERITED;
|
||||
@ -185,6 +178,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
|
||||
|
||||
void onAbandon() override {
|
||||
GrRenderTarget::onAbandon();
|
||||
GrMockTexture::onAbandon();
|
||||
|
@ -80,6 +80,8 @@ private:
|
||||
Wrapped);
|
||||
|
||||
bool completeStencilAttachment() override;
|
||||
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
|
||||
};
|
||||
|
||||
|
||||
|
@ -36,13 +36,6 @@ public:
|
||||
|
||||
bool reallocForMipmap(GrMtlGpu* gpu, uint32_t mipLevels);
|
||||
|
||||
void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
|
||||
// Since all MTLResources are inherently ref counted, we can call the Release proc when we
|
||||
// delete the GrMtlTexture without worry of the MTLTexture getting deleted before it is done
|
||||
// on the GPU.
|
||||
fReleaseHelper = std::move(releaseHelper);
|
||||
}
|
||||
|
||||
void setIdleProc(IdleProc proc, void* context) override {
|
||||
fIdleProc = proc;
|
||||
fIdleProcContext = context;
|
||||
@ -55,11 +48,9 @@ protected:
|
||||
GrMtlGpu* getMtlGpu() const;
|
||||
|
||||
void onAbandon() override {
|
||||
this->invokeReleaseProc();
|
||||
fTexture = nil;
|
||||
}
|
||||
void onRelease() override {
|
||||
this->invokeReleaseProc();
|
||||
fTexture = nil;
|
||||
}
|
||||
|
||||
@ -70,11 +61,10 @@ protected:
|
||||
private:
|
||||
enum Wrapped { kWrapped };
|
||||
|
||||
void invokeReleaseProc() {
|
||||
// Depending on the ref count of fReleaseHelper this may or may not actually trigger the
|
||||
// ReleaseProc to be called.
|
||||
fReleaseHelper.reset();
|
||||
}
|
||||
// Since all MTLResources are inherently ref counted, we can call the Release proc when we
|
||||
// delete the GrMtlTexture without worry of the MTLTexture getting deleted before it is done on
|
||||
// the GPU. Thus we do nothing special here with the releaseHelper.
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
|
||||
|
||||
void removedLastRefOrPendingIO() override {
|
||||
if (fIdleProc) {
|
||||
|
@ -75,6 +75,8 @@ private:
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
numColorSamples, GrMipMapped::kNo, false);
|
||||
}
|
||||
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -160,6 +160,13 @@ private:
|
||||
|
||||
bool completeStencilAttachment() override;
|
||||
|
||||
// In Vulkan we call the release proc after we are finished with the underlying
|
||||
// GrVkImage::Resource object (which occurs after the GPU has finished all work on it).
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
|
||||
// Forward the release proc on to GrVkImage
|
||||
this->setResourceRelease(std::move(releaseHelper));
|
||||
}
|
||||
|
||||
void releaseInternalObjects();
|
||||
void abandonInternalObjects();
|
||||
|
||||
|
@ -38,13 +38,6 @@ public:
|
||||
|
||||
const GrVkImageView* textureView();
|
||||
|
||||
// In Vulkan we call the release proc after we are finished with the underlying
|
||||
// GrVkImage::Resource object (which occurs after the GPU has finsihed all work on it).
|
||||
void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
|
||||
// Forward the release proc on to GrVkImage
|
||||
this->setResourceRelease(std::move(releaseHelper));
|
||||
}
|
||||
|
||||
void setIdleProc(IdleProc, void* context) override;
|
||||
void* idleContext() const override { return fIdleProcContext; }
|
||||
|
||||
@ -69,6 +62,13 @@ private:
|
||||
const GrVkImageView*, GrMipMapsStatus, GrBackendObjectOwnership, GrWrapCacheable,
|
||||
GrIOType);
|
||||
|
||||
// In Vulkan we call the release proc after we are finished with the underlying
|
||||
// GrVkImage::Resource object (which occurs after the GPU has finished all work on it).
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
|
||||
// Forward the release proc on to GrVkImage
|
||||
this->setResourceRelease(std::move(releaseHelper));
|
||||
}
|
||||
|
||||
void removedLastRefOrPendingIO() override;
|
||||
|
||||
const GrVkImageView* fTextureView;
|
||||
|
@ -104,6 +104,13 @@ private:
|
||||
|
||||
// GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
|
||||
size_t onGpuMemorySize() const override;
|
||||
|
||||
// In Vulkan we call the release proc after we are finished with the underlying
|
||||
// GrVkImage::Resource object (which occurs after the GPU has finished all work on it).
|
||||
void onSetRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
|
||||
// Forward the release proc on to GrVkImage
|
||||
this->setResourceRelease(std::move(releaseHelper));
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user