[cairo] Re: Lander Game
in7y118 at public.uni-hamburg.de
Tue Jan 9 10:33:42 PST 2007
On Tue, 9 Jan 2007, Owen Taylor wrote:
> On the other hand, there's no reason cairo shouldn't be fast enough
> to do full-frame-rate rendering from scratch of most things. After all,
> that's how 3D games work! While the stuff cairo is doing isn't going to
> be as well matched by the hardware, there's a lot of cycles in 1/30th
> of a second these days...
After hacking on swfdec and trying to render Flash movies with cairo, I
can tell you that unless you use the full magic of OpenGL on dedicated
hardware, what you can do in 1/30th of a second is very little.
If you try to render 320x200 pixels with 10 layers on recent hardware,
you'll probably start to sweat already. I have no clue if you get to
30fps. But my 1GHz iBook will definitely not reach 10fps. As of cairo
1.3 this is no longer a tesselation issue, but the fact that alpha
compositing in the X server will eat your cycles. With cairo 1.2 you will
not even reach 5fps as your time is spent tesselating. That's at least
from my benchmarks a few weeks ago (cairo 1.3.8, so i.e. the long lines
issue was still present, no clue how much that influenced the result).
The most important thing I learned when trying to speed up swfdec was
Avoid drawing at all costs.
It's a lot of work to handle invalidation of objects in your
display, especially with multiple layers that overlap. But if you only
need to redraw the 100x100 pixels where your space ship moved instead of
the 1024x768 pixels of the whole screen, your code just got 70x faster.
And you won't get 70x speedup by caching traps - not with cairo 1.3.
Also, if an object is outside the invalid area (or outside the screen),
make sure to not draw it.
Another thing that I learned is that caching surfaces is hard. Or it
limits what you can do with your API. Swfdec has a call like this:
swfdec_player_render (SwfdecPlayer *player, cairo_t *cr)
So my surface caching code has to check that the matrix is still the
same, the target is actually compatible with the cache, and probably lots
of other things. Also, caching lots of layers can easily become a memory
management problem, and if I'm not careful in that case, I end up
using more time than before, because you cache stuff and then free it
again because memory is limited.
But I get almost realtime on my iBook with the rather simple Flash movies
that swfdec manages to decode these days, so I'm happy and hope that X
gets faster before I need to invent more sophisticated caching methods.
More information about the cairo