2 * Cairo Performance Test Framework
3 * (c) 2012 Samsung Electronics, Inc.
6 * Measures rendering performance for image, gl backends
8 * This software is a confidential and proprietary information of Samsung
9 * Electronics, Inc. ("Confidential Information"). You shall not disclose such
10 * Confidential Information and shall use it only in accordance with the terms
11 * of the license agreement you entered into with Samsung Electronics.
13 * Author: Dongyeon Kim <dy5.kim@samsung.com>
18 #define RENDER_LOOP 100
20 extern int WIDTH, HEIGHT;
22 extern cairo_device_t *cairo_device;
23 cairo_pattern_t *pattern1, *pattern2;
24 int image_width, image_height;
26 int preRender(cairo_t *cr)
29 cairo_surface_t *image_surface = cairo_image_surface_create_from_png("./image1.png");
30 image_width = cairo_image_surface_get_width(image_surface);
31 image_height = cairo_image_surface_get_height(image_surface);
33 if(cairo_surface_get_type(cairo_get_target(cr)) == CAIRO_SURFACE_TYPE_IMAGE) {
34 pattern1 = cairo_pattern_create_for_surface(image_surface);
36 cairo_surface_t *gl_surface = cairo_gl_surface_create(cairo_device, CAIRO_CONTENT_COLOR_ALPHA,
37 image_width, image_height);
38 cairo_t *cr_gl = cairo_create(gl_surface);
39 cairo_set_source_surface(cr_gl, image_surface, 0, 0);
42 pattern1 = cairo_pattern_create_for_surface(gl_surface);
44 cairo_surface_destroy(gl_surface);
47 cairo_surface_destroy(image_surface);
50 cairo_surface_t *image_surface = cairo_image_surface_create_from_png("./image2.png");
51 image_width = cairo_image_surface_get_width(image_surface);
52 image_height = cairo_image_surface_get_height(image_surface);
54 if(cairo_surface_get_type(cairo_get_target(cr)) == CAIRO_SURFACE_TYPE_IMAGE) {
55 pattern2 = cairo_pattern_create_for_surface(image_surface);
57 cairo_surface_t *gl_surface = cairo_gl_surface_create(cairo_device, CAIRO_CONTENT_COLOR_ALPHA,
58 image_width, image_height);
59 cairo_t *cr_gl = cairo_create(gl_surface);
60 cairo_set_source_surface(cr_gl, image_surface, 0, 0);
63 pattern2 = cairo_pattern_create_for_surface(gl_surface);
65 cairo_surface_destroy(gl_surface);
68 cairo_surface_destroy(image_surface);
74 int render(cairo_t *cr)
78 clearCairo(cr, WIDTH, HEIGHT);
79 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
81 for(i = 0; i < RENDER_LOOP; i++)
83 float x = drand48() * WIDTH - image_width / 2;
84 float y = drand48() * HEIGHT - image_height / 2;
85 int index = drand48() * 2;
87 cairo_identity_matrix(cr);
88 cairo_translate(cr, x, y);
90 cairo_set_source(cr, pattern1);
92 cairo_set_source(cr, pattern2);
93 cairoSquare(cr, 0, 0, image_width);
99 int postRender(cairo_t *cr)
101 cairo_pattern_destroy(pattern1);
102 cairo_pattern_destroy(pattern2);