summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoe Hao Cheng <haochengho12907@gmail.com>2023-03-25 21:31:36 +0800
committerErik Faye-Lund <erik.faye-lund@collabora.com>2023-04-04 19:56:58 +0000
commit4bbacec1719fab574d116d1b3218851304ced592 (patch)
tree4ba379afcdd95a927df0920a552c77d98673cd45
parenta9f16d6430e0973a26fab1fa684349deccb3a95c (diff)
downloadmesa-demos-4bbacec1719fab574d116d1b3218851304ced592.tar.gz
eglut: introduce eglut_wsi_interface
The goal is to unify the *_x11 and *_wayland binaries into one, just like how the Vulkan demo does it. Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
-rw-r--r--src/egl/eglut/wsi/wsi.c39
-rw-r--r--src/egl/eglut/wsi/wsi.h53
2 files changed, 92 insertions, 0 deletions
diff --git a/src/egl/eglut/wsi/wsi.c b/src/egl/eglut/wsi/wsi.c
new file mode 100644
index 00000000..77ace25f
--- /dev/null
+++ b/src/egl/eglut/wsi/wsi.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2023 Hoe Hao Cheng
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "wsi.h"
+
+#include <stdlib.h>
+
+struct eglut_wsi_interface
+_eglutGetWindowSystemInterface(void)
+{
+#if defined(WAYLAND_SUPPORT) && defined(X11_SUPPORT)
+ const char *wayland_dpy = getenv("WAYLAND_DISPLAY");
+ return wayland_dpy && *wayland_dpy ? wayland_wsi_interface() :
+ x11_wsi_interface();
+#elif defined(WAYLAND_SUPPORT)
+ return wayland_wsi_interface();
+#elif defined(X11_SUPPORT)
+ return x11_wsi_interface();
+#endif
+}
diff --git a/src/egl/eglut/wsi/wsi.h b/src/egl/eglut/wsi/wsi.h
new file mode 100644
index 00000000..cd3a2548
--- /dev/null
+++ b/src/egl/eglut/wsi/wsi.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2023 Hoe Hao Cheng
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WSI_H_
+#define WSI_H_
+
+#include <stdbool.h>
+
+struct eglut_window;
+
+struct eglut_wsi_interface {
+ void (*init_display)();
+ void (*fini_display)();
+
+ void (*init_window)(struct eglut_window *win, const char *title,
+ int x, int y, int w, int h);
+ void (*event_loop)();
+ void (*fini_window)(struct eglut_window *win);
+};
+
+#ifdef WAYLAND_SUPPORT
+struct eglut_wsi_interface
+wayland_wsi_interface(void);
+#endif
+
+#ifdef X11_SUPPORT
+struct eglut_wsi_interface
+x11_wsi_interface(void);
+#endif
+
+struct eglut_wsi_interface
+_eglutGetWindowSystemInterface(void);
+
+#endif /* WSI_H_ */