Upload Tizen2.0 source
[framework/graphics/cairo.git] / TC / perf / stroke.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 int preRender(cairo_t *cr)
23 {
24     return 1;
25 }
26
27 int render(cairo_t *cr)
28 {
29     int i;
30     double r, g, b, a;
31
32     clearCairo(cr, WIDTH, HEIGHT);
33     cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
34
35     for(i = 0; i < RENDER_LOOP; i++)
36     {
37         r = drand48();
38         g = drand48();
39         b = drand48();
40         a = drand48();
41         float x = drand48() * WIDTH;
42         float y = drand48() * HEIGHT;
43         float side = drand48() * 300;
44         int shape = drand48() *3;
45         float width = drand48() * 50 + 1;
46         int line_cap = drand48() * 3;
47         cairo_line_cap_t line_cap_style = CAIRO_LINE_CAP_BUTT;
48         if(line_cap == 1)
49             line_cap_style = CAIRO_LINE_CAP_ROUND;
50         else if(line_cap == 2)
51             line_cap_style = CAIRO_LINE_CAP_SQUARE;
52         int line_join = drand48() * 3;
53         cairo_line_join_t line_join_style = CAIRO_LINE_JOIN_MITER;
54         if(line_join == 1)
55             line_join_style = CAIRO_LINE_JOIN_ROUND;
56         else if(line_join == 2)
57             line_join_style = CAIRO_LINE_JOIN_BEVEL;
58
59         double dash[] = {0.0, 0.0};
60         dash[0] = drand48() * 50;
61         dash[1] = drand48() * 50;
62
63         cairo_set_dash(cr, dash, 2, 0);
64         cairo_set_line_width(cr, width);
65         cairo_set_line_join(cr, line_join_style);
66         cairo_set_line_cap(cr, line_cap_style);
67
68         cairo_set_source_rgba(cr, r, g, b, a);
69
70         if(shape == 0)
71             cairoSquareStroke(cr, x, y, side);
72         else if(shape == 1)
73             cairoCircleStroke(cr, x, y, side/2);
74         else
75             cairoTriangleStroke(cr, x, y, side);
76     }
77
78     return 1;
79 }
80
81 int postRender(cairo_t *cr)
82 {
83     return 1;
84 }
85