[cairo] Speedup _cairo_matrix_to_pixman_matrix

Daniel Amelang daniel.amelang at gmail.com
Tue Nov 21 12:16:44 PST 2006


Ok, after rounding and glyph transforming dropped off the softfloat
profile, _cairo_fixed_from_double showed up again (even with the new
optimization). Most of these calls came from
_cairo_matrix_to_pixman_matrix, and luckly, most of the time, the
matrix being converted was an identity matrix, so we can easily solve
this one by adding a quick check for an identity matrix, and do a fast
memcpy from a template pixman identity matrix to perform the
conversion.

Again, I need someone with a Nokia 770 to perform the real test.
Sorry. If I weren't living off student loans at the moment, I buy one
in a heartbeat. Maybe Santa Claus thinks I've been a good boy this
year...

On a side note, I have laying around a version of
_cairo_fixed_from_double doesn't have any FP operations at all. Once I
clean it up, I'll submit the patch. Thing is, it slows down systems
that _do_ have a FPU, so we''ll have to come up with some sort of
--avoid-fp configure flag to enable paths that run faster on FP
crippled systems, but slower on those that have an FPU. Either way,
it's nice to get _cairo_fixed_from_double entirely off FP, and thus
far away from the top of any profile on softfloat.

Dan
-------------- next part --------------
From nobody Mon Sep 17 00:00:00 2001
From: Dan Amelang <dan at amelang.net>
Date: Tue Nov 21 12:14:05 2006 -0800
Subject: [PATCH] Optimize _cairo_matrix_to_pixman_matrix for the common case of an identity matrix

---

 src/cairo-matrix.c |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)

9fb93de774f55c2b4dafe7262b7bc9ba20548962
diff --git a/src/cairo-matrix.c b/src/cairo-matrix.c
index ed5da92..7f43f23 100644
--- a/src/cairo-matrix.c
+++ b/src/cairo-matrix.c
@@ -725,15 +725,28 @@ void
 _cairo_matrix_to_pixman_matrix (const cairo_matrix_t	*matrix,
 				pixman_transform_t	*pixman_transform)
 {
-    pixman_transform->matrix[0][0] = _cairo_fixed_from_double (matrix->xx);
-    pixman_transform->matrix[0][1] = _cairo_fixed_from_double (matrix->xy);
-    pixman_transform->matrix[0][2] = _cairo_fixed_from_double (matrix->x0);
+    static const pixman_fixed16_16_t pixman_identity_matrix[3][3] = {
+        {1 << 16,        0,       0},
+        {       0, 1 << 16,       0},
+        {       0,       0, 1 << 16}
+    };
 
-    pixman_transform->matrix[1][0] = _cairo_fixed_from_double (matrix->yx);
-    pixman_transform->matrix[1][1] = _cairo_fixed_from_double (matrix->yy);
-    pixman_transform->matrix[1][2] = _cairo_fixed_from_double (matrix->y0);
+    if (_cairo_matrix_is_identity (matrix)) {
+        memcpy (pixman_transform->matrix,
+                &pixman_identity_matrix,
+                sizeof (pixman_identity_matrix));
+    }
+    else {
+        pixman_transform->matrix[0][0] = _cairo_fixed_from_double (matrix->xx);
+        pixman_transform->matrix[0][1] = _cairo_fixed_from_double (matrix->xy);
+        pixman_transform->matrix[0][2] = _cairo_fixed_from_double (matrix->x0);
 
-    pixman_transform->matrix[2][0] = 0;
-    pixman_transform->matrix[2][1] = 0;
-    pixman_transform->matrix[2][2] = _cairo_fixed_from_double (1);
+        pixman_transform->matrix[1][0] = _cairo_fixed_from_double (matrix->yx);
+        pixman_transform->matrix[1][1] = _cairo_fixed_from_double (matrix->yy);
+        pixman_transform->matrix[1][2] = _cairo_fixed_from_double (matrix->y0);
+
+        pixman_transform->matrix[2][0] = 0;
+        pixman_transform->matrix[2][1] = 0;
+        pixman_transform->matrix[2][2] = 1 << 16;
+    }
 }
-- 
1.2.6


More information about the cairo mailing list