nx_x11_pixmap.nx source
↩ module page · 69 lines · 2207 B
1// nx_x11_pixmap.nx -- bits-up X11 off-screen pixmap drawable.
2//
3// Part of the "Nishi troubleshoots Nishi" self-closing-loop arc.
4// Off-screen pixmaps let us render the SAME drawing code-path to a
5// drawable we can read back via GetImage, then drop to a file the
6// developer (human OR Claude) can open without needing a live X11
7// session. Replaces "ask the user did you see X?" with "diff
8// /tmp/nishi_render.ppm against the expected golden."
9//
10// X11 Protocol ยง6 Pixmap.
11//
12// CreatePixmap (opcode 53):
13// byte 0: opcode = 53
14// byte 1: depth
15// bytes 2-3: request_length (4-byte units) = 4
16// bytes 4-7: pixmap id (allocated via nx_x11_alloc_id)
17// bytes 8-11: drawable (typically the window -- gives screen context)
18// bytes 12-13: width
19// bytes 14-15: height
20//
21// FreePixmap (opcode 54):
22// byte 0: 54
23// byte 1: unused
24// bytes 2-3: request_length = 2
25// bytes 4-7: pixmap id
26//
27// license_tier: ORIGINAL
28// genealogy_id: international-research-sources/x_org/xproto_v11_r0
29// lineage_id: nishi_x11_pixmap_q10
30
31import "nx_syscalls.nx"
32import "nx_x11_connect.nx"
33import "nx_x11_window.nx"
34
35// Create an off-screen pixmap. Returns pixmap_id (positive) or
36// 0 - error. Use `drawable` = a window on the same screen so the
37// server can pick the right visual.
38func nx_x11_create_pixmap(conn: *X11Conn, drawable: i64,
39 width: i64, height: i64, depth: i64) -> i64 {
40 let pid: i64 = nx_x11_alloc_id(conn)
41 let req: *u8 = sys_mmap(32)
42 var i: i64 = 0
43 while i < 32 { req[i] = 0; i = i + 1 }
44 req[0] = 53
45 req[1] = depth as u8
46 _x11_wr_u16(req, 2, 4)
47 _x11_wr_u32(req, 4, pid)
48 _x11_wr_u32(req, 8, drawable)
49 _x11_wr_u16(req, 12, width)
50 _x11_wr_u16(req, 14, height)
51 if _x11_send(conn, req, 16) < 0 { return 0 - 1 }
52 return pid
53}
54
55// Free a pixmap (release server resources).
56func nx_x11_free_pixmap(conn: *X11Conn, pixmap_id: i64) -> i64 {
57 let req: *u8 = sys_mmap(16)
58 var i: i64 = 0
59 while i < 16 { req[i] = 0; i = i + 1 }
60 req[0] = 54
61 req[1] = 0
62 _x11_wr_u16(req, 2, 2)
63 _x11_wr_u32(req, 4, pixmap_id)
64 return _x11_send(conn, req, 8)
65}
66
67func main() -> i64 {
68 return 0
69}