Files
harfbuzz/util/gpu/demo-renderer.h
T
Behdad Esfahbod f840ae39a2 [util/gpu] Add --draw / --paint flags with auto-detect by font
Adds command-line flags --draw (force monochrome Slug path) and
--paint (force COLRv1 paint path) to hb-gpu, defaulting to
auto-detect based on hb_ot_color_has_paint(face).  Threads a
draw_only bool through the demo layer so each backend compiles
exactly one fragment program (draw or paint, not both).

The paint pipeline is ~10x slower than the draw pipeline on
monochrome content; auto-detect lets monochrome fonts keep the
fast path while still exercising both code paths from the same
binary.

Plumbing:

- demo_renderer_create_{gl,metal,d3d11} and demo_font_create
  take a draw_only argument.
- demo-fragment.{glsl,msl,hlsl} branch on HB_GPU_DEMO_DRAW,
  calling either hb_gpu_draw or hb_gpu_paint.
- demo-shader / glstate / d3d11 / metal include only the
  fragment helper for the chosen path and prepend
  HB_GPU_DEMO_DRAW to the source when draw_only.
- demo-font dispatches glyph upload to hb_gpu_draw_* or
  hb_gpu_paint_* and hides palette/foreground setters in
  draw mode.

Web demos pass false (paint-only) for now; a runtime
re-creation hook on font change would be needed there.

Tested on desktop GL, win64 D3D11, WebGL, WebGPU.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 00:04:27 -06:00

58 lines
1.4 KiB
C

/*
* Copyright 2026 Behdad Esfahbod. All Rights Reserved.
*/
#ifndef DEMO_RENDERER_H
#define DEMO_RENDERER_H
#include "demo-common.h"
#include "demo-shader.h"
typedef struct demo_atlas_t demo_atlas_t;
struct demo_renderer_t
{
virtual ~demo_renderer_t () {}
/* Atlas for glyph data upload. */
virtual demo_atlas_t *get_atlas () = 0;
/* One-time setup after atlas is populated. */
virtual void setup () = 0;
/* Rendering state. */
virtual void set_gamma (float gamma) = 0;
virtual void set_foreground (float r, float g, float b, float a) = 0;
virtual void set_background (float r, float g, float b, float a) = 0;
virtual void set_debug (bool enabled) = 0;
virtual void set_stem_darkening (bool enabled) { (void) enabled; }
/* Vsync toggle. */
virtual void toggle_vsync (bool &vsync) = 0;
/* Render a frame. generation changes when buffer content is rebuilt. */
virtual void display (glyph_vertex_t *vertices, unsigned int count,
unsigned generation,
int width, int height, float mat[16]) = 0;
};
#ifndef HB_GPU_NO_GLFW
demo_renderer_t *
demo_renderer_create_gl (GLFWwindow *window, bool draw_only);
#ifdef __APPLE__
demo_renderer_t *
demo_renderer_create_metal (GLFWwindow *window, bool draw_only);
#endif
#ifdef _WIN32
demo_renderer_t *
demo_renderer_create_d3d11 (GLFWwindow *window, bool draw_only);
#endif
#endif
#endif /* DEMO_RENDERER_H */