aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2018-01-30 09:28:44 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-30 14:50:00 +0000
commit6a0176bf033c780bb92396220db8140f30948345 (patch)
treee1ddcf9e3ca552d5063542d18ce30028e1ca0ca7 /src/gpu/vk
parentaa71c899fdf55e0a6cce60a2aed1ad904d23646d (diff)
Add ref counted wrapped around GrTexture ReleaseProc
Bug: skia: Change-Id: I0cd11a539fd6b16d4b3f9512694f84e0a429518c Reviewed-on: https://skia-review.googlesource.com/101341 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/vk')
-rw-r--r--src/gpu/vk/GrVkImage.cpp6
-rw-r--r--src/gpu/vk/GrVkImage.h32
-rw-r--r--src/gpu/vk/GrVkTexture.h4
3 files changed, 18 insertions, 24 deletions
diff --git a/src/gpu/vk/GrVkImage.cpp b/src/gpu/vk/GrVkImage.cpp
index d23ebfe360..5e0ffe240f 100644
--- a/src/gpu/vk/GrVkImage.cpp
+++ b/src/gpu/vk/GrVkImage.cpp
@@ -152,13 +152,13 @@ void GrVkImage::abandonImage() {
}
}
-void GrVkImage::setResourceRelease(ReleaseProc proc, ReleaseCtx ctx) {
+void GrVkImage::setResourceRelease(sk_sp<GrReleaseProcHelper> releaseHelper) {
// Forward the release proc on to GrVkImage::Resource
- fResource->setRelease(proc, ctx);
+ fResource->setRelease(std::move(releaseHelper));
}
void GrVkImage::Resource::freeGPUData(const GrVkGpu* gpu) const {
- SkASSERT(!fReleaseProc);
+ SkASSERT(!fReleaseHelper);
VK_CALL(gpu, DestroyImage(gpu->device(), fImage, nullptr));
bool isLinear = (VK_IMAGE_TILING_LINEAR == fImageTiling);
GrVkMemory::FreeImageMemory(gpu, isLinear, fAlloc);
diff --git a/src/gpu/vk/GrVkImage.h b/src/gpu/vk/GrVkImage.h
index b71ed4940c..587c3a8d25 100644
--- a/src/gpu/vk/GrVkImage.h
+++ b/src/gpu/vk/GrVkImage.h
@@ -83,7 +83,7 @@ public:
typedef void* ReleaseCtx;
typedef void (*ReleaseProc)(ReleaseCtx);
- void setResourceRelease(ReleaseProc proc, ReleaseCtx ctx);
+ void setResourceRelease(sk_sp<GrReleaseProcHelper> releaseHelper);
protected:
void releaseImage(const GrVkGpu* gpu);
@@ -98,23 +98,18 @@ private:
class Resource : public GrVkResource {
public:
Resource()
- : INHERITED()
- , fReleaseProc(nullptr)
- , fReleaseCtx(nullptr)
- , fImage(VK_NULL_HANDLE) {
+ : fImage(VK_NULL_HANDLE) {
fAlloc.fMemory = VK_NULL_HANDLE;
fAlloc.fOffset = 0;
}
Resource(VkImage image, const GrVkAlloc& alloc, VkImageTiling tiling)
- : fReleaseProc(nullptr)
- , fReleaseCtx(nullptr)
- , fImage(image)
+ : fImage(image)
, fAlloc(alloc)
, fImageTiling(tiling) {}
~Resource() override {
- SkASSERT(!fReleaseProc);
+ SkASSERT(!fReleaseHelper);
}
#ifdef SK_TRACE_VK_RESOURCES
@@ -122,18 +117,16 @@ private:
SkDebugf("GrVkImage: %d (%d refs)\n", fImage, this->getRefCnt());
}
#endif
- void setRelease(ReleaseProc proc, ReleaseCtx ctx) const {
- fReleaseProc = proc;
- fReleaseCtx = ctx;
+ void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) {
+ fReleaseHelper = std::move(releaseHelper);
}
protected:
- mutable ReleaseProc fReleaseProc;
- mutable ReleaseCtx fReleaseCtx;
+ mutable sk_sp<GrReleaseProcHelper> fReleaseHelper;
private:
void freeGPUData(const GrVkGpu* gpu) const override;
void abandonGPUData() const override {
- SkASSERT(!fReleaseProc);
+ SkASSERT(!fReleaseHelper);
}
VkImage fImage;
@@ -151,9 +144,10 @@ private:
}
private:
void invokeReleaseProc() const {
- if (fReleaseProc) {
- fReleaseProc(fReleaseCtx);
- fReleaseProc = nullptr;
+ if (fReleaseHelper) {
+ // Depending on the ref count of fReleaseHelper this may or may not actually trigger
+ // the ReleaseProc to be called.
+ fReleaseHelper.reset();
}
}
@@ -161,7 +155,7 @@ private:
void abandonGPUData() const override;
};
- const Resource* fResource;
+ Resource* fResource;
friend class GrVkRenderTarget;
};
diff --git a/src/gpu/vk/GrVkTexture.h b/src/gpu/vk/GrVkTexture.h
index a2a357a182..f2fabc887b 100644
--- a/src/gpu/vk/GrVkTexture.h
+++ b/src/gpu/vk/GrVkTexture.h
@@ -39,9 +39,9 @@ public:
// 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(GrTexture::ReleaseProc proc, GrTexture::ReleaseCtx ctx) override {
+ void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
// Forward the release proc on to GrVkImage
- this->setResourceRelease(proc, ctx);
+ this->setResourceRelease(std::move(releaseHelper));
}
protected: