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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 << GetLastEGLErrorString(); | 105 << GetLastEGLErrorString(); |
106 return false; | 106 return false; |
107 } | 107 } |
108 | 108 |
109 SetCurrent(this, surface); | 109 SetCurrent(this, surface); |
110 if (!InitializeExtensionBindings()) { | 110 if (!InitializeExtensionBindings()) { |
111 ReleaseCurrent(surface); | 111 ReleaseCurrent(surface); |
112 return false; | 112 return false; |
113 } | 113 } |
114 | 114 |
| 115 if (!RecreateSurfaceIfNeeded(surface)) |
| 116 return false; |
| 117 |
115 if (!surface->OnMakeCurrent(this)) { | 118 if (!surface->OnMakeCurrent(this)) { |
116 LOG(ERROR) << "Could not make current."; | 119 LOG(ERROR) << "Could not make current."; |
117 return false; | 120 return false; |
118 } | 121 } |
119 | 122 |
120 SetRealGLApi(); | 123 SetRealGLApi(); |
121 return true; | 124 return true; |
122 } | 125 } |
123 | 126 |
| 127 bool GLContextEGL::RecreateSurfaceIfNeeded(GLSurface* surface) { |
| 128 if (!surface || !surface->RecreateOnMakeCurrent()) |
| 129 return true; |
| 130 |
| 131 // This is specifically needed for Vivante GPU's on Android. |
| 132 // A native view surface will not be configured correctly |
| 133 // unless we do all of the following steps after making the |
| 134 // surface current. |
| 135 GLint fbo = 0; |
| 136 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo); |
| 137 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| 138 |
| 139 eglMakeCurrent(display_, |
| 140 EGL_NO_SURFACE, |
| 141 EGL_NO_SURFACE, |
| 142 EGL_NO_CONTEXT); |
| 143 if (!surface->Recreate()) { |
| 144 LOG(ERROR) << "Failed to recreate surface"; |
| 145 return false; |
| 146 } |
| 147 if (!eglMakeCurrent(display_, |
| 148 surface->GetHandle(), |
| 149 surface->GetHandle(), |
| 150 context_)) { |
| 151 LOG(ERROR) << "eglMakeCurrent failed with error " |
| 152 << GetLastEGLErrorString(); |
| 153 return false; |
| 154 } |
| 155 |
| 156 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo); |
| 157 return true; |
| 158 } |
| 159 |
124 void GLContextEGL::ReleaseCurrent(GLSurface* surface) { | 160 void GLContextEGL::ReleaseCurrent(GLSurface* surface) { |
125 if (!IsCurrent(surface)) | 161 if (!IsCurrent(surface)) |
126 return; | 162 return; |
127 | 163 |
128 SetCurrent(NULL, NULL); | 164 SetCurrent(NULL, NULL); |
129 eglMakeCurrent(display_, | 165 eglMakeCurrent(display_, |
130 EGL_NO_SURFACE, | 166 EGL_NO_SURFACE, |
131 EGL_NO_SURFACE, | 167 EGL_NO_SURFACE, |
132 EGL_NO_CONTEXT); | 168 EGL_NO_CONTEXT); |
133 } | 169 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 220 |
185 #if !defined(OS_ANDROID) | 221 #if !defined(OS_ANDROID) |
186 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { | 222 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { |
187 DCHECK(bytes); | 223 DCHECK(bytes); |
188 *bytes = 0; | 224 *bytes = 0; |
189 return false; | 225 return false; |
190 } | 226 } |
191 #endif | 227 #endif |
192 | 228 |
193 } // namespace gfx | 229 } // namespace gfx |
OLD | NEW |