mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-11 02:50:16 +01:00
quartz: Provide a valid implementation of map_to_image
and reuse it to implement acquire_source. Fixes cairo-quartz-surface.c: In function '_cairo_quartz_surface_map_to_image': cairo-quartz-surface.c:1568: warning: return from incompatible pointer type cairo-quartz-surface.c:1576: warning: return from incompatible pointer type
This commit is contained in:
parent
a8a4a8dfd4
commit
fc33cc3c3a
1 changed files with 74 additions and 135 deletions
|
|
@ -43,7 +43,7 @@
|
|||
#include "cairo-compositor-private.h"
|
||||
#include "cairo-default-context-private.h"
|
||||
#include "cairo-error-private.h"
|
||||
#include "cairo-image-surface-private.h"
|
||||
#include "cairo-image-surface-inline.h"
|
||||
#include "cairo-pattern-private.h"
|
||||
#include "cairo-surface-backend-private.h"
|
||||
#include "cairo-surface-clipper-private.h"
|
||||
|
|
@ -1386,96 +1386,82 @@ _cairo_quartz_draw_source (cairo_quartz_drawing_state_t *state,
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* get source/dest image implementation
|
||||
*/
|
||||
|
||||
/* Read the image from the surface's front buffer */
|
||||
static cairo_int_status_t
|
||||
_cairo_quartz_get_image (cairo_quartz_surface_t *surface,
|
||||
cairo_image_surface_t **image_out)
|
||||
static cairo_image_surface_t *
|
||||
_cairo_quartz_surface_map_to_image (void *abstract_surface,
|
||||
const cairo_rectangle_int_t *extents)
|
||||
{
|
||||
unsigned char *imageData;
|
||||
cairo_image_surface_t *isurf;
|
||||
cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
|
||||
unsigned int stride, bitinfo, bpp, color_comps;
|
||||
CGColorSpaceRef colorspace;
|
||||
void *imageData;
|
||||
cairo_format_t format;
|
||||
|
||||
if (IS_EMPTY (surface)) {
|
||||
*image_out = (cairo_image_surface_t*) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
if (surface->imageSurfaceEquiv)
|
||||
return _cairo_surface_map_to_image (surface->imageSurfaceEquiv, extents);
|
||||
|
||||
if (IS_EMPTY (surface))
|
||||
return (cairo_image_surface_t *) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);
|
||||
|
||||
if (! _cairo_quartz_is_cgcontext_bitmap_context (surface->cgContext))
|
||||
return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
|
||||
|
||||
bitinfo = CGBitmapContextGetBitmapInfo (surface->cgContext);
|
||||
bpp = CGBitmapContextGetBitsPerPixel (surface->cgContext);
|
||||
|
||||
// let's hope they don't add YUV under us
|
||||
colorspace = CGBitmapContextGetColorSpace (surface->cgContext);
|
||||
color_comps = CGColorSpaceGetNumberOfComponents (colorspace);
|
||||
|
||||
/* XXX TODO: We can handle many more data formats by
|
||||
* converting to pixman_format_t */
|
||||
|
||||
if (bpp == 32 && color_comps == 3 &&
|
||||
(bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst &&
|
||||
(bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host)
|
||||
{
|
||||
format = CAIRO_FORMAT_ARGB32;
|
||||
}
|
||||
else if (bpp == 32 && color_comps == 3 &&
|
||||
(bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaNoneSkipFirst &&
|
||||
(bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host)
|
||||
{
|
||||
format = CAIRO_FORMAT_RGB24;
|
||||
}
|
||||
else if (bpp == 8 && color_comps == 1)
|
||||
{
|
||||
format = CAIRO_FORMAT_A1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
|
||||
}
|
||||
|
||||
if (surface->imageSurfaceEquiv) {
|
||||
*image_out = (cairo_image_surface_t*) cairo_surface_reference (surface->imageSurfaceEquiv);
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
imageData = CGBitmapContextGetData (surface->cgContext);
|
||||
stride = CGBitmapContextGetBytesPerRow (surface->cgContext);
|
||||
|
||||
if (_cairo_quartz_is_cgcontext_bitmap_context (surface->cgContext)) {
|
||||
unsigned int stride;
|
||||
unsigned int bitinfo;
|
||||
unsigned int bpc, bpp;
|
||||
CGColorSpaceRef colorspace;
|
||||
unsigned int color_comps;
|
||||
return (cairo_image_surface_t *) cairo_image_surface_create_for_data (imageData,
|
||||
format,
|
||||
extents->width,
|
||||
extents->height,
|
||||
stride);
|
||||
}
|
||||
|
||||
imageData = (unsigned char *) CGBitmapContextGetData (surface->cgContext);
|
||||
static cairo_int_status_t
|
||||
_cairo_quartz_surface_unmap_image (void *abstract_surface,
|
||||
cairo_image_surface_t *image)
|
||||
{
|
||||
cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
|
||||
|
||||
bitinfo = CGBitmapContextGetBitmapInfo (surface->cgContext);
|
||||
stride = CGBitmapContextGetBytesPerRow (surface->cgContext);
|
||||
bpp = CGBitmapContextGetBitsPerPixel (surface->cgContext);
|
||||
bpc = CGBitmapContextGetBitsPerComponent (surface->cgContext);
|
||||
if (surface->imageSurfaceEquiv)
|
||||
return _cairo_surface_unmap_image (surface->imageSurfaceEquiv, image);
|
||||
|
||||
// let's hope they don't add YUV under us
|
||||
colorspace = CGBitmapContextGetColorSpace (surface->cgContext);
|
||||
color_comps = CGColorSpaceGetNumberOfComponents (colorspace);
|
||||
cairo_surface_finish (&image->base);
|
||||
cairo_surface_destroy (&image->base);
|
||||
|
||||
// XXX TODO: We can handle all of these by converting to
|
||||
// pixman masks, including non-native-endian masks
|
||||
if (bpc != 8)
|
||||
return CAIRO_INT_STATUS_UNSUPPORTED;
|
||||
|
||||
if (bpp != 32 && bpp != 8)
|
||||
return CAIRO_INT_STATUS_UNSUPPORTED;
|
||||
|
||||
if (color_comps != 3 && color_comps != 1)
|
||||
return CAIRO_INT_STATUS_UNSUPPORTED;
|
||||
|
||||
if (bpp == 32 && color_comps == 3 &&
|
||||
(bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst &&
|
||||
(bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host)
|
||||
{
|
||||
isurf = (cairo_image_surface_t *)
|
||||
cairo_image_surface_create_for_data (imageData,
|
||||
CAIRO_FORMAT_ARGB32,
|
||||
surface->extents.width,
|
||||
surface->extents.height,
|
||||
stride);
|
||||
} else if (bpp == 32 && color_comps == 3 &&
|
||||
(bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaNoneSkipFirst &&
|
||||
(bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host)
|
||||
{
|
||||
isurf = (cairo_image_surface_t *)
|
||||
cairo_image_surface_create_for_data (imageData,
|
||||
CAIRO_FORMAT_RGB24,
|
||||
surface->extents.width,
|
||||
surface->extents.height,
|
||||
stride);
|
||||
} else if (bpp == 8 && color_comps == 1)
|
||||
{
|
||||
isurf = (cairo_image_surface_t *)
|
||||
cairo_image_surface_create_for_data (imageData,
|
||||
CAIRO_FORMAT_A8,
|
||||
surface->extents.width,
|
||||
surface->extents.height,
|
||||
stride);
|
||||
} else {
|
||||
return CAIRO_INT_STATUS_UNSUPPORTED;
|
||||
}
|
||||
} else {
|
||||
return CAIRO_INT_STATUS_UNSUPPORTED;
|
||||
}
|
||||
|
||||
*image_out = isurf;
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Cairo surface backend implementations
|
||||
*/
|
||||
|
|
@ -1514,75 +1500,28 @@ _cairo_quartz_surface_acquire_source_image (void *abstract_surface,
|
|||
cairo_image_surface_t **image_out,
|
||||
void **image_extra)
|
||||
{
|
||||
cairo_int_status_t status;
|
||||
cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
|
||||
|
||||
//ND ((stderr, "%p _cairo_quartz_surface_acquire_source_image\n", surface));
|
||||
|
||||
status = _cairo_quartz_get_image (surface, image_out);
|
||||
if (unlikely (status))
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
*image_extra = NULL;
|
||||
|
||||
*image_out = _cairo_quartz_surface_map_to_image (surface, &surface->extents);
|
||||
if (unlikely (cairo_surface_status(&(*image_out)->base))) {
|
||||
cairo_surface_destroy (&(*image_out)->base);
|
||||
*image_out = NULL;
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
}
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static cairo_surface_t *
|
||||
_cairo_quartz_surface_snapshot (void *abstract_surface)
|
||||
{
|
||||
cairo_int_status_t status;
|
||||
cairo_quartz_surface_t *surface = abstract_surface;
|
||||
cairo_image_surface_t *image;
|
||||
|
||||
if (surface->imageSurfaceEquiv)
|
||||
return NULL;
|
||||
|
||||
status = _cairo_quartz_get_image (surface, &image);
|
||||
if (unlikely (status))
|
||||
return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
return &image->base;
|
||||
}
|
||||
|
||||
static void
|
||||
_cairo_quartz_surface_release_source_image (void *abstract_surface,
|
||||
cairo_image_surface_t *image,
|
||||
void *image_extra)
|
||||
{
|
||||
cairo_surface_destroy (&image->base);
|
||||
}
|
||||
|
||||
|
||||
static cairo_image_surface_t *
|
||||
_cairo_quartz_surface_map_to_image (void *abstract_surface,
|
||||
const cairo_rectangle_int_t *extents)
|
||||
{
|
||||
cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
|
||||
cairo_image_surface_t *image;
|
||||
cairo_surface_t *subsurface;
|
||||
cairo_status_t status;
|
||||
|
||||
status = _cairo_quartz_get_image (surface, &image);
|
||||
if (unlikely (status))
|
||||
return _cairo_surface_create_in_error (status);
|
||||
|
||||
/* Is this legitimate? shouldn't it return an image surface? */
|
||||
/* XXX: BROKEN! */
|
||||
|
||||
subsurface = _cairo_surface_create_for_rectangle_int (&image->base, extents);
|
||||
cairo_surface_destroy (&image->base);
|
||||
|
||||
return subsurface;
|
||||
}
|
||||
|
||||
static cairo_int_status_t
|
||||
_cairo_quartz_surface_unmap_image (void *abstract_surface,
|
||||
cairo_image_surface_t *image)
|
||||
{
|
||||
cairo_surface_destroy (&image->base);
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
_cairo_quartz_surface_unmap_image (abstract_surface, image);
|
||||
}
|
||||
|
||||
static cairo_surface_t *
|
||||
|
|
@ -2221,7 +2160,7 @@ static const struct _cairo_surface_backend cairo_quartz_surface_backend = {
|
|||
_cairo_surface_default_source,
|
||||
_cairo_quartz_surface_acquire_source_image,
|
||||
_cairo_quartz_surface_release_source_image,
|
||||
_cairo_quartz_surface_snapshot,
|
||||
NULL, /* snapshot */
|
||||
|
||||
NULL, /* copy_page */
|
||||
NULL, /* show_page */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue