From 184bb09ff5cf2715dfee91e25ec20cbaa2e4445c Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Sat, 30 Apr 2011 11:18:23 +0200 Subject: st/egl: Implement EGL_WL_bind_wayland_display for x11,drm,wayland --- src/gallium/state_trackers/egl/common/egl_g3d.c | 5 ++ .../state_trackers/egl/common/egl_g3d_api.c | 33 +++++++++++++ .../state_trackers/egl/common/egl_g3d_image.c | 27 ++++++++++ src/gallium/state_trackers/egl/common/native.h | 2 + .../egl/common/native_wayland_bufmgr.h | 46 +++++++++++++++++ .../egl/common/native_wayland_drm_bufmgr_helper.c | 57 ++++++++++++++++++++++ .../egl/common/native_wayland_drm_bufmgr_helper.h | 44 +++++++++++++++++ 7 files changed, 214 insertions(+) create mode 100644 src/gallium/state_trackers/egl/common/native_wayland_bufmgr.h create mode 100644 src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c create mode 100644 src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h (limited to 'src/gallium/state_trackers/egl/common') diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index 2c7f3bde4f0..4bd865638a3 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -552,6 +552,11 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy) if (dpy->Platform == _EGL_PLATFORM_WAYLAND && gdpy->native->buffer) dpy->Extensions.MESA_drm_image = EGL_TRUE; +#ifdef EGL_WL_bind_wayland_display + if (gdpy->native->wayland_bufmgr) + dpy->Extensions.WL_bind_wayland_display = EGL_TRUE; +#endif + if (egl_g3d_add_configs(drv, dpy, 1) == 1) { _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)"); goto fail; diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c index f1568329ecf..8b1821e0055 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_api.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c @@ -868,6 +868,34 @@ egl_g3d_show_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy, #endif /* EGL_MESA_screen_surface */ +#ifdef EGL_WL_bind_wayland_display + +static EGLBoolean +egl_g3d_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *dpy, + struct wl_display *wl_dpy) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + + if (!gdpy->native->wayland_bufmgr) + return EGL_FALSE; + + return gdpy->native->wayland_bufmgr->bind_display(gdpy->native, wl_dpy); +} + +static EGLBoolean +egl_g3d_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *dpy, + struct wl_display *wl_dpy) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + + if (!gdpy->native->wayland_bufmgr) + return EGL_FALSE; + + return gdpy->native->wayland_bufmgr->unbind_display(gdpy->native, wl_dpy); +} + +#endif /* EGL_WL_bind_wayland_display */ + void egl_g3d_init_driver_api(_EGLDriver *drv) { @@ -897,6 +925,11 @@ egl_g3d_init_driver_api(_EGLDriver *drv) drv->API.CreateDRMImageMESA = egl_g3d_create_drm_image; drv->API.ExportDRMImageMESA = egl_g3d_export_drm_image; #endif +#ifdef EGL_WL_bind_wayland_display + drv->API.BindWaylandDisplayWL = egl_g3d_bind_wayland_display_wl; + drv->API.UnbindWaylandDisplayWL = egl_g3d_unbind_wayland_display_wl; + +#endif #ifdef EGL_KHR_reusable_sync drv->API.CreateSyncKHR = egl_g3d_create_sync; diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.c b/src/gallium/state_trackers/egl/common/egl_g3d_image.c index e1c83168b3a..210b8c2ee82 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_image.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.c @@ -179,6 +179,27 @@ egl_g3d_reference_drm_buffer(_EGLDisplay *dpy, EGLint name, #endif /* EGL_MESA_drm_image */ +#ifdef EGL_WL_bind_wayland_display + +static struct pipe_resource * +egl_g3d_reference_wl_buffer(_EGLDisplay *dpy, struct wl_buffer *buffer, + _EGLImage *img, const EGLint *attribs) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct pipe_resource *resource = NULL, *tmp = NULL; + + if (!gdpy->native->wayland_bufmgr) + return NULL; + + tmp = gdpy->native->wayland_bufmgr->buffer_get_resource(gdpy->native, buffer); + + pipe_resource_reference(&resource, tmp); + + return resource; +} + +#endif /* EGL_WL_bind_wayland_display */ + _EGLImage * egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLenum target, EGLClientBuffer buffer, @@ -209,6 +230,12 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, ptex = egl_g3d_reference_drm_buffer(dpy, (EGLint) buffer, &gimg->base, attribs); break; +#endif +#ifdef EGL_WL_bind_wayland_display + case EGL_WAYLAND_BUFFER_WL: + ptex = egl_g3d_reference_wl_buffer(dpy, + (struct wl_buffer *) buffer, &gimg->base, attribs); + break; #endif default: ptex = NULL; diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h index 9246f8c32a4..8646e52ed7c 100644 --- a/src/gallium/state_trackers/egl/common/native.h +++ b/src/gallium/state_trackers/egl/common/native.h @@ -40,6 +40,7 @@ extern "C" { #include "native_buffer.h" #include "native_modeset.h" +#include "native_wayland_bufmgr.h" /** * Only color buffers are listed. The others are allocated privately through, @@ -198,6 +199,7 @@ struct native_display { const struct native_display_buffer *buffer; const struct native_display_modeset *modeset; + const struct native_display_wayland_bufmgr *wayland_bufmgr; }; /** diff --git a/src/gallium/state_trackers/egl/common/native_wayland_bufmgr.h b/src/gallium/state_trackers/egl/common/native_wayland_bufmgr.h new file mode 100644 index 00000000000..b29fd15c1ae --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native_wayland_bufmgr.h @@ -0,0 +1,46 @@ +/* + * Mesa 3-D graphics library + * Version: 7.11 + * + * Copyright (C) 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 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 _NATIVE_WAYLAND_BUFMGR_H_ +#define _NATIVE_WAYLAND_BUFMGR_H_ + +struct native_display; +struct wl_display; +struct wl_buffer; +struct pipe_resource; + +struct native_display_wayland_bufmgr { + boolean (*bind_display)(struct native_display *ndpy, + struct wl_display *wl_dpy); + + boolean (*unbind_display)(struct native_display *ndpy, + struct wl_display *wl_dpy); + + struct pipe_resource *(*buffer_get_resource)(struct native_display *ndpy, + struct wl_buffer *buffer); + +}; + +#endif /* _NATIVE_WAYLAND_BUFMGR_H_ */ diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c new file mode 100644 index 00000000000..bc2cee4c386 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c @@ -0,0 +1,57 @@ +#include +#include + +#include "native.h" +#include "util/u_inlines.h" +#include "state_tracker/drm_driver.h" + +#ifdef HAVE_WAYLAND_BACKEND + +#include +#include + +#include "native_wayland_drm_bufmgr_helper.h" + +void * +egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name, + int32_t width, int32_t height, + uint32_t stride, + struct wl_visual *visual) +{ + struct native_display *ndpy = user_data; + struct pipe_resource templ; + struct winsys_handle wsh; + enum pipe_format format = PIPE_FORMAT_B8G8R8A8_UNORM; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.format = format; + templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.array_size = 1; + + memset(&wsh, 0, sizeof(wsh)); + wsh.handle = name; + wsh.stride = stride; + + return ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh); +} + +void +egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, void *buffer) +{ + struct pipe_resource *resource = buffer; + + pipe_resource_reference(&resource, NULL); +} + +struct pipe_resource * +egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy, + struct wl_buffer *buffer) +{ + return wayland_drm_buffer_get_buffer(buffer); +} + +#endif diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h new file mode 100644 index 00000000000..71cb6c52b26 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h @@ -0,0 +1,44 @@ +/* + * Mesa 3-D graphics library + * Version: 7.11 + * + * Copyright (C) 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 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 _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_ +#define _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_ + +#include "wayland-drm.h" + +void * +egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name, + int32_t width, int32_t height, + uint32_t stride, + struct wl_visual *visual); + +void +egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, void *buffer); + +struct pipe_resource * +egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy, + struct wl_buffer *buffer); + +#endif /* _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_ */ -- cgit v1.2.3