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