From d05cbc0af02bca3be8dd2f95a6a7bbd0edd7a3b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 11 Aug 2023 16:45:16 +0800 Subject: [PATCH] Monitor (macOS): detect HDR support --- CMakeLists.txt | 2 +- src/detection/monitor/monitor.h | 1 + .../{monitor_apple.c => monitor_apple.m} | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) rename src/detection/monitor/{monitor_apple.c => monitor_apple.m} (76%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 423f1df40..0326edecb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -541,7 +541,7 @@ elseif(APPLE) src/detection/gamepad/gamepad_apple.c src/detection/media/media_apple.m src/detection/memory/memory_apple.c - src/detection/monitor/monitor_apple.c + src/detection/monitor/monitor_apple.m src/detection/opengl/opengl_apple.c src/detection/os/os_apple.m src/detection/packages/packages_apple.c diff --git a/src/detection/monitor/monitor.h b/src/detection/monitor/monitor.h index 1fc514d90..8314c4cf4 100644 --- a/src/detection/monitor/monitor.h +++ b/src/detection/monitor/monitor.h @@ -7,6 +7,7 @@ typedef struct FFMonitorResult uint32_t height; // native / maximum resolution, in pixels uint32_t physicalWidth; // in mm uint32_t physicalHeight; // in mm + bool hdrCompatible; } FFMonitorResult; const char* ffDetectMonitor(FFlist* results); diff --git a/src/detection/monitor/monitor_apple.c b/src/detection/monitor/monitor_apple.m similarity index 76% rename from src/detection/monitor/monitor_apple.c rename to src/detection/monitor/monitor_apple.m index d022d825b..41e88ae58 100644 --- a/src/detection/monitor/monitor_apple.c +++ b/src/detection/monitor/monitor_apple.m @@ -4,6 +4,9 @@ #include "util/apple/ddcci.h" #include "util/edidHelper.h" +#import +#import + extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import)); static const char* detectWithDisplayServices(const FFDisplayServerResult* displayServer, FFlist* results) @@ -31,6 +34,30 @@ static const char* detectWithDisplayServices(const FFDisplayServerResult* displa CGSize size = CGDisplayScreenSize((CGDirectDisplayID) display->id); monitor->physicalWidth = (uint32_t) (size.width + 0.5); monitor->physicalHeight = (uint32_t) (size.height + 0.5); + monitor->hdrCompatible = false; + + if (CFDictionaryContainsKey(displayInfo, CFSTR("ReferencePeakHDRLuminance"))) + monitor->hdrCompatible = true; + else + { + NSScreen* mainScreen = NSScreen.mainScreen; + if (display->primary) + monitor->hdrCompatible = mainScreen.maximumPotentialExtendedDynamicRangeColorComponentValue > 1; + else + { + for (NSScreen* screen in NSScreen.screens) + { + if (screen == mainScreen) continue; + NSNumber* screenNumber = [screen.deviceDescription valueForKey:@"NSScreenNumber"]; + if (screenNumber && screenNumber.longValue == 1) + { + monitor->hdrCompatible = screen.maximumPotentialExtendedDynamicRangeColorComponentValue > 1; + break; + } + } + continue; + } + } } } } @@ -93,6 +120,7 @@ static const char* detectWithDdcci(FFlist* results) ffStrbufInit(&display->name); ffEdidGetName(edidData, &display->name); ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight); + monitor->hdrCompatible = false; } return NULL; }