From 66366c697853e906d961ae691e2bc5209cdcfa62 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Thu, 15 Jun 2017 15:25:38 -0400 Subject: Add API for flushing surfaces with gpu semaphores BUG=skia: Change-Id: Ia4bfef784cd5f2516ceccafce958be18a86f91d1 Reviewed-on: https://skia-review.googlesource.com/11488 Commit-Queue: Greg Daniel Reviewed-by: Brian Salomon Reviewed-by: Forrest Reiling --- src/gpu/gl/GrGLGpu.cpp | 13 ++++++++++--- src/gpu/gl/GrGLGpu.h | 4 +++- src/gpu/gl/GrGLSemaphore.h | 25 ++++++++++++++++++++----- 3 files changed, 33 insertions(+), 9 deletions(-) (limited to 'src/gpu/gl') diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index b3f8c2caa8..d40160044c 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -9,6 +9,7 @@ #include #include "../private/GrGLSL.h" +#include "GrBackendSemaphore.h" #include "GrBackendSurface.h" #include "GrFixedClip.h" #include "GrGLBuffer.h" @@ -4288,10 +4289,16 @@ void GrGLGpu::deleteFence(GrFence fence) const { this->deleteSync((GrGLsync)fence); } -sk_sp SK_WARN_UNUSED_RESULT GrGLGpu::makeSemaphore() { - return GrGLSemaphore::Make(this); +sk_sp SK_WARN_UNUSED_RESULT GrGLGpu::makeSemaphore(bool isOwned) { + return GrGLSemaphore::Make(this, isOwned); } +sk_sp GrGLGpu::wrapBackendSemaphore(const GrBackendSemaphore& semaphore, + GrWrapOwnership ownership) { + return GrGLSemaphore::MakeWrapped(this, semaphore.glSync(), ownership); +} + + void GrGLGpu::insertSemaphore(sk_sp semaphore, bool flush) { GrGLSemaphore* glSem = static_cast(semaphore.get()); @@ -4316,7 +4323,7 @@ void GrGLGpu::deleteSync(GrGLsync sync) const { sk_sp GrGLGpu::prepareTextureForCrossContextUsage(GrTexture* texture) { // Set up a semaphore to be signaled once the data is ready, and flush GL - sk_sp semaphore = this->makeSemaphore(); + sk_sp semaphore = this->makeSemaphore(true); this->insertSemaphore(semaphore, true); return semaphore; diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index f121df3f01..80a12eb7cc 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -166,7 +166,9 @@ public: bool waitFence(GrFence, uint64_t timeout) override; void deleteFence(GrFence) const override; - sk_sp SK_WARN_UNUSED_RESULT makeSemaphore() override; + sk_sp SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override; + sk_sp wrapBackendSemaphore(const GrBackendSemaphore& semaphore, + GrWrapOwnership ownership) override; void insertSemaphore(sk_sp semaphore, bool flush) override; void waitSemaphore(sk_sp semaphore) override; diff --git a/src/gpu/gl/GrGLSemaphore.h b/src/gpu/gl/GrGLSemaphore.h index f439ebd294..cfc3de9951 100644 --- a/src/gpu/gl/GrGLSemaphore.h +++ b/src/gpu/gl/GrGLSemaphore.h @@ -10,16 +10,26 @@ #include "GrSemaphore.h" -class GrGLGpu; +#include "GrBackendSemaphore.h" +#include "GrGLGpu.h" class GrGLSemaphore : public GrSemaphore { public: - static sk_sp Make(const GrGLGpu* gpu) { - return sk_sp(new GrGLSemaphore(gpu)); + static sk_sp Make(const GrGLGpu* gpu, bool isOwned) { + return sk_sp(new GrGLSemaphore(gpu, isOwned)); + } + + static sk_sp MakeWrapped(const GrGLGpu* gpu, + GrGLsync sync, + GrWrapOwnership ownership) { + auto sema = sk_sp(new GrGLSemaphore(gpu, + kBorrow_GrWrapOwnership != ownership)); + sema->setSync(sync); + return sema; } ~GrGLSemaphore() override { - if (fGpu) { + if (fIsOwned && fGpu) { static_cast(fGpu)->deleteSync(fSync); } } @@ -28,9 +38,14 @@ public: void setSync(const GrGLsync& sync) { fSync = sync; } private: - GrGLSemaphore(const GrGLGpu* gpu) : INHERITED(gpu), fSync(0) {} + GrGLSemaphore(const GrGLGpu* gpu, bool isOwned) : INHERITED(gpu), fSync(0), fIsOwned(isOwned) {} + + void setBackendSemaphore(GrBackendSemaphore* backendSemaphore) const override { + backendSemaphore->initGL(fSync); + } GrGLsync fSync; + bool fIsOwned; typedef GrSemaphore INHERITED; }; -- cgit v1.2.3