summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--third_party/khronos/GLES2/gl2ext.h9
-rw-r--r--third_party/khronos/README.chromium1
-rw-r--r--third_party/mesa/MesaLib/include/GL/glext.h7
-rw-r--r--third_party/mesa/README.chromium2
-rw-r--r--ui/gl/gl_context.cc6
-rw-r--r--ui/gl/gl_context.h5
-rw-r--r--ui/gl/gl_context_cgl.cc58
-rw-r--r--ui/gl/gl_context_cgl.h10
-rw-r--r--ui/gl/gl_context_glx.cc12
-rw-r--r--ui/gl/gl_context_glx.h1
-rw-r--r--ui/gl/gl_context_mac.mm16
11 files changed, 112 insertions, 15 deletions
diff --git a/third_party/khronos/GLES2/gl2ext.h b/third_party/khronos/GLES2/gl2ext.h
index ee0da03..fee1192 100644
--- a/third_party/khronos/GLES2/gl2ext.h
+++ b/third_party/khronos/GLES2/gl2ext.h
@@ -573,6 +573,15 @@ typedef void* GLeglImageOES;
/* GL_NV_texture_npot_2D_mipmap */
/* No new tokens introduced by this extension. */
+/* GL_NVX_gpu_memory_info */
+#ifndef GL_NVX_gpu_memory_info
+#define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
+#define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
+#define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
+#define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
+#define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
+#endif
+
/*------------------------------------------------------------------------*
* QCOM extension tokens
*------------------------------------------------------------------------*/
diff --git a/third_party/khronos/README.chromium b/third_party/khronos/README.chromium
index 837d13e..f49e752 100644
--- a/third_party/khronos/README.chromium
+++ b/third_party/khronos/README.chromium
@@ -27,5 +27,6 @@ GLES2/gl2ext.h
- Added GL_CHROMIUM_copy_texture
- Added GL_CHROMIUM_bind_uniform_location
- Added GL_CHROMIUM_get_error_query
+ - Added GL_NVX_gpu_memory_info
EGL/eglplatform.h
- Added EGLNative*Type for Mac.
diff --git a/third_party/mesa/MesaLib/include/GL/glext.h b/third_party/mesa/MesaLib/include/GL/glext.h
index 77335bd..653e4fd 100644
--- a/third_party/mesa/MesaLib/include/GL/glext.h
+++ b/third_party/mesa/MesaLib/include/GL/glext.h
@@ -5019,6 +5019,13 @@ extern "C" {
#ifndef GL_AMD_transform_feedback3_lines_triangles
#endif
+#ifndef GL_NVX_gpu_memory_info
+#define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
+#define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
+#define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
+#define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
+#define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
+#endif
/*************************************************************/
diff --git a/third_party/mesa/README.chromium b/third_party/mesa/README.chromium
index db954fd..32fee68 100644
--- a/third_party/mesa/README.chromium
+++ b/third_party/mesa/README.chromium
@@ -113,3 +113,5 @@ Later modifications (see chromium.patch):
http://code.google.com/p/chromium/issues/detail?id=142316
- Fix the compile errors on Android
+
+- Added constants for GL_NVX_gpu_memory_info to glext.h
diff --git a/ui/gl/gl_context.cc b/ui/gl/gl_context.cc
index 6ab53a1..b3a119c 100644
--- a/ui/gl/gl_context.cc
+++ b/ui/gl/gl_context.cc
@@ -35,6 +35,12 @@ GLContext::~GLContext() {
}
}
+bool GLContext::GetTotalGpuMemory(size_t* bytes) {
+ DCHECK(bytes);
+ *bytes = 0;
+ return false;
+}
+
std::string GLContext::GetExtensions() {
DCHECK(IsCurrent(NULL));
const char* ext = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
diff --git a/ui/gl/gl_context.h b/ui/gl/gl_context.h
index defeb25..7c0b669 100644
--- a/ui/gl/gl_context.h
+++ b/ui/gl/gl_context.h
@@ -50,6 +50,11 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
// Returns space separated list of extensions. The context must be current.
virtual std::string GetExtensions();
+ // Returns in bytes the total amount of GPU memory for the GPU which this
+ // context is currently rendering on. Returns false if no extension exists
+ // to get the exact amount of GPU memory.
+ virtual bool GetTotalGpuMemory(size_t* bytes);
+
// Returns whether the current context supports the named extension. The
// context must be current.
bool HasExtension(const char* name);
diff --git a/ui/gl/gl_context_cgl.cc b/ui/gl/gl_context_cgl.cc
index 8affe56..1f79ea0 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
diff --git a/ui/gl/gl_context_cgl.h b/ui/gl/gl_context_cgl.h
index 1e41b52..49bc346 100644
--- a/ui/gl/gl_context_cgl.h
+++ b/ui/gl/gl_context_cgl.h
@@ -7,6 +7,7 @@
#include <OpenGL/CGLTypes.h>
+#include "base/memory/scoped_generic_obj.h"
#include "ui/gl/gl_context.h"
namespace gfx {
@@ -27,6 +28,7 @@ class GLContextCGL : public GLContext {
virtual bool IsCurrent(GLSurface* surface) OVERRIDE;
virtual void* GetHandle() OVERRIDE;
virtual void SetSwapInterval(int interval) OVERRIDE;
+ virtual bool GetTotalGpuMemory(size_t* bytes) OVERRIDE;
protected:
virtual ~GLContextCGL();
@@ -49,6 +51,14 @@ class GLContextCGL : public GLContext {
DISALLOW_COPY_AND_ASSIGN(GLContextCGL);
};
+class ScopedCGLDestroyRendererInfo {
+ public:
+ void operator()(CGLRendererInfoObj x) const;
+};
+
+typedef ScopedGenericObj<CGLRendererInfoObj, ScopedCGLDestroyRendererInfo>
+ ScopedCGLRendererInfoObj;
+
} // namespace gfx
#endif // UI_GL_GL_CONTEXT_CGL_H_
diff --git a/ui/gl/gl_context_glx.cc b/ui/gl/gl_context_glx.cc
index d052644..dc8226b 100644
--- a/ui/gl/gl_context_glx.cc
+++ b/ui/gl/gl_context_glx.cc
@@ -244,6 +244,18 @@ std::string GLContextGLX::GetExtensions() {
return GLContext::GetExtensions();
}
+bool GLContextGLX::GetTotalGpuMemory(size_t* bytes) {
+ DCHECK(bytes);
+ *bytes = 0;
+ if (HasExtension("GL_NVX_gpu_memory_info")) {
+ GLint kbytes = 0;
+ glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &kbytes);
+ *bytes = 1024*kbytes;
+ return true;
+ }
+ return false;
+}
+
bool GLContextGLX::WasAllocatedUsingRobustnessExtension() {
return GLSurfaceGLX::IsCreateContextRobustnessSupported();
}
diff --git a/ui/gl/gl_context_glx.h b/ui/gl/gl_context_glx.h
index bba6b3d..2847881 100644
--- a/ui/gl/gl_context_glx.h
+++ b/ui/gl/gl_context_glx.h
@@ -33,6 +33,7 @@ class GL_EXPORT GLContextGLX : public GLContext {
virtual void* GetHandle() OVERRIDE;
virtual void SetSwapInterval(int interval) OVERRIDE;
virtual std::string GetExtensions() OVERRIDE;
+ virtual bool GetTotalGpuMemory(size_t* bytes) OVERRIDE;
virtual bool WasAllocatedUsingRobustnessExtension() OVERRIDE;
protected:
diff --git a/ui/gl/gl_context_mac.mm b/ui/gl/gl_context_mac.mm
index 6ece7a6..a2df392 100644
--- a/ui/gl/gl_context_mac.mm
+++ b/ui/gl/gl_context_mac.mm
@@ -7,7 +7,6 @@
#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "base/mac/mac_util.h"
-#include "base/memory/scoped_generic_obj.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/mesa/MesaLib/include/GL/osmesa.h"
#include "ui/gl/gl_bindings.h"
@@ -22,18 +21,6 @@
#include "ui/gl/gl_context_nsview.h"
#endif
-namespace {
-
-// ScopedGenericObj functor for CGLDestroyRendererInfo().
-class ScopedDestroyRendererInfo {
- public:
- void operator()(CGLRendererInfoObj x) const {
- CGLDestroyRendererInfo(x);
- }
-};
-
-} // namespace
-
namespace gfx {
class GLShareGroup;
@@ -119,8 +106,7 @@ bool GLContext::SupportsDualGpus() {
return false;
}
- ScopedGenericObj<CGLRendererInfoObj, ScopedDestroyRendererInfo>
- scoper(renderer_info);
+ ScopedCGLRendererInfoObj scoper(renderer_info);
for (GLint i = 0; i < num_renderers; ++i) {
GLint accelerated = 0;