rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
gfx_turn.h
Go to the documentation of this file.
1
31#pragma once
32
33#include <stdatomic.h>
34#include <stdbool.h>
35#include <stdint.h>
36
37#include "gfx.h"
38#include "gfx_damage.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
45#define GFX_TURN_BUDGET_US 50000u
48#define GFX_TURN_FULL_FLIPS 2u
49
56
64
71
73typedef struct {
84 gfx_turn_copy_t (*copy)(void *ctx, const gfx_color_t *src,
85 gfx_color_t *dst, gfx_rect_t r,
86 uint32_t budget_us);
92 uint32_t (*now_us)(void *ctx);
93 void *ctx;
95
100typedef struct {
101 const gfx_color_t *in;
102 gfx_color_t *out;
103 int16_t width;
104 int16_t height;
106 int16_t dst_x;
107 int16_t dst_y;
108 void *user_data;
112
118typedef struct {
125 bool (*submit)(void *engine, const gfx_turn_job_t *job);
132 bool (*wait)(void *engine, uint32_t budget_us);
133 void *engine;
134 void *done_ctx;
137
139typedef struct {
141 int16_t width;
142 int16_t height;
144 bool drawing;
145 bool failed;
147 bool alerted;
148 bool repaint;
149 bool alert;
150 uint8_t full_left;
151 uint16_t rects;
152 uint32_t pixels;
153 uint32_t copy_us;
154} gfx_turn_t;
155
163void gfx_turn_init(gfx_turn_t *t, int width, int height);
164
170void gfx_turn_request(gfx_turn_t *t, bool turned);
171
178
184bool gfx_turn_drawing(const gfx_turn_t *t);
185
192void gfx_turn_begin(gfx_turn_t *t, const gfx_canvas_t *logical);
193
209gfx_turn_show_t gfx_turn_flush(gfx_turn_t *t, const gfx_color_t *logical,
210 gfx_color_t *fb, const gfx_turn_ops_t *ops);
211
219
230
238
245
262 const gfx_color_t *src,
263 gfx_color_t *dst, gfx_rect_t r,
264 int width, int height,
265 uint32_t budget_us);
266
268extern atomic_uint gfx_turn_stray;
269
277static inline void *gfx_turn_done_ctx(void *user_data)
278{
279 if (user_data == NULL) {
280 atomic_fetch_add(&gfx_turn_stray, 1u);
281 }
282 return user_data;
283}
284
289uint32_t gfx_turn_stray_dones(void);
290
296bool gfx_turn_shown(void);
297
298#ifdef __cplusplus
299}
300#endif
gfx: an RGB565 (16-bit red, green, blue) rasteriser with no dependencies.
Damage: the part of one frame buffer the rasteriser wrote since the last reset, kept as 16-row bands ...
gfx_turn_show_t gfx_turn_flush(gfx_turn_t *t, const gfx_color_t *logical, gfx_color_t *fb, const gfx_turn_ops_t *ops)
End a frame: copy what it drew into fb, turned.
Definition gfx_turn.c:83
void gfx_turn_begin(gfx_turn_t *t, const gfx_canvas_t *logical)
Start a frame: drawing turned, the damage record bound to logical, empty and attached; NORMAL,...
Definition gfx_turn.c:54
bool gfx_turn_take_alert(gfx_turn_t *t)
Whether the fallback's alert is due; clears it.
Definition gfx_turn.c:175
gfx_turn_copy_t gfx_turn_engine_copy(const gfx_turn_engine_t *e, const gfx_color_t *src, gfx_color_t *dst, gfx_rect_t r, int width, int height, uint32_t budget_us)
One block through e: the job built from r with e->done_ctx as its user_data, submitted and waited for...
Definition gfx_turn.c:189
bool gfx_turn_shown(void)
What the panel shows: the one flag picture and touch turn by. Read from any task.
Definition gfx_turn.c:184
bool gfx_turn_take_repaint(gfx_turn_t *t)
Whether the UI must repaint everything before the next frame; clears it.
Definition gfx_turn.c:166
void gfx_turn_request(gfx_turn_t *t, bool turned)
What the setting asks for; taken at the next gfx_turn_next().
Definition gfx_turn.c:31
void gfx_turn_next(gfx_turn_t *t)
After a flip: take the request for the next frame.
Definition gfx_turn.c:148
void gfx_turn_fail(gfx_turn_t *t, gfx_turn_fail_t why)
Fall back to NORMAL until the next start.
Definition gfx_turn.c:38
void gfx_turn_init(gfx_turn_t *t, int width, int height)
NORMAL, nothing failed, for a width x height picture; the shown flag NORMAL too.
Definition gfx_turn.c:20
atomic_uint gfx_turn_stray
Done callbacks that came with a NULL context; gfx_turn.c.
Definition gfx_turn.c:18
bool gfx_turn_presented(gfx_turn_t *t, gfx_turn_show_t show)
The frame of the last flush is on the glass: set the shown flag.
Definition gfx_turn.c:141
bool gfx_turn_drawing(const gfx_turn_t *t)
Whether the frame being drawn goes into a logical buffer.
Definition gfx_turn.c:49
uint32_t gfx_turn_stray_dones(void)
Done callbacks that came with a NULL context since start-up.
Definition gfx_turn.c:218
gfx_turn_fail_t
Why the flush fell back to NORMAL.
Definition gfx_turn.h:58
@ GFX_TURN_FAIL_ERROR
Definition gfx_turn.h:61
@ GFX_TURN_FAIL_TIMEOUT
Definition gfx_turn.h:60
@ GFX_TURN_FAIL_NONE
Definition gfx_turn.h:59
@ GFX_TURN_FAIL_ENGINE
Definition gfx_turn.h:62
gfx_turn_copy_t
How one copy ended.
Definition gfx_turn.h:51
@ GFX_TURN_COPY_DONE
Definition gfx_turn.h:52
@ GFX_TURN_COPY_TIMEOUT
Definition gfx_turn.h:53
@ GFX_TURN_COPY_ERROR
Definition gfx_turn.h:54
static void * gfx_turn_done_ctx(void *user_data)
The done callback's first step: the context it was given, or NULL, counted in gfx_turn_stray_dones(),...
Definition gfx_turn.h:277
gfx_turn_show_t
What a flush leaves in the frame buffer.
Definition gfx_turn.h:66
@ GFX_TURN_SHOW_FALLBACK
Definition gfx_turn.h:69
@ GFX_TURN_SHOW_TURNED
Definition gfx_turn.h:68
@ GFX_TURN_SHOW_NORMAL
Definition gfx_turn.h:67
Definition gfx.h:129
What one buffer has had written since gfx_damage_reset().
Definition gfx_damage.h:44
Definition gfx.h:81
An engine that takes a job, ends it later in an interrupt that calls its done callback with the job's...
Definition gfx_turn.h:118
bool(*) wait(void *engine, uint32_t budget_us)
Wait for the job's done callback.
Definition gfx_turn.h:132
bool(*) submit(void *engine, const gfx_turn_job_t *job)
Start job.
Definition gfx_turn.h:125
void * done_ctx
Definition gfx_turn.h:134
void * engine
Definition gfx_turn.h:133
One block as the copy engine takes it: where it is read, where it lands turned, and the context the e...
Definition gfx_turn.h:100
gfx_rect_t src
Definition gfx_turn.h:105
const gfx_color_t * in
Definition gfx_turn.h:101
int16_t width
Definition gfx_turn.h:103
void * user_data
Definition gfx_turn.h:108
int16_t dst_x
Definition gfx_turn.h:106
int16_t dst_y
Definition gfx_turn.h:107
int16_t height
Definition gfx_turn.h:104
gfx_color_t * out
Definition gfx_turn.h:102
The copy engine.
Definition gfx_turn.h:73
gfx_turn_copy_t(*) copy(void *ctx, const gfx_color_t *src, gfx_color_t *dst, gfx_rect_t r, uint32_t budget_us)
Copy block r of src into dst, turned by 180°, and wait for it.
Definition gfx_turn.h:84
uint32_t(*) now_us(void *ctx)
The time, us; differences wrap.
Definition gfx_turn.h:92
void * ctx
Definition gfx_turn.h:93
The rotation's state.
Definition gfx_turn.h:139
bool failed
Definition gfx_turn.h:145
uint8_t full_left
Definition gfx_turn.h:150
bool alerted
Definition gfx_turn.h:147
bool alert
Definition gfx_turn.h:149
int16_t width
Definition gfx_turn.h:141
gfx_damage_t damage
Definition gfx_turn.h:140
uint32_t copy_us
Definition gfx_turn.h:153
uint16_t rects
Definition gfx_turn.h:151
bool drawing
Definition gfx_turn.h:144
bool requested
Definition gfx_turn.h:143
bool repaint
Definition gfx_turn.h:148
gfx_turn_fail_t why
Definition gfx_turn.h:146
int16_t height
Definition gfx_turn.h:142
uint32_t pixels
Definition gfx_turn.h:152