diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2023-01-01 15:14:08 +1030 |
---|---|---|
committer | Adrian Johnson <ajohnson@redneon.com> | 2023-01-15 19:29:28 +1030 |
commit | 7146358250975ec0f29b8ba80e80a26c52526bdc (patch) | |
tree | e37c45b2f6c4523aab202b331a4094949b189040 /src/cairo-paginated-surface.c | |
parent | a2b376ed787fc35270421730863411a0c047f564 (diff) | |
download | cairo-7146358250975ec0f29b8ba80e80a26c52526bdc.tar.gz |
Fix shared use of recording surface with paginated targets
The problem is _cairo_recording_surface_replay_and_create_regions()
stores the cairo_recording_region_type_t in the same structure as the
recording commands. This does not work well when the recording surface
is used as source by multiple surfaces
Fix this by moving the cairo_recording_region_type_t into a separate
struct cairo_recording_regions_array_t. This struct is stored in a
list that allows multiple create regions results to be store in the
surface.
The new function _cairo_recording_surface_region_array_attach() is
used to create a new cairo_recording_regions_array_t, attach it to the
recording surface and return a unique region id.
The _cairo_recording_surface_replay_and_create_regions() and
_cairo_recording_surface_replay_region() functions use this region id
to identify the cairo_recording_regions_array_t.
To handle nested recording surfaces, when replaying a recording, the
region id is passed to the target as an extra parameter in the surface
pattern. The wrapper surface makes a temporary copy of the pattern to
ensure the snapshot pattern in the recording surface is not modified.
cairo_recording_regions_array_t has a reference count so the target
can hold on to the cairo_recording_regions_array_t after the paginated
surface has called _cairo_recording_surface_region_array_remove().
Diffstat (limited to 'src/cairo-paginated-surface.c')
-rw-r--r-- | src/cairo-paginated-surface.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c index 07d86d070..278c1a641 100644 --- a/src/cairo-paginated-surface.c +++ b/src/cairo-paginated-surface.c @@ -1,3 +1,4 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ /* cairo - a vector graphics library with display and print output * * Copyright © 2005 Red Hat, Inc @@ -401,11 +402,12 @@ _paint_page (cairo_paginated_surface_t *surface) cairo_surface_t *analysis; cairo_int_status_t status; cairo_bool_t has_supported, has_page_fallback, has_finegrained_fallback; + unsigned int regions_id = 0; if (unlikely (surface->target->status)) return surface->target->status; - analysis = _cairo_analysis_surface_create (surface->target); + analysis = _cairo_analysis_surface_create (surface->target, TRUE); if (unlikely (analysis->status)) return _cairo_surface_set_error (surface->target, analysis->status); @@ -414,21 +416,26 @@ _paint_page (cairo_paginated_surface_t *surface) if (unlikely (status)) goto FAIL; + status = _cairo_recording_surface_region_array_attach (surface->recording_surface, ®ions_id); + if (status) + goto FAIL; + status = _cairo_recording_surface_replay_and_create_regions (surface->recording_surface, + regions_id, NULL, analysis, FALSE); if (status) goto FAIL; assert (analysis->status == CAIRO_STATUS_SUCCESS); - if (surface->backend->set_bounding_box) { - cairo_box_t bbox; + if (surface->backend->set_bounding_box) { + cairo_box_t bbox; - _cairo_analysis_surface_get_bounding_box (analysis, &bbox); - status = surface->backend->set_bounding_box (surface->target, &bbox); - if (unlikely (status)) - goto FAIL; - } + _cairo_analysis_surface_get_bounding_box (analysis, &bbox); + status = surface->backend->set_bounding_box (surface->target, &bbox); + if (unlikely (status)) + goto FAIL; + } if (surface->backend->set_fallback_images_required) { cairo_bool_t has_fallbacks = _cairo_analysis_surface_has_unsupported (analysis); @@ -467,6 +474,7 @@ _paint_page (cairo_paginated_surface_t *surface) goto FAIL; status = _cairo_recording_surface_replay_region (surface->recording_surface, + regions_id, NULL, surface->target, CAIRO_RECORDING_REGION_NATIVE); @@ -525,6 +533,9 @@ _paint_page (cairo_paginated_surface_t *surface) } FAIL: + if (regions_id) + _cairo_recording_surface_region_array_remove (surface->recording_surface, regions_id); + cairo_surface_destroy (analysis); return _cairo_surface_set_error (surface->target, status); |