Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: tools/gpu/gl/GLTestContext.cpp

Issue 2383383002: Move GPU fences into sk_gpu_test (Closed)
Patch Set: Move GPU fences into sk_gpu_test Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
10 #include "GLFenceSync.h"
9 #include "gl/GrGLUtil.h" 11 #include "gl/GrGLUtil.h"
10 12
11 namespace sk_gpu_test { 13 namespace sk_gpu_test {
12 class GLTestContext::GLFenceSync : public SkGpuFenceSync {
13 public:
14 static GLFenceSync* CreateIfSupported(const GLTestContext*);
15
16 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override;
17 bool waitFence(SkPlatformGpuFence fence) const override;
18 void deleteFence(SkPlatformGpuFence fence) const override;
19
20 private:
21 GLFenceSync() {}
22
23 static const GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117;
24 static const GrGLenum GL_WAIT_FAILED = 0x911d;
25 static const GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001;
26
27 typedef struct __GLsync *GLsync;
28
29 typedef GLsync (GR_GL_FUNCTION_TYPE* GLFenceSyncProc) (GrGLenum, GrGLbitfiel d);
30 typedef GrGLenum (GR_GL_FUNCTION_TYPE* GLClientWaitSyncProc) (GLsync, GrGLbi tfield, GrGLuint64);
31 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GLDeleteSyncProc) (GLsync);
32
33 GLFenceSyncProc fGLFenceSync;
34 GLClientWaitSyncProc fGLClientWaitSync;
35 GLDeleteSyncProc fGLDeleteSync;
36
37 typedef SkGpuFenceSync INHERITED;
38 };
39 14
40 GLTestContext::GLTestContext() : TestContext() {} 15 GLTestContext::GLTestContext() : TestContext() {}
41 16
42 GLTestContext::~GLTestContext() { 17 GLTestContext::~GLTestContext() {
43 SkASSERT(nullptr == fGL.get()); 18 SkASSERT(nullptr == fGL.get());
44 } 19 }
45 20
46 void GLTestContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) { 21 void GLTestContext::init(const GrGLInterface* gl, FenceSync* fenceSync) {
47 SkASSERT(!fGL.get()); 22 SkASSERT(!fGL.get());
48 fGL.reset(gl); 23 fGL.reset(gl);
49 fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this); 24 fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this);
50 } 25 }
51 26
52 void GLTestContext::teardown() { 27 void GLTestContext::teardown() {
53 fGL.reset(nullptr); 28 fGL.reset(nullptr);
54 INHERITED::teardown(); 29 INHERITED::teardown();
55 } 30 }
56 31
57 void GLTestContext::testAbandon() { 32 void GLTestContext::testAbandon() {
58 INHERITED::testAbandon(); 33 INHERITED::testAbandon();
59 if (fGL) { 34 if (fGL) {
60 fGL->abandon(); 35 fGL->abandon();
61 } 36 }
62 } 37 }
63 38
64 void GLTestContext::submit() { 39 void GLTestContext::submit() {
65 if (fGL) { 40 if (fGL) {
66 GR_GL_CALL(fGL.get(), Flush()); 41 GR_GL_CALL(fGL.get(), Flush());
67 } 42 }
68 } 43 }
69 44
70 void GLTestContext::finish() { 45 void GLTestContext::finish() {
71 if (fGL) { 46 if (fGL) {
72 GR_GL_CALL(fGL.get(), Finish()); 47 GR_GL_CALL(fGL.get(), Finish());
73 } 48 }
74 } 49 }
75 50
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, 51 GrGLint GLTestContext::createTextureRectangle(int width, int height, GrGLenum in ternalFormat,
126 GrGLenum externalFormat, GrGLenum exte rnalType, 52 GrGLenum externalFormat, GrGLenum exte rnalType,
127 GrGLvoid* data) { 53 GrGLvoid* data) {
128 if (!(kGL_GrGLStandard == fGL->fStandard && GrGLGetVersion(fGL) >= GR_GL_VER (3, 1)) && 54 if (!(kGL_GrGLStandard == fGL->fStandard && GrGLGetVersion(fGL) >= GR_GL_VER (3, 1)) &&
129 !fGL->fExtensions.has("GL_ARB_texture_rectangle")) { 55 !fGL->fExtensions.has("GL_ARB_texture_rectangle")) {
130 return 0; 56 return 0;
131 } 57 }
132 58
133 if (GrGLGetGLSLVersion(fGL) < GR_GLSL_VER(1, 40)) { 59 if (GrGLGetGLSLVersion(fGL) < GR_GLSL_VER(1, 40)) {
134 return 0; 60 return 0;
135 } 61 }
136 62
137 GrGLuint id; 63 GrGLuint id;
138 GR_GL_CALL(fGL, GenTextures(1, &id)); 64 GR_GL_CALL(fGL, GenTextures(1, &id));
139 GR_GL_CALL(fGL, BindTexture(GR_GL_TEXTURE_RECTANGLE, id)); 65 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, 66 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MAG_FIL TER,
141 GR_GL_NEAREST)); 67 GR_GL_NEAREST));
142 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FIL TER, 68 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FIL TER,
143 GR_GL_NEAREST)); 69 GR_GL_NEAREST));
144 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, 70 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S,
145 GR_GL_CLAMP_TO_EDGE)); 71 GR_GL_CLAMP_TO_EDGE));
146 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, 72 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T,
147 GR_GL_CLAMP_TO_EDGE)); 73 GR_GL_CLAMP_TO_EDGE));
148 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width , height, 0, 74 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width , height, 0,
149 externalFormat, externalType, data)); 75 externalFormat, externalType, data));
150 return id; 76 return id;
151 } 77 }
152 } // namespace sk_gpu_test 78 } // namespace sk_gpu_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698