diff options
author | Greg Daniel <egdaniel@google.com> | 2017-03-07 13:37:21 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-07 20:37:38 +0000 |
commit | d85f97d6968c9a287a27d6ba10da8fff3b0230e2 (patch) | |
tree | 002e6d15842acd3c6b5b432a33765d1a3f93fd15 /src | |
parent | 3a9aab9ef0874d7fe661e48608a334c3ef98c6ba (diff) |
Control making of GrSemaphore objects inside of GrResourceProvider
This change will help us get to the point of not needing access to the GrGpu
object from GrContext.
BUG=skia:
Change-Id: Icff9815c73f1791d2ce34a4d27c57898a36f2b8f
Reviewed-on: https://skia-review.googlesource.com/9391
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrContext.cpp | 1 | ||||
-rw-r--r-- | src/gpu/GrContextPriv.h | 1 | ||||
-rw-r--r-- | src/gpu/GrResourceProvider.cpp | 15 | ||||
-rw-r--r-- | src/gpu/GrResourceProvider.h | 11 | ||||
-rw-r--r-- | src/gpu/GrSemaphore.h | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLExternalTextureData.cpp | 12 | ||||
-rw-r--r-- | src/gpu/gl/GrGLTexture.cpp | 6 |
7 files changed, 42 insertions, 6 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 49b8c96c16..38ab1a46aa 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -13,6 +13,7 @@ #include "GrResourceCache.h" #include "GrResourceProvider.h" #include "GrRenderTargetProxy.h" +#include "GrSemaphore.h" #include "GrSoftwarePathRenderer.h" #include "GrSurfaceContext.h" #include "GrSurfacePriv.h" diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index 9ee0b9c66f..9128cf4c7e 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -11,6 +11,7 @@ #include "GrContext.h" #include "GrSurfaceContext.h" +class GrSemaphore; class GrSurfaceProxy; /** Class that adds methods to GrContext that are only intended for use internal to Skia. diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index 636f16c0c1..ea3486aa1f 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -15,6 +15,7 @@ #include "GrRenderTargetPriv.h" #include "GrResourceCache.h" #include "GrResourceKey.h" +#include "GrSemaphore.h" #include "GrStencilAttachment.h" #include "GrTexturePriv.h" #include "../private/GrSingleOwner.h" @@ -372,3 +373,17 @@ sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendTextureAsRenderTarget( } return this->gpu()->wrapBackendTextureAsRenderTarget(desc); } + +sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT GrResourceProvider::makeSemaphore() { + return fGpu->makeSemaphore(); +} + +void GrResourceProvider::takeOwnershipOfSemaphore(sk_sp<GrSemaphore> semaphore) { + semaphore->resetGpu(fGpu); +} + +void GrResourceProvider::releaseOwnershipOfSemaphore(sk_sp<GrSemaphore> semaphore) { + semaphore->resetGpu(nullptr); +} + + diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index 5ecaac3473..1f1ff8e173 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -227,6 +227,17 @@ public: */ GrGpuResource* findAndRefResourceByUniqueKey(const GrUniqueKey&); + sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(); + + // Takes the GrSemaphore and sets the ownership of the semaphore to the GrGpu object used by + // this class. This call is only used when passing a GrSemaphore from one context to another. + void takeOwnershipOfSemaphore(sk_sp<GrSemaphore>); + // Takes the GrSemaphore and resets the ownership of the semaphore so that it is not owned by + // any GrGpu. A follow up call to takeOwnershipofSemaphore must be made so that the underlying + // semaphore can be deleted. This call is only used when passing a GrSemaphore from one context + // to another. + void releaseOwnershipOfSemaphore(sk_sp<GrSemaphore>); + void abandon() { fCache = NULL; fGpu = NULL; diff --git a/src/gpu/GrSemaphore.h b/src/gpu/GrSemaphore.h index 717b4bb506..b4843ff780 100644 --- a/src/gpu/GrSemaphore.h +++ b/src/gpu/GrSemaphore.h @@ -23,7 +23,7 @@ private: protected: explicit GrSemaphore(const GrGpu* gpu) : fGpu(gpu) {} - friend class GrGLExternalTextureData; // resetGpu + friend class GrResourceProvider; // resetGpu const GrGpu* fGpu; }; diff --git a/src/gpu/gl/GrGLExternalTextureData.cpp b/src/gpu/gl/GrGLExternalTextureData.cpp index 32c49b17a8..1087830947 100644 --- a/src/gpu/gl/GrGLExternalTextureData.cpp +++ b/src/gpu/gl/GrGLExternalTextureData.cpp @@ -6,19 +6,25 @@ */ #include "GrContext.h" +#include "GrContextPriv.h" #include "GrGpu.h" +#include "GrResourceProvider.h" #include "GrSemaphore.h" #include "gl/GrGLTypes.h" GrGLExternalTextureData::GrGLExternalTextureData(const GrGLTextureInfo& info, - sk_sp<GrSemaphore> semaphore) + sk_sp<GrSemaphore> semaphore, + GrContext* context) : fInfo(info) , fSemaphore(std::move(semaphore)) { SkASSERT(fSemaphore->unique()); - fSemaphore->resetGpu(nullptr); + context->resourceProvider()->releaseOwnershipOfSemaphore(fSemaphore); } void GrGLExternalTextureData::attachToContext(GrContext* context) { - fSemaphore->resetGpu(context->getGpu()); + context->resourceProvider()->takeOwnershipOfSemaphore(fSemaphore); + // Ideally we don't want to get the Gpu off of the context here. However, eventually this + // semaphore will live on a GrTexture object and the wait will be called from there. At that + // point we can use the GrGpu already stored directly on the GrTexture. context->getGpu()->waitSemaphore(fSemaphore); } diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp index ee029bc9a0..2f75001680 100644 --- a/src/gpu/gl/GrGLTexture.cpp +++ b/src/gpu/gl/GrGLTexture.cpp @@ -8,6 +8,7 @@ #include "GrContext.h" #include "GrGLTexture.h" #include "GrGLGpu.h" +#include "GrResourceProvider.h" #include "GrSemaphore.h" #include "GrShaderCaps.h" #include "SkMakeUnique.h" @@ -119,12 +120,13 @@ std::unique_ptr<GrExternalTextureData> GrGLTexture::detachBackendTexture() { this->getContext()->prepareSurfaceForExternalIO(this); // Set up a semaphore to be signaled once the data is ready, and flush GL - sk_sp<GrSemaphore> semaphore = this->getGpu()->makeSemaphore(); + sk_sp<GrSemaphore> semaphore = this->getContext()->resourceProvider()->makeSemaphore(); this->getGpu()->insertSemaphore(semaphore); this->getGpu()->flush(); // Make a copy of our GL-specific information - auto data = skstd::make_unique<GrGLExternalTextureData>(fInfo, std::move(semaphore)); + auto data = skstd::make_unique<GrGLExternalTextureData>(fInfo, std::move(semaphore), + this->getContext()); // Ensure the cache can't reach this texture anymore this->detachFromCache(); |