diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-14 13:56:48 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-14 13:56:48 +0300 |
| commit | 87279f6903343e621c0446b20d1e7d6a495f1125 (patch) | |
| tree | 999b5fb5fb76702efb02f856f082147304f0859b /tests/wayland/test_reconnect.c | |
| parent | 1ab3e5a123109704789c2768e11a4f9af515821d (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'tests/wayland/test_reconnect.c')
| -rw-r--r-- | tests/wayland/test_reconnect.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/tests/wayland/test_reconnect.c b/tests/wayland/test_reconnect.c index 737afb2..891d98b 100644 --- a/tests/wayland/test_reconnect.c +++ b/tests/wayland/test_reconnect.c @@ -2,9 +2,6 @@ * after "ready" and starts a new one after "lost". Windows must survive, keep * their pixels, and accept new GL and Vulkan objects after DISPLAY_RESTORED. */ #include <yasl/yasl.h> -#include <yasl/cpu.h> -#include <yasl/gl.h> -#include <yasl/native/wayland.h> #if TEST_VULKAN #include <yasl/vulkan.h> #endif @@ -58,29 +55,25 @@ static VkSurfaceKHR vulkan_surface(void) int main(void) { - CHECK((yasl_init(&(struct yasl_options){.backend=YASL_BACKEND_WAYLAND}) == 0), "selecting Wayland"); - cpu = yasl_surface_create(&(struct yasl_surface_options){.title="reconnect CPU", .width=160, .height=120, .type=YASL_SURFACE_CPU, .flags=0}); + CHECK(yasl_init(YASL_BACKEND_WAYLAND, NULL) == 0, "selecting Wayland"); + cpu = yasl_surface_create(&(struct yasl_surface_options){.title="reconnect CPU", .width=160, .height=120}); CHECK(cpu, "creating CPU window"); - gl = yasl_gl_surface_create(&(struct yasl_surface_options){.title="reconnect GL", .width=160, .height=120, .type=YASL_SURFACE_NATIVE, .flags=0}, NULL); + gl = yasl_surface_create(&(struct yasl_surface_options){.title="reconnect GL", .width=160, .height=120, .type=YASL_SURFACE_GL}); CHECK(gl, "creating GL window"); expect(YASL_EVENT_REFRESH, cpu, 5000); int w, h; - struct yasl_cpu_buffer buffer; - CHECK(yasl_cpu_acquire(cpu, &buffer) == 0, "acquire CPU buffer"); - w=buffer.width; h=buffer.height; - uint32_t *pixels = buffer.pixels; + uint32_t *pixels = yasl_cpu_pixels(cpu, &w, &h); CHECK(pixels, "getting pixels"); for (size_t i = 0; i < (size_t)w * h; i++) pixels[i] = 0xff336699u; - CHECK((yasl_cpu_present(cpu, &buffer) == 0), "presenting"); + CHECK(yasl_cpu_present(cpu) == 0, "presenting"); draw_gl(0.8f); #if TEST_VULKAN - CHECK((yasl_vulkan_init(vkGetInstanceProcAddr) == 0), "loading Vulkan"); - vk = yasl_surface_create(&(struct yasl_surface_options){.title="reconnect Vulkan", .width=160, .height=120, .type=YASL_SURFACE_NATIVE, .flags=0}); - CHECK(vk, "creating Vulkan window"); struct yasl_vulkan_requirements requirements; - CHECK(yasl_vulkan_get_requirements(vk, &requirements) == 0, "Vulkan requirements"); + CHECK(yasl_vulkan_init(vkGetInstanceProcAddr, &requirements) == 0, "loading Vulkan"); + vk = yasl_surface_create(&(struct yasl_surface_options){.title="reconnect Vulkan", .width=160, .height=120, .type=YASL_SURFACE_NATIVE}); + CHECK(vk, "creating Vulkan window"); VkInstanceCreateInfo info = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .flags = requirements.flags, .enabledExtensionCount = requirements.extension_count, .ppEnabledExtensionNames = requirements.extensions}; @@ -92,29 +85,29 @@ int main(void) fflush(stdout); expect(YASL_EVENT_DISPLAY_LOST, NULL, 10000); - struct yasl_wayland_handles native; - CHECK(yasl_wayland_get_native(cpu, &native) == -ENOTCONN && !native.display && !native.surface, + struct yasl_native native; + CHECK(yasl_surface_get_native(cpu, &native) == -ENOTCONN && !native.wl_display && !native.wl_surface, "rejecting native handles while offline"); - CHECK(yasl_cpu_acquire(cpu, &buffer) == -ENOTCONN, "rejecting CPU acquisition while offline"); + CHECK(yasl_cpu_present(cpu) == -ENOTCONN, "rejecting CPU presentation while offline"); CHECK(yasl_gl_make_current(gl) == -ENOTCONN, "rejecting GL binding while offline"); + CHECK(yasl_gl_make_current(NULL) == 0, "detaching GL while offline"); #if TEST_VULKAN CHECK(yasl_vulkan_destroy_surface(vk) == 0, "destroying Vulkan surface"); #endif - CHECK(!yasl_surface_create(&(struct yasl_surface_options){.title="offline", .width=64, .height=64, .type=YASL_SURFACE_CPU, .flags=0}), "refusing windows while offline"); + CHECK(!yasl_surface_create(&(struct yasl_surface_options){.title="offline", .width=64, .height=64}), "refusing windows while offline"); CHECK(errno == ENOTCONN, "reporting the disconnect"); puts("lost"); fflush(stdout); expect(YASL_EVENT_DISPLAY_RESTORED, NULL, 15000); - CHECK(yasl_wayland_get_native(cpu, &native) == 0 && native.display && native.surface, + CHECK(yasl_surface_get_native(cpu, &native) == 0 && native.wl_display && native.wl_surface, "querying restored native handles"); expect(YASL_EVENT_REFRESH, cpu, 5000); int rw, rh; - CHECK(yasl_cpu_acquire(cpu, &buffer) == 0, "reacquire CPU buffer"); - rw=buffer.width; rh=buffer.height; pixels=buffer.pixels; + pixels = yasl_cpu_pixels(cpu, &rw, &rh); CHECK(pixels && rw == w && rh == h, "keeping the window size"); CHECK(pixels[0] == 0xff336699u && pixels[(size_t)w * h - 1] == 0xff336699u, "keeping the pixels"); - CHECK((yasl_cpu_present(cpu, &buffer) == 0), "presenting after reconnect"); + CHECK(yasl_cpu_present(cpu) == 0, "presenting after reconnect"); draw_gl(0.1f); #if TEST_VULKAN CHECK(vulkan_surface() != VK_NULL_HANDLE, "restored Vulkan handle"); @@ -123,7 +116,7 @@ int main(void) #endif /* A second window proves the new connection accepts creation. */ - CHECK(yasl_surface_create(&(struct yasl_surface_options){.title="after reconnect", .width=64, .height=64, .type=YASL_SURFACE_CPU, .flags=0}), "creating a window after reconnect"); + CHECK(yasl_surface_create(&(struct yasl_surface_options){.title="after reconnect", .width=64, .height=64}), "creating a window after reconnect"); yasl_gl_make_current(NULL); yasl_shutdown(); puts("restored"); |
