diff --git a/src/cairo-deprecated.h b/src/cairo-deprecated.h index 6397cc4..e1f25bf 100644 --- a/src/cairo-deprecated.h +++ b/src/cairo-deprecated.h @@ -36,20 +36,6 @@ #ifndef CAIRO_DEPRECATED_H #define CAIRO_DEPRECATED_H -/* The %CAIRO_FORMAT_RGB16_565 value was added in cairo 1.2.0 as part - * of fixing cairo's xlib backend to work with X servers advertising a - * 16-bit, 565 visual. But as it turned out, adding this format to - * #cairo_format_t was not necessary, and was a mistake, (cairo's xlib - * backend can work fine with 16-bit visuals in the same way it works - * with BGR visuals without any BGR formats in - * #cairo_format_t). - * - * Additionally, the support for the RGB16_565 format was never - * completely implemented. So while this format value is currently - * deprecated, it may eventually acquire complete support in the future. - */ -#define CAIRO_FORMAT_RGB16_565 4 - #define CAIRO_FONT_TYPE_ATSUI CAIRO_FONT_TYPE_QUARTZ /* Obsolete functions. These definitions exist to coerce the compiler diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index 099cacf..9b23800 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -86,8 +86,10 @@ _cairo_format_from_pixman_format (pixman_format_code_t pixman_format) return CAIRO_FORMAT_A8; case PIXMAN_a1: return CAIRO_FORMAT_A1; + case PIXMAN_r5g6b5: + return CAIRO_FORMAT_RGB16_565; case PIXMAN_a8b8g8r8: case PIXMAN_x8b8g8r8: case PIXMAN_r8g8b8: - case PIXMAN_b8g8r8: case PIXMAN_r5g6b5: case PIXMAN_b5g6r5: + case PIXMAN_b8g8r8: case PIXMAN_b5g6r5: case PIXMAN_a1r5g5b5: case PIXMAN_x1r5g5b5: case PIXMAN_a1b5g5r5: case PIXMAN_x1b5g5r5: case PIXMAN_a4r4g4b4: case PIXMAN_x4r4g4b4: case PIXMAN_a4b4g4r4: case PIXMAN_x4b4g4r4: case PIXMAN_r3g3b2: @@ -276,6 +278,9 @@ _cairo_format_to_pixman_format_code (cairo_format_t format) case CAIRO_FORMAT_RGB24: ret = PIXMAN_x8r8g8b8; break; + case CAIRO_FORMAT_RGB16_565: + ret = PIXMAN_r5g6b5; + break; case CAIRO_FORMAT_ARGB32: case CAIRO_FORMAT_INVALID: default: @@ -638,6 +643,8 @@ _cairo_content_from_format (cairo_format_t format) return CAIRO_CONTENT_COLOR_ALPHA; case CAIRO_FORMAT_RGB24: return CAIRO_CONTENT_COLOR; + case CAIRO_FORMAT_RGB16_565: + return CAIRO_CONTENT_COLOR; case CAIRO_FORMAT_A8: case CAIRO_FORMAT_A1: return CAIRO_CONTENT_ALPHA; @@ -657,6 +664,8 @@ _cairo_format_bits_per_pixel (cairo_format_t format) return 32; case CAIRO_FORMAT_RGB24: return 32; + case CAIRO_FORMAT_RGB16_565: + return 16; case CAIRO_FORMAT_A8: return 8; case CAIRO_FORMAT_A1: @@ -4426,6 +4435,11 @@ _cairo_image_analyze_transparency (cairo_image_surface_t *image) return image->transparency = CAIRO_IMAGE_HAS_ALPHA; } + if (image->format == CAIRO_FORMAT_RGB16_565) { + image->transparency = CAIRO_IMAGE_IS_OPAQUE; + return CAIRO_IMAGE_IS_OPAQUE; + } + if (image->format != CAIRO_FORMAT_ARGB32) return image->transparency = CAIRO_IMAGE_HAS_ALPHA; diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c index f9b9617..69b7c66 100644 --- a/src/cairo-xlib-display.c +++ b/src/cairo-xlib-display.c @@ -53,7 +53,7 @@ struct _cairo_xlib_display { int render_major; int render_minor; - XRenderPictFormat *cached_xrender_formats[CAIRO_FORMAT_A1 + 1]; + XRenderPictFormat *cached_xrender_formats[CAIRO_FORMAT_RGB16_565 + 1]; cairo_xlib_job_t *workqueue; cairo_freelist_t wq_freelist; @@ -591,14 +591,36 @@ _cairo_xlib_display_get_xrender_format (cairo_xlib_display_t *display, pict_format = PictStandardA8; break; case CAIRO_FORMAT_RGB24: pict_format = PictStandardRGB24; break; + case CAIRO_FORMAT_RGB16_565: { + Visual *visual = NULL; + Screen *screen = DefaultScreenOfDisplay(display->display); + int j; + for (j = 0; j < screen->ndepths; j++) { + Depth *d = &screen->depths[j]; + if (d->depth == 16 && d->nvisuals && &d->visuals[0]) { + if (d->visuals[0].red_mask == 0xf800 && + d->visuals[0].green_mask == 0x7e0 && + d->visuals[0].blue_mask == 0x1f) + visual = &d->visuals[0]; + break; + } + } + if (!visual) { + CAIRO_MUTEX_UNLOCK (display->mutex); + return NULL; + } + xrender_format = XRenderFindVisualFormat(display->display, visual); + break; + } case CAIRO_FORMAT_INVALID: default: ASSERT_NOT_REACHED; case CAIRO_FORMAT_ARGB32: pict_format = PictStandardARGB32; break; } - xrender_format = XRenderFindStandardFormat (display->display, - pict_format); + if (!xrender_format) + xrender_format = XRenderFindStandardFormat (display->display, + pict_format); display->cached_xrender_formats[format] = xrender_format; } CAIRO_MUTEX_UNLOCK (display->mutex); diff --git a/src/cairo.h b/src/cairo.h index feb564a..6c4faea 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -2277,11 +2277,8 @@ typedef enum _cairo_format { CAIRO_FORMAT_ARGB32 = 0, CAIRO_FORMAT_RGB24 = 1, CAIRO_FORMAT_A8 = 2, - CAIRO_FORMAT_A1 = 3 - /* The value of 4 is reserved by a deprecated enum value. - * The next format added must have an explicit value of 5. - CAIRO_FORMAT_RGB16_565 = 4, - */ + CAIRO_FORMAT_A1 = 3, + CAIRO_FORMAT_RGB16_565 = 4 } cairo_format_t; cairo_public cairo_surface_t * diff --git a/src/cairoint.h b/src/cairoint.h index 741ccf3..f39b9a1 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -2149,7 +2149,7 @@ _cairo_surface_has_device_transform (cairo_surface_t *surface) cairo_pure; * in cairo-xlib-surface.c--again see -Wswitch-enum). */ #define CAIRO_FORMAT_VALID(format) ((format) >= CAIRO_FORMAT_ARGB32 && \ - (format) <= CAIRO_FORMAT_A1) + (format) <= CAIRO_FORMAT_RGB16_565) /* pixman-required stride alignment in bytes. */ #define CAIRO_STRIDE_ALIGNMENT (sizeof (uint32_t))