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
//! Shared CoreGraphics FFI bindings and small paint helpers used by
//! (most of) the per-primitive rasterisers in [`super`].
//!
//! Before this module existed, 28 files under `src/macos/` each
//! declared their own private `extern "C"` block for the handful of
//! `CGContext*` entry points every rasteriser needs (save/restore
//! state, clip, set fill/stroke colour, fill/stroke a rect, stroke a
//! line), and 24 of them carried their own byte-identical
//! `color_to_cg`/`fill_rect`/`stroke_rect` copies plus (11 of them) a
//! `CGRectExt::new_xywh` trait shim for building a `CGRect` from
//! `(x, y, w, h)` (quadraui#1071). This module is the single source
//! of truth for all of that; per-file copies are deleted in favour of
//! a glob import (`use super::cg::*;`) so call sites are unchanged.
//!
//! `stroke_line` (and the `CGContextMoveToPoint`/`CGContextAddLineToPoint`/
//! `CGContextStrokePath` extern decls it alone used) was removed in #1077
//! once its only caller, `macos::tooltip`'s `TooltipBorder::Sides` arm,
//! moved onto `PaintSurface::surface_draw_line` (`CgSurface` →
//! `super::backend::ns_draw_line`) instead. `stroke_rect` (and the
//! `CGContextSetRGBStrokeColor`/`CGContextSetLineWidth`/`CGContextStrokeRect`
//! extern decls it alone used) was removed the same way once its last
//! caller, `macos::rich_text_popup`, moved onto
//! `PaintSurface::surface_stroke_rect` instead.
//!
//! Not every `src/macos/` file that touches CoreGraphics draws through
//! here — `backend.rs`, `board.rs`, `headless.rs`, `image.rs`,
//! `pipeline_view.rs`, `text.rs`, `toolbar.rs`, and a handful of other
//! small rasterisers (`activity_bar.rs`, `command_center.rs`,
//! `completions.rs`, `form.rs`, `list.rs`, `menu_bar.rs`, `minimap.rs`,
//! `progress.rs`, `run.rs`, `text_selection.rs`, `message_list.rs`,
//! `spinner.rs`) still carry their own copies of some or all of this
//! (some also need extra entry points — `CGContextTranslateCTM`,
//! path-construction for rounded rects, image drawing, font/text
//! layout — that this module intentionally does not take on). Folding
//! those in is tracked as a follow-up once a macOS host can verify
//! each one; this module covers the rasterisers that were already
//! byte-identical, which is what quadraui#1071 asks for.
//!
//! ## A divergence found while consolidating (reported per #1071's
//! ## "report any divergence" instruction, not silently resolved)
//!
//! `macos/minimap.rs`'s own `fill_rect` (out of scope here, still
//! local to that file) additionally early-returns on `w <= 0.0 || h <=
//! 0.0`, which none of the other 20 `fill_rect` copies did. This
//! module's [`fill_rect`] intentionally matches the *majority* shape
//! (unguarded) rather than picking `minimap.rs`'s; [`fill_rect_alpha`]
//! below *does* carry that guard because both of its two source copies
//! (`editor.rs`, `minimap.rs`) agreed on it.
use ;
use CGContextRef;
use crateColor;
extern "C"
/// Build a `CGRect` from `(x, y, w, h)` — replaces the `CGRectExt::new_xywh`
/// trait shim that used to be copy-pasted into 11 files.
pub
/// Decompose a [`Color`] into the `(r, g, b, a)` `f64` tuple
/// `CGContextSetRGB{Fill,Stroke}Color` expects, each channel scaled to
/// `0.0..=1.0`.
pub
/// Fill the rect `(x, y, w, h)` with `c` (using `c`'s own alpha).
///
/// # Safety
///
/// `ctx` must be a valid `CGContextRef` borrowed for the duration of
/// the call.
pub unsafe
/// Like [`fill_rect`], but the alpha channel is `alpha` instead of the
/// colour's own — mirrors GTK's `cr.set_source_rgba(r, g, b, alpha)`
/// for selection/overlay tints, where the opacity is carried separately
/// from the colour's own (always-opaque) `a` channel.
///
/// # Safety
///
/// `ctx` must be a valid `CGContextRef` borrowed for the duration of
/// the call.
pub unsafe