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_context_egl.h" | 5 #include "ui/gl/gl_context_egl.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 using ui::GetLastEGLErrorString; | 23 using ui::GetLastEGLErrorString; |
24 | 24 |
25 namespace gfx { | 25 namespace gfx { |
26 | 26 |
27 GLContextEGL::GLContextEGL(GLShareGroup* share_group) | 27 GLContextEGL::GLContextEGL(GLShareGroup* share_group) |
28 : GLContextReal(share_group), | 28 : GLContextReal(share_group), |
29 context_(NULL), | 29 context_(NULL), |
30 display_(NULL), | 30 display_(NULL), |
31 config_(NULL), | 31 config_(NULL), |
32 unbind_fbo_on_makecurrent_(false) { | 32 unbind_fbo_on_makecurrent_(false), |
| 33 swap_interval_(1) { |
33 } | 34 } |
34 | 35 |
35 bool GLContextEGL::Initialize( | 36 bool GLContextEGL::Initialize( |
36 GLSurface* compatible_surface, GpuPreference gpu_preference) { | 37 GLSurface* compatible_surface, GpuPreference gpu_preference) { |
37 DCHECK(compatible_surface); | 38 DCHECK(compatible_surface); |
38 DCHECK(!context_); | 39 DCHECK(!context_); |
39 | 40 |
40 static const EGLint kContextAttributes[] = { | 41 static const EGLint kContextAttributes[] = { |
41 EGL_CONTEXT_CLIENT_VERSION, 2, | 42 EGL_CONTEXT_CLIENT_VERSION, 2, |
42 EGL_NONE | 43 EGL_NONE |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 SetCurrent(surface); | 119 SetCurrent(surface); |
119 if (!InitializeDynamicBindings()) { | 120 if (!InitializeDynamicBindings()) { |
120 return false; | 121 return false; |
121 } | 122 } |
122 | 123 |
123 if (!surface->OnMakeCurrent(this)) { | 124 if (!surface->OnMakeCurrent(this)) { |
124 LOG(ERROR) << "Could not make current."; | 125 LOG(ERROR) << "Could not make current."; |
125 return false; | 126 return false; |
126 } | 127 } |
127 | 128 |
| 129 surface->OnSetSwapInterval(swap_interval_); |
| 130 |
128 release_current.Cancel(); | 131 release_current.Cancel(); |
129 return true; | 132 return true; |
130 } | 133 } |
131 | 134 |
132 void GLContextEGL::SetUnbindFboOnMakeCurrent() { | 135 void GLContextEGL::SetUnbindFboOnMakeCurrent() { |
133 unbind_fbo_on_makecurrent_ = true; | 136 unbind_fbo_on_makecurrent_ = true; |
134 } | 137 } |
135 | 138 |
136 void GLContextEGL::ReleaseCurrent(GLSurface* surface) { | 139 void GLContextEGL::ReleaseCurrent(GLSurface* surface) { |
137 if (!IsCurrent(surface)) | 140 if (!IsCurrent(surface)) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 DCHECK(IsCurrent(NULL) && GLSurface::GetCurrent()); | 179 DCHECK(IsCurrent(NULL) && GLSurface::GetCurrent()); |
177 | 180 |
178 // This is a surfaceless context. eglSwapInterval doesn't take any effect in | 181 // This is a surfaceless context. eglSwapInterval doesn't take any effect in |
179 // this case and will just return EGL_BAD_SURFACE. | 182 // this case and will just return EGL_BAD_SURFACE. |
180 if (GLSurface::GetCurrent()->IsSurfaceless()) | 183 if (GLSurface::GetCurrent()->IsSurfaceless()) |
181 return; | 184 return; |
182 | 185 |
183 if (!eglSwapInterval(display_, interval)) { | 186 if (!eglSwapInterval(display_, interval)) { |
184 LOG(ERROR) << "eglSwapInterval failed with error " | 187 LOG(ERROR) << "eglSwapInterval failed with error " |
185 << GetLastEGLErrorString(); | 188 << GetLastEGLErrorString(); |
| 189 } else { |
| 190 swap_interval_ = interval; |
| 191 GLSurface::GetCurrent()->OnSetSwapInterval(interval); |
186 } | 192 } |
187 } | 193 } |
188 | 194 |
189 std::string GLContextEGL::GetExtensions() { | 195 std::string GLContextEGL::GetExtensions() { |
190 const char* extensions = eglQueryString(display_, | 196 const char* extensions = eglQueryString(display_, |
191 EGL_EXTENSIONS); | 197 EGL_EXTENSIONS); |
192 if (!extensions) | 198 if (!extensions) |
193 return GLContext::GetExtensions(); | 199 return GLContext::GetExtensions(); |
194 | 200 |
195 return GLContext::GetExtensions() + " " + extensions; | 201 return GLContext::GetExtensions() + " " + extensions; |
196 } | 202 } |
197 | 203 |
198 bool GLContextEGL::WasAllocatedUsingRobustnessExtension() { | 204 bool GLContextEGL::WasAllocatedUsingRobustnessExtension() { |
199 return GLSurfaceEGL::IsCreateContextRobustnessSupported(); | 205 return GLSurfaceEGL::IsCreateContextRobustnessSupported(); |
200 } | 206 } |
201 | 207 |
202 GLContextEGL::~GLContextEGL() { | 208 GLContextEGL::~GLContextEGL() { |
203 Destroy(); | 209 Destroy(); |
204 } | 210 } |
205 | 211 |
206 #if !defined(OS_ANDROID) | 212 #if !defined(OS_ANDROID) |
207 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { | 213 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { |
208 DCHECK(bytes); | 214 DCHECK(bytes); |
209 *bytes = 0; | 215 *bytes = 0; |
210 return false; | 216 return false; |
211 } | 217 } |
212 #endif | 218 #endif |
213 | 219 |
214 } // namespace gfx | 220 } // namespace gfx |
OLD | NEW |