From 8951c51d9e63dc175bc1eff6592833de627bce74 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 18 Aug 2011 12:51:28 +0200 Subject: [PATCH] xcb: Merge two functions for creating shm images This merges most of _cairo_xcb_surface_create_similar_image() into _cairo_xcb_shm_image_create(). These two functions where already doing almost the same thing with only some differences in error handling. Signed-off-by: Uli Schlachter --- src/cairo-xcb-private.h | 2 ++ src/cairo-xcb-surface-core.c | 3 +++ src/cairo-xcb-surface.c | 46 ++++-------------------------------- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/src/cairo-xcb-private.h b/src/cairo-xcb-private.h index d9557b471..648bd5705 100644 --- a/src/cairo-xcb-private.h +++ b/src/cairo-xcb-private.h @@ -56,6 +56,8 @@ #include #include +#define XLIB_COORD_MAX 32767 + /* maximum number of cached GC's */ #define GC_CACHE_SIZE 4 diff --git a/src/cairo-xcb-surface-core.c b/src/cairo-xcb-surface-core.c index 0770dcd7a..20cb5d37d 100644 --- a/src/cairo-xcb-surface-core.c +++ b/src/cairo-xcb-surface-core.c @@ -156,6 +156,9 @@ _cairo_xcb_shm_image_create_shm (cairo_xcb_connection_t *connection, if (! (connection->flags & CAIRO_XCB_HAS_SHM)) return CAIRO_INT_STATUS_UNSUPPORTED; + if (unlikely (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX)) + return CAIRO_INT_STATUS_UNSUPPORTED; + stride = CAIRO_STRIDE_FOR_WIDTH_BPP (width, PIXMAN_FORMAT_BPP (pixman_format)); size = stride * height; if (size <= CAIRO_XCB_SHM_SMALL_IMAGE) diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c index 48aa17672..c3df5ed52 100644 --- a/src/cairo-xcb-surface.c +++ b/src/cairo-xcb-surface.c @@ -46,8 +46,6 @@ #include "cairo-default-context-private.h" #include "cairo-image-surface-private.h" -#define XLIB_COORD_MAX 32767 - #if CAIRO_HAS_XLIB_XCB_FUNCTIONS slim_hidden_proto (cairo_xcb_surface_create); slim_hidden_proto (cairo_xcb_surface_create_for_bitmap); @@ -164,56 +162,22 @@ _cairo_xcb_surface_create_similar_image (void *abstract_other, int width, int height) { -#if CAIRO_HAS_XCB_SHM_FUNCTIONS cairo_xcb_surface_t *other = abstract_other; cairo_xcb_connection_t *connection = other->connection; - cairo_surface_t *image; cairo_xcb_shm_info_t *shm_info; + cairo_image_surface_t *image; cairo_status_t status; - size_t stride; pixman_format_code_t pixman_format; - if (unlikely(width > XLIB_COORD_MAX || height > XLIB_COORD_MAX)) - return cairo_image_surface_create (format, width, height); - - if ((connection->flags & CAIRO_XCB_HAS_SHM) == 0) - return cairo_image_surface_create (format, width, height); - pixman_format = _cairo_format_to_pixman_format_code (format); - stride = CAIRO_STRIDE_FOR_WIDTH_BPP (width, - PIXMAN_FORMAT_BPP (pixman_format)); - status = _cairo_xcb_connection_allocate_shm_info (connection, - stride * height, - &shm_info); + status = _cairo_xcb_shm_image_create (connection, pixman_format, + width, height, &image, + &shm_info); if (unlikely (status)) - return cairo_image_surface_create (format, width, height); - - image = _cairo_image_surface_create_with_pixman_format (shm_info->mem, - pixman_format, - width, - height, - stride); - if (unlikely (image->status)) { - _cairo_xcb_shm_info_destroy (shm_info); - return image; - } - - status = _cairo_user_data_array_set_data (&image->user_data, - (const cairo_user_data_key_t *) connection, - shm_info, - (cairo_destroy_func_t) _cairo_xcb_shm_info_destroy); - if (unlikely (status)) { - cairo_surface_destroy (image); - _cairo_xcb_shm_info_destroy (shm_info); return _cairo_surface_create_in_error (status); - } - - return image; -#else - return cairo_image_surface_create (format, width, height); -#endif + return &image->base; } static cairo_status_t