wayland: add shm buffer code

It's not enabled to do anything yet.
This commit is contained in:
nobled 2011-01-31 04:22:50 +00:00
parent d4ccef786b
commit d84f31ef3a
4 changed files with 75 additions and 0 deletions

View File

@ -175,6 +175,10 @@ display_handle_global (struct wl_display *display,
wl_drm_add_listener (backend_wayland->wayland_drm, wl_drm_add_listener (backend_wayland->wayland_drm,
&drm_listener, backend_wayland); &drm_listener, backend_wayland);
} }
else if (strcmp (interface, "shm") == 0)
{
backend_wayland->wayland_shm = wl_shm_create (display, id);
}
} }
static gboolean static gboolean

View File

@ -67,6 +67,7 @@ struct _ClutterBackendWayland
struct wl_compositor *wayland_compositor; struct wl_compositor *wayland_compositor;
struct wl_shell *wayland_shell; struct wl_shell *wayland_shell;
struct wl_drm *wayland_drm; struct wl_drm *wayland_drm;
struct wl_shm *wayland_shm;
char *device_name; char *device_name;
int authenticated; int authenticated;
struct wl_output *wayland_output; struct wl_output *wayland_output;

View File

@ -28,7 +28,12 @@
#include "config.h" #include "config.h"
#endif #endif
#include <fcntl.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include <wayland-util.h> #include <wayland-util.h>
#include <wayland-client.h> #include <wayland-client.h>
#include <xf86drm.h> #include <xf86drm.h>
@ -84,6 +89,50 @@ get_visual (struct wl_display *display, CoglPixelFormat format)
return NULL; return NULL;
} }
} }
static ClutterStageWaylandWaylandBuffer *
wayland_create_shm_buffer (ClutterBackendWayland *backend_wayland,
ClutterGeometry *geom)
{
ClutterStageWaylandWaylandBufferSHM *buffer;
struct wl_visual *visual;
CoglTextureFlags flags = COGL_TEXTURE_NONE; /* XXX: tweak flags? */
CoglPixelFormat format = VISUAL_ARGB_PRE;
unsigned int stride;
int fd;
gchar tmp[] = "/tmp/clutter-wayland-shm-XXXXXX";
buffer = g_slice_new (ClutterStageWaylandWaylandBufferSHM);
buffer->buffer.type = BUFFER_TYPE_SHM;
/* XXX: can we query Cogl for what the stride should
be for a given format and width? */
stride = geom->width;
buffer->size = stride * geom->height;
fd = g_mkstemp_full(tmp, O_RDWR, 0600);
ftruncate(fd, buffer->size);
buffer->data = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
g_unlink(tmp);
buffer->buffer.tex = cogl_texture_new_from_data ((unsigned int)geom->width,
(unsigned int)geom->height,
flags, format,
COGL_PIXEL_FORMAT_ANY,
stride, buffer->data);
visual = get_visual (backend_wayland->wayland_display, format);
buffer->buffer.wayland_buffer =
wl_shm_create_buffer (backend_wayland->wayland_shm,
fd,
geom->width,
geom->height,
stride, visual);
close(fd);
return &buffer->buffer;
}
static ClutterStageWaylandWaylandBuffer * static ClutterStageWaylandWaylandBuffer *
wayland_create_drm_buffer (ClutterBackendWayland *backend_wayland, wayland_create_drm_buffer (ClutterBackendWayland *backend_wayland,
@ -154,6 +203,17 @@ wayland_create_buffer (ClutterGeometry *geom)
return buffer; return buffer;
} }
static void
wayland_free_shm_buffer (ClutterStageWaylandWaylandBuffer *generic_buffer)
{
ClutterStageWaylandWaylandBufferSHM *buffer;
buffer = (ClutterStageWaylandWaylandBufferSHM *)generic_buffer;
munmap(buffer->data, buffer->size);
g_slice_free (ClutterStageWaylandWaylandBufferSHM, buffer);
}
static void static void
wayland_free_drm_buffer (ClutterStageWaylandWaylandBuffer *generic_buffer) wayland_free_drm_buffer (ClutterStageWaylandWaylandBuffer *generic_buffer)
{ {
@ -178,6 +238,8 @@ wayland_free_buffer (ClutterStageWaylandWaylandBuffer *buffer)
if (buffer->type == BUFFER_TYPE_DRM) if (buffer->type == BUFFER_TYPE_DRM)
wayland_free_drm_buffer(buffer); wayland_free_drm_buffer(buffer);
else if (buffer->type == BUFFER_TYPE_SHM)
wayland_free_shm_buffer(buffer);
} }
static void static void

View File

@ -52,6 +52,7 @@ typedef struct _ClutterStageWayland ClutterStageWayland;
typedef struct _ClutterStageWaylandClass ClutterStageWaylandClass; typedef struct _ClutterStageWaylandClass ClutterStageWaylandClass;
#define BUFFER_TYPE_DRM 1 #define BUFFER_TYPE_DRM 1
#define BUFFER_TYPE_SHM 2
typedef struct _ClutterStageWaylandWaylandBuffer typedef struct _ClutterStageWaylandWaylandBuffer
{ {
@ -69,6 +70,13 @@ typedef struct _ClutterStageWaylandWaylandBufferDRM
GLuint texture; GLuint texture;
} ClutterStageWaylandWaylandBufferDRM; } ClutterStageWaylandWaylandBufferDRM;
typedef struct _ClutterStageWaylandWaylandBufferSHM
{
ClutterStageWaylandWaylandBuffer buffer;
guint8 *data;
size_t size;
} ClutterStageWaylandWaylandBufferSHM;
struct _ClutterStageWayland struct _ClutterStageWayland
{ {
GObject parent_instance; GObject parent_instance;