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.h" | 5 #include "ui/gl/gl_context.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 GetCurrent()->ReleaseCurrent(nullptr); | 39 GetCurrent()->ReleaseCurrent(nullptr); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 void GLContext::ScopedReleaseCurrent::Cancel() { | 43 void GLContext::ScopedReleaseCurrent::Cancel() { |
44 canceled_ = true; | 44 canceled_ = true; |
45 } | 45 } |
46 | 46 |
47 GLContext::GLContext(GLShareGroup* share_group) | 47 GLContext::GLContext(GLShareGroup* share_group) |
48 : share_group_(share_group), | 48 : share_group_(share_group), |
| 49 current_virtual_context_(nullptr), |
49 state_dirtied_externally_(false), | 50 state_dirtied_externally_(false), |
50 swap_interval_(1), | 51 swap_interval_(1), |
51 force_swap_interval_zero_(false) { | 52 force_swap_interval_zero_(false) { |
52 if (!share_group_.get()) | 53 if (!share_group_.get()) |
53 share_group_ = new GLShareGroup; | 54 share_group_ = new GLShareGroup; |
54 | 55 |
55 share_group_->AddContext(this); | 56 share_group_->AddContext(this); |
56 } | 57 } |
57 | 58 |
58 GLContext::~GLContext() { | 59 GLContext::~GLContext() { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 180 } |
180 | 181 |
181 bool GLContext::InitializeDynamicBindings() { | 182 bool GLContext::InitializeDynamicBindings() { |
182 DCHECK(IsCurrent(nullptr)); | 183 DCHECK(IsCurrent(nullptr)); |
183 bool initialized = InitializeDynamicGLBindings(GetGLImplementation(), this); | 184 bool initialized = InitializeDynamicGLBindings(GetGLImplementation(), this); |
184 if (!initialized) | 185 if (!initialized) |
185 LOG(ERROR) << "Could not initialize dynamic bindings."; | 186 LOG(ERROR) << "Could not initialize dynamic bindings."; |
186 return initialized; | 187 return initialized; |
187 } | 188 } |
188 | 189 |
189 void GLContext::SetupForVirtualization() { | |
190 if (!virtual_gl_api_) { | |
191 virtual_gl_api_.reset(new VirtualGLApi()); | |
192 virtual_gl_api_->Initialize(&g_driver_gl, this); | |
193 } | |
194 } | |
195 | |
196 bool GLContext::MakeVirtuallyCurrent( | 190 bool GLContext::MakeVirtuallyCurrent( |
197 GLContext* virtual_context, GLSurface* surface) { | 191 GLContext* virtual_context, GLSurface* surface) { |
198 DCHECK(virtual_gl_api_); | |
199 if (!ForceGpuSwitchIfNeeded()) | 192 if (!ForceGpuSwitchIfNeeded()) |
200 return false; | 193 return false; |
201 return virtual_gl_api_->MakeCurrent(virtual_context, surface); | 194 bool switched_real_contexts = GLContext::GetRealCurrent() != this; |
| 195 GLSurface* current_surface = GLSurface::GetCurrent(); |
| 196 if (switched_real_contexts || surface != current_surface) { |
| 197 // MakeCurrent 'lite' path that avoids potentially expensive MakeCurrent() |
| 198 // calls if the GLSurface uses the same underlying surface or renders to |
| 199 // an FBO. |
| 200 if (switched_real_contexts || !current_surface || |
| 201 !virtual_context->IsCurrent(surface)) { |
| 202 if (!MakeCurrent(surface)) { |
| 203 return false; |
| 204 } |
| 205 } |
| 206 } |
| 207 |
| 208 DCHECK_EQ(this, GLContext::GetRealCurrent()); |
| 209 DCHECK(IsCurrent(NULL)); |
| 210 DCHECK(virtual_context->IsCurrent(surface)); |
| 211 |
| 212 if (switched_real_contexts || virtual_context != current_virtual_context_) { |
| 213 #if DCHECK_IS_ON() |
| 214 GLenum error = glGetError(); |
| 215 // Accepting a context loss error here enables using debug mode to work on |
| 216 // context loss handling in virtual context mode. |
| 217 // There should be no other errors from the previous context leaking into |
| 218 // the new context. |
| 219 DCHECK(error == GL_NO_ERROR || error == GL_CONTEXT_LOST_KHR) << |
| 220 "GL error was: " << error; |
| 221 #endif |
| 222 |
| 223 // Set all state that is different from the real state |
| 224 if (virtual_context->GetGLStateRestorer()->IsInitialized()) { |
| 225 GLStateRestorer* virtual_state = virtual_context->GetGLStateRestorer(); |
| 226 GLStateRestorer* current_state = |
| 227 current_virtual_context_ |
| 228 ? current_virtual_context_->GetGLStateRestorer() |
| 229 : nullptr; |
| 230 if (current_state) |
| 231 current_state->PauseQueries(); |
| 232 virtual_state->ResumeQueries(); |
| 233 |
| 234 virtual_state->RestoreState( |
| 235 (current_state && !switched_real_contexts) ? current_state : NULL); |
| 236 } |
| 237 current_virtual_context_ = virtual_context; |
| 238 } |
| 239 |
| 240 virtual_context->SetCurrent(surface); |
| 241 if (!surface->OnMakeCurrent(virtual_context)) { |
| 242 LOG(ERROR) << "Could not make GLSurface current."; |
| 243 return false; |
| 244 } |
| 245 return true; |
202 } | 246 } |
203 | 247 |
204 void GLContext::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { | 248 void GLContext::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { |
205 if (virtual_gl_api_) | 249 if (current_virtual_context_ == virtual_context) |
206 virtual_gl_api_->OnReleaseVirtuallyCurrent(virtual_context); | 250 current_virtual_context_ = nullptr; |
207 } | 251 } |
208 | 252 |
209 void GLContext::SetRealGLApi() { | 253 void GLContext::SetRealGLApi() { |
210 SetGLToRealGLApi(); | 254 SetGLToRealGLApi(); |
211 } | 255 } |
212 | 256 |
213 GLContextReal::GLContextReal(GLShareGroup* share_group) | 257 GLContextReal::GLContextReal(GLShareGroup* share_group) |
214 : GLContext(share_group) {} | 258 : GLContext(share_group) {} |
215 | 259 |
216 scoped_refptr<GPUTimingClient> GLContextReal::CreateGPUTimingClient() { | 260 scoped_refptr<GPUTimingClient> GLContextReal::CreateGPUTimingClient() { |
(...skipping 15 matching lines...) Expand all Loading... |
232 | 276 |
233 scoped_refptr<GLContext> InitializeGLContext(scoped_refptr<GLContext> context, | 277 scoped_refptr<GLContext> InitializeGLContext(scoped_refptr<GLContext> context, |
234 GLSurface* compatible_surface, | 278 GLSurface* compatible_surface, |
235 GpuPreference gpu_preference) { | 279 GpuPreference gpu_preference) { |
236 if (!context->Initialize(compatible_surface, gpu_preference)) | 280 if (!context->Initialize(compatible_surface, gpu_preference)) |
237 return nullptr; | 281 return nullptr; |
238 return context; | 282 return context; |
239 } | 283 } |
240 | 284 |
241 } // namespace gl | 285 } // namespace gl |
OLD | NEW |