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 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 |
40 GLTestContext::GLTestContext() : TestContext() {} | 84 GLTestContext::GLTestContext() : TestContext() {} |
41 | 85 |
42 GLTestContext::~GLTestContext() { | 86 GLTestContext::~GLTestContext() { |
43 SkASSERT(nullptr == fGL.get()); | 87 SkASSERT(nullptr == fGL.get()); |
44 } | 88 } |
45 | 89 |
46 void GLTestContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) { | 90 void GLTestContext::init(const GrGLInterface* gl, FenceSync* fenceSync) { |
47 SkASSERT(!fGL.get()); | 91 SkASSERT(!fGL.get()); |
48 fGL.reset(gl); | 92 fGL.reset(gl); |
49 fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this); | 93 fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this); |
50 } | 94 } |
51 | 95 |
52 void GLTestContext::teardown() { | 96 void GLTestContext::teardown() { |
53 fGL.reset(nullptr); | 97 fGL.reset(nullptr); |
54 INHERITED::teardown(); | 98 INHERITED::teardown(); |
55 } | 99 } |
56 | 100 |
57 void GLTestContext::testAbandon() { | 101 void GLTestContext::testAbandon() { |
58 INHERITED::testAbandon(); | 102 INHERITED::testAbandon(); |
59 if (fGL) { | 103 if (fGL) { |
60 fGL->abandon(); | 104 fGL->abandon(); |
61 } | 105 } |
62 } | 106 } |
63 | 107 |
64 void GLTestContext::submit() { | 108 void GLTestContext::submit() { |
65 if (fGL) { | 109 if (fGL) { |
66 GR_GL_CALL(fGL.get(), Flush()); | 110 GR_GL_CALL(fGL.get(), Flush()); |
67 } | 111 } |
68 } | 112 } |
69 | 113 |
70 void GLTestContext::finish() { | 114 void GLTestContext::finish() { |
71 if (fGL) { | 115 if (fGL) { |
72 GR_GL_CALL(fGL.get(), Finish()); | 116 GR_GL_CALL(fGL.get(), Finish()); |
73 } | 117 } |
74 } | 118 } |
75 | 119 |
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, | 120 GrGLint GLTestContext::createTextureRectangle(int width, int height, GrGLenum in
ternalFormat, |
126 GrGLenum externalFormat, GrGLenum exte
rnalType, | 121 GrGLenum externalFormat, GrGLenum exte
rnalType, |
127 GrGLvoid* data) { | 122 GrGLvoid* data) { |
128 if (!(kGL_GrGLStandard == fGL->fStandard && GrGLGetVersion(fGL) >= GR_GL_VER
(3, 1)) && | 123 if (!(kGL_GrGLStandard == fGL->fStandard && GrGLGetVersion(fGL) >= GR_GL_VER
(3, 1)) && |
129 !fGL->fExtensions.has("GL_ARB_texture_rectangle")) { | 124 !fGL->fExtensions.has("GL_ARB_texture_rectangle")) { |
130 return 0; | 125 return 0; |
131 } | 126 } |
132 | 127 |
133 if (GrGLGetGLSLVersion(fGL) < GR_GLSL_VER(1, 40)) { | 128 if (GrGLGetGLSLVersion(fGL) < GR_GLSL_VER(1, 40)) { |
134 return 0; | 129 return 0; |
135 } | 130 } |
136 | 131 |
137 GrGLuint id; | 132 GrGLuint id; |
138 GR_GL_CALL(fGL, GenTextures(1, &id)); | 133 GR_GL_CALL(fGL, GenTextures(1, &id)); |
139 GR_GL_CALL(fGL, BindTexture(GR_GL_TEXTURE_RECTANGLE, id)); | 134 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, | 135 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MAG_FIL
TER, |
141 GR_GL_NEAREST)); | 136 GR_GL_NEAREST)); |
142 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FIL
TER, | 137 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FIL
TER, |
143 GR_GL_NEAREST)); | 138 GR_GL_NEAREST)); |
144 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, | 139 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, |
145 GR_GL_CLAMP_TO_EDGE)); | 140 GR_GL_CLAMP_TO_EDGE)); |
146 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, | 141 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, |
147 GR_GL_CLAMP_TO_EDGE)); | 142 GR_GL_CLAMP_TO_EDGE)); |
148 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width
, height, 0, | 143 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width
, height, 0, |
149 externalFormat, externalType, data)); | 144 externalFormat, externalType, data)); |
150 return id; | 145 return id; |
151 } | 146 } |
152 } // namespace sk_gpu_test | 147 } // namespace sk_gpu_test |
OLD | NEW |