[cairo] Text Grid Performance

Gerdus van Zyl gerdusvanzyl at gmail.com
Wed Feb 27 11:30:21 PST 2008


For future reference the main problem was that I was relying on
pop_group/push_group for double buffering.

This is a mistake since push/pop-group calls create_similar internally
but requests an color+alpha surface. On Windows this creates a Device
Independent Bitmap instead of a Device Dependant Bitmap that is much
faster. YMMV but in my app the FPS increased from 9-14 FPS to 40-55
FPS.

[code]
from
-----------------------------------------------------
surf = cairo.Win32Surface(hdc)
ctx = cairo.Context(surf)

ctx.push_group()

/* Rendering code using ctx */

ctx.pop_group_to_source()
ctx.paint()
-----------------------------------------------------
to
-----------------------------------------------------
surf = cairo.Win32Surface(_buffer)
ctx = cairo.Context(surf)

surfB = surf.create_similar(cairo.CONTENT_COLOR,cw,ch)
ctxB = cairo.Context(surfB)

/* Rendering code using ctxB*/

ctx.set_source_surface(surfB)
ctx.paint()
-----------------------------------------------------

Please note my case was the double buffering of a window other use
cases will differ.

~Gerdus

On Thu, Feb 7, 2008 at 10:02 AM, Gerdus van Zyl <gerdusvanzyl at gmail.com> wrote:
> I have again gone over my application with a fine tooth comb and found
>  some problems like not reusing the offscreen surface, etc. Also
>  stripped down the code, predictably it's faster.
>  What I did not expect was the large difference between using pango and
>  the toy text API.
>  pango - 0.08s - 11fps (much better than last time)
>  toyapi - 0.03s - 30fps (perfect)
>
>  Is there a way to speed up pango? I would love to use pango everywhere
>  since the toyapi is so limited. Otherwise i will just use the toyapi
>  where speed is of the essence and pango everywhere else. See my text
>  code below that gave the results above:
>
>  ctx.set_source_rgb(0,0,0)
>  if True:
>     ctx.select_font_face("Arial",cairo.FONT_SLANT_NORMAL,
>  cairo.FONT_WEIGHT_NORMAL)
>     ctx.set_font_size(10)
>     ctx.move_to(5,10)
>     ctx.show_text(self.text)
>  else:
>     ctx.move_to(0,0)
>     cr = pangocairo.CairoContext(ctx)
>     layout = cr.create_layout()
>     layout.set_text(self.text)
>     layout.set_font_description(pango.FontDescription("Arial, 8"))
>     cr.show_layout(layout)
>
>  Thank you.
>
>  ~GerdusVZ
>


More information about the cairo mailing list