summaryrefslogtreecommitdiffstats
path: root/gfx/angle/src/tests/third_party/gpu_test_expectations/gpu_test_config_mac.mm
blob: 8cbd49894bc06f282ce760df3e44d77734c9f4f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// gpu_test_config_mac.mm:
//   Helper functions for gpu_test_config that have to be compiled in ObjectiveC++

#include "gpu_test_config_mac.h"

#import <Cocoa/Cocoa.h>

namespace base {

void SysInfo::OperatingSystemVersionNumbers(
    int32 *major_version, int32 *minor_version, int32 *bugfix_version)
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
  Gestalt(gestaltSystemVersionMajor, reinterpret_cast<SInt32*>(major_version));
  Gestalt(gestaltSystemVersionMinor, reinterpret_cast<SInt32*>(minor_version));
  Gestalt(gestaltSystemVersionBugFix, reinterpret_cast<SInt32*>(bugfix_version));
#else
  NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
  *major_version = version.majorVersion;
  *minor_version = version.minorVersion;
  *bugfix_version = version.patchVersion;
#endif
}

} // namespace base

UInt32 GetEntryProperty(io_registry_entry_t entry, CFStringRef property_name) {
  CFTypeRef type = IORegistryEntrySearchCFProperty(entry,
                                                   kIOServicePlane,
                                                   property_name,
                                                   kCFAllocatorDefault,
                                                   kIORegistryIterateRecursively | kIORegistryIterateParents);
  CFDataRef data = reinterpret_cast<CFDataRef>(type);
  if (!data) {
    CFRelease(data);
    return 0;
  }

  UInt32 value = 0;
  const uint32_t* valuePointer = reinterpret_cast<const uint32_t*>(CFDataGetBytePtr(data));
  if (valuePointer != NULL) {
    value = *valuePointer;
  }
  CFRelease(data);
  return value;
}

gpu::GPUInfo::GPUDevice GetActiveGPU() {
  gpu::GPUInfo::GPUDevice gpu;

  // Ignore the fact that CGDisplayIOServicePort is deprecated as Apple
  // did not provide a good replacement for it as of 10.10.
  // TODO(cwallez) revisit with later systems
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    io_registry_entry_t dsp_port = CGDisplayIOServicePort(kCGDirectMainDisplay);
  #pragma clang diagnostic pop

  gpu.vendor_id = GetEntryProperty(dsp_port, CFSTR("vendor-id"));
  gpu.device_id = GetEntryProperty(dsp_port, CFSTR("device-id"));
  return gpu;
}