| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GLTestContext.h" | 8 #include "GLTestContext.h" |
| 9 #include "gl/GrGLUtil.h" | 9 #include "gl/GrGLUtil.h" |
| 10 | 10 |
| 11 namespace sk_gpu_test { | 11 namespace { |
| 12 class GLTestContext::GLFenceSync : public SkGpuFenceSync { | 12 |
| 13 class GLFenceSync : public sk_gpu_test::FenceSync { |
| 13 public: | 14 public: |
| 14 static GLFenceSync* CreateIfSupported(const GLTestContext*); | 15 static GLFenceSync* CreateIfSupported(const sk_gpu_test::GLTestContext*); |
| 15 | 16 |
| 16 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; | 17 sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const overrid
e; |
| 17 bool waitFence(SkPlatformGpuFence fence) const override; | 18 bool waitFence(sk_gpu_test::PlatformFence fence) const override; |
| 18 void deleteFence(SkPlatformGpuFence fence) const override; | 19 void deleteFence(sk_gpu_test::PlatformFence fence) const override; |
| 19 | 20 |
| 20 private: | 21 private: |
| 21 GLFenceSync() {} | 22 GLFenceSync(const sk_gpu_test::GLTestContext*, const char* ext = ""); |
| 22 | 23 |
| 23 static const GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117; | 24 bool validate() { return fGLFenceSync && fGLClientWaitSync && fGLDeleteSync;
} |
| 24 static const GrGLenum GL_WAIT_FAILED = 0x911d; | 25 |
| 25 static const GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001; | 26 static constexpr GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117; |
| 27 static constexpr GrGLenum GL_WAIT_FAILED = 0x911d; |
| 28 static constexpr GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001; |
| 26 | 29 |
| 27 typedef struct __GLsync *GLsync; | 30 typedef struct __GLsync *GLsync; |
| 28 | 31 |
| 29 typedef GLsync (GR_GL_FUNCTION_TYPE* GLFenceSyncProc) (GrGLenum, GrGLbitfiel
d); | 32 typedef GLsync (GR_GL_FUNCTION_TYPE* GLFenceSyncProc) (GrGLenum, GrGLbitfiel
d); |
| 30 typedef GrGLenum (GR_GL_FUNCTION_TYPE* GLClientWaitSyncProc) (GLsync, GrGLbi
tfield, GrGLuint64); | 33 typedef GrGLenum (GR_GL_FUNCTION_TYPE* GLClientWaitSyncProc) (GLsync, GrGLbi
tfield, GrGLuint64); |
| 31 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GLDeleteSyncProc) (GLsync); | 34 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GLDeleteSyncProc) (GLsync); |
| 32 | 35 |
| 33 GLFenceSyncProc fGLFenceSync; | 36 GLFenceSyncProc fGLFenceSync; |
| 34 GLClientWaitSyncProc fGLClientWaitSync; | 37 GLClientWaitSyncProc fGLClientWaitSync; |
| 35 GLDeleteSyncProc fGLDeleteSync; | 38 GLDeleteSyncProc fGLDeleteSync; |
| 36 | 39 |
| 37 typedef SkGpuFenceSync INHERITED; | 40 typedef FenceSync INHERITED; |
| 38 }; | 41 }; |
| 39 | 42 |
| 43 GLFenceSync* GLFenceSync::CreateIfSupported(const sk_gpu_test::GLTestContext* ct
x) { |
| 44 SkAutoTDelete<GLFenceSync> ret; |
| 45 if (kGL_GrGLStandard == ctx->gl()->fStandard) { |
| 46 const GrGLubyte* versionStr; |
| 47 GR_GL_CALL_RET(ctx->gl(), versionStr, GetString(GR_GL_VERSION)); |
| 48 if (GrGLGetVersion(ctx->gl()) < GR_GL_VER(3,2) && !ctx->gl()->hasExtensi
on("GL_ARB_sync")) { |
| 49 return nullptr; |
| 50 } |
| 51 ret.reset(new GLFenceSync(ctx)); |
| 52 } else { |
| 53 if (!ctx->gl()->hasExtension("GL_APPLE_sync")) { |
| 54 return nullptr; |
| 55 } |
| 56 ret.reset(new GLFenceSync(ctx, "APPLE")); |
| 57 } |
| 58 return ret->validate() ? ret.release() : nullptr; |
| 59 } |
| 60 |
| 61 GLFenceSync::GLFenceSync(const sk_gpu_test::GLTestContext* ctx, const char* ext)
{ |
| 62 ctx->getGLProcAddress(&fGLFenceSync, "glFenceSync"); |
| 63 ctx->getGLProcAddress(&fGLClientWaitSync, "glClientWaitSync"); |
| 64 ctx->getGLProcAddress(&fGLDeleteSync, "glDeleteSync"); |
| 65 } |
| 66 |
| 67 sk_gpu_test::PlatformFence GLFenceSync::insertFence() const { |
| 68 __GLsync* glsync = fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); |
| 69 return reinterpret_cast<sk_gpu_test::PlatformFence>(glsync); |
| 70 } |
| 71 |
| 72 bool GLFenceSync::waitFence(sk_gpu_test::PlatformFence fence) const { |
| 73 GLsync glsync = reinterpret_cast<GLsync>(fence); |
| 74 return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BI
T, -1); |
| 75 } |
| 76 |
| 77 void GLFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const { |
| 78 GLsync glsync = reinterpret_cast<GLsync>(fence); |
| 79 fGLDeleteSync(glsync); |
| 80 } |
| 81 |
| 82 } // anonymous namespace |
| 83 |
| 84 namespace sk_gpu_test { |
| 85 |
| 40 GLTestContext::GLTestContext() : TestContext() {} | 86 GLTestContext::GLTestContext() : TestContext() {} |
| 41 | 87 |
| 42 GLTestContext::~GLTestContext() { | 88 GLTestContext::~GLTestContext() { |
| 43 SkASSERT(nullptr == fGL.get()); | 89 SkASSERT(nullptr == fGL.get()); |
| 44 } | 90 } |
| 45 | 91 |
| 46 void GLTestContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) { | 92 void GLTestContext::init(const GrGLInterface* gl, FenceSync* fenceSync) { |
| 47 SkASSERT(!fGL.get()); | 93 SkASSERT(!fGL.get()); |
| 48 fGL.reset(gl); | 94 fGL.reset(gl); |
| 49 fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this); | 95 fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this); |
| 50 } | 96 } |
| 51 | 97 |
| 52 void GLTestContext::teardown() { | 98 void GLTestContext::teardown() { |
| 53 fGL.reset(nullptr); | 99 fGL.reset(nullptr); |
| 54 INHERITED::teardown(); | 100 INHERITED::teardown(); |
| 55 } | 101 } |
| 56 | 102 |
| 57 void GLTestContext::testAbandon() { | 103 void GLTestContext::testAbandon() { |
| 58 INHERITED::testAbandon(); | 104 INHERITED::testAbandon(); |
| 59 if (fGL) { | 105 if (fGL) { |
| 60 fGL->abandon(); | 106 fGL->abandon(); |
| 61 } | 107 } |
| 62 } | 108 } |
| 63 | 109 |
| 64 void GLTestContext::submit() { | 110 void GLTestContext::submit() { |
| 65 if (fGL) { | 111 if (fGL) { |
| 66 GR_GL_CALL(fGL.get(), Flush()); | 112 GR_GL_CALL(fGL.get(), Flush()); |
| 67 } | 113 } |
| 68 } | 114 } |
| 69 | 115 |
| 70 void GLTestContext::finish() { | 116 void GLTestContext::finish() { |
| 71 if (fGL) { | 117 if (fGL) { |
| 72 GR_GL_CALL(fGL.get(), Finish()); | 118 GR_GL_CALL(fGL.get(), Finish()); |
| 73 } | 119 } |
| 74 } | 120 } |
| 75 | 121 |
| 76 GLTestContext::GLFenceSync* GLTestContext::GLFenceSync::CreateIfSupported(const
GLTestContext* ctx) { | |
| 77 SkAutoTDelete<GLFenceSync> ret(new GLFenceSync); | |
| 78 | |
| 79 if (kGL_GrGLStandard == ctx->gl()->fStandard) { | |
| 80 const GrGLubyte* versionStr; | |
| 81 GR_GL_CALL_RET(ctx->gl(), versionStr, GetString(GR_GL_VERSION)); | |
| 82 GrGLVersion version = GrGLGetVersionFromString(reinterpret_cast<const ch
ar*>(versionStr)); | |
| 83 if (version < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync"))
{ | |
| 84 return nullptr; | |
| 85 } | |
| 86 ret->fGLFenceSync = reinterpret_cast<GLFenceSyncProc>( | |
| 87 ctx->onPlatformGetProcAddress("glFenceSync")); | |
| 88 ret->fGLClientWaitSync = reinterpret_cast<GLClientWaitSyncProc>( | |
| 89 ctx->onPlatformGetProcAddress("glClientWaitSync")); | |
| 90 ret->fGLDeleteSync = reinterpret_cast<GLDeleteSyncProc>( | |
| 91 ctx->onPlatformGetProcAddress("glDeleteSync")); | |
| 92 } else { | |
| 93 if (!ctx->gl()->hasExtension("GL_APPLE_sync")) { | |
| 94 return nullptr; | |
| 95 } | |
| 96 ret->fGLFenceSync = reinterpret_cast<GLFenceSyncProc>( | |
| 97 ctx->onPlatformGetProcAddress("glFenceSyncAPPLE")); | |
| 98 ret->fGLClientWaitSync = reinterpret_cast<GLClientWaitSyncProc>( | |
| 99 ctx->onPlatformGetProcAddress("glClientWaitSyncAPPLE")); | |
| 100 ret->fGLDeleteSync = reinterpret_cast<GLDeleteSyncProc>( | |
| 101 ctx->onPlatformGetProcAddress("glDeleteSyncAPPLE")); | |
| 102 } | |
| 103 | |
| 104 if (!ret->fGLFenceSync || !ret->fGLClientWaitSync || !ret->fGLDeleteSync) { | |
| 105 return nullptr; | |
| 106 } | |
| 107 | |
| 108 return ret.release(); | |
| 109 } | |
| 110 | |
| 111 SkPlatformGpuFence GLTestContext::GLFenceSync::insertFence() const { | |
| 112 return fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); | |
| 113 } | |
| 114 | |
| 115 bool GLTestContext::GLFenceSync::waitFence(SkPlatformGpuFence fence) const { | |
| 116 GLsync glsync = static_cast<GLsync>(fence); | |
| 117 return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BI
T, -1); | |
| 118 } | |
| 119 | |
| 120 void GLTestContext::GLFenceSync::deleteFence(SkPlatformGpuFence fence) const { | |
| 121 GLsync glsync = static_cast<GLsync>(fence); | |
| 122 fGLDeleteSync(glsync); | |
| 123 } | |
| 124 | |
| 125 GrGLint GLTestContext::createTextureRectangle(int width, int height, GrGLenum in
ternalFormat, | 122 GrGLint GLTestContext::createTextureRectangle(int width, int height, GrGLenum in
ternalFormat, |
| 126 GrGLenum externalFormat, GrGLenum exte
rnalType, | 123 GrGLenum externalFormat, GrGLenum exte
rnalType, |
| 127 GrGLvoid* data) { | 124 GrGLvoid* data) { |
| 128 if (!(kGL_GrGLStandard == fGL->fStandard && GrGLGetVersion(fGL) >= GR_GL_VER
(3, 1)) && | 125 if (!(kGL_GrGLStandard == fGL->fStandard && GrGLGetVersion(fGL) >= GR_GL_VER
(3, 1)) && |
| 129 !fGL->fExtensions.has("GL_ARB_texture_rectangle")) { | 126 !fGL->fExtensions.has("GL_ARB_texture_rectangle")) { |
| 130 return 0; | 127 return 0; |
| 131 } | 128 } |
| 132 | 129 |
| 133 if (GrGLGetGLSLVersion(fGL) < GR_GLSL_VER(1, 40)) { | 130 if (GrGLGetGLSLVersion(fGL) < GR_GLSL_VER(1, 40)) { |
| 134 return 0; | 131 return 0; |
| 135 } | 132 } |
| 136 | 133 |
| 137 GrGLuint id; | 134 GrGLuint id; |
| 138 GR_GL_CALL(fGL, GenTextures(1, &id)); | 135 GR_GL_CALL(fGL, GenTextures(1, &id)); |
| 139 GR_GL_CALL(fGL, BindTexture(GR_GL_TEXTURE_RECTANGLE, id)); | 136 GR_GL_CALL(fGL, BindTexture(GR_GL_TEXTURE_RECTANGLE, id)); |
| 140 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MAG_FIL
TER, | 137 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MAG_FIL
TER, |
| 141 GR_GL_NEAREST)); | 138 GR_GL_NEAREST)); |
| 142 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FIL
TER, | 139 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FIL
TER, |
| 143 GR_GL_NEAREST)); | 140 GR_GL_NEAREST)); |
| 144 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, | 141 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, |
| 145 GR_GL_CLAMP_TO_EDGE)); | 142 GR_GL_CLAMP_TO_EDGE)); |
| 146 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, | 143 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, |
| 147 GR_GL_CLAMP_TO_EDGE)); | 144 GR_GL_CLAMP_TO_EDGE)); |
| 148 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width
, height, 0, | 145 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width
, height, 0, |
| 149 externalFormat, externalType, data)); | 146 externalFormat, externalType, data)); |
| 150 return id; | 147 return id; |
| 151 } | 148 } |
| 152 } // namespace sk_gpu_test | 149 } // namespace sk_gpu_test |
| OLD | NEW |