Git init
[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
41     while (loops--) {
42         cairo_reset_clip (cr);
43         cairo_rectangle (cr, x, y, w, h);
44         cairo_clip (cr);
45         cairo_paint (cr);
46     }
47
48     cairo_perf_timer_stop ();
49
50     return cairo_perf_timer_elapsed ();
51 }
52
53 static cairo_time_t
54 rect_fill (cairo_t *cr, int width, int height, int loops)
55 {
56     int x = width/4, w = width/2;
57     int y = height/4, h = height/2;
58
59     cairo_perf_timer_start ();
60
61     while (loops--) {
62         cairo_rectangle (cr, x, y, w, h);
63         cairo_fill (cr);
64     }
65
66     cairo_perf_timer_stop ();
67
68     return cairo_perf_timer_elapsed ();
69 }
70
71 static cairo_time_t
72 direct (cairo_t *cr, int width, int height, int loops)
73 {
74     int x = width/4, w = width/2;
75     int y = height/4, h = height/2;
76     cairo_surface_t *surface, *image;
77     uint8_t *data;
78     int stride, bpp;
79
80
81     surface = cairo_get_target (cr);
82     image = cairo_surface_map_to_image (surface, NULL);
83     data = cairo_image_surface_get_data (image);
84     stride = cairo_image_surface_get_stride (image);
85
86     switch (cairo_image_surface_get_format (image)) {
87     default:
88     case CAIRO_FORMAT_INVALID:
89     case CAIRO_FORMAT_A1: bpp = 0; break;
90     case CAIRO_FORMAT_A8: bpp = 8; break;
91     case CAIRO_FORMAT_RGB16_565: bpp = 16; break;
92     case CAIRO_FORMAT_RGB24:
93     case CAIRO_FORMAT_RGB30:
94     case CAIRO_FORMAT_ARGB32: bpp = 32; break;
95     }
96
97     cairo_perf_timer_start ();
98
99     while (loops--) {
100         pixman_fill ((uint32_t *)data, stride / sizeof(uint32_t), bpp,
101                      x, y, w, h,
102                      -1);
103     }
104
105     cairo_perf_timer_stop ();
106
107     cairo_surface_unmap_image (surface, image);
108
109     return cairo_perf_timer_elapsed ();
110 }
111
112 cairo_bool_t
113 fill_clip_enabled (cairo_perf_t *perf)
114 {
115     return cairo_perf_can_run (perf, "fillclip", NULL);
116 }
117
118 void
119 fill_clip (cairo_perf_t *perf, cairo_t *cr, int width, int height)
120 {
121     cairo_set_source_rgb (cr, 1., 1., 1.);
122
123     cairo_perf_run (perf, "fillclip-clip", clip_paint, NULL);
124     cairo_perf_run (perf, "fillclip-fill", rect_fill, NULL);
125     cairo_perf_run (perf, "fillclip-direct", direct, NULL);
126 }