[cairo-commit] 3 commits - src/cairo-meta-surface.c src/cairo-meta-surface-private.h src/cairo-paginated-surface.c src/cairo-pdf-surface.c src/cairo-ps-surface.c test/mask.c

Carl Worth cworth at kemper.freedesktop.org
Thu Apr 27 08:22:04 PDT 2006


 src/cairo-meta-surface-private.h |    3 +++
 src/cairo-meta-surface.c         |   14 +++++++++++++-
 src/cairo-paginated-surface.c    |    9 +--------
 src/cairo-pdf-surface.c          |    7 ++++---
 src/cairo-ps-surface.c           |   15 ++++++++++++++-
 test/mask.c                      |    3 +--
 6 files changed, 36 insertions(+), 15 deletions(-)

New commits:
diff-tree 5515191f84bb837383278495f1f7034e7a97bdce (from 9bca27a1adc89b12905ec95ebb4e006830010df1)
Author: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date:   Tue Apr 25 21:55:56 2006 +0200

    Use CLEAR operator in mask.c in order to not trig image fallback
    for polygon masking.
    (cherry picked from 30b2d1c5df9d1c6b536838a6a3407fdfa7198e29 commit)

diff --git a/test/mask.c b/test/mask.c
index 6d0e458..2f0349d 100644
--- a/test/mask.c
+++ b/test/mask.c
@@ -81,8 +81,7 @@ mask_polygon (cairo_t *cr, int x, int y)
     cr2 = cairo_create (mask_surface);
 
     cairo_save (cr2);
-    cairo_set_source_rgba (cr2, 0, 0, 0, 0); /* transparent */
-    cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
+    cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
     cairo_paint (cr2);
     cairo_restore (cr2);
 
diff-tree 9bca27a1adc89b12905ec95ebb4e006830010df1 (from a7320589207088351c035df55644f1d94600f313)
Author: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date:   Sun Apr 23 22:55:37 2006 +0200

    Optimisation of CLEAR operator in meta-surface.
    
    This optimisation takes care to not replay what was done
    before surface is cleared. We don't erase recorded commands
    since we may have earlier snapshots of this surface.
    (cherry picked from 926e2494ca2211e9117ab70fc427208d125e1bd5 commit)

diff --git a/src/cairo-meta-surface-private.h b/src/cairo-meta-surface-private.h
index eafe3f4..24b1b47 100644
--- a/src/cairo-meta-surface-private.h
+++ b/src/cairo-meta-surface-private.h
@@ -137,6 +137,9 @@ typedef struct _cairo_meta_surface {
 
     cairo_array_t commands;
     cairo_surface_t *commands_owner;
+
+    cairo_bool_t is_clipped;
+    int replay_start_idx;
 } cairo_meta_surface_t;
 
 cairo_private cairo_surface_t *
diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c
index f7aeb71..f02f0a7 100644
--- a/src/cairo-meta-surface.c
+++ b/src/cairo-meta-surface.c
@@ -81,6 +81,9 @@ _cairo_meta_surface_create (cairo_conten
     _cairo_array_init (&meta->commands, sizeof (cairo_command_t *));
     meta->commands_owner = NULL;
 
+    meta->is_clipped = FALSE;
+    meta->replay_start_idx = 0;
+
     return &meta->base;
 }
 
@@ -226,6 +229,12 @@ _cairo_meta_surface_paint (void			*abstr
     cairo_meta_surface_t *meta = abstract_surface;
     cairo_command_paint_t *command;
 
+    /* An optimisation that takes care to not replay what was done
+     * before surface is cleared. We don't erase recorded commands 
+     * since we may have earlier snapshots of this surface. */
+    if (op == CAIRO_OPERATOR_CLEAR && !meta->is_clipped) 
+	meta->replay_start_idx = meta->commands.num_elements;
+
     command = malloc (sizeof (cairo_command_paint_t));
     if (command == NULL)
 	return CAIRO_STATUS_NO_MEMORY;
@@ -473,6 +482,7 @@ _cairo_meta_surface_snapshot (void *abst
 
     meta->width_pixels = other->width_pixels;
     meta->height_pixels = other->height_pixels;
+    meta->replay_start_idx = other->replay_start_idx;
 
     _cairo_array_init_snapshot (&meta->commands, &other->commands);
     meta->commands_owner = cairo_surface_reference (&other->base);
@@ -504,8 +514,10 @@ _cairo_meta_surface_intersect_clip_path 
 	    return status;
 	}
 	command->path_pointer = &command->path;
+	meta->is_clipped = TRUE;
     } else {
 	command->path_pointer = NULL;
+	meta->is_clipped = FALSE;
     }
     command->fill_rule = fill_rule;
     command->tolerance = tolerance;
@@ -610,7 +622,7 @@ _cairo_meta_surface_replay (cairo_surfac
 
     num_elements = meta->commands.num_elements;
     elements = _cairo_array_index (&meta->commands, 0);
-    for (i = 0; i < num_elements; i++) {
+    for (i = meta->replay_start_idx; i < num_elements; i++) {
 	command = elements[i];
 	switch (command->type) {
 	case CAIRO_COMMAND_PAINT:
diff-tree a7320589207088351c035df55644f1d94600f313 (from e1be80b02080955e29d17c50118471158593b86f)
Author: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date:   Thu Apr 20 22:07:52 2006 +0200

    Implement paginated create_similar, moving similar images down to PS and PDF.
    
    The new paginated create_similar simply forwards to target backend create_similar.
    
    We maintain the fact that PS and PDF surfaces are returning image
    surfaces for create_similar by moving that explicitly to their own
    create_similar functions.
    
    (This commit is the combination of the following original commits:
    
    	6b69e8c012adb4f2fc2ee9c1579fed8214e8f510
    	2589db92a4395f8e900dbc4eafc45982f0d985d3
    )

diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index da6a60b..080102b 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -79,12 +79,6 @@ const cairo_private cairo_surface_backen
 static cairo_int_status_t
 _cairo_paginated_surface_show_page (void *abstract_surface);
 
-/* XXX: This would seem the natural thing to do here. But currently,
- * PDF and PS surfaces do not yet work as source surfaces. So instead,
- * we don't implement create_similar for the paginate_surface which
- * means that any create_similar() call on a paginated_surfacae will
- * result in a new image surface. */
-#if 0
 static cairo_surface_t *
 _cairo_paginated_surface_create_similar (void			*abstract_surface,
 					 cairo_content_t	 content,
@@ -95,7 +89,6 @@ _cairo_paginated_surface_create_similar 
     return cairo_surface_create_similar (surface->target, content,
 					 width, height);
 }
-#endif
 
 cairo_surface_t *
 _cairo_paginated_surface_create (cairo_surface_t				*target,
@@ -471,7 +464,7 @@ _cairo_paginated_surface_snapshot (void 
 
 const cairo_surface_backend_t cairo_paginated_surface_backend = {
     CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED,
-    NULL, /* create_similar --- see note for _cairo_paginated_surface_create_similar */
+    _cairo_paginated_surface_create_similar,
     _cairo_paginated_surface_finish,
     _cairo_paginated_surface_acquire_source_image,
     _cairo_paginated_surface_release_source_image,
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 93a8217..4d557aa 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -456,10 +456,11 @@ _cairo_pdf_surface_create_similar (void	
 				   int			width,
 				   int			height)
 {
-    cairo_pdf_surface_t *template = abstract_src;
+    cairo_format_t format = _cairo_format_from_content (content);
 
-    return _cairo_pdf_surface_create_for_document (template->document,
-						   width, height);
+    /* Just return an image for now, until PDF surface can be used
+     * as source. */
+    return cairo_image_surface_create (format, width, height);
 }
 
 static cairo_pdf_stream_t *
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index cf77db2..f84a57a 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -780,6 +780,19 @@ _word_wrap_stream_create (cairo_output_s
 					NULL, stream);
 }
 
+static cairo_surface_t *
+_cairo_ps_surface_create_similar (void		       *abstract_src,
+				   cairo_content_t	content,
+				   int			width,
+				   int			height)
+{
+    cairo_format_t format = _cairo_format_from_content (content);
+
+    /* Just return an image for now, until PS surface can be used
+     * as source. */
+    return cairo_image_surface_create (format, width, height);
+}
+
 static cairo_status_t
 _cairo_ps_surface_finish (void *abstract_surface)
 {
@@ -1634,7 +1647,7 @@ _cairo_ps_surface_set_paginated_mode (vo
 
 static const cairo_surface_backend_t cairo_ps_surface_backend = {
     CAIRO_SURFACE_TYPE_PS,
-    NULL, /* create_similar */
+    _cairo_ps_surface_create_similar,
     _cairo_ps_surface_finish,
     NULL, /* acquire_source_image */
     NULL, /* release_source_image */


More information about the cairo-commit mailing list