f8f65870310aa2ae6cf603d925e8aeb7da29e414
[framework/graphics/cairo.git] / TC / perf / image.c
1 /*
2  * Cairo Performance Test Framework
3  * (c) 2012 Samsung Electronics, Inc.
4  * All rights reserved.
5  *
6  * Measures rendering performance for image, gl backends
7  *
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.
12  *
13  * Author: Dongyeon Kim <dy5.kim@samsung.com>
14  */
15
16 #include "common.h"
17
18 #define RENDER_LOOP 100
19
20 extern int WIDTH, HEIGHT;
21
22 extern cairo_device_t *cairo_device;
23 cairo_pattern_t *pattern1, *pattern2;
24 int image_width, image_height;
25
26 int preRender(cairo_t *cr)
27 {
28     { // Image 1
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);
32
33         if(cairo_surface_get_type(cairo_get_target(cr)) == CAIRO_SURFACE_TYPE_IMAGE) {
34             pattern1 = cairo_pattern_create_for_surface(image_surface);
35         } else {
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);
40             cairo_paint(cr_gl);
41
42             pattern1 = cairo_pattern_create_for_surface(gl_surface);
43
44             cairo_surface_destroy(gl_surface);
45             cairo_destroy(cr_gl);
46         }
47         cairo_surface_destroy(image_surface);
48     }
49     { // Image 2
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);
53
54         if(cairo_surface_get_type(cairo_get_target(cr)) == CAIRO_SURFACE_TYPE_IMAGE) {
55             pattern2 = cairo_pattern_create_for_surface(image_surface);
56         } else {
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);
61             cairo_paint(cr_gl);
62
63             pattern2 = cairo_pattern_create_for_surface(gl_surface);
64
65             cairo_surface_destroy(gl_surface);
66             cairo_destroy(cr_gl);
67         }
68         cairo_surface_destroy(image_surface);
69     }
70
71     return 1;
72 }
73
74 int render(cairo_t *cr)
75 {
76     int i;
77
78     clearCairo(cr, WIDTH, HEIGHT);
79     cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
80
81     for(i = 0; i < RENDER_LOOP; i++)
82     {
83         float x = drand48() * WIDTH - image_width / 2;
84         float y = drand48() * HEIGHT - image_height / 2;
85         int index = drand48() * 2;
86
87         cairo_identity_matrix(cr);
88         cairo_translate(cr, x, y);
89         if(index == 0)
90             cairo_set_source(cr, pattern1);
91         else
92             cairo_set_source(cr, pattern2);
93         cairoSquare(cr, 0, 0, image_width);
94     }
95
96     return 1;
97 }
98
99 int postRender(cairo_t *cr)
100 {
101     cairo_pattern_destroy(pattern1);
102     cairo_pattern_destroy(pattern2);
103     return 1;
104 }
105