rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
gfx_int.h
Go to the documentation of this file.
1
9
10#ifndef GFX_INT_H
11#define GFX_INT_H
12
13#include "gfx.h"
14#include "gfx_damage.h"
15
16#include <limits.h>
17#include <stddef.h>
18
23#define GFX_DAMAGE(c, x, y, w, h) \
24 do { \
25 if (gfx_damage_sink != NULL) { \
26 gfx_damage_mark(gfx_damage_sink, (c), (x), (y), (w), (h)); \
27 } \
28 } while (0)
29
34#define GFX_DAMAGE_CLIP(cv, rx, ry, rw, rh) \
35 do { \
36 if (gfx_damage_sink != NULL) { \
37 gfx_rect_t dmg_; \
38 if (gfx_rect_intersect(gfx_rect_make((rx), (ry), (rw), (rh)), \
39 (cv)->clip, &dmg_)) { \
40 gfx_damage_mark(gfx_damage_sink, (cv), dmg_.x, dmg_.y, \
41 dmg_.w, dmg_.h); \
42 } \
43 } \
44 } while (0)
45
52static inline bool canvas_ok(const gfx_canvas_t *c)
53{
54 return c && c->pixels && !gfx_rect_empty(c->clip);
55}
56
57/*
58 * The bodies of gfx_pixel(), gfx_pixel_get(), gfx_hline() and
59 * gfx_clip_intersect(). The public functions in gfx.c are one-line wrappers
60 * around these, and gfx_text.c calls these directly, so that the glyph loop
61 * has them inline: across files the compiler cannot inline the public
62 * functions.
63 *
64 * gfx.c defines GFX_INL_FORCE before including this header. The wrappers
65 * then compile to the body itself, and the callers in gfx.c inline or call
66 * them as they did when the bodies were the public functions. gfx_text.c
67 * leaves the macro undefined; the plain static inline gives it the smaller
68 * glyph loop.
69 */
70#ifdef GFX_INL_FORCE
72#define GFX_INL static inline __attribute__((always_inline))
73#else
75#define GFX_INL static inline
76#endif
85GFX_INL void gfx_pixel_inl(gfx_canvas_t *c, int x, int y,
86 gfx_color_t color)
87{
88 if (!canvas_ok(c) || !gfx_rect_contains(c->clip, x, y)) {
89 return;
90 }
91 GFX_DAMAGE(c, x, y, 1, 1);
92 c->pixels[(ptrdiff_t)y * c->stride + x] = color;
93}
94
104 gfx_color_t color)
105{
106 if (!canvas_ok(c) || !gfx_rect_contains(c->clip, x, y)) {
107 return;
108 }
109 c->pixels[(ptrdiff_t)y * c->stride + x] = color;
110}
111
119GFX_INL gfx_color_t gfx_pixel_get_inl(const gfx_canvas_t *c, int x, int y)
120{
121 if (!c || !c->pixels || x < 0 || y < 0 || x >= c->width || y >= c->height) {
122 return 0;
123 }
124 return c->pixels[(ptrdiff_t)y * c->stride + x];
125}
126
136GFX_INL void gfx_hline_inl(gfx_canvas_t *c, int x, int y, int w,
137 gfx_color_t color)
138{
139 if (w == INT_MIN) {
140 return; /* -INT_MIN is undefined, and no line is this long */
141 }
142 if (w < 0) {
143 x += w + 1;
144 w = -w;
145 }
146 gfx_fill_rect(c, x, y, w, 1, color);
147}
148
156{
157 if (!c) {
158 return false;
159 }
160 return gfx_rect_intersect(r, c->clip, &c->clip);
161}
162
163/*
164 * The fit check's hooks (gfx.h), compiled in only with GFX_TEXT_TRACE. A
165 * shape is reported once, as the caller drew it: the spans a rounded
166 * rectangle or a glyph is filled with are held back. s_trace_hold is
167 * defined in gfx.c.
168 */
169#ifdef GFX_TEXT_TRACE
171extern int s_trace_hold;
173#define TRACE_BOX(c, x, y, w, h) \
174 do { \
175 if (s_trace_hold == 0) { \
176 gfx_trace_box((c), (x), (y), (w), (h)); \
177 } \
178 } while (0)
179
180#define TRACE_HOLD() (++s_trace_hold)
182#define TRACE_RELEASE() (--s_trace_hold)
183#else
185#define TRACE_BOX(c, x, y, w, h) ((void)0)
187#define TRACE_HOLD() ((void)0)
189#define TRACE_RELEASE() ((void)0)
190#endif
191
192#endif /* GFX_INT_H */
int s_trace_hold
The fit check's hold depth: 0 reports, more holds back.
Definition gfx.c:25
bool gfx_rect_intersect(gfx_rect_t a, gfx_rect_t b, gfx_rect_t *out)
Definition gfx.c:93
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_INL void gfx_pixel_put_inl(gfx_canvas_t *c, int x, int y, gfx_color_t color)
One pixel inside the clip, not reported to the damage record: for a caller that reported the area it ...
Definition gfx_int.h:103
GFX_INL gfx_color_t gfx_pixel_get_inl(const gfx_canvas_t *c, int x, int y)
The body of gfx_pixel_get().
Definition gfx_int.h:119
#define GFX_INL
How the primitives' bodies are declared: plain inline.
Definition gfx_int.h:75
static bool canvas_ok(const gfx_canvas_t *c)
Whether c can be drawn on: it exists, has pixels and a non-empty clip.
Definition gfx_int.h:52
GFX_INL void gfx_pixel_inl(gfx_canvas_t *c, int x, int y, gfx_color_t color)
The body of gfx_pixel(): one pixel inside the clip, reported to the damage record.
Definition gfx_int.h:85
GFX_INL bool gfx_clip_intersect_inl(gfx_canvas_t *c, gfx_rect_t r)
The body of gfx_clip_intersect().
Definition gfx_int.h:155
#define GFX_DAMAGE(c, x, y, w, h)
Report a clipped rectangle written through c to the attached damage record (gfx_damage....
Definition gfx_int.h:23
GFX_INL void gfx_hline_inl(gfx_canvas_t *c, int x, int y, int w, gfx_color_t color)
The body of gfx_hline(): a horizontal line through gfx_fill_rect(), drawn leftwards for a negative w.
Definition gfx_int.h:136
Definition gfx.h:129
gfx_rect_t clip
Definition gfx.h:134
int16_t width
Definition gfx.h:131
int16_t height
Definition gfx.h:132
gfx_color_t * pixels
Definition gfx.h:130
int32_t stride
Definition gfx.h:133
Definition gfx.h:81