[Sugar-devel] TA cairo conversion

Walter Bender walter.bender at gmail.com
Sat Nov 5 15:26:34 EDT 2011


On Sat, Nov 5, 2011 at 11:08 AM, C. Scott Ananian <cscott at laptop.org> wrote:
> I've been pushing my work to
>  http://git.sugarlabs.org/~walter/turtleart/walters-gtk3/commits/cscotts-gtk3
>
> I'll rebase to the latest cairo bits.  (It might be best to continue
> working with HEAD of my branch, since it runs fine on gtk2 and will
> minimize unnecessary patch conflicts.)  It's also a little confusing
> to have so many clones: walters-cairo, walters-gtk3, cscott-gtk3, etc.
>  Can we pick one clone and stick with it, even if we're going to work
> on separate branches?
>
> Gtk2 operation on my branch is unmodified, although the code uses Gtk3
> "style" throughout, for future-proofing.  The GTK3 version just needs
> some more incremental fixes; at the moment it's failing trying to
> create a CairoContext from a canvas---which I think should just be a
> no-op, more or less.  Just a matter of getting enough time to work
> through the fixes, help welcome.
>  --scott
>
> On Sat, Nov 5, 2011 at 9:15 AM, Benjamin Berg <benzea at sugarlabs.org> wrote:
>> Hello,
>>
>> On Sat, 2011-11-05 at 08:56 -0400, Walter Bender wrote:
>>> I pushed a few more patches last night [1]. I have just two blockers
>>> right now to releasing the Cairo version:
>>>
>>> (1) I cannot seem to figure out how to convert my surface to a pixbuf
>>> or png for saving to a file;
>>>         surface = canvas.canvas.get_target()  # get the surface used
>>> by the canvas
>>>         surface.cairo_surface_write_to_png(file_name)  <--- fails
>>> because XlibSurface doesn't have a cairo_surface_write_to_png
>>> attribute
>>
>> What you can do is the following:
>>  1. x_surface = canvas.canvas.get_target()
>>  2. Create an image surface:
>>    img_surface = cairo.ImageSurface(...)
>>  3. Create a context:
>>    cr = cairo.Context(img_surface)
>>  4. cr.set_source_surface(x_surface)
>>  5. cr.paint()
>>  6. img_surface.write_to_png(file_name)
>>
>> This way you can download the image data from the X server, and store it
>> inside the applications memory. After this it can be written out to a
>> file.

Worked great. Thanks.

>>
>>> (2) I cannot seem to create the proper surface from a Pixbuf to use in
>>> non-interactive mode in replacement of the canvas surface. I have
>>> unsuccessfully tried to create a pixbuf and use it to source a cairo
>>> context.

This worked as well. But I had to clean up a few other things that
were broken in the code. I suspect that non-interactive mode has been
broken for a while.

>>
>> The pixel format that cairo uses, and the one that Gdk.Pixbuf uses is
>> differs.  If I understand correctly, what you want to do is to create an
>> cairo.ImageSurface instead of the create_similar call.
>>
>>> The only non-blockers are:
>>> (1) I am struggling with the erratic behavior of rotate on bitmaps. It
>>> is disabled at the moment.
>>> (2) There must be some way to cache the surfaces used by the sprites
>>> instead of re-rendering them from pixbufs each time, but using
>>> get_target() gives X errors.
>>
>> Hm, I can't say anything about these of the top of my head.
>>
>> Benjamin
>>
>>
>
>
>
> --
>       ( http://cscott.net )
>

OK. I am pretty confident that there are no regressions in my current
Cairo branch. So now the question is, what is the most sensible way to
merge my branch with Scott's gtk3 branch? The merged branch can
presumably become the new master branch.

-walter

-- 
Walter Bender
Sugar Labs
http://www.sugarlabs.org


More information about the Sugar-devel mailing list