From 7432d8b8020d6da72b816ac369af2793a10394d2 Mon Sep 17 00:00:00 2001 From: Emanuele Aina Date: Thu, 8 Jan 2015 12:09:54 +0100 Subject: [PATCH 3/3] cairo-trace: Extract common helper for _surface_create_similar[_image]() To avoid any divergence between cairo_surface_create_similar_image() and cairo_surface_create_similar() in future, coalesce the code to emit the trace line in a common helper. Unfortunately the signature of the two trace lines are slightly different (in 'similar' the content type precedes width and height, while for 'similar-image' width and height come before the format identifier), but to be able to run new traces with older cairo tools it cannot be changed. Signed-off-by: Emanuele Aina --- util/cairo-trace/trace.c | 73 +++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 44 deletions(-) diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c index d388ab4f3777..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,34 +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->operand != -1) { - if (current_stack_depth == other_obj->operand + 1) - _trace_printf ("dup "); - else - _trace_printf ("%d index ", - current_stack_depth - other_obj->operand - 1); - } else { - assert(other_obj->defined); - _trace_printf ("s%ld ", other_obj->token); - } - - _trace_printf ("//%s %d %d similar-image dup /s%ld exch def\n", - _format_to_string (format), - width, height, - new_obj->token); - - new_obj->width = width; - new_obj->height = height; - new_obj->defined = TRUE; - - _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.4