Commit 910e3cf7 authored by maf@google.com's avatar maf@google.com

Add Mac GPU logging code.

Add separate GL version field.
Review URL: http://codereview.chromium.org/3104011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56957 0039d316-1c4b-4281-b951-d872f2087c98
parent 14462f6f
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
GPUInfo::GPUInfo() GPUInfo::GPUInfo()
: vendor_id_(0), device_id_(0), driver_version_(L""), : vendor_id_(0), device_id_(0), driver_version_(L""),
pixel_shader_version_(0), vertex_shader_version_(0) { pixel_shader_version_(0), vertex_shader_version_(0),
gl_version_(0) {
} }
uint32 GPUInfo::vendor_id() const { uint32 GPUInfo::vendor_id() const {
...@@ -29,13 +30,20 @@ uint32 GPUInfo::vertex_shader_version() const { ...@@ -29,13 +30,20 @@ uint32 GPUInfo::vertex_shader_version() const {
return vertex_shader_version_; return vertex_shader_version_;
} }
uint32 GPUInfo::gl_version() const {
return gl_version_;
}
void GPUInfo::SetGraphicsInfo(uint32 vendor_id, uint32 device_id, void GPUInfo::SetGraphicsInfo(uint32 vendor_id, uint32 device_id,
const std::wstring& driver_version, const std::wstring& driver_version,
uint32 pixel_shader_version, uint32 pixel_shader_version,
uint32 vertex_shader_version) { uint32 vertex_shader_version,
uint32 gl_version) {
vendor_id_ = vendor_id; vendor_id_ = vendor_id;
device_id_ = device_id; device_id_ = device_id;
driver_version_ = driver_version; driver_version_ = driver_version;
pixel_shader_version_ = pixel_shader_version; pixel_shader_version_ = pixel_shader_version;
vertex_shader_version_ = vertex_shader_version; vertex_shader_version_ = vertex_shader_version;
gl_version_ = gl_version;
} }
...@@ -39,17 +39,26 @@ class GPUInfo { ...@@ -39,17 +39,26 @@ class GPUInfo {
// should be okay. // should be okay.
uint32 vertex_shader_version() const; uint32 vertex_shader_version() const;
// Return the version of OpenGL we are using.
// Major version in the high word, minor in the low word, eg version 2.5
// would be 0x00020005.
// Returns 0 if we're not using OpenGL, say because we're going through
// D3D instead.
uint32 gl_version() const;
// Populate variables with passed in values // Populate variables with passed in values
void SetGraphicsInfo(uint32 vendor_id, uint32 device_id, void SetGraphicsInfo(uint32 vendor_id, uint32 device_id,
const std::wstring& driver_version, const std::wstring& driver_version,
uint32 pixel_shader_version, uint32 pixel_shader_version,
uint32 vertex_shader_version); uint32 vertex_shader_version,
uint32 gl_version);
private: private:
uint32 vendor_id_; uint32 vendor_id_;
uint32 device_id_; uint32 device_id_;
std::wstring driver_version_; std::wstring driver_version_;
uint32 pixel_shader_version_; uint32 pixel_shader_version_;
uint32 vertex_shader_version_; uint32 vertex_shader_version_;
uint32 gl_version_;
}; };
#endif // CHROME_COMMON_GPU_INFO_H__ #endif // CHROME_COMMON_GPU_INFO_H__
...@@ -87,6 +87,7 @@ struct ParamTraits<GPUInfo> { ...@@ -87,6 +87,7 @@ struct ParamTraits<GPUInfo> {
m->WriteWString(p.driver_version()); m->WriteWString(p.driver_version());
m->WriteUInt32(p.pixel_shader_version()); m->WriteUInt32(p.pixel_shader_version());
m->WriteUInt32(p.vertex_shader_version()); m->WriteUInt32(p.vertex_shader_version());
m->WriteUInt32(p.gl_version());
} }
static bool Read(const Message* m, void** iter, param_type* p) { static bool Read(const Message* m, void** iter, param_type* p) {
uint32 vendor_id; uint32 vendor_id;
...@@ -94,13 +95,16 @@ struct ParamTraits<GPUInfo> { ...@@ -94,13 +95,16 @@ struct ParamTraits<GPUInfo> {
std::wstring driver_version; std::wstring driver_version;
uint32 pixel_shader_version; uint32 pixel_shader_version;
uint32 vertex_shader_version; uint32 vertex_shader_version;
uint32 gl_version;
bool ret = m->ReadUInt32(iter, &vendor_id); bool ret = m->ReadUInt32(iter, &vendor_id);
ret = ret && m->ReadUInt32(iter, &device_id); ret = ret && m->ReadUInt32(iter, &device_id);
ret = ret && m->ReadWString(iter, &driver_version); ret = ret && m->ReadWString(iter, &driver_version);
ret = ret && m->ReadUInt32(iter, &pixel_shader_version); ret = ret && m->ReadUInt32(iter, &pixel_shader_version);
ret = ret && m->ReadUInt32(iter, &vertex_shader_version); ret = ret && m->ReadUInt32(iter, &vertex_shader_version);
ret = ret && m->ReadUInt32(iter, &gl_version);
p->SetGraphicsInfo(vendor_id, device_id, driver_version, p->SetGraphicsInfo(vendor_id, device_id, driver_version,
pixel_shader_version, vertex_shader_version); pixel_shader_version, vertex_shader_version,
gl_version);
return ret; return ret;
} }
static void Log(const param_type& p, std::string* l) { static void Log(const param_type& p, std::string* l) {
......
...@@ -15,7 +15,8 @@ TEST(GPUIPCMessageTest, GPUInfo) { ...@@ -15,7 +15,8 @@ TEST(GPUIPCMessageTest, GPUInfo) {
GPUInfo input; GPUInfo input;
// Test variables taken from Lenovo T61 // Test variables taken from Lenovo T61
input.SetGraphicsInfo(0x10de, 0x429, L"6.14.11.7715", input.SetGraphicsInfo(0x10de, 0x429, L"6.14.11.7715",
0xffff0300, 0xfffe0300); 0xffff0300, 0xfffe0300,
0x00010005);
IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
IPC::WriteParam(&msg, input); IPC::WriteParam(&msg, input);
...@@ -28,6 +29,7 @@ TEST(GPUIPCMessageTest, GPUInfo) { ...@@ -28,6 +29,7 @@ TEST(GPUIPCMessageTest, GPUInfo) {
EXPECT_EQ(input.driver_version(), output.driver_version()); EXPECT_EQ(input.driver_version(), output.driver_version());
EXPECT_EQ(input.pixel_shader_version(), output.pixel_shader_version()); EXPECT_EQ(input.pixel_shader_version(), output.pixel_shader_version());
EXPECT_EQ(input.vertex_shader_version(), output.vertex_shader_version()); EXPECT_EQ(input.vertex_shader_version(), output.vertex_shader_version());
EXPECT_EQ(input.gl_version(), output.gl_version());
std::string log_message; std::string log_message;
IPC::LogParam(output, &log_message); IPC::LogParam(output, &log_message);
......
...@@ -3,11 +3,131 @@ ...@@ -3,11 +3,131 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/gpu/gpu_info_collector.h" #include "chrome/gpu/gpu_info_collector.h"
#include "base/sys_string_conversions.h"
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <IOKit/IOKitLib.h>
#import <OpenGL/GL.h>
namespace gpu_info_collector { namespace gpu_info_collector {
static CFTypeRef SearchPortForProperty(io_registry_entry_t dspPort,
CFStringRef propertyName) {
return IORegistryEntrySearchCFProperty(dspPort,
kIOServicePlane,
propertyName,
kCFAllocatorDefault,
kIORegistryIterateRecursively |
kIORegistryIterateParents);
}
static void CFReleaseIf(CFTypeRef type_ref) {
if (type_ref)
CFRelease(type_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;
}
return value;
}
static void CollectVideoCardInfo(CGDirectDisplayID displayID,
int *vendorID,
int *deviceID) {
io_registry_entry_t dspPort = CGDisplayIOServicePort(displayID);
CFTypeRef vendorIDRef = SearchPortForProperty(dspPort, CFSTR("vendor-id"));
if (vendorID) *vendorID = IntValueOfCFData((CFDataRef)vendorIDRef);
CFTypeRef deviceIDRef = SearchPortForProperty(dspPort, CFSTR("device-id"));
if (deviceID) *deviceID = IntValueOfCFData((CFDataRef)deviceIDRef);
CFReleaseIf(vendorIDRef);
CFReleaseIf(deviceIDRef);
}
// 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;
while (*s != '\0') {
if (*s == c)
s_found = s;
s++;
}
return s_found;
}
bool CollectGraphicsInfo(GPUInfo& gpu_info) { bool CollectGraphicsInfo(GPUInfo& gpu_info) {
// TODO(rlp): complete this function 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;
CollectVideoCardInfo(kCGDirectMainDisplay, &vendor_id, &device_id);
char *gl_version_string = (char*)glGetString(GL_VERSION);
char *gl_extensions_string = (char*)glGetString(GL_EXTENSIONS);
if ((gl_version_string == NULL) || (gl_extensions_string == NULL))
return false;
// Get the OpenGL version from the start of the string.
int gl_major = 0, gl_minor = 0;
sscanf(gl_version_string, "%u.%u", &gl_major, &gl_minor);
// Get the OpenGL driver version.
// Mac OpenGL drivers have the driver version
// at the end of the gl version string preceded by a dash.
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];
}
// 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);
}
}
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,
gl_version);
return true; return true;
} }
......
...@@ -70,7 +70,7 @@ bool CollectGraphicsInfoD3D(IDirect3D9* d3d, ...@@ -70,7 +70,7 @@ bool CollectGraphicsInfoD3D(IDirect3D9* d3d,
uint32 vertex_shader_version = d3d_caps.VertexShaderVersion; uint32 vertex_shader_version = d3d_caps.VertexShaderVersion;
gpu_info.SetGraphicsInfo(vendor_id, device_id, driver_version, gpu_info.SetGraphicsInfo(vendor_id, device_id, driver_version,
pixel_shader_version, vertex_shader_version); pixel_shader_version, vertex_shader_version, 0);
return true; return true;
} }
...@@ -100,7 +100,7 @@ bool CollectGraphicsInfoGL(GPUInfo& gpu_info) { ...@@ -100,7 +100,7 @@ bool CollectGraphicsInfoGL(GPUInfo& gpu_info) {
uint32 pixel_shader_version = 0; uint32 pixel_shader_version = 0;
uint32 vertex_shader_version = 0; uint32 vertex_shader_version = 0;
gpu_info.SetGraphicsInfo(vendor_id, device_id, driver_version, gpu_info.SetGraphicsInfo(vendor_id, device_id, driver_version,
pixel_shader_version, vertex_shader_version); pixel_shader_version, vertex_shader_version, 0);
return true; return true;
// TODO(rlp): Add driver and pixel versions // TODO(rlp): Add driver and pixel versions
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment