sl: use SPDX license and copyright identifiers
[mesa-waffle.git] / src / waffle / surfaceless_egl / sl_platform.c
blob30018c1d7c7b73f95afaf24b4a81256bea99c7f9
1 // SPDX-FileCopyrightText: Copyright 2012 Intel Corporation
2 // SPDX-License-Identifier: BSD-2-Clause
4 #include <dlfcn.h>
5 #include <stdlib.h>
7 #include "wcore_error.h"
9 #include "posix_platform.h"
11 #include "wegl_config.h"
12 #include "wegl_context.h"
13 #include "wegl_platform.h"
14 #include "wegl_util.h"
16 #include "sl_config.h"
17 #include "sl_display.h"
18 #include "sl_platform.h"
19 #include "sl_window.h"
21 static const struct wcore_platform_vtbl sl_platform_vtbl;
23 static bool
24 sl_platform_destroy(struct wcore_platform *wc_self)
26 struct sl_platform *self = sl_platform(wegl_platform(wc_self));
27 bool ok = wegl_platform_teardown(&self->wegl);
29 free(self);
30 return ok;
33 struct wcore_platform*
34 sl_platform_create(void)
36 struct sl_platform *self = wcore_calloc(sizeof(*self));
37 if (self == NULL)
38 return NULL;
40 bool ok = wegl_platform_init(&self->wegl, EGL_PLATFORM_SURFACELESS_MESA);
41 if (!ok)
42 goto fail;
44 self->wegl.egl_surface_type_mask = EGL_PBUFFER_BIT;
46 self->wegl.wcore.vtbl = &sl_platform_vtbl;
47 return &self->wegl.wcore;
49 fail:
50 sl_platform_destroy(&self->wegl.wcore);
51 return NULL;
54 static union waffle_native_context *
55 sl_context_get_native(struct wcore_context *wc_ctx)
57 struct sl_display *dpy = sl_display(wegl_display(wc_ctx->display));
58 struct wegl_context *ctx = wegl_context(wc_ctx);
59 union waffle_native_context *n_ctx;
61 WCORE_CREATE_NATIVE_UNION(n_ctx, surfaceless_egl);
62 if (!n_ctx)
63 return NULL;
65 sl_display_fill_native(dpy, &n_ctx->surfaceless_egl->display);
66 n_ctx->surfaceless_egl->egl_context = ctx->egl;
68 return n_ctx;
71 static const struct wcore_platform_vtbl sl_platform_vtbl = {
72 .destroy = sl_platform_destroy,
74 .make_current = wegl_make_current,
75 .get_proc_address = wegl_get_proc_address,
77 .dl_can_open = posix_platform_can_dlopen,
78 .dl_sym = posix_platform_dlsym,
80 .display = {
81 .connect = sl_display_connect,
82 .destroy = sl_display_destroy,
83 .supports_context_api = wegl_display_supports_context_api,
84 .get_native = sl_display_get_native,
87 .config = {
88 .choose = wegl_config_choose,
89 .destroy = wegl_config_destroy,
90 .get_native = sl_config_get_native,
93 .context = {
94 .create = wegl_context_create,
95 .destroy = wegl_context_destroy,
96 .get_native = sl_context_get_native,
99 .window = {
100 .create = sl_window_create,
101 .destroy = sl_window_destroy,
102 .show = sl_window_show,
103 .resize = sl_window_resize,
104 .swap_buffers = wegl_surface_swap_buffers,
105 .get_native = sl_window_get_native,