Upload Tizen2.0 source
[framework/graphics/cairo.git] / perf / micro / fill-clip.c
1 /*
2  * Copyright © 2011 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  * Author: Chris Wilson <chris@chris-wilson.co.uk>
25  */
26
27 /* Compares the overhead for WebKit's drawRect() */
28
29 #include "cairo-perf.h"
30
31 #include <pixman.h>
32
33 static cairo_time_t
34 clip_paint (cairo_t *cr, int width, int height, int loops)
35 {
36     int x = width/4, w = width/2;
37     int y = height/4, h = height/2;
38
39     cairo_perf_timer_start ();
40     cairo_perf_set_thread_aware (cr, FALSE);
41
42     while (loops--) {
43         if (loops == 0)
44                 cairo_perf_set_thread_aware (cr, TRUE);
45         cairo_reset_clip (cr);
46         cairo_rectangle (cr, x, y, w, h);
47         cairo_clip (cr);
48         cairo_paint (cr);
49     }
50
51     cairo_perf_timer_stop ();
52
53     return cairo_perf_timer_elapsed ();
54 }
55
56 static cairo_time_t
57 rect_fill (cairo_t *cr, int width, int height, int loops)
58 {
59     int x = width/4, w = width/2;
60     int y = height/4, h = height/2;
61
62     cairo_perf_timer_start ();
63     cairo_perf_set_thread_aware (cr, FALSE);
64
65     while (loops--) {
66         if (loops == 0)
67                 cairo_perf_set_thread_aware (cr, TRUE);
68         cairo_rectangle (cr, x, y, w, h);
69         cairo_fill (cr);
70     }
71
72     cairo_perf_timer_stop ();
73
74     return cairo_perf_timer_elapsed ();
75 }
76
77 static cairo_time_t
78 direct (cairo_t *cr, int width, int height, int loops)
79 {
80     int x = width/4, w = width/2;
81     int y = height/4, h = height/2;
82     cairo_surface_t *surface, *image;
83     uint8_t *data;
84     int stride, bpp;
85
86
87     surface = cairo_get_target (cr);
88     image = cairo_surface_map_to_image (surface, NULL);
89     data = cairo_image_surface_get_data (image);
90     stride = cairo_image_surface_get_stride (image);
91
92     switch (cairo_image_surface_get_format (image)) {
93     default:
94     case CAIRO_FORMAT_INVALID:
95     case CAIRO_FORMAT_A1: bpp = 0; break;
96     case CAIRO_FORMAT_A8: bpp = 8; break;
97     case CAIRO_FORMAT_RGB16_565: bpp = 16; break;
98     case CAIRO_FORMAT_RGB24:
99     case CAIRO_FORMAT_RGB30:
100     case CAIRO_FORMAT_ARGB32: bpp = 32; break;
101     }
102
103     cairo_perf_timer_start ();
104     cairo_perf_set_thread_aware (cr, FALSE);
105
106     while (loops--) {
107         if (loops == 0)
108                 cairo_perf_set_thread_aware (cr, TRUE);
109         pixman_fill ((uint32_t *)data, stride / sizeof(uint32_t), bpp,
110                      x, y, w, h,
111                      -1);
112     }
113
114     cairo_perf_timer_stop ();
115
116     cairo_surface_unmap_image (surface, image);
117
118     return cairo_perf_timer_elapsed ();
119 }
120
121 cairo_bool_t
122 fill_clip_enabled (cairo_perf_t *perf)
123 {
124     return cairo_perf_can_run (perf, "fillclip", NULL);
125 }
126
127 void
128 fill_clip (cairo_perf_t *perf, cairo_t *cr, int width, int height)
129 {
130     cairo_set_source_rgb (cr, 1., 1., 1.);
131
132     cairo_perf_run (perf, "fillclip-clip", clip_paint, NULL);
133     cairo_perf_run (perf, "fillclip-fill", rect_fill, NULL);
134     cairo_perf_run (perf, "fillclip-direct", direct, NULL);
135 }