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
use Canvas;
/// RAII guard that calls `Canvas::save()` on construction and
/// `Canvas::restore()` on drop. Use it to ensure the canvas matrix and clip
/// stack are restored even if the wrapped code returns early via `?` or
/// panics, preventing latent state corruption between frames.
///
/// Construction takes a raw pointer instead of a borrow because Skia's
/// `Canvas::save()` takes `&mut`, but we want consumers to keep using the
/// canvas immutably afterwards (the visible mutation is a stack push). The
/// pointer is dereferenced only inside `Drop`, which always runs on the same
/// thread that built the guard — so this is sound for our use.