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

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

Issue 1964243003: Add base class for GLTestContext and add new subclass VkTestContext. (Closed) Base URL: https://chromium.googlesource.com/skia.git@ContextInfo
Patch Set: move #include "GrVkBackendContext.h" inside #ifdef SK_VULKAN Created 4 years, 7 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
« no previous file with comments | « tools/gpu/gl/GLTestContext.h ('k') | tools/gpu/vk/VkTestContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1
2 /* 1 /*
3 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
4 * 3 *
5 * 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
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
7
8 #include "GLTestContext.h" 8 #include "GLTestContext.h"
9 #include "gl/GrGLUtil.h" 9 #include "gl/GrGLUtil.h"
10 #include "SkGpuFenceSync.h"
11 10
12 namespace sk_gpu_test { 11 namespace sk_gpu_test {
13 class GLTestContext::GLFenceSync : public SkGpuFenceSync { 12 class GLTestContext::GLFenceSync : public SkGpuFenceSync {
14 public: 13 public:
15 static GLFenceSync* CreateIfSupported(const GLTestContext*); 14 static GLFenceSync* CreateIfSupported(const GLTestContext*);
16 15
17 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; 16 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override;
18 bool waitFence(SkPlatformGpuFence fence, bool flush) const override; 17 bool waitFence(SkPlatformGpuFence fence, bool flush) const override;
19 void deleteFence(SkPlatformGpuFence fence) const override; 18 void deleteFence(SkPlatformGpuFence fence) const override;
20 19
(...skipping 10 matching lines...) Expand all
31 typedef GrGLenum (GR_GL_FUNCTION_TYPE* GLClientWaitSyncProc) (GLsync, GrGLbi tfield, GrGLuint64); 30 typedef GrGLenum (GR_GL_FUNCTION_TYPE* GLClientWaitSyncProc) (GLsync, GrGLbi tfield, GrGLuint64);
32 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GLDeleteSyncProc) (GLsync); 31 typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GLDeleteSyncProc) (GLsync);
33 32
34 GLFenceSyncProc fGLFenceSync; 33 GLFenceSyncProc fGLFenceSync;
35 GLClientWaitSyncProc fGLClientWaitSync; 34 GLClientWaitSyncProc fGLClientWaitSync;
36 GLDeleteSyncProc fGLDeleteSync; 35 GLDeleteSyncProc fGLDeleteSync;
37 36
38 typedef SkGpuFenceSync INHERITED; 37 typedef SkGpuFenceSync INHERITED;
39 }; 38 };
40 39
41 GLTestContext::GLTestContext() 40 GLTestContext::GLTestContext() : TestContext() {}
42 : fCurrentFenceIdx(0) {
43 memset(fFrameFences, 0, sizeof(fFrameFences));
44 }
45 41
46 GLTestContext::~GLTestContext() { 42 GLTestContext::~GLTestContext() {
47 // Subclass should call teardown.
48 #ifdef SK_DEBUG
49 for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) {
50 SkASSERT(0 == fFrameFences[i]);
51 }
52 #endif
53 SkASSERT(nullptr == fGL.get()); 43 SkASSERT(nullptr == fGL.get());
54 SkASSERT(nullptr == fFenceSync.get());
55 } 44 }
56 45
57 void GLTestContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) { 46 void GLTestContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) {
58 SkASSERT(!fGL.get()); 47 SkASSERT(!fGL.get());
59 fGL.reset(gl); 48 fGL.reset(gl);
60 fFenceSync.reset(fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this )); 49 fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this);
61 } 50 }
62 51
63 void GLTestContext::teardown() { 52 void GLTestContext::teardown() {
64 if (fFenceSync) {
65 for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) {
66 if (fFrameFences[i]) {
67 fFenceSync->deleteFence(fFrameFences[i]);
68 fFrameFences[i] = 0;
69 }
70 }
71 fFenceSync.reset(nullptr);
72 }
73
74 fGL.reset(nullptr); 53 fGL.reset(nullptr);
75 } 54 INHERITED::teardown();
76
77 void GLTestContext::makeCurrent() const {
78 this->onPlatformMakeCurrent();
79 }
80
81 void GLTestContext::swapBuffers() {
82 this->onPlatformSwapBuffers();
83 }
84
85 void GLTestContext::waitOnSyncOrSwap() {
86 if (!fFenceSync) {
87 // Fallback on the platform SwapBuffers method for synchronization. This may have no effect.
88 this->swapBuffers();
89 return;
90 }
91
92 if (fFrameFences[fCurrentFenceIdx]) {
93 if (!fFenceSync->waitFence(fFrameFences[fCurrentFenceIdx], true)) {
94 SkDebugf("WARNING: Wait failed for fence sync. Timings might not be accurate.\n");
95 }
96 fFenceSync->deleteFence(fFrameFences[fCurrentFenceIdx]);
97 }
98
99 fFrameFences[fCurrentFenceIdx] = fFenceSync->insertFence();
100 fCurrentFenceIdx = (fCurrentFenceIdx + 1) % SK_ARRAY_COUNT(fFrameFences);
101 } 55 }
102 56
103 void GLTestContext::testAbandon() { 57 void GLTestContext::testAbandon() {
58 INHERITED::testAbandon();
104 if (fGL) { 59 if (fGL) {
105 fGL->abandon(); 60 fGL->abandon();
106 } 61 }
107 if (fFenceSync) {
108 memset(fFrameFences, 0, sizeof(fFrameFences));
109 }
110 } 62 }
111 63
112 GLTestContext::GLFenceSync* GLTestContext::GLFenceSync::CreateIfSupported(const GLTestContext* ctx) { 64 GLTestContext::GLFenceSync* GLTestContext::GLFenceSync::CreateIfSupported(const GLTestContext* ctx) {
113 SkAutoTDelete<GLFenceSync> ret(new GLFenceSync); 65 SkAutoTDelete<GLFenceSync> ret(new GLFenceSync);
114 66
115 if (kGL_GrGLStandard == ctx->gl()->fStandard) { 67 if (kGL_GrGLStandard == ctx->gl()->fStandard) {
116 const GrGLubyte* versionStr; 68 const GrGLubyte* versionStr;
117 GR_GL_CALL_RET(ctx->gl(), versionStr, GetString(GR_GL_VERSION)); 69 GR_GL_CALL_RET(ctx->gl(), versionStr, GetString(GR_GL_VERSION));
118 GrGLVersion version = GrGLGetVersionFromString(reinterpret_cast<const ch ar*>(versionStr)); 70 GrGLVersion version = GrGLGetVersionFromString(reinterpret_cast<const ch ar*>(versionStr));
119 if (version < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) { 71 if (version < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 GR_GL_NEAREST)); 131 GR_GL_NEAREST));
180 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, 132 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S,
181 GR_GL_CLAMP_TO_EDGE)); 133 GR_GL_CLAMP_TO_EDGE));
182 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, 134 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T,
183 GR_GL_CLAMP_TO_EDGE)); 135 GR_GL_CLAMP_TO_EDGE));
184 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width , height, 0, 136 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width , height, 0,
185 externalFormat, externalType, data)); 137 externalFormat, externalType, data));
186 return id; 138 return id;
187 } 139 }
188 } // namespace sk_gpu_test 140 } // namespace sk_gpu_test
OLDNEW
« no previous file with comments | « tools/gpu/gl/GLTestContext.h ('k') | tools/gpu/vk/VkTestContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698