diff options
Diffstat (limited to 'src/waffle/wayland')
-rw-r--r-- | src/waffle/wayland/wayland_config.c | 74 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_config.h | 39 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_context.c | 98 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_context.h | 34 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_display.c | 121 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_display.h | 43 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_dl.c | 56 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_dl.h | 51 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_gl_misc.c | 58 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_gl_misc.h | 53 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_platform.c | 129 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_platform.h | 30 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_priv_egl.c | 7 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_priv_egl.h | 13 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_priv_types.h | 84 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_window.c | 154 | ||||
-rw-r--r-- | src/waffle/wayland/wayland_window.h | 42 |
17 files changed, 425 insertions, 661 deletions
diff --git a/src/waffle/wayland/wayland_config.c b/src/waffle/wayland/wayland_config.c index b8d5b63..910ce47 100644 --- a/src/waffle/wayland/wayland_config.c +++ b/src/waffle/wayland/wayland_config.c @@ -23,65 +23,71 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @addtogroup wayland_config -/// @{ - -/// @file - -#include "wayland_config.h" +#define WL_EGL_PLATFORM 1 #include <stdlib.h> #include <string.h> -#include <waffle/native.h> -#include <waffle/waffle_enum.h> #include <waffle/core/wcore_config_attrs.h> #include <waffle/core/wcore_error.h> +#include "wayland_config.h" +#include "wayland_display.h" +#include "wayland_platform.h" #include "wayland_priv_egl.h" -#include "wayland_priv_types.h" -union native_config* -wayland_config_choose( - union native_display *dpy, - const struct wcore_config_attrs *attrs) +static const struct wcore_config_vtbl wayland_config_wcore_vtbl; + +static bool +wayland_config_destroy(struct wcore_config *wc_self) +{ + struct wayland_config *self = wayland_config(wc_self); + bool ok = true; + + if (!self) + return ok; + + ok &= wcore_config_teardown(wc_self); + free(self); + return ok; +} + +struct wcore_config* +wayland_config_choose(struct wcore_platform *wc_plat, + struct wcore_display *wc_dpy, + const struct wcore_config_attrs *attrs) { - union native_platform *platform = dpy->wl->platform; + struct wayland_config *self; + struct wayland_display *dpy = wayland_display(wc_dpy); bool ok = true; - union native_config *self; - NATIVE_ALLOC(self, wl); + self = calloc(1, sizeof(*self)); if (!self) { wcore_error(WAFFLE_OUT_OF_MEMORY); return NULL; } - self->wl->display = dpy; - - ok &= egl_get_render_buffer_attrib(attrs, &self->wl->egl_render_buffer); + ok = wcore_config_init(&self->wcore, wc_dpy); if (!ok) goto error; - self->wl->egl_config = egl_choose_config(platform->wl->linux_, - dpy->wl->egl_display, - attrs); - if (!self->wl->egl_config) + ok = egl_get_render_buffer_attrib(attrs, &self->egl_render_buffer); + if (!ok) goto error; - self->wl->waffle_context_api = attrs->context_api; + self->egl = egl_choose_config(wc_plat, dpy->egl, attrs); + if (!self->egl) + goto error; - return self; + self->waffle_context_api = attrs->context_api; + self->wcore.vtbl = &wayland_config_wcore_vtbl; + return &self->wcore; error: - free(self); + wayland_config_destroy(&self->wcore); return NULL; } -bool -wayland_config_destroy(union native_config *self) -{ - free(self); - return true; -} - -/// @} +static const struct wcore_config_vtbl wayland_config_wcore_vtbl = { + .destroy = wayland_config_destroy, +}; diff --git a/src/waffle/wayland/wayland_config.h b/src/waffle/wayland/wayland_config.h index 5c0884f..efe5c12 100644 --- a/src/waffle/wayland/wayland_config.h +++ b/src/waffle/wayland/wayland_config.h @@ -23,27 +23,36 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @defgroup wayland_config wayland_config -/// @ingroup wayland -/// @{ - -/// @file - #pragma once #include <stdbool.h> #include <stdint.h> +#include <EGL/egl.h> + +#include <waffle/core/wcore_config.h> +#include <waffle/core/wcore_util.h> + struct wcore_config_attrs; -union native_config; -union native_display; +struct wcore_platform; + +struct wayland_config { + struct wcore_config wcore; + + EGLConfig egl; + int32_t waffle_context_api; -union native_config* -wayland_config_choose( - union native_display *dpy, - const struct wcore_config_attrs *attrs); + /// The value of @c EGL_RENDER_BUFFER that will be set in the attrib_list + /// of eglCreateWindowSurface(). + EGLint egl_render_buffer; +}; -bool -wayland_config_destroy(union native_config *self); +DEFINE_CONTAINER_CAST_FUNC(wayland_config, + struct wayland_config, + struct wcore_config, + wcore) -/// @} +struct wcore_config* +wayland_config_choose(struct wcore_platform *wc_plat, + struct wcore_display *wc_dpy, + const struct wcore_config_attrs *attrs); diff --git a/src/waffle/wayland/wayland_context.c b/src/waffle/wayland/wayland_context.c index f4db769..d8faf1e 100644 --- a/src/waffle/wayland/wayland_context.c +++ b/src/waffle/wayland/wayland_context.c @@ -23,66 +23,76 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @addtogroup wayland_context -/// @{ - -/// @file - -#include "wayland_context.h" +#define WL_EGL_PLATFORM 1 #include <stdlib.h> -#include <waffle/native.h> +#include <waffle/core/wcore_config.h> #include <waffle/core/wcore_error.h> +#include "wayland_config.h" +#include "wayland_context.h" +#include "wayland_display.h" #include "wayland_priv_egl.h" -#include "wayland_priv_types.h" -union native_context* -wayland_context_create( - union native_config *config, - union native_context *share_ctx) +static const struct wcore_context_vtbl wayland_context_wcore_vtbl; + +static bool +wayland_context_destroy(struct wcore_context *wc_self) { - union native_display *dpy = config->wl->display; + struct wayland_context *self = wayland_context(wc_self); + bool ok = true; - union native_context *self; - NATIVE_ALLOC(self, wl); - if (!self) { - wcore_error(WAFFLE_OUT_OF_MEMORY); - return NULL; - } + if (!self) + return ok; - self->wl->display = config->wl->display; - self->wl->egl_context = egl_create_context( - dpy->wl->egl_display, - config->wl->egl_config, - share_ctx - ? share_ctx->wl->egl_context - : NULL, - config->wl->waffle_context_api); + if (self->egl) + ok &= egl_destroy_context(wayland_display(wc_self->display)->egl, + self->egl); + + ok &= wcore_context_teardown(wc_self); + free(self); + return ok; +} - if (!self->wl->egl_context) { - free(self); +struct wcore_context* +wayland_context_create(struct wcore_platform *wc_plat, + struct wcore_config *wc_config, + struct wcore_context *wc_share_ctx) +{ + struct wayland_context *self; + struct wayland_config *config = wayland_config(wc_config); + struct wayland_context *share_ctx = wayland_context(wc_share_ctx); + struct wayland_display *dpy = wayland_display(wc_config->display); + bool ok = true; + + self = calloc(1, sizeof(*self)); + if (!self) { + wcore_error(WAFFLE_OUT_OF_MEMORY); return NULL; } - return self; -} + ok = wcore_context_init(&self->wcore, wc_config); + if (!ok) + goto error; -bool -wayland_context_destroy(union native_context *self) -{ - if (!self) - return true; + self->egl = egl_create_context(dpy->egl, + config->egl, + share_ctx + ? share_ctx->egl + : NULL, + config->waffle_context_api); + if (!self->egl) + goto error; - bool ok = true; - union native_display *dpy = self->wl->display; + self->wcore.vtbl = &wayland_context_wcore_vtbl; + return &self->wcore; - if (self->wl->egl_context) - ok &= egl_destroy_context(dpy->wl->egl_display, - self->wl->egl_context); - free(self); - return ok; +error: + wayland_context_destroy(&self->wcore); + return NULL; } -/// @} +static const struct wcore_context_vtbl wayland_context_wcore_vtbl = { + .destroy = wayland_context_destroy, +}; diff --git a/src/waffle/wayland/wayland_context.h b/src/waffle/wayland/wayland_context.h index e0f59e2..1be76bc 100644 --- a/src/waffle/wayland/wayland_context.h +++ b/src/waffle/wayland/wayland_context.h @@ -23,25 +23,29 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @defgroup wayland_context wayland_context -/// @ingroup wayland -/// @{ - -/// @file - #pragma once #include <stdbool.h> -union native_context; -union native_config; +#include <EGL/egl.h> + +#include <waffle/core/wcore_context.h> +#include <waffle/core/wcore_util.h> + +struct wcore_config; +struct wcore_platform; -union native_context* -wayland_context_create( - union native_config *config, - union native_context *share_ctx); +struct wayland_context { + struct wcore_context wcore; + EGLContext egl; +}; -bool -wayland_context_destroy(union native_context *self); +DEFINE_CONTAINER_CAST_FUNC(wayland_context, + struct wayland_context, + struct wcore_context, + wcore) -/// @} +struct wcore_context* +wayland_context_create(struct wcore_platform *wc_plat, + struct wcore_config *wc_config, + struct wcore_context *wc_share_ctx); diff --git a/src/waffle/wayland/wayland_display.c b/src/waffle/wayland/wayland_display.c index c9c5f4b..809e782 100644 --- a/src/waffle/wayland/wayland_display.c +++ b/src/waffle/wayland/wayland_display.c @@ -23,103 +23,108 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @addtogroup wayland_display -/// @{ - -/// @file - -#include "wayland_display.h" +#define WL_EGL_PLATFORM 1 #include <stdlib.h> #include <string.h> -#include <waffle/native.h> +#include <wayland-client.h> +#undef container_of + #include <waffle/core/wcore_error.h> +#include <waffle/core/wcore_display.h> +#include "wayland_display.h" +#include "wayland_platform.h" #include "wayland_priv_egl.h" -#include "wayland_priv_types.h" + +static const struct wcore_display_vtbl wayland_display_wcore_vtbl; + +static bool +wayland_display_destroy(struct wcore_display *wc_self) +{ + struct wayland_display *self = wayland_display(wc_self); + bool ok = true; + + if (!self) + return ok; + + if (self->egl) + ok &= egl_terminate(self->egl); + + if (self->wl_display) + wl_display_disconnect(self->wl_display); + + ok &= wcore_display_teardown(&self->wcore); + free(self); + return ok; +} static void -wayland_display_listener( - struct wl_display *display, - uint32_t id, - const char *interface, - uint32_t version, - void *data) +wayland_display_listener(struct wl_display *display, + uint32_t name, + const char *interface, + uint32_t version, + void *data) { - union native_display *self = data; + struct wayland_display *self = data; if (!strncmp(interface, "wl_compositor", 14)) { - self->wl->wl_compositor = wl_display_bind(display, id, - &wl_compositor_interface); + self->wl_compositor = wl_display_bind(display, name, &wl_compositor_interface); } else if (!strncmp(interface, "wl_shell", 9)) { - self->wl->wl_shell = wl_display_bind(display, id, - &wl_shell_interface); + self->wl_shell = wl_display_bind(display, name, &wl_shell_interface); } } -union native_display* -wayland_display_connect( - union native_platform *platform, - const char *name) +struct wcore_display* +wayland_display_connect(struct wcore_platform *wc_plat, + const char *name) { - union native_display *self; - NATIVE_ALLOC(self, wl); + struct wayland_display *self; + bool ok = true; + + self = calloc(1, sizeof(*self)); if (!self) { wcore_error(WAFFLE_OUT_OF_MEMORY); return NULL; } - self->wl->platform = platform; + ok = wcore_display_init(&self->wcore, wc_plat); + if (!ok) + goto error; - self->wl->wl_display = wl_display_connect(name); - if (!self->wl->wl_display) { + self->wl_display = wl_display_connect(name); + if (!self->wl_display) { wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wl_display_connect failed"); goto error; } - wl_display_add_global_listener(self->wl->wl_display, + wl_display_add_global_listener(self->wl_display, wayland_display_listener, self); - self->wl->egl_display = wayland_egl_initialize(self->wl->wl_display); - if (!self->wl->egl_display) + self->egl = wayland_egl_initialize(self->wl_display); + if (!self->egl) goto error; - return self; + self->wcore.vtbl = &wayland_display_wcore_vtbl; + return &self->wcore; error: - wayland_display_disconnect(self); + wayland_display_destroy(&self->wcore); return NULL; } -bool -wayland_display_disconnect(union native_display *self) -{ - bool ok = true; - - if (!self) - return true; - if (self->wl->egl_display) - ok &= egl_terminate(self->wl->egl_display); - - if (self->wl->wl_display) - wl_display_disconnect(self->wl->wl_display); - - free(self); - return ok; -} - -bool -wayland_display_supports_context_api( - union native_display *self, - int32_t context_api) +static bool +wayland_display_supports_context_api(struct wcore_display *wc_self, + int32_t waffle_context_api) { - union native_platform *platform = self->wl->platform; - return egl_supports_context_api(platform->wl->linux_, context_api); + return egl_supports_context_api(wc_self->platform, waffle_context_api); } - -/// @} +static const struct wcore_display_vtbl wayland_display_wcore_vtbl = { + .destroy = wayland_display_destroy, + .supports_context_api = wayland_display_supports_context_api, +}; diff --git a/src/waffle/wayland/wayland_display.h b/src/waffle/wayland/wayland_display.h index 5aad291..557181f 100644 --- a/src/waffle/wayland/wayland_display.h +++ b/src/waffle/wayland/wayland_display.h @@ -23,31 +23,36 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @defgroup wayland_display wayland_display -/// @ingroup wayland -/// @{ - -/// @file - #pragma once #include <stdbool.h> #include <stdint.h> -union native_display; -union native_platform; +#include <EGL/egl.h> + +#include <waffle/core/wcore_display.h> +#include <waffle/core/wcore_util.h> + +struct wcore_platform; +struct wl_display; +struct wl_compositor; +struct wl_shell; + +struct wayland_display { + struct wcore_display wcore; -union native_display* -wayland_display_connect( - union native_platform *platform, - const char *name); + struct wl_display *wl_display; + struct wl_compositor *wl_compositor; + struct wl_shell *wl_shell; -bool -wayland_display_disconnect(union native_display *self); + EGLDisplay egl; +}; -bool -wayland_display_supports_context_api( - union native_display *self, - int32_t context_api); +DEFINE_CONTAINER_CAST_FUNC(wayland_display, + struct wayland_display, + struct wcore_display, + wcore) -/// @} +struct wcore_display* +wayland_display_connect(struct wcore_platform *wc_plat, + const char *name); diff --git a/src/waffle/wayland/wayland_dl.c b/src/waffle/wayland/wayland_dl.c deleted file mode 100644 index 2d03f29..0000000 --- a/src/waffle/wayland/wayland_dl.c +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2012 Intel Corporation -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/// @addtogroup wayland_dl -/// @{ - -/// @file - -#include "wayland_dl.h" - -#include <waffle/native.h> -#include <waffle/linux/linux_dl.h> -#include <waffle/linux/linux_platform.h> - -#include "wayland_priv_types.h" - -bool -wayland_dl_can_open( - union native_platform *native, - int32_t waffle_dl) -{ - return linux_platform_dl_can_open(native->wl->linux_, waffle_dl); -} - -void* -wayland_dl_sym( - union native_platform *native, - int32_t waffle_dl, - const char *name) -{ - return linux_platform_dl_sym(native->wl->linux_, waffle_dl, name); -} - -/// @} diff --git a/src/waffle/wayland/wayland_dl.h b/src/waffle/wayland/wayland_dl.h deleted file mode 100644 index 68efb5a..0000000 --- a/src/waffle/wayland/wayland_dl.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2012 Intel Corporation -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/// @defgroup wayland_dl wayland_dl -/// @ingroup wayland -/// @{ - -/// @file - -#pragma once - - -#include <stdbool.h> -#include <stdint.h> - -union native_platform; - -bool -wayland_dl_can_open( - union native_platform *native, - int32_t waffle_dl); - -void* -wayland_dl_sym( - union native_platform *native, - int32_t waffle_dl, - const char *name); - -/// @} diff --git a/src/waffle/wayland/wayland_gl_misc.c b/src/waffle/wayland/wayland_gl_misc.c deleted file mode 100644 index 3f0e8e7..0000000 --- a/src/waffle/wayland/wayland_gl_misc.c +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2012 Intel Corporation -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/// @addtogroup wayland_gl_misc -/// @{ - -/// @file - -#include "wayland_gl_misc.h" - -#include <waffle/native.h> -#include <waffle/linux/linux_platform.h> - -#include "wayland_priv_egl.h" -#include "wayland_priv_types.h" - -bool -wayland_make_current( - union native_display *dpy, - union native_window *window, - union native_context *ctx) -{ - return egl_make_current(dpy->wl->egl_display, - window ? window->wl->egl_surface : 0, - ctx ? ctx->wl->egl_context : 0); -} - -void* -wayland_get_proc_address( - union native_platform *native, - const char *name) -{ - return eglGetProcAddress(name); -} - -/// @} diff --git a/src/waffle/wayland/wayland_gl_misc.h b/src/waffle/wayland/wayland_gl_misc.h deleted file mode 100644 index a5e20fa..0000000 --- a/src/waffle/wayland/wayland_gl_misc.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2012 Intel Corporation -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/// @defgroup wayland_gl_misc wayland_gl_misc -/// @ingroup wayland -/// @{ - -/// @file - -#pragma once - -#include <stdbool.h> -#include <stdint.h> - -union native_platform; -union native_display; -union native_window; -union native_context; - -bool -wayland_make_current( - union native_display *dpy, - union native_window *window, - union native_context *ctx); - -void* -wayland_get_proc_address( - union native_platform *native, - const char *name); - -/// @} diff --git a/src/waffle/wayland/wayland_platform.c b/src/waffle/wayland/wayland_platform.c index 04558ef..9ecd48a 100644 --- a/src/waffle/wayland/wayland_platform.c +++ b/src/waffle/wayland/wayland_platform.c @@ -23,89 +23,116 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @addtogroup wayland_platform -/// @{ - -/// @file - -#include "wayland_platform.h" - +#define WL_EGL_PLATFORM 1 #define _POSIX_C_SOURCE 200112 // glib feature macro for unsetenv() -#include <dlfcn.h> #include <stdlib.h> -#include <waffle/native.h> -#include <waffle/waffle_enum.h> #include <waffle/core/wcore_error.h> #include <waffle/linux/linux_platform.h> #include "wayland_config.h" #include "wayland_context.h" #include "wayland_display.h" -#include "wayland_dl.h" -#include "wayland_gl_misc.h" +#include "wayland_platform.h" #include "wayland_priv_egl.h" -#include "wayland_priv_types.h" #include "wayland_window.h" -static const struct native_dispatch wayland_dispatch = { - .display_connect = wayland_display_connect, - .display_disconnect = wayland_display_disconnect, - .display_supports_context_api = wayland_display_supports_context_api, - .config_choose = wayland_config_choose, - .config_destroy = wayland_config_destroy, - .context_create = wayland_context_create, - .context_destroy = wayland_context_destroy, - .dl_can_open = wayland_dl_can_open, - .dl_sym = wayland_dl_sym, - .window_create = wayland_window_create, - .window_destroy = wayland_window_destroy, - .window_show = wayland_window_show, - .window_swap_buffers = wayland_window_swap_buffers, - .make_current = wayland_make_current, - .get_proc_address = wayland_get_proc_address, -}; +static const struct wcore_platform_vtbl wayland_platform_wcore_vtbl; + +static bool +wayland_platform_destroy(struct wcore_platform *wc_self) +{ + struct wayland_platform *self = wayland_platform(wc_self); + bool ok = true; + + if (!self) + return true; + + unsetenv("EGL_PLATFORM"); + + if (self->linux) + ok &= linux_platform_destroy(self->linux); + + ok &= wcore_platform_teardown(wc_self); + free(self); + return ok; +} -union native_platform* -wayland_platform_create(const struct native_dispatch **dispatch) +struct wcore_platform* +wayland_platform_create(void) { - union native_platform *self; - NATIVE_ALLOC(self, wl); + struct wayland_platform *self; + bool ok = true; + + self= calloc(1, sizeof(*self)); if (!self) { wcore_error(WAFFLE_OUT_OF_MEMORY); return NULL; } - self->wl->linux_ = linux_platform_create(); - if (!self->wl->linux_) + ok = wcore_platform_init(&self->wcore); + if (!ok) + goto error; + + self->linux = linux_platform_create(); + if (!self->linux) goto error; setenv("EGL_PLATFORM", "wayland", true); - *dispatch = &wayland_dispatch; - return self; + self->wcore.vtbl = &wayland_platform_wcore_vtbl; + return &self->wcore; error: - wayland_platform_destroy(self); + wayland_platform_destroy(&self->wcore); return NULL; } -bool -wayland_platform_destroy(union native_platform *self) +static bool +wayland_platform_make_current(struct wcore_platform *wc_self, + struct wcore_display *wc_dpy, + struct wcore_window *wc_window, + struct wcore_context *wc_ctx) { - bool ok = true; - - if (!self) - return true; + return egl_make_current(wayland_display(wc_dpy)->egl, + wc_window ? wayland_window(wc_window)->egl : NULL, + wc_ctx ? wayland_context(wc_ctx)->egl : NULL); +} - unsetenv("EGL_PLATFORM"); +static void* +wayland_platform_get_proc_address(struct wcore_platform *wc_self, + const char *name) +{ + return eglGetProcAddress(name); +} - if (self->wl->linux_) - ok &= linux_platform_destroy(self->wl->linux_); +static bool +wayland_platform_dl_can_open(struct wcore_platform *wc_self, + int32_t waffle_dl) +{ + return linux_platform_dl_can_open(wayland_platform(wc_self)->linux, + waffle_dl); +} - free(self); - return ok; +static void* +wayland_platform_dl_sym(struct wcore_platform *wc_self, + int32_t waffle_dl, + const char *name) +{ + return linux_platform_dl_sym(wayland_platform(wc_self)->linux, + waffle_dl, + name); } -/// @} +static const struct wcore_platform_vtbl wayland_platform_wcore_vtbl = { + .destroy = wayland_platform_destroy, + .connect_to_display = wayland_display_connect, + .choose_config = wayland_config_choose, + .create_context = wayland_context_create, + .create_window = wayland_window_create, + .make_current = wayland_platform_make_current, + .get_proc_address = wayland_platform_get_proc_address, + .dl_can_open = wayland_platform_dl_can_open, + .dl_sym = wayland_platform_dl_sym, +}; diff --git a/src/waffle/wayland/wayland_platform.h b/src/waffle/wayland/wayland_platform.h index 9b9fc92..8f5a11a 100644 --- a/src/waffle/wayland/wayland_platform.h +++ b/src/waffle/wayland/wayland_platform.h @@ -23,23 +23,27 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @defgroup wayland_platform wayland_platform -/// @ingroup wayland -/// @{ - -/// @file - #pragma once #include <stdbool.h> +#include <stdlib.h> + +#undef linux + +#include <waffle/core/wcore_platform.h> +#include <waffle/core/wcore_util.h> -struct native_dispatch; -union native_platform; +struct linux_platform; -union native_platform* -wayland_platform_create(const struct native_dispatch **dispatch); +struct wayland_platform { + struct wcore_platform wcore; + struct linux_platform *linux; +}; -bool -wayland_platform_destroy(union native_platform *self); +DEFINE_CONTAINER_CAST_FUNC(wayland_platform, + struct wayland_platform, + struct wcore_platform, + wcore) -/// @} +struct wcore_platform* +wayland_platform_create(void); diff --git a/src/waffle/wayland/wayland_priv_egl.c b/src/waffle/wayland/wayland_priv_egl.c index 2982584..d5851e1 100644 --- a/src/waffle/wayland/wayland_priv_egl.c +++ b/src/waffle/wayland/wayland_priv_egl.c @@ -23,12 +23,7 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @addtogroup wayland_priv_egl -/// @{ - -/// @file +#define WL_EGL_PLATFORM 1 #include "wayland_priv_egl.h" #include <waffle/egl/egl_native_template.c> - -/// @} diff --git a/src/waffle/wayland/wayland_priv_egl.h b/src/waffle/wayland/wayland_priv_egl.h index d595921..d9b415b 100644 --- a/src/waffle/wayland/wayland_priv_egl.h +++ b/src/waffle/wayland/wayland_priv_egl.h @@ -23,19 +23,8 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @defgroup wayland_priv_egl wayland_priv_egl -/// @ingroup wayland -/// @{ - -/// @file - #pragma once -// WL_EGL_PLATFORM configures Mesa's <EGL/egl.h> to define native types (such -// as EGLNativeDisplay) as Wayland types rather than Xlib types. -#define WL_EGL_PLATFORM 1 - #define NATIVE_EGL(basename) wayland_egl_##basename -#include <waffle/egl/egl.h> -/// @} +#include <waffle/egl/egl.h> diff --git a/src/waffle/wayland/wayland_priv_types.h b/src/waffle/wayland/wayland_priv_types.h deleted file mode 100644 index 95c200b..0000000 --- a/src/waffle/wayland/wayland_priv_types.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2012 Intel Corporation -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// - Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/// @defgroup wayland_priv_types wayland_priv_types -/// @ingroup wayland -/// @{ - -/// @file - -#pragma once - -// WL_EGL_PLATFORM configures Mesa's <EGL/egl.h> to define native types (such -// as EGLNativeDisplay) as Wayland types rather than Xlib types. -#define WL_EGL_PLATFORM 1 - -#include <wayland-client.h> -#include <wayland-egl.h> - -#include <EGL/egl.h> - -struct linux_platform; - -union native_display; -union native_platform; - -struct wayland_platform { - struct linux_platform *linux_; -}; - -struct wayland_display { - union native_platform *platform; - struct wl_display *wl_display; - struct wl_compositor *wl_compositor; - struct wl_shell *wl_shell; - EGLDisplay egl_display; -}; - -struct wayland_config { - union native_display *display; - EGLConfig egl_config; - - /// The value of @c EGL_RENDER_BUFFER that will be set in the attrib_list - /// of eglCreateWindowSurface(). - EGLint egl_render_buffer; - - int32_t waffle_context_api; -}; - -struct wayland_context { - union native_display *display; - EGLContext egl_context; -}; - -struct wayland_window { - union native_display *display; - struct wl_surface *wl_surface; - struct wl_shell_surface *wl_shell_surface; - struct wl_egl_window *wl_window; - EGLSurface egl_surface; -}; - -/// @} diff --git a/src/waffle/wayland/wayland_window.c b/src/waffle/wayland/wayland_window.c index ae36550..cd2c6c7 100644 --- a/src/waffle/wayland/wayland_window.c +++ b/src/waffle/wayland/wayland_window.c @@ -23,116 +23,123 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @addtogroup wayland_window -/// @{ - -/// @file - -#include "wayland_window.h" +#define WL_EGL_PLATFORM 1 #include <stdlib.h> #include <string.h> -#include <waffle/native.h> +#include <wayland-egl.h> +#undef container_of + #include <waffle/core/wcore_error.h> -#include <waffle/x11/x11.h> +#include "wayland_config.h" +#include "wayland_display.h" #include "wayland_priv_egl.h" -#include "wayland_priv_types.h" +#include "wayland_window.h" + +static const struct wcore_window_vtbl wayland_window_wcore_vtbl; + +static bool +wayland_window_destroy(struct wcore_window *wc_self) +{ + struct wayland_window *self = wayland_window(wc_self); + struct wayland_display *dpy; + bool ok = true; + + if (!self) + return ok; + + dpy = wayland_display(wc_self->display); + + if (self->egl) + ok &= egl_destroy_surface(dpy->egl, self->egl); + + if (self->wl_window) + wl_egl_window_destroy(self->wl_window); + + if (self->wl_shell_surface) + wl_shell_surface_destroy(self->wl_shell_surface); + + if (self->wl_surface) + wl_surface_destroy(self->wl_surface); + + ok &= wcore_window_teardown(wc_self); + free(self); + return ok; +} -union native_window* -wayland_window_create( - union native_config *config, - int width, - int height) +struct wcore_window* +wayland_window_create(struct wcore_platform *wc_plat, + struct wcore_config *wc_config, + int width, + int height) { - union native_display *display = config->wl->display; + struct wayland_window *self; + struct wayland_config *config = wayland_config(wc_config); + struct wayland_display *dpy = wayland_display(wc_config->display); + bool ok = true; - union native_window *self; - NATIVE_ALLOC(self, wl); + self = calloc(1, sizeof(*self)); if (!self) { wcore_error(WAFFLE_OUT_OF_MEMORY); return NULL; } - self->wl->display = display; + ok = wcore_window_init(&self->wcore, wc_config); + if (!ok) + goto error; - if (!display->wl->wl_compositor) { + if (!dpy->wl_compositor) { wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wayland compositor not found"); goto error; } - if (!display->wl->wl_shell) { + if (!dpy->wl_shell) { wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wayland shell not found"); goto error; } - self->wl->wl_surface = wl_compositor_create_surface(display->wl->wl_compositor); - if (!self->wl->wl_surface) { + self->wl_surface = wl_compositor_create_surface(dpy->wl_compositor); + if (!self->wl_surface) { wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wl_compositor_create_surface failed"); goto error; } - self->wl->wl_shell_surface = wl_shell_get_shell_surface( - display->wl->wl_shell, - self->wl->wl_surface); - if (!self->wl->wl_shell_surface) { + self->wl_shell_surface = wl_shell_get_shell_surface(dpy->wl_shell, + self->wl_surface); + if (!self->wl_shell_surface) { wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wl_shell_get_shell_surface failed"); goto error; } - self->wl->wl_window = wl_egl_window_create(self->wl->wl_surface, - width, - height); - if (!self->wl->wl_window) { + self->wl_window = wl_egl_window_create(self->wl_surface, width, height); + if (!self->wl_window) { wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wl_egl_window_create failed"); goto error; } - self->wl->egl_surface = wayland_egl_create_window_surface( - display->wl->egl_display, - config->wl->egl_config, - self->wl->wl_window, - config->wl->egl_render_buffer); - if (!self->wl->egl_surface) - goto error; + self->egl = wayland_egl_create_window_surface(dpy->egl, + config->egl, + self->wl_window, + config->egl_render_buffer); + if (!self->egl) + goto error; - return self; + self->wcore.vtbl = &wayland_window_wcore_vtbl; + return &self->wcore; error: - wayland_window_destroy(self); + wayland_window_destroy(&self->wcore); return NULL; } -bool -wayland_window_destroy(union native_window *self) -{ - if (!self) - return true; - bool ok = true; - union native_display *dpy = self->wl->display; - - if (self->wl->egl_surface) - ok &= egl_destroy_surface(dpy->wl->egl_display, - self->wl->egl_surface); - - if (self->wl->wl_window) - wl_egl_window_destroy(self->wl->wl_window); - if (self->wl->wl_shell_surface) - wl_shell_surface_destroy(self->wl->wl_shell_surface); - if (self->wl->wl_surface) - wl_surface_destroy(self->wl->wl_surface); - - free(self); - return ok; -} - -bool -wayland_window_show(union native_window *native_self) +static bool +wayland_window_show(struct wcore_window *wc_self) { - struct wayland_window *self = native_self->wl; + struct wayland_window *self = wayland_window(wc_self); wl_shell_surface_set_toplevel(self->wl_shell_surface); @@ -140,12 +147,17 @@ wayland_window_show(union native_window *native_self) return true; } -bool -wayland_window_swap_buffers(union native_window *self) +static bool +wayland_window_swap_buffers(struct wcore_window *wc_self) { - union native_display *dpy = self->wl->display; - return egl_swap_buffers(dpy->wl->egl_display, - self->wl->egl_surface); + struct wayland_window *self = wayland_window(wc_self); + struct wayland_display *dpy = wayland_display(wc_self->display); + + return egl_swap_buffers(dpy->egl, self->egl); } -/// @} +static const struct wcore_window_vtbl wayland_window_wcore_vtbl = { + .destroy = wayland_window_destroy, + .show = wayland_window_show, + .swap_buffers = wayland_window_swap_buffers, +}; diff --git a/src/waffle/wayland/wayland_window.h b/src/waffle/wayland/wayland_window.h index b6ca086..01fdcdf 100644 --- a/src/waffle/wayland/wayland_window.h +++ b/src/waffle/wayland/wayland_window.h @@ -23,33 +23,33 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/// @defgroup wayland_window wayland_window -/// @ingroup wayland -/// @{ - -/// @file - #pragma once #include <stdbool.h> -union native_config; -union native_display; -union native_window; +#include <EGL/egl.h> + +#include <waffle/core/wcore_window.h> +#include <waffle/core/wcore_util.h> -union native_window* -wayland_window_create( - union native_config *config, - int width, - int height); +struct wcore_platform; -bool -wayland_window_destroy(union native_window *self); +struct wayland_window { + struct wcore_window wcore; -bool -wayland_window_show(union native_window *native_self); + struct wl_surface *wl_surface; + struct wl_shell_surface *wl_shell_surface; + struct wl_egl_window *wl_window; -bool -wayland_window_swap_buffers(union native_window *self); + EGLSurface egl; +}; -/// @} +DEFINE_CONTAINER_CAST_FUNC(wayland_window, + struct wayland_window, + struct wcore_window, + wcore) +struct wcore_window* +wayland_window_create(struct wcore_platform *wc_plat, + struct wcore_config *wc_config, + int width, + int height); |