From 76073fe5fad8799e5850805f2f090af2cb62c741 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 23:41:31 +0300 Subject: Simplify the public event and CPU API Applications now need far less ceremony: hello.c is a 20-line loop that handles REFRESH, CLOSE and QUIT and draws into the surface's own pixels. - Fold GEOMETRY, STATE and FOCUS into one WINDOW event carrying size, scale and state; unchanged values send nothing. - Guarantee REFRESH once a window has a size and after every resize, never at size zero. - Merge DROP_HOVER into DROP with over/leave/data actions and give drag and drop actions enums. - Keep event strings valid until the next wait and drop yasl_event_release; empty or failed waits report NONE. - Replace copy-in presentation with a lent pixel buffer: yasl_cpu_pixels and yasl_cpu_present. - Remove yasl_poll_event, yasl_cpu_read_pixels, unused event fields and comments that restated names. - Wayland: resize floating windows in request_size instead of reporting it unsupported, and stop marking new GPU surfaces as Vulkan so yasl_vulkan_create_surface no longer fails with NATIVE_WINDOW_IN_USE. Also includes the in-progress public API refactor that was uncommitted in the tree (removal of the app/loop layer, new surface, GL and Vulkan entry points). Co-Authored-By: Claude Opus 5.5 --- tests/benchmark.c | 150 +++++++++++++++++++++++++++--------------------------- 1 file changed, 75 insertions(+), 75 deletions(-) (limited to 'tests/benchmark.c') diff --git a/tests/benchmark.c b/tests/benchmark.c index 1cea614..8fa8066 100644 --- a/tests/benchmark.c +++ b/tests/benchmark.c @@ -7,12 +7,12 @@ #include #include -#include "yasl/yasl.h" -#include "yasl/loop.h" -#include "yasl/timing.h" +#include "common/types.h" +#include "common/private_loop.h" +#include "common/private_timing.h" #include "common/input.h" #if YASL_HAS_WAYLAND -#include "yasl/native/wayland.h" +#include "common/private_native_wayland.h" #endif static inline uint64_t get_time_ns(void) { @@ -48,28 +48,28 @@ static void print_bench_skipped(const char *name, const char *reason) { static void bench_surface_lookup(void) { const int num_surfaces = 16; const int lookups = 10000000; - struct yasl_display_spec spec = { + struct yasl_private_display_spec spec = { .app_id = "org.yasl.benchmark", - .backend = YASL_BACKEND_WAYLAND, + .backend = YASL_PRIVATE_BACKEND_WAYLAND, }; - struct yasl_display *d = yasl_display_open(NULL, &spec); + struct yasl_private_display *d = yasl_private_display_open(NULL, &spec); struct yasl_surface *surfaces[num_surfaces]; memset(surfaces, 0, sizeof(surfaces)); if (d) { for (int i = 0; i < num_surfaces; i++) { - struct yasl_window_spec sspec = { + struct yasl_private_window_spec sspec = { .title = "Benchmark", .size = { .x = 320, .y = 240 }, }; - surfaces[i] = yasl_surface_create_toplevel(d, &sspec); + surfaces[i] = yasl_private_surface_create_toplevel(d, &sspec); } } uint64_t t0 = get_time_ns(); uintptr_t sum = 0; for (int i = 0; i < lookups; i++) { - struct wl_surface *found = yasl_wayland_surface_get_wl_surface(surfaces[i % num_surfaces]); + struct wl_surface *found = yasl_private_wayland_surface_get_wl_surface(surfaces[i % num_surfaces]); sum += (uintptr_t)found; } uint64_t t1 = get_time_ns(); @@ -82,35 +82,35 @@ static void bench_surface_lookup(void) { if (d) { for (int i = 0; i < num_surfaces; i++) { - if (surfaces[i]) yasl_surface_destroy(surfaces[i]); + if (surfaces[i]) yasl_private_surface_destroy(surfaces[i]); } - yasl_display_close(d); + yasl_private_display_close(d); } } /* Benchmark 2: Public Surface Geometry & Refresh Timing */ static void bench_output_follow(void) { const int iters = 10000000; - struct yasl_display_spec spec = { + struct yasl_private_display_spec spec = { .app_id = "org.yasl.benchmark", - .backend = YASL_BACKEND_WAYLAND, + .backend = YASL_PRIVATE_BACKEND_WAYLAND, }; - struct yasl_display *d = yasl_display_open(NULL, &spec); + struct yasl_private_display *d = yasl_private_display_open(NULL, &spec); struct yasl_surface *s = NULL; if (d) { - struct yasl_window_spec sspec = { + struct yasl_private_window_spec sspec = { .title = "Benchmark", .size = { .x = 320, .y = 240 }, }; - s = yasl_surface_create_toplevel(d, &sspec); + s = yasl_private_surface_create_toplevel(d, &sspec); } uint64_t t0 = get_time_ns(); uint64_t sum = 0; for (int i = 0; i < iters; i++) { - struct yasl_geometry geom = yasl_surface_geometry(s); - struct yasl_timing timing = yasl_surface_timing(s); - int dev = yasl_scale_to_device(320.0, geom.scale_120); + struct yasl_private_geometry geom = yasl_private_surface_geometry(s); + struct yasl_private_timing timing = yasl_private_surface_timing(s); + int dev = yasl_private_scale_to_device(320.0, geom.scale_120); sum += (uint64_t)dev + timing.refresh_ns; } uint64_t t1 = get_time_ns(); @@ -121,8 +121,8 @@ static void bench_output_follow(void) { iters, (unsigned long long)sum); print_bench_row("[2] surface_geometry_timing", per_cycle, ms, details); - if (s) yasl_surface_destroy(s); - if (d) yasl_display_close(d); + if (s) yasl_private_surface_destroy(s); + if (d) yasl_private_display_close(d); } #endif @@ -135,8 +135,8 @@ static void bench_input_queue_resize(void) { for (int b = 0; b < batches; b++) { struct input_queue q = {0}; for (int i = 0; i < size; i++) { - struct yasl_event ev = { - .type = YASL_EVENT_POINTER_MOTION, + struct yasl_private_event ev = { + .type = YASL_PRIVATE_EVENT_POINTER_MOTION, .pointer = { .pos = { .x = i, .y = b } }, }; input_queue_push(&q, &ev); @@ -160,13 +160,13 @@ static void bench_input_queue_push_pop(void) { uint64_t t0 = get_time_ns(); for (int r = 0; r < rounds; r++) { for (int i = 0; i < events_per_round; i++) { - struct yasl_event ev = { - .type = YASL_EVENT_POINTER_DOWN, - .pointer = { .pos = { .x = i, .y = r }, .button = YASL_BUTTON_MIDDLE }, + struct yasl_private_event ev = { + .type = YASL_PRIVATE_EVENT_POINTER_DOWN, + .pointer = { .pos = { .x = i, .y = r }, .button = YASL_PRIVATE_BUTTON_MIDDLE }, }; input_queue_push(&q, &ev); } - struct yasl_event out; + struct yasl_private_event out; while (input_queue_pop(&q, &out)) { /* consume */ } @@ -181,22 +181,22 @@ static void bench_input_queue_push_pop(void) { } /* Benchmark 5: Event Loop Timers Add & Delete */ -static uint64_t timer_dummy_cb(void *ud, yasl_timer_id id, uint64_t interval_ns) { +static uint64_t timer_dummy_cb(void *ud, yasl_private_timer_id id, uint64_t interval_ns) { (void)ud; (void)id; (void)interval_ns; return 0; } static void bench_timers(void) { const int iters = 2000000; - struct yasl_loop *loop = yasl_loop_create(); + struct yasl_private_loop *loop = yasl_private_loop_create(); uint64_t t0 = get_time_ns(); for (int i = 0; i < iters; i++) { - yasl_timer_id id = yasl_loop_add_timer(loop, 1000000, timer_dummy_cb, NULL); - yasl_loop_del_timer(loop, id); + yasl_private_timer_id id = yasl_private_loop_add_timer(loop, 1000000, timer_dummy_cb, NULL); + yasl_private_loop_del_timer(loop, id); } uint64_t t1 = get_time_ns(); - yasl_loop_destroy(loop); + yasl_private_loop_destroy(loop); double ms = (double)(t1 - t0) / 1e6; double per_cycle = (double)(t1 - t0) / iters; char details[128]; @@ -207,30 +207,30 @@ static void bench_timers(void) { /* Benchmark 6: Window Cold Create & Teardown */ static void bench_window_cold_create(void) { const int iters = 200; - struct yasl_display_spec dspec = { .app_id = "org.yasl.bench.cold" }; - struct yasl_window_spec sspec = { + struct yasl_private_display_spec dspec = { .app_id = "org.yasl.bench.cold" }; + struct yasl_private_window_spec sspec = { .title = "Benchmark Cold", .size = { .x = 320, .y = 240 }, }; - struct yasl_display *probe = yasl_display_open(NULL, &dspec); + struct yasl_private_display *probe = yasl_private_display_open(NULL, &dspec); if (!probe) { print_bench_skipped("[6] window_cold_create", "no display server"); return; } - yasl_display_close(probe); + yasl_private_display_close(probe); uint64_t t0 = get_time_ns(); int count = 0; for (int i = 0; i < iters; i++) { - struct yasl_display *d = yasl_display_open(NULL, &dspec); + struct yasl_private_display *d = yasl_private_display_open(NULL, &dspec); if (d) { - struct yasl_surface *s = yasl_surface_create_toplevel(d, &sspec); + struct yasl_surface *s = yasl_private_surface_create_toplevel(d, &sspec); if (s) { - yasl_surface_destroy(s); + yasl_private_surface_destroy(s); count++; } - yasl_display_close(d); + yasl_private_display_close(d); } } uint64_t t1 = get_time_ns(); @@ -244,14 +244,14 @@ static void bench_window_cold_create(void) { /* Benchmark 7: Window Warm Create */ static void bench_window_warm_create(void) { const int iters = 2000; - struct yasl_display_spec dspec = { .app_id = "org.yasl.bench.warm" }; - struct yasl_display *d = yasl_display_open(NULL, &dspec); + struct yasl_private_display_spec dspec = { .app_id = "org.yasl.bench.warm" }; + struct yasl_private_display *d = yasl_private_display_open(NULL, &dspec); if (!d) { print_bench_skipped("[7] window_warm_create", "no display server"); return; } - struct yasl_window_spec sspec = { + struct yasl_private_window_spec sspec = { .title = "Benchmark Warm", .size = { .x = 320, .y = 240 }, }; @@ -259,14 +259,14 @@ static void bench_window_warm_create(void) { uint64_t t0 = get_time_ns(); int count = 0; for (int i = 0; i < iters; i++) { - struct yasl_surface *s = yasl_surface_create_toplevel(d, &sspec); + struct yasl_surface *s = yasl_private_surface_create_toplevel(d, &sspec); if (s) { - yasl_surface_destroy(s); + yasl_private_surface_destroy(s); count++; } } uint64_t t1 = get_time_ns(); - yasl_display_close(d); + yasl_private_display_close(d); double ms = (double)(t1 - t0) / 1e6; double per_cycle = count ? (double)(t1 - t0) / count : 0.0; char details[128]; @@ -277,14 +277,14 @@ static void bench_window_warm_create(void) { /* Benchmark 8: Window Shutdown (Single) */ static void bench_window_shutdown_single(void) { const int iters = 2000; - struct yasl_display_spec dspec = { .app_id = "org.yasl.bench.shutdown_single" }; - struct yasl_display *d = yasl_display_open(NULL, &dspec); + struct yasl_private_display_spec dspec = { .app_id = "org.yasl.bench.shutdown_single" }; + struct yasl_private_display *d = yasl_private_display_open(NULL, &dspec); if (!d) { print_bench_skipped("[8] window_shutdown_single", "no display server"); return; } - struct yasl_window_spec sspec = { + struct yasl_private_window_spec sspec = { .title = "Benchmark Shutdown Single", .size = { .x = 320, .y = 240 }, }; @@ -292,16 +292,16 @@ static void bench_window_shutdown_single(void) { uint64_t destroy_time_ns = 0; int count = 0; for (int i = 0; i < iters; i++) { - struct yasl_surface *s = yasl_surface_create_toplevel(d, &sspec); + struct yasl_surface *s = yasl_private_surface_create_toplevel(d, &sspec); if (s) { uint64_t t0 = get_time_ns(); - yasl_surface_destroy(s); + yasl_private_surface_destroy(s); uint64_t t1 = get_time_ns(); destroy_time_ns += (t1 - t0); count++; } } - yasl_display_close(d); + yasl_private_display_close(d); double ms = (double)destroy_time_ns / 1e6; double per_cycle = count ? (double)destroy_time_ns / count : 0.0; char details[128]; @@ -313,14 +313,14 @@ static void bench_window_shutdown_single(void) { static void bench_window_shutdown_all(void) { const int batches = 50; const int batch_size = 64; - struct yasl_display_spec dspec = { .app_id = "org.yasl.bench.shutdown_all" }; - struct yasl_display *d = yasl_display_open(NULL, &dspec); + struct yasl_private_display_spec dspec = { .app_id = "org.yasl.bench.shutdown_all" }; + struct yasl_private_display *d = yasl_private_display_open(NULL, &dspec); if (!d) { print_bench_skipped("[9] window_shutdown_all", "no display server"); return; } - struct yasl_window_spec sspec = { + struct yasl_private_window_spec sspec = { .title = "Benchmark Bulk Window", .size = { .x = 320, .y = 240 }, }; @@ -331,12 +331,12 @@ static void bench_window_shutdown_all(void) { for (int b = 0; b < batches; b++) { for (int i = 0; i < batch_size; i++) { - surfaces[i] = yasl_surface_create_toplevel(d, &sspec); + surfaces[i] = yasl_private_surface_create_toplevel(d, &sspec); } uint64_t t0 = get_time_ns(); for (int i = 0; i < batch_size; i++) { if (surfaces[i]) { - yasl_surface_destroy(surfaces[i]); + yasl_private_surface_destroy(surfaces[i]); surfaces[i] = NULL; total_destroyed++; } @@ -344,7 +344,7 @@ static void bench_window_shutdown_all(void) { uint64_t t1 = get_time_ns(); destroy_time_ns += (t1 - t0); } - yasl_display_close(d); + yasl_private_display_close(d); double ms = (double)destroy_time_ns / 1e6; double per_cycle = total_destroyed ? (double)destroy_time_ns / total_destroyed : 0.0; double per_batch_ns = batches ? (double)destroy_time_ns / batches : 0.0; @@ -359,20 +359,20 @@ static void bench_window_shutdown_all(void) { /* Benchmark 10: Window Titlebar Update */ static void bench_window_title_update(void) { const int iters = 200000; - struct yasl_display_spec dspec = { .app_id = "org.yasl.bench.title" }; - struct yasl_display *d = yasl_display_open(NULL, &dspec); + struct yasl_private_display_spec dspec = { .app_id = "org.yasl.bench.title" }; + struct yasl_private_display *d = yasl_private_display_open(NULL, &dspec); if (!d) { print_bench_skipped("[10] window_titlebar_update", "no display server"); return; } - struct yasl_window_spec sspec = { + struct yasl_private_window_spec sspec = { .title = "Initial Title", .size = { .x = 320, .y = 240 }, }; - struct yasl_surface *s = yasl_surface_create_toplevel(d, &sspec); + struct yasl_surface *s = yasl_private_surface_create_toplevel(d, &sspec); if (!s) { - yasl_display_close(d); + yasl_private_display_close(d); print_bench_skipped("[10] window_titlebar_update", "failed to create surface"); return; } @@ -386,11 +386,11 @@ static void bench_window_title_update(void) { uint64_t t0 = get_time_ns(); for (int i = 0; i < iters; i++) { - yasl_surface_set_title(s, titles[i & 3]); + yasl_private_surface_set_title(s, titles[i & 3]); } uint64_t t1 = get_time_ns(); - yasl_surface_destroy(s); - yasl_display_close(d); + yasl_private_surface_destroy(s); + yasl_private_display_close(d); double ms = (double)(t1 - t0) / 1e6; double per_cycle = (double)(t1 - t0) / iters; char details[128]; @@ -401,14 +401,14 @@ static void bench_window_title_update(void) { /* Benchmark 11: Window Resize / Dimension Reallocation */ static void bench_window_resize(void) { const int iters = 2000; - struct yasl_display_spec dspec = { .app_id = "org.yasl.bench.resize" }; - struct yasl_display *d = yasl_display_open(NULL, &dspec); + struct yasl_private_display_spec dspec = { .app_id = "org.yasl.bench.resize" }; + struct yasl_private_display *d = yasl_private_display_open(NULL, &dspec); if (!d) { print_bench_skipped("[11] window_resize_cycle", "no display server"); return; } - static const struct yasl_vector2i sizes[] = { + static const struct yasl_private_vector2i sizes[] = { { 320, 240 }, { 640, 480 }, { 800, 600 }, @@ -421,20 +421,20 @@ static void bench_window_resize(void) { uint64_t t0 = get_time_ns(); int count = 0; for (int i = 0; i < iters; i++) { - struct yasl_window_spec sspec = { + struct yasl_private_window_spec sspec = { .title = "Resize Bench", .size = sizes[i % num_sizes], }; - struct yasl_surface *s = yasl_surface_create_toplevel(d, &sspec); + struct yasl_surface *s = yasl_private_surface_create_toplevel(d, &sspec); if (s) { - struct yasl_geometry geom = yasl_surface_geometry(s); + struct yasl_private_geometry geom = yasl_private_surface_geometry(s); (void)geom; - yasl_surface_destroy(s); + yasl_private_surface_destroy(s); count++; } } uint64_t t1 = get_time_ns(); - yasl_display_close(d); + yasl_private_display_close(d); double ms = (double)(t1 - t0) / 1e6; double per_cycle = count ? (double)(t1 - t0) / count : 0.0; char details[128]; -- cgit v1.2.3