summaryrefslogtreecommitdiff
path: root/include/yasl/native.h
blob: f7e30206802850f901c25cfdc241ccff4f2a7ed8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef YASL_NATIVE_H
#define YASL_NATIVE_H

#include "yasl/yasl.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Optional platform interoperability. All handles are borrowed and expire on
 * object destruction. Check yasl_display_backend() before casting:
 *
 *              display                  surface
 * Wayland      struct wl_display *       struct wl_surface *
 * X11          Display *                 Window (cast through uintptr_t)
 * Cocoa        NSApplication *           NSWindow * (view: window.contentView)
 */
YASL_API void *yasl_display_get_native_handle(struct yasl_display *d);
YASL_API void *yasl_surface_get_native_handle(struct yasl_surface *s);

/* Create a surface for application-managed native rendering. graphics_device
 * must be non-NULL; currently an id<MTLDevice> on Cocoa, retained by the surface.
 * Other backends return NULL with errno=ENOTSUP. CPU rendering uses the ordinary
 * yasl_surface_create_toplevel() and requires no native device. */
YASL_API struct yasl_surface *yasl_surface_create_native(struct yasl_display *d,
        const struct yasl_surface_spec *spec, void *graphics_device);

struct yasl_native_frame {
    void *drawable; /* id<CAMetalDrawable> on Cocoa */
    bool transaction; /* CAMetalLayer.presentsWithTransaction */
};

/* Query the current draw target's native drawable. Returns false for unsupported
 * backends, stale targets, or outside the draw callback. The result expires on
 * successful present, callback return, or surface destruction. Native renderers
 * submit/present the drawable, then call yasl_surface_present() to record it. */
YASL_API bool yasl_surface_get_native_frame(struct yasl_surface *s,
        const struct yasl_framebuffer *target, struct yasl_native_frame *out);

#ifdef __cplusplus
}
#endif

#endif /* YASL_NATIVE_H */