[cairo] Supporting Different Pixel Formats at Runtime

Eric M. Hielscher hielscher at gmail.com
Mon Jul 24 09:12:38 PDT 2006


Hi all,

This is in effect a generic C/C++ question, but the specific context
is Cairo so I thought I might try this list.  It may be that I'm just
being stupid, but here goes.

For my Google Summer of Code project, I'm writing a Cairo backend
surface (in C++) that renders using Antigrain.  In writing the
implementations of the Cairo API I want to have something like this:

 pipeline = create_agg_pipeline_for_pix_format (pixel_format, surface->buffer);

 algorithm-specific code which calls methods like:

    pipeline->blend_solid_hspan (x, y, len, color, covers);

 destroy_agg_pipeline (pipeline);

The issue I'm having is that I don't want to have to duplicate the
algorithm-specific code in big switch statements that instantiate the
Agg templates with the different pixel formats - I want to leverage
some sort of dynamic polymorphism to deal with that transparently and
elegantly.  The problem is that the templating of Agg leads to
compile-time instantiations of the pipeline code to specific pixel
formats.

The one solution I came up with was to write a virtual wrapper class
that exposes all the Agg pipeline rendering operations in which I'm
interested and also to write a subclass for each pixel format.  Is
this the best way to handle this?  Any suggestions?
-- 
Eric Hielscher

http://www.cs.wisc.edu/~hielsche


More information about the cairo mailing list