2 * Copyright 2011 Red Hat Inc.
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: Benjamin Otte <otte@redhat.com>
27 #include "cairo-perf.h"
29 static cairo_surface_t *
30 generate_random_waveform(cairo_t *target, int width, int height)
32 cairo_surface_t *surface;
38 surface = cairo_surface_create_similar (cairo_get_target (target),
41 cr = cairo_create (surface);
45 for (i = 0; i < width; i++)
47 r += rand () % (height / 4) - (height / 8);
52 cairo_rectangle (cr, i, (height - r) / 2, 1, r);
61 do_wave (cairo_t *cr, int width, int height, int loops)
63 cairo_surface_t *wave;
64 cairo_pattern_t *mask;
66 wave = generate_random_waveform (cr, width, height);
68 cairo_perf_timer_start ();
69 cairo_perf_set_thread_aware (cr, FALSE);
73 cairo_perf_set_thread_aware (cr, TRUE);
74 /* paint outline (and contents) */
75 cairo_set_source_rgb (cr, 1, 0, 0);
76 cairo_mask_surface (cr, wave, 0, 0);
79 /* first, create a mask */
80 cairo_push_group_with_content (cr, CAIRO_CONTENT_ALPHA);
81 cairo_set_source_surface (cr, wave, 0, 0);
83 cairo_set_operator (cr, CAIRO_OPERATOR_IN);
84 cairo_set_source_surface (cr, wave, 1, 0);
86 cairo_set_source_surface (cr, wave, -1, 0);
88 cairo_set_source_surface (cr, wave, 0, 1);
90 cairo_set_source_surface (cr, wave, 0, -1);
92 mask = cairo_pop_group (cr);
94 /* second, paint the mask */
95 cairo_set_source_rgb (cr, 0, 1, 0);
96 cairo_mask (cr, mask);
98 cairo_pattern_destroy (mask);
101 cairo_perf_timer_stop ();
103 cairo_surface_destroy (wave);
105 return cairo_perf_timer_elapsed ();
109 wave_enabled (cairo_perf_t *perf)
111 return cairo_perf_can_run (perf, "wave", NULL);
115 wave (cairo_perf_t *perf, cairo_t *cr, int width, int height)
117 cairo_perf_run (perf, "wave", do_wave, NULL);