Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
drawlist_format.hpp
Go to the documentation of this file.
1#pragma once
2
3// Drawlist formatting — a `RecordingCanvas` drawlist as readable text.
4//
5// A recorded drawlist is already a value (`RecordingCanvas::commands()`), but
6// reading one means walking a vector and switching on an enum. Every test that
7// asserts on drawing does that by hand today, indexing into `commands()` and
8// comparing `.type` — which says what the Nth command was, and nothing about
9// what the drawing IS.
10//
11// CHECK(format_commands(rc.commands()).find("fill_rect 10.000 20.000") != npos);
12//
13// ── Why this exists next to the pixel comparisons ────────────────────────
14// Pulp's visual checks compare pixels, and `docs/status/tools.yaml` records
15// what each of them cannot see: the histogram scorer is position-blind (a
16// design with every element in the wrong place scores the same as a correct
17// one), and the block-mean scorer is material-blind (a flattened gradient
18// matches its own mean exactly). A drawlist is neither. The coordinates, the
19// colours, the blur radii and the blend modes are all in the ops, so a text
20// golden over this catches exactly the two defect classes a pixel diff waves
21// through — and it catches them without a GPU, a font, or a reference image.
22//
23// It is NOT a replacement for pixel comparison: a drawlist says what was
24// ASKED for, never what was drawn. A backend that silently ignores a blur
25// still records the blur. Use both; they fail on different things.
26//
27// ── Round-tripping is deliberately absent ────────────────────────────────
28// There is no parser here and there should not be one. Pulp already has two
29// round-trippable draw formats — SKP capture (`render/skp_capture.hpp`, which
30// the Skia debugger reads) and the canvas2d API the ops were authored in. A
31// third format nobody authors in would be weight without a reader.
32//
33// ── Stability ────────────────────────────────────────────────────────────
34// Floats print at fixed precision so a golden does not flap on the last bit
35// of a float, and ALL SIX are always printed. Printing only the ones a
36// command "uses" would need a per-command arity table — 83 chances to encode
37// a wrong one, and a wrong one hides a parameter rather than failing. The
38// command name tells a reader which slots carry meaning.
39
40#include <string>
41#include <vector>
42
44
45namespace pulp::canvas {
46
53
59std::string format_command(const DrawCommand& command);
60
63std::string format_commands(const std::vector<DrawCommand>& commands);
64
65} // namespace pulp::canvas
Definition affine_transform.hpp:24
std::string format_commands(const std::vector< DrawCommand > &commands)
A whole drawlist, one command per line, newline-separated with a trailing newline.
const char * draw_command_name(DrawCommand::Type type)
The command's name, exactly as its enumerator is spelled.
std::string format_command(const DrawCommand &command)
One command as a single line, with no trailing newline.
Definition recording_canvas.hpp:16
Type
Definition recording_canvas.hpp:19