[cairo] Bindings and virtual functions
spitzak at d2.com
Thu May 26 09:25:23 PDT 2005
IMHO, if an wrapper for Cairo requires virtual functions, it indicates a
failure in design of Cairo itself. Therefore you should certainly not
use virtual functions, and if you feel there is a need to, you have
found a bug that should be reported to the Cairo developers.
Cairo does implement virtual functions, in the form of the different
surface backends. Depending on what surface you are drawing to, totally
different code can be executed, without any changes to the calling code.
As soon as your wrapper requires virtual functions, you will start
making code that only takes your wrapper, rather than a cairo_t, as an
argument. This is VERY bad. The big deal with Cairo is not antialiased
graphics. The big deal is that there is a hope that portable drawing
functions will be possible, where the only argument is a cairo_t, and
they will work in Qt widgets and GTK widgets and GTK canvas objects and
in a raw XCB or Xlib program, or in a Windows .net program. If you put
virtual functions around this you will completely kill this idea and
that would be very bad.
I do think there may be some mistakes, mostly that *all* Cairo drawing
functions should be directly implementable by back-ends and thus
"virtual". For instance Cairo was, for awhile, insisting on converting
fills to trapazoids and calling a backend fill-trapazoid function. It
would be better if "fill" and "stroke" were the interface to the
backend. To reuse the Cairo trapazoid code, the backend can implement
fill by calling a _convert_to_trapazoids function, passing a pointer to
whatever it wants called with the resulting trapazoinds.
More information about the cairo