From patchwork Mon Jul 25 13:56:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 3082 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id B5E0023E54 for ; Mon, 25 Jul 2011 13:57:23 +0000 (UTC) Received: from mail-qy0-f173.google.com (mail-qy0-f173.google.com [209.85.216.173]) by fiordland.canonical.com (Postfix) with ESMTP id 632BAA18492 for ; Mon, 25 Jul 2011 13:57:23 +0000 (UTC) Received: by qyk10 with SMTP id 10so1057030qyk.11 for ; Mon, 25 Jul 2011 06:57:22 -0700 (PDT) Received: by 10.224.198.7 with SMTP id em7mr3452841qab.112.1311602242485; Mon, 25 Jul 2011 06:57:22 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs77878qcb; Mon, 25 Jul 2011 06:57:21 -0700 (PDT) Received: by 10.14.99.205 with SMTP id x53mr1573005eef.103.1311602240770; Mon, 25 Jul 2011 06:57:20 -0700 (PDT) Received: from mail-fx0-f44.google.com (mail-fx0-f44.google.com [209.85.161.44]) by mx.google.com with ESMTPS id 18si7042659fat.105.2011.07.25.06.57.20 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 06:57:20 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.161.44 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) client-ip=209.85.161.44; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.161.44 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) smtp.mail=alexandros.frantzis@linaro.org Received: by mail-fx0-f44.google.com with SMTP id 6so6802455fxe.17 for ; Mon, 25 Jul 2011 06:57:20 -0700 (PDT) Received: by 10.223.160.144 with SMTP id n16mr5332452fax.88.1311602240105; Mon, 25 Jul 2011 06:57:20 -0700 (PDT) Received: from localhost (77.49.93.204.dsl.dyn.forthnet.gr [77.49.93.204]) by mx.google.com with ESMTPS id j19sm3802392faa.41.2011.07.25.06.57.18 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 06:57:19 -0700 (PDT) From: alexandros.frantzis@linaro.org To: patches@linaro.org Subject: [PATCH 08/21] Extract function to query endianness from xlib/xcb and make it common Date: Mon, 25 Jul 2011 16:56:35 +0300 Message-Id: <1311602208-5973-8-git-send-email-alexandros.frantzis@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1311602208-5973-1-git-send-email-alexandros.frantzis@linaro.org> References: <1311602208-5973-1-git-send-email-alexandros.frantzis@linaro.org> From: Alexandros Frantzis Signed-off-by: Chris Wilson --- src/cairo-xcb-surface-render.c | 12 ++---------- src/cairo-xlib-surface.c | 19 ++++--------------- src/cairoint.h | 7 +++++++ 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/cairo-xcb-surface-render.c b/src/cairo-xcb-surface-render.c index 9c377e3..8e9acf5 100644 --- a/src/cairo-xcb-surface-render.c +++ b/src/cairo-xcb-surface-render.c @@ -3820,14 +3820,6 @@ _cairo_xcb_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph, } } -static cairo_bool_t -_native_byte_order_lsb (void) -{ - int x = 1; - - return *((char *) &x) == 1; -} - static int _cairo_xcb_get_glyphset_index_for_format (cairo_format_t format) { @@ -4016,7 +4008,7 @@ _cairo_xcb_surface_add_glyph (cairo_xcb_connection_t *connection, switch (_cairo_xcb_get_glyphset_index_for_format (scaled_glyph->surface->format)) { case GLYPHSET_INDEX_A1: /* local bitmaps are always stored with bit == byte */ - if (_native_byte_order_lsb() != (connection->root->bitmap_format_bit_order == XCB_IMAGE_ORDER_LSB_FIRST)) { + if (_cairo_is_little_endian() != (connection->root->bitmap_format_bit_order == XCB_IMAGE_ORDER_LSB_FIRST)) { int c = glyph_surface->stride * glyph_surface->height; const uint8_t *d; uint8_t *new, *n; @@ -4044,7 +4036,7 @@ _cairo_xcb_surface_add_glyph (cairo_xcb_connection_t *connection, break; case GLYPHSET_INDEX_ARGB32: - if (_native_byte_order_lsb() != (connection->root->image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST)) { + if (_cairo_is_little_endian() != (connection->root->image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST)) { unsigned int c = glyph_surface->stride * glyph_surface->height / 4; const uint32_t *d; uint32_t *new, *n; diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index 3f5d0ea..90db7d3 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -164,9 +164,6 @@ _cairo_xlib_surface_create_internal (cairo_xlib_screen_t *screen, static cairo_bool_t _cairo_surface_is_xlib (cairo_surface_t *surface); -static cairo_bool_t -_native_byte_order_lsb (void); - static cairo_int_status_t _cairo_xlib_surface_show_glyphs (void *abstract_dst, cairo_operator_t op, @@ -644,7 +641,7 @@ static void _swap_ximage_to_native (XImage *ximage) { int unit_bytes = 0; - int native_byte_order = _native_byte_order_lsb () ? LSBFirst : MSBFirst; + int native_byte_order = _cairo_is_little_endian () ? LSBFirst : MSBFirst; if (ximage->bits_per_pixel == 1 && ximage->bitmap_bit_order != native_byte_order) @@ -1151,7 +1148,7 @@ _draw_image_surface (cairo_xlib_surface_t *surface, cairo_xlib_display_t *display; XImage ximage; cairo_format_masks_t image_masks; - int native_byte_order = _native_byte_order_lsb () ? LSBFirst : MSBFirst; + int native_byte_order = _cairo_is_little_endian () ? LSBFirst : MSBFirst; pixman_image_t *pixman_image = NULL; cairo_status_t status; cairo_bool_t own_data; @@ -4025,14 +4022,6 @@ _cairo_xlib_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph, } } -static cairo_bool_t -_native_byte_order_lsb (void) -{ - int x = 1; - - return *((char *) &x) == 1; -} - static int _cairo_xlib_get_glyphset_index_for_format (cairo_format_t format) { @@ -4254,7 +4243,7 @@ _cairo_xlib_surface_add_glyph (cairo_xlib_display_t *display, switch (_cairo_xlib_get_glyphset_index_for_format (scaled_glyph->surface->format)) { case GLYPHSET_INDEX_A1: /* local bitmaps are always stored with bit == byte */ - if (_native_byte_order_lsb() != (BitmapBitOrder (display->display) == LSBFirst)) { + if (_cairo_is_little_endian() != (BitmapBitOrder (display->display) == LSBFirst)) { int c = glyph_surface->stride * glyph_surface->height; unsigned char *d; unsigned char *new, *n; @@ -4279,7 +4268,7 @@ _cairo_xlib_surface_add_glyph (cairo_xlib_display_t *display, case GLYPHSET_INDEX_A8: break; case GLYPHSET_INDEX_ARGB32: - if (_native_byte_order_lsb() != (ImageByteOrder (display->display) == LSBFirst)) { + if (_cairo_is_little_endian() != (ImageByteOrder (display->display) == LSBFirst)) { unsigned int c = glyph_surface->stride * glyph_surface->height / 4; const uint32_t *d; uint32_t *new, *n; diff --git a/src/cairoint.h b/src/cairoint.h index efe9424..1d658c8 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -182,6 +182,13 @@ _cairo_popcount (uint32_t mask) #endif } +static cairo_always_inline cairo_bool_t +_cairo_is_little_endian (void) +{ + static const int i = 1; + return *((char *) &i) == 0x01; +} + #ifdef WORDS_BIGENDIAN #define CAIRO_BITSWAP8_IF_LITTLE_ENDIAN(c) (c) #else