Make GrSemaphore a GrGpuResource
This makes semaphores get handled correctly when GrContext is abandoned or
asked to free all its resources.
Change-Id: I0b935bb95cf99b9acf647472bcd0231bb2759db6
Reviewed-on: https://skia-review.googlesource.com/150364
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/gl/GrGLSemaphore.cpp b/src/gpu/gl/GrGLSemaphore.cpp
index c26b74e..b557efb 100644
--- a/src/gpu/gl/GrGLSemaphore.cpp
+++ b/src/gpu/gl/GrGLSemaphore.cpp
@@ -9,12 +9,20 @@
#include "GrGLGpu.h"
-GrGLSemaphore::GrGLSemaphore(const GrGLGpu* gpu, bool isOwned)
- : INHERITED(gpu), fSync(0), fIsOwned(isOwned) {
+GrGLSemaphore::GrGLSemaphore(GrGLGpu* gpu, bool isOwned)
+ : INHERITED(gpu), fSync(0), fIsOwned(isOwned) {
+ isOwned ? this->registerWithCache(SkBudgeted::kNo) : this->registerWithCacheWrapped();
}
-GrGLSemaphore::~GrGLSemaphore() {
- if (fIsOwned && fGpu) {
- static_cast<const GrGLGpu*>(fGpu)->deleteSync(fSync);
+void GrGLSemaphore::onRelease() {
+ if (fSync && fIsOwned) {
+ static_cast<const GrGLGpu*>(this->getGpu())->deleteSync(fSync);
}
+ fSync = 0;
+ INHERITED::onRelease();
+}
+
+void GrGLSemaphore::onAbandon() {
+ fSync = 0;
+ INHERITED::onAbandon();
}
diff --git a/src/gpu/gl/GrGLSemaphore.h b/src/gpu/gl/GrGLSemaphore.h
index 6fd1a6f..851ae02 100644
--- a/src/gpu/gl/GrGLSemaphore.h
+++ b/src/gpu/gl/GrGLSemaphore.h
@@ -16,11 +16,11 @@
class GrGLSemaphore : public GrSemaphore {
public:
- static sk_sp<GrGLSemaphore> Make(const GrGLGpu* gpu, bool isOwned) {
+ static sk_sp<GrGLSemaphore> Make(GrGLGpu* gpu, bool isOwned) {
return sk_sp<GrGLSemaphore>(new GrGLSemaphore(gpu, isOwned));
}
- static sk_sp<GrGLSemaphore> MakeWrapped(const GrGLGpu* gpu,
+ static sk_sp<GrGLSemaphore> MakeWrapped(GrGLGpu* gpu,
GrGLsync sync,
GrWrapOwnership ownership) {
auto sema = sk_sp<GrGLSemaphore>(new GrGLSemaphore(gpu,
@@ -29,8 +29,6 @@
return sema;
}
- ~GrGLSemaphore() override;
-
GrGLsync sync() const { return fSync; }
void setSync(const GrGLsync& sync) { fSync = sync; }
@@ -41,8 +39,10 @@
}
private:
- GrGLSemaphore(const GrGLGpu* gpu, bool isOwned);
+ GrGLSemaphore(GrGLGpu* gpu, bool isOwned);
+ void onRelease() override;
+ void onAbandon() override;
GrGLsync fSync;
bool fIsOwned;