AtlatestRepositorysigil-ui

sigil-ui / tree / nativesurface.c

1/*
2 * Framebuffer surfaces for (sigil ui surface): fbdev and DRM dumb buffers.
3 *
4 * Both keep the mode they find. The fbdev surface maps /dev/fbN as it is,
5 * activates it (needed on DRM fbdev emulation) and flushes deferred I/O on
6 * every present.
7 * The DRM surface reads the mode the CRTC already scans out (the mode the
8 * firmware or the previous owner left), allocates a dumb buffer of that
9 * size and shows it with that same mode. It modesets only when the CRTC has
10 * no mode at all, and reports that it did.
11 *
12 * Only 32 bpp XRGB8888 is supported; anything else is refused at open.
13 */
15#include <sigil/sigil.h>
16#include <errno.h>
17#include <fcntl.h>
18#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <sys/ioctl.h>
23#include <sys/mman.h>
24#include <sys/stat.h>
25#include <sys/sysmacros.h>
26#include <unistd.h>
27#include <linux/fb.h>
28#include <drm/drm.h>
29#include <drm/drm_mode.h>
30#include "surface-close.h"
31#include "surface-mode.h"
33#define REGISTER_AND_EXPORT(name, func, arity, doc) \
34 sigil_module_register_native(vm, name, func, arity, doc); \
35 sigil_module_export(vm, name)
37#define DONE SIGIL_UNDEFINED
39static Value fb_tag = SIGIL_UNDEFINED;
40static Value drm_tag = SIGIL_UNDEFINED;
42typedef struct {
43 int fd;
44 uint8_t *map;
45 size_t map_size;
46 int64_t width, height, stride;
47} Fb;
49typedef struct {
50 int fd;
51 uint32_t connector, crtc, fb, handle, pitch;
52 uint64_t size;
53 uint8_t *map;
54 struct drm_mode_modeinfo mode;
55 int64_t width, height;
56 int modeset; /* 1 when open had to pick a mode itself */
57 int shown;
58} Drm;
60static int path_arg(SigilVM *vm, Value v, char *buf, size_t n, const char *who)
62 if (!sigil_is_string(v)) {
63 sigil__vm_error(vm, SIGIL_ERR_TYPE, "%s: path must be a string", who);
64 return 0;
65 }
66 size_t len = ((SigilString *)sigil_as_ptr(v))->byte_length;
67 if (len + 1 > n) {
68 sigil__vm_error(vm, SIGIL_ERR_TYPE, "%s: path too long", who);
69 return 0;
70 }
71 memcpy(buf, sigil_string_bytes(v), len);
72 buf[len] = 0;
73 return 1;
76static int int_arg(SigilVM *vm, Value v, int64_t *out, const char *who)
78 if (!sigil_is_fixnum(v)) {
79 sigil__vm_error(vm, SIGIL_ERR_TYPE, "%s: expected an exact integer", who);
80 return 0;
81 }
82 *out = sigil_as_fixnum(v);
83 return 1;
86/* Copy a rectangle of a canvas (bytevector, width) into mapped memory. */
87static int copy_rect(SigilVM *vm, Value *args, uint8_t *dst, int64_t dst_stride,
88 int64_t dst_w, int64_t dst_h, int64_t *clip, const char *who)
90 int64_t cw, x, y, w, h;
91 if (!sigil_is_bytevector(args[0])) {
92 sigil__vm_error(vm, SIGIL_ERR_TYPE, "%s: canvas pixels must be a bytevector", who);
93 return 0;
94 }
95 if (!int_arg(vm, args[1], &cw, who) || !int_arg(vm, args[2], &x, who) ||
96 !int_arg(vm, args[3], &y, who) || !int_arg(vm, args[4], &w, who) ||
97 !int_arg(vm, args[5], &h, who))
98 return 0;
99 size_t len = sigil_bytevector_length(args[0]);
100 if (cw <= 0 || len % (size_t)(4 * cw) != 0) {
101 sigil__vm_error(vm, SIGIL_ERR_TYPE, "%s: not a canvas", who);
102 return 0;
103 }
104 int64_t ch = (int64_t)(len / (size_t)(4 * cw));
105 if (cw != dst_w || ch != dst_h) {
106 sigil__vm_error(vm, SIGIL_ERR_TYPE, "%s: canvas is %lldx%lld, surface is %lldx%lld", who,
107 (long long)cw, (long long)ch, (long long)dst_w, (long long)dst_h);
108 return 0;
109 }
110 if (x < 0) { w += x; x = 0; }
111 if (y < 0) { h += y; y = 0; }
112 if (x + w > cw) w = cw - x;
113 if (y + h > ch) h = ch - y;
114 clip[0] = x; clip[1] = y; clip[2] = w; clip[3] = h;
115 if (w <= 0 || h <= 0) return 1;
116 const uint8_t *src = sigil_bytevector_data(args[0]);
117 for (int64_t j = y; j < y + h; j++)
118 memcpy(dst + j * dst_stride + x * 4, src + (j * cw + x) * 4, (size_t)w * 4);
119 return 1;
122/* ---------------------------------------------------------------- fbdev */
124static void fb_close(Fb *f)
126 if (f->map) munmap(f->map, f->map_size);
127 if (f->fd >= 0) close(f->fd);
128 f->map = NULL;
129 f->fd = -1;
132static void fb_finalize(void *data)
134 Fb *f = data;
135 if (f) { fb_close(f); free(f); }
138static Fb *as_fb(SigilVM *vm, Value v, const char *who)
140 if (!sigil_is_foreign(v) || sigil_foreign_type(v) != fb_tag) {
141 sigil__vm_error(vm, SIGIL_ERR_TYPE, "%s: not an fbdev surface", who);
142 return NULL;
143 }
144 Fb *f = sigil_foreign_data(v);
145 if (f->fd < 0) {
146 sigil__vm_error(vm, SIGIL_ERR_IO, "%s: surface is closed", who);
147 return NULL;
148 }
149 return f;
152/* (%fb-open path) => surface */
153static Value native_fb_open(SigilVM *vm, int argc, Value *args)
155 char path[256];
156 struct fb_var_screeninfo var;
157 struct fb_fix_screeninfo fix;
158 if (!path_arg(vm, args[0], path, sizeof path, "fb-open")) return DONE;
159 int fd = open(path, O_RDWR | O_CLOEXEC);
160 if (fd < 0) {
161 sigil__vm_error(vm, SIGIL_ERR_IO, "fb-open: %s: %s", path, strerror(errno));
162 return DONE;
163 }
164 if (ioctl(fd, FBIOGET_VSCREENINFO, &var) < 0 || ioctl(fd, FBIOGET_FSCREENINFO, &fix) < 0) {
165 int e = errno; close(fd);
166 sigil__vm_error(vm, SIGIL_ERR_IO, "fb-open: %s: screen info: %s", path, strerror(e));
167 return DONE;
168 }
169 if (var.bits_per_pixel != 32 || var.red.offset != 16 || var.green.offset != 8 ||
170 var.blue.offset != 0) {
171 close(fd);
172 sigil__vm_error(vm, SIGIL_ERR_IO,
173 "fb-open: %s: %u bpp with red at %u, green at %u, blue at %u is not XRGB8888",
174 path, var.bits_per_pixel, var.red.offset, var.green.offset, var.blue.offset);
175 return DONE;
176 }
177 /* Put the same mode back with FB_ACTIVATE_FORCE. On a DRM driver's
178 * fbdev emulation this runs set_par, which commits the emulated
179 * framebuffer to the display; until then (with fbcon's takeover
180 * deferred) nothing scans it out and writes to the mapping are never
181 * seen. On a plain fbdev driver it is a no-op, and a refusal is
182 * harmless, so the result is not checked. */
183 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
184 (void)ioctl(fd, FBIOPUT_VSCREENINFO, &var);
185 size_t size = (size_t)fix.line_length * var.yres_virtual;
186 if (fix.smem_len && size > fix.smem_len) size = fix.smem_len;
187 void *map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
188 if (map == MAP_FAILED) {
189 int e = errno; close(fd);
190 sigil__vm_error(vm, SIGIL_ERR_IO, "fb-open: %s: mmap: %s", path, strerror(e));
191 return DONE;
192 }
193 Fb *f = calloc(1, sizeof *f);
194 if (!f) { munmap(map, size); close(fd); return SIGIL_FALSE; }
195 f->fd = fd; f->map = map; f->map_size = size;
196 f->width = var.xres; f->height = var.yres; f->stride = fix.line_length;
197 if ((int64_t)size < f->stride * f->height) {
198 fb_close(f); free(f);
199 sigil__vm_error(vm, SIGIL_ERR_IO, "fb-open: %s: mapping smaller than one screen", path);
200 return DONE;
201 }
202 return sigil_make_foreign(vm, fb_tag, f, fb_finalize, sizeof *f);
205/* (%fb-geometry fb) => (width height stride) */
206static Value native_fb_geometry(SigilVM *vm, int argc, Value *args)
208 Fb *f = as_fb(vm, args[0], "fb-geometry");
209 if (!f) return DONE;
210 return sigil_cons(vm, sigil_fixnum(f->width),
211 sigil_cons(vm, sigil_fixnum(f->height),
212 sigil_cons(vm, sigil_fixnum(f->stride), SIGIL_EMPTY)));
215/* (%fb-present! fb pixels width x y w h) */
216static Value native_fb_present(SigilVM *vm, int argc, Value *args)
218 int64_t clip[4];
219 Fb *f = as_fb(vm, args[0], "fb-present!");
220 if (!f) return DONE;
221 if (!copy_rect(vm, args + 1, f->map, f->stride, f->width, f->height, clip, "fb-present!"))
222 return DONE;
223 /* fbdev emulation on DRM uses deferred I/O: writes to the mapping are
224 * copied to the display by a worker some 50 ms later. fsync runs that
225 * flush now. Drivers without deferred I/O refuse fsync with EINVAL,
226 * and their writes are already visible. */
227 if (fsync(f->fd) < 0 && errno != EINVAL && errno != EROFS) {
228 sigil__vm_error(vm, SIGIL_ERR_IO, "fb-present!: flush: %s", strerror(errno));
229 return DONE;
230 }
231 return DONE;
234/* (%fb-close! fb) */
235static Value native_fb_close(SigilVM *vm, int argc, Value *args)
237 if (!sigil_is_foreign(args[0]) || sigil_foreign_type(args[0]) != fb_tag) {
238 sigil__vm_error(vm, SIGIL_ERR_TYPE, "fb-close!: not an fbdev surface");
239 return DONE;
240 }
241 fb_close(sigil_foreign_data(args[0]));
242 return DONE;
245/* ---------------------------------------------------------------- DRM */
247static void drm_close(Drm *d)
249 if (d->map) munmap(d->map, d->size);
250 if (d->fd >= 0) {
251 if (d->fb) ioctl(d->fd, DRM_IOCTL_MODE_RMFB, &d->fb);
252 if (d->handle) {
253 struct drm_mode_destroy_dumb des = { .handle = d->handle };
254 ioctl(d->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &des);
255 }
256 close(d->fd);
257 }
258 d->map = NULL;
259 d->fd = -1;
262static void drm_finalize(void *data)
264 Drm *d = data;
265 if (d) { drm_close(d); free(d); }
268static Drm *as_drm(SigilVM *vm, Value v, const char *who)
270 if (!sigil_is_foreign(v) || sigil_foreign_type(v) != drm_tag) {
271 sigil__vm_error(vm, SIGIL_ERR_TYPE, "%s: not a DRM surface", who);
272 return NULL;
273 }
274 Drm *d = sigil_foreign_data(v);
275 if (d->fd < 0) {
276 sigil__vm_error(vm, SIGIL_ERR_IO, "%s: surface is closed", who);
277 return NULL;
278 }
279 return d;
282/* Find a connected connector and the CRTC driving it. 0 on success. */
283static int drm_pick(int fd, Drm *d, char *err, size_t errn)
285 struct drm_mode_card_res res = {0};
286 if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res) < 0) {
287 snprintf(err, errn, "resources: %s", strerror(errno));
288 return -1;
289 }
290 uint32_t nconn = res.count_connectors;
291 uint32_t *conns = calloc(nconn ? nconn : 1, sizeof *conns);
292 if (!conns) { snprintf(err, errn, "out of memory"); return -1; }
293 struct drm_mode_card_res res2 = {0};
294 res2.connector_id_ptr = (uint64_t)(uintptr_t)conns;
295 res2.count_connectors = nconn;
296 if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res2) < 0) {
297 free(conns);
298 snprintf(err, errn, "resources: %s", strerror(errno));
299 return -1;
300 }
301 int found = -1;
302 for (uint32_t i = 0; i < nconn && found < 0; i++) {
303 struct drm_mode_get_connector c = { .connector_id = conns[i] };
304 if (ioctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &c) < 0) continue;
305 if (c.connection != 1 || c.count_modes == 0) continue;
306 struct drm_mode_modeinfo *modes = calloc(c.count_modes, sizeof *modes);
307 uint32_t *encs = calloc(c.count_encoders ? c.count_encoders : 1, sizeof *encs);
308 if (!modes || !encs) { free(modes); free(encs); continue; }
309 struct drm_mode_get_connector c2 = { .connector_id = conns[i] };
310 c2.modes_ptr = (uint64_t)(uintptr_t)modes;
311 c2.count_modes = c.count_modes;
312 c2.encoders_ptr = (uint64_t)(uintptr_t)encs;
313 c2.count_encoders = c.count_encoders;
314 if (ioctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &c2) == 0) {
315 uint32_t enc_id = c2.encoder_id ? c2.encoder_id : (c2.count_encoders ? encs[0] : 0);
316 struct drm_mode_get_encoder e = { .encoder_id = enc_id };
317 if (enc_id && ioctl(fd, DRM_IOCTL_MODE_GETENCODER, &e) == 0) {
318 uint32_t crtc = e.crtc_id;
319 if (!crtc && res.count_crtcs) {
320 /* first CRTC this encoder can drive */
321 uint32_t *crtcs = calloc(res.count_crtcs, sizeof *crtcs);
322 struct drm_mode_card_res r3 = {0};
323 if (crtcs) {
324 r3.crtc_id_ptr = (uint64_t)(uintptr_t)crtcs;
325 r3.count_crtcs = res.count_crtcs;
326 if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &r3) == 0)
327 for (uint32_t k = 0; k < res.count_crtcs; k++)
328 if (e.possible_crtcs & (1u << k)) { crtc = crtcs[k]; break; }
329 free(crtcs);
330 }
331 }
332 struct drm_mode_crtc cr = { .crtc_id = crtc };
333 if (crtc && ioctl(fd, DRM_IOCTL_MODE_GETCRTC, &cr) == 0) {
334 d->connector = conns[i];
335 d->crtc = crtc;
336 if (cr.mode_valid) {
337 d->mode = cr.mode;
338 d->modeset = 0;
339 } else {
340 d->mode = modes[0]; /* the connector's preferred mode */
341 d->modeset = 1;
342 }
343 found = 0;
344 }
345 }
346 }
347 free(modes);
348 free(encs);
349 }
350 free(conns);
351 if (found < 0) snprintf(err, errn, "no connected output with a CRTC");
352 return found;
355/* (%drm-open path) => surface. Maps a dumb buffer the size of the current mode. */
356static Value native_drm_open(SigilVM *vm, int argc, Value *args)
358 char path[256], err[160];
359 if (!path_arg(vm, args[0], path, sizeof path, "drm-open")) return DONE;
360 int fd = open(path, O_RDWR | O_CLOEXEC);
361 if (fd < 0) {
362 sigil__vm_error(vm, SIGIL_ERR_IO, "drm-open: %s: %s", path, strerror(errno));
363 return DONE;
364 }
365 Drm *d = calloc(1, sizeof *d);
366 if (!d) { close(fd); return SIGIL_FALSE; }
367 d->fd = fd;
368 if (drm_pick(fd, d, err, sizeof err) < 0) {
369 drm_close(d); free(d);
370 sigil__vm_error(vm, SIGIL_ERR_IO, "drm-open: %s: %s", path, err);
371 return DONE;
372 }
373 d->width = d->mode.hdisplay;
374 d->height = d->mode.vdisplay;
375 struct drm_mode_create_dumb cd = { .width = (uint32_t)d->width, .height = (uint32_t)d->height, .bpp = 32 };
376 if (ioctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &cd) < 0) {
377 snprintf(err, sizeof err, "create dumb buffer: %s", strerror(errno));
378 goto fail;
379 }
380 d->handle = cd.handle; d->pitch = cd.pitch; d->size = cd.size;
381 struct drm_mode_fb_cmd2 fbc = {
382 .width = (uint32_t)d->width, .height = (uint32_t)d->height,
383 .pixel_format = 0x34325258, /* DRM_FORMAT_XRGB8888, 'XR24' */
384 };
385 fbc.handles[0] = d->handle;
386 fbc.pitches[0] = d->pitch;
387 if (ioctl(fd, DRM_IOCTL_MODE_ADDFB2, &fbc) < 0) {
388 snprintf(err, sizeof err, "add framebuffer: %s", strerror(errno));
389 goto fail;
390 }
391 d->fb = fbc.fb_id;
392 struct drm_mode_map_dumb md = { .handle = d->handle };
393 if (ioctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &md) < 0) {
394 snprintf(err, sizeof err, "map dumb buffer: %s", strerror(errno));
395 goto fail;
396 }
397 void *map = mmap(NULL, d->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, md.offset);
398 if (map == MAP_FAILED) {
399 snprintf(err, sizeof err, "mmap: %s", strerror(errno));
400 goto fail;
401 }
402 d->map = map;
403 return sigil_make_foreign(vm, drm_tag, d, drm_finalize, sizeof *d + d->size);
404fail:
405 drm_close(d); free(d);
406 sigil__vm_error(vm, SIGIL_ERR_IO, "drm-open: %s: %s", path, err);
407 return DONE;
410/* (%drm-geometry d) => (width height stride modeset?) */
411static Value native_drm_geometry(SigilVM *vm, int argc, Value *args)
413 Drm *d = as_drm(vm, args[0], "drm-geometry");
414 if (!d) return DONE;
415 return sigil_cons(vm, sigil_fixnum(d->width),
416 sigil_cons(vm, sigil_fixnum(d->height),
417 sigil_cons(vm, sigil_fixnum(d->pitch),
418 sigil_cons(vm, d->modeset ? SIGIL_TRUE : SIGIL_FALSE, SIGIL_EMPTY))));
421static Value native_drm_display_info(SigilVM *vm, int argc, Value *args)
423 Drm *d = as_drm(vm, args[0], "drm-display-info");
424 struct stat device;
425 if (!d) return DONE;
426 int64_t refresh = surface_refresh_mhz(&d->mode);
427 if (!refresh || fstat(d->fd, &device) || !S_ISCHR(device.st_mode)) {
428 sigil__vm_error(vm, SIGIL_ERR_IO, "drm-display-info: unavailable mode or device identity");
429 return DONE;
430 }
431 return sigil_cons(vm, sigil_fixnum(refresh),
432 sigil_cons(vm, sigil_fixnum(major(device.st_rdev)),
433 sigil_cons(vm, sigil_fixnum(minor(device.st_rdev)),
434 sigil_cons(vm, sigil_fixnum(d->connector), SIGIL_EMPTY))));
437static int drm_show(Drm *d)
439 struct drm_mode_crtc cr = {
440 .crtc_id = d->crtc, .fb_id = d->fb,
441 .set_connectors_ptr = (uint64_t)(uintptr_t)&d->connector,
442 .count_connectors = 1, .mode = d->mode, .mode_valid = 1,
443 };
444 return ioctl(d->fd, DRM_IOCTL_MODE_SETCRTC, &cr);
447/* (%drm-present! d pixels width x y w h): copy, then show or flush damage. */
448static Value native_drm_present(SigilVM *vm, int argc, Value *args)
450 int64_t clip[4];
451 Drm *d = as_drm(vm, args[0], "drm-present!");
452 if (!d) return DONE;
453 if (!copy_rect(vm, args + 1, d->map, d->pitch, d->width, d->height, clip, "drm-present!"))
454 return DONE;
455 if (!d->shown) {
456 if (drm_show(d) < 0) {
457 sigil__vm_error(vm, SIGIL_ERR_IO, "drm-present!: set CRTC: %s", strerror(errno));
458 return DONE;
459 }
460 d->shown = 1;
461 return DONE;
462 }
463 if (clip[2] <= 0 || clip[3] <= 0) return DONE;
464 struct drm_clip_rect r = {
465 .x1 = (unsigned short)clip[0], .y1 = (unsigned short)clip[1],
466 .x2 = (unsigned short)(clip[0] + clip[2]), .y2 = (unsigned short)(clip[1] + clip[3]),
467 };
468 struct drm_mode_fb_dirty_cmd dc = {
469 .fb_id = d->fb, .num_clips = 1, .clips_ptr = (uint64_t)(uintptr_t)&r,
470 };
471 /* Drivers that scan the buffer out directly answer ENOSYS: nothing to flush. */
472 if (ioctl(d->fd, DRM_IOCTL_MODE_DIRTYFB, &dc) < 0 && errno != ENOSYS) {
473 sigil__vm_error(vm, SIGIL_ERR_IO, "drm-present!: dirty: %s", strerror(errno));
474 return DONE;
475 }
476 return DONE;
479/* (%drm-master! d on?) sets or drops DRM master. */
480static Value native_drm_master(SigilVM *vm, int argc, Value *args)
482 Drm *d = as_drm(vm, args[0], "drm-master!");
483 if (!d) return DONE;
484 unsigned long req = sigil_is_false(args[1]) ? DRM_IOCTL_DROP_MASTER : DRM_IOCTL_SET_MASTER;
485 if (ioctl(d->fd, req, 0) < 0) {
486 sigil__vm_error(vm, SIGIL_ERR_IO, "drm-master!: %s", strerror(errno));
487 return DONE;
488 }
489 return DONE;
492/* Preserve requests fail before teardown on kernels without CLOSEFB. */
493static Value native_drm_close(SigilVM *vm, int argc, Value *args)
495 if (!sigil_is_foreign(args[0]) || sigil_foreign_type(args[0]) != drm_tag) {
496 sigil__vm_error(vm, SIGIL_ERR_TYPE, "drm-close!: not a DRM surface");
497 return DONE;
498 }
499 Drm *d = sigil_foreign_data(args[0]);
500 if (close_surface(&d->fd, &d->fb, &d->map, d->size, argc > 1 && !sigil_is_false(args[1])) < 0) {
501 sigil__vm_error(vm, SIGIL_ERR_IO, "drm-close!: cannot preserve frame: %s", strerror(errno));
502 return DONE;
503 }
504 return DONE;
507void sigil__register_sigil_ui_surface(SigilVM *vm)
509 fb_tag = sigil_intern_symbol(vm, "ui-fbdev-surface", 16);
510 drm_tag = sigil_intern_symbol(vm, "ui-drm-surface", 14);
511 SigilModule *module = sigil_begin_module(vm, "(sigil ui surface)");
512 if (!module) return;
513 REGISTER_AND_EXPORT("%fb-open", native_fb_open, SIGIL_ARITY_EXACT(1), "Map an fbdev framebuffer");
514 REGISTER_AND_EXPORT("%fb-geometry", native_fb_geometry, SIGIL_ARITY_EXACT(1), "Width, height, stride");
515 REGISTER_AND_EXPORT("%fb-present!", native_fb_present, SIGIL_ARITY_EXACT(7), "Copy a canvas rectangle");
516 REGISTER_AND_EXPORT("%fb-close!", native_fb_close, SIGIL_ARITY_EXACT(1), "Unmap and close");
517 REGISTER_AND_EXPORT("%drm-open", native_drm_open, SIGIL_ARITY_EXACT(1), "Open a DRM card in its current mode");
518 REGISTER_AND_EXPORT("%drm-geometry", native_drm_geometry, SIGIL_ARITY_EXACT(1), "Width, height, stride, modeset?");
519 REGISTER_AND_EXPORT("%drm-display-info", native_drm_display_info, SIGIL_ARITY_EXACT(1), "Refresh in millihertz, DRM major, minor, connector ID");
520 REGISTER_AND_EXPORT("%drm-present!", native_drm_present, SIGIL_ARITY_EXACT(7), "Copy a canvas rectangle and flush it");
521 REGISTER_AND_EXPORT("%drm-master!", native_drm_master, SIGIL_ARITY_EXACT(2), "Set or drop DRM master");
522 REGISTER_AND_EXPORT("%drm-close!", native_drm_close, SIGIL_ARITY_RANGE(1, 2), "Close, optionally preserving active scanout (Linux 6.8+)");
523 sigil_end_module(vm);