| 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" |
| 11 | 11 |
| 12 class SkGLContext::GLFenceSync : public SkGpuFenceSync { | 12 class SkGLContext::GLFenceSync : public SkGpuFenceSync { |
| 13 public: | 13 public: |
| 14 static GLFenceSync* CreateIfSupported(const SkGLContext*); | 14 static GLFenceSync* CreateIfSupported(const SkGLContext*); |
| 15 | 15 |
| 16 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; | 16 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; |
| 17 bool flushAndWaitFence(SkPlatformGpuFence fence) const override; | 17 bool waitFence(SkPlatformGpuFence fence, bool flush) const override; |
| 18 void deleteFence(SkPlatformGpuFence fence) const override; | 18 void deleteFence(SkPlatformGpuFence fence) const override; |
| 19 | 19 |
| 20 private: | 20 private: |
| 21 GLFenceSync() {} | 21 GLFenceSync() {} |
| 22 | 22 |
| 23 static const GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117; | 23 static const GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117; |
| 24 static const GrGLenum GL_WAIT_FAILED = 0x911d; | 24 static const GrGLenum GL_WAIT_FAILED = 0x911d; |
| 25 static const GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001; | 25 static const GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001; |
| 26 | 26 |
| 27 typedef struct __GLsync *GLsync; | 27 typedef struct __GLsync *GLsync; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(); |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 | 86 |
| 87 if (fFrameFences[fCurrentFenceIdx]) { | 87 if (fFrameFences[fCurrentFenceIdx]) { |
| 88 if (!fFenceSync->flushAndWaitFence(fFrameFences[fCurrentFenceIdx])) { | 88 if (!fFenceSync->waitFence(fFrameFences[fCurrentFenceIdx], true)) { |
| 89 SkDebugf("WARNING: Wait failed for fence sync. Timings might not be
accurate.\n"); | 89 SkDebugf("WARNING: Wait failed for fence sync. Timings might not be
accurate.\n"); |
| 90 } | 90 } |
| 91 fFenceSync->deleteFence(fFrameFences[fCurrentFenceIdx]); | 91 fFenceSync->deleteFence(fFrameFences[fCurrentFenceIdx]); |
| 92 } | 92 } |
| 93 | 93 |
| 94 fFrameFences[fCurrentFenceIdx] = fFenceSync->insertFence(); | 94 fFrameFences[fCurrentFenceIdx] = fFenceSync->insertFence(); |
| 95 fCurrentFenceIdx = (fCurrentFenceIdx + 1) % SK_ARRAY_COUNT(fFrameFences); | 95 fCurrentFenceIdx = (fCurrentFenceIdx + 1) % SK_ARRAY_COUNT(fFrameFences); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void SkGLContext::testAbandon() { | 98 void SkGLContext::testAbandon() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return nullptr; | 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::waitFence(SkPlatformGpuFence fence, bool flush) c
onst { |
| 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, flush ? GL_SYNC_FLUSH_COM
MANDS_BIT : 0, -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 } |
| 155 | 155 |
| 156 GrGLint SkGLContext::createTextureRectangle(int width, int height, GrGLenum inte
rnalFormat, | 156 GrGLint SkGLContext::createTextureRectangle(int width, int height, GrGLenum inte
rnalFormat, |
| 157 GrGLenum externalFormat, GrGLenum ex
ternalType, | 157 GrGLenum externalFormat, GrGLenum ex
ternalType, |
| 158 GrGLvoid* data) { | 158 GrGLvoid* data) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 173 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FIL
TER, | 173 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FIL
TER, |
| 174 GR_GL_NEAREST)); | 174 GR_GL_NEAREST)); |
| 175 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, | 175 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, |
| 176 GR_GL_CLAMP_TO_EDGE)); | 176 GR_GL_CLAMP_TO_EDGE)); |
| 177 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, | 177 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, |
| 178 GR_GL_CLAMP_TO_EDGE)); | 178 GR_GL_CLAMP_TO_EDGE)); |
| 179 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width
, height, 0, | 179 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width
, height, 0, |
| 180 externalFormat, externalType, data)); | 180 externalFormat, externalType, data)); |
| 181 return id; | 181 return id; |
| 182 } | 182 } |
| OLD | NEW |