Commit 2061cd81 authored by Chris Wilson's avatar Chris Wilson 🤔
Browse files

Replace the ad-hoc surface unwrappers with a function pointer


Signed-off-by: Chris Wilson's avatarChris Wilson <chris@chris-wilson.co.uk>
parent 7c34997a
......@@ -702,6 +702,7 @@ static const cairo_surface_backend_t cairo_analysis_surface_backend = {
NULL, /* map_to_image */
NULL, /* unmap */
NULL, /* source */
NULL, /* acquire_source_image */
NULL, /* release_source_image */
NULL, /* snapshot */
......@@ -895,6 +896,7 @@ static const cairo_surface_backend_t cairo_null_surface_backend = {
NULL, /* map to image */
NULL, /* unmap image*/
NULL, /* source */
NULL, /* acquire_source_image */
NULL, /* release_source_image */
NULL, /* snapshot */
......
......@@ -2463,6 +2463,7 @@ const cairo_surface_backend_t _cairo_cogl_surface_backend = {
NULL, /* map to image */
NULL, /* unmap image */
_cairo_surface_default_source,
_cairo_cogl_surface_acquire_source_image,
_cairo_cogl_surface_release_source_image,
NULL, /* snapshot */
......
......@@ -1835,6 +1835,7 @@ _cairo_directfb_surface_backend = {
NULL, /* map to image */
NULL, /* unmap image */
_cairo_surface_default_source,
_cairo_directfb_surface_acquire_source_image,/*acquire_source_image*/
_cairo_directfb_surface_release_source_image,/*release_source_image*/
_cairo_directfb_surface_acquire_dest_image,/*acquire_dest_image*/
......
......@@ -1078,6 +1078,19 @@ _cairo_gl_surface_map_to_image (void *abstract_surface,
return &image->base;
}
static cairo_surface_t *
_cairo_gl_surface_source (void *abstract_surface,
cairo_rectangle_int_t *extents)
{
cairo_gl_surface_t *surface = abstract_surface;
extents->x = extents->y = 0;
extents->width = surface->width;
extents->height = surface->height;
return &surface->base;
}
static cairo_status_t
_cairo_gl_surface_acquire_source_image (void *abstract_surface,
cairo_image_surface_t **image_out,
......@@ -1249,6 +1262,7 @@ static const cairo_surface_backend_t _cairo_gl_surface_backend = {
_cairo_gl_surface_map_to_image,
_cairo_gl_surface_unmap_image,
_cairo_gl_surface_source,
_cairo_gl_surface_acquire_source_image,
_cairo_gl_surface_release_source_image,
NULL, /* snapshot */
......
......@@ -609,15 +609,9 @@ _pixman_image_for_recording (cairo_image_surface_t *dst,
*ix = *iy = 0;
source = pattern->surface;
if (_cairo_surface_is_subsurface (source))
source = _cairo_surface_subsurface_get_target_with_offset (source, &tx, &ty);
if (_cairo_surface_is_snapshot (source))
source = _cairo_surface_snapshot_get_target (source);
if (_cairo_surface_is_observer (source))
source = _cairo_surface_observer_get_target (source);
if (_cairo_surface_is_paginated (source))
source = _cairo_paginated_surface_get_target (source);
source = _cairo_pattern_get_source (pattern, &limit);
tx = limit.x;
ty = limit.y;
extend = pattern->base.extend;
if (_cairo_surface_get_extents (source, &limit)) {
......
......@@ -97,6 +97,11 @@ _cairo_image_surface_map_to_image (void *abstract_other,
cairo_private cairo_int_status_t
_cairo_image_surface_unmap_image (void *abstract_surface,
cairo_image_surface_t *image);
cairo_private cairo_surface_t *
_cairo_image_surface_source (void *abstract_surface,
cairo_rectangle_int_t *extents);
cairo_private cairo_status_t
_cairo_image_surface_acquire_source_image (void *abstract_surface,
cairo_image_surface_t **image_out,
......
......@@ -819,6 +819,19 @@ _cairo_image_surface_assume_ownership_of_data (cairo_image_surface_t *surface)
surface->owns_data = TRUE;
}
cairo_surface_t *
_cairo_image_surface_source (void *abstract_surface,
cairo_rectangle_int_t *extents)
{
cairo_image_surface_t *surface = abstract_surface;
extents->x = extents->y = 0;
extents->width = surface->width;
extents->height = surface->height;
return &surface->base;
}
cairo_status_t
_cairo_image_surface_acquire_source_image (void *abstract_surface,
cairo_image_surface_t **image_out,
......@@ -948,6 +961,7 @@ const cairo_surface_backend_t _cairo_image_surface_backend = {
_cairo_image_surface_map_to_image,
_cairo_image_surface_unmap_image,
_cairo_image_surface_source,
_cairo_image_surface_acquire_source_image,
_cairo_image_surface_release_source_image,
_cairo_image_surface_snapshot,
......
......@@ -778,39 +778,30 @@ upload_boxes (const cairo_mask_compositor_t *compositor,
{
cairo_surface_t *dst = extents->surface;
const cairo_pattern_t *source = &extents->source_pattern.base;
const cairo_surface_pattern_t *pattern;
cairo_surface_t *src;
cairo_rectangle_int_t limit;
cairo_int_status_t status;
int tx, ty;
pattern = (const cairo_surface_pattern_t *) source;
src = pattern->surface;
src = _cairo_pattern_get_source ((cairo_surface_pattern_t *)source, &limit);
if (!(src->type == CAIRO_SURFACE_TYPE_IMAGE || src->type == dst->type))
return CAIRO_INT_STATUS_UNSUPPORTED;
if (! _cairo_matrix_is_integer_translation (&source->matrix, &tx, &ty))
return CAIRO_INT_STATUS_UNSUPPORTED;
if (_cairo_surface_is_snapshot (src))
src = _cairo_surface_snapshot_get_target (src);
if (_cairo_surface_is_observer (src))
src = _cairo_surface_observer_get_target (src);
if (_cairo_surface_is_subsurface (src)) {
_cairo_surface_subsurface_offset (src, &tx, &ty);
src = _cairo_surface_subsurface_get_target (src);
}
/* Check that the data is entirely within the image */
if (extents->bounded.x + tx < 0 || extents->bounded.y + ty < 0)
if (extents->bounded.x + tx < limit.x || extents->bounded.y + ty < limit.y)
return CAIRO_INT_STATUS_UNSUPPORTED;
_cairo_surface_get_extents (pattern->surface, &limit);
if (extents->bounded.x + extents->bounded.width + tx > limit.width ||
extents->bounded.y + extents->bounded.height + ty > limit.height)
if (extents->bounded.x + extents->bounded.width + tx > limit.x + limit.width ||
extents->bounded.y + extents->bounded.height + ty > limit.y + limit.height)
return CAIRO_INT_STATUS_UNSUPPORTED;
if (pattern->surface->type == CAIRO_SURFACE_TYPE_IMAGE)
tx += limit.x;
ty += limit.y;
if (src->type == CAIRO_SURFACE_TYPE_IMAGE)
status = compositor->draw_image_boxes (dst,
(cairo_image_surface_t *)src,
boxes, tx, ty);
......
......@@ -1394,6 +1394,7 @@ static const cairo_surface_backend_t cairo_os2_surface_backend = {
_cairo_os2_surface_map_to_image,
_cairo_os2_surface_unmap_image,
_cairo_surface_default_source,
_cairo_os2_surface_acquire_source_image,
_cairo_os2_surface_release_source_image,
NULL, /* snapshot */
......
......@@ -242,6 +242,14 @@ _cairo_paginated_surface_create_image_surface (void *abstract_surface,
return image;
}
static cairo_surface_t *
_cairo_paginated_surface_source (void *abstract_surface,
cairo_rectangle_int_t *extents)
{
cairo_paginated_surface_t *surface = abstract_surface;
return _cairo_surface_get_source (surface->target, extents);
}
static cairo_status_t
_cairo_paginated_surface_acquire_source_image (void *abstract_surface,
cairo_image_surface_t **image_out,
......@@ -682,6 +690,7 @@ static const cairo_surface_backend_t cairo_paginated_surface_backend = {
NULL, /* map to image */
NULL, /* unmap image */
_cairo_paginated_surface_source,
_cairo_paginated_surface_acquire_source_image,
_cairo_paginated_surface_release_source_image,
_cairo_paginated_surface_snapshot,
......
......@@ -39,6 +39,7 @@
#include "cairo-error-private.h"
#include "cairo-types-private.h"
#include "cairo-list-private.h"
#include "cairo-surface-private.h"
#include <stdio.h> /* FILE* */
......@@ -370,6 +371,13 @@ _cairo_raster_source_pattern_finish (cairo_pattern_t *abstract_pattern);
cairo_private void
_cairo_debug_print_pattern (FILE *file, const cairo_pattern_t *pattern);
static inline cairo_surface_t *
_cairo_pattern_get_source (const cairo_surface_pattern_t *pattern,
cairo_rectangle_int_t *extents)
{
return _cairo_surface_get_source (pattern->surface, extents);
}
CAIRO_END_DECLS
#endif /* CAIRO_PATTERN_PRIVATE */
......
......@@ -7274,6 +7274,7 @@ static const cairo_surface_backend_t cairo_pdf_surface_backend = {
NULL, /* map to image */
NULL, /* unmap image */
_cairo_surface_default_source,
NULL, /* acquire_source_image */
NULL, /* release_source_image */
NULL, /* snapshot */
......
......@@ -4538,6 +4538,7 @@ static const cairo_surface_backend_t cairo_ps_surface_backend = {
NULL, /* map to image */
NULL, /* unmap image */
_cairo_surface_default_source,
NULL, /* acquire_source_image */
NULL, /* release_source_image */
NULL, /* snapshot */
......
......@@ -1561,6 +1561,7 @@ static const cairo_surface_backend_t cairo_qt_surface_backend = {
NULL, /* map to image */
NULL, /* unmap image */
_cairo_surface_default_source,
_cairo_qt_surface_acquire_source_image,
_cairo_qt_surface_release_source_image,
_cairo_qt_surface_acquire_dest_image,
......
......@@ -260,6 +260,7 @@ static const cairo_surface_backend_t cairo_quartz_image_surface_backend = {
_cairo_quartz_image_surface_map_to_image,
_cairo_quartz_image_surface_unmap_image,
_cairo_surface_default_source,
_cairo_quartz_image_surface_acquire_source_image,
NULL, /* release_source_image */
NULL, /* snapshot */
......
......@@ -535,6 +535,7 @@ static const cairo_surface_backend_t proxy_backend = {
NULL, /* map to image */
NULL, /* unmap image */
_cairo_surface_default_source,
proxy_acquire_source_image,
proxy_release_source_image,
};
......@@ -1135,6 +1136,7 @@ static const cairo_surface_backend_t cairo_recording_surface_backend = {
NULL, /* map to image */
NULL, /* unmap image */
_cairo_surface_default_source,
_cairo_recording_surface_acquire_source_image,
_cairo_recording_surface_release_source_image,
_cairo_recording_surface_snapshot,
......
......@@ -2090,6 +2090,19 @@ _device_destroy (void *abstract_device)
free (ctx);
}
static cairo_surface_t *
_cairo_script_surface_source (void *abstract_surface,
cairo_rectangle_int_t *extents)
{
cairo_script_surface_t *surface = abstract_surface;
extents->x = extents->y = 0;
extents->width = surface->width;
extents->height = surface->height;
return &surface->base;
}
static cairo_status_t
_cairo_script_surface_acquire_source_image (void *abstract_surface,
cairo_image_surface_t **image_out,
......@@ -3557,6 +3570,7 @@ _cairo_script_surface_backend = {
NULL, /* map to image */
NULL, /* unmap image */
_cairo_script_surface_source,
_cairo_script_surface_acquire_source_image,
_cairo_script_surface_release_source_image,
_cairo_script_surface_snapshot,
......
......@@ -379,18 +379,12 @@ error:
}
static cairo_surface_t *
unwrap_surface (const cairo_pattern_t *pattern)
unwrap_source (const cairo_pattern_t *pattern)
{
cairo_surface_t *surface;
cairo_rectangle_int_t limit;
surface = ((const cairo_surface_pattern_t *) pattern)->surface;
if (_cairo_surface_is_paginated (surface))
surface = _cairo_paginated_surface_get_recording (surface);
if (_cairo_surface_is_snapshot (surface))
surface = _cairo_surface_snapshot_get_target (surface);
if (_cairo_surface_is_observer (surface))
surface = _cairo_surface_observer_get_target (surface);
return surface;
return _cairo_pattern_get_source ((cairo_surface_pattern_t *)pattern,
&limit);
}
static cairo_bool_t
......@@ -417,7 +411,7 @@ recording_pattern_contains_sample (const cairo_pattern_t *pattern,
if (pattern->extend == CAIRO_EXTEND_NONE)
return TRUE;
surface = (cairo_recording_surface_t *) unwrap_surface (pattern);
surface = (cairo_recording_surface_t *) unwrap_source (pattern);
if (surface->unbounded)
return TRUE;
......@@ -482,7 +476,7 @@ composite_aligned_boxes (const cairo_spans_compositor_t *compositor,
boxes);
recording_clip = _cairo_clip_from_boxes (boxes);
status = _cairo_recording_surface_replay_with_clip (unwrap_surface (source),
status = _cairo_recording_surface_replay_with_clip (unwrap_source (source),
&source->matrix,
dst, recording_clip);
_cairo_clip_destroy (recording_clip);
......
......@@ -70,6 +70,10 @@ struct _cairo_surface_backend {
(*unmap_image) (void *surface,
cairo_image_surface_t *image);
cairo_surface_t *
(*source) (void *abstract_surface,
cairo_rectangle_int_t *extents);
cairo_warn cairo_status_t
(*acquire_source_image) (void *abstract_surface,
cairo_image_surface_t **image_out,
......@@ -197,6 +201,10 @@ struct _cairo_surface_backend {
(*get_supported_mime_types) (void *surface);
};
cairo_private cairo_surface_t *
_cairo_surface_default_source (void *surface,
cairo_rectangle_int_t *extents);
CAIRO_END_DECLS
#endif /* CAIRO_SURFACE_BACKEND_PRIVATE_H */
......@@ -1276,6 +1276,14 @@ _cairo_surface_observer_get_font_options (void *abstract_surface,
surface->target->backend->get_font_options (surface->target, options);
}
static cairo_surface_t *
_cairo_surface_observer_source (void *abstract_surface,
cairo_rectangle_int_t *extents)
{
cairo_surface_observer_t *surface = abstract_surface;
return _cairo_surface_get_source (surface->target, extents);
}
static cairo_status_t
_cairo_surface_observer_acquire_source_image (void *abstract_surface,
cairo_image_surface_t **image_out,
......@@ -1339,6 +1347,7 @@ static const cairo_surface_backend_t _cairo_surface_observer_backend = {
_cairo_surface_observer_map_to_image,
_cairo_surface_observer_unmap_image,
_cairo_surface_observer_source,
_cairo_surface_observer_acquire_source_image,
_cairo_surface_observer_release_source_image,
_cairo_surface_observer_snapshot,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment