summaryrefslogtreecommitdiff
path: root/src/cocoa
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-12 00:09:38 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-12 00:09:38 +0300
commit624d1371304a5ae4b3429ad5e4267aac7cd03dfd (patch)
tree32de069f6eec83686521fc4bf39cc9874b123e93 /src/cocoa
parente813252e685d761235ad45e170d97c9375f51958 (diff)
missing impls and hardening
Diffstat (limited to 'src/cocoa')
-rw-r--r--src/cocoa/window.m67
1 files changed, 18 insertions, 49 deletions
diff --git a/src/cocoa/window.m b/src/cocoa/window.m
index 8712ce8..4454be3 100644
--- a/src/cocoa/window.m
+++ b/src/cocoa/window.m
@@ -42,35 +42,7 @@ enum {
@property (nonatomic, assign) BOOL fullscreenTransition;
@end
-#define YASL_QUEUE_CAP 256
-struct input_queue {
- struct yasl_input_event events[YASL_QUEUE_CAP];
- int head;
- int tail;
- int count;
-};
-
-static inline void input_queue_push(struct input_queue *q, const struct yasl_input_event *ev)
-{
- if (q->count >= YASL_QUEUE_CAP) return;
- q->events[q->tail] = *ev;
- q->tail = (q->tail + 1) % YASL_QUEUE_CAP;
- q->count++;
-}
-
-static inline bool input_queue_pop(struct input_queue *q, struct yasl_input_event *ev)
-{
- if (q->count <= 0) return false;
- *ev = q->events[q->head];
- q->head = (q->head + 1) % YASL_QUEUE_CAP;
- q->count--;
- return true;
-}
-
-static inline void input_queue_clear(struct input_queue *q)
-{
- q->head = q->tail = q->count = 0;
-}
+#include "common/input.h"
struct cocoa_surface {
struct yasl_surface base;
@@ -145,15 +117,6 @@ static struct cocoa_display darwin_ctx;
static void render_and_commit(struct cocoa_surface *w);
static void reap_dead(struct cocoa_display *d);
-static uint64_t media_to_loop_ns(CFTimeInterval t)
-{
- double delta = (t - CACurrentMediaTime()) * 1e9;
- uint64_t now = yasl_loop_now_ns();
- if (delta < 0.0 && -delta >= (double)now)
- return 0;
- return (uint64_t)((double)now + delta);
-}
-
static void set_state(struct cocoa_surface *w, uint32_t bit, bool on)
{
if (!w || w->closed)
@@ -502,7 +465,6 @@ static NSCursor *cocoa_cursor(enum yasl_cursor cursor)
CFTimeInterval period = link.targetTimestamp - link.timestamp;
if (period > 0.0 && period < 0.25)
w->clock.refresh_ns = period * 1e9;
- w->clock.last_present_ns = media_to_loop_ns(link.timestamp);
w->frame_due = true;
if (!w->want_draw || (w->state & YASL_STATE_SUSPENDED)) {
if (++w->idle_frames >= LINK_IDLE_FRAMES)
@@ -810,8 +772,10 @@ static NSString *plain_string(id string)
bool cocoa_surface_present(struct cocoa_surface *w, const struct yasl_framebuffer *fb,
const struct yasl_damage_list *damage)
{
- (void)damage;
- if (!w || w->closed || !w->rendering || w->did_present || !fb ||
+ if (!w || w->closed || !w->rendering || w->did_present || !fb || !damage ||
+ fb->pixels != w->frame.target.pixels || fb->size.x != w->size.x ||
+ fb->size.y != w->size.y || fb->buffer != w->frame.target.buffer ||
+ fb->transaction != w->frame.target.transaction ||
!fb->native_drawable || fb->native_drawable != w->frame.target.native_drawable)
return false;
if (w->software_queue) {
@@ -850,7 +814,7 @@ static void render_and_commit(struct cocoa_surface *w)
return;
size_t count = (size_t)w->size.x * (size_t)w->size.y;
- if (count > w->pixel_capacity) {
+ if (w->software_queue && count > w->pixel_capacity) {
uint32_t *pixels = realloc(w->pixels, count * sizeof(*pixels));
if (!pixels) return;
w->pixels = pixels;
@@ -866,7 +830,8 @@ static void render_and_commit(struct cocoa_surface *w)
w->frame = (struct yasl_frame){
.surface = &w->base,
.target = {
- .pixels = w->pixels,
+ .generation = yasl_frame_begin(&w->base),
+ .pixels = w->software_queue ? w->pixels : NULL,
.size = w->size,
.damage = &w->damage,
.native_drawable = drawable,
@@ -943,7 +908,8 @@ void cocoa_display_dispatch(struct cocoa_display *d)
bool immediate = false;
for (int i = 0; i < d->count; i++) {
struct cocoa_surface *w = d->windows[i];
- if (w->input.count > 0 || (w->want_draw && (!w->link || w->frame_due || w->unpaced))) {
+ if (w->input.count > 0 || w->input.reset_pending ||
+ (w->want_draw && (!w->link || w->frame_due || w->unpaced))) {
immediate = true;
break;
}
@@ -1039,7 +1005,8 @@ struct cocoa_display *cocoa_display_open(struct yasl_loop *loop, const struct ya
darwin_ctx.open = true;
darwin_ctx.loop = loop;
if (spec) {
- darwin_ctx.cbs = spec->cbs;
+ darwin_ctx.base.callbacks = spec->cbs ? *spec->cbs : (struct yasl_display_cbs){0};
+ darwin_ctx.cbs = &darwin_ctx.base.callbacks;
darwin_ctx.ud = spec->ud;
if (spec->app_id) darwin_ctx.app_id = strdup(spec->app_id);
}
@@ -1065,7 +1032,8 @@ void cocoa_display_close(struct cocoa_display *d)
uint32_t cocoa_display_caps(const struct cocoa_display *d)
{
- return d ? (YASL_CAP_PLACE_WINDOW | YASL_CAP_CSD) : 0;
+ return d ? (YASL_CAP_PLACE_WINDOW | YASL_CAP_CSD | YASL_CAP_NATIVE_GRAPHICS |
+ YASL_CAP_FRAME_PACING) : 0;
}
struct cocoa_surface *cocoa_surface_create_toplevel(struct cocoa_display *d,
@@ -1302,7 +1270,7 @@ void cocoa_display_paste(struct cocoa_display *d, enum yasl_selection sel, struc
(void)d; (void)sel;
if (!target) return;
NSString *s = [[NSPasteboard generalPasteboard] stringForType:NSPasteboardTypeString];
- const char *utf8 = s.length ? s.UTF8String : NULL;
+ const char *utf8 = s ? s.UTF8String : NULL;
if (utf8) {
struct yasl_input_event ev = {
.kind = YASL_INPUT_PASTE,
@@ -1388,9 +1356,9 @@ void *cocoa_surface_get_native_handle(struct cocoa_surface *s)
void cocoa_surface_set_callbacks(struct cocoa_surface *w,
const struct yasl_surface_cbs *cbs, void *ud)
{
- static const struct yasl_surface_cbs empty = {0};
if (!w || w->closed) return;
- w->cbs = cbs ? cbs : &empty;
+ w->base.callbacks = cbs ? *cbs : (struct yasl_surface_cbs){0};
+ w->cbs = &w->base.callbacks;
w->ud = ud;
}
@@ -1412,6 +1380,7 @@ struct yasl_timing cocoa_surface_timing(const struct cocoa_surface *w)
timing.last_present_ns = w->clock.last_present_ns;
timing.next_present_ns = yasl_clock_next_present_ns(&w->clock);
timing.frames_skipped = w->frames_skipped;
+ timing.source = w->clock.source;
yasl_clock_resize_stats(&w->clock, &timing.resize);
}
return timing;