[cairo-commit] 3 commits - configure.ac src/cairoint.h src/cairo-surface.c src/cairo-surface-fallback.c src/cairo-types-private.h util/cairo-trace

Chris Wilson ickle at kemper.freedesktop.org
Mon Nov 3 16:24:38 PST 2008


 configure.ac                    |    5 +-
 src/cairo-surface-fallback.c    |   29 ++-------------
 src/cairo-surface.c             |   77 ++++++++++++++++++++++++++++------------
 src/cairo-types-private.h       |    2 +
 src/cairoint.h                  |    5 ++
 util/cairo-trace/Makefile.am    |   11 +++--
 util/cairo-trace/cairo-trace.in |   13 +++++-
 7 files changed, 84 insertions(+), 58 deletions(-)

New commits:
commit 90217550120f129004bc555b59ced28b4b25a4d4
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Nov 3 23:45:12 2008 +0000

    [mime-data] Copy a reference to the mime-data on snapshotting.
    
    Instead of doing a full-copy of the mime data (which can be 10K-100K,
    or even larger) just copy a reference to the original mime to the
    snapshot surface (as suggested by Behdad).

diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c
index 7cfbd65..f8f8902 100644
--- a/src/cairo-surface-fallback.c
+++ b/src/cairo-surface-fallback.c
@@ -1035,8 +1035,6 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface)
     cairo_status_t status;
     cairo_surface_pattern_t pattern;
     cairo_image_surface_t *image;
-    const unsigned char *mime_data;
-    unsigned int mime_data_length;
     void *image_extra;
 
     status = _cairo_surface_acquire_source_image (surface,
@@ -1081,28 +1079,11 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface)
      * For now, just copy "image/jpeg", but in future we should construct
      * an array of known types and iterate.
      */
-    cairo_surface_get_mime_data (surface, CAIRO_MIME_TYPE_JPEG,
-				 &mime_data, &mime_data_length);
-    if (mime_data != NULL) {
-	unsigned char *mime_data_copy;
-
-	mime_data_copy = malloc (mime_data_length);
-	if (mime_data == NULL) {
-	    cairo_surface_destroy (snapshot);
-	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-	}
-	memcpy (mime_data_copy, mime_data, mime_data_length);
-
-	status = cairo_surface_set_mime_data (snapshot,
-					      CAIRO_MIME_TYPE_JPEG,
-					      mime_data_copy,
-					      mime_data_length,
-					      free);
-	if (status) {
-	    free (mime_data_copy);
-	    cairo_surface_destroy (snapshot);
-	    return _cairo_surface_create_in_error (status);
-	}
+    status = _cairo_surface_copy_mime_data (snapshot, surface,
+	                                    CAIRO_MIME_TYPE_JPEG);
+    if (status) {
+	cairo_surface_destroy (snapshot);
+	return _cairo_surface_create_in_error (status);
     }
 
     snapshot->is_snapshot = TRUE;
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 109cbb9..72997b0 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -637,6 +637,9 @@ _cairo_mime_data_destroy (void *ptr)
 {
     cairo_mime_data_t *mime_data = ptr;
 
+    if (! _cairo_reference_count_dec_and_test (&mime_data->ref_count))
+	return;
+
     if (mime_data->destroy && mime_data->data)
 	mime_data->destroy (mime_data->data);
 
@@ -679,35 +682,63 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
     if (status)
 	return _cairo_surface_set_error (surface, status);
 
-    mime_data = _cairo_user_data_array_get_data (&surface->user_data,
+    mime_data = malloc (sizeof (cairo_mime_data_t));
+    if (mime_data == NULL)
+	return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_NO_MEMORY));
+
+    CAIRO_REFERENCE_COUNT_INIT (&mime_data->ref_count, 1);
+
+    mime_data->data = (unsigned char *) data;
+    mime_data->length = length;
+    mime_data->destroy = destroy;
+
+    status = _cairo_user_data_array_set_data (&surface->user_data,
+					      (cairo_user_data_key_t *) mime_type,
+					      mime_data,
+					      _cairo_mime_data_destroy);
+    if (status)
+	return _cairo_surface_set_error (surface, status);
+
+    return CAIRO_STATUS_SUCCESS;
+}
+slim_hidden_def (cairo_surface_set_mime_data);
+
+cairo_status_t
+_cairo_surface_copy_mime_data (cairo_surface_t *dst,
+			       cairo_surface_t *src,
+			       const char *mime_type)
+{
+    cairo_status_t status;
+    cairo_mime_data_t *mime_data;
+
+    if (dst->status)
+	return dst->status;
+
+    if (src->status)
+	return _cairo_surface_set_error (dst, src->status);
+
+    status = _cairo_intern_string (&mime_type, -1);
+    if (status)
+	return _cairo_surface_set_error (dst, status);
+
+    mime_data = _cairo_user_data_array_get_data (&src->user_data,
 						 (cairo_user_data_key_t *) mime_type);
-    if (mime_data != NULL) {
-	if (mime_data->destroy && mime_data->data)
-	    mime_data->destroy (mime_data->data);
+    if (mime_data == NULL)
+	return CAIRO_STATUS_SUCCESS;
 
-	mime_data->data = (unsigned char *) data;
-	mime_data->length = length;
-	mime_data->destroy = destroy;
-    } else {
-	mime_data = malloc (sizeof (cairo_mime_data_t));
-	if (mime_data == NULL)
-	    return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-	mime_data->data = (unsigned char *) data;
-	mime_data->length = length;
-	mime_data->destroy = destroy;
-
-	status = _cairo_user_data_array_set_data (&surface->user_data,
-						  (cairo_user_data_key_t *) mime_type,
-						  mime_data,
-						  _cairo_mime_data_destroy);
-	if (status)
-	    return _cairo_surface_set_error (surface, status);
+    _cairo_reference_count_inc (&mime_data->ref_count);
+
+    status = _cairo_user_data_array_set_data (&dst->user_data,
+					      (cairo_user_data_key_t *) mime_type,
+					      mime_data,
+					      _cairo_mime_data_destroy);
+    if (status) {
+	_cairo_mime_data_destroy (mime_data);
+	return _cairo_surface_set_error (dst, status);
     }
 
     return CAIRO_STATUS_SUCCESS;
 }
-slim_hidden_def (cairo_surface_set_mime_data);
 
 /**
  * _cairo_surface_set_font_options:
diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h
index 8bcbf9a..30180b0 100644
--- a/src/cairo-types-private.h
+++ b/src/cairo-types-private.h
@@ -41,6 +41,7 @@
 
 #include "cairo.h"
 #include "cairo-fixed-type-private.h"
+#include "cairo-reference-count-private.h"
 
 typedef struct _cairo_array cairo_array_t;
 typedef struct _cairo_cache cairo_cache_t;
@@ -344,6 +345,7 @@ typedef enum _cairo_image_transparency {
 } cairo_image_transparency_t;
 
 struct _cairo_mime_data {
+    cairo_reference_count_t ref_count;
     unsigned char *data;
     unsigned int length;
     cairo_destroy_func_t destroy;
diff --git a/src/cairoint.h b/src/cairoint.h
index 7fe853c..c7acbf7 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1666,6 +1666,11 @@ cairo_private cairo_surface_t *
 _cairo_surface_create_in_error (cairo_status_t status);
 
 cairo_private cairo_status_t
+_cairo_surface_copy_mime_data (cairo_surface_t *dst,
+			       cairo_surface_t *src,
+			       const char *mime_type);
+
+cairo_private cairo_status_t
 _cairo_surface_set_error (cairo_surface_t	*surface,
 			  cairo_status_t	 status);
 
commit 4f032ca35a7086b76775e4b53c6b99ba4e1eb3cb
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Nov 3 23:23:09 2008 +0000

    [trace] Install cairo-trace.so into $(libdir)/cairo
    
    Install the auxiliary library into the cairo subdirectory within the
    lib path, so that it doesn't clutter $(libdir) and sets a precedent for
    future auxiliary libraries.

diff --git a/util/cairo-trace/Makefile.am b/util/cairo-trace/Makefile.am
index b927768..c6caf0c 100644
--- a/util/cairo-trace/Makefile.am
+++ b/util/cairo-trace/Makefile.am
@@ -1,5 +1,6 @@
 bin_SCRIPTS = cairo-trace
-lib_LTLIBRARIES = cairo-trace.la
+cairolibdir = @libdir@/cairo
+cairolib_LTLIBRARIES = cairo-trace.la
 
 AM_CPPFLAGS = -I$(top_srcdir)/src \
 	      -I$(top_builddir)/src
@@ -13,10 +14,10 @@ cairo_trace_la_LDFLAGS = -module -no-undefined
 cairo_trace_la_LIBADD = -ldl -lz $(BFD_LIBS)
 
 system-install:
-	grep -sq @libdir@/cairo-trace.so /etc/ld.so.preload || echo @libdir@/cairo-trace.so >> /etc/ld.so.preload
+	grep -sq @cairolibdir@/cairo-trace.so /etc/ld.so.preload || echo @libdir@/cairo-trace.so >> /etc/ld.so.preload
 
 system-uninstall:
-	sed -e '@libdir@\/cairo-trace.so/d' < /etc/ld.so.preload > /tmp/ld.so.preload && mv /tmp/ld.so.preload /etc/ld.so.preload;
+	sed -e '@cairolibdir@\/cairo-trace.so/d' < /etc/ld.so.preload > /tmp/ld.so.preload && mv /tmp/ld.so.preload /etc/ld.so.preload;
 
 EXTRA_DIST = \
 	COPYING \
diff --git a/util/cairo-trace/cairo-trace.in b/util/cairo-trace/cairo-trace.in
index ee38161..93bb954 100644
--- a/util/cairo-trace/cairo-trace.in
+++ b/util/cairo-trace/cairo-trace.in
@@ -49,10 +49,17 @@ if test -z "$nofile"; then
   filename=`basename $1`.$$.trace
 fi
 
+LD_PRELOAD=@libdir@/cairo/cairo-trace.so 
+export LD_PRELOAD
+
+# Force the decimal output to the 'C' locale
+LC_ALL=C 
+export LC_ALL
+
 if test -z "$filename"; then
-  LD_PRELOAD=@libdir@/cairo-trace.so CAIRO_TRACE_FD=3 LC_ALL=C $* 3>&1 >/dev/null
+  CAIRO_TRACE_FD=3 $* 3>&1 >/dev/null
 elif test -n "$silent"; then
-  LD_PRELOAD=@libdir@/cairo-trace.so LC_ALL=C CAIRO_TRACE_OUTFILE_EXACT=$filename $*
+  CAIRO_TRACE_OUTFILE_EXACT=$filename $*
 else
-  LD_PRELOAD=@libdir@/cairo-trace.so CAIRO_TRACE_FD=3 LC_ALL=C $* 3>&1 >/dev/null | tee $filename
+  CAIRO_TRACE_FD=3 $* 3>&1 >/dev/null | tee $filename
 fi
commit c80a1c68c19f876c9f55b7c6d62b18ae110b11d0
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Nov 3 23:16:09 2008 +0000

    [configure] Make trace consistent.
    
    Remove the debianism from the comments for HAVE_BFD and comply with
    Behdad's guidelines on using  $(...) within Makefile.am.

diff --git a/configure.ac b/configure.ac
index 97a09b6..1ed086e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -497,10 +497,9 @@ AM_CONDITIONAL(BUILD_TRACE, test "x$have_ld_preload" = "xyes")
 
 AC_CHECK_LIB(bfd, bfd_openr,
 	 [AC_CHECK_HEADER(bfd.h, [have_bfd=yes],
-	 [have_bfd="no (requires binutils-dev)"])],
-	 [have_bfd="no (requires binutils-dev)"])
+	 [have_bfd=no])], [have_bfd=no])
 if test "x$have_bfd" = "xyes"; then
-    AC_DEFINE([HAVE_BFD], [1], [Define to 1 if you have binutils-dev installed])
+    AC_DEFINE([HAVE_BFD], [1], [Define to 1 if you have the binutils development files installed])
     BFD_LIBS=-lbfd
     AC_SUBST(BFD_LIBS)
 fi
diff --git a/util/cairo-trace/Makefile.am b/util/cairo-trace/Makefile.am
index 6d7d748..b927768 100644
--- a/util/cairo-trace/Makefile.am
+++ b/util/cairo-trace/Makefile.am
@@ -8,15 +8,15 @@ cairo_trace_la_SOURCES = \
 			 lookup-symbol.c \
 			 lookup-symbol.h \
 			 trace.c
-cairo_trace_la_CFLAGS = @FREETYPE_CFLAGS@ @CAIRO_CFLAGS@
+cairo_trace_la_CFLAGS = $(FREETYPE_CFLAGS) $(CAIRO_CFLAGS)
 cairo_trace_la_LDFLAGS = -module -no-undefined
-cairo_trace_la_LIBADD = -ldl -lz @BFD_LIBS@
+cairo_trace_la_LIBADD = -ldl -lz $(BFD_LIBS)
 
 system-install:
 	grep -sq @libdir@/cairo-trace.so /etc/ld.so.preload || echo @libdir@/cairo-trace.so >> /etc/ld.so.preload
 
 system-uninstall:
-	sed -e '/\/usr\/local\/lib\/cairo-trace.so/d' < /etc/ld.so.preload > /tmp/ld.so.preload && mv /tmp/ld.so.preload /etc/ld.so.preload;
+	sed -e '@libdir@\/cairo-trace.so/d' < /etc/ld.so.preload > /tmp/ld.so.preload && mv /tmp/ld.so.preload /etc/ld.so.preload;
 
 EXTRA_DIST = \
 	COPYING \


More information about the cairo-commit mailing list