MythTV master
mythutilscocoa.mm
Go to the documentation of this file.
1// MythTV
2#include "libmythbase/mythconfig.h"
3#include "mythutilscocoa.h"
4
5// OSX
6#import <Cocoa/Cocoa.h>
7#import <IOKit/graphics/IOGraphicsLib.h>
8#include <AvailabilityMacros.h>
9
10#if !HAVE_IOMAINPORT
11#define kIOMainPortDefault kIOMasterPortDefault
12#endif
13
14CGDirectDisplayID GetOSXCocoaDisplay(void* View)
15{
16 NSView *thisview = static_cast<NSView *>(View);
17 if (!thisview)
18 return 0;
19 NSScreen *screen = [[thisview window] screen];
20 if (!screen)
21 return 0;
22 NSDictionary* desc = [screen deviceDescription];
23 return (CGDirectDisplayID)[[desc objectForKey:@"NSScreenNumber"] intValue];
24}
25
26static Boolean CFNumberEqualsUInt32(CFNumberRef Number, uint32_t Uint32)
27{
28 if (Number == nullptr)
29 return (Uint32 == 0);
30 int64_t Int64;
31 if (!CFNumberGetValue(Number, kCFNumberSInt64Type, &Int64))
32 return false;
33 return Int64 == Uint32;
34}
35
36QByteArray GetOSXEDID(CGDirectDisplayID Display)
37{
38 QByteArray result;
39 if (!Display)
40 return result;
41
42 uint32_t vendor = CGDisplayVendorNumber(Display);
43 uint32_t model = CGDisplayModelNumber(Display);
44 uint32_t serial = CGDisplaySerialNumber(Display);
45 CFMutableDictionaryRef matching = IOServiceMatching("IODisplayConnect");
46
47 io_iterator_t iter;
48 if (IOServiceGetMatchingServices(kIOMainPortDefault, matching, &iter))
49 return result;
50
51 io_service_t service = 0;
52 while ((service = IOIteratorNext(iter)) != 0)
53 {
54 CFDictionaryRef info = IODisplayCreateInfoDictionary(service, kIODisplayOnlyPreferredName);
55 CFNumberRef vendorID = static_cast<CFNumberRef>(CFDictionaryGetValue(info, CFSTR(kDisplayVendorID)));
56 CFNumberRef productID = static_cast<CFNumberRef>(CFDictionaryGetValue(info, CFSTR(kDisplayProductID)));
57 CFNumberRef serialNumber = static_cast<CFNumberRef>(CFDictionaryGetValue(info, CFSTR(kDisplaySerialNumber)));
58
59 if (CFNumberEqualsUInt32(vendorID, vendor) &&
60 CFNumberEqualsUInt32(productID, model) &&
61 CFNumberEqualsUInt32(serialNumber, serial))
62 {
63 CFDataRef edid = static_cast<CFDataRef>(CFDictionaryGetValue(info, CFSTR(kIODisplayEDIDKey)));
64 if (edid)
65 {
66 const char* data = reinterpret_cast<const char*>(CFDataGetBytePtr(edid));
67 int length = CFDataGetLength(edid);
68 result = QByteArray(data, length);
69 }
70 CFRelease(info);
71 break;
72 }
73 CFRelease(info);
74 }
75 IOObjectRelease(iter);
76 return result;
77}
CGDirectDisplayID GetOSXCocoaDisplay(void *View)
#define kIOMainPortDefault
static Boolean CFNumberEqualsUInt32(CFNumberRef Number, uint32_t Uint32)
QByteArray GetOSXEDID(CGDirectDisplayID Display)
dictionary info
Definition: azlyrics.py:7