2 * Copyright © 2011 Intel Corporation
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 * Author: Chris Wilson <chris@chris-wilson.co.uk>
27 /* Compares the overhead for WebKit's drawRect() */
29 #include "cairo-perf.h"
34 clip_paint (cairo_t *cr, int width, int height, int loops)
36 int x = width/4, w = width/2;
37 int y = height/4, h = height/2;
39 cairo_perf_timer_start ();
40 cairo_perf_set_thread_aware (cr, FALSE);
44 cairo_perf_set_thread_aware (cr, TRUE);
45 cairo_reset_clip (cr);
46 cairo_rectangle (cr, x, y, w, h);
51 cairo_perf_timer_stop ();
53 return cairo_perf_timer_elapsed ();
57 rect_fill (cairo_t *cr, int width, int height, int loops)
59 int x = width/4, w = width/2;
60 int y = height/4, h = height/2;
62 cairo_perf_timer_start ();
63 cairo_perf_set_thread_aware (cr, FALSE);
67 cairo_perf_set_thread_aware (cr, TRUE);
68 cairo_rectangle (cr, x, y, w, h);
72 cairo_perf_timer_stop ();
74 return cairo_perf_timer_elapsed ();
78 direct (cairo_t *cr, int width, int height, int loops)
80 int x = width/4, w = width/2;
81 int y = height/4, h = height/2;
82 cairo_surface_t *surface, *image;
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);
92 switch (cairo_image_surface_get_format (image)) {
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;
103 cairo_perf_timer_start ();
104 cairo_perf_set_thread_aware (cr, FALSE);
108 cairo_perf_set_thread_aware (cr, TRUE);
109 pixman_fill ((uint32_t *)data, stride / sizeof(uint32_t), bpp,
114 cairo_perf_timer_stop ();
116 cairo_surface_unmap_image (surface, image);
118 return cairo_perf_timer_elapsed ();
122 fill_clip_enabled (cairo_perf_t *perf)
124 return cairo_perf_can_run (perf, "fillclip", NULL);
128 fill_clip (cairo_perf_t *perf, cairo_t *cr, int width, int height)
130 cairo_set_source_rgb (cr, 1., 1., 1.);
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);