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_cgl.h" | 5 #include "ui/gl/gl_context_cgl.h" |
6 | 6 |
7 #include <OpenGL/CGLRenderers.h> | 7 #include <OpenGL/CGLRenderers.h> |
8 #include <OpenGL/CGLTypes.h> | 8 #include <OpenGL/CGLTypes.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "ui/gl/gl_bindings.h" | 19 #include "ui/gl/gl_bindings.h" |
| 20 #include "ui/gl/gl_gl_api_implementation.h" |
20 #include "ui/gl/gl_implementation.h" | 21 #include "ui/gl/gl_implementation.h" |
21 #include "ui/gl/gl_surface.h" | 22 #include "ui/gl/gl_surface.h" |
22 #include "ui/gl/gpu_switching_manager.h" | 23 #include "ui/gl/gpu_switching_manager.h" |
23 #include "ui/gl/scoped_cgl.h" | 24 #include "ui/gl/scoped_cgl.h" |
24 #include "ui/gl/yuv_to_rgb_converter.h" | 25 #include "ui/gl/yuv_to_rgb_converter.h" |
25 | 26 |
26 namespace gl { | 27 namespace gl { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // Contexts that prefer integrated gpu are known to use only the subset of GL | 143 // Contexts that prefer integrated gpu are known to use only the subset of GL |
143 // that can be safely migrated between the iGPU and the dGPU. Mark those | 144 // that can be safely migrated between the iGPU and the dGPU. Mark those |
144 // contexts as safe to forcibly transition between the GPUs by default. | 145 // contexts as safe to forcibly transition between the GPUs by default. |
145 // http://crbug.com/180876, http://crbug.com/227228 | 146 // http://crbug.com/180876, http://crbug.com/227228 |
146 safe_to_force_gpu_switch_ = gpu_preference == PreferIntegratedGpu; | 147 safe_to_force_gpu_switch_ = gpu_preference == PreferIntegratedGpu; |
147 return true; | 148 return true; |
148 } | 149 } |
149 | 150 |
150 void GLContextCGL::Destroy() { | 151 void GLContextCGL::Destroy() { |
151 if (yuv_to_rgb_converter_) { | 152 if (yuv_to_rgb_converter_) { |
| 153 // If this context is not current, bind this context's API so that the YUV |
| 154 // converter can safely destruct |
| 155 GLContext* current_context = GetRealCurrent(); |
| 156 if (current_context != this) { |
| 157 SetCurrentGL(GetCurrentGL()); |
| 158 } |
| 159 |
152 ScopedCGLSetCurrentContext(static_cast<CGLContextObj>(context_)); | 160 ScopedCGLSetCurrentContext(static_cast<CGLContextObj>(context_)); |
153 yuv_to_rgb_converter_.reset(); | 161 yuv_to_rgb_converter_.reset(); |
| 162 |
| 163 // Rebind the current context's API if needed. |
| 164 if (current_context && current_context != this) { |
| 165 SetCurrentGL(current_context->GetCurrentGL()); |
| 166 } |
154 } | 167 } |
155 if (discrete_pixelformat_) { | 168 if (discrete_pixelformat_) { |
156 if (base::MessageLoop::current() != nullptr) { | 169 if (base::MessageLoop::current() != nullptr) { |
157 // Delay releasing the pixel format for 10 seconds to reduce the number of | 170 // Delay releasing the pixel format for 10 seconds to reduce the number of |
158 // unnecessary GPU switches. | 171 // unnecessary GPU switches. |
159 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 172 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
160 FROM_HERE, base::Bind(&CGLReleasePixelFormat, discrete_pixelformat_), | 173 FROM_HERE, base::Bind(&CGLReleasePixelFormat, discrete_pixelformat_), |
161 base::TimeDelta::FromSeconds(10)); | 174 base::TimeDelta::FromSeconds(10)); |
162 } else { | 175 } else { |
163 CGLReleasePixelFormat(discrete_pixelformat_); | 176 CGLReleasePixelFormat(discrete_pixelformat_); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 ScopedReleaseCurrent release_current; | 242 ScopedReleaseCurrent release_current; |
230 TRACE_EVENT0("gpu", "GLContextCGL::MakeCurrent"); | 243 TRACE_EVENT0("gpu", "GLContextCGL::MakeCurrent"); |
231 | 244 |
232 if (CGLSetCurrentContext( | 245 if (CGLSetCurrentContext( |
233 static_cast<CGLContextObj>(context_)) != kCGLNoError) { | 246 static_cast<CGLContextObj>(context_)) != kCGLNoError) { |
234 LOG(ERROR) << "Unable to make gl context current."; | 247 LOG(ERROR) << "Unable to make gl context current."; |
235 return false; | 248 return false; |
236 } | 249 } |
237 | 250 |
238 // Set this as soon as the context is current, since we might call into GL. | 251 // Set this as soon as the context is current, since we might call into GL. |
239 SetRealGLApi(); | 252 BindGLApi(); |
240 | 253 |
241 SetCurrent(surface); | 254 SetCurrent(surface); |
242 InitializeDynamicBindings(); | 255 InitializeDynamicBindings(); |
243 | 256 |
244 if (!surface->OnMakeCurrent(this)) { | 257 if (!surface->OnMakeCurrent(this)) { |
245 LOG(ERROR) << "Unable to make gl context current."; | 258 LOG(ERROR) << "Unable to make gl context current."; |
246 return false; | 259 return false; |
247 } | 260 } |
248 | 261 |
249 release_current.Cancel(); | 262 release_current.Cancel(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 300 |
288 GLContextCGL::~GLContextCGL() { | 301 GLContextCGL::~GLContextCGL() { |
289 Destroy(); | 302 Destroy(); |
290 } | 303 } |
291 | 304 |
292 GpuPreference GLContextCGL::GetGpuPreference() { | 305 GpuPreference GLContextCGL::GetGpuPreference() { |
293 return gpu_preference_; | 306 return gpu_preference_; |
294 } | 307 } |
295 | 308 |
296 } // namespace gl | 309 } // namespace gl |
OLD | NEW |