- remote/: shared-memory framebuffer mirror served as RFB 3.8 (VNC, port 5900) and an HTTP/WebSocket PWA (port 6080), bound to the Tailscale interface and loopback by default - Compositor: remote pointer, button, scroll, modifier, key, key-tap, text and clipboard input, routed past OLED blanking - chandra-ctl: add status, refresh and osk commands; add input-* and clipboard-set for remote control - Camera: debayer 10-bit CSI-2 Quad-Bayer frames for imx371 and high-quality still capture - Camera: rotate frames by the libcamera mounting angle (CCW for 90), fix the expected test values, and restyle the UI for a dark theme
This commit is contained in:
1 parent
de39b74282
commit
bfc60ee0e5
24 files changed
+5310
-79
No files matched your search
@@ -177,6 +177,9 @@ fn changed_images(panel : @wt.Val) -> R {
|
||||
///|
|
||||
extern "C" fn rs_frame_begin() = "rs_frame_begin"
|
||||
|
||||
///|
|
||||
extern "C" fn rs_publish_frame() = "rs_publish_frame"
|
||||
|
||||
///|
|
||||
extern "C" fn rs_damage(x : Int, y : Int, w : Int, h : Int) = "rs_damage"
|
||||
|
||||
@@ -706,6 +709,7 @@ fn submit(v : @wt.Val) -> Unit {
|
||||
// Nothing on screen changed (a window off screen, say).
|
||||
last_drawn.val = 0
|
||||
keep_prev(f)
|
||||
rs_publish_frame()
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -816,6 +820,7 @@ fn submit(v : @wt.Val) -> Unit {
|
||||
rs_blit_surface(p.field("surface").to_uint(), a.x, a.y, a.w, a.h) |> ignore
|
||||
}
|
||||
keep_prev(f)
|
||||
rs_publish_frame()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- images
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "moonbit.h"
|
||||
#include "../../remote/chandra_fb_shm.h"
|
||||
|
||||
#define NANOSVG_IMPLEMENTATION
|
||||
#define NANOSVGRAST_IMPLEMENTATION
|
||||
@@ -961,11 +962,16 @@ static Box box_fb(Box b) {
|
||||
#define EXPORT_SLOTS 3
|
||||
static Box kms_damage;
|
||||
static Box slot_damage[EXPORT_SLOTS];
|
||||
static Box shm_slot_dmg[2];
|
||||
static Box shm_pub_dmg;
|
||||
|
||||
/* The frame just drawn changed (x, y, w, h) of the framebuffer. */
|
||||
void rs_damage(int32_t x, int32_t y, int32_t w, int32_t h) {
|
||||
box_add(&kms_damage, x, y, x + w, y + h);
|
||||
for (int i = 0; i < EXPORT_SLOTS; i++) box_add(&slot_damage[i], x, y, x + w, y + h);
|
||||
box_add(&shm_slot_dmg[0], x, y, x + w, y + h);
|
||||
box_add(&shm_slot_dmg[1], x, y, x + w, y + h);
|
||||
box_add(&shm_pub_dmg, x, y, x + w, y + h);
|
||||
}
|
||||
|
||||
/* RGBA8888 -> little-endian XRGB8888 (B, G, R, 255) for the rows and columns of `b`. */
|
||||
@@ -1244,3 +1250,113 @@ void rs_snapshot_pixels(int32_t x, int32_t y, int32_t w, int32_t h, int32_t ow,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- live shared-memory framebuffer mirror (for chandra-remote) ---- */
|
||||
|
||||
static int shm_fd = -1;
|
||||
static ChandraFbHeader *shm_hdr;
|
||||
static int32_t shm_w, shm_h;
|
||||
static int shm_init_tried;
|
||||
|
||||
static void shm_ensure_open(void) {
|
||||
if (shm_init_tried) return;
|
||||
shm_init_tried = 1;
|
||||
char path[512];
|
||||
const char *env = getenv("CHANDRA_FB_SHM");
|
||||
if (env && env[0]) {
|
||||
snprintf(path, sizeof path, "%s", env);
|
||||
} else {
|
||||
const char *tc = getenv("CHANDRA_TEST_CONFIG");
|
||||
if (tc && tc[0]) return;
|
||||
const char *rt = getenv("XDG_RUNTIME_DIR");
|
||||
if (!rt || !rt[0]) return;
|
||||
char dir[512];
|
||||
snprintf(dir, sizeof dir, "%s/chandra", rt);
|
||||
mkdir(dir, 0700);
|
||||
snprintf(path, sizeof path, "%s/fb.shm", dir);
|
||||
}
|
||||
int fd = open(path, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
|
||||
if (fd < 0) return;
|
||||
struct stat st;
|
||||
size_t need = (size_t)CHANDRA_FB_TOTAL_BYTES;
|
||||
if (fstat(fd, &st) < 0 || (size_t)st.st_size < need) {
|
||||
if (ftruncate(fd, (off_t)need) < 0) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
void *m = mmap(NULL, need, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (m == MAP_FAILED) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
shm_fd = fd;
|
||||
shm_hdr = (ChandraFbHeader *)m;
|
||||
uint64_t saved_ping = 0;
|
||||
if (shm_hdr->magic == CHANDRA_FB_MAGIC && shm_hdr->version == CHANDRA_FB_VERSION &&
|
||||
shm_hdr->slot_bytes == CHANDRA_FB_SLOT_BYTES) {
|
||||
saved_ping = __atomic_load_n(&shm_hdr->consumer_ping_ms, __ATOMIC_ACQUIRE);
|
||||
} else {
|
||||
memset(shm_hdr, 0, sizeof *shm_hdr);
|
||||
}
|
||||
shm_hdr->magic = CHANDRA_FB_MAGIC;
|
||||
shm_hdr->version = CHANDRA_FB_VERSION;
|
||||
shm_hdr->slot_bytes = CHANDRA_FB_SLOT_BYTES;
|
||||
shm_hdr->active_slot = 0;
|
||||
shm_hdr->width = 0;
|
||||
shm_hdr->height = 0;
|
||||
shm_hdr->dmg_x0 = shm_hdr->dmg_y0 = shm_hdr->dmg_x1 = shm_hdr->dmg_y1 = 0;
|
||||
shm_hdr->frame_ms = 0;
|
||||
__atomic_store_n(&shm_hdr->consumer_ping_ms, saved_ping, __ATOMIC_RELEASE);
|
||||
__atomic_store_n(&shm_hdr->seq, 0, __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
void rs_publish_frame(void) {
|
||||
if (!fb || fb_w <= 0 || fb_h <= 0) return;
|
||||
if ((size_t)fb_w * (size_t)fb_h * 4 > CHANDRA_FB_SLOT_BYTES) return;
|
||||
shm_ensure_open();
|
||||
if (!shm_hdr) return;
|
||||
uint64_t now = rec_now_ms();
|
||||
uint64_t ping = __atomic_load_n(&shm_hdr->consumer_ping_ms, __ATOMIC_ACQUIRE);
|
||||
uint64_t cur_seq = __atomic_load_n(&shm_hdr->seq, __ATOMIC_RELAXED);
|
||||
if (cur_seq > 0 && (ping == 0 || now > ping + 5000)) return;
|
||||
if (fb_w != shm_w || fb_h != shm_h || cur_seq == 0) {
|
||||
shm_slot_dmg[0] = (Box){ 0, 0, fb_w, fb_h };
|
||||
shm_slot_dmg[1] = (Box){ 0, 0, fb_w, fb_h };
|
||||
shm_pub_dmg = (Box){ 0, 0, fb_w, fb_h };
|
||||
shm_w = fb_w;
|
||||
shm_h = fb_h;
|
||||
}
|
||||
Box pb = box_fb(shm_pub_dmg);
|
||||
if (pb.x0 >= pb.x1 || pb.y0 >= pb.y1) {
|
||||
if (cur_seq == 0) pb = (Box){ 0, 0, fb_w, fb_h };
|
||||
else return;
|
||||
}
|
||||
uint32_t next = 1u - (__atomic_load_n(&shm_hdr->active_slot, __ATOMIC_RELAXED) & 1u);
|
||||
uint8_t *dst = chandra_fb_slot_ptr(shm_hdr, next, shm_hdr->slot_bytes);
|
||||
Box sb = box_fb(shm_slot_dmg[next]);
|
||||
if (sb.x0 < sb.x1 && sb.y0 < sb.y1) {
|
||||
if (sb.x0 == 0 && sb.x1 == fb_w) {
|
||||
size_t off = (size_t)sb.y0 * (size_t)fb_w * 4;
|
||||
size_t bytes = (size_t)(sb.y1 - sb.y0) * (size_t)fb_w * 4;
|
||||
memcpy(dst + off, fb + off, bytes);
|
||||
} else {
|
||||
size_t span = (size_t)(sb.x1 - sb.x0) * 4;
|
||||
for (int y = sb.y0; y < sb.y1; y++) {
|
||||
size_t off = ((size_t)y * (size_t)fb_w + (size_t)sb.x0) * 4;
|
||||
memcpy(dst + off, fb + off, span);
|
||||
}
|
||||
}
|
||||
}
|
||||
shm_slot_dmg[next] = (Box){ 0, 0, 0, 0 };
|
||||
shm_pub_dmg = (Box){ 0, 0, 0, 0 };
|
||||
shm_hdr->width = (uint32_t)fb_w;
|
||||
shm_hdr->height = (uint32_t)fb_h;
|
||||
shm_hdr->dmg_x0 = pb.x0;
|
||||
shm_hdr->dmg_y0 = pb.y0;
|
||||
shm_hdr->dmg_x1 = pb.x1;
|
||||
shm_hdr->dmg_y1 = pb.y1;
|
||||
shm_hdr->frame_ms = now;
|
||||
__atomic_store_n(&shm_hdr->active_slot, next, __ATOMIC_RELEASE);
|
||||
__atomic_store_n(&shm_hdr->seq, cur_seq + 1, __ATOMIC_RELEASE);
|
||||
}
|
||||
Reference in new issue
Block a user