"$_src/gpu/gl/GrGLGpuCommandBuffer.h",
"$_src/gpu/gl/GrGLGpuProgramCache.cpp",
"$_src/gpu/gl/GrGLExtensions.cpp",
+ "$_src/gpu/gl/GrGLExternalTextureData.cpp",
"$_src/gpu/gl/GrGLInterface.cpp",
"$_src/gpu/gl/GrGLIRect.h",
"$_src/gpu/gl/GrGLPath.cpp",
void prepareSurfaceForExternalIO(GrSurface*);
/**
- * As above, but additionally flushes the backend API (eg calls glFlush), and returns a fence
- * that can be used to determine if the surface is safe to use on another context or thread.
- */
- GrFence SK_WARN_UNUSED_RESULT prepareSurfaceForExternalIOAndFlush(GrSurface*);
-
- /**
* An ID associated with this context, guaranteed to be unique.
*/
uint32_t uniqueID() { return fUniqueID; }
#define GrExternalTextureData_DEFINED
#include "GrTypes.h"
-#include "GrTypesPriv.h"
+
+class GrContext;
class SK_API GrExternalTextureData : SkNoncopyable {
public:
- GrExternalTextureData(GrFence fence) : fFence(fence) {}
virtual ~GrExternalTextureData() {}
virtual GrBackend getBackend() const = 0;
- GrFence getFence() const { return fFence; }
-
protected:
virtual GrBackendObject getBackendObject() const = 0;
-
- GrFence fFence;
+ virtual void attachToContext(GrContext*) = 0;
friend class SkCrossContextImageData;
+ friend class SkImage;
};
#endif
#include "GrExternalTextureData.h"
#include "GrGLConfig.h"
+#include "SkRefCnt.h"
/**
* Classifies GL contexts by which standard they implement (currently as OpenGL vs. OpenGL ES).
GrGLuint fID;
};
+class GrSemaphore;
+
class GrGLExternalTextureData : public GrExternalTextureData {
public:
- GrGLExternalTextureData(const GrGLTextureInfo& info, GrFence fence)
- : INHERITED(fence)
- , fInfo(info) {}
+ GrGLExternalTextureData(const GrGLTextureInfo& info, sk_sp<GrSemaphore> semaphore);
GrBackend getBackend() const override { return kOpenGL_GrBackend; }
protected:
GrBackendObject getBackendObject() const override {
return reinterpret_cast<GrBackendObject>(&fInfo);
}
+ void attachToContext(GrContext*) override;
GrGLTextureInfo fInfo;
+ sk_sp<GrSemaphore> fSemaphore;
typedef GrExternalTextureData INHERITED;
};
class GrVkExternalTextureData : public GrExternalTextureData {
public:
- GrVkExternalTextureData(const GrVkImageInfo& info, GrFence fence)
- : INHERITED(fence)
- , fInfo(info) {}
+ GrVkExternalTextureData(const GrVkImageInfo& info) : fInfo(info) {}
GrBackend getBackend() const override { return kVulkan_GrBackend; }
protected:
GrBackendObject getBackendObject() const override {
return reinterpret_cast<GrBackendObject>(&fInfo);
}
+ void attachToContext(GrContext*) override {
+ // TODO: Implement this
+ }
GrVkImageInfo fInfo;
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
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
protected:
explicit GrSemaphore(const GrGpu* gpu) : fGpu(gpu) {}
+ friend class GrGLExternalTextureData; // resetGpu
+
const GrGpu* fGpu;
};
--- /dev/null
+/*
+ * 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);
+}
#include "GrContext.h"
#include "GrGLTexture.h"
#include "GrGLGpu.h"
+#include "GrSemaphore.h"
#include "GrShaderCaps.h"
#include "SkMakeUnique.h"
#include "SkTraceMemoryDump.h"
}
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();
#include "GrGpu.h"
#include "GrImageTextureMaker.h"
#include "GrRenderTargetContext.h"
+#include "GrSemaphore.h"
#include "GrTextureAdjuster.h"
#include "GrTexturePriv.h"
#include "GrTextureProvider.h"
}
if (ccid->fTextureData) {
- GrFence fence = ccid->fTextureData->getFence();
- context->getGpu()->waitFence(fence);
- context->getGpu()->deleteFence(fence);
+ ccid->fTextureData->attachToContext(context);
}
return MakeFromAdoptedTexture(context, ccid->fDesc, ccid->fAlphaType,