EGL: Add support for weston
authorZhaowei Yuan <zhaowei.yuan@samsung.com>
Mon, 3 Dec 2018 03:08:44 +0000 (11:08 +0800)
committerXuelian Bai <xuelian.bai@samsung.com>
Tue, 21 Feb 2023 06:32:44 +0000 (14:32 +0800)
Add support for wayland & drm platforms which are used by weston.
Select EGL platform for weston by setting environment variable:
    export EGL_PLATFORM=wayland

Modifications to mesa.spec:
    Add platforms wayland and drm which is needed by weston
    Enable gbm and pack it into RPM package
Modifications to egl_dri2.h
    Since tizen, drm and wayland are all supported now, remove
    the duplicate definition of "color_buffers" and "back" for
    tizen to avoid from building error.

Merged commit:
commit 7c8922c1ead5875fda90106793c2fcfab2feb9f3
Author: Xiaowei Guan <xiaowei.guan@samsung.com>
    - fix weston build error and app launch error

commit 6e7ce80fc524b78980d702549cf5bbc3a641e6ae
Author: Xiaowei Guan <xiaowei.guan@samsung.com>
    - add wayland-egl code for platform_wayland

commit 5cd0256faa43e376dcd5b5f2c2edd2515aff9c04
Author: Zhaowei Yuan <zhaowei.yuan@samsung.com>
    - EGL: Add support for weston

Change-Id: I58272083b7d110d55800d8b9ad7e7c4f0a6f6077
Signed-off-by: Zhaowei Yuan <zhaowei.yuan@samsung.com>
packaging/mesa.spec
src/egl/drivers/dri2/egl_dri2.h
src/egl/meson.build
src/egl/wayland/wayland-egl/wayland-egl-priv.h [new file with mode: 0644]
src/egl/wayland/wayland-egl/wayland-egl-symbols-check [new file with mode: 0755]
src/egl/wayland/wayland-egl/wayland-egl.c [new file with mode: 0644]
src/egl/wayland/wayland-egl/wayland-egl.pc.in [new file with mode: 0644]

index eff7a36..d5a9861 100644 (file)
@@ -66,7 +66,7 @@ meson --prefix %{_prefix} build/ \
                -Dglx=disabled \
                -Ddri3=false \
                -Dgbm=true \
-               -Dplatforms="tizen" \
+               -Dplatforms="tizen,wayland,drm" \
 %ifarch %ix86 x86_64
                -Dgallium-drivers="i915,swrast" \
                -Ddri-drivers="" \
@@ -96,4 +96,5 @@ cp 99-GPU-Acceleration.rules %{buildroot}/etc/udev/rules.d
 %{_libdir}/libglapi*
 %{_libdir}/driver/*
 %{_libdir}/dri/*
+%{_libdir}/libgbm*
 /etc/udev/rules.d/99-GPU-Acceleration.rules
index cdbdd67..7eea735 100644 (file)
@@ -371,19 +371,10 @@ struct dri2_egl_surface
    __DRIimage    *dri_image_back;
    __DRIimage    *dri_image_front;
 
-   /* Used to record all the tbm_surface created by tpl_surface and their ages.
-    * Usually Tizen uses at most triple buffers in tpl_surface (tbm_surface_queue)
-    * so hardcode the number of color_buffers to 3.
-    */
-   struct {
-      tbm_surface_h tbm_surface;
-      int age;
-   } color_buffers[3], *back;
-
    int buffer_count;
 #endif
 
-#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
+#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM) || defined(HAVE_TIZEN_PLATFORM)
    struct {
 #ifdef HAVE_WAYLAND_PLATFORM
       struct wl_buffer *wl_buffer;
@@ -400,6 +391,13 @@ struct dri2_egl_surface
 #endif
       bool locked;
       int age;
+#ifdef HAVE_TIZEN_PLATFORM
+      /* Used to record all the tbm_surface created by tpl_surface and their ages.
+      * Usually Tizen uses at most triple buffers in tpl_surface (tbm_surface_queue)
+      * so hardcode the number of color_buffers to 3.
+      */
+      tbm_surface_h tbm_surface;
+#endif
    } color_buffers[4], *back, *current;
 #endif
 
index 5f8f008..94844ec 100644 (file)
@@ -125,6 +125,7 @@ if with_dri2
       wayland_drm_client_protocol_h,
     ]
     incs_for_egl += [include_directories('wayland/wayland-drm')]
+    incs_for_egl += [include_directories('wayland/wayland-egl')]
   endif
   if with_platform_tizen
     files_egl += files('drivers/dri2/platform_tizen.c')
diff --git a/src/egl/wayland/wayland-egl/wayland-egl-priv.h b/src/egl/wayland/wayland-egl/wayland-egl-priv.h
new file mode 100644 (file)
index 0000000..63545fe
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef _WAYLAND_EGL_PRIV_H
+#define _WAYLAND_EGL_PRIV_H
+
+
+#include <wayland-client.h>
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+/*
+ * NOTE: This version must be kept in sync with the Version field in the
+ * wayland-egl-backend.pc.in file.
+ */
+#define WL_EGL_WINDOW_VERSION 3
+
+struct wl_surface;
+
+struct wl_egl_window {
+       const intptr_t version;
+
+       int width;
+       int height;
+       int dx;
+       int dy;
+
+       int attached_width;
+       int attached_height;
+
+       void *driver_private;
+       void (*resize_callback)(struct wl_egl_window *, void *);
+       void (*destroy_window_callback)(void *);
+
+       struct wl_surface *surface;
+};
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/egl/wayland/wayland-egl/wayland-egl-symbols-check b/src/egl/wayland/wayland-egl/wayland-egl-symbols-check
new file mode 100755 (executable)
index 0000000..0c5fd09
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+FUNCS=$(nm -D --defined-only ${1-.libs/libwayland-egl.so} | grep -o "T .*" | cut -c 3- | while read func; do
+( grep -q "^$func$" || echo $func )  <<EOF
+wl_egl_window_resize
+wl_egl_window_create
+wl_egl_window_destroy
+wl_egl_window_get_attached_size
+_fini
+_init
+EOF
+done)
+
+test ! -n "$FUNCS" || echo $FUNCS
+test ! -n "$FUNCS"
+
diff --git a/src/egl/wayland/wayland-egl/wayland-egl.c b/src/egl/wayland/wayland-egl/wayland-egl.c
new file mode 100644 (file)
index 0000000..0ef5fa7
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright © 2011 Kristian Høgsberg
+ * Copyright © 2011 Benjamin Franzke
+ *
+ * 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 (including the next
+ * paragraph) 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.
+ *
+ * Authors:
+ *    Kristian Høgsberg <krh@bitplanet.net>
+ *    Benjamin Franzke <benjaminfranzke@googlemail.com>
+ */
+
+#include <stdlib.h>
+
+#include <wayland-client.h>
+#include "wayland-egl.h"
+#include "wayland-egl-priv.h"
+
+WL_EGL_EXPORT void
+wl_egl_window_resize(struct wl_egl_window *egl_window,
+                    int width, int height,
+                    int dx, int dy)
+{
+       if (width <= 0 || height <= 0)
+               return;
+
+       egl_window->width  = width;
+       egl_window->height = height;
+       egl_window->dx     = dx;
+       egl_window->dy     = dy;
+
+       if (egl_window->resize_callback)
+               egl_window->resize_callback(egl_window, egl_window->driver_private);
+}
+
+WL_EGL_EXPORT struct wl_egl_window *
+wl_egl_window_create(struct wl_surface *surface,
+                    int width, int height)
+{
+       struct wl_egl_window *egl_window;
+
+       if (width <= 0 || height <= 0)
+               return NULL;
+
+       egl_window = calloc(1, sizeof *egl_window);
+       if (!egl_window)
+               return NULL;
+
+       /* Cast away the constness to set the version number.
+        *
+        * We want the const notation since it gives an explicit
+        * feedback to the backend implementation, should it try to
+        * change it.
+        *
+        * The latter in itself is not too surprising as these days APIs
+        * tend to provide bidirectional version field.
+        */
+       intptr_t *version = (intptr_t *)&egl_window->version;
+       *version = WL_EGL_WINDOW_VERSION;
+
+       egl_window->surface = surface;
+
+       egl_window->width  = width;
+       egl_window->height = height;
+
+       return egl_window;
+}
+
+WL_EGL_EXPORT void
+wl_egl_window_destroy(struct wl_egl_window *egl_window)
+{
+       if (egl_window->destroy_window_callback)
+               egl_window->destroy_window_callback(egl_window->driver_private);
+       free(egl_window);
+}
+
+WL_EGL_EXPORT void
+wl_egl_window_get_attached_size(struct wl_egl_window *egl_window,
+                               int *width, int *height)
+{
+       if (width)
+               *width = egl_window->attached_width;
+       if (height)
+               *height = egl_window->attached_height;
+}
diff --git a/src/egl/wayland/wayland-egl/wayland-egl.pc.in b/src/egl/wayland/wayland-egl/wayland-egl.pc.in
new file mode 100644 (file)
index 0000000..8a40cfa
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: wayland-egl
+Description: Mesa wayland-egl library
+Version: @VERSION@
+Requires: wayland-client
+Libs: -L${libdir} -lwayland-egl
+Cflags: -I${includedir}