[cairo] push_group vector question

Carl Worth cworth at cworth.org
Thu Dec 13 15:37:32 PST 2007


On Fri, 14 Dec 2007 00:40:37 +0200, Donn wrote:
>  I feel more than a little sheepish having so many replies and *still* not
> getting some of the basics. I will press on.

No worries. Hopefully we all learn from the process.

> I savvy that a Pattern is a source of data for Cairo.

Yes.

> I also see that vector data remains vector and raster remains raster.

When the destination surface can store data as vectors we try to do
that whenever possible. Older versions of cairo did a fairly poor job
of this though.

>  Now, when one draws stuff in Cairo, let's say a tree, within a push/pop
> group -- what becomes of that data?

The way to understand push_group is that it redirects drawing to an
intermediate surface that is "similar" to the current destination
surface. The intermediate surface is much like the one you would get
from cairo_surface_create_similar.

So, if your original target surface supports vectors, then you'll
likely get a vector meta-surface for the intermediate stuff, (with
cairo 1.5.x at least). But if you are targeting a raster surface, then
the intermediate surface will be a raster as well.

>  My experience has been that it becomes a raster of what was drawn (clipped to
> the edges of the window). But it started life as what I would think of as
> a "vector" -- lines between points -- so wouldn't it make sense to expect a
> vector back again?

Well, everything "starts as vector" in cairo---so we can't use that as
a deciding criteria. When you do a cairo_line_to;cairo_stroke to a
raster surface we want that to go as fast as possible, (for example,
by using Render calls), and we don't want to spend the memory to save
all the vector data "just in case" or anything.

>  What if one wanted to paint it at a larger scale or output it to an SVG?

So the original intent of cairo_surface_create_similar is to give you
an intermediate surface that will perform as well as possible. So, for
example, when targeting cairo-xlib you'll get another xlib surface for
the intermediate, and a subsequent cairo_paint from one to the other
can be a server-side blit. That can go really fast.

Now, what you're asking for, (capturing data as a set of vectors for
replaying later with a different transformation), is actually
something quite different. We've talked about exposing interfaces at
the cairo API for creating an explicit meta-surface, and that should
allow you to do exactly what you describe here. I don't think it would
necessarily make sense to make cairo_push_group give you a meta
surface when you're targeting cairo-xlib though. In that case, you
would just want to call cairo_meta_surface_create directly, (which is
the function that isn't currently exposed).

Meanwhile, an alternate approach, (as I just described in another
thread), is for the application to just maintain its own data
structures and code for emitting cairo calls from them. That will
always be more efficient than anything we could do with a
meta-surface. Cairo surfaces should not be looked at as substitutes
for good data structures in the application.

> Perhaps there's a setting somewhere I have not seen.

I don't think so in this case.

I hope the above is helpful.

> Just wondering aloud for clarity.

Please feel free to continue doing so. You've raised some very
interesting issues.

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071213/d26c3597/attachment.pgp 


More information about the cairo mailing list