Skip to content

Commit ea18d93

Browse files
committed
Display / Monitor (macOS): code refactor
1 parent f6e1e5c commit ea18d93

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

src/detection/displayserver/displayserver_apple.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
#include <CoreGraphics/CGDirectDisplay.h>
99
#include <CoreVideo/CVDisplayLink.h>
1010

11+
#ifdef MAC_OS_X_VERSION_10_15
1112
extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import));
12-
#ifndef MAC_OS_X_VERSION_10_15
13-
#import <IOKit/graphics/IOGraphicsLib.h>
14-
extern CFDictionaryRef CoreDisplay_IODisplayCreateInfoDictionary(io_service_t framebuffer, IOOptionBits options) __attribute__((weak_import));
13+
extern Boolean CoreDisplay_Display_IsHDRModeEnabled(CGDirectDisplayID display) __attribute__((weak_import));
14+
#else
15+
#include <IOKit/graphics/IOGraphicsLib.h>
1516
#endif
1617

1718
static void detectDisplays(FFDisplayServerResult* ds)
@@ -43,30 +44,22 @@ static void detectDisplays(FFDisplayServerResult* ds)
4344
}
4445

4546
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
47+
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = NULL;
4648
#ifdef MAC_OS_X_VERSION_10_15
4749
if(CoreDisplay_DisplayCreateInfoDictionary)
48-
{
49-
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_DisplayCreateInfoDictionary(screen);
50-
if(displayInfo)
51-
{
52-
CFDictionaryRef productNames;
53-
if(!ffCfDictGetDict(displayInfo, CFSTR(kDisplayProductName), &productNames))
54-
ffCfDictGetString(productNames, CFSTR("en_US"), &name);
55-
}
56-
}
50+
displayInfo = CoreDisplay_DisplayCreateInfoDictionary(screen);
5751
#else
58-
if(CoreDisplay_IODisplayCreateInfoDictionary)
5952
{
6053
io_service_t servicePort = CGDisplayIOServicePort(screen);
61-
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);
62-
if(displayInfo)
63-
{
64-
CFDictionaryRef productNames;
65-
if(!ffCfDictGetDict(displayInfo, CFSTR(kDisplayProductName), &productNames))
66-
ffCfDictGetString(productNames, CFSTR("en_US"), &name);
67-
}
54+
displayInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);
6855
}
6956
#endif
57+
if(displayInfo)
58+
{
59+
CFDictionaryRef productNames;
60+
if(!ffCfDictGetDict(displayInfo, CFSTR(kDisplayProductName), &productNames))
61+
ffCfDictGetString(productNames, CFSTR("en_US"), &name);
62+
}
7063

7164
CGSize size = CGDisplayScreenSize(screen);
7265

@@ -95,6 +88,11 @@ static void detectDisplays(FFDisplayServerResult* ds)
9588
ffCfDictGetInt(dict, kCGDisplayBitsPerSample, &bitDepth);
9689
display->bitDepth = (uint8_t) bitDepth;
9790
}
91+
92+
if (CoreDisplay_Display_IsHDRModeEnabled)
93+
{
94+
display->hdrEnabled = CoreDisplay_Display_IsHDRModeEnabled(screen);
95+
}
9896
}
9997
CGDisplayModeRelease(mode);
10098
}

src/detection/monitor/monitor_apple.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
#import <Foundation/Foundation.h>
88
#import <CoreGraphics/CoreGraphics.h>
99

10+
#ifdef MAC_OS_X_VERSION_10_15
1011
extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import));
11-
12-
#ifndef MAC_OS_X_VERSION_10_15
13-
#import <IOKit/graphics/IOGraphicsLib.h>
14-
extern CFDictionaryRef CoreDisplay_IODisplayCreateInfoDictionary(io_service_t framebuffer, IOOptionBits options) __attribute__((weak_import));
12+
#else
13+
#include <IOKit/graphics/IOGraphicsLib.h>
1514
#endif
1615

1716
static bool detectHdrSupportWithNSScreen(FFDisplayResult* display)
@@ -57,7 +56,7 @@ static bool detectHdrSupportWithNSScreen(FFDisplayResult* display)
5756
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_DisplayCreateInfoDictionary((CGDirectDisplayID) display->id);
5857
#else
5958
io_service_t servicePort = CGDisplayIOServicePort((CGDirectDisplayID) display->id);
60-
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);
59+
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);
6160
#endif
6261
if(!displayInfo) continue;
6362

@@ -67,7 +66,7 @@ static bool detectHdrSupportWithNSScreen(FFDisplayResult* display)
6766

6867
uint8_t edidData[128] = {};
6968
uint32_t edidLength = 0;
70-
if (ffCfDictGetData(displayInfo, CFSTR("IODisplayEDID"), 0, sizeof(edidData), edidData, &edidLength) == NULL)
69+
if (ffCfDictGetData(displayInfo, CFSTR(kIODisplayEDIDKey), 0, sizeof(edidData), edidData, &edidLength) == NULL)
7170
{
7271
uint32_t width, height;
7372
ffEdidGetPhysicalResolution(edidData, &width, &height);

0 commit comments

Comments
 (0)