Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(780)

Unified Diff: ui/gl/gl_context_cgl.cc

Issue 10957009: Get real GPU memory values on NV+Linux and OS X (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate review feedback Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gl/gl_context_cgl.h ('k') | ui/gl/gl_context_glx.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1f79ea0eb0b6b308d6cb031b65f5c3acc8c4ae98 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,59 @@ void GLContextCGL::SetSwapInterval(int interval) {
LOG(WARNING) << "GLContex: GLContextCGL::SetSwapInterval is ignored.";
}
+
+bool GLContextCGL::GetTotalGpuMemory(size_t* bytes) {
+ DCHECK(bytes);
+ *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,
+ &current_renderer_id) != kCGLNoError)
+ return false;
+
+ // Iterate through the list of all renderers
+ GLuint display_mask = static_cast<GLuint>(-1);
+ CGLRendererInfoObj renderer_info = NULL;
+ GLint num_renderers = 0;
+ if (CGLQueryRendererInfo(display_mask,
+ &renderer_info,
+ &num_renderers) != kCGLNoError)
+ return false;
+
+ ScopedCGLRendererInfoObj scoper(renderer_info);
+
+ 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;
+ return true;
+ }
+
+ return false;
+}
+
GLContextCGL::~GLContextCGL() {
Destroy();
}
@@ -173,4 +227,8 @@ void GLContextCGL::ForceUseOfDiscreteGPU() {
// format is deliberately leaked.
}
+void ScopedCGLDestroyRendererInfo::operator()(CGLRendererInfoObj x) const {
+ CGLDestroyRendererInfo(x);
+}
+
} // namespace gfx
« no previous file with comments | « ui/gl/gl_context_cgl.h ('k') | ui/gl/gl_context_glx.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698