forked from AuroraMiddleware/gtk
wayland: Port to SHM pool allocation mechanism
This commit is contained in:
parent
3eb0b195ed
commit
f20ac38315
@ -309,6 +309,7 @@ typedef struct _GdkWaylandCairoSurfaceData {
|
|||||||
#else
|
#else
|
||||||
gpointer buf;
|
gpointer buf;
|
||||||
size_t buf_length;
|
size_t buf_length;
|
||||||
|
struct wl_shm_pool *pool;
|
||||||
#endif
|
#endif
|
||||||
struct wl_buffer *buffer;
|
struct wl_buffer *buffer;
|
||||||
GdkWaylandDisplay *display;
|
GdkWaylandDisplay *display;
|
||||||
@ -434,16 +435,31 @@ gdk_wayland_create_cairo_surface (GdkWaylandDisplay *display,
|
|||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static struct wl_buffer *
|
static void
|
||||||
create_shm_buffer (struct wl_shm *shm,
|
gdk_wayland_cairo_surface_destroy (void *p)
|
||||||
int width,
|
{
|
||||||
int height,
|
GdkWaylandCairoSurfaceData *data = p;
|
||||||
uint32_t format,
|
|
||||||
size_t *buf_length,
|
if (data->buffer)
|
||||||
void **data_out)
|
wl_buffer_destroy (data->buffer);
|
||||||
|
|
||||||
|
if (data->pool)
|
||||||
|
wl_shm_pool_destroy (data->pool);
|
||||||
|
|
||||||
|
munmap (data->buf, data->buf_length);
|
||||||
|
g_free (data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static struct wl_shm_pool *
|
||||||
|
_create_shm_pool (struct wl_shm *shm,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
size_t *buf_length,
|
||||||
|
void **data_out)
|
||||||
{
|
{
|
||||||
char filename[] = "/tmp/wayland-shm-XXXXXX";
|
char filename[] = "/tmp/wayland-shm-XXXXXX";
|
||||||
struct wl_buffer *buffer;
|
struct wl_shm_pool *pool;
|
||||||
int fd, size, stride;
|
int fd, size, stride;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
@ -472,27 +488,14 @@ create_shm_buffer (struct wl_shm *shm,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = wl_shm_create_buffer (shm, fd,
|
pool = wl_shm_create_pool(shm, fd, size);
|
||||||
width, height,
|
|
||||||
stride, format);
|
|
||||||
|
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
*data_out = data;
|
*data_out = data;
|
||||||
*buf_length = size;
|
*buf_length = size;
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
return pool;
|
||||||
gdk_wayland_cairo_surface_destroy (void *p)
|
|
||||||
{
|
|
||||||
GdkWaylandCairoSurfaceData *data = p;
|
|
||||||
|
|
||||||
if (data->buffer)
|
|
||||||
wl_buffer_destroy (data->buffer);
|
|
||||||
|
|
||||||
munmap (data->buf, data->buf_length);
|
|
||||||
g_free (data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static cairo_surface_t *
|
static cairo_surface_t *
|
||||||
@ -502,6 +505,7 @@ gdk_wayland_create_cairo_surface (GdkWaylandDisplay *display,
|
|||||||
GdkWaylandCairoSurfaceData *data;
|
GdkWaylandCairoSurfaceData *data;
|
||||||
cairo_surface_t *surface = NULL;
|
cairo_surface_t *surface = NULL;
|
||||||
cairo_status_t status;
|
cairo_status_t status;
|
||||||
|
int stride;
|
||||||
|
|
||||||
data = g_new (GdkWaylandCairoSurfaceData, 1);
|
data = g_new (GdkWaylandCairoSurfaceData, 1);
|
||||||
data->display = display;
|
data->display = display;
|
||||||
@ -509,18 +513,22 @@ gdk_wayland_create_cairo_surface (GdkWaylandDisplay *display,
|
|||||||
data->width = width;
|
data->width = width;
|
||||||
data->height = height;
|
data->height = height;
|
||||||
|
|
||||||
data->buffer = create_shm_buffer (display->shm,
|
stride = width * 4;
|
||||||
width,
|
|
||||||
height,
|
data->pool = _create_shm_pool (display->shm,
|
||||||
WL_SHM_FORMAT_ARGB8888,
|
width, height,
|
||||||
&data->buf_length,
|
&data->buf_length,
|
||||||
&data->buf);
|
&data->buf);
|
||||||
|
|
||||||
|
data->buffer = wl_shm_pool_create_buffer (data->pool, 0,
|
||||||
|
width, height,
|
||||||
|
stride, WL_SHM_FORMAT_ARGB8888);
|
||||||
|
|
||||||
surface = cairo_image_surface_create_for_data (data->buf,
|
surface = cairo_image_surface_create_for_data (data->buf,
|
||||||
CAIRO_FORMAT_ARGB32,
|
CAIRO_FORMAT_ARGB32,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
width * 4);
|
stride);
|
||||||
|
|
||||||
cairo_surface_set_user_data (surface, &gdk_wayland_cairo_key,
|
cairo_surface_set_user_data (surface, &gdk_wayland_cairo_key,
|
||||||
data, gdk_wayland_cairo_surface_destroy);
|
data, gdk_wayland_cairo_surface_destroy);
|
||||||
|
Loading…
Reference in New Issue
Block a user