Files
chandra/wasmhost/bin/raster_gpu.h
nandiandClaude Opus 5.5 cfb25fe699 Draw on the GPU: the desktop with OpenGL ES, apps through linux-dmabuf
The host's rasteriser has a GPU half (raster_gpu.c): the same primitives, drawn the same way, on
machines with a real GPU and OpenGL ES 3, straight into the display's buffers in a login session.
EGL and GLES are loaded at run time; without them everything is drawn on the CPU as before
(CHANDRA_GPU=0 does that too). zwp_linux_dmabuf_v1 lets apps draw on the GPU as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:42:22 -08:00

55 lines
3.1 KiB
C

/* The GPU half of the host's rasteriser (raster_stub.c calls these when gpu_on). */
#ifndef CHANDRA_RASTER_GPU_H
#define CHANDRA_RASTER_GPU_H
#include <stdint.h>
/* 1 once gpu_init found a GPU: every drawing call then goes to it. */
extern int gpu_on;
/* `session`: for a login session on the display itself (the crash guard). */
int gpu_init(int session);
/* The frame: a texture of w x h that keeps its contents between frames (so damage works). */
int gpu_resize(int w, int h); /* 0 when the GPU can't */
void gpu_clear(void);
void gpu_clip(int on, int x, int y, int w, int h);
void gpu_flush(void); /* send what was batched to GL */
void gpu_submit(void); /* and start the GPU on it */
void gpu_read(uint8_t *fb, int stride_px, int x0, int y0, int x1, int y1); /* RGBA rows, at their place in fb */
void gpu_fill(int x, int y, int w, int h, int r, int g, int b, int a, int radius);
void gpu_stroke(int x, int y, int w, int h, int r, int g, int b, int a, int width, int radius);
void gpu_circle(int cx, int cy, int radius, int r, int g, int b, int a, int filled);
/* A glyph's coverage (w * h bytes). *ax, *ay, *gen: where the atlas holds it, kept by the caller. */
void gpu_glyph(const uint8_t *cov, int w, int h, int *ax, int *ay, uint32_t *gen, int x, int y, int r, int g, int b,
int a);
/* Textures. Straight-alpha RGBA pixels, or (gpu_tex_shm) a client's B, G, R, A/X rows. */
uint32_t gpu_tex_rgba(const uint8_t *px, int w, int h);
uint32_t gpu_tex_shm(const uint8_t *px, int stride, int w, int h, int opaque);
void gpu_tex_free(uint32_t tex, int w, int h); /* w, h: its size, to reuse it */
/* A copy of texture `src` (sw x sh, premultiplied) scaled to w x h. */
uint32_t gpu_tex_scaled(uint32_t src, int sw, int sh, int w, int h);
/* Draw `tex` stretched over (x, y, w, h). */
void gpu_image(uint32_t tex, int x, int y, int w, int h, int premultiplied);
/* Draw `tex` (tw x th, premultiplied) unscaled at (x, y), cut to w x h; the part past the
* texture takes its bottom-right pixel. */
void gpu_surface(uint32_t tex, int tw, int th, int x, int y, int w, int h);
void gpu_save_backdrop(void);
void gpu_copy_backdrop(void);
/* Client buffers on the GPU (linux-dmabuf). */
uint64_t gpu_device(void); /* the render node's dev_t; 0 without dmabuf support */
int gpu_dmabuf_formats(uint32_t *fourcc, uint64_t *modifier, int cap); /* how many there are */
uint32_t gpu_dmabuf_import(int n, const int *fd, const uint32_t *offset, const uint32_t *stride, uint64_t modifier,
int w, int h, uint32_t fourcc, int y_invert);
void gpu_dmabuf_free(uint32_t id);
/* A copy of the buffer as it is now, as a texture. *opaque: its format has no alpha. */
uint32_t gpu_dmabuf_copy(uint32_t id, int *w, int *h, int *opaque);
/* Draw the frame into scanout buffer `slot` (0 or 1), a dmabuf of pw x ph XRGB8888: the frame's
* x0..y1, at `scale` and turned by `rot` quarters. `fd` is only used the first time (and not
* closed). 0 when the GPU can't draw there. */
int gpu_scanout(int slot, int fd, uint32_t pitch, int pw, int ph, int scale, int rot, int x0, int y0, int x1, int y1);
#endif