From 87279f6903343e621c0446b20d1e7d6a495f1125 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Wed, 14 Oct 2026 13:56:48 +0300 Subject: Simplify the public API into one dense header yasl.h now holds everything except Vulkan: 45 functions instead of 62, and three installed headers instead of ten. - One constructor: yasl_surface_create takes CPU, GL or NATIVE, with zero-initialized GL options meaning 3.2 core, RGBA8, D24S8. - Events carry action, mods, x, y and text at the top level; pen positions are now logical like pointer positions. - yasl_cpu_pixels/yasl_cpu_present draw into one persistent canvas, cutting three full-frame copies per frame. - yasl_surface_get_info, yasl_surface_request, YASL_CURSOR_LOCKED, yasl_surface_set_text_input, yasl_surface_begin_move_resize and yasl_surface_get_native replace groups of narrower calls. - Interactive calls drop the decorative trigger event argument. - yasl_wait_event returns 0 only on timeout or yasl_wake, the refresh callback runs only in native modal loops, focus loss sends INPUT_RESET, and a lost event no longer fails every later wait. - Unsupported operations and bad arguments report ENOTSUP and EINVAL instead of EIO; the keycodes header no longer needs C23. - The shared library gets a versioned SONAME and version macros. Co-Authored-By: Claude Opus 5.5 --- tests/common/test_gl.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'tests/common/test_gl.c') diff --git a/tests/common/test_gl.c b/tests/common/test_gl.c index 0e4597b..2bf3d8c 100644 --- a/tests/common/test_gl.c +++ b/tests/common/test_gl.c @@ -1,6 +1,6 @@ #define _POSIX_C_SOURCE 200809L -#include +#include #include #include #include @@ -60,7 +60,9 @@ static void wait_for_size(yasl_surface *surface, int width, int height) double deadline = seconds_now() + 8.0; int actual_width = 0, actual_height = 0; while (seconds_now() < deadline) { - yasl_surface_get_size(surface, &actual_width, &actual_height); + struct yasl_surface_info info = yasl_surface_get_info(surface); + actual_width = info.width; + actual_height = info.height; if (actual_width == width && actual_height == height) return; yasl_event event = {0}; int result = yasl_wait_event(&event, 50); @@ -75,11 +77,12 @@ static void wait_for_size(yasl_surface *surface, int width, int height) int main(int argc, char **argv) { REQUIRE(argc == 2, "expected backend argument: wayland or x11"); - if (!strcmp(argv[1], "wayland")) REQUIRE((yasl_init(&(struct yasl_options){.backend=YASL_BACKEND_WAYLAND}) == 0), "select Wayland backend"); - else if (!strcmp(argv[1], "x11")) REQUIRE((yasl_init(&(struct yasl_options){.backend=YASL_BACKEND_X11}) == 0), "select X11 backend"); + if (!strcmp(argv[1], "wayland")) REQUIRE(yasl_init(YASL_BACKEND_WAYLAND, NULL) == 0, "select Wayland backend"); + else if (!strcmp(argv[1], "x11")) REQUIRE(yasl_init(YASL_BACKEND_X11, NULL) == 0, "select X11 backend"); else REQUIRE(false, "backend must be wayland or x11"); - primary = yasl_gl_surface_create(&(struct yasl_surface_options){.title="YASL GL test", .width=320, .height=240, .type=YASL_SURFACE_NATIVE, .flags=0}, NULL); + primary = yasl_surface_create(&(struct yasl_surface_options){.title="YASL GL test", .width=320, .height=240, .type=YASL_SURFACE_GL}); + REQUIRE(yasl_get_features() & YASL_FEATURE_OPENGL, "report OpenGL support"); REQUIRE(primary != NULL, "create default OpenGL 3.2 surface"); REQUIRE((yasl_gl_make_current(primary) == 0), "make first GL context current"); @@ -109,7 +112,8 @@ int main(int argc, char **argv) finish(); unsigned char pixel[4] = {0}; int pixel_width = 0, pixel_height = 0; - yasl_surface_get_framebuffer_size(primary, &pixel_width, &pixel_height); + pixel_width = yasl_surface_get_info(primary).pixel_width; + pixel_height = yasl_surface_get_info(primary).pixel_height; REQUIRE(pixel_width > 0 && pixel_height > 0, "query initial framebuffer size"); read_pixels(pixel_width / 2, pixel_height / 2, 1, 1, GL_RGBA_, GL_UNSIGNED_BYTE_, pixel); REQUIRE(abs((int)pixel[0] - 51) <= 3 && abs((int)pixel[1] - 102) <= 3 && @@ -123,9 +127,7 @@ int main(int argc, char **argv) bind_texture(GL_TEXTURE_2D_, texture); REQUIRE(is_texture(texture), "create a shareable GL texture"); - struct yasl_gl_options sharing = YASL_GL_OPTIONS_INIT; - sharing.share = primary; - shared = yasl_gl_surface_create(&(struct yasl_surface_options){.title="YASL GL shared context", .width=160, .height=120, .type=YASL_SURFACE_NATIVE, .flags=0}, &sharing); + shared = yasl_surface_create(&(struct yasl_surface_options){.title="YASL GL shared context", .width=160, .height=120, .type=YASL_SURFACE_GL, .gl = {.share = primary}}); REQUIRE(shared != NULL, "create shared GL context"); REQUIRE((yasl_gl_make_current(shared) == 0), "make shared context current"); REQUIRE(is_texture(texture), "verify context shares GL objects"); @@ -134,8 +136,9 @@ int main(int argc, char **argv) REQUIRE((yasl_surface_request_size(primary, 400, 300) == 0), "request surface resize"); wait_for_size(primary, 400, 300); - yasl_surface_get_framebuffer_size(primary, &pixel_width, &pixel_height); - double scale = yasl_surface_get_scale(primary); + pixel_width = yasl_surface_get_info(primary).pixel_width; + pixel_height = yasl_surface_get_info(primary).pixel_height; + double scale = yasl_surface_get_info(primary).scale; REQUIRE(abs(pixel_width - (int)lround(400 * scale)) <= 1 && abs(pixel_height - (int)lround(300 * scale)) <= 1, "query resized framebuffer dimensions"); @@ -143,13 +146,11 @@ int main(int argc, char **argv) clear(GL_COLOR_BUFFER_BIT_); REQUIRE((yasl_gl_present(primary) == 0), "swap resized GL surface"); - struct yasl_gl_options invalid_options = YASL_GL_OPTIONS_INIT; - invalid_options.major = -1; - REQUIRE(yasl_gl_surface_create(&(struct yasl_surface_options){.title="invalid attrs", .width=100, .height=100, .type=YASL_SURFACE_NATIVE, .flags=0}, &invalid_options) == NULL, + REQUIRE(yasl_surface_create(&(struct yasl_surface_options){.title="invalid attrs", .width=100, .height=100, .type=YASL_SURFACE_GL, .gl = {.major = -1}}) == NULL && errno == EINVAL, "reject invalid GL context options"); - REQUIRE(yasl_gl_surface_create(&(struct yasl_surface_options){.title="invalid CPU GL", .width=100, .height=100, .type=YASL_SURFACE_CPU, .flags=0}, NULL) == NULL, - "reject CPU flag on GL surface creation"); - cpu = yasl_surface_create(&(struct yasl_surface_options){.title="CPU surface", .width=100, .height=100, .type=YASL_SURFACE_CPU, .flags=0}); + cpu = yasl_surface_create(&(struct yasl_surface_options){.title="CPU surface", .width=100, .height=100}); + REQUIRE(yasl_surface_create(&(struct yasl_surface_options){.title="no CPU sharing", .width=100, .height=100, .type=YASL_SURFACE_GL, .gl = {.share = cpu}}) == NULL && errno == EINVAL, + "reject a non-GL share surface"); REQUIRE(cpu != NULL, "create CPU surface for incompatibility check"); REQUIRE((yasl_gl_make_current(cpu) < 0), "reject CPU surface as a GL context"); -- cgit v1.2.3