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" |
11 #include "third_party/khronos/EGL/egl.h" | 11 #include "third_party/khronos/EGL/egl.h" |
12 #include "third_party/khronos/EGL/eglext.h" | 12 #include "third_party/khronos/EGL/eglext.h" |
13 #include "ui/gl/egl_util.h" | 13 #include "ui/gl/egl_util.h" |
14 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
15 #include "ui/gl/gl_surface_egl.h" | 15 #include "ui/gl/gl_surface_egl.h" |
16 | 16 |
17 #if defined(USE_X11) | 17 #if defined(USE_X11) |
18 extern "C" { | 18 extern "C" { |
19 #include <X11/Xlib.h> | 19 #include <X11/Xlib.h> |
20 } | 20 } |
21 #endif | 21 #endif |
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 : GLContext(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 } | 33 } |
34 | 34 |
35 bool GLContextEGL::Initialize( | 35 bool GLContextEGL::Initialize( |
36 GLSurface* compatible_surface, GpuPreference gpu_preference) { | 36 GLSurface* compatible_surface, GpuPreference gpu_preference) { |
37 DCHECK(compatible_surface); | 37 DCHECK(compatible_surface); |
38 DCHECK(!context_); | 38 DCHECK(!context_); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 if (!eglMakeCurrent(display_, | 106 if (!eglMakeCurrent(display_, |
107 surface->GetHandle(), | 107 surface->GetHandle(), |
108 surface->GetHandle(), | 108 surface->GetHandle(), |
109 context_)) { | 109 context_)) { |
110 DVLOG(1) << "eglMakeCurrent failed with error " | 110 DVLOG(1) << "eglMakeCurrent failed with error " |
111 << GetLastEGLErrorString(); | 111 << GetLastEGLErrorString(); |
112 return false; | 112 return false; |
113 } | 113 } |
114 | 114 |
115 SetCurrent(this, surface); | 115 SetCurrent(surface); |
116 if (!InitializeExtensionBindings()) { | 116 if (!InitializeExtensionBindings()) { |
117 ReleaseCurrent(surface); | 117 ReleaseCurrent(surface); |
118 return false; | 118 return false; |
119 } | 119 } |
120 | 120 |
121 if (!surface->OnMakeCurrent(this)) { | 121 if (!surface->OnMakeCurrent(this)) { |
122 LOG(ERROR) << "Could not make current."; | 122 LOG(ERROR) << "Could not make current."; |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 SetRealGLApi(); | 126 SetRealGLApi(); |
127 return true; | 127 return true; |
128 } | 128 } |
129 | 129 |
130 void GLContextEGL::SetUnbindFboOnMakeCurrent() { | 130 void GLContextEGL::SetUnbindFboOnMakeCurrent() { |
131 unbind_fbo_on_makecurrent_ = true; | 131 unbind_fbo_on_makecurrent_ = true; |
132 } | 132 } |
133 | 133 |
134 void GLContextEGL::ReleaseCurrent(GLSurface* surface) { | 134 void GLContextEGL::ReleaseCurrent(GLSurface* surface) { |
135 if (!IsCurrent(surface)) | 135 if (!IsCurrent(surface)) |
136 return; | 136 return; |
137 | 137 |
138 if (unbind_fbo_on_makecurrent_) | 138 if (unbind_fbo_on_makecurrent_) |
139 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 139 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
140 | 140 |
141 SetCurrent(NULL, NULL); | 141 SetCurrent(NULL); |
142 eglMakeCurrent(display_, | 142 eglMakeCurrent(display_, |
143 EGL_NO_SURFACE, | 143 EGL_NO_SURFACE, |
144 EGL_NO_SURFACE, | 144 EGL_NO_SURFACE, |
145 EGL_NO_CONTEXT); | 145 EGL_NO_CONTEXT); |
146 } | 146 } |
147 | 147 |
148 bool GLContextEGL::IsCurrent(GLSurface* surface) { | 148 bool GLContextEGL::IsCurrent(GLSurface* surface) { |
149 DCHECK(context_); | 149 DCHECK(context_); |
150 | 150 |
151 bool native_context_is_current = context_ == eglGetCurrentContext(); | 151 bool native_context_is_current = context_ == eglGetCurrentContext(); |
152 | 152 |
153 // If our context is current then our notion of which GLContext is | 153 // If our context is current then our notion of which GLContext is |
154 // current must be correct. On the other hand, third-party code | 154 // current must be correct. On the other hand, third-party code |
155 // using OpenGL might change the current context. | 155 // using OpenGL might change the current context. |
156 DCHECK(!native_context_is_current || (GetCurrent() == this)); | 156 DCHECK(!native_context_is_current || (GetRealCurrent() == this)); |
157 | 157 |
158 if (!native_context_is_current) | 158 if (!native_context_is_current) |
159 return false; | 159 return false; |
160 | 160 |
161 if (surface) { | 161 if (surface) { |
162 if (surface->GetHandle() != eglGetCurrentSurface(EGL_DRAW)) | 162 if (surface->GetHandle() != eglGetCurrentSurface(EGL_DRAW)) |
163 return false; | 163 return false; |
164 } | 164 } |
165 | 165 |
166 return true; | 166 return true; |
(...skipping 30 matching lines...) Expand all Loading... |
197 | 197 |
198 #if !defined(OS_ANDROID) | 198 #if !defined(OS_ANDROID) |
199 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { | 199 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { |
200 DCHECK(bytes); | 200 DCHECK(bytes); |
201 *bytes = 0; | 201 *bytes = 0; |
202 return false; | 202 return false; |
203 } | 203 } |
204 #endif | 204 #endif |
205 | 205 |
206 } // namespace gfx | 206 } // namespace gfx |
OLD | NEW |