summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/egl/common
diff options
context:
space:
mode:
authorAnder Conselvan de Oliveira <[email protected]>2013-07-18 15:11:23 +0300
committerKristian Høgsberg <[email protected]>2013-08-07 10:37:58 -0700
commit331a8fa41d174c74afe58f43a5943627398eac6b (patch)
tree972c6bdd468c9f317ea19d0ac92bfaaf5da729ba /src/gallium/state_trackers/egl/common
parent79b868fea137bea095b64bd14cb174ca8af98705 (diff)
gallium-egl: Simplify native_wayland_drm_bufmgr_helper interface
The helper provides a series of functions to easy the implementation of the WL_bind_wayland_display extension on different platforms. But even with the helpers there was still a bit of duplicated code between platforms, with the drm authentication being the only part that differs. This patch changes the bufmgr interface to provide a self contained object with a create function that takes a drm authentication callback as an argument. That way all the helper functions are made static and the "_helper" suffix was removed from the sources file name. This change also removes the mix of Wayland client and server code in the wayland drm platform source file. All the uses of libwayland-server are now contained in native_wayland_drm_bufmgr.c. Changes to the drm platform are only compile tested. Signed-off-by: Ander Conselvan de Oliveira <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/egl/common')
-rw-r--r--src/gallium/state_trackers/egl/common/native.h2
-rw-r--r--src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c214
-rw-r--r--src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.h (renamed from src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h)26
-rw-r--r--src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c106
4 files changed, 223 insertions, 125 deletions
diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h
index 431bd3f2dc0..797933d8d75 100644
--- a/src/gallium/state_trackers/egl/common/native.h
+++ b/src/gallium/state_trackers/egl/common/native.h
@@ -245,7 +245,7 @@ struct native_display {
const struct native_display_buffer *buffer;
const struct native_display_modeset *modeset;
- const struct native_display_wayland_bufmgr *wayland_bufmgr;
+ struct native_display_wayland_bufmgr *wayland_bufmgr;
};
/**
diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c
new file mode 100644
index 00000000000..1603a3a71e2
--- /dev/null
+++ b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c
@@ -0,0 +1,214 @@
+#include <stdint.h>
+#include <string.h>
+
+#include "native.h"
+#include "util/u_inlines.h"
+#include "state_tracker/drm_driver.h"
+
+#ifdef HAVE_WAYLAND_BACKEND
+
+#include <wayland-server.h>
+#include <wayland-drm-server-protocol.h>
+
+#include "native_wayland_drm_bufmgr.h"
+
+#include "wayland-drm.h"
+
+struct wayland_drm_bufmgr {
+ struct native_display_wayland_bufmgr base;
+
+ struct wl_drm *wl_server_drm;
+ char *device_name;
+
+ void *user_data;
+
+ wayland_drm_bufmgr_authenticate_func authenticate;
+};
+
+static INLINE struct wayland_drm_bufmgr *
+wayland_drm_bufmgr(const struct native_display_wayland_bufmgr *base)
+{
+ return (struct wayland_drm_bufmgr *) base;
+}
+
+static int
+wayland_drm_bufmgr_authenticate(void *user_data, uint32_t magic)
+{
+ struct native_display *ndpy = user_data;
+ struct wayland_drm_bufmgr *bufmgr;
+
+ bufmgr = wayland_drm_bufmgr(ndpy->wayland_bufmgr);
+
+ return bufmgr->authenticate(user_data, magic);
+}
+
+static void
+wayland_drm_bufmgr_reference_buffer(void *user_data, uint32_t name, int fd,
+ struct wl_drm_buffer *buffer)
+{
+ struct native_display *ndpy = user_data;
+ struct pipe_resource templ;
+ struct winsys_handle wsh;
+ enum pipe_format pf;
+
+ switch (buffer->format) {
+ case WL_DRM_FORMAT_ARGB8888:
+ pf = PIPE_FORMAT_B8G8R8A8_UNORM;
+ break;
+ case WL_DRM_FORMAT_XRGB8888:
+ pf = PIPE_FORMAT_B8G8R8X8_UNORM;
+ break;
+ default:
+ pf = PIPE_FORMAT_NONE;
+ break;
+ }
+
+ if (pf == PIPE_FORMAT_NONE)
+ return;
+
+ memset(&templ, 0, sizeof(templ));
+ templ.target = PIPE_TEXTURE_2D;
+ templ.format = pf;
+ templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+ templ.width0 = buffer->buffer.width;
+ templ.height0 = buffer->buffer.height;
+ templ.depth0 = 1;
+ templ.array_size = 1;
+
+ memset(&wsh, 0, sizeof(wsh));
+ wsh.handle = name;
+ wsh.stride = buffer->stride[0];
+
+ buffer->driver_buffer =
+ ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh);
+}
+
+static void
+wayland_drm_bufmgr_unreference_buffer(void *user_data,
+ struct wl_drm_buffer *buffer)
+{
+ struct pipe_resource *resource = buffer->driver_buffer;
+
+ pipe_resource_reference(&resource, NULL);
+}
+
+static struct wayland_drm_callbacks wl_drm_callbacks = {
+ wayland_drm_bufmgr_authenticate,
+ wayland_drm_bufmgr_reference_buffer,
+ wayland_drm_bufmgr_unreference_buffer
+};
+
+static boolean
+wayland_drm_bufmgr_bind_display(struct native_display *ndpy,
+ struct wl_display *wl_dpy)
+{
+ struct wayland_drm_bufmgr *bufmgr;
+
+ bufmgr = wayland_drm_bufmgr(ndpy->wayland_bufmgr);
+
+ if (bufmgr->wl_server_drm)
+ return FALSE;
+
+ bufmgr->wl_server_drm = wayland_drm_init(wl_dpy, bufmgr->device_name,
+ &wl_drm_callbacks, ndpy, 0);
+
+ if (!bufmgr->wl_server_drm)
+ return FALSE;
+
+ return TRUE;
+}
+
+static boolean
+wayland_drm_bufmgr_unbind_display(struct native_display *ndpy,
+ struct wl_display *wl_dpy)
+{
+ struct wayland_drm_bufmgr *bufmgr;
+
+ bufmgr = wayland_drm_bufmgr(ndpy->wayland_bufmgr);
+
+ if (!bufmgr->wl_server_drm)
+ return FALSE;
+
+ wayland_drm_uninit(bufmgr->wl_server_drm);
+ bufmgr->wl_server_drm = NULL;
+
+ return TRUE;
+}
+
+static struct pipe_resource *
+wayland_drm_bufmgr_wl_buffer_get_resource(struct native_display *ndpy,
+ struct wl_buffer *buffer)
+{
+ return wayland_drm_buffer_get_buffer(buffer);
+}
+
+static EGLBoolean
+wayland_drm_bufmgr_query_buffer(struct native_display *ndpy,
+ struct wl_buffer *_buffer,
+ EGLint attribute, EGLint *value)
+{
+ struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer;
+ struct pipe_resource *resource = buffer->driver_buffer;
+
+ if (!wayland_buffer_is_drm(&buffer->buffer))
+ return EGL_FALSE;
+
+ switch (attribute) {
+ case EGL_TEXTURE_FORMAT:
+ switch (resource->format) {
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ *value = EGL_TEXTURE_RGBA;
+ return EGL_TRUE;
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ *value = EGL_TEXTURE_RGB;
+ return EGL_TRUE;
+ default:
+ return EGL_FALSE;
+ }
+ case EGL_WIDTH:
+ *value = buffer->buffer.width;
+ return EGL_TRUE;
+ case EGL_HEIGHT:
+ *value = buffer->buffer.height;
+ return EGL_TRUE;
+ default:
+ return EGL_FALSE;
+ }
+}
+
+
+struct native_display_wayland_bufmgr *
+wayland_drm_bufmgr_create(wayland_drm_bufmgr_authenticate_func authenticate,
+ void *user_data, char *device_name)
+{
+ struct wayland_drm_bufmgr *bufmgr;
+
+ bufmgr = calloc(1, sizeof *bufmgr);
+ if (!bufmgr)
+ return NULL;
+
+ bufmgr->user_data = user_data;
+ bufmgr->authenticate = authenticate;
+ bufmgr->device_name = strdup(device_name);
+
+ bufmgr->base.bind_display = wayland_drm_bufmgr_bind_display;
+ bufmgr->base.unbind_display = wayland_drm_bufmgr_unbind_display;
+ bufmgr->base.buffer_get_resource = wayland_drm_bufmgr_wl_buffer_get_resource;
+ bufmgr->base.query_buffer = wayland_drm_bufmgr_query_buffer;
+
+ return &bufmgr->base;
+}
+
+void
+wayland_drm_bufmgr_destroy(struct native_display_wayland_bufmgr *_bufmgr)
+{
+ struct wayland_drm_bufmgr *bufmgr = wayland_drm_bufmgr(_bufmgr);
+
+ if (!bufmgr)
+ return;
+
+ free(bufmgr->device_name);
+ free(bufmgr);
+}
+
+#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.h
index 543dc6faf47..7bf6513f300 100644
--- a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h
+++ b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.h
@@ -22,26 +22,16 @@
* DEALINGS IN THE SOFTWARE.
*/
-#ifndef _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_
-#define _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_
+#ifndef _NATIVE_WAYLAND_DRM_BUFMGR_H_
+#define _NATIVE_WAYLAND_DRM_BUFMGR_H_
-#include "wayland-drm.h"
+typedef int (*wayland_drm_bufmgr_authenticate_func)(void *, uint32_t);
-void
-egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name, int fd,
- struct wl_drm_buffer *buffer);
+struct native_display_wayland_bufmgr *
+wayland_drm_bufmgr_create(wayland_drm_bufmgr_authenticate_func authenticate,
+ void *user_data, char *device_name);
void
-egl_g3d_wl_drm_helper_unreference_buffer(void *user_data,
- struct wl_drm_buffer *buffer);
-
-struct pipe_resource *
-egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy,
- struct wl_buffer *buffer);
-
-EGLBoolean
-egl_g3d_wl_drm_common_query_buffer(struct native_display *ndpy,
- struct wl_buffer *buffer,
- EGLint attribute, EGLint *value);
+wayland_drm_bufmgr_destroy(struct native_display_wayland_bufmgr *bufmgr);
-#endif /* _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_ */
+#endif /* _NATIVE_WAYLAND_DRM_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
deleted file mode 100644
index a9e7342b68b..00000000000
--- a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c
+++ /dev/null
@@ -1,106 +0,0 @@
-#include <stdint.h>
-#include <string.h>
-
-#include "native.h"
-#include "util/u_inlines.h"
-#include "state_tracker/drm_driver.h"
-
-#ifdef HAVE_WAYLAND_BACKEND
-
-#include <wayland-server.h>
-#include <wayland-drm-server-protocol.h>
-
-#include "native_wayland_drm_bufmgr_helper.h"
-
-void
-egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name, int fd,
- struct wl_drm_buffer *buffer)
-{
- struct native_display *ndpy = user_data;
- struct pipe_resource templ;
- struct winsys_handle wsh;
- enum pipe_format pf;
-
- switch (buffer->format) {
- case WL_DRM_FORMAT_ARGB8888:
- pf = PIPE_FORMAT_B8G8R8A8_UNORM;
- break;
- case WL_DRM_FORMAT_XRGB8888:
- pf = PIPE_FORMAT_B8G8R8X8_UNORM;
- break;
- default:
- pf = PIPE_FORMAT_NONE;
- break;
- }
-
- if (pf == PIPE_FORMAT_NONE)
- return;
-
- memset(&templ, 0, sizeof(templ));
- templ.target = PIPE_TEXTURE_2D;
- templ.format = pf;
- templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
- templ.width0 = buffer->buffer.width;
- templ.height0 = buffer->buffer.height;
- templ.depth0 = 1;
- templ.array_size = 1;
-
- memset(&wsh, 0, sizeof(wsh));
- wsh.handle = name;
- wsh.stride = buffer->stride[0];
-
- buffer->driver_buffer =
- ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh);
-}
-
-void
-egl_g3d_wl_drm_helper_unreference_buffer(void *user_data,
- struct wl_drm_buffer *buffer)
-{
- struct pipe_resource *resource = buffer->driver_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);
-}
-
-EGLBoolean
-egl_g3d_wl_drm_common_query_buffer(struct native_display *ndpy,
- struct wl_buffer *_buffer,
- EGLint attribute, EGLint *value)
-{
- struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer;
- struct pipe_resource *resource = buffer->driver_buffer;
-
- if (!wayland_buffer_is_drm(&buffer->buffer))
- return EGL_FALSE;
-
- switch (attribute) {
- case EGL_TEXTURE_FORMAT:
- switch (resource->format) {
- case PIPE_FORMAT_B8G8R8A8_UNORM:
- *value = EGL_TEXTURE_RGBA;
- return EGL_TRUE;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
- *value = EGL_TEXTURE_RGB;
- return EGL_TRUE;
- default:
- return EGL_FALSE;
- }
- case EGL_WIDTH:
- *value = buffer->buffer.width;
- return EGL_TRUE;
- case EGL_HEIGHT:
- *value = buffer->buffer.height;
- return EGL_TRUE;
- default:
- return EGL_FALSE;
- }
-}
-
-#endif