[cairo] A Couple of questions about text
chris at chris-wilson.co.uk
Wed Apr 21 01:01:26 PDT 2010
On Tue, 20 Apr 2010 23:57:55 -0300, JerÃ³nimo Barraco <jerobarraco at yahoo.com.ar> wrote:
> Hello, my name is JerÃ³nimo this is the first time i write to the list.
> I've been searching for some information but couldn't find what i was
> looking for, so i wanna ask kindly if someone here can answer me some
> I'm doing a software wich renders animated text over a video, it basically
> re-renders everything for every frame, so is very cpu-intensive.
> also, the context get recreated every frame (is because i need to use the
> video buffer).
Contexts are cheap. Setting properties on contexts, also cheap. Recreating
a context per frame is a good pattern. Surfaces are 'expensive' and thus
longer lived that persist over contexts (a very rough rule of thumb, but
they also are very often created on demand and used as masks and
> I was trying this approach, every frame i set every property (font size
> and colours) and then render the text using text_path.
> I've tried caching the path using ctx.copy_path, but seems slower.
> And i emulate some things like blur and particles using patterns and
> * Does cairo cache the path for text, so when i call text_path is actually
> faster than calling append_path with the previous copy?
> * Its faster to use a surface for repetitive painting or converting it to
> a pattern? (i use this for blur, with get_group_target)
> * Creating a matrix object doesnt requiere a lot of cpu time, right?
So it seems to me that you have dived into performance tuning without
profiling first. Use something like perf and it will show more precisely
the hot spots to work on first, or to adjust the code to avoid entirely.
In the first place, without knowing too many details, I would strongly
suggest that text_path is not the approach to take. If possibly use
show_text as that caches the pre-rendered glyphs and is far faster.
> and a lot more but those are the most important.
> If someone want to take a look at the software or the code to understand
> more, please ask me.
One method for sharing complex sequences is to use cairo-trace which will
record all the cairo operations performed and enable us to not only read
what you are doing but also replay and profile your drawing code without
the overhead (or requirements) of actually running your program.
However, since you are also doing things that are currently out-of-scope
for cairo, the picture it presents will be myopic. But baby steps first.
Have fun using Cairo!
Chris Wilson, Intel Open Source Technology Centre
More information about the cairo