[cairo] [Cairo]Recording suface performance

hyeonji Kim hyeonji1021 at gmail.com
Mon Feb 21 01:05:02 PST 2011


Hi,
I'm developer of mobile browser using webkit with cairo library.
I did performance comparing test between recording surface and image surface
with cairo 1.10.2.
The performance(paint time) of recording surface seems quite low.
I doubt the testing code maybe written wrong and if the test code is right,
I want to know why the recording surface performance is low.

I'd appreciate if you explain how recording surface works when
cairo_paint(dst_cr); is called in recording_surface().
When the operations "replay" for recording surface?
Why cairo_paint(dst_cr) time is different in recording_surface() and
image_surface()?
I wonder the advantage of recording surface over image surface.

Thank you
My testing code was like below :

int image_surface(int num, uint32_t width, uint32_t height)
{
 // Dst Surface
 uint32_t* dst_buffer = create_buffer32(480*800, 0xffff0000);
 cairo_surface_t* dst_surface = cairo_image_surface_create_for_data (
                                                         (unsigned
char*)dst_buffer,

CAIRO_FORMAT_ARGB32,
                                                         480, 800,

cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, 480));
 // Src Surface
 uint32_t* src_buffer = create_buffer32(width*height, 0xff0000ff);
 cairo_surface_t* src_surface = cairo_image_surface_create_for_data (
                                                         (unsigned
char*)src_buffer,

CAIRO_FORMAT_ARGB32,
                                                         width, height,

cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width));
 cairo_t* dst_cr = cairo_create(dst_surface);
 cairo_t* src_cr = cairo_create(src_surface);

 curve_rectangle(src_cr);
 gradient(src_cr);
 fill(src_cr);
 arc(src_cr);
 text(src_cr);
 cairo_paint(src_cr);

 cairo_set_source_surface(dst_cr, src_surface, 0, 0);

 uint64_t sTime = CURRENT_TIME_USEC();
 cairo_paint(dst_cr);
 uint64_t eTime = CURRENT_TIME_USEC();

 uint64_t png_sTime = CURRENT_TIME_USEC();
 cairo_surface_write_to_png(dst_surface,"test.png");
 uint64_t png_eTime = CURRENT_TIME_USEC();

 fprintf(stderr, "[%s] size(%d,%d),paint time(%lld),write png time(%lld)
\n", __FUNCTION__, width,height, (eTime-sTime), (png_eTime-png_sTime));

 cairo_destroy(src_cr);
 cairo_surface_destroy(src_surface);
 cairo_surface_destroy(dst_surface);
 cairo_destroy(dst_cr);
 destroy_buffer32(src_buffer);
 destroy_buffer32(dst_buffer);
}

int recoding_surface(int num, uint32_t width, uint32_t height)
{
 cairo_surface_t *record_surface;
 cairo_t *record_cr;

 // Dst Surface
 uint32_t* dst_buffer = create_buffer32(480*800, 0xffff0000);
 cairo_surface_t* dst_surface = cairo_image_surface_create_for_data (
                                                         (unsigned
char*)dst_buffer,

CAIRO_FORMAT_ARGB32,
                                                         480, 800,

cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, 480));
 // Src Surface
 uint32_t* src_buffer = create_buffer32(width*height, 0xff0000ff);
 cairo_surface_t* src_surface = cairo_image_surface_create_for_data (
                                                         (unsigned
char*)src_buffer,

CAIRO_FORMAT_ARGB32,
                                                         width, height,

cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width));

 cairo_t* dst_cr = cairo_create(dst_surface);
 cairo_t* src_cr = cairo_create(src_surface);
 cairo_rectangle_t extents = { 0, 0, width, height};

 curve_rectangle(src_cr);
 gradient(src_cr);
 fill(src_cr);
 arc(src_cr);
 text(src_cr);
 cairo_paint(src_cr);

 record_surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA,
&extents);
 record_cr = cairo_create (record_surface);

 cairo_set_source_surface (record_cr, src_surface, 0, 0);
 cairo_paint(record_cr);
 cairo_surface_destroy(src_surface);
 cairo_destroy(src_cr);

 cairo_set_source_surface (dst_cr, record_surface, 0, 0);
 uint64_t sTime = CURRENT_TIME_USEC();
 cairo_paint(dst_cr);
 uint64_t eTime = CURRENT_TIME_USEC();

 uint64_t png_sTime = CURRENT_TIME_USEC();
 cairo_surface_write_to_png(dst_surface,"test.png");
 uint64_t png_eTime = CURRENT_TIME_USEC();


 fprintf(stderr, "[%s] size(%d,%d),paint time(%lld),write png time(%lld)
\n", __FUNCTION__, width,height, (eTime-sTime), (png_eTime-png_sTime));

 cairo_surface_destroy(record_surface);
 cairo_destroy(record_cr);

 cairo_surface_destroy(dst_surface);
 cairo_destroy(dst_cr);
 destroy_buffer32(src_buffer);
 destroy_buffer32(dst_buffer);
}

This is test results in linux host :
src_size(2, 2) [image_surface] size(2,2),paint time(6),write png time(32870)

src_size(4, 4) [image_surface] size(4,4),paint time(5),write png time(34295)

src_size(8, 8) [image_surface] size(8,8),paint time(5),write png time(36821)

src_size(16, 16) [image_surface] size(16,16),paint time(3),write png
time(35396)
src_size(32, 32) [image_surface] size(32,32),paint time(7),write png
time(43746)
src_size(64, 64) [image_surface] size(64,64),paint time(12),write png
time(35914)
src_size(128, 128) [image_surface] size(128,128),paint time(31),write png
time(34925)
src_size(256, 256) [image_surface] size(256,256),paint time(42),write png
time(34202)
src_size(480, 480) [image_surface] size(480,480),paint time(133),write png
time(35698)
src_size(480, 640) [image_surface] size(480,640),paint time(175),write png
time(34986)
src_size(480, 800) [image_surface] size(480,800),paint time(219),write png
time(34949)
-----------------------------------------------------------------------------------------------------------------------------
src_size(2, 2) [recoding_surface] size(2,2),paint time(19),write png
time(33206)
src_size(4, 4) [recoding_surface] size(4,4),paint time(7),write png
time(33482)
src_size(8, 8) [recoding_surface] size(8,8),paint time(14),write png
time(39522)
src_size(16, 16) [recoding_surface] size(16,16),paint time(16),write png
time(37932)
src_size(32, 32) [recoding_surface] size(32,32),paint time(19),write png
time(37256)
src_size(64, 64) [recoding_surface] size(64,64),paint time(31),write png
time(36909)
src_size(128, 128) [recoding_surface] size(128,128),paint time(73),write png
time(34764)
src_size(256, 256) [recoding_surface] size(256,256),paint time(141),write
png time(34244)
src_size(480, 480) [recoding_surface] size(480,480),paint time(537),write
png time(34879)
src_size(480, 640) [recoding_surface] size(480,640),paint time(722),write
png time(35424)
src_size(480, 800) [recoding_surface] size(480,800),paint time(891),write
png time(34894)

Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20110221/97db853a/attachment.htm>


More information about the cairo mailing list