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 10 matching lines...) Expand all Loading... |
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 : GLContext(share_group), |
29 context_(NULL), | 29 context_(NULL), |
30 display_(NULL), | 30 display_(NULL), |
31 config_(NULL) { | 31 config_(NULL), |
| 32 recreate_surface_on_makecurrent_(false) { |
32 } | 33 } |
33 | 34 |
34 bool GLContextEGL::Initialize( | 35 bool GLContextEGL::Initialize( |
35 GLSurface* compatible_surface, GpuPreference gpu_preference) { | 36 GLSurface* compatible_surface, GpuPreference gpu_preference) { |
36 DCHECK(compatible_surface); | 37 DCHECK(compatible_surface); |
37 DCHECK(!context_); | 38 DCHECK(!context_); |
38 | 39 |
39 static const EGLint kContextAttributes[] = { | 40 static const EGLint kContextAttributes[] = { |
40 EGL_CONTEXT_CLIENT_VERSION, 2, | 41 EGL_CONTEXT_CLIENT_VERSION, 2, |
41 EGL_NONE | 42 EGL_NONE |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 << GetLastEGLErrorString(); | 106 << GetLastEGLErrorString(); |
106 return false; | 107 return false; |
107 } | 108 } |
108 | 109 |
109 SetCurrent(this, surface); | 110 SetCurrent(this, surface); |
110 if (!InitializeExtensionBindings()) { | 111 if (!InitializeExtensionBindings()) { |
111 ReleaseCurrent(surface); | 112 ReleaseCurrent(surface); |
112 return false; | 113 return false; |
113 } | 114 } |
114 | 115 |
| 116 #if defined(OS_ANDROID) |
| 117 if (!RecreateSurfaceIfNeeded(surface)) |
| 118 return false; |
| 119 #endif |
| 120 |
115 if (!surface->OnMakeCurrent(this)) { | 121 if (!surface->OnMakeCurrent(this)) { |
116 LOG(ERROR) << "Could not make current."; | 122 LOG(ERROR) << "Could not make current."; |
117 return false; | 123 return false; |
118 } | 124 } |
119 | 125 |
120 SetRealGLApi(); | 126 SetRealGLApi(); |
121 return true; | 127 return true; |
122 } | 128 } |
123 | 129 |
| 130 void GLContextEGL::SetRecreateSurfaceOnMakeCurrent() { |
| 131 recreate_surface_on_makecurrent_ = true; |
| 132 } |
| 133 |
| 134 bool GLContextEGL::RecreateSurfaceIfNeeded(GLSurface* surface) { |
| 135 if (!recreate_surface_on_makecurrent_ || |
| 136 !surface || |
| 137 surface->IsOffscreen() || |
| 138 surface->GetBackingFrameBufferObject()) |
| 139 return true; |
| 140 |
| 141 // This is specifically needed for Vivante GPU's on Android. |
| 142 // A native view surface will not be configured correctly |
| 143 // unless we do all of the following steps after making the |
| 144 // surface current. |
| 145 GLint fbo = 0; |
| 146 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo); |
| 147 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| 148 |
| 149 eglMakeCurrent(display_, |
| 150 EGL_NO_SURFACE, |
| 151 EGL_NO_SURFACE, |
| 152 EGL_NO_CONTEXT); |
| 153 if (!surface->Recreate()) { |
| 154 LOG(ERROR) << "Failed to recreate surface"; |
| 155 return false; |
| 156 } |
| 157 if (!eglMakeCurrent(display_, |
| 158 surface->GetHandle(), |
| 159 surface->GetHandle(), |
| 160 context_)) { |
| 161 LOG(ERROR) << "eglMakeCurrent failed with error " |
| 162 << GetLastEGLErrorString(); |
| 163 return false; |
| 164 } |
| 165 |
| 166 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo); |
| 167 return true; |
| 168 } |
| 169 |
124 void GLContextEGL::ReleaseCurrent(GLSurface* surface) { | 170 void GLContextEGL::ReleaseCurrent(GLSurface* surface) { |
125 if (!IsCurrent(surface)) | 171 if (!IsCurrent(surface)) |
126 return; | 172 return; |
127 | 173 |
128 SetCurrent(NULL, NULL); | 174 SetCurrent(NULL, NULL); |
129 eglMakeCurrent(display_, | 175 eglMakeCurrent(display_, |
130 EGL_NO_SURFACE, | 176 EGL_NO_SURFACE, |
131 EGL_NO_SURFACE, | 177 EGL_NO_SURFACE, |
132 EGL_NO_CONTEXT); | 178 EGL_NO_CONTEXT); |
133 } | 179 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 230 |
185 #if !defined(OS_ANDROID) | 231 #if !defined(OS_ANDROID) |
186 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { | 232 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { |
187 DCHECK(bytes); | 233 DCHECK(bytes); |
188 *bytes = 0; | 234 *bytes = 0; |
189 return false; | 235 return false; |
190 } | 236 } |
191 #endif | 237 #endif |
192 | 238 |
193 } // namespace gfx | 239 } // namespace gfx |
OLD | NEW |