1// Copyright (c) 2012 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// gpu_test_config_mac.mm: 6// Helper functions for gpu_test_config that have to be compiled in ObjectiveC++ 7 8#include "gpu_test_config_mac.h" 9 10#import <Cocoa/Cocoa.h> 11 12namespace base { 13 14void SysInfo::OperatingSystemVersionNumbers( 15 int32 *major_version, int32 *minor_version, int32 *bugfix_version) 16{ 17#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 18 Gestalt(gestaltSystemVersionMajor, reinterpret_cast<SInt32*>(major_version)); 19 Gestalt(gestaltSystemVersionMinor, reinterpret_cast<SInt32*>(minor_version)); 20 Gestalt(gestaltSystemVersionBugFix, reinterpret_cast<SInt32*>(bugfix_version)); 21#else 22 NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; 23 *major_version = version.majorVersion; 24 *minor_version = version.minorVersion; 25 *bugfix_version = version.patchVersion; 26#endif 27} 28 29} // namespace base 30 31UInt32 GetEntryProperty(io_registry_entry_t entry, CFStringRef property_name) { 32 CFTypeRef type = IORegistryEntrySearchCFProperty(entry, 33 kIOServicePlane, 34 property_name, 35 kCFAllocatorDefault, 36 kIORegistryIterateRecursively | kIORegistryIterateParents); 37 CFDataRef data = reinterpret_cast<CFDataRef>(type); 38 if (!data) { 39 CFRelease(data); 40 return 0; 41 } 42 43 UInt32 value = 0; 44 const uint32_t* valuePointer = reinterpret_cast<const uint32_t*>(CFDataGetBytePtr(data)); 45 if (valuePointer != NULL) { 46 value = *valuePointer; 47 } 48 CFRelease(data); 49 return value; 50} 51 52gpu::GPUInfo::GPUDevice GetActiveGPU() { 53 gpu::GPUInfo::GPUDevice gpu; 54 55 // Ignore the fact that CGDisplayIOServicePort is deprecated as Apple 56 // did not provide a good replacement for it as of 10.10. 57 // TODO(cwallez) revisit with later systems 58 #pragma clang diagnostic push 59 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 60 io_registry_entry_t dsp_port = CGDisplayIOServicePort(kCGDirectMainDisplay); 61 #pragma clang diagnostic pop 62 63 gpu.vendor_id = GetEntryProperty(dsp_port, CFSTR("vendor-id")); 64 gpu.device_id = GetEntryProperty(dsp_port, CFSTR("device-id")); 65 return gpu; 66} 67 68