[cairo] set_source_rgb vs set_source_rgba [Performance]

Jeff Muizelaar jeff at infidigm.net
Fri Aug 15 08:36:23 PDT 2008


On Fri, Aug 15, 2008 at 11:59:16AM -0300, Ian Britten wrote:
> Hi all,
> When drawing solid colours (Alpha=1.0), is there any performance
> benefit to using set_source_rgb() as opposed to set_source_rgba()?

There is potentially a performance advantage. i.e. cairo creates
a CAIRO_CONTENT_COLOR_ALPHA pattern instead of a CAIRO_CONTENT_COLOR
pattern. It is possible that whatever backend is being used optimizes
the difference.
> 
> I'm wondering whether to add the complexity to my code to
> distinguish the two cases and make the appropriate calls, or
> whether simply calling set_source_rgba() all the time will
> automatically fall back to same behaviour?
> [ Obviously, rendering speed is a concern, and I'll add the
> complexity to our code, if there's a benefit ]

Arguably cairo could do this optimization itself. It's a question of
where the smarts belong, in the calling application or cairo. I'm sure
opinions on this vary.

-Jeff


More information about the cairo mailing list