| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 252 } |
| 253 | 253 |
| 254 void* GLContextCGL::GetHandle() { | 254 void* GLContextCGL::GetHandle() { |
| 255 return context_; | 255 return context_; |
| 256 } | 256 } |
| 257 | 257 |
| 258 void GLContextCGL::OnSetSwapInterval(int interval) { | 258 void GLContextCGL::OnSetSwapInterval(int interval) { |
| 259 DCHECK(IsCurrent(nullptr)); | 259 DCHECK(IsCurrent(nullptr)); |
| 260 } | 260 } |
| 261 | 261 |
| 262 bool GLContextCGL::GetTotalGpuMemory(size_t* bytes) { | |
| 263 DCHECK(bytes); | |
| 264 *bytes = 0; | |
| 265 | |
| 266 CGLContextObj context = reinterpret_cast<CGLContextObj>(context_); | |
| 267 if (!context) | |
| 268 return false; | |
| 269 | |
| 270 // Retrieve the current renderer ID | |
| 271 GLint current_renderer_id = 0; | |
| 272 if (CGLGetParameter(context, | |
| 273 kCGLCPCurrentRendererID, | |
| 274 ¤t_renderer_id) != kCGLNoError) | |
| 275 return false; | |
| 276 | |
| 277 // Iterate through the list of all renderers | |
| 278 GLuint display_mask = static_cast<GLuint>(-1); | |
| 279 CGLRendererInfoObj renderer_info = nullptr; | |
| 280 GLint num_renderers = 0; | |
| 281 if (CGLQueryRendererInfo(display_mask, | |
| 282 &renderer_info, | |
| 283 &num_renderers) != kCGLNoError) | |
| 284 return false; | |
| 285 | |
| 286 scoped_ptr<CGLRendererInfoObj, | |
| 287 CGLRendererInfoObjDeleter> scoper(&renderer_info); | |
| 288 | |
| 289 for (GLint renderer_index = 0; | |
| 290 renderer_index < num_renderers; | |
| 291 ++renderer_index) { | |
| 292 // Skip this if this renderer is not the current renderer. | |
| 293 GLint renderer_id = 0; | |
| 294 if (CGLDescribeRenderer(renderer_info, | |
| 295 renderer_index, | |
| 296 kCGLRPRendererID, | |
| 297 &renderer_id) != kCGLNoError) | |
| 298 continue; | |
| 299 if (renderer_id != current_renderer_id) | |
| 300 continue; | |
| 301 // Retrieve the video memory for the renderer. | |
| 302 GLint video_memory = 0; | |
| 303 if (CGLDescribeRenderer(renderer_info, | |
| 304 renderer_index, | |
| 305 kCGLRPVideoMemory, | |
| 306 &video_memory) != kCGLNoError) | |
| 307 continue; | |
| 308 *bytes = video_memory; | |
| 309 return true; | |
| 310 } | |
| 311 | |
| 312 return false; | |
| 313 } | |
| 314 | |
| 315 void GLContextCGL::SetSafeToForceGpuSwitch() { | 262 void GLContextCGL::SetSafeToForceGpuSwitch() { |
| 316 safe_to_force_gpu_switch_ = true; | 263 safe_to_force_gpu_switch_ = true; |
| 317 } | 264 } |
| 318 | 265 |
| 319 | 266 |
| 320 GLContextCGL::~GLContextCGL() { | 267 GLContextCGL::~GLContextCGL() { |
| 321 Destroy(); | 268 Destroy(); |
| 322 } | 269 } |
| 323 | 270 |
| 324 GpuPreference GLContextCGL::GetGpuPreference() { | 271 GpuPreference GLContextCGL::GetGpuPreference() { |
| 325 return gpu_preference_; | 272 return gpu_preference_; |
| 326 } | 273 } |
| 327 | 274 |
| 328 } // namespace gfx | 275 } // namespace gfx |
| OLD | NEW |