From 79420bf4df3b26bb2e774ddb46a7e695f8c00b1d Mon Sep 17 00:00:00 2001 From: Emanuele Aina Date: Tue, 16 Dec 2014 14:58:55 +0100 Subject: [PATCH] cairo-trace: Extract common helper for _surface_create_similar[_image]() After commit c1ac8db7e60b the cairo_surface_create_similar() and cairo_surface_create_similar_image() overrides diverged, with the latter not getting the bugfixes that have been applied to the first. This means that the cairo_surface_create_similar_image() override was still affected by off-by-one issues with its stack handling, pushing the reference surface one time too many on the stack with trace lines like the following one: s1 s1 //ARGB32 48 48 similar-image % s2 This greatly confused later commands when the script was replayed, causing traces for trivial GTK3 programs to be unplayable, usually yielding the following error: "invalid value (typically too big) for the size of the input (surface, pattern, etc.)" By coalescing the code to emit the trace line in a common helper based on _create_similar() the traces generated now work correctly even for complex GTK3 programs (eg. epiphany). Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=73580 Signed-off-by: Emanuele Aina --- util/cairo-trace/trace.c | 68 +++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c index 4d3482646695..edc6ce6604ca 100644 --- a/util/cairo-trace/trace.c +++ b/util/cairo-trace/trace.c @@ -3669,21 +3669,12 @@ cairo_pattern_create_raster_source (void *data, cairo_content_t content, int wid return ret; } -cairo_surface_t * -cairo_surface_create_similar (cairo_surface_t *other, - cairo_content_t content, - int width, int height) +static void +_emit_surface_create_similar (cairo_surface_t *other, cairo_surface_t *created, cairo_bool_t image, const char *format_or_content, int width, int height) { - cairo_surface_t *ret; - - _enter_trace (); - - ret = DLCALL (cairo_surface_create_similar, other, content, width, height); - - _emit_line_info (); if (other != NULL && _write_lock ()) { Object *other_obj = _get_object(SURFACE, other); - Object *new_obj = _create_surface (ret); + Object *new_obj = _create_surface (created); if (other_obj->operand != -1) { if (current_stack_depth == other_obj->operand + 1) @@ -3696,10 +3687,16 @@ cairo_surface_create_similar (cairo_surface_t *other, _trace_printf ("s%ld ", other_obj->token); } - _trace_printf ("%d %d //%s similar dup /s%ld exch def\n", - width, height, - _content_to_string (content), - new_obj->token); + if (image) + _trace_printf ("//%s %d %d similar-image dup /s%ld exch def\n", + format_or_content, + width, height, + new_obj->token); + else + _trace_printf ("%d %d //%s similar dup /s%ld exch def\n", + width, height, + format_or_content, + new_obj->token); new_obj->width = width; new_obj->height = height; @@ -3709,6 +3706,21 @@ cairo_surface_create_similar (cairo_surface_t *other, dump_stack(__func__); _write_unlock (); } +} + +cairo_surface_t * +cairo_surface_create_similar (cairo_surface_t *other, + cairo_content_t content, + int width, int height) +{ + cairo_surface_t *ret; + + _enter_trace (); + + ret = DLCALL (cairo_surface_create_similar, other, content, width, height); + + _emit_line_info (); + _emit_surface_create_similar (other, ret, FALSE, _content_to_string (content), width, height); _exit_trace (); return ret; @@ -3727,29 +3739,7 @@ cairo_surface_create_similar_image (cairo_surface_t *other, other, format, width, height); _emit_line_info (); - if (other != NULL && _write_lock ()) { - Object *other_obj = _get_object(SURFACE, other); - Object *new_obj = _create_surface (ret); - - if (other_obj->defined) - _trace_printf ("s%ld ", other_obj->token); - else if (current_stack_depth == other_obj->operand + 1) - _trace_printf ("dup "); - else - _trace_printf ("%d index ", - current_stack_depth - other_obj->operand - 1); - _trace_printf ("s%ld //%s %d %d similar-image %% s%ld\n", - _get_surface_id (other), - _format_to_string (format), - width, height, - new_obj->token); - new_obj->width = width; - new_obj->height = height; - - _push_object (new_obj); - dump_stack(__func__); - _write_unlock (); - } + _emit_surface_create_similar (other, ret, TRUE, _format_to_string (format), width, height); _exit_trace (); return ret; -- 2.1.3