core_graphics2/
direct_display.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use core_foundation::{array::CFArrayRef, base::CFTypeID, dictionary::CFDictionaryRef, string::CFStringRef};
use libc::{c_double, c_float, c_void, size_t};

use crate::{
    context::CGContextRef,
    error::CGError,
    geometry::{CGPoint, CGRect},
    image::CGImageRef,
};
#[cfg(feature = "window")]
use crate::{window::CGWindowID, window_level::CGWindowLevel};

pub type CGDirectDisplayID = u32;
pub type CGOpenGLDisplayMask = u32;
pub type CGRefreshRate = c_double;
pub type CGGammaValue = c_float;

#[repr(C)]
pub struct __CGDisplayMode(c_void);

pub type CGDisplayModeRef = *mut __CGDisplayMode;

pub const kCGNullDirectDisplay: CGDirectDisplayID = 0;

extern "C" {
    pub fn CGMainDisplayID() -> CGDirectDisplayID;
    pub fn CGGetDisplaysWithPoint(point: CGPoint, maxDisplays: u32, displays: *mut CGDirectDisplayID, matchingDisplayCount: *mut u32) -> CGError;
    pub fn CGGetDisplaysWithRect(rect: CGRect, maxDisplays: u32, displays: *mut CGDirectDisplayID, matchingDisplayCount: *mut u32) -> CGError;
    pub fn CGGetDisplaysWithOpenGLDisplayMask(
        mask: CGOpenGLDisplayMask,
        maxDisplays: u32,
        displays: *mut CGDirectDisplayID,
        matchingDisplayCount: *mut u32,
    ) -> CGError;
    pub fn CGGetActiveDisplayList(maxDisplays: u32, activeDisplays: *mut CGDirectDisplayID, displayCount: *mut u32) -> CGError;
    pub fn CGGetOnlineDisplayList(maxDisplays: u32, onlineDisplays: *mut CGDirectDisplayID, displayCount: *mut u32) -> CGError;
    pub fn CGDisplayIDToOpenGLDisplayMask(display: CGDirectDisplayID) -> CGOpenGLDisplayMask;
    pub fn CGOpenGLDisplayMaskToDisplayID(mask: CGOpenGLDisplayMask) -> CGDirectDisplayID;
    pub fn CGDisplayBounds(display: CGDirectDisplayID) -> CGRect;
    pub fn CGDisplayPixelsWide(display: CGDirectDisplayID) -> size_t;
    pub fn CGDisplayPixelsHigh(display: CGDirectDisplayID) -> size_t;
    pub fn CGDisplayCopyAllDisplayModes(display: CGDirectDisplayID, options: CFDictionaryRef) -> CFArrayRef;
    pub fn CGDisplayCopyDisplayMode(display: CGDirectDisplayID) -> CGDisplayModeRef;
    pub fn CGDisplaySetDisplayMode(display: CGDirectDisplayID, mode: CGDisplayModeRef, options: CFDictionaryRef) -> CGError;
    pub fn CGDisplayModeGetWidth(mode: CGDisplayModeRef) -> size_t;
    pub fn CGDisplayModeGetHeight(mode: CGDisplayModeRef) -> size_t;
    pub fn CGDisplayModeCopyPixelEncoding(mode: CGDisplayModeRef) -> CFStringRef;
    pub fn CGDisplayModeGetRefreshRate(mode: CGDisplayModeRef) -> CGRefreshRate;
    pub fn CGDisplayModeGetIOFlags(mode: CGDisplayModeRef) -> u32;
    pub fn CGDisplayModeGetIODisplayModeID(mode: CGDisplayModeRef) -> i32;
    pub fn CGDisplayModeIsUsableForDesktopGUI(mode: CGDisplayModeRef) -> bool;
    pub fn CGDisplayModeGetTypeID() -> CFTypeID;
    pub fn CGDisplayModeRetain(mode: CGDisplayModeRef) -> CGDisplayModeRef;
    pub fn CGDisplayModeRelease(mode: CGDisplayModeRef);
    pub fn CGDisplayModeGetPixelWidth(mode: CGDisplayModeRef) -> size_t;
    pub fn CGDisplayModeGetPixelHeight(mode: CGDisplayModeRef) -> size_t;
    pub fn CGSetDisplayTransferByFormula(
        display: CGDirectDisplayID,
        redMin: CGGammaValue,
        redMax: CGGammaValue,
        redGamma: CGGammaValue,
        greenMin: CGGammaValue,
        greenMax: CGGammaValue,
        greenGamma: CGGammaValue,
        blueMin: CGGammaValue,
        blueMax: CGGammaValue,
        blueGamma: CGGammaValue,
    ) -> CGError;
    pub fn CGGetDisplayTransferByFormula(
        display: CGDirectDisplayID,
        redMin: *mut CGGammaValue,
        redMax: *mut CGGammaValue,
        redGamma: *mut CGGammaValue,
        greenMin: *mut CGGammaValue,
        greenMax: *mut CGGammaValue,
        greenGamma: *mut CGGammaValue,
        blueMin: *mut CGGammaValue,
        blueMax: *mut CGGammaValue,
        blueGamma: *mut CGGammaValue,
    ) -> CGError;
    pub fn CGDisplayGammaTableCapacity(display: CGDirectDisplayID) -> u32;
    pub fn CGSetDisplayTransferByTable(
        display: CGDirectDisplayID,
        tableSize: u32,
        redTable: *const CGGammaValue,
        greenTable: *const CGGammaValue,
        blueTable: *const CGGammaValue,
    ) -> CGError;
    pub fn CGGetDisplayTransferByTable(
        display: CGDirectDisplayID,
        capacity: u32,
        redTable: *mut CGGammaValue,
        greenTable: *mut CGGammaValue,
        blueTable: *mut CGGammaValue,
        sampleCount: *mut u32,
    ) -> CGError;
    pub fn CGSetDisplayTransferByByteTable(
        display: CGDirectDisplayID,
        tableSize: u32,
        redTable: *const u8,
        greenTable: *const u8,
        blueTable: *const u8,
    ) -> CGError;
    pub fn CGDisplayRestoreColorSyncSettings();

    pub static kCGDisplayShowDuplicateLowResolutionModes: CFDictionaryRef;
}

bitflags! {
    #[repr(C)]
    #[derive(Clone, Copy, Debug, Default, PartialEq)]
    pub struct CGCaptureOptions: u32 {
        #[doc(alias = "kCGCaptureNoOptions")]
        const NoOptions = 0;
        #[doc(alias = "kCGCaptureNoFill")]
        const NoFill = 1;
    }
}

extern "C" {
    pub fn CGDisplayCapture(display: CGDirectDisplayID) -> CGError;
    pub fn CGDisplayCaptureWithOptions(display: CGDirectDisplayID, options: CGCaptureOptions) -> CGError;
    pub fn CGDisplayRelease(display: CGDirectDisplayID) -> CGError;
    pub fn CGCaptureAllDisplays() -> CGError;
    pub fn CGCaptureAllDisplaysWithOptions(options: CGCaptureOptions) -> CGError;
    pub fn CGReleaseAllDisplays() -> CGError;
    #[cfg(feature = "window")]
    pub fn CGShieldingWindowID(display: CGDirectDisplayID) -> CGWindowID;
    #[cfg(feature = "window")]
    pub fn CGShieldingWindowLevel() -> CGWindowLevel;
    pub fn CGDisplayCreateImage(display: CGDirectDisplayID) -> CGImageRef;
    pub fn CGDisplayCreateImageForRect(display: CGDirectDisplayID, rect: CGRect) -> CGImageRef;
    pub fn CGDisplayHideCursor(display: CGDirectDisplayID) -> CGError;
    pub fn CGDisplayShowCursor(display: CGDirectDisplayID) -> CGError;
    pub fn CGDisplayMoveCursorToPoint(display: CGDirectDisplayID, point: CGPoint) -> CGError;
    pub fn CGGetLastMouseDelta(deltaX: *mut i32, deltaY: *mut i32) -> CGError;
    pub fn CGDisplayGetDrawingContext(display: CGDirectDisplayID) -> CGContextRef;
}