aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/gpu/gl
diff options
context:
space:
mode:
authorGravatar csmartdalton <csmartdalton@google.com>2016-10-04 11:08:45 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-10-04 11:08:45 -0700
commit421a3c1cc1b227084c7c84618d0b6a6804faabef (patch)
tree121df15df779adc93866c323571c3a02ee349429 /tools/gpu/gl
parentd36baa7a4a5ae3cc94cc4a45379f55658f80c0a6 (diff)
Move GPU fences into sk_gpu_test
Diffstat (limited to 'tools/gpu/gl')
-rw-r--r--tools/gpu/gl/GLTestContext.cpp117
-rw-r--r--tools/gpu/gl/GLTestContext.h22
-rw-r--r--tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp23
3 files changed, 85 insertions, 77 deletions
diff --git a/tools/gpu/gl/GLTestContext.cpp b/tools/gpu/gl/GLTestContext.cpp
index 68980922cd..1d53bbcd83 100644
--- a/tools/gpu/gl/GLTestContext.cpp
+++ b/tools/gpu/gl/GLTestContext.cpp
@@ -8,21 +8,24 @@
#include "GLTestContext.h"
#include "gl/GrGLUtil.h"
-namespace sk_gpu_test {
-class GLTestContext::GLFenceSync : public SkGpuFenceSync {
+namespace {
+
+class GLFenceSync : public sk_gpu_test::FenceSync {
public:
- static GLFenceSync* CreateIfSupported(const GLTestContext*);
+ static GLFenceSync* CreateIfSupported(const sk_gpu_test::GLTestContext*);
- SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override;
- bool waitFence(SkPlatformGpuFence fence) const override;
- void deleteFence(SkPlatformGpuFence fence) const override;
+ sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override;
+ bool waitFence(sk_gpu_test::PlatformFence fence) const override;
+ void deleteFence(sk_gpu_test::PlatformFence fence) const override;
private:
- GLFenceSync() {}
+ GLFenceSync(const sk_gpu_test::GLTestContext*, const char* ext = "");
+
+ bool validate() { return fGLFenceSync && fGLClientWaitSync && fGLDeleteSync; }
- static const GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117;
- static const GrGLenum GL_WAIT_FAILED = 0x911d;
- static const GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001;
+ static constexpr GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117;
+ static constexpr GrGLenum GL_WAIT_FAILED = 0x911d;
+ static constexpr GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001;
typedef struct __GLsync *GLsync;
@@ -34,16 +37,57 @@ private:
GLClientWaitSyncProc fGLClientWaitSync;
GLDeleteSyncProc fGLDeleteSync;
- typedef SkGpuFenceSync INHERITED;
+ typedef FenceSync INHERITED;
};
+GLFenceSync* GLFenceSync::CreateIfSupported(const sk_gpu_test::GLTestContext* ctx) {
+ SkAutoTDelete<GLFenceSync> ret;
+ if (kGL_GrGLStandard == ctx->gl()->fStandard) {
+ if (GrGLGetVersion(ctx->gl()) < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) {
+ return nullptr;
+ }
+ ret.reset(new GLFenceSync(ctx));
+ } else {
+ if (!ctx->gl()->hasExtension("GL_APPLE_sync")) {
+ return nullptr;
+ }
+ ret.reset(new GLFenceSync(ctx, "APPLE"));
+ }
+ return ret->validate() ? ret.release() : nullptr;
+}
+
+GLFenceSync::GLFenceSync(const sk_gpu_test::GLTestContext* ctx, const char* ext) {
+ ctx->getGLProcAddress(&fGLFenceSync, "glFenceSync");
+ ctx->getGLProcAddress(&fGLClientWaitSync, "glClientWaitSync");
+ ctx->getGLProcAddress(&fGLDeleteSync, "glDeleteSync");
+}
+
+sk_gpu_test::PlatformFence GLFenceSync::insertFence() const {
+ __GLsync* glsync = fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
+ return reinterpret_cast<sk_gpu_test::PlatformFence>(glsync);
+}
+
+bool GLFenceSync::waitFence(sk_gpu_test::PlatformFence fence) const {
+ GLsync glsync = reinterpret_cast<GLsync>(fence);
+ return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BIT, -1);
+}
+
+void GLFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const {
+ GLsync glsync = reinterpret_cast<GLsync>(fence);
+ fGLDeleteSync(glsync);
+}
+
+} // anonymous namespace
+
+namespace sk_gpu_test {
+
GLTestContext::GLTestContext() : TestContext() {}
GLTestContext::~GLTestContext() {
SkASSERT(nullptr == fGL.get());
}
-void GLTestContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) {
+void GLTestContext::init(const GrGLInterface* gl, FenceSync* fenceSync) {
SkASSERT(!fGL.get());
fGL.reset(gl);
fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this);
@@ -73,55 +117,6 @@ void GLTestContext::finish() {
}
}
-GLTestContext::GLFenceSync* GLTestContext::GLFenceSync::CreateIfSupported(const GLTestContext* ctx) {
- SkAutoTDelete<GLFenceSync> ret(new GLFenceSync);
-
- if (kGL_GrGLStandard == ctx->gl()->fStandard) {
- const GrGLubyte* versionStr;
- GR_GL_CALL_RET(ctx->gl(), versionStr, GetString(GR_GL_VERSION));
- GrGLVersion version = GrGLGetVersionFromString(reinterpret_cast<const char*>(versionStr));
- if (version < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) {
- return nullptr;
- }
- ret->fGLFenceSync = reinterpret_cast<GLFenceSyncProc>(
- ctx->onPlatformGetProcAddress("glFenceSync"));
- ret->fGLClientWaitSync = reinterpret_cast<GLClientWaitSyncProc>(
- ctx->onPlatformGetProcAddress("glClientWaitSync"));
- ret->fGLDeleteSync = reinterpret_cast<GLDeleteSyncProc>(
- ctx->onPlatformGetProcAddress("glDeleteSync"));
- } else {
- if (!ctx->gl()->hasExtension("GL_APPLE_sync")) {
- return nullptr;
- }
- ret->fGLFenceSync = reinterpret_cast<GLFenceSyncProc>(
- ctx->onPlatformGetProcAddress("glFenceSyncAPPLE"));
- ret->fGLClientWaitSync = reinterpret_cast<GLClientWaitSyncProc>(
- ctx->onPlatformGetProcAddress("glClientWaitSyncAPPLE"));
- ret->fGLDeleteSync = reinterpret_cast<GLDeleteSyncProc>(
- ctx->onPlatformGetProcAddress("glDeleteSyncAPPLE"));
- }
-
- if (!ret->fGLFenceSync || !ret->fGLClientWaitSync || !ret->fGLDeleteSync) {
- return nullptr;
- }
-
- return ret.release();
-}
-
-SkPlatformGpuFence GLTestContext::GLFenceSync::insertFence() const {
- return fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
-}
-
-bool GLTestContext::GLFenceSync::waitFence(SkPlatformGpuFence fence) const {
- GLsync glsync = static_cast<GLsync>(fence);
- return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BIT, -1);
-}
-
-void GLTestContext::GLFenceSync::deleteFence(SkPlatformGpuFence fence) const {
- GLsync glsync = static_cast<GLsync>(fence);
- fGLDeleteSync(glsync);
-}
-
GrGLint GLTestContext::createTextureRectangle(int width, int height, GrGLenum internalFormat,
GrGLenum externalFormat, GrGLenum externalType,
GrGLvoid* data) {
diff --git a/tools/gpu/gl/GLTestContext.h b/tools/gpu/gl/GLTestContext.h
index efe9d8f100..0cd9762f8b 100644
--- a/tools/gpu/gl/GLTestContext.h
+++ b/tools/gpu/gl/GLTestContext.h
@@ -59,27 +59,39 @@ public:
*/
virtual GLTestContext *createNew() const { return nullptr; }
+ template<typename Ret, typename... Args>
+ void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE** out)(Args...),
+ const char* name, const char* ext = nullptr) const {
+ using Proc = Ret(GR_GL_FUNCTION_TYPE*)(Args...);
+ if (!SkStrStartsWith(name, "gl")) {
+ SkFAIL("getGLProcAddress: proc name must have 'gl' prefix");
+ *out = nullptr;
+ } else if (ext) {
+ SkString fullname(name);
+ fullname.append(ext);
+ *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(fullname.c_str()));
+ } else {
+ *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(name));
+ }
+ }
+
protected:
GLTestContext();
/*
* Methods that sublcasses must call from their constructors and destructors.
*/
- void init(const GrGLInterface *, SkGpuFenceSync * = NULL);
+ void init(const GrGLInterface *, FenceSync* = nullptr);
void teardown() override;
virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
private:
- class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL functionality.
-
/** Subclass provides the gl interface object if construction was
* successful. */
SkAutoTUnref<const GrGLInterface> fGL;
- friend class GLFenceSync; // For onPlatformGetProcAddress.
-
typedef TestContext INHERITED;
};
diff --git a/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp b/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp
index edbc63200b..8fdd3fea86 100644
--- a/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp
+++ b/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp
@@ -20,20 +20,20 @@
namespace {
// TODO: Share this class with ANGLE if/when it gets support for EGL_KHR_fence_sync.
-class EGLFenceSync : public SkGpuFenceSync {
+class EGLFenceSync : public sk_gpu_test::FenceSync {
public:
static EGLFenceSync* CreateIfSupported(EGLDisplay);
- SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override;
- bool waitFence(SkPlatformGpuFence fence) const override;
- void deleteFence(SkPlatformGpuFence fence) const override;
+ sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override;
+ bool waitFence(sk_gpu_test::PlatformFence fence) const override;
+ void deleteFence(sk_gpu_test::PlatformFence fence) const override;
private:
EGLFenceSync(EGLDisplay display) : fDisplay(display) {}
EGLDisplay fDisplay;
- typedef SkGpuFenceSync INHERITED;
+ typedef sk_gpu_test::FenceSync INHERITED;
};
class EGLGLTestContext : public sk_gpu_test::GLTestContext {
@@ -301,12 +301,13 @@ EGLFenceSync* EGLFenceSync::CreateIfSupported(EGLDisplay display) {
return new EGLFenceSync(display);
}
-SkPlatformGpuFence EGLFenceSync::insertFence() const {
- return eglCreateSyncKHR(fDisplay, EGL_SYNC_FENCE_KHR, nullptr);
+sk_gpu_test::PlatformFence EGLFenceSync::insertFence() const {
+ EGLSyncKHR eglsync = eglCreateSyncKHR(fDisplay, EGL_SYNC_FENCE_KHR, nullptr);
+ return reinterpret_cast<sk_gpu_test::PlatformFence>(eglsync);
}
-bool EGLFenceSync::waitFence(SkPlatformGpuFence platformFence) const {
- EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence);
+bool EGLFenceSync::waitFence(sk_gpu_test::PlatformFence platformFence) const {
+ EGLSyncKHR eglsync = reinterpret_cast<EGLSyncKHR>(platformFence);
return EGL_CONDITION_SATISFIED_KHR ==
eglClientWaitSyncKHR(fDisplay,
eglsync,
@@ -314,8 +315,8 @@ bool EGLFenceSync::waitFence(SkPlatformGpuFence platformFence) const {
EGL_FOREVER_KHR);
}
-void EGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const {
- EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence);
+void EGLFenceSync::deleteFence(sk_gpu_test::PlatformFence platformFence) const {
+ EGLSyncKHR eglsync = reinterpret_cast<EGLSyncKHR>(platformFence);
eglDestroySyncKHR(fDisplay, eglsync);
}