summaryrefslogtreecommitdiff
path: root/tests/cocoa/test_native.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
commit76073fe5fad8799e5850805f2f090af2cb62c741 (patch)
tree9658019babe4760a3634bdab4da0731a10e42e68 /tests/cocoa/test_native.c
parentdd1775a9927922c14f8679ccbc4d3ca8d5917e20 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'tests/cocoa/test_native.c')
-rw-r--r--tests/cocoa/test_native.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/tests/cocoa/test_native.c b/tests/cocoa/test_native.c
index 674513d..9b8f8fa 100644
--- a/tests/cocoa/test_native.c
+++ b/tests/cocoa/test_native.c
@@ -1,77 +1,77 @@
#define _POSIX_C_SOURCE 200809L
-#include "yasl/native.h"
-#include "yasl/loop.h"
-#include "yasl/yasl.h"
+#include "common/private_native.h"
+#include "common/private_loop.h"
+#include "common/types.h"
#include <assert.h>
#include <time.h>
struct state {
- struct yasl_display *display;
+ struct yasl_private_display *display;
struct yasl_surface *surface;
unsigned draws;
};
-static void draw(struct yasl_surface *surface, struct yasl_frame *frame, void *ud)
+static void draw(struct yasl_surface *surface, struct yasl_private_frame *frame, void *ud)
{
struct state *state = ud;
assert(surface == state->surface && frame->surface == surface);
- assert(yasl_surface_display(surface) == state->display);
+ assert(yasl_private_surface_display(surface) == state->display);
assert(frame->target.pixels);
- struct yasl_native_frame native;
- assert(yasl_surface_get_native_frame(surface, &frame->target, &native));
+ struct yasl_private_native_frame native;
+ assert(yasl_private_surface_get_native_frame(surface, &frame->target, &native));
assert(native.drawable);
- struct yasl_vector2i size = yasl_surface_geometry(surface).size;
+ struct yasl_private_vector2i size = yasl_private_surface_geometry(surface).size;
assert(size.x == frame->target.size.x && size.y == frame->target.size.y);
for (int i = 0; i < size.x * size.y; i++) frame->target.pixels[i] = 0xff4080c0;
- struct yasl_damage_list damage = {.n = YASL_DAMAGE_MAX + 1};
- assert(!yasl_surface_present(surface, &frame->target, &damage));
+ struct yasl_private_damage_list damage = {.n = YASL_PRIVATE_DAMAGE_MAX + 1};
+ assert(!yasl_private_surface_present(surface, &frame->target, &damage));
damage.n = -1;
- struct yasl_framebuffer invalid = frame->target;
+ struct yasl_private_framebuffer invalid = frame->target;
invalid.size.x++;
- assert(!yasl_surface_present(surface, &invalid, &damage));
+ assert(!yasl_private_surface_present(surface, &invalid, &damage));
invalid = frame->target;
invalid.generation--;
- assert(!yasl_surface_present(surface, &invalid, &damage));
- assert(!yasl_surface_present(surface, &frame->target, NULL));
- assert(yasl_surface_present(surface, &frame->target, &damage));
- assert(!yasl_surface_get_native_frame(surface, &frame->target, &native));
- assert(!yasl_surface_present(surface, &frame->target, &damage));
+ assert(!yasl_private_surface_present(surface, &invalid, &damage));
+ assert(!yasl_private_surface_present(surface, &frame->target, NULL));
+ assert(yasl_private_surface_present(surface, &frame->target, &damage));
+ assert(!yasl_private_surface_get_native_frame(surface, &frame->target, &native));
+ assert(!yasl_private_surface_present(surface, &frame->target, &damage));
state->draws++;
- yasl_surface_destroy(surface);
+ yasl_private_surface_destroy(surface);
state->surface = NULL;
}
-static void test_window(enum yasl_backend request, bool null_spec)
+static void test_window(enum yasl_private_backend request, bool null_spec)
{
- struct yasl_display_spec spec = {.backend = request};
- struct state state = {.display = yasl_display_open(NULL, null_spec ? NULL : &spec)};
+ struct yasl_private_display_spec spec = {.backend = request};
+ struct state state = {.display = yasl_private_display_open(NULL, null_spec ? NULL : &spec)};
assert(state.display);
- assert(yasl_display_backend(state.display) == YASL_BACKEND_COCOA);
- struct yasl_window_cbs callbacks = {.draw = draw};
- struct yasl_window_spec surface = {
+ assert(yasl_private_display_backend(state.display) == YASL_PRIVATE_BACKEND_COCOA);
+ struct yasl_private_window_cbs callbacks = {.draw = draw};
+ struct yasl_private_window_spec surface = {
.title = "Native backend test", .size = {160, 100},
.cbs = &callbacks, .ud = &state,
};
- state.surface = yasl_surface_create_toplevel(state.display, &surface);
+ state.surface = yasl_private_surface_create_toplevel(state.display, &surface);
assert(state.surface);
assert(!state.draws);
callbacks.draw = NULL;
- yasl_surface_schedule_redraw(state.surface);
- uint64_t deadline = yasl_loop_now_ns() + 3000000000ull;
- while (!state.draws && yasl_loop_now_ns() < deadline) {
- yasl_display_dispatch(state.display, 0);
- yasl_display_flush(state.display);
+ yasl_private_surface_schedule_redraw(state.surface);
+ uint64_t deadline = yasl_private_loop_now_ns() + 3000000000ull;
+ while (!state.draws && yasl_private_loop_now_ns() < deadline) {
+ yasl_private_display_dispatch(state.display, 0);
+ yasl_private_display_flush(state.display);
nanosleep(&(struct timespec){.tv_nsec = 1000000}, NULL);
}
assert(state.draws == 1 && !state.surface);
- yasl_display_close(state.display);
+ yasl_private_display_close(state.display);
}
int main(void)
{
- test_window(YASL_BACKEND_AUTO, true);
- test_window(YASL_BACKEND_AUTO, false);
- test_window(YASL_BACKEND_COCOA, false);
+ test_window(YASL_PRIVATE_BACKEND_AUTO, true);
+ test_window(YASL_PRIVATE_BACKEND_AUTO, false);
+ test_window(YASL_PRIVATE_BACKEND_COCOA, false);
return 0;
}