surface: Make map_to_image return cairo_image_surface_t*

This makes it easier to check that the funciton is returning the
correct type of surfaces.
This commit is contained in:
Andrea Canciani 2012-04-10 20:15:04 +02:00
parent 10c0a1c68c
commit df7829e2cc
17 changed files with 51 additions and 39 deletions

View file

@ -40,7 +40,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-fallback-private.h"
@ -171,7 +171,7 @@ _cairo_dfb_surface_finish (void *abstract_surface)
return _cairo_image_surface_finish (abstract_surface);
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_dfb_surface_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{
@ -184,7 +184,7 @@ _cairo_dfb_surface_map_to_image (void *abstract_surface,
int pitch;
if (buffer->Lock (buffer, DSLF_READ | DSLF_WRITE, &data, &pitch))
return _cairo_surface_create_in_error(_cairo_error (CAIRO_STATUS_NO_MEMORY));
return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
image = pixman_image_create_bits (surface->image.pixman_format,
surface->image.width,
@ -192,19 +192,20 @@ _cairo_dfb_surface_map_to_image (void *abstract_surface,
data, pitch);
if (image == NULL) {
buffer->Unlock (buffer);
return _cairo_surface_create_in_error(_cairo_error (CAIRO_STATUS_NO_MEMORY));
return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
}
_cairo_image_surface_init (&surface->image, image, surface->image.pixman_format);
}
return _cairo_image_surface_map_to_image (&surface->image, extents);
return _cairo_surface_map_to_image (&surface->image.base, extents);
}
static cairo_int_status_t
_cairo_dfb_surface_unmap_image (void *abstract_surface,
cairo_image_surface_t *image)
{
return CAIRO_INT_STATUS_SUCCESS;
cairo_dfb_surface_t *surface = abstract_surface;
return _cairo_surface_unmap_image (&surface->image.base, image);
}
static cairo_status_t

View file

@ -46,7 +46,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-surface-backend-private.h"
static const cairo_surface_backend_t _cairo_gl_surface_backend;
@ -985,7 +985,7 @@ _cairo_gl_surface_finish (void *abstract_surface)
return _cairo_gl_context_release (ctx, status);
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_gl_surface_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{
@ -1050,15 +1050,15 @@ _cairo_gl_surface_map_to_image (void *abstract_surface,
extents->height,
-1);
if (unlikely (image->base.status))
return &image->base;
return image;
if (surface->base.serial == 0)
return &image->base;
return image;
status = _cairo_gl_context_acquire (surface->base.device, &ctx);
if (unlikely (status)) {
cairo_surface_destroy (&image->base);
return _cairo_surface_create_in_error (status);
return _cairo_image_surface_create_in_error (status);
}
cairo_surface_set_device_offset (&image->base, -extents->x, -extents->y);
@ -1092,7 +1092,7 @@ _cairo_gl_surface_map_to_image (void *abstract_surface,
status = _cairo_gl_context_release (ctx, status);
if (unlikely (status)) {
cairo_surface_destroy (&image->base);
return _cairo_surface_create_in_error (status);
return _cairo_image_surface_create_in_error (status);
}
/* We must invert the image manualy if we lack GL_MESA_pack_invert */
@ -1105,7 +1105,7 @@ _cairo_gl_surface_map_to_image (void *abstract_surface,
row = malloc (image->stride);
if (unlikely (row == NULL)) {
cairo_surface_destroy (&image->base);
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
}
}
@ -1121,7 +1121,7 @@ _cairo_gl_surface_map_to_image (void *abstract_surface,
free(row);
}
return &image->base;
return image;
}
static cairo_surface_t *

View file

@ -42,6 +42,12 @@
CAIRO_BEGIN_DECLS
static inline cairo_image_surface_t *
_cairo_image_surface_create_in_error (cairo_status_t status)
{
return (cairo_image_surface_t *) _cairo_surface_create_in_error (status);
}
static inline void
_cairo_image_surface_set_parent (cairo_image_surface_t *image,
cairo_surface_t *parent)

View file

@ -151,7 +151,7 @@ _cairo_image_surface_init (cairo_image_surface_t *surface,
pixman_image_t *pixman_image,
pixman_format_code_t pixman_format);
cairo_private cairo_surface_t *
cairo_private cairo_image_surface_t *
_cairo_image_surface_map_to_image (void *abstract_other,
const cairo_rectangle_int_t *extents);

View file

@ -794,7 +794,7 @@ _cairo_image_surface_snapshot (void *abstract_surface)
return &clone->base;
}
cairo_surface_t *
cairo_image_surface_t *
_cairo_image_surface_map_to_image (void *abstract_other,
const cairo_rectangle_int_t *extents)
{
@ -814,7 +814,7 @@ _cairo_image_surface_map_to_image (void *abstract_other,
other->stride);
cairo_surface_set_device_offset (surface, -extents->x, -extents->y);
return surface;
return (cairo_image_surface_t *) surface;
}
cairo_int_status_t

View file

@ -585,7 +585,7 @@ _cairo_os2_surface_release_source_image (void *abstract_surface
DosReleaseMutexSem (surface->hmtx_use_private_fields);
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_os2_surface_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{

View file

@ -107,7 +107,7 @@ _cairo_quartz_image_surface_acquire_source_image (void *asurface,
return CAIRO_STATUS_SUCCESS;
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_quartz_image_surface_map_to_image (void *asurface,
const cairo_rectangle_int_t *extents)
{

View file

@ -1553,7 +1553,7 @@ _cairo_quartz_surface_release_source_image (void *abstract_surface,
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_quartz_surface_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{

View file

@ -63,7 +63,7 @@ struct _cairo_surface_backend {
int width,
int height);
cairo_surface_t *
cairo_image_surface_t *
(*map_to_image) (void *surface,
const cairo_rectangle_int_t *extents);
cairo_int_status_t

View file

@ -474,7 +474,7 @@ _cairo_surface_observer_create_similar_image (void *other,
return NULL;
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_surface_observer_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{

View file

@ -84,7 +84,7 @@ _cairo_surface_subsurface_create_similar_image (void *other,
width, height);
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_surface_subsurface_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{

View file

@ -638,7 +638,7 @@ _cairo_surface_map_to_image (cairo_surface_t *surface,
/* TODO: require map_to_image != NULL */
if (surface->backend->map_to_image)
image = (cairo_image_surface_t *) surface->backend->map_to_image (surface, extents);
image = surface->backend->map_to_image (surface, extents);
if (image == NULL)
image = _cairo_image_surface_clone_subimage (surface, extents);

View file

@ -45,8 +45,8 @@
#include "cairo-composite-rectangles-private.h"
#include "cairo-default-context-private.h"
#include "cairo-image-surface-inline.h"
#include "cairo-list-inline.h"
#include "cairo-image-surface-private.h"
#include "cairo-surface-backend-private.h"
#if CAIRO_HAS_XLIB_XCB_FUNCTIONS
@ -755,12 +755,13 @@ _cairo_xcb_surface_flush (void *abstract_surface)
return status;
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_xcb_surface_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{
cairo_xcb_surface_t *surface = abstract_surface;
cairo_surface_t *image;
cairo_status_t status;
if (surface->fallback)
return surface->fallback->base.backend->map_to_image (&surface->fallback->base, extents);
@ -768,8 +769,11 @@ _cairo_xcb_surface_map_to_image (void *abstract_surface,
image = _get_image (surface, TRUE,
extents->x, extents->y,
extents->width, extents->height);
if (unlikely (image->status))
return image;
status = cairo_surface_status (image);
if (unlikely (status)) {
cairo_surface_destroy(image);
return _cairo_image_surface_create_in_error (status);
}
/* Do we have a deferred clear and this image surface does NOT cover the
* whole xcb surface? Have to apply the clear in that case, else
@ -778,16 +782,16 @@ _cairo_xcb_surface_map_to_image (void *abstract_surface,
if (surface->deferred_clear &&
! (extents->width == surface->width &&
extents->height == surface->height)) {
cairo_status_t status = _cairo_xcb_surface_clear (surface);
status = _cairo_xcb_surface_clear (surface);
if (unlikely (status)) {
cairo_surface_destroy(image);
return _cairo_surface_create_in_error (status);
return _cairo_image_surface_create_in_error (status);
}
}
surface->deferred_clear = FALSE;
cairo_surface_set_device_offset (image, -extents->x, -extents->y);
return image;
return (cairo_image_surface_t *) image;
}
static cairo_int_status_t

View file

@ -1278,7 +1278,7 @@ _cairo_xlib_surface_release_source_image (void *abstract_surfa
cairo_surface_destroy (&image->base);
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_xlib_surface_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{
@ -1287,7 +1287,7 @@ _cairo_xlib_surface_map_to_image (void *abstract_surface,
image = _get_image_surface (abstract_surface, extents);
cairo_surface_set_device_offset (image, -extents->x, -extents->y);
return image;
return (cairo_image_surface_t *) image;
}
static cairo_int_status_t

View file

@ -116,7 +116,7 @@ _cairo_xlib_xcb_surface_create_similar_image (void *abstract_other,
return cairo_surface_create_similar_image (&surface->xcb->base, format, width, height);
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_xlib_xcb_surface_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{

View file

@ -90,7 +90,7 @@ _cairo_skia_surface_finish (void *asurface)
return CAIRO_STATUS_SUCCESS;
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_skia_surface_map_to_image (void *asurface,
const cairo_rectangle_int_t *extents)
{
@ -98,6 +98,7 @@ _cairo_skia_surface_map_to_image (void *asurface,
surface->bitmap->lockPixels ();
/* XXX: Broken! */
if (extents->width < surface->image.width ||
extents->height < surface->image.height)
{

View file

@ -427,7 +427,7 @@ _cairo_win32_display_surface_finish (void *abstract_surface)
return CAIRO_STATUS_SUCCESS;
}
static cairo_surface_t *
static cairo_image_surface_t *
_cairo_win32_display_surface_map_to_image (void *abstract_surface,
const cairo_rectangle_int_t *extents)
{
@ -464,13 +464,13 @@ _cairo_win32_display_surface_map_to_image (void *abstract_sur
surface = to_win32_display_surface (surface->fallback);
done:
GdiFlush();
return _cairo_image_surface_map_to_image (surface->image, extents);
return _cairo_surface_map_to_image (&surface->image->base, extents);
err:
cairo_surface_destroy (surface->fallback);
surface->fallback = NULL;
return _cairo_surface_create_in_error (status);
return _cairo_image_surface_create_in_error (status);
}
static cairo_int_status_t
@ -499,7 +499,7 @@ _cairo_win32_display_surface_unmap_image (void *abstract_surf
_cairo_damage_add_rectangle (surface->fallback->damage, &r);
}
return CAIRO_INT_STATUS_SUCCESS;
return _cairo_surface_unmap_image (&surface->image->base, image);
}
static cairo_status_t