wayland: Improve error messages during SHM buffer creation
Use g_critical rather than fprintf and and also grab the error messages from errno and from Cairo
This commit is contained in:
@ -34,6 +34,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <wayland-egl.h>
|
#include <wayland-egl.h>
|
||||||
|
|
||||||
@ -440,33 +441,36 @@ create_shm_buffer (struct wl_shm *shm,
|
|||||||
int fd, size, stride;
|
int fd, size, stride;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
fd = mkstemp(filename);
|
fd = mkstemp (filename);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, "open %s failed: %m\n", filename);
|
g_critical (G_STRLOC ": Unable to create temporary file (%s): %s",
|
||||||
|
filename, g_strerror (errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
stride = width * 4;
|
stride = width * 4;
|
||||||
size = stride * height;
|
size = stride * height;
|
||||||
if (ftruncate(fd, size) < 0) {
|
if (ftruncate (fd, size) < 0) {
|
||||||
fprintf(stderr, "ftruncate failed: %m\n");
|
g_critical (G_STRLOC ": Truncating temporary file failed: %s",
|
||||||
|
g_strerror (errno));
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
unlink(filename);
|
unlink (filename);
|
||||||
|
|
||||||
if (data == MAP_FAILED) {
|
if (data == MAP_FAILED) {
|
||||||
fprintf(stderr, "mmap failed: %m\n");
|
g_critical (G_STRLOC ": mmap'ping temporary file failed: %s",
|
||||||
|
g_strerror (errno));
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = wl_shm_create_buffer(shm, fd,
|
buffer = wl_shm_create_buffer (shm, fd,
|
||||||
width, height,
|
width, height,
|
||||||
stride, format);
|
stride, format);
|
||||||
|
|
||||||
close(fd);
|
close (fd);
|
||||||
|
|
||||||
*data_out = data;
|
*data_out = data;
|
||||||
*buf_length = size;
|
*buf_length = size;
|
||||||
@ -479,10 +483,10 @@ gdk_wayland_cairo_surface_destroy (void *p)
|
|||||||
GdkWaylandCairoSurfaceData *data = p;
|
GdkWaylandCairoSurfaceData *data = p;
|
||||||
|
|
||||||
if (data->buffer)
|
if (data->buffer)
|
||||||
wl_buffer_destroy(data->buffer);
|
wl_buffer_destroy (data->buffer);
|
||||||
|
|
||||||
munmap(data->buf, data->buf_length);
|
munmap (data->buf, data->buf_length);
|
||||||
g_free(data);
|
g_free (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static cairo_surface_t *
|
static cairo_surface_t *
|
||||||
@ -490,7 +494,8 @@ gdk_wayland_create_cairo_surface (GdkWaylandDisplay *display,
|
|||||||
int width, int height)
|
int width, int height)
|
||||||
{
|
{
|
||||||
GdkWaylandCairoSurfaceData *data;
|
GdkWaylandCairoSurfaceData *data;
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface = NULL;
|
||||||
|
cairo_status_t status;
|
||||||
|
|
||||||
data = g_new (GdkWaylandCairoSurfaceData, 1);
|
data = g_new (GdkWaylandCairoSurfaceData, 1);
|
||||||
data->display = display;
|
data->display = display;
|
||||||
@ -514,8 +519,12 @@ gdk_wayland_create_cairo_surface (GdkWaylandDisplay *display,
|
|||||||
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);
|
||||||
|
|
||||||
if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
|
status = cairo_surface_status (surface);
|
||||||
fprintf (stderr, "create image surface failed\n");
|
if (status != CAIRO_STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
g_critical (G_STRLOC ": Unable to create Cairo image surface: %s",
|
||||||
|
cairo_status_to_string (status));
|
||||||
|
}
|
||||||
|
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user