| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/gpu/gpu_info_collector.h" | |
| 6 #include "base/logging.h" | |
| 7 #include "base/scoped_ptr.h" | |
| 8 #include "base/string_piece.h" | |
| 9 #include "base/sys_string_conversions.h" | |
| 10 #include "app/gfx/gl/gl_bindings.h" | |
| 11 #include "app/gfx/gl/gl_context.h" | |
| 12 #include "app/gfx/gl/gl_implementation.h" | |
| 13 #include "app/gfx/gl/gl_interface.h" | |
| 14 | |
| 15 #import <Cocoa/Cocoa.h> | |
| 16 #import <Foundation/Foundation.h> | |
| 17 #import <IOKit/IOKitLib.h> | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 CFTypeRef SearchPortForProperty(io_registry_entry_t dspPort, | |
| 22 CFStringRef propertyName) { | |
| 23 return IORegistryEntrySearchCFProperty(dspPort, | |
| 24 kIOServicePlane, | |
| 25 propertyName, | |
| 26 kCFAllocatorDefault, | |
| 27 kIORegistryIterateRecursively | | |
| 28 kIORegistryIterateParents); | |
| 29 } | |
| 30 | |
| 31 UInt32 IntValueOfCFData(CFDataRef data_ref) { | |
| 32 DCHECK(data_ref); | |
| 33 | |
| 34 UInt32 value = 0; | |
| 35 const UInt32* value_pointer = | |
| 36 reinterpret_cast<const UInt32*>(CFDataGetBytePtr(data_ref)); | |
| 37 if (value_pointer != NULL) | |
| 38 value = *value_pointer; | |
| 39 return value; | |
| 40 } | |
| 41 | |
| 42 } // namespace anonymous | |
| 43 | |
| 44 namespace gpu_info_collector { | |
| 45 | |
| 46 bool CollectGraphicsInfo(GPUInfo* gpu_info) { | |
| 47 DCHECK(gpu_info); | |
| 48 | |
| 49 gpu_info->can_lose_context = | |
| 50 (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2); | |
| 51 gpu_info-> level = GPUInfo::kComplete; | |
| 52 return CollectGraphicsInfoGL(gpu_info); | |
| 53 } | |
| 54 | |
| 55 bool CollectPreliminaryGraphicsInfo(GPUInfo* gpu_info) { | |
| 56 DCHECK(gpu_info); | |
| 57 | |
| 58 gpu_info->level = GPUInfo::kPartial; | |
| 59 | |
| 60 bool rt = true; | |
| 61 if (!CollectVideoCardInfo(gpu_info)) | |
| 62 rt = false; | |
| 63 | |
| 64 return rt; | |
| 65 } | |
| 66 | |
| 67 bool CollectVideoCardInfo(GPUInfo* gpu_info) { | |
| 68 DCHECK(gpu_info); | |
| 69 | |
| 70 UInt32 vendor_id = 0, device_id = 0; | |
| 71 io_registry_entry_t dsp_port = CGDisplayIOServicePort(kCGDirectMainDisplay); | |
| 72 CFTypeRef vendor_id_ref = SearchPortForProperty(dsp_port, CFSTR("vendor-id")); | |
| 73 if (vendor_id_ref) { | |
| 74 vendor_id = IntValueOfCFData((CFDataRef)vendor_id_ref); | |
| 75 CFRelease(vendor_id_ref); | |
| 76 } | |
| 77 CFTypeRef device_id_ref = SearchPortForProperty(dsp_port, CFSTR("device-id")); | |
| 78 if (device_id_ref) { | |
| 79 device_id = IntValueOfCFData((CFDataRef)device_id_ref); | |
| 80 CFRelease(device_id_ref); | |
| 81 } | |
| 82 | |
| 83 gpu_info->vendor_id = vendor_id; | |
| 84 gpu_info->device_id = device_id; | |
| 85 return true; | |
| 86 } | |
| 87 | |
| 88 bool CollectDriverInfoGL(GPUInfo* gpu_info) { | |
| 89 DCHECK(gpu_info); | |
| 90 | |
| 91 // Extract the OpenGL driver version string from the GL_VERSION string. | |
| 92 // Mac OpenGL drivers have the driver version | |
| 93 // at the end of the gl version string preceded by a dash. | |
| 94 // Use some jiggery-pokery to turn that utf8 string into a std::wstring. | |
| 95 std::string gl_version_string = gpu_info->gl_version_string; | |
| 96 size_t pos = gl_version_string.find_last_of('-'); | |
| 97 if (pos == std::string::npos) | |
| 98 return false; | |
| 99 gpu_info->driver_version = gl_version_string.substr(pos + 1); | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 103 } // namespace gpu_info_collector | |
| OLD | NEW |