From 6e7ce80fc524b78980d702549cf5bbc3a641e6ae Mon Sep 17 00:00:00 2001 From: Xiaowei Guan Date: Thu, 18 Apr 2019 16:43:01 +0800 Subject: add wayland-egl code for platform_wayland Change-Id: Ic7b4623c24f95187bb4effa3e88f6ee691b4b0b3 --- src/egl/Makefile.am | 1 + src/egl/drivers/dri2/platform_wayland.c | 7 +- src/egl/wayland/wayland-egl/Makefile.am | 20 ++++ src/egl/wayland/wayland-egl/wayland-egl-priv.h | 41 +++++++++ .../wayland/wayland-egl/wayland-egl-symbols-check | 16 ++++ src/egl/wayland/wayland-egl/wayland-egl.c | 102 +++++++++++++++++++++ src/egl/wayland/wayland-egl/wayland-egl.pc.in | 11 +++ 7 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 src/egl/wayland/wayland-egl/Makefile.am create mode 100644 src/egl/wayland/wayland-egl/wayland-egl-priv.h create mode 100755 src/egl/wayland/wayland-egl/wayland-egl-symbols-check create mode 100644 src/egl/wayland/wayland-egl/wayland-egl.c create mode 100644 src/egl/wayland/wayland-egl/wayland-egl.pc.in diff --git a/src/egl/Makefile.am b/src/egl/Makefile.am index 2383022962b..ba8d6c599d4 100644 --- a/src/egl/Makefile.am +++ b/src/egl/Makefile.am @@ -125,6 +125,7 @@ AM_CFLAGS += \ -I$(top_builddir)/src/egl/drivers/dri2 \ -I$(top_srcdir)/src/egl/drivers/dri2 \ -I$(top_srcdir)/src/gbm/backends/dri \ + -I$(top_srcdir)/src/egl/wayland/wayland-egl \ -I$(top_builddir)/src/egl/wayland/wayland-drm \ -I$(top_srcdir)/src/egl/wayland/wayland-drm diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index 0064f827ef8..c4a58a28d15 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -45,8 +45,7 @@ #include "util/u_vector.h" #include "eglglobals.h" -//include -#include +#include "wayland-egl-priv.h" #include #include "wayland-drm-client-protocol.h" #include "linux-dmabuf-unstable-v1-client-protocol.h" @@ -345,7 +344,7 @@ dri2_wl_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, dri2_surf->wl_queue); dri2_surf->wl_win = window; - dri2_surf->wl_win->private = dri2_surf; + dri2_surf->wl_win->driver_private = dri2_surf; dri2_surf->wl_win->destroy_window_callback = destroy_window_callback; if (dri2_dpy->flush) dri2_surf->wl_win->resize_callback = resize_callback; @@ -431,7 +430,7 @@ dri2_wl_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) wl_callback_destroy(dri2_surf->throttle_callback); if (dri2_surf->wl_win) { - dri2_surf->wl_win->private = NULL; + dri2_surf->wl_win->driver_private = NULL; dri2_surf->wl_win->resize_callback = NULL; dri2_surf->wl_win->destroy_window_callback = NULL; } diff --git a/src/egl/wayland/wayland-egl/Makefile.am b/src/egl/wayland/wayland-egl/Makefile.am new file mode 100644 index 00000000000..8c45e8e26d7 --- /dev/null +++ b/src/egl/wayland/wayland-egl/Makefile.am @@ -0,0 +1,20 @@ +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = wayland-egl.pc + +AM_CFLAGS = $(DEFINES) \ + $(VISIBILITY_CFLAGS) \ + $(WAYLAND_CFLAGS) + +lib_LTLIBRARIES = libwayland-egl.la +noinst_HEADERS = wayland-egl-priv.h +libwayland_egl_la_SOURCES = wayland-egl.c +libwayland_egl_la_LDFLAGS = \ + -no-undefined \ + -version-info 1 \ + $(GC_SECTIONS) \ + $(LD_NO_UNDEFINED) + +TESTS = wayland-egl-symbols-check +EXTRA_DIST = wayland-egl-symbols-check + +include $(top_srcdir)/install-lib-links.mk 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 index 00000000000..63545fee221 --- /dev/null +++ b/src/egl/wayland/wayland-egl/wayland-egl-priv.h @@ -0,0 +1,41 @@ +#ifndef _WAYLAND_EGL_PRIV_H +#define _WAYLAND_EGL_PRIV_H + + +#include + +#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 index 00000000000..0c5fd09a012 --- /dev/null +++ b/src/egl/wayland/wayland-egl/wayland-egl-symbols-check @@ -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 ) < + * Benjamin Franzke + */ + +#include + +#include +#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 index 00000000000..8a40cfac5aa --- /dev/null +++ b/src/egl/wayland/wayland-egl/wayland-egl.pc.in @@ -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} -- cgit v1.2.3