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

Unified Diff: chrome/gpu/gpu_info_collector_mac.mm

Issue 6346007: Refactor and improve gpu_info_collector: collect information on linux;... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
Index: chrome/gpu/gpu_info_collector_mac.mm
===================================================================
--- chrome/gpu/gpu_info_collector_mac.mm (revision 71329)
+++ chrome/gpu/gpu_info_collector_mac.mm (working copy)
@@ -16,10 +16,10 @@
#import <Foundation/Foundation.h>
#import <IOKit/IOKitLib.h>
-namespace gpu_info_collector {
+namespace {
-static CFTypeRef SearchPortForProperty(io_registry_entry_t dspPort,
- CFStringRef propertyName) {
+CFTypeRef SearchPortForProperty(io_registry_entry_t dspPort,
+ CFStringRef propertyName) {
return IORegistryEntrySearchCFProperty(dspPort,
kIOServicePlane,
propertyName,
@@ -28,145 +28,65 @@
kIORegistryIterateParents);
}
-static void CFReleaseIf(CFTypeRef type_ref) {
- if (type_ref)
- CFRelease(type_ref);
-}
+UInt32 IntValueOfCFData(CFDataRef data_ref) {
+ DCHECK(data_ref);
-static UInt32 IntValueOfCFData(CFDataRef data_ref) {
UInt32 value = 0;
-
- if (data_ref) {
- const UInt32 *value_pointer =
- reinterpret_cast<const UInt32*>(CFDataGetBytePtr(data_ref));
- if (value_pointer != NULL)
- value = *value_pointer;
- }
-
+ const UInt32* value_pointer =
+ reinterpret_cast<const UInt32*>(CFDataGetBytePtr(data_ref));
+ if (value_pointer != NULL)
+ value = *value_pointer;
return value;
}
-static void CollectVideoCardInfo(CGDirectDisplayID displayID,
- int *vendorID,
- int *deviceID) {
- io_registry_entry_t dspPort = CGDisplayIOServicePort(displayID);
+} // namespace anonymous
- CFTypeRef vendorIDRef = SearchPortForProperty(dspPort, CFSTR("vendor-id"));
- if (vendorID) *vendorID = IntValueOfCFData((CFDataRef)vendorIDRef);
+namespace gpu_info_collector {
- CFTypeRef deviceIDRef = SearchPortForProperty(dspPort, CFSTR("device-id"));
- if (deviceID) *deviceID = IntValueOfCFData((CFDataRef)deviceIDRef);
+bool CollectGraphicsInfo(GPUInfo* gpu_info) {
+ DCHECK(gpu_info);
- CFReleaseIf(vendorIDRef);
- CFReleaseIf(deviceIDRef);
+ gpu_info->SetCanLoseContext(
+ gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2);
+ gpu_info->SetProgress(GPUInfo::kComplete);
+ return CollectGraphicsInfoGL(gpu_info);
}
-// 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) {
- char *s_found = NULL;
+bool CollectVideoCardInfo(GPUInfo* gpu_info) {
+ DCHECK(gpu_info);
- while (*s != '\0') {
- if (*s == c)
- s_found = s;
- s++;
- }
- return s_found;
-}
+ if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL)
+ return false;
-// 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;
-
- if (gl_major_version == 1) {
- const char *gl_extensions_string = (const char*)glGetString(GL_EXTENSIONS);
- if (gl_extensions_string &&
- strstr(gl_extensions_string, "GL_ARB_shading_language_100")) {
- gl_hlsl_major = 1;
- gl_hlsl_minor = 0;
- }
- } else if (gl_major_version > 1) {
- const char *glsl_version_string =
- (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
- if (glsl_version_string)
- sscanf(glsl_version_string, "%u.%u", &gl_hlsl_major, &gl_hlsl_minor);
+ UInt32 vendor_id = 0, device_id = 0;
+ io_registry_entry_t dsp_port = CGDisplayIOServicePort(kCGDirectMainDisplay);
+ CFTypeRef vendor_id_ref = SearchPortForProperty(dsp_port, CFSTR("vendor-id"));
+ if (vendor_id_ref) {
+ vendor_id = IntValueOfCFData((CFDataRef)vendor_id_ref);
+ CFRelease(vendor_id_ref);
}
+ CFTypeRef device_id_ref = SearchPortForProperty(dsp_port, CFSTR("device-id"));
+ if (device_id_ref) {
+ device_id = IntValueOfCFData((CFDataRef)device_id_ref);
+ CFRelease(device_id_ref);
+ }
- shader_version = (gl_hlsl_major << 8) | (gl_hlsl_minor & 0xFF);
- return shader_version;
+ gpu_info->SetVideoCardInfo(vendor_id, device_id);
+ return true;
}
+bool CollectDriverInfo(GPUInfo* gpu_info) {
+ DCHECK(gpu_info);
-static std::wstring CStringToWString(const char *s) {
- base::StringPiece sp(s);
- return base::SysUTF8ToWide(sp);
-}
-
-
-// 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);
-
- *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)
- driver_version = CStringToWString(s + 1);
-
- return driver_version;
-}
-
-
-bool CollectGraphicsInfo(GPUInfo* gpu_info) {
- if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL)
+ std::string gl_version_string = gpu_info->gl_version_string();
+ size_t pos = gl_version_string.find_last_of('-');
+ if (pos == std::string::npos)
return false;
- // 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()) {
- scoped_ptr<gfx::GLContext> ctx(
- gfx::GLContext::CreateOffscreenGLContext(NULL));
- if (ctx.get()) {
- if (ctx->MakeCurrent()) {
- driver_version = CollectGLInfo(&gl_version, &shader_version);
- }
- ctx->Destroy();
- }
- }
-
-
- // 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,
- false);
-
- gpu_info->SetProgress(GPUInfo::kComplete);
-
+ gpu_info->SetDriverInfo("", gl_version_string.substr(pos + 1));
return true;
}

Powered by Google App Engine
This is Rietveld 408576698