|
9 | 9 |
|
10 | 10 | extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import)); |
11 | 11 |
|
12 | | -static const char* detectWithDisplayServices(const FFDisplayServerResult* displayServer, FFlist* results) |
| 12 | +static bool detectHdrSupportWithNSScreen(FFDisplayResult* display) |
13 | 13 | { |
14 | | - if(!CoreDisplay_DisplayCreateInfoDictionary) return "CoreDisplay_DisplayCreateInfoDictionary is not available"; |
15 | | - |
16 | | - FF_LIST_FOR_EACH(FFDisplayResult, display, displayServer->displays) |
| 14 | + NSScreen* mainScreen = NSScreen.mainScreen; |
| 15 | + if (display->primary) |
| 16 | + return mainScreen.maximumPotentialExtendedDynamicRangeColorComponentValue > 1; |
| 17 | + else |
17 | 18 | { |
18 | | - if (display->type == FF_DISPLAY_TYPE_BUILTIN) |
| 19 | + for (NSScreen* screen in NSScreen.screens) |
19 | 20 | { |
20 | | - CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_DisplayCreateInfoDictionary((CGDirectDisplayID) display->id); |
21 | | - if(displayInfo) |
| 21 | + if (screen == mainScreen) continue; |
| 22 | + NSNumber* screenNumber = [screen.deviceDescription valueForKey:@"NSScreenNumber"]; |
| 23 | + if (screenNumber && screenNumber.longValue == (long) display->id) |
22 | 24 | { |
23 | | - int width, height; |
24 | | - if (ffCfDictGetInt(displayInfo, CFSTR("kCGDisplayPixelWidth"), &width) || // Default resolution (limited by connectors, GPUs, etc.) |
25 | | - ffCfDictGetInt(displayInfo, CFSTR("kCGDisplayPixelHeight"), &height) || |
26 | | - width <= 0 || height <= 0) |
27 | | - continue; |
28 | | - |
29 | | - FFMonitorResult* monitor = (FFMonitorResult*) ffListAdd(results); |
30 | | - monitor->width = (uint32_t) width; |
31 | | - monitor->height = (uint32_t) height; |
32 | | - ffStrbufInitCopy(&monitor->name, &display->name); |
33 | | - |
34 | | - CGSize size = CGDisplayScreenSize((CGDirectDisplayID) display->id); |
35 | | - monitor->physicalWidth = (uint32_t) (size.width + 0.5); |
36 | | - monitor->physicalHeight = (uint32_t) (size.height + 0.5); |
37 | | - monitor->hdrCompatible = false; |
38 | | - |
39 | | - if (CFDictionaryContainsKey(displayInfo, CFSTR("ReferencePeakHDRLuminance"))) |
40 | | - monitor->hdrCompatible = true; |
41 | | - else |
42 | | - { |
43 | | - NSScreen* mainScreen = NSScreen.mainScreen; |
44 | | - if (display->primary) |
45 | | - monitor->hdrCompatible = mainScreen.maximumPotentialExtendedDynamicRangeColorComponentValue > 1; |
46 | | - else |
47 | | - { |
48 | | - for (NSScreen* screen in NSScreen.screens) |
49 | | - { |
50 | | - if (screen == mainScreen) continue; |
51 | | - NSNumber* screenNumber = [screen.deviceDescription valueForKey:@"NSScreenNumber"]; |
52 | | - if (screenNumber && screenNumber.longValue == (long) display->id) |
53 | | - { |
54 | | - monitor->hdrCompatible = screen.maximumPotentialExtendedDynamicRangeColorComponentValue > 1; |
55 | | - break; |
56 | | - } |
57 | | - } |
58 | | - continue; |
59 | | - } |
60 | | - } |
| 25 | + return screen.maximumPotentialExtendedDynamicRangeColorComponentValue > 1; |
61 | 26 | } |
62 | 27 | } |
63 | 28 | } |
64 | | - return NULL; |
| 29 | + return false; |
65 | 30 | } |
66 | 31 |
|
67 | | -static const char* detectWithDdcci(FFlist* results) |
| 32 | +const char* ffDetectMonitor(FFlist* results) |
68 | 33 | { |
69 | | - if (!IOAVServiceCreate || !IOAVServiceReadI2C) |
70 | | - return "IOAVService is not available"; |
71 | | - |
72 | | - CFMutableDictionaryRef matchDict = IOServiceMatching("DCPAVServiceProxy"); |
73 | | - if (matchDict == NULL) |
74 | | - return "IOServiceMatching(\"DCPAVServiceProxy\") failed"; |
75 | | - |
76 | | - io_iterator_t iterator; |
77 | | - if(IOServiceGetMatchingServices(MACH_PORT_NULL, matchDict, &iterator) != kIOReturnSuccess) |
78 | | - return "IOServiceGetMatchingServices() failed"; |
| 34 | + if(!CoreDisplay_DisplayCreateInfoDictionary) return "CoreDisplay_DisplayCreateInfoDictionary is not available"; |
79 | 35 |
|
80 | | - FF_STRBUF_AUTO_DESTROY location = ffStrbufCreate(); |
| 36 | + const FFDisplayServerResult* displayServer = ffConnectDisplayServer(); |
81 | 37 |
|
82 | | - io_registry_entry_t registryEntry; |
83 | | - while((registryEntry = IOIteratorNext(iterator)) != 0) |
| 38 | + FF_LIST_FOR_EACH(FFDisplayResult, display, displayServer->displays) |
84 | 39 | { |
85 | | - CFMutableDictionaryRef properties; |
86 | | - if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) |
87 | | - { |
88 | | - IOObjectRelease(registryEntry); |
89 | | - continue; |
90 | | - } |
| 40 | + CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_DisplayCreateInfoDictionary((CGDirectDisplayID) display->id); |
| 41 | + if(!displayInfo) continue; |
91 | 42 |
|
92 | | - ffStrbufClear(&location); |
93 | | - if(ffCfDictGetString(properties, CFSTR("Location"), &location) || ffStrbufEqualS(&location, "Embedded")) |
| 43 | + uint8_t edidData[128] = {}; |
| 44 | + uint32_t edidLength = 0; |
| 45 | + if (false || !ffCfDictGetData(displayInfo, CFSTR("IODisplayEDID"), 0, sizeof(edidData), edidData, &edidLength)) |
94 | 46 | { |
95 | | - // Builtin display should be handled by DisplayServices |
96 | | - IOObjectRelease(registryEntry); |
97 | | - continue; |
| 47 | + uint32_t width, height; |
| 48 | + ffEdidGetPhysicalResolution(edidData, &width, &height); |
| 49 | + if (width > 0 && height > 0) |
| 50 | + { |
| 51 | + FFMonitorResult* monitor = (FFMonitorResult*) ffListAdd(results); |
| 52 | + ffStrbufInitCopy(&monitor->name, &display->name); |
| 53 | + monitor->width = width; |
| 54 | + monitor->height = height; |
| 55 | + ffEdidGetPhysicalSize(edidData, &monitor->physicalWidth, &monitor->physicalHeight); |
| 56 | + monitor->hdrCompatible = CFDictionaryContainsKey(displayInfo, CFSTR("ReferencePeakHDRLuminance")) || |
| 57 | + detectHdrSupportWithNSScreen(display); |
| 58 | + continue; |
| 59 | + } |
98 | 60 | } |
99 | 61 |
|
100 | | - FF_CFTYPE_AUTO_RELEASE IOAVServiceRef service = IOAVServiceCreateWithService(kCFAllocatorDefault, (io_service_t) registryEntry); |
101 | | - IOObjectRelease(registryEntry); |
102 | | - |
103 | | - if (!service) continue; |
104 | | - |
105 | | - FF_CFTYPE_AUTO_RELEASE CFDataRef edid = NULL; |
106 | | - if (IOAVServiceCopyEDID(service, &edid) != KERN_SUCCESS) |
107 | | - continue; |
108 | | - |
109 | | - uint32_t edidLength = (uint32_t) CFDataGetLength(edid); |
110 | | - if (edidLength == 0 || edidLength % 128 != 0) |
| 62 | + int width, height; |
| 63 | + if (ffCfDictGetInt(displayInfo, CFSTR("kCGDisplayPixelWidth"), &width) || // Default resolution (limited by connectors, GPUs, etc.) |
| 64 | + ffCfDictGetInt(displayInfo, CFSTR("kCGDisplayPixelHeight"), &height) || |
| 65 | + width <= 0 || height <= 0) |
111 | 66 | continue; |
112 | 67 |
|
113 | | - uint32_t width, height; |
114 | | - const uint8_t* edidData = CFDataGetBytePtr(edid); |
| 68 | + FFMonitorResult* monitor = (FFMonitorResult*) ffListAdd(results); |
| 69 | + monitor->width = (uint32_t) width; |
| 70 | + monitor->height = (uint32_t) height; |
| 71 | + ffStrbufInitCopy(&monitor->name, &display->name); |
115 | 72 |
|
116 | | - ffEdidGetPhysicalResolution(edidData, &width, &height); |
117 | | - if (width == 0 || height == 0) continue; |
118 | | - |
119 | | - FFMonitorResult* display = (FFMonitorResult*) ffListAdd(results); |
120 | | - display->width = width; |
121 | | - display->height = height; |
122 | | - ffStrbufInit(&display->name); |
123 | | - ffEdidGetName(edidData, &display->name); |
124 | | - ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight); |
125 | | - display->hdrCompatible = ffEdidGetHdrCompatible(edidData, edidLength); |
| 73 | + CGSize size = CGDisplayScreenSize((CGDirectDisplayID) display->id); |
| 74 | + monitor->physicalWidth = (uint32_t) (size.width + 0.5); |
| 75 | + monitor->physicalHeight = (uint32_t) (size.height + 0.5); |
| 76 | + monitor->hdrCompatible = CFDictionaryContainsKey(displayInfo, CFSTR("ReferencePeakHDRLuminance")) || |
| 77 | + detectHdrSupportWithNSScreen(display); |
126 | 78 | } |
127 | | - return NULL; |
128 | | -} |
129 | | - |
130 | | -const char* ffDetectMonitor(FFlist* results) |
131 | | -{ |
132 | | - const FFDisplayServerResult* displayServer = ffConnectDisplayServer(); |
133 | | - |
134 | | - detectWithDisplayServices(displayServer, results); |
135 | 79 |
|
136 | | - if (displayServer->displays.length > results->length) |
137 | | - detectWithDdcci(results); |
138 | 80 | return NULL; |
139 | 81 | } |
0 commit comments