Chromium Code Reviews| Index: ui/gl/gl_context_cgl.cc |
| diff --git a/ui/gl/gl_context_cgl.cc b/ui/gl/gl_context_cgl.cc |
| index 8affe56f683a97bd7cb56aa072337b16e09842c1..6247cf5d3812cafb17dbf8581af89d4e0c676e2d 100644 |
| --- a/ui/gl/gl_context_cgl.cc |
| +++ b/ui/gl/gl_context_cgl.cc |
| @@ -5,6 +5,7 @@ |
| #include "ui/gl/gl_context_cgl.h" |
| #include <OpenGL/CGLRenderers.h> |
| +#include <OpenGL/CGLTypes.h> |
| #include <vector> |
| #include "base/debug/trace_event.h" |
| @@ -154,6 +155,58 @@ void GLContextCGL::SetSwapInterval(int interval) { |
| LOG(WARNING) << "GLContex: GLContextCGL::SetSwapInterval is ignored."; |
| } |
| + |
| +bool GLContextCGL::GetTotalGpuMemory(size_t& bytes) { |
| + bool got_current_gpu_memory_value = false; |
| + bytes = 0; |
| + |
| + CGLContextObj context = reinterpret_cast<CGLContextObj>(context_); |
| + if (!context) |
| + return false; |
| + |
| + // Retrieve the current renderer ID |
| + GLint current_renderer_id = 0; |
| + if (CGLGetParameter(context, |
| + kCGLCPCurrentRendererID, |
| + ¤t_renderer_id) != kCGLNoError) |
| + return false; |
| + |
| + // Iterate through the list of all renderers |
| + GLuint display_mask = static_cast<GLuint>(-1); |
| + CGLRendererInfoObj renderer_info = NULL; |
|
Ken Russell (switch to Gerrit)
2012/09/20 06:47:23
Use ScopedGenericObj parameterized with a ScopedDe
|
| + GLint num_renderers = 0; |
| + if (CGLQueryRendererInfo(display_mask, |
| + &renderer_info, |
| + &num_renderers) != kCGLNoError) |
| + return false; |
| + for (GLint renderer_index = 0; |
| + renderer_index < num_renderers; |
| + ++renderer_index) { |
| + // Skip this if this renderer is not the current renderer. |
| + GLint renderer_id = 0; |
| + if (CGLDescribeRenderer(renderer_info, |
| + renderer_index, |
| + kCGLRPRendererID, |
| + &renderer_id) != kCGLNoError) |
| + continue; |
| + if (renderer_id != current_renderer_id) |
| + continue; |
| + // Retrieve the video memory for the renderer. |
| + GLint video_memory = 0; |
| + if (CGLDescribeRenderer(renderer_info, |
| + renderer_index, |
| + kCGLRPVideoMemory, |
| + &video_memory) != kCGLNoError) |
| + continue; |
| + bytes = video_memory; |
| + got_current_gpu_memory_value = true; |
| + break; |
| + } |
| + |
| + CGLDestroyRendererInfo(renderer_info); |
| + return got_current_gpu_memory_value; |
| +} |
| + |
| GLContextCGL::~GLContextCGL() { |
| Destroy(); |
| } |