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