diff options
| author | Berke Güzel <berke.guzel@gdh.digital> | 2026-10-14 09:38:31 +0300 |
|---|---|---|
| committer | Berke Güzel <berke.guzel@gdh.digital> | 2026-10-14 09:38:31 +0300 |
| commit | 5ef6ca21ab9e1cf4f69254234d190a634b777d52 (patch) | |
| tree | 974d3797a6d9487e54a811e224bf78a3f52dda85 /src/platform/cocoa | |
| parent | 563b23a33726289387193b85d90fb569631ee05f (diff) | |
Remove deprecated Cocoa OpenGL and private compatibility APIs
Diffstat (limited to 'src/platform/cocoa')
| -rw-r--r-- | src/platform/cocoa/api.h | 3 | ||||
| -rw-r--r-- | src/platform/cocoa/window.m | 239 |
2 files changed, 3 insertions, 239 deletions
diff --git a/src/platform/cocoa/api.h b/src/platform/cocoa/api.h index 4a22410..006954c 100644 --- a/src/platform/cocoa/api.h +++ b/src/platform/cocoa/api.h @@ -12,8 +12,6 @@ uint32_t cocoa_display_caps(const struct cocoa_display *d); int cocoa_display_dispatch_timeout(struct cocoa_display *d, int timeout_ms); void cocoa_display_flush(struct cocoa_display *d); int cocoa_display_modifiers(const struct cocoa_display *d); -void cocoa_display_copy(struct cocoa_display *d, enum yasl_private_selection sel, const char *text); -void cocoa_display_paste(struct cocoa_display *d, enum yasl_private_selection sel, struct cocoa_surface *target); bool cocoa_display_drag_start(struct cocoa_display *d, struct cocoa_surface *origin, const struct yasl_private_drag_image *image, const struct yasl_private_drag_listener *l, void *ud); struct cocoa_surface *cocoa_surface_create_toplevel(struct cocoa_display *d, const struct yasl_private_window_spec *spec, void *graphics_device); @@ -24,7 +22,6 @@ void cocoa_surface_set_callbacks(struct cocoa_surface *s, const struct yasl_priv void cocoa_surface_set_title(struct cocoa_surface *s, const char *title); void cocoa_surface_schedule_redraw(struct cocoa_surface *s); bool cocoa_surface_present(struct cocoa_surface *s, const struct yasl_private_framebuffer *fb, const struct yasl_private_damage_list *damage); -bool cocoa_surface_poll_event(struct cocoa_surface *s, struct yasl_private_event *ev); struct yasl_private_geometry cocoa_surface_geometry(const struct cocoa_surface *s); struct yasl_private_timing cocoa_surface_timing(const struct cocoa_surface *s); void cocoa_surface_set_cursor(struct cocoa_surface *s, enum yasl_private_cursor cursor); diff --git a/src/platform/cocoa/window.m b/src/platform/cocoa/window.m index 7be78fd..4b97ce1 100644 --- a/src/platform/cocoa/window.m +++ b/src/platform/cocoa/window.m @@ -1,7 +1,6 @@ #import <AppKit/AppKit.h> #import <Metal/Metal.h> #import <QuartzCore/QuartzCore.h> -#import <OpenGL/OpenGL.h> #include "platform/cocoa/api.h" #include "common/backend.h" @@ -20,7 +19,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <dlfcn.h> #include <sys/event.h> #include <unistd.h> #include <objc/message.h> @@ -68,7 +66,6 @@ struct cocoa_surface { YaslWindowController *controller; YaslView *view; CAMetalLayer *layer; - NSOpenGLContext *gl_context; id<MTLCommandQueue> software_queue; id<MTLBuffer> software_buffer; NSUInteger software_buffer_capacity; @@ -130,8 +127,6 @@ struct cocoa_display { struct cocoa_surface **windows; int count; int capacity; - const struct yasl_private_display_cbs *cbs; - void *ud; char *app_id; struct yasl_private_loop *loop; id key_up_monitor; @@ -275,11 +270,7 @@ static void sync_size(struct cocoa_surface *w, bool force) w->layer.contentsScale = scale; w->layer.drawableSize = CGSizeMake(size.x, size.y); } - if (w->gl_context) - [w->gl_context update]; - /* Common configure notification already requests a frame before invoking - * the legacy callback. Finish local bookkeeping before that callback can - * destroy this surface. */ + /* Finish local bookkeeping before publishing geometry and requesting a frame. */ yasl_private_clock_note_resize(&w->clock, yasl_private_loop_now_ns() - start); yasl_private_surface_notify_configure(&w->base, (struct yasl_private_geometry){ .size = size, .scale_120 = scale_120, @@ -1642,10 +1633,6 @@ struct cocoa_display *cocoa_display_open(struct yasl_private_loop *loop, const s } darwin_ctx.base.loop = darwin_ctx.loop; if (spec) { - darwin_ctx.base.callbacks = spec->cbs ? *spec->cbs : (struct yasl_private_display_cbs){0}; - darwin_ctx.cbs = &darwin_ctx.base.callbacks; - darwin_ctx.ud = spec->ud; - darwin_ctx.base.callback_ud = spec->ud; if (spec->app_id) darwin_ctx.app_id = strdup(spec->app_id); darwin_ctx.base.app_id = darwin_ctx.app_id; } @@ -1789,7 +1776,6 @@ struct cocoa_surface *cocoa_surface_create_toplevel(struct cocoa_display *d, static void surface_free(struct cocoa_surface *w) { [w->link release]; - [w->gl_context release]; [w->software_buffer release]; [w->software_queue release]; [w->view release]; @@ -1987,11 +1973,6 @@ static NSPasteboard *pasteboard_for_selection(enum yasl_private_selection sel) static bool cocoa_display_copy_text(struct cocoa_display *d, enum yasl_private_selection sel, const char *text); -void cocoa_display_copy(struct cocoa_display *d, enum yasl_private_selection sel, const char *text) -{ - (void)cocoa_display_copy_text(d, sel, text); -} - static bool cocoa_display_copy_text(struct cocoa_display *d, enum yasl_private_selection sel, const char *text) { assert([NSThread isMainThread]); @@ -2030,11 +2011,6 @@ static bool cocoa_display_request_paste(struct cocoa_display *d, enum yasl_priva return true; } -void cocoa_display_paste(struct cocoa_display *d, enum yasl_private_selection sel, struct cocoa_surface *target) -{ - (void)cocoa_display_request_paste(d, sel, target, 0); -} - int cocoa_display_modifiers(const struct cocoa_display *d) { (void)d; @@ -2053,8 +2029,8 @@ static bool popup_spec_valid(const struct cocoa_surface *parent, const struct yasl_private_popup_spec *spec) { if (!parent || !spec) return false; - if (spec->positioner_explicit && (spec->anchor_edges > 8 || spec->gravity > 8 || - (spec->constraints & ~63u))) return false; + if (spec->anchor_edges > 8 || spec->gravity > 8 || + (spec->constraints & ~63u)) return false; int parent_cx = parent->is_popup ? parent->content_offset.x : 0; int parent_cy = parent->is_popup ? parent->content_offset.y : 0; int64_t x = (int64_t)spec->anchor.x - parent_cx; @@ -2069,70 +2045,6 @@ static bool popup_spec_valid(const struct cocoa_surface *parent, (int64_t)spec->content_offset.y + spec->content_size.y <= spec->size.y; } -static NSRect popup_calc_frame_legacy(struct cocoa_surface *parent, const struct yasl_private_popup_spec *spec) -{ - CGFloat scale = parent->window ? parent->window.backingScaleFactor : 1.0; - if (scale < 1.0) scale = 1.0; - - CGFloat pcx = (parent->is_popup ? parent->content_offset.x : 0) / scale; - CGFloat pcy = (parent->is_popup ? parent->content_offset.y : 0) / scale; - - CGFloat pw = spec->size.x / scale; - CGFloat ph = spec->size.y / scale; - CGFloat ax = (spec->anchor.x / scale) - pcx; - CGFloat ay = (spec->anchor.y / scale) - pcy; - CGFloat aw = spec->anchor.width / scale; - CGFloat ah = spec->anchor.height / scale; - CGFloat ox = spec->content_offset.x / scale; - CGFloat oy = spec->content_offset.y / scale; - - CGFloat top_left_x = spec->beside ? (ax + aw - ox) : (ax - ox); - CGFloat top_left_y = spec->beside ? (ay - oy) : (ay + ah - oy); - - CGFloat view_h = parent->view.bounds.size.height; - CGFloat view_y = view_h - top_left_y; - - NSPoint ptInView = NSMakePoint(top_left_x, view_y); - NSPoint ptInWin = [parent->view convertPoint:ptInView toView:nil]; - NSPoint screen_tl = [parent->window convertPointToScreen:ptInWin]; - - NSRect frame = NSMakeRect(screen_tl.x, screen_tl.y - ph, pw, ph); - - NSScreen *screen = parent->window.screen ?: [NSScreen mainScreen]; - if (screen) { - NSRect visible = screen.visibleFrame; - if (NSMaxX(frame) > NSMaxX(visible)) { - if (spec->beside) { - CGFloat flip_tl_x = ax - pw + ox; - NSPoint flip_v = NSMakePoint(flip_tl_x, view_y); - NSPoint flip_w = [parent->view convertPoint:flip_v toView:nil]; - NSPoint flip_s = [parent->window convertPointToScreen:flip_w]; - frame.origin.x = flip_s.x; - } - if (NSMaxX(frame) > NSMaxX(visible)) - frame.origin.x = NSMaxX(visible) - frame.size.width; - } - if (NSMinX(frame) < NSMinX(visible)) - frame.origin.x = NSMinX(visible); - - if (NSMinY(frame) < NSMinY(visible)) { - if (!spec->beside) { - CGFloat flip_top_y = ay - ph + oy; - CGFloat flip_vy = view_h - flip_top_y; - NSPoint flip_v = NSMakePoint(top_left_x, flip_vy); - NSPoint flip_w = [parent->view convertPoint:flip_v toView:nil]; - NSPoint flip_s = [parent->window convertPointToScreen:flip_w]; - frame.origin.y = flip_s.y - ph; - } - if (NSMinY(frame) < NSMinY(visible)) - frame.origin.y = NSMinY(visible); - } - if (NSMaxY(frame) > NSMaxY(visible)) - frame.origin.y = NSMaxY(visible) - frame.size.height; - } - return frame; -} - enum { POPUP_EDGE_TOP = 1, POPUP_EDGE_BOTTOM = 2, @@ -2227,8 +2139,6 @@ static NSRect popup_frame_explicit(struct cocoa_surface *parent, static NSRect popup_calc_frame(struct cocoa_surface *parent, const struct yasl_private_popup_spec *spec) { - if (!spec->positioner_explicit) - return popup_calc_frame_legacy(parent, spec); NSRect frame = popup_frame_explicit(parent, spec, spec->anchor_edges, spec->gravity); NSScreen *screen = parent->window.screen ?: [NSScreen mainScreen]; @@ -2505,22 +2415,6 @@ void cocoa_surface_set_callbacks(struct cocoa_surface *w, w->ud = ud; } -bool cocoa_surface_poll_event(struct cocoa_surface *w, struct yasl_private_event *ev) -{ - if (!w || !ev || !input_queue_pop(&w->input, ev)) - return false; - if (ev->type == YASL_PRIVATE_EVENT_INPUT_RESET) { - w->buttons = 0; - w->tablet_down = false; - w->mods = 0; - if (w->preedit) { - free(w->preedit); - w->preedit = NULL; - } - } - return true; -} - struct yasl_private_timing cocoa_surface_timing(const struct cocoa_surface *w) { struct yasl_private_timing timing = {0}; @@ -2572,16 +2466,6 @@ static int impl_display_modifiers(const struct yasl_private_display *d) return cocoa_display_modifiers((const struct cocoa_display *)d); } -static void impl_display_copy(struct yasl_private_display *d, enum yasl_private_selection sel, const char *text) -{ - cocoa_display_copy((struct cocoa_display *)d, sel, text); -} - -static void impl_display_paste(struct yasl_private_display *d, enum yasl_private_selection sel, struct yasl_surface *target) -{ - cocoa_display_paste((struct cocoa_display *)d, sel, (struct cocoa_surface *)target); -} - static bool impl_display_copy_text(struct yasl_private_display *d, enum yasl_private_selection sel, const char *text) { return cocoa_display_copy_text((struct cocoa_display *)d, sel, text); @@ -2725,116 +2609,6 @@ static bool impl_surface_place_under_pointer(struct yasl_surface *s, struct yasl return cocoa_surface_place_under_pointer((struct cocoa_surface *)s, at); } -static struct yasl_surface *impl_surface_create_gl(struct yasl_private_display *display, - const struct yasl_private_window_spec *spec, const int *attrs, struct yasl_surface *share) -{ - struct yasl_private_gl_options options; - if (!spec || !yasl_private_gl_parse_options(attrs, &options) || - options.api != YASL_PRIVATE_GL_OPENGL || options.debug || (share && - (share->display != display || share->presenter != YASL_PRIVATE_PRESENTER_GL))) - return NULL; - int profile = options.profile; - if (profile == YASL_PRIVATE_GL_ANY) - profile = options.major >= 3 ? YASL_PRIVATE_GL_CORE : YASL_PRIVATE_GL_COMPATIBILITY; - if (options.forward_compat && profile != YASL_PRIVATE_GL_CORE) - return NULL; - if ((profile == YASL_PRIVATE_GL_CORE && - (options.major != 3 || options.minor != 2)) || - (profile == YASL_PRIVATE_GL_COMPATIBILITY && - (options.major > 2 || (options.major == 2 && options.minor > 1)))) - return NULL; - - struct yasl_private_window_spec gl_spec = *spec; - gl_spec.external_gpu = true; - struct cocoa_surface *w = cocoa_surface_create_toplevel((struct cocoa_display *)display, &gl_spec, NULL); - if (!w) return NULL; - - NSOpenGLPixelFormatAttribute pixel_attrs[32]; - NSUInteger n = 0; - pixel_attrs[n++] = NSOpenGLPFAAccelerated; - pixel_attrs[n++] = NSOpenGLPFADoubleBuffer; - pixel_attrs[n++] = NSOpenGLPFAColorSize; - pixel_attrs[n++] = options.red_bits + options.green_bits + options.blue_bits + options.alpha_bits; - pixel_attrs[n++] = NSOpenGLPFAAlphaSize; - pixel_attrs[n++] = options.alpha_bits; - pixel_attrs[n++] = NSOpenGLPFADepthSize; - pixel_attrs[n++] = options.depth_bits; - pixel_attrs[n++] = NSOpenGLPFAStencilSize; - pixel_attrs[n++] = options.stencil_bits; - if (options.samples > 0) { - pixel_attrs[n++] = NSOpenGLPFASampleBuffers; - pixel_attrs[n++] = 1; - pixel_attrs[n++] = NSOpenGLPFASamples; - pixel_attrs[n++] = options.samples; - } - if (options.srgb) pixel_attrs[n++] = NSOpenGLPFASRGB; - if (profile == YASL_PRIVATE_GL_CORE) { - pixel_attrs[n++] = NSOpenGLPFAOpenGLProfile; - pixel_attrs[n++] = NSOpenGLProfileVersion3_2Core; - } else if (profile == YASL_PRIVATE_GL_COMPATIBILITY) { - pixel_attrs[n++] = NSOpenGLPFAOpenGLProfile; - pixel_attrs[n++] = NSOpenGLProfileVersionLegacy; - } - pixel_attrs[n++] = 0; - - NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixel_attrs]; - NSOpenGLContext *shared = share ? ((struct cocoa_surface *)share)->gl_context : nil; - if (format) - w->gl_context = [[NSOpenGLContext alloc] initWithFormat:format shareContext:shared]; - [format release]; - if (!w->gl_context) { - cocoa_surface_destroy(w); - reap_dead((struct cocoa_display *)display); - return NULL; - } - [w->view setLayer:[CALayer layer]]; - w->layer = nil; - [w->gl_context setView:w->view]; - w->base.presenter = YASL_PRIVATE_PRESENTER_GL; - return &w->base; -} - -static bool impl_gl_make_current(struct yasl_private_display *display, struct yasl_surface *surface) -{ - (void)display; - if (!surface) { - [NSOpenGLContext clearCurrentContext]; - return true; - } - struct cocoa_surface *w = (struct cocoa_surface *)surface; - if (w->base.presenter != YASL_PRIVATE_PRESENTER_GL || !w->gl_context || w->closed) - return false; - [w->gl_context makeCurrentContext]; - return [NSOpenGLContext currentContext] == w->gl_context; -} - -static yasl_private_gl_proc impl_gl_get_proc_address(struct yasl_private_display *display, const char *name) -{ - (void)display; - return name ? (yasl_private_gl_proc)dlsym(RTLD_DEFAULT, name) : NULL; -} - -static bool impl_gl_swap_interval(struct yasl_private_display *display, struct yasl_surface *surface, int interval) -{ - (void)display; - struct cocoa_surface *w = (struct cocoa_surface *)surface; - if (!w || w->base.presenter != YASL_PRIVATE_PRESENTER_GL || !w->gl_context || w->closed) - return false; - [w->gl_context setValues:&interval forParameter:NSOpenGLCPSwapInterval]; - return true; -} - -static bool impl_gl_swap_buffers(struct yasl_private_display *display, struct yasl_surface *surface) -{ - (void)display; - struct cocoa_surface *w = (struct cocoa_surface *)surface; - if (!w || w->base.presenter != YASL_PRIVATE_PRESENTER_GL || !w->gl_context || w->closed) - return false; - [w->gl_context flushBuffer]; - yasl_private_clock_presented(&w->clock, yasl_private_loop_now_ns(), false); - return true; -} - static void *impl_surface_get_metal_layer(struct yasl_surface *surface) { struct cocoa_surface *w = (struct cocoa_surface *)surface; @@ -2899,11 +2673,6 @@ static bool impl_surface_get_native_frame(struct yasl_surface *s, const struct yasl_private_backend_ops yasl_private_cocoa_backend = { .type = YASL_PRIVATE_BACKEND_COCOA, - .surface_create_gl = impl_surface_create_gl, - .gl_make_current = impl_gl_make_current, - .gl_get_proc_address = impl_gl_get_proc_address, - .gl_swap_interval = impl_gl_swap_interval, - .gl_swap_buffers = impl_gl_swap_buffers, .surface_get_metal_layer = impl_surface_get_metal_layer, .surface_update_text_input = impl_surface_update_text_input, .display_open = impl_display_open, @@ -2913,8 +2682,6 @@ const struct yasl_private_backend_ops yasl_private_cocoa_backend = { .display_flush = impl_display_flush, .display_modifiers = impl_display_modifiers, .display_double_click_ms = impl_display_double_click_ms, - .display_copy = impl_display_copy, - .display_paste = impl_display_paste, .display_copy_text = impl_display_copy_text, .display_request_paste = impl_display_request_paste, .display_drag_start = impl_display_drag_start, |
