blob: 88604c9b0819914ddcd7c5616615173a71d47cea (
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "backend.h"
#include <errno.h>
void *yasl_private_display_get_native_handle(struct yasl_private_display *d)
{
if (!d) return NULL;
if (d->native_handle) return d->native_handle;
return d->ops && d->ops->display_get_native_handle ?
d->ops->display_get_native_handle(d) : NULL;
}
void *yasl_private_surface_get_native_handle(struct yasl_surface *s)
{
if (!s) return NULL;
if (s->native_handle) return s->native_handle;
return s->display && s->display->ops && s->display->ops->surface_get_native_handle ?
s->display->ops->surface_get_native_handle(s) : NULL;
}
struct yasl_surface *yasl_private_surface_create_native(struct yasl_private_display *d,
const struct yasl_private_window_spec *spec, void *graphics_device)
{
if (!graphics_device) {
errno = EINVAL;
return NULL;
}
return yasl_private_create_toplevel(d, spec, graphics_device);
}
bool yasl_private_surface_get_native_frame(struct yasl_surface *s,
const struct yasl_private_framebuffer *target, struct yasl_private_native_frame *out)
{
if (!s || !target || !out || !target->generation ||
target->generation != s->frame_generation ||
!s->display->ops->surface_get_native_frame)
return false;
return s->display->ops->surface_get_native_frame(s, target, out);
}
#include "public_internal.h"
#include "yasl/metal.h"
#if YASL_HAS_WAYLAND
#include "yasl/native/wayland.h"
struct wl_display *yasl_wayland_display(const yasl_surface *s)
{ return s && s->display->ops->type==YASL_PRIVATE_BACKEND_WAYLAND ? yasl_private_display_get_native_handle(s->display):NULL; }
struct wl_surface *yasl_wayland_surface(const yasl_surface *s)
{ return s && s->display->ops->type==YASL_PRIVATE_BACKEND_WAYLAND ? yasl_private_surface_get_native_handle((yasl_surface*)s):NULL; }
#endif
#if YASL_HAS_X11
#include "yasl/native/x11.h"
Display *yasl_x11_display(const yasl_surface *s)
{ return s && s->display->ops->type==YASL_PRIVATE_BACKEND_X11 ? yasl_private_display_get_native_handle(s->display):NULL; }
uintptr_t yasl_x11_window(const yasl_surface *s)
{ return s && s->display->ops->type==YASL_PRIVATE_BACKEND_X11 ? (uintptr_t)yasl_private_surface_get_native_handle((yasl_surface*)s):0; }
#endif
#if YASL_HAS_COCOA
#include "yasl/native/cocoa.h"
#include "common/private_native_cocoa.h"
NSApplication *yasl_cocoa_application(void)
{ struct yasl_private_display *d=yasl_public_display();return d ? yasl_private_cocoa_display_get_application(d):NULL; }
NSWindow *yasl_cocoa_window(const yasl_surface *s)
{ return yasl_private_cocoa_surface_get_window((yasl_surface*)s); }
NSView *yasl_cocoa_view(const yasl_surface *s)
{ return yasl_private_cocoa_surface_get_view((yasl_surface*)s); }
#endif
CAMetalLayer *yasl_metal_layer(yasl_surface *s)
{
if(!yasl_public_surface(s,false))return NULL;
if(s->presenter!=YASL_PRIVATE_PRESENTER_NONE && s->presenter!=YASL_PRIVATE_PRESENTER_METAL) {yasl_public_fail(EBUSY);return NULL;}
if(!s->display->ops->surface_get_metal_layer){yasl_public_fail(ENOTSUP);return NULL;}
CAMetalLayer *layer=s->display->ops->surface_get_metal_layer(s);
if(!layer){yasl_public_fail(ENOTSUP);return NULL;}
s->presenter=YASL_PRIVATE_PRESENTER_METAL;return layer;
}
|