aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-03-02 15:09:20 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-02 20:47:36 +0000
commitfe3b51636d4216c4ea6cb74ed0964c1d315ca487 (patch)
treee85907dad1a167ecceace5de1e6157a787fe0bac /src/gpu
parente836b7817e8b28f0bd69578b8dfd83b8ef00248c (diff)
Use GrSemaphore rather than GrFence for external texture data
BUG=skia: Change-Id: I0d23eb9dcf5c01c71d3571ef97690af68b900807 Reviewed-on: https://skia-review.googlesource.com/9141 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrContext.cpp7
-rw-r--r--src/gpu/GrSemaphore.h4
-rw-r--r--src/gpu/gl/GrGLExternalTextureData.cpp24
-rw-r--r--src/gpu/gl/GrGLTexture.cpp12
4 files changed, 36 insertions, 11 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 97b525d7ef..7dfee00ed2 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -546,13 +546,6 @@ void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) {
fDrawingManager->prepareSurfaceForExternalIO(surface);
}
-GrFence GrContext::prepareSurfaceForExternalIOAndFlush(GrSurface* surface) {
- this->prepareSurfaceForExternalIO(surface);
- GrFence fence = fGpu->insertFence();
- fGpu->flush();
- return fence;
-}
-
void GrContext::flushSurfaceWrites(GrSurface* surface) {
ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
diff --git a/src/gpu/GrSemaphore.h b/src/gpu/GrSemaphore.h
index bdeff09ec2..717b4bb506 100644
--- a/src/gpu/GrSemaphore.h
+++ b/src/gpu/GrSemaphore.h
@@ -13,7 +13,7 @@
class GrGpu;
class GrSemaphore : public SkRefCnt {
-public:
+private:
// This function should only be used in the case of exporting and importing a GrSemaphore object
// from one GrContext to another. When exporting, the GrSemaphore should be set to a null GrGpu,
// and when importing it should be set to the GrGpu of the current context. Once exported, a
@@ -23,6 +23,8 @@ public:
protected:
explicit GrSemaphore(const GrGpu* gpu) : fGpu(gpu) {}
+ friend class GrGLExternalTextureData; // resetGpu
+
const GrGpu* fGpu;
};
diff --git a/src/gpu/gl/GrGLExternalTextureData.cpp b/src/gpu/gl/GrGLExternalTextureData.cpp
new file mode 100644
index 0000000000..32c49b17a8
--- /dev/null
+++ b/src/gpu/gl/GrGLExternalTextureData.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrContext.h"
+#include "GrGpu.h"
+#include "GrSemaphore.h"
+#include "gl/GrGLTypes.h"
+
+GrGLExternalTextureData::GrGLExternalTextureData(const GrGLTextureInfo& info,
+ sk_sp<GrSemaphore> semaphore)
+ : fInfo(info)
+ , fSemaphore(std::move(semaphore)) {
+ SkASSERT(fSemaphore->unique());
+ fSemaphore->resetGpu(nullptr);
+}
+
+void GrGLExternalTextureData::attachToContext(GrContext* context) {
+ fSemaphore->resetGpu(context->getGpu());
+ context->getGpu()->waitSemaphore(fSemaphore);
+}
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index a5609887c0..ee029bc9a0 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 "GrSemaphore.h"
#include "GrShaderCaps.h"
#include "SkMakeUnique.h"
#include "SkTraceMemoryDump.h"
@@ -114,11 +115,16 @@ GrBackendObject GrGLTexture::getTextureHandle() const {
}
std::unique_ptr<GrExternalTextureData> GrGLTexture::detachBackendTexture() {
- // Flush any pending writes to this texture, as well GL itself
- GrFence fence = this->getContext()->prepareSurfaceForExternalIOAndFlush(this);
+ // Flush any pending writes to this texture
+ 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();
+ this->getGpu()->insertSemaphore(semaphore);
+ this->getGpu()->flush();
// Make a copy of our GL-specific information
- auto data = skstd::make_unique<GrGLExternalTextureData>(fInfo, fence);
+ auto data = skstd::make_unique<GrGLExternalTextureData>(fInfo, std::move(semaphore));
// Ensure the cache can't reach this texture anymore
this->detachFromCache();