Upload Tizen2.0 source
[framework/graphics/cairo.git] / perf / micro / disjoint.c
1 /* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
2 /* cairo - a vector graphics library with display and print output
3  *
4  * Copyright (c) 2011 Intel Corporation
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #include <assert.h>
28 #include "cairo-perf.h"
29
30 #define STEP    5
31
32 static void path (cairo_t *cr, int width, int height)
33 {
34     int i;
35
36     cairo_rectangle (cr, 0, 0, width, height);
37     cairo_clip (cr);
38
39     cairo_translate (cr, width/2, height/2);
40     cairo_rotate (cr, M_PI/4);
41     cairo_translate (cr, -width/2, -height/2);
42
43     for (i = 0; i < width; i += STEP) {
44         cairo_rectangle (cr, i, -2, 1, height+4);
45         cairo_rectangle (cr, -2, i, width+4, 1);
46     }
47 }
48
49 static void clip (cairo_t *cr, int width, int height)
50 {
51     int i, j;
52
53     for (j = 0; j < height; j += 2*STEP) {
54         for (i = 0; i < width; i += 2*STEP)
55             cairo_rectangle (cr, i, j, STEP, STEP);
56
57         j += 2*STEP;
58         for (i = 0; i < width; i += 2*STEP)
59             cairo_rectangle (cr, i+STEP/2, j, STEP, STEP);
60     }
61
62     cairo_clip (cr);
63 }
64
65 static cairo_time_t
66 draw (cairo_t *cr, int width, int height, int loops)
67 {
68     cairo_save (cr);
69     cairo_set_source_rgb (cr, 1, 1, 1);
70     cairo_paint (cr);
71     cairo_set_source_rgb (cr, 1, 0, 0);
72
73     cairo_perf_timer_start ();
74     cairo_perf_set_thread_aware (cr, FALSE);
75     while (loops--) {
76         if (loops == 0)
77             cairo_perf_set_thread_aware (cr, TRUE);
78         cairo_save (cr);
79         clip (cr, width, height);
80         path (cr, width, height);
81         cairo_fill (cr);
82         cairo_restore (cr);
83     }
84
85     cairo_perf_timer_stop ();
86
87     cairo_restore (cr);
88
89     return cairo_perf_timer_elapsed ();
90 }
91
92 cairo_bool_t
93 disjoint_enabled (cairo_perf_t *perf)
94 {
95     return cairo_perf_can_run (perf, "disjoint", NULL);
96 }
97
98 void
99 disjoint (cairo_perf_t *perf, cairo_t *cr, int width, int height)
100 {
101     if (! cairo_perf_can_run (perf, "disjoint", NULL))
102         return;
103
104     cairo_perf_run (perf, "disjoint", draw, NULL);
105 }