[cairo-commit] 3 commits - test/caps.c test/caps-joins.c test/reference util/cairo-trace

Chris Wilson ickle at kemper.freedesktop.org
Wed Jun 5 14:34:42 PDT 2013


 test/caps-joins.c                          |   55 ++++++++++
 test/caps.c                                |   57 ++++++++++-
 test/reference/caps-05.ref.png             |binary
 test/reference/caps-05.traps.ref.png       |binary
 test/reference/caps-1.ref.png              |binary
 test/reference/caps-1.traps.ref.png        |binary
 test/reference/caps-2.ref.png              |binary
 test/reference/caps-2.traps.ref.png        |binary
 test/reference/caps-joins-05.ref.png       |binary
 test/reference/caps-joins-05.traps.ref.png |binary
 test/reference/caps-joins-1.ref.png        |binary
 test/reference/caps-joins-1.traps.ref.png  |binary
 test/reference/caps-joins-2.ref.png        |binary
 test/reference/caps-joins-2.traps.ref.png  |binary
 util/cairo-trace/trace.c                   |  147 +++++++++++++++++------------
 15 files changed, 192 insertions(+), 67 deletions(-)

New commits:
commit 17dc312221c294b120bd159e01f5f566c6ec4a2d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jun 5 22:34:52 2013 +0100

    trace: Improve operand emission
    
    In particular fixing up a couple of corner cases in emitting the right
    instructions for scaled-fonts and patterns.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index ead48a6..085059f 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -997,18 +997,22 @@ _pop_operands_to_depth (int depth)
 static cairo_bool_t
 _pop_operands_to_object (Object *obj)
 {
+    if (!obj)
+	return FALSE;
+
     if (obj->operand == -1)
 	return FALSE;
 
     if (obj->operand == current_stack_depth - 1)
 	return TRUE;
 
-    if (! _pop_operands_to_depth (obj->operand + 2))
-	return FALSE;
+    if (obj->operand == current_stack_depth - 2) {
+	_exch_operands ();
+	_trace_printf ("exch ");
+	return TRUE;
+    }
 
-    _exch_operands ();
-    _trace_printf ("exch ");
-    return TRUE;
+    return _pop_operands_to_depth (obj->operand + 2);
 }
 
 static cairo_bool_t
@@ -1147,12 +1151,6 @@ _has_id (enum operand_type op_type, const void *ptr)
 }
 
 static long
-_get_context_id (cairo_t *cr)
-{
-    return _get_id (CONTEXT, cr);
-}
-
-static long
 _create_font_face_id (cairo_font_face_t *font_face)
 {
     Object *obj;
@@ -1225,25 +1223,33 @@ _emit_pattern_id (cairo_pattern_t *pattern)
     }
 }
 
-static long
-_create_scaled_font_id (cairo_scaled_font_t *font)
+static void
+_emit_scaled_font_id (const cairo_scaled_font_t *scaled_font)
 {
-    Object *obj;
-
-    obj = _get_object (SCALED_FONT, font);
+    Object *obj = _get_object (SCALED_FONT, scaled_font);
     if (obj == NULL) {
-	obj = _type_object_create (SCALED_FONT, font);
-	DLCALL (cairo_scaled_font_set_user_data,
-		font, &destroy_key, obj, _object_undef);
+	_trace_printf ("null ");
+    } else {
+	if (obj->defined) {
+	    _trace_printf ("sf%ld ", obj->token);
+	} else {
+	    _trace_printf ("%d index ",
+		     current_stack_depth - obj->operand - 1);
+	}
     }
-
-    return obj->token;
 }
 
 static long
-_get_scaled_font_id (const cairo_scaled_font_t *font)
+_create_scaled_font_id (cairo_scaled_font_t *font)
 {
-    return _get_id (SCALED_FONT, font);
+    Object *obj;
+
+    assert(_get_object (SCALED_FONT, font) == NULL);
+    obj = _type_object_create (SCALED_FONT, font);
+    DLCALL (cairo_scaled_font_set_user_data,
+	    font, &destroy_key, obj, _object_undef);
+
+    return obj->token;
 }
 
 static cairo_bool_t
@@ -1888,7 +1894,21 @@ static void
 _emit_current (Object *obj)
 {
     if (obj != NULL && ! _pop_operands_to_object (obj)) {
-	_trace_printf ("%s%ld\n", obj->type->op_code, obj->token);
+	if (obj->defined) {
+	    _trace_printf ("%s%ld\n", obj->type->op_code, obj->token);
+	} else {
+	    int n;
+
+	    _trace_printf ("%d -1 roll %% %s%ld\n",
+			   current_stack_depth - obj->operand + 1,
+			   obj->type->op_code, obj->token);
+
+	    for (n = obj->operand; n < current_stack_depth - 1; n++) {
+		current_object[n] = current_object[n+1];
+		current_object[n]->operand = n;
+	    }
+	    current_stack_depth--;
+	}
 	_push_object (obj);
     }
 }
@@ -2184,7 +2204,8 @@ cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface, double x, doubl
 	    _consume_operand (false);
 	}
 	else if (_is_current (SURFACE, surface, 1) &&
-		 _is_current (CONTEXT, cr, 0))
+		 _is_current (CONTEXT, cr, 0) &&
+		 obj->defined)
 	{
 	    _trace_printf ("exch ");
 	    _exch_operands ();
@@ -2227,8 +2248,11 @@ cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
 	{
 	    if (obj->defined) {
 		_consume_operand (false);
-		need_context_and_pattern = FALSE;
+	    } else {
+		_trace_printf ("exch 1 index ");
+		_exch_operands ();
 	    }
+	    need_context_and_pattern = FALSE;
 	}
 	else if (_is_current (PATTERN, source, 1) &&
 		 _is_current (CONTEXT, cr, 0))
@@ -3080,31 +3104,39 @@ cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font)
 {
     _enter_trace ();
     _emit_line_info ();
-    if (cr != NULL && scaled_font != NULL) {
-	if (_pop_operands_to (SCALED_FONT, scaled_font)) {
-	    if (_is_current (CONTEXT, cr, 1)) {
-		if (_write_lock ()) {
-		    _consume_operand (false);
-		    _trace_printf ("set-scaled-font\n");
-		    _write_unlock ();
-		}
+    if (cr != NULL && scaled_font != NULL && _write_lock ()) {
+	Object *obj = _get_object (SCALED_FONT, scaled_font);
+	cairo_bool_t need_context_and_font = TRUE;
+
+	if (_is_current (SCALED_FONT, scaled_font, 0) &&
+	    _is_current (CONTEXT, cr, 1))
+	{
+	    if (obj->defined) {
+		_consume_operand (false);
 	    } else {
-		if (_get_object (CONTEXT, cr)->defined) {
-		    if (_write_lock ()) {
-			_consume_operand (false);
-			_trace_printf ("c%ld exch set-scaled-font pop\n",
-				       _get_context_id (cr));
-			_write_unlock ();
-		    }
-		} else {
-		    _emit_cairo_op (cr, "sf%ld set-scaled-font\n",
-				    _get_scaled_font_id (scaled_font));
-		}
+		_trace_printf ("exch 1 index ");
+		_exch_operands ();
 	    }
-	} else {
-	    _emit_cairo_op (cr, "sf%ld set-scaled-font\n",
-			    _get_scaled_font_id (scaled_font));
+	    need_context_and_font = FALSE;
 	}
+	else if (_is_current (SCALED_FONT, scaled_font, 1) &&
+		 _is_current (CONTEXT, cr, 0))
+	{
+	    if (obj->defined) {
+		_trace_printf ("exch ");
+		_exch_operands ();
+		_consume_operand (false);
+		need_context_and_font = FALSE;
+	    }
+	}
+
+	if (need_context_and_font) {
+	    _emit_context (cr);
+	    _emit_scaled_font_id (scaled_font);
+	}
+
+	_trace_printf ("set-scaled-font\n");
+	_write_unlock ();
     }
     DLCALL (cairo_set_scaled_font, cr, scaled_font);
     _exit_trace ();
@@ -3133,12 +3165,12 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
 			  const cairo_font_options_t *options)
 {
     cairo_scaled_font_t *ret;
-    long scaled_font_id;
 
     _enter_trace ();
 
     ret = DLCALL (cairo_scaled_font_create, font_face, font_matrix, ctm, options);
-    scaled_font_id = _create_scaled_font_id (ret);
+    if (_has_scaled_font_id (ret))
+	    goto out;
 
     _emit_line_info ();
     if (font_face != NULL &&
@@ -3160,20 +3192,15 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
 
 	_emit_font_options (options);
 
-	if (_get_object (SCALED_FONT, ret)->defined) {
-	    _trace_printf ("  scaled-font pop %% sf%ld\n",
-			   scaled_font_id);
-	} else {
-	    _trace_printf ("  scaled-font dup /sf%ld exch def\n",
-			   scaled_font_id);
-	    _push_operand (SCALED_FONT, ret);
-
-	    _get_object (SCALED_FONT, ret)->defined = TRUE;
-	}
+	_trace_printf ("  scaled-font dup /sf%ld exch def\n",
+		       _create_scaled_font_id (ret));
+	_push_operand (SCALED_FONT, ret);
+	_get_object (SCALED_FONT, ret)->defined = TRUE;
 
 	_write_unlock ();
     }
 
+out:
     _exit_trace ();
     return ret;
 }
commit e34b800214c78ec3d92de505d173fc617cf6220f
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Jun 4 11:47:07 2013 +0100

    test: Extend testing of joins for fine lines

diff --git a/test/caps-joins.c b/test/caps-joins.c
index 9d1c2a8..de22d03 100644
--- a/test/caps-joins.c
+++ b/test/caps-joins.c
@@ -72,7 +72,7 @@ draw_caps_joins (cairo_t *cr)
 }
 
 static cairo_test_status_t
-draw (cairo_t *cr, int width, int height)
+draw (cairo_t *cr, float line_width)
 {
     /* We draw in the default black, so paint white first. */
     cairo_save (cr);
@@ -80,12 +80,12 @@ draw (cairo_t *cr, int width, int height)
     cairo_paint (cr);
     cairo_restore (cr);
 
-    cairo_set_line_width (cr, LINE_WIDTH);
+    cairo_set_line_width (cr, line_width);
 
     draw_caps_joins (cr);
 
     /* and reflect to generate the opposite vertex ordering */
-    cairo_translate (cr, 0, height);
+    cairo_translate (cr, 0, 2 * (PAD + SIZE) + PAD);
     cairo_scale (cr, 1, -1);
 
     draw_caps_joins (cr);
@@ -93,11 +93,58 @@ draw (cairo_t *cr, int width, int height)
     return CAIRO_TEST_SUCCESS;
 }
 
+static cairo_test_status_t
+draw_10 (cairo_t *cr, int width, int height)
+{
+    return draw (cr, LINE_WIDTH);
+}
+
+static cairo_test_status_t
+draw_2 (cairo_t *cr, int width, int height)
+{
+    return draw (cr, 2.0);
+}
+
+static cairo_test_status_t
+draw_1 (cairo_t *cr, int width, int height)
+{
+    return draw (cr, 1.0);
+}
+
+static cairo_test_status_t
+draw_05 (cairo_t *cr, int width, int height)
+{
+    return draw (cr, 0.5);
+}
+
 CAIRO_TEST (caps_joins,
 	    "Test caps and joins",
 	    "stroke", /* keywords */
 	    NULL, /* requirements */
 	    3 * (PAD + SIZE) + PAD,
 	    2 * (PAD + SIZE) + PAD,
-	    NULL, draw)
+	    NULL, draw_10)
+
+CAIRO_TEST (caps_joins_2,
+	    "Test caps and joins with default line width",
+	    "stroke", /* keywords */
+	    NULL, /* requirements */
+	    3 * (PAD + SIZE) + PAD,
+	    2 * (PAD + SIZE) + PAD,
+	    NULL, draw_2)
 
+CAIRO_TEST (caps_joins_1,
+	    "Test caps and joins with hairlines",
+	    "stroke", /* keywords */
+	    NULL, /* requirements */
+	    3 * (PAD + SIZE) + PAD,
+	    2 * (PAD + SIZE) + PAD,
+	    NULL, draw_1)
+
+CAIRO_TEST (caps_joins_05,
+	    "Test caps and joins with fine lines",
+	    "stroke", /* keywords */
+	    NULL, /* requirements */
+	    3 * (PAD + SIZE) + PAD,
+	    2 * (PAD + SIZE) + PAD,
+	    NULL, draw_05)
diff --git a/test/reference/caps-joins-05.ref.png b/test/reference/caps-joins-05.ref.png
new file mode 100644
index 0000000..8814ace
Binary files /dev/null and b/test/reference/caps-joins-05.ref.png differ
diff --git a/test/reference/caps-joins-05.traps.ref.png b/test/reference/caps-joins-05.traps.ref.png
new file mode 100644
index 0000000..938fb6d
Binary files /dev/null and b/test/reference/caps-joins-05.traps.ref.png differ
diff --git a/test/reference/caps-joins-1.ref.png b/test/reference/caps-joins-1.ref.png
new file mode 100644
index 0000000..d7cdf2c
Binary files /dev/null and b/test/reference/caps-joins-1.ref.png differ
diff --git a/test/reference/caps-joins-1.traps.ref.png b/test/reference/caps-joins-1.traps.ref.png
new file mode 100644
index 0000000..d9721f2
Binary files /dev/null and b/test/reference/caps-joins-1.traps.ref.png differ
diff --git a/test/reference/caps-joins-2.ref.png b/test/reference/caps-joins-2.ref.png
new file mode 100644
index 0000000..1416a54
Binary files /dev/null and b/test/reference/caps-joins-2.ref.png differ
diff --git a/test/reference/caps-joins-2.traps.ref.png b/test/reference/caps-joins-2.traps.ref.png
new file mode 100644
index 0000000..e7089a8
Binary files /dev/null and b/test/reference/caps-joins-2.traps.ref.png differ
commit a2d852497364afa742518ac0d9feb0466dccc191
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Jun 4 11:34:31 2013 +0100

    test: Expand testing of caps for fine strokes

diff --git a/test/caps.c b/test/caps.c
index 7f56117..cde2773 100644
--- a/test/caps.c
+++ b/test/caps.c
@@ -45,14 +45,13 @@ make_path (cairo_t *cr)
 }
 
 static cairo_test_status_t
-draw (cairo_t *cr, int width, int height)
+draw (cairo_t *cr)
 {
     cairo_save (cr);
     cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
     cairo_paint (cr);
     cairo_restore (cr);
 
-    cairo_set_line_width (cr, LINE_WIDTH);
     cairo_translate (cr, PAD + SIZE / 2., PAD + SIZE / 2.);
 
     cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
@@ -77,11 +76,63 @@ draw (cairo_t *cr, int width, int height)
     return CAIRO_TEST_SUCCESS;
 }
 
+static cairo_test_status_t
+draw_10 (cairo_t *cr, int width, int height)
+{
+    cairo_set_line_width (cr, LINE_WIDTH);
+    return draw (cr);
+}
+
+static cairo_test_status_t
+draw_2 (cairo_t *cr, int width, int height)
+{
+    cairo_set_line_width (cr, 2);
+    return draw (cr);
+}
+
+static cairo_test_status_t
+draw_1 (cairo_t *cr, int width, int height)
+{
+    cairo_set_line_width (cr, 1);
+    return draw (cr);
+}
+
+static cairo_test_status_t
+draw_05 (cairo_t *cr, int width, int height)
+{
+    cairo_set_line_width (cr, 0.5);
+    return draw (cr);
+}
+
 CAIRO_TEST (caps,
 	    "Test caps",
 	    "stroke caps", /* keywords */
 	    NULL, /* requirements */
 	    PAD + SIZE + PAD,
 	    3 * (PAD + SIZE) + PAD,
-	    NULL, draw)
+	    NULL, draw_10)
+
+CAIRO_TEST (caps_2,
+	    "Test normal caps",
+	    "stroke caps", /* keywords */
+	    NULL, /* requirements */
+	    PAD + SIZE + PAD,
+	    3 * (PAD + SIZE) + PAD,
+	    NULL, draw_2)
+
+CAIRO_TEST (caps_1,
+	    "Test hairline caps",
+	    "stroke caps", /* keywords */
+	    NULL, /* requirements */
+	    PAD + SIZE + PAD,
+	    3 * (PAD + SIZE) + PAD,
+	    NULL, draw_1)
+
+CAIRO_TEST (caps_05,
+	    "Test fine caps",
+	    "stroke caps", /* keywords */
+	    NULL, /* requirements */
+	    PAD + SIZE + PAD,
+	    3 * (PAD + SIZE) + PAD,
+	    NULL, draw_05)
 
diff --git a/test/reference/caps-05.ref.png b/test/reference/caps-05.ref.png
new file mode 100644
index 0000000..946adcb
Binary files /dev/null and b/test/reference/caps-05.ref.png differ
diff --git a/test/reference/caps-05.traps.ref.png b/test/reference/caps-05.traps.ref.png
new file mode 100644
index 0000000..409bdab
Binary files /dev/null and b/test/reference/caps-05.traps.ref.png differ
diff --git a/test/reference/caps-1.ref.png b/test/reference/caps-1.ref.png
new file mode 100644
index 0000000..dfb1118
Binary files /dev/null and b/test/reference/caps-1.ref.png differ
diff --git a/test/reference/caps-1.traps.ref.png b/test/reference/caps-1.traps.ref.png
new file mode 100644
index 0000000..10f7d57
Binary files /dev/null and b/test/reference/caps-1.traps.ref.png differ
diff --git a/test/reference/caps-2.ref.png b/test/reference/caps-2.ref.png
new file mode 100644
index 0000000..ca420bc
Binary files /dev/null and b/test/reference/caps-2.ref.png differ
diff --git a/test/reference/caps-2.traps.ref.png b/test/reference/caps-2.traps.ref.png
new file mode 100644
index 0000000..1c5d885
Binary files /dev/null and b/test/reference/caps-2.traps.ref.png differ


More information about the cairo-commit mailing list