[cairo] Using the recording surface as a kind of display list

Torsten Landschoff t.landschoff at gmx.net
Wed May 4 15:16:03 PDT 2011


Hi list,

I just tried to use the cairo recording surface as a kind of display 
list to speed up repeated display. My app is written in Python and I 
wanted to get rid of the Python overhead in redisplay for zooming and 
panning.

Perhaps I misunderstood the recording surface. My approach is to render 
my stuff to an unbounded recording surface and render that to the GUI. 
Mostly like an OpenGL display list.

As PyCairo does not seem to support recording surfaces yet, I wrote a 
patch and filed it as a bug:

https://bugs.freedesktop.org/show_bug.cgi?id=36854

With that patch, I tried running the attached Python code. Please 
forgive the sloppy code, it is late and I am running out of motivation...

When running this code, I first get this error:

Traceback (most recent call last):

    File "recording_surface_demo.py", line 113, in OnPaint

      cr.paint()

MemoryError

The stacktrace in gdb to the _cairo_error call is this:

#0  _cairo_error (status=CAIRO_STATUS_INVALID_SIZE) at cairo.c:177

#1  0x00007fffefc61718 in _cairo_image_surface_create_with_pixman_format 
(data=0x0, pixman_format=PIXMAN_a8r8g8b8, width=-350097328, 
height=32767, stride=-1)

      at cairo-image-surface.c:331

#2  0x00007fffefc6180a in *INT_cairo_image_surface_create 
(format=CAIRO_FORMAT_ARGB32, width=-350097328, height=32767) at 
cairo-image-surface.c:384

#3  0x00007fffefc61836 in _cairo_image_surface_create_with_content 
(content=CAIRO_CONTENT_COLOR_ALPHA, width=-350097328, height=32767) at 
cairo-image-surface.c:394

#4  0x00007fffefc88342 in 
_cairo_recording_surface_acquire_source_image_transformed 
(abstract_surface=0xed96f0, device_transform=0x19da778, 
image_out=0x7fffffffb598,

      image_extra=0x7fffffffb590) at cairo-recording-surface.c:273

#5  0x00007fffefc97bcf in 
_cairo_surface_acquire_source_image_transformed (surface=0xed96f0, 
device_transform=0x19da778, image_out=0x7fffffffb598, 
image_extra=0x7fffffffb590)

      at cairo-surface.c:1483

#6  0x00007fffefc62e18 in _pixman_image_for_surface 
(pattern=0x7fffffffc350, is_mask=0, extents=0x7fffffffb770, 
dst_device_transform=0x19da778, ix=0x7fffffffb76c, iy=

      0x7fffffffb768) at cairo-image-surface.c:1452

#7  0x00007fffefc63372 in _pixman_image_for_pattern 
(pattern=0x7fffffffc350, is_mask=0, extents=0x7fffffffb770, 
dst_device_transform=0x19da778, tx=0x7fffffffb76c, ty=

      0x7fffffffb768) at cairo-image-surface.c:1613

#8  0x00007fffefc692ce in _cairo_image_surface_composite 
(op=CAIRO_OPERATOR_OVER, src_pattern=0x7fffffffc350, mask_pattern=0x0, 
abstract_dst=0x19da720, src_x=0, src_y=28,

      mask_x=0, mask_y=0, dst_x=0, dst_y=0, width=798, height=598, 
clip_region=0x0) at cairo-image-surface.c:4219

It seems like Cairo is using some random size for creating an image from 
the contents of the recorded surface. What's even more weird: There are 
a number of cairo internal errors, of which only the memory error is 
propagated. As you can see from the backtrace, the original error is 
about INVALID_SIZE.

Funny enough, when refreshing the canvas content, I actually get the 
following Python error:

Traceback (most recent call last):
    File "recording_surface_demo.py", line 112, in OnPaint
      cr.set_source_surface(self._displaylist, 0, 0)
cairo.Error: invalid value (typically too big) for the size of the input 
(surface, pattern, etc.)

This looks more sensible, but I still do not know what I am doing wrong. 
I tried passing the extents parameter to the RecordingSurface 
constructor, but at that time I have no idea about the size of the final 
bitmap. The whole idea is to record the vector graphic and have cairo 
scale it at drawing time.

Final note: When using a PDF Surface instead of the recording surface, 
the code at least runs. However, there is nothing drawn when using the 
recorded surface.

Any hints greatly appreciated.

Greetings, Torsten


-------------- next part --------------
A non-text attachment was scrubbed...
Name: recording_surface_demo.py
Type: text/x-python
Size: 5411 bytes
Desc: not available
URL: <http://lists.cairographics.org/archives/cairo/attachments/20110505/0b92a377/attachment.py>


More information about the cairo mailing list