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