5
5
#include <OpenGL/OpenGL.h>
6
6
#include <OpenGL/gl.h>
7
7
#include <ApplicationServices/ApplicationServices.h>
8
+ #include <ScreenCaptureKit/ScreenCaptureKit.h>
8
9
#elif defined(USE_X11 )
9
10
#include <X11/Xlib.h>
10
11
#include <X11/Xutil.h>
13
14
#include <string.h>
14
15
#endif
15
16
17
+ #if defined(IS_MACOSX ) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > MAC_OS_VERSION_14_4
18
+ static CGImageRef capture15 (CGDirectDisplayID id , CGRect diIntersectDisplayLocal , CGColorSpaceRef colorSpace ) {
19
+ dispatch_semaphore_t semaphore = dispatch_semaphore_create (0 );
20
+ __block CGImageRef image1 = nil ;
21
+ [SCShareableContent getShareableContentWithCompletionHandler :^(SCShareableContent * content , NSError * error ) {
22
+ @autoreleasepool {
23
+ if (error ) {
24
+ dispatch_semaphore_signal (semaphore );
25
+ return ;
26
+ }
27
+ SCDisplay * target = nil ;
28
+ for (SCDisplay * display in content .displays ) {
29
+ if (display .displayID == id ) {
30
+ target = display ;
31
+ break ;
32
+ }
33
+ }
34
+ if (!target ) {
35
+ dispatch_semaphore_signal (semaphore );
36
+ return ;
37
+ }
38
+
39
+ SCContentFilter * filter = [[SCContentFilter alloc ] initWithDisplay :target excludingWindows :@[]];
40
+ SCStreamConfiguration * config = [[SCStreamConfiguration alloc ] init ];
41
+ config .sourceRect = diIntersectDisplayLocal ;
42
+ config .width = diIntersectDisplayLocal .size .width ;
43
+ config .height = diIntersectDisplayLocal .size .height ;
44
+ [SCScreenshotManager captureImageWithFilter :filter
45
+ configuration :config
46
+ completionHandler :^(CGImageRef img , NSError * error ) {
47
+ if (!error ) {
48
+ image1 = CGImageCreateCopyWithColorSpace (img , colorSpace );
49
+ }
50
+ dispatch_semaphore_signal (semaphore );
51
+ }];
52
+ }
53
+ }];
54
+ dispatch_semaphore_wait (semaphore , DISPATCH_TIME_FOREVER );
55
+ dispatch_release (semaphore );
56
+ return image1 ;
57
+ }
58
+ #endif
59
+
16
60
MMBitmapRef copyMMBitmapFromDisplayInRect (MMRectInt32 rect , int32_t display_id , int8_t isPid ) {
17
61
#if defined(IS_MACOSX )
18
62
MMBitmapRef bitmap = NULL ;
@@ -25,9 +69,16 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id,
25
69
}
26
70
27
71
MMPointInt32 o = rect .origin ; MMSizeInt32 s = rect .size ;
28
- CGImageRef image = CGDisplayCreateImageForRect (displayID , CGRectMake (o .x , o .y , s .w , s .h ));
72
+ #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > MAC_OS_VERSION_14_4
73
+ CGColorSpaceRef color = CGColorSpaceCreateWithName (kCGColorSpaceSRGB );
74
+ CGImageRef image = capture15 (displayID , CGRectMake (o .x , o .y , s .w , s .h ), color );
75
+ CGColorSpaceRelease (color );
76
+ #else
77
+ // This API is deprecated in macos 15, use ScreenCaptureKit's captureScreenshot
78
+ CGImageRef image = CGDisplayCreateImageForRect (displayID , CGRectMake (o .x , o .y , s .w , s .h ));
79
+ #endif
29
80
if (!image ) { return NULL ; }
30
-
81
+
31
82
CFDataRef imageData = CGDataProviderCopyData (CGImageGetDataProvider (image ));
32
83
if (!imageData ) { return NULL ; }
33
84
0 commit comments