feat: xorg viewer scale modes, resize fix, arch notes

Scale modes (STRETCH/FIT/FILL/1:1) with CENTER/TOP_LEFT anchor:
- UV crop via u_uv_scale/u_uv_offset uniforms in vertex shader
- glViewport sub-rect + glClear for FIT and 1:1 modes
- xorg_viewer_set_scale() / xorg_viewer_set_anchor() setters
- Stub implementations for both

Resize fix: glfwSetWindowUserPointer + framebuffer_size_callback calls
render() synchronously during resize so image tracks window edge
immediately. Forward declaration added to fix implicit decl error.

Q/Escape close the window via key_callback.

xorg_cli: --scale and --anchor arguments added.

architecture.md:
- Scale mode table and anchor docs in Frame Viewer Sink section
- Render loop design note: frame-driven not timer-driven, resize callback
  rationale, threading note (GL context ownership, frame queue)
- Text overlay section: tier 1 bitmap atlas (Pillow build tool, skyline
  packing, quad rendering), tier 2 HarfBuzz+FreeType, migration path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-28 21:30:28 +00:00
parent ef0319b45b
commit 7fd79e6120
6 changed files with 413 additions and 56 deletions

View File

@@ -6,6 +6,26 @@
typedef struct Xorg_Viewer Xorg_Viewer;
/*
* How the frame is scaled to fit the window.
* SCALE_STRETCH is the only implemented mode; others are reserved.
*/
typedef enum Xorg_Scale {
XORG_SCALE_STRETCH, /* fill window, ignore aspect ratio (default) */
XORG_SCALE_FIT, /* largest rect that fits, preserve aspect, black bars */
XORG_SCALE_FILL, /* smallest rect that covers, preserve aspect, crop edges */
XORG_SCALE_1_1, /* native pixel size, no scaling */
} Xorg_Scale;
/*
* Where the frame is positioned within the window.
* Used with XORG_SCALE_FIT, XORG_SCALE_FILL, and XORG_SCALE_1_1.
*/
typedef enum Xorg_Anchor {
XORG_ANCHOR_CENTER, /* center frame in window (default) */
XORG_ANCHOR_TOP_LEFT, /* align frame to top-left corner */
} Xorg_Anchor;
/* Returns false when compiled without HAVE_GLFW. */
bool xorg_available(void);
@@ -32,6 +52,10 @@ bool xorg_viewer_push_bgra(Xorg_Viewer *v,
bool xorg_viewer_push_mjpeg(Xorg_Viewer *v,
const uint8_t *data, size_t size);
/* Change scale/anchor at any time; takes effect on the next render. */
void xorg_viewer_set_scale(Xorg_Viewer *v, Xorg_Scale scale);
void xorg_viewer_set_anchor(Xorg_Viewer *v, Xorg_Anchor anchor);
/*
* Process pending window events.
* Returns false when the user has closed the window.