OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gl/gl_fence.h" | 5 #include "ui/gl/gl_fence.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "ui/gl/gl_bindings.h" | 8 #include "ui/gl/gl_bindings.h" |
9 #include "ui/gl/gl_context.h" | 9 #include "ui/gl/gl_context.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 // We will arbitrarily return TRUE for consistency. | 25 // We will arbitrarily return TRUE for consistency. |
26 glGenFencesNV(1, &fence_); | 26 glGenFencesNV(1, &fence_); |
27 glSetFenceNV(fence_, GL_ALL_COMPLETED_NV); | 27 glSetFenceNV(fence_, GL_ALL_COMPLETED_NV); |
28 glFlush(); | 28 glFlush(); |
29 } | 29 } |
30 | 30 |
31 virtual bool HasCompleted() OVERRIDE { | 31 virtual bool HasCompleted() OVERRIDE { |
32 return !!glTestFenceNV(fence_); | 32 return !!glTestFenceNV(fence_); |
33 } | 33 } |
34 | 34 |
| 35 virtual void ClientWait() OVERRIDE { |
| 36 glFinishFenceNV(fence_); |
| 37 } |
| 38 |
35 private: | 39 private: |
36 virtual ~GLFenceNVFence() { | 40 virtual ~GLFenceNVFence() { |
37 glDeleteFencesNV(1, &fence_); | 41 glDeleteFencesNV(1, &fence_); |
38 } | 42 } |
39 | 43 |
40 GLuint fence_; | 44 GLuint fence_; |
41 }; | 45 }; |
42 | 46 |
43 class GLFenceARBSync: public gfx::GLFence { | 47 class GLFenceARBSync: public gfx::GLFence { |
44 public: | 48 public: |
(...skipping 10 matching lines...) Expand all Loading... |
55 GLsizei length = 0; | 59 GLsizei length = 0; |
56 GLsizei value = 0; | 60 GLsizei value = 0; |
57 glGetSynciv(sync_, | 61 glGetSynciv(sync_, |
58 GL_SYNC_STATUS, | 62 GL_SYNC_STATUS, |
59 1, // bufSize | 63 1, // bufSize |
60 &length, | 64 &length, |
61 &value); | 65 &value); |
62 return length == 1 && value == GL_SIGNALED; | 66 return length == 1 && value == GL_SIGNALED; |
63 } | 67 } |
64 | 68 |
| 69 virtual void ClientWait() OVERRIDE { |
| 70 glClientWaitSync(sync_, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED); |
| 71 } |
| 72 |
65 private: | 73 private: |
66 virtual ~GLFenceARBSync() { | 74 virtual ~GLFenceARBSync() { |
67 glDeleteSync(sync_); | 75 glDeleteSync(sync_); |
68 } | 76 } |
69 | 77 |
70 GLsync sync_; | 78 GLsync sync_; |
71 }; | 79 }; |
72 | 80 |
| 81 #if !defined(OS_MACOSX) |
| 82 class EGLFenceSync : public gfx::GLFence { |
| 83 public: |
| 84 EGLFenceSync() { |
| 85 display_ = eglGetCurrentDisplay(); |
| 86 sync_ = eglCreateSyncKHR(display_, EGL_SYNC_FENCE_KHR, NULL); |
| 87 } |
| 88 |
| 89 virtual bool HasCompleted() OVERRIDE { |
| 90 EGLint value = 0; |
| 91 eglGetSyncAttribKHR(display_, sync_, EGL_SYNC_STATUS_KHR, &value); |
| 92 DCHECK(value == EGL_SIGNALED_KHR || value == EGL_UNSIGNALED_KHR); |
| 93 return !value || value == EGL_SIGNALED_KHR; |
| 94 } |
| 95 |
| 96 virtual void ClientWait() OVERRIDE { |
| 97 EGLint flags = EGL_SYNC_FLUSH_COMMANDS_BIT_KHR; |
| 98 EGLTimeKHR time = EGL_FOREVER_KHR; |
| 99 eglClientWaitSyncKHR(display_, sync_, flags, time); |
| 100 } |
| 101 |
| 102 private: |
| 103 virtual ~EGLFenceSync() { |
| 104 eglDestroySyncKHR(display_, sync_); |
| 105 } |
| 106 |
| 107 EGLSyncKHR sync_; |
| 108 EGLDisplay display_; |
| 109 }; |
| 110 #endif // !OS_MACOSX |
| 111 |
73 } // namespace | 112 } // namespace |
74 | 113 |
75 namespace gfx { | 114 namespace gfx { |
76 | 115 |
77 GLFence::GLFence() { | 116 GLFence::GLFence() { |
78 } | 117 } |
79 | 118 |
80 GLFence::~GLFence() { | 119 GLFence::~GLFence() { |
81 } | 120 } |
82 | 121 |
83 // static | 122 // static |
84 GLFence* GLFence::Create() { | 123 GLFence* GLFence::Create() { |
85 if (gfx::g_driver_gl.ext.b_GL_NV_fence) { | 124 #if !defined(OS_MACOSX) |
| 125 if (gfx::g_driver_egl.ext.b_EGL_KHR_fence_sync) |
| 126 return new EGLFenceSync(); |
| 127 #endif |
| 128 if (gfx::g_driver_gl.ext.b_GL_NV_fence) |
86 return new GLFenceNVFence(); | 129 return new GLFenceNVFence(); |
87 } else if (gfx::g_driver_gl.ext.b_GL_ARB_sync) { | 130 if (gfx::g_driver_gl.ext.b_GL_ARB_sync) |
88 return new GLFenceARBSync(); | 131 return new GLFenceARBSync(); |
89 } else { | 132 return NULL; |
90 return NULL; | |
91 } | |
92 } | 133 } |
93 | 134 |
94 } // namespace gfx | 135 } // namespace gfx |
OLD | NEW |