| 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 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 Destroy(); | 115 Destroy(); |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 | 118 |
| 119 gpu_preference_ = gpu_preference; | 119 gpu_preference_ = gpu_preference; |
| 120 return true; | 120 return true; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void GLContextCGL::Destroy() { | 123 void GLContextCGL::Destroy() { |
| 124 if (discrete_pixelformat_) { | 124 if (discrete_pixelformat_) { |
| 125 // Delay releasing the pixel format for 10 seconds to reduce the number of | 125 if (base::MessageLoop::current() != NULL) { |
| 126 // unnecessary GPU switches. | 126 // Delay releasing the pixel format for 10 seconds to reduce the number of |
| 127 base::MessageLoop::current()->PostDelayedTask( | 127 // unnecessary GPU switches. |
| 128 FROM_HERE, | 128 base::MessageLoop::current()->PostDelayedTask( |
| 129 base::Bind(&CGLReleasePixelFormat, discrete_pixelformat_), | 129 FROM_HERE, base::Bind(&CGLReleasePixelFormat, discrete_pixelformat_), |
| 130 base::TimeDelta::FromSeconds(10)); | 130 base::TimeDelta::FromSeconds(10)); |
| 131 } else { |
| 132 CGLReleasePixelFormat(discrete_pixelformat_); |
| 133 } |
| 131 discrete_pixelformat_ = NULL; | 134 discrete_pixelformat_ = NULL; |
| 132 } | 135 } |
| 133 if (context_) { | 136 if (context_) { |
| 134 CGLDestroyContext(static_cast<CGLContextObj>(context_)); | 137 CGLDestroyContext(static_cast<CGLContextObj>(context_)); |
| 135 context_ = NULL; | 138 context_ = NULL; |
| 136 } | 139 } |
| 137 } | 140 } |
| 138 | 141 |
| 139 bool GLContextCGL::ForceGpuSwitchIfNeeded() { | 142 bool GLContextCGL::ForceGpuSwitchIfNeeded() { |
| 140 DCHECK(context_); | 143 DCHECK(context_); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 | 305 |
| 303 GLContextCGL::~GLContextCGL() { | 306 GLContextCGL::~GLContextCGL() { |
| 304 Destroy(); | 307 Destroy(); |
| 305 } | 308 } |
| 306 | 309 |
| 307 GpuPreference GLContextCGL::GetGpuPreference() { | 310 GpuPreference GLContextCGL::GetGpuPreference() { |
| 308 return gpu_preference_; | 311 return gpu_preference_; |
| 309 } | 312 } |
| 310 | 313 |
| 311 } // namespace gfx | 314 } // namespace gfx |
| OLD | NEW |