summaryrefslogtreecommitdiff
path: root/tests/x11/test_tablet_native.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/x11/test_tablet_native.c')
-rw-r--r--tests/x11/test_tablet_native.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/tests/x11/test_tablet_native.c b/tests/x11/test_tablet_native.c
index f4f8014..66cdd93 100644
--- a/tests/x11/test_tablet_native.c
+++ b/tests/x11/test_tablet_native.c
@@ -71,8 +71,10 @@ static void render_event(yasl_surface *surface, struct canvas_state *state, cons
state->pen = event->pen;
state->down = event->pen.in_contact;
}
+ struct yasl_cpu_buffer buffer;
+ free(state->pixels);
state->pixels = canvas(surface, &state->width, &state->height,
- &state->painted_width, &state->painted_height, false);
+ &state->painted_width, &state->painted_height, false, &buffer);
assert(state->pixels);
if (event->type == YASL_EVENT_PEN && state->down &&
(event->pen.action == YASL_PEN_DOWN || event->pen.action == YASL_PEN_MOVE)) {
@@ -81,7 +83,11 @@ static void render_event(yasl_surface *surface, struct canvas_state *state, cons
event->pen.x * scale, event->pen.y * scale,
(1.5 + 12 * event->pen.pressure) * scale, event->pen.tool == YASL_PEN_ERASER);
}
- assert(yasl_cpu_present(surface));
+ uint32_t *snapshot = malloc((size_t)state->width * state->height * sizeof(*snapshot));
+ assert(snapshot);
+ memcpy(snapshot, buffer.pixels, (size_t)state->width * state->height * sizeof(*snapshot));
+ assert(yasl_cpu_present(surface, &buffer) == 0);
+ state->pixels = snapshot;
}
static void drain(yasl_surface *surface, struct canvas_state *state)
@@ -101,10 +107,12 @@ static void pump(int fd, yasl_surface *surface, struct canvas_state *state)
receive_all(fd, &response, sizeof(response));
assert(response.type == XF86IT_RESPONSE_SYNC_FINISHED && response.length == sizeof(response));
/* The driver acknowledgment guarantees XI2 processing has finished. */
- XSync(yasl_x11_display(surface), False);
+ struct yasl_x11_handles native;
+ assert(yasl_x11_get_native(surface, &native) == 0);
+ XSync(native.display, False);
drain(surface, state);
/* Public polling submits the CPU frame before the native readback. */
- XSync(yasl_x11_display(surface), False);
+ XSync(native.display, False);
}
static void set_eraser_property(Display *display)
@@ -132,11 +140,13 @@ int main(int argc, char **argv)
{
assert(argc == 3); /* pen socket, eraser socket */
struct canvas_state app = {0};
- assert(yasl_set_backend(YASL_BACKEND_X11));
- yasl_surface *surface = yasl_surface_create("YASL native pressure test", 500, 400, YASL_SURFACE_CPU);
- assert(surface && (yasl_surface_features(surface) & YASL_CAP_TABLET));
- Display *x = yasl_x11_display(surface);
- Window window = (Window)yasl_x11_window(surface);
+ assert((yasl_init(&(struct yasl_options){.backend=YASL_BACKEND_X11}) == 0));
+ yasl_surface *surface = yasl_surface_create(&(struct yasl_surface_options){.title="YASL native pressure test", .width=500, .height=400, .type=YASL_SURFACE_CPU, .flags=0});
+ assert(surface && (yasl_surface_get_features(surface) & YASL_CAP_TABLET));
+ struct yasl_x11_handles native;
+ assert(yasl_x11_get_native(surface, &native) == 0);
+ Display *x = native.display;
+ Window window = (Window)native.window;
XMoveWindow(x, window, 0, 0);
XSetInputFocus(x, window, RevertToParent, CurrentTime);
XSync(x, False);
@@ -194,6 +204,7 @@ int main(int argc, char **argv)
assert(!app.down && !app.pen.pressure);
close(pen_fd);
close(eraser_fd);
+ free(app.pixels);
yasl_shutdown();
puts("Native Xorg pen pressure, stationary pressure, release, and eraser drawing passed.");
return 0;