OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "gl/SkGLContext.h" | 8 #include "gl/SkGLContext.h" |
9 #include "GrGLUtil.h" | 9 #include "GrGLUtil.h" |
10 #include "SkGpuFenceSync.h" | 10 #include "SkGpuFenceSync.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 memset(fFrameFences, 0, sizeof(fFrameFences)); | 42 memset(fFrameFences, 0, sizeof(fFrameFences)); |
43 } | 43 } |
44 | 44 |
45 SkGLContext::~SkGLContext() { | 45 SkGLContext::~SkGLContext() { |
46 // Subclass should call teardown. | 46 // Subclass should call teardown. |
47 #ifdef SK_DEBUG | 47 #ifdef SK_DEBUG |
48 for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) { | 48 for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) { |
49 SkASSERT(0 == fFrameFences[i]); | 49 SkASSERT(0 == fFrameFences[i]); |
50 } | 50 } |
51 #endif | 51 #endif |
52 SkASSERT(NULL == fGL.get()); | 52 SkASSERT(nullptr == fGL.get()); |
53 SkASSERT(NULL == fFenceSync.get()); | 53 SkASSERT(nullptr == fFenceSync.get()); |
54 } | 54 } |
55 | 55 |
56 void SkGLContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) { | 56 void SkGLContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) { |
57 SkASSERT(!fGL.get()); | 57 SkASSERT(!fGL.get()); |
58 fGL.reset(gl); | 58 fGL.reset(gl); |
59 fFenceSync.reset(fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this
)); | 59 fFenceSync.reset(fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this
)); |
60 } | 60 } |
61 | 61 |
62 void SkGLContext::teardown() { | 62 void SkGLContext::teardown() { |
63 if (fFenceSync) { | 63 if (fFenceSync) { |
64 for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) { | 64 for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) { |
65 if (fFrameFences[i]) { | 65 if (fFrameFences[i]) { |
66 fFenceSync->deleteFence(fFrameFences[i]); | 66 fFenceSync->deleteFence(fFrameFences[i]); |
67 fFrameFences[i] = 0; | 67 fFrameFences[i] = 0; |
68 } | 68 } |
69 } | 69 } |
70 fFenceSync.reset(NULL); | 70 fFenceSync.reset(nullptr); |
71 } | 71 } |
72 | 72 |
73 fGL.reset(NULL); | 73 fGL.reset(nullptr); |
74 } | 74 } |
75 | 75 |
76 void SkGLContext::makeCurrent() const { | 76 void SkGLContext::makeCurrent() const { |
77 this->onPlatformMakeCurrent(); | 77 this->onPlatformMakeCurrent(); |
78 } | 78 } |
79 | 79 |
80 void SkGLContext::swapBuffers() { | 80 void SkGLContext::swapBuffers() { |
81 if (!fFenceSync) { | 81 if (!fFenceSync) { |
82 // Fallback on the platform SwapBuffers method for synchronization. This
may have no effect. | 82 // Fallback on the platform SwapBuffers method for synchronization. This
may have no effect. |
83 this->onPlatformSwapBuffers(); | 83 this->onPlatformSwapBuffers(); |
(...skipping 21 matching lines...) Expand all Loading... |
105 } | 105 } |
106 | 106 |
107 SkGLContext::GLFenceSync* SkGLContext::GLFenceSync::CreateIfSupported(const SkGL
Context* ctx) { | 107 SkGLContext::GLFenceSync* SkGLContext::GLFenceSync::CreateIfSupported(const SkGL
Context* ctx) { |
108 SkAutoTDelete<GLFenceSync> ret(new GLFenceSync); | 108 SkAutoTDelete<GLFenceSync> ret(new GLFenceSync); |
109 | 109 |
110 if (kGL_GrGLStandard == ctx->gl()->fStandard) { | 110 if (kGL_GrGLStandard == ctx->gl()->fStandard) { |
111 const GrGLubyte* versionStr; | 111 const GrGLubyte* versionStr; |
112 SK_GL_RET(*ctx, versionStr, GetString(GR_GL_VERSION)); | 112 SK_GL_RET(*ctx, versionStr, GetString(GR_GL_VERSION)); |
113 GrGLVersion version = GrGLGetVersionFromString(reinterpret_cast<const ch
ar*>(versionStr)); | 113 GrGLVersion version = GrGLGetVersionFromString(reinterpret_cast<const ch
ar*>(versionStr)); |
114 if (version < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync"))
{ | 114 if (version < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync"))
{ |
115 return NULL; | 115 return nullptr; |
116 } | 116 } |
117 ret->fGLFenceSync = reinterpret_cast<GLFenceSyncProc>( | 117 ret->fGLFenceSync = reinterpret_cast<GLFenceSyncProc>( |
118 ctx->onPlatformGetProcAddress("glFenceSync")); | 118 ctx->onPlatformGetProcAddress("glFenceSync")); |
119 ret->fGLClientWaitSync = reinterpret_cast<GLClientWaitSyncProc>( | 119 ret->fGLClientWaitSync = reinterpret_cast<GLClientWaitSyncProc>( |
120 ctx->onPlatformGetProcAddress("glClientWaitSync")); | 120 ctx->onPlatformGetProcAddress("glClientWaitSync")); |
121 ret->fGLDeleteSync = reinterpret_cast<GLDeleteSyncProc>( | 121 ret->fGLDeleteSync = reinterpret_cast<GLDeleteSyncProc>( |
122 ctx->onPlatformGetProcAddress("glDeleteSync")); | 122 ctx->onPlatformGetProcAddress("glDeleteSync")); |
123 } else { | 123 } else { |
124 if (!ctx->gl()->hasExtension("GL_APPLE_sync")) { | 124 if (!ctx->gl()->hasExtension("GL_APPLE_sync")) { |
125 return NULL; | 125 return nullptr; |
126 } | 126 } |
127 ret->fGLFenceSync = reinterpret_cast<GLFenceSyncProc>( | 127 ret->fGLFenceSync = reinterpret_cast<GLFenceSyncProc>( |
128 ctx->onPlatformGetProcAddress("glFenceSyncAPPLE")); | 128 ctx->onPlatformGetProcAddress("glFenceSyncAPPLE")); |
129 ret->fGLClientWaitSync = reinterpret_cast<GLClientWaitSyncProc>( | 129 ret->fGLClientWaitSync = reinterpret_cast<GLClientWaitSyncProc>( |
130 ctx->onPlatformGetProcAddress("glClientWaitSyncAPPLE")); | 130 ctx->onPlatformGetProcAddress("glClientWaitSyncAPPLE")); |
131 ret->fGLDeleteSync = reinterpret_cast<GLDeleteSyncProc>( | 131 ret->fGLDeleteSync = reinterpret_cast<GLDeleteSyncProc>( |
132 ctx->onPlatformGetProcAddress("glDeleteSyncAPPLE")); | 132 ctx->onPlatformGetProcAddress("glDeleteSyncAPPLE")); |
133 } | 133 } |
134 | 134 |
135 if (!ret->fGLFenceSync || !ret->fGLClientWaitSync || !ret->fGLDeleteSync) { | 135 if (!ret->fGLFenceSync || !ret->fGLClientWaitSync || !ret->fGLDeleteSync) { |
136 return NULL; | 136 return nullptr; |
137 } | 137 } |
138 | 138 |
139 return ret.detach(); | 139 return ret.detach(); |
140 } | 140 } |
141 | 141 |
142 SkPlatformGpuFence SkGLContext::GLFenceSync::insertFence() const { | 142 SkPlatformGpuFence SkGLContext::GLFenceSync::insertFence() const { |
143 return fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); | 143 return fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); |
144 } | 144 } |
145 | 145 |
146 bool SkGLContext::GLFenceSync::flushAndWaitFence(SkPlatformGpuFence fence) const
{ | 146 bool SkGLContext::GLFenceSync::flushAndWaitFence(SkPlatformGpuFence fence) const
{ |
147 GLsync glsync = static_cast<GLsync>(fence); | 147 GLsync glsync = static_cast<GLsync>(fence); |
148 return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BI
T, -1); | 148 return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BI
T, -1); |
149 } | 149 } |
150 | 150 |
151 void SkGLContext::GLFenceSync::deleteFence(SkPlatformGpuFence fence) const { | 151 void SkGLContext::GLFenceSync::deleteFence(SkPlatformGpuFence fence) const { |
152 GLsync glsync = static_cast<GLsync>(fence); | 152 GLsync glsync = static_cast<GLsync>(fence); |
153 fGLDeleteSync(glsync); | 153 fGLDeleteSync(glsync); |
154 } | 154 } |
OLD | NEW |