1
/*
2
 * Copyright © 2006 Dan Amelang
3
 *
4
 * Permission to use, copy, modify, distribute, and sell this software
5
 * and its documentation for any purpose is hereby granted without
6
 * fee, provided that the above copyright notice appear in all copies
7
 * and that both that copyright notice and this permission notice
8
 * appear in supporting documentation, and that the name of
9
 * the authors not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. The authors make no representations about the
12
 * suitability of this software for any purpose.  It is provided "as
13
 * is" without express or implied warranty.
14
 *
15
 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
18
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 *
23
 * Authors: Dan Amelang <dan@amelang.net>
24
 *
25
 * This test was originally created to test _cairo_fixed_from_double.
26
 * cairo_pattern_create_radial was selected as the entry point into
27
 * cairo as it makes several calls to _cairo_fixed_from_double and
28
 * presents a somewhat realistic use-case (although the RADIALS_COUNT
29
 * isn't very realistic).
30
 */
31
#include "cairo-perf.h"
32
#include <time.h>
33

            
34
#define RADIALS_COUNT (10000)
35

            
36
static struct
37
{
38
    double cx0;
39
    double cy0;
40
    double radius0;
41
    double cx1;
42
    double cy1;
43
    double radius1;
44
} radials[RADIALS_COUNT];
45

            
46
static double
47
generate_double_in_range (double min, double max)
48
{
49
    double d;
50

            
51
    d = rand () / (double) RAND_MAX;
52
    d *= max - min;
53
    d += min;
54

            
55
    return d;
56
}
57

            
58
static cairo_time_t
59
do_pattern_create_radial (cairo_t *cr, int width, int height, int loops)
60
{
61
    cairo_perf_timer_start ();
62

            
63
    while (loops--) {
64
	cairo_pattern_t *pattern;
65
	int i;
66

            
67
	for (i = 0; i < RADIALS_COUNT; i++) {
68
	    pattern =
69
		cairo_pattern_create_radial (radials[i].cx0, radials[i].cy0,
70
					     radials[i].radius0,
71
					     radials[i].cx1, radials[i].cy1,
72
					     radials[i].radius1);
73
	    cairo_pattern_destroy (pattern);
74
	}
75
    }
76

            
77
    cairo_perf_timer_stop ();
78

            
79
    return cairo_perf_timer_elapsed ();
80
}
81

            
82
cairo_bool_t
83
pattern_create_radial_enabled (cairo_perf_t *perf)
84
{
85
    return cairo_perf_can_run (perf, "pattern-create-radial", NULL);
86
}
87

            
88
void
89
pattern_create_radial (cairo_perf_t *perf, cairo_t *cr, int width, int height)
90
{
91
    int i;
92

            
93
    srand (time (0));
94
    for (i = 0; i < RADIALS_COUNT; i++)
95
    {
96
        radials[i].cx0 = generate_double_in_range (-50000.0, 50000.0);
97
        radials[i].cy0 = generate_double_in_range (-50000.0, 50000.0);
98
        radials[i].radius0 = generate_double_in_range (0.0, 1000.0);
99
        radials[i].cx1 = generate_double_in_range (-50000.0, 50000.0);
100
        radials[i].cy1 = generate_double_in_range (-50000.0, 50000.0);
101
        radials[i].radius1 = generate_double_in_range (0.0, 1000.0);
102
    }
103

            
104
    cairo_perf_run (perf, "pattern-create-radial",
105
                          do_pattern_create_radial, NULL);
106
}