Re: Public API for pattern duplication

Mark Vender <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
On 02/27/2012 08:46 PM, Chris Wilson wrote:
> On Mon, 27 Feb 2012 20:23:20 +0200, Mark Vender<[email protected]>  wrote:
>> Could someone indicate whether this function is still welcome to cairo?
>> If the problem is that just nobody else is interested, I could easily
>> contribute a patch adding this functionality myself.
>
> If you have a concrete use case and such functionality will be useful to
> you, please do submit the patch to give a public entry point to
> _cairo_pattern_create_copy(). Be prepared to justify your use case
> though. ;)
> -Chris
>

I have a fairly simple use case, in which it is almost impossible to 
workaround the lack of pattern copying routine. I have several threads, 
that do drawing on a separate surfaces using a separate contexts. An 
equivalent pattern needs to be passed to each of the threads. The 
pattern transformation matrix is modified during the drawing, therefore 
I can't use a single pattern without adding much complexity to the code 
and incurring a performance penalty. I don't use surface patterns, so 
_cairo_pattern_create_copy would solve this issue completely for me.

I attach a patch that adds new function cairo_pattern_create_copy, which 
acts as a wrapper to _cairo_pattern_create_copy. The pattern copying 
code currently doesn't use the freed pattern cache, this might be a 
possible addition in the future.

     Mark

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
0001-Add-cairo_pattern_create_copy-to-the-public-API.patch (text/x-patch, 2 KB)
From 22bc2b28ab3c18666c0b7d90b58ce8823b9dd830 Mon Sep 17 00:00:00 2001
From: Mark Vender <[email protected]>
Date: Fri, 2 Mar 2012 20:41:50 +0200
Subject: [PATCH] Add cairo_pattern_create_copy to the public API

---
 src/cairo-pattern.c |   32 ++++++++++++++++++++++++++++++++
 src/cairo.h         |    3 +++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index f114ca8..337fe97 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -1026,6 +1026,38 @@ cairo_pattern_create_mesh (void)
 }
 
 /**
+ * cairo_pattern_create_copy:
+ * @pattern: a #cairo_pattern_t
+ * 
+ * Creates a copy of @pattern. 
+ * 
+ * Return value: the newly created #cairo_pattern_t if successful, or an 
+ * error pattern in case of no memory. The caller owns the returned
+ * object and should call cairo_pattern_destroy() when finished with
+ * it.
+ *
+ * This function will always return a valid pointer, but if an error
+ * occurred the pattern status will be set to an error. To inspect the
+ * status of a pattern use cairo_pattern_status().
+ *
+ * Since: 1.12
+ */
+cairo_pattern_t *
+cairo_pattern_create_copy (const cairo_pattern_t *pattern)
+{
+    cairo_pattern_t *pattern_out;
+    cairo_status_t status;
+    
+    status = _cairo_pattern_create_copy (&pattern_out, pattern);
+    
+    if (unlikely (status)) {
+        // error has already been accounted for in _cairo_pattern_create_copy
+        return (cairo_pattern_t *) &_cairo_pattern_nil;
+    }
+    return pattern_out;
+}
+
+/**
  * cairo_pattern_reference:
  * @pattern: a #cairo_pattern_t
  *
diff --git a/src/cairo.h b/src/cairo.h
index d23cd10..0d6a337 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -2644,6 +2644,9 @@ cairo_public cairo_pattern_t *
 cairo_pattern_create_mesh (void);
 
 cairo_public cairo_pattern_t *
+cairo_pattern_create_copy (const cairo_pattern_t *pattern);
+
+cairo_public cairo_pattern_t *
 cairo_pattern_reference (cairo_pattern_t *pattern);
 
 cairo_public void
-- 
1.7.9
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.