[cairo] reference counting vs garbage collection

Kristian Høgsberg krh at bitplanet.net
Tue Jan 4 15:10:10 PST 2005


Keith Packard wrote:
> Around 15 o'clock on Jan 3, =?UTF-8?B?S3Jpc3RpYW4gSMO4Z3NiZXJn?= wrote:
> 
>>Also, I don't think its a good idea to "overload" show_page in this way -
>>show_page should introduce a new blank page in a paginated backend and be a
>>no-op for single-page media.
> 
> As we can't re-write the page image, we really have to know when the page
> is complete.  So, the semantics for single-page static media (like PNG
> files) appears to resemble the multi-page static media (like PS or PDF) in 
> that an end-of-drawing indication is required.  Having the back-end 
> implicitly call 'copy_page' if the application hasn't already done so 
> seems like a reasonable way to define how the close operation works, even 
> if we don't expect applications to call copy_page on their own.

For paginated media, copy_page/show_page obviously can't be used for 
signalling end-of-drawing - it may be that the user just want to add 
another page.  Still, for PDF you also want to know when the drawing is 
finished, since you need to write out some tables and indices at the end 
of the file.  In the current PDF backend I'm just handling this in the 
surface destructor, which of course has the problem with closing the 
FILE you describe.  Owen's suggestion would solve this though.  As for 
the "close surface" operation: would this be useful if it wasn't necessary?

A more radical approach to all this could be to drop the concept of a 
default target and then add a surface parameter to the functions that 
draw to the surface.  E.g.

	cairo_stroke (cr, surface);
	cairo_fill (cr, surface);

Then you wouldn't need reference counting or callbacks, you'd just 
destroy the surface and then fclose() the FILE.

cheers,
Kristian



More information about the cairo mailing list