Skip to main content

apple_cf/cg/
mod.rs

1//! Core Graphics types for screen coordinates, dimensions, and bitmap drawing.
2//!
3//! This module provides Rust equivalents of Core Graphics types used in
4//! `ScreenCaptureKit` plus safe wrappers for the most common offscreen drawing
5//! APIs (`CGColorSpace`, `CGImage`, and `CGContext`).
6
7mod affine;
8mod context;
9mod drawing;
10mod point;
11mod rect;
12mod size;
13
14/// Low-level FFI declarations used by the safe wrappers.
15pub(crate) mod ffi {
16    use core::ffi::c_void;
17
18    use super::rect::CGRect;
19
20    #[link(name = "ApplicationServices", kind = "framework")]
21    extern "C" {
22        /// Apple SDK function `CGColorSpaceCreateDeviceRGB`.
23        pub(crate) fn CGColorSpaceCreateDeviceRGB() -> *mut c_void;
24        /// Apple SDK function `CGColorSpaceCreateDeviceGray`.
25        pub(crate) fn CGColorSpaceCreateDeviceGray() -> *mut c_void;
26        /// Apple SDK function `CGColorSpaceCreateWithName`.
27        pub(crate) fn CGColorSpaceCreateWithName(name: *const c_void) -> *mut c_void;
28        /// Apple SDK function `CGColorSpaceRelease`.
29        pub(crate) fn CGColorSpaceRelease(cs: *mut c_void);
30        /// Apple SDK function `CGColorSpaceRetain`.
31        pub(crate) fn CGColorSpaceRetain(cs: *mut c_void) -> *mut c_void;
32        /// Apple SDK function `CGColorSpaceGetNumberOfComponents`.
33        pub(crate) fn CGColorSpaceGetNumberOfComponents(cs: *mut c_void) -> usize;
34
35        /// Apple SDK function `CGImageGetWidth`.
36        pub(crate) fn CGImageGetWidth(image: *mut c_void) -> usize;
37        /// Apple SDK function `CGImageGetHeight`.
38        pub(crate) fn CGImageGetHeight(image: *mut c_void) -> usize;
39        /// Apple SDK function `CGImageGetBitsPerComponent`.
40        pub(crate) fn CGImageGetBitsPerComponent(image: *mut c_void) -> usize;
41        /// Apple SDK function `CGImageGetBitsPerPixel`.
42        pub(crate) fn CGImageGetBitsPerPixel(image: *mut c_void) -> usize;
43        /// Apple SDK function `CGImageGetBytesPerRow`.
44        pub(crate) fn CGImageGetBytesPerRow(image: *mut c_void) -> usize;
45        /// Apple SDK function `CGImageRelease`.
46        pub(crate) fn CGImageRelease(image: *mut c_void);
47        /// Apple SDK function `CGImageRetain`.
48        pub(crate) fn CGImageRetain(image: *mut c_void) -> *mut c_void;
49
50        /// Apple SDK function `CGBitmapContextCreate`.
51        pub(crate) fn CGBitmapContextCreate(
52            data: *mut c_void,
53            width: usize,
54            height: usize,
55            bits_per_component: usize,
56            bytes_per_row: usize,
57            space: *mut c_void,
58            bitmap_info: u32,
59        ) -> *mut c_void;
60        /// Apple SDK function `CGBitmapContextGetData`.
61        pub(crate) fn CGBitmapContextGetData(context: *mut c_void) -> *mut c_void;
62        /// Apple SDK function `CGBitmapContextGetWidth`.
63        pub(crate) fn CGBitmapContextGetWidth(context: *mut c_void) -> usize;
64        /// Apple SDK function `CGBitmapContextGetHeight`.
65        pub(crate) fn CGBitmapContextGetHeight(context: *mut c_void) -> usize;
66        /// Apple SDK function `CGBitmapContextGetBitsPerComponent`.
67        pub(crate) fn CGBitmapContextGetBitsPerComponent(context: *mut c_void) -> usize;
68        /// Apple SDK function `CGBitmapContextGetBitsPerPixel`.
69        pub(crate) fn CGBitmapContextGetBitsPerPixel(context: *mut c_void) -> usize;
70        /// Apple SDK function `CGBitmapContextGetBytesPerRow`.
71        pub(crate) fn CGBitmapContextGetBytesPerRow(context: *mut c_void) -> usize;
72        /// Apple SDK function `CGBitmapContextGetColorSpace`.
73        pub(crate) fn CGBitmapContextGetColorSpace(context: *mut c_void) -> *mut c_void;
74        /// Apple SDK function `CGBitmapContextGetAlphaInfo`.
75        pub(crate) fn CGBitmapContextGetAlphaInfo(context: *mut c_void) -> u32;
76        /// Apple SDK function `CGBitmapContextCreateImage`.
77        pub(crate) fn CGBitmapContextCreateImage(context: *mut c_void) -> *mut c_void;
78
79        /// Apple SDK function `CGContextRetain`.
80        pub(crate) fn CGContextRetain(context: *mut c_void) -> *mut c_void;
81        /// Apple SDK function `CGContextRelease`.
82        pub(crate) fn CGContextRelease(context: *mut c_void);
83        /// Apple SDK function `CGContextSetRGBFillColor`.
84        pub(crate) fn CGContextSetRGBFillColor(
85            context: *mut c_void,
86            red: f64,
87            green: f64,
88            blue: f64,
89            alpha: f64,
90        );
91        /// Apple SDK function `CGContextSetRGBStrokeColor`.
92        pub(crate) fn CGContextSetRGBStrokeColor(
93            context: *mut c_void,
94            red: f64,
95            green: f64,
96            blue: f64,
97            alpha: f64,
98        );
99        /// Apple SDK function `CGContextSetLineWidth`.
100        pub(crate) fn CGContextSetLineWidth(context: *mut c_void, width: f64);
101        /// Apple SDK function `CGContextFillRect`.
102        pub(crate) fn CGContextFillRect(context: *mut c_void, rect: CGRect);
103        /// Apple SDK function `CGContextStrokeRect`.
104        pub(crate) fn CGContextStrokeRect(context: *mut c_void, rect: CGRect);
105        /// Apple SDK function `CGContextFillPath`.
106        pub(crate) fn CGContextFillPath(context: *mut c_void);
107        /// Apple SDK function `CGContextStrokePath`.
108        pub(crate) fn CGContextStrokePath(context: *mut c_void);
109        /// Apple SDK function `CGContextClearRect`.
110        pub(crate) fn CGContextClearRect(context: *mut c_void, rect: CGRect);
111        /// Apple SDK function `CGContextMoveToPoint`.
112        pub(crate) fn CGContextMoveToPoint(context: *mut c_void, x: f64, y: f64);
113        /// Apple SDK function `CGContextAddLineToPoint`.
114        pub(crate) fn CGContextAddLineToPoint(context: *mut c_void, x: f64, y: f64);
115        /// Apple SDK function `CGContextAddRect`.
116        pub(crate) fn CGContextAddRect(context: *mut c_void, rect: CGRect);
117        /// Apple SDK function `CGContextAddEllipseInRect`.
118        pub(crate) fn CGContextAddEllipseInRect(context: *mut c_void, rect: CGRect);
119        /// Apple SDK function `CGContextBeginPath`.
120        pub(crate) fn CGContextBeginPath(context: *mut c_void);
121        /// Apple SDK function `CGContextClosePath`.
122        pub(crate) fn CGContextClosePath(context: *mut c_void);
123        /// Apple SDK function `CGContextDrawImage`.
124        pub(crate) fn CGContextDrawImage(context: *mut c_void, rect: CGRect, image: *mut c_void);
125        /// Apple SDK function `CGContextTranslateCTM`.
126        pub(crate) fn CGContextTranslateCTM(context: *mut c_void, tx: f64, ty: f64);
127        /// Apple SDK function `CGContextScaleCTM`.
128        pub(crate) fn CGContextScaleCTM(context: *mut c_void, sx: f64, sy: f64);
129        /// Apple SDK function `CGContextRotateCTM`.
130        pub(crate) fn CGContextRotateCTM(context: *mut c_void, radians: f64);
131        /// Apple SDK function `CGContextSaveGState`.
132        pub(crate) fn CGContextSaveGState(context: *mut c_void);
133        /// Apple SDK function `CGContextRestoreGState`.
134        pub(crate) fn CGContextRestoreGState(context: *mut c_void);
135    }
136}
137
138#[doc(inline)]
139pub use crate::raw::CGCharCode;
140#[doc(inline)]
141pub use crate::raw::CGContextRef;
142#[doc(inline)]
143pub use crate::raw::CGKeyCode;
144pub use affine::{CGAffineTransform, CGVector};
145pub use context::CGContext;
146pub use drawing::{CGColorSpace, CGImage};
147pub use point::CGPoint;
148pub use rect::CGRect;
149pub use size::CGSize;
150
151/// `CGDisplayID` type alias
152pub type CGDisplayID = u32;