wayland: fix shm buffers
We need to *write* to the shared memory, not read from it. cogl_texture_from_data() is read-only, it doesn't keep the data in sync with the texture. Instead, we have to call cogl_texture_get_data() ourselves to sync manually.
This commit is contained in:
parent
c1a27d481b
commit
734a236a97
@ -95,9 +95,9 @@ wayland_create_shm_buffer (ClutterBackendWayland *backend_wayland,
|
|||||||
{
|
{
|
||||||
ClutterStageWaylandWaylandBufferSHM *buffer;
|
ClutterStageWaylandWaylandBufferSHM *buffer;
|
||||||
struct wl_visual *visual;
|
struct wl_visual *visual;
|
||||||
|
CoglHandle tex;
|
||||||
CoglTextureFlags flags = COGL_TEXTURE_NONE; /* XXX: tweak flags? */
|
CoglTextureFlags flags = COGL_TEXTURE_NONE; /* XXX: tweak flags? */
|
||||||
CoglPixelFormat format = VISUAL_ARGB_PRE;
|
CoglPixelFormat format = VISUAL_ARGB_PRE;
|
||||||
unsigned int stride;
|
|
||||||
int fd;
|
int fd;
|
||||||
gchar tmp[] = "/tmp/clutter-wayland-shm-XXXXXX";
|
gchar tmp[] = "/tmp/clutter-wayland-shm-XXXXXX";
|
||||||
|
|
||||||
@ -105,10 +105,13 @@ wayland_create_shm_buffer (ClutterBackendWayland *backend_wayland,
|
|||||||
|
|
||||||
buffer->buffer.type = BUFFER_TYPE_SHM;
|
buffer->buffer.type = BUFFER_TYPE_SHM;
|
||||||
|
|
||||||
/* XXX: can we query Cogl for what the stride should
|
tex = cogl_texture_new_with_size ((unsigned int)geom->width,
|
||||||
be for a given format and width? */
|
(unsigned int)geom->height,
|
||||||
stride = geom->width;
|
flags, format);
|
||||||
buffer->size = stride * geom->height;
|
buffer->format = format;
|
||||||
|
buffer->stride = cogl_texture_get_rowstride(tex);
|
||||||
|
buffer->size = cogl_texture_get_data(tex, format, buffer->stride, NULL);
|
||||||
|
buffer->buffer.tex = tex;
|
||||||
|
|
||||||
fd = g_mkstemp_full(tmp, O_RDWR, 0600);
|
fd = g_mkstemp_full(tmp, O_RDWR, 0600);
|
||||||
ftruncate(fd, buffer->size);
|
ftruncate(fd, buffer->size);
|
||||||
@ -117,19 +120,14 @@ wayland_create_shm_buffer (ClutterBackendWayland *backend_wayland,
|
|||||||
|
|
||||||
g_unlink(tmp);
|
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);
|
visual = get_visual (backend_wayland->wayland_display, format);
|
||||||
|
|
||||||
buffer->buffer.wayland_buffer =
|
buffer->buffer.wayland_buffer =
|
||||||
wl_shm_create_buffer (backend_wayland->wayland_shm,
|
wl_shm_create_buffer (backend_wayland->wayland_shm,
|
||||||
fd,
|
fd,
|
||||||
geom->width,
|
geom->width,
|
||||||
geom->height,
|
geom->height,
|
||||||
stride, visual);
|
buffer->stride, visual);
|
||||||
close(fd);
|
close(fd);
|
||||||
return &buffer->buffer;
|
return &buffer->buffer;
|
||||||
}
|
}
|
||||||
@ -465,6 +463,26 @@ wayland_frame_callback (void *data, uint32_t _time)
|
|||||||
stage_wayland->pending_swaps--;
|
stage_wayland->pending_swaps--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wayland_damage_buffer(ClutterStageWaylandWaylandBuffer *generic_buffer)
|
||||||
|
{
|
||||||
|
ClutterStageWaylandWaylandBufferSHM *buffer;
|
||||||
|
int size;
|
||||||
|
|
||||||
|
if (generic_buffer->type != BUFFER_TYPE_SHM)
|
||||||
|
return;
|
||||||
|
|
||||||
|
buffer = (ClutterStageWaylandWaylandBufferSHM *)generic_buffer;
|
||||||
|
|
||||||
|
size = cogl_texture_get_data(buffer->buffer.tex, buffer->format,
|
||||||
|
buffer->stride, NULL);
|
||||||
|
g_assert(size == (int)buffer->size);
|
||||||
|
|
||||||
|
(void) cogl_texture_get_data(buffer->buffer.tex, buffer->format,
|
||||||
|
buffer->stride, buffer->data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wayland_swap_buffers (ClutterStageWayland *stage_wayland)
|
wayland_swap_buffers (ClutterStageWayland *stage_wayland)
|
||||||
{
|
{
|
||||||
@ -476,6 +494,8 @@ wayland_swap_buffers (ClutterStageWayland *stage_wayland)
|
|||||||
stage_wayland->front_buffer = stage_wayland->back_buffer;
|
stage_wayland->front_buffer = stage_wayland->back_buffer;
|
||||||
stage_wayland->back_buffer = buffer;
|
stage_wayland->back_buffer = buffer;
|
||||||
|
|
||||||
|
wayland_damage_buffer(stage_wayland->front_buffer);
|
||||||
|
|
||||||
wl_surface_attach (stage_wayland->wayland_surface,
|
wl_surface_attach (stage_wayland->wayland_surface,
|
||||||
stage_wayland->front_buffer->wayland_buffer,
|
stage_wayland->front_buffer->wayland_buffer,
|
||||||
/* 0,0 here is "relative to the old buffer," not absolute */
|
/* 0,0 here is "relative to the old buffer," not absolute */
|
||||||
|
@ -60,7 +60,7 @@ typedef struct _ClutterStageWaylandWaylandBuffer
|
|||||||
struct wl_buffer *wayland_buffer;
|
struct wl_buffer *wayland_buffer;
|
||||||
cairo_region_t *dirty_region;
|
cairo_region_t *dirty_region;
|
||||||
CoglHandle tex;
|
CoglHandle tex;
|
||||||
guint8 type;
|
guint type;
|
||||||
} ClutterStageWaylandWaylandBuffer;
|
} ClutterStageWaylandWaylandBuffer;
|
||||||
|
|
||||||
typedef struct _ClutterStageWaylandWaylandBufferDRM
|
typedef struct _ClutterStageWaylandWaylandBufferDRM
|
||||||
@ -73,8 +73,10 @@ typedef struct _ClutterStageWaylandWaylandBufferDRM
|
|||||||
typedef struct _ClutterStageWaylandWaylandBufferSHM
|
typedef struct _ClutterStageWaylandWaylandBufferSHM
|
||||||
{
|
{
|
||||||
ClutterStageWaylandWaylandBuffer buffer;
|
ClutterStageWaylandWaylandBuffer buffer;
|
||||||
|
CoglPixelFormat format;
|
||||||
guint8 *data;
|
guint8 *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
unsigned int stride;
|
||||||
} ClutterStageWaylandWaylandBufferSHM;
|
} ClutterStageWaylandWaylandBufferSHM;
|
||||||
|
|
||||||
struct _ClutterStageWayland
|
struct _ClutterStageWayland
|
||||||
|
Loading…
x
Reference in New Issue
Block a user