diff options
author | maf@google.com <maf@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-28 01:08:24 +0000 |
---|---|---|
committer | maf@google.com <maf@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-28 01:08:24 +0000 |
commit | 1dc7feedeeb6e05952017463cb9217c283463eaa (patch) | |
tree | 7ab75c6633338bce13ffde94dfbee9e138d57e2f /chrome/gpu | |
parent | e0ba360bbe5502a91a676dd84cb00ada53bc3fb3 (diff) | |
download | chromium_src-1dc7feedeeb6e05952017463cb9217c283463eaa.zip chromium_src-1dc7feedeeb6e05952017463cb9217c283463eaa.tar.gz chromium_src-1dc7feedeeb6e05952017463cb9217c283463eaa.tar.bz2 |
Re-enable data collection, using a temporary
offscreen GL context this time.
Review URL: http://codereview.chromium.org/3212001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57764 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/gpu')
-rw-r--r-- | chrome/gpu/gpu_info_collector_mac.mm | 118 |
1 files changed, 68 insertions, 50 deletions
diff --git a/chrome/gpu/gpu_info_collector_mac.mm b/chrome/gpu/gpu_info_collector_mac.mm index 0b494d3..097a840 100644 --- a/chrome/gpu/gpu_info_collector_mac.mm +++ b/chrome/gpu/gpu_info_collector_mac.mm @@ -3,7 +3,9 @@ // found in the LICENSE file. #include "chrome/gpu/gpu_info_collector.h" +#include "base/string_piece.h" #include "base/sys_string_conversions.h" +#include "app/gfx/gl/gl_context.h" #import <Cocoa/Cocoa.h> #import <Foundation/Foundation.h> @@ -55,8 +57,6 @@ static void CollectVideoCardInfo(CGDirectDisplayID displayID, CFReleaseIf(deviceIDRef); } -// TODO(maf): uncomment when using code below is re-enabled. -/* // Return a pointer to the last character with value c in string s. // Returns NULL if c is not found. static char* FindLastChar(char *s, char c) { @@ -69,72 +69,90 @@ static char* FindLastChar(char *s, char c) { } return s_found; } -*/ +// Gets the numeric HLSL version. +// You pass it the current GL major version, to give it a hint where to look. +static int GetShaderNumericVersion(int gl_major_version) { + int gl_hlsl_major = 0, gl_hlsl_minor = 0; + int shader_version = 0; -bool CollectGraphicsInfo(GPUInfo& gpu_info) { - int vendor_id = 0; - int device_id = 0; - std::wstring driver_version = L""; - uint32 pixel_shader_version = 0u; - uint32 vertex_shader_version = 0u; - uint32 gl_version = 0u; + if (gl_major_version == 1) { + char *gl_extensions_string = (char*)glGetString(GL_EXTENSIONS); + if (strstr(gl_extensions_string, "GL_ARB_shading_language_100")) { + gl_hlsl_major = 1; + gl_hlsl_minor = 0; + } + } else if (gl_major_version > 1) { + char *glsl_version_string = (char*)glGetString(GL_SHADING_LANGUAGE_VERSION); + if (glsl_version_string) + sscanf(glsl_version_string, "%u.%u", &gl_hlsl_major, &gl_hlsl_minor); + } + + shader_version = (gl_hlsl_major << 8) | (gl_hlsl_minor & 0xFF); + return shader_version; +} - CollectVideoCardInfo(kCGDirectMainDisplay, &vendor_id, &device_id); - // TODO(maf): when this is called, there is no OpenGL context - // current, so calls to glGetString crash. - /* - char *gl_version_string = (char*)glGetString(GL_VERSION); - char *gl_extensions_string = (char*)glGetString(GL_EXTENSIONS); +static std::wstring CStringToWString(const char *s) { + base::StringPiece sp(s); + return base::SysUTF8ToWide(sp); +} - if ((gl_version_string == NULL) || (gl_extensions_string == NULL)) - return false; - // Get the OpenGL version from the start of the string. +// Returns the driver version string as its value, and also returns the +// gl version and shader language version by setting the arguments pointed to. +static std::wstring CollectGLInfo(int *out_gl_version, + int *out_shader_version) { int gl_major = 0, gl_minor = 0; + char *gl_version_string = NULL; + std::wstring driver_version; + + gl_version_string = (char*)glGetString(GL_VERSION); sscanf(gl_version_string, "%u.%u", &gl_major, &gl_minor); - // Get the OpenGL driver version. + *out_gl_version = (gl_major << 8) | (gl_minor & 0xFF); + *out_shader_version = GetShaderNumericVersion(gl_major); + + // Extract the OpenGL driver version string from the GL_VERSION string. // Mac OpenGL drivers have the driver version // at the end of the gl version string preceded by a dash. + // Use some jiggery-pokery to turn that utf8 string into a std::wstring. char *s = FindLastChar(gl_version_string, '-'); - if (s) { - NSString *driver_version_ns = [[NSString alloc ] initWithUTF8String:s + 1]; - driver_version = base::SysNSStringToWide(driver_version_ns); - [driver_version_ns release]; - } + if (s) + driver_version = CStringToWString(s + 1); - // Get the HLSL version. - // On OpenGL 1.x it's 1.0 if the GL_ARB_shading_language_100 extension is - // present. - // On OpenGL 2.x it's a matter of getting the GL_SHADING_LANGUAGE_VERSION - // string. - int gl_hlsl_major = 0, gl_hlsl_minor = 0; - if ((gl_major == 1) && - strstr(gl_extensions_string, "GL_ARB_shading_language_100")) { - gl_hlsl_major = 1; - gl_hlsl_minor = 0; - } else if (gl_major >= 2) { - char* glsl_version_string = (char*)glGetString(GL_SHADING_LANGUAGE_VERSION); - if (glsl_version_string) { - sscanf(glsl_version_string, "%u.%u", &gl_hlsl_major, &gl_hlsl_minor); + return driver_version; +} + + +bool CollectGraphicsInfo(GPUInfo& gpu_info) { + // Video Card data. + int vendor_id = 0, device_id = 0; + // OpenGL data. + std::wstring driver_version = L""; + int gl_version = 0, shader_version = 0; + + CollectVideoCardInfo(kCGDirectMainDisplay, &vendor_id, &device_id); + + // Temporarily make an offscreen GL context so we can gather info from it. + if (gfx::GLContext::InitializeOneOff()) { + gfx::GLContext* ctx = gfx::GLContext::CreateOffscreenGLContext(NULL); + if (ctx) { + if (ctx->MakeCurrent()) { + driver_version = CollectGLInfo(&gl_version, &shader_version); + } + ctx->Destroy(); } } - pixel_shader_version = ((gl_hlsl_major << 16) & 0xffff0000) - + (gl_hlsl_minor & 0x0000ffff); - - // OpenGL doesn't have separate versions for pixel and vertex shader - // languages, so set them both to the GL_SHADING_LANGUAGE_VERSION value. - vertex_shader_version = pixel_shader_version; - gl_version = ((gl_major << 16) & 0xffff0000) - + (gl_minor & 0x0000ffff); - */ - gpu_info.SetGraphicsInfo(vendor_id, device_id, driver_version, - pixel_shader_version, vertex_shader_version, + // OpenGL doesn't have separate versions for pixel and vertex shader + // languages, so we just pass the shader_version for both. + gpu_info.SetGraphicsInfo(vendor_id, device_id, + driver_version, + shader_version, shader_version, gl_version); + return true; } |