summaryrefslogtreecommitdiff
path: root/examples/tablet.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tablet.c')
-rw-r--r--examples/tablet.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/examples/tablet.c b/examples/tablet.c
index 176a82b..ce796a4 100644
--- a/examples/tablet.c
+++ b/examples/tablet.c
@@ -24,10 +24,11 @@ static void stamp(uint32_t *pixels, int w, int h, double x, double y, double rad
}
/* Paints paper over the area a resize added, or everything when clear is set. */
-static uint32_t *canvas(yasl_surface *s, int *w, int *h, int *painted_w, int *painted_h, bool clear)
+static uint32_t *canvas(yasl_surface *s, int *w, int *h, int *painted_w, int *painted_h, bool clear, struct yasl_cpu_buffer *buffer)
{
- uint32_t *pixels = yasl_cpu_pixels(s, w, h);
- if (!pixels) return NULL;
+ if (yasl_cpu_acquire(s, buffer) < 0) return NULL;
+ *w = buffer->width; *h = buffer->height;
+ uint32_t *pixels = buffer->pixels;
if (clear) *painted_w = *painted_h = 0;
for (int y = 0; y < *h; y++)
for (int x = y < *painted_h ? *painted_w : 0; x < *w; x++) pixels[(size_t)y * *w + x] = PAPER;
@@ -43,11 +44,11 @@ int main(int argc, char **argv)
if (!strcmp(argv[i], "--smoke-test")) smoke = true;
else if (!strcmp(argv[i], "--backend") && i + 1 < argc) {
const char *b = argv[++i];
- if (!yasl_set_backend(!strcmp(b, "wayland") ? YASL_BACKEND_WAYLAND :
- !strcmp(b, "x11") ? YASL_BACKEND_X11 : YASL_BACKEND_COCOA)) return 1;
+ if (!(yasl_init(&(struct yasl_options){.backend=!strcmp(b, "wayland") ? YASL_BACKEND_WAYLAND :
+ !strcmp(b, "x11") ? YASL_BACKEND_X11 : YASL_BACKEND_COCOA}) == 0)) return 1;
} else return 1;
}
- yasl_surface *s = yasl_surface_create("YASL pen canvas — C clears, Escape exits", 800, 600, YASL_SURFACE_CPU);
+ yasl_surface *s = yasl_surface_create(&(struct yasl_surface_options){.title="YASL pen canvas — C clears, Escape exits", .width=800, .height=600, .type=YASL_SURFACE_CPU, .flags=0});
if (!s) return 1;
int painted_w = 0, painted_h = 0, frames = 0, result = 1;
bool contact = false;
@@ -87,7 +88,8 @@ int main(int argc, char **argv)
if (draw || present) {
int w, h;
int old_w = painted_w, old_h = painted_h;
- uint32_t *pixels = canvas(s, &w, &h, &painted_w, &painted_h, clear);
+ struct yasl_cpu_buffer buffer;
+ uint32_t *pixels = canvas(s, &w, &h, &painted_w, &painted_h, clear, &buffer);
if (!pixels) break;
if (w != old_w || h != old_h) contact = false;
if (draw) {
@@ -99,7 +101,7 @@ int main(int argc, char **argv)
for (int i = 1; i <= steps; i++) stamp(pixels, w, h, x - dx + dx * i / steps, y - dy + dy * i / steps, radius, erase);
last_x = x; last_y = y;
}
- if (!yasl_cpu_present(s)) break;
+ if ((yasl_cpu_present(s, &buffer) < 0)) break;
frames++;
}
if (e.type == YASL_EVENT_PEN || e.type == YASL_EVENT_POINTER) contact = down;