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

Side by Side Diff: ui/gl/gl_fence.cc

Issue 14358014: gpu: Add EGL fence support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Mac (it doesn't include EGL). Created 7 years, 6 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 | « ui/gl/gl_fence.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « ui/gl/gl_fence.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698