Index: tools/gpu/gl/GLFenceSync.cpp |
diff --git a/tools/gpu/gl/GLFenceSync.cpp b/tools/gpu/gl/GLFenceSync.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a4f9c65c8c6d5d4c866d7a46ff8e8857aaa3985c |
--- /dev/null |
+++ b/tools/gpu/gl/GLFenceSync.cpp |
@@ -0,0 +1,63 @@ |
+/* |
+ * Copyright 2016 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "GLFenceSync.h" |
+ |
+#include "GLTestContext.h" |
+#include "gl/GrGLUtil.h" |
+ |
+namespace sk_gpu_test { |
+ |
+GLFenceSync* 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)); |
+ if (GrGLGetVersion(ctx->gl()) < 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(); |
+} |
+ |
+PlatformFence GLFenceSync::insertFence() const { |
+ return reinterpret_cast<PlatformFence>(fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0)); |
+} |
+ |
+bool GLFenceSync::waitFence(PlatformFence fence) const { |
+ GLsync glsync = reinterpret_cast<GLsync>(fence); |
+ return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BIT, -1); |
+} |
+ |
+void GLFenceSync::deleteFence(PlatformFence fence) const { |
+ GLsync glsync = reinterpret_cast<GLsync>(fence); |
+ fGLDeleteSync(glsync); |
+} |
+ |
+} // namespace sk_gpu_test |