2007-01-03 16:27:52 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2006 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Author: Carl D. Worth <cworth@cworth.org>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "cairo-perf.h"
|
|
|
|
|
|
|
|
|
|
/* This test case is designed to illustrate a performance bug in
|
|
|
|
|
* drawing very long lines, where most of the line is out of bounds of
|
|
|
|
|
* the destination surface, (but some portion of the line is
|
2017-11-09 09:43:02 -05:00
|
|
|
* visible). These results are in the "long-lines-uncropped" report.
|
2007-01-03 16:27:52 -08:00
|
|
|
*
|
|
|
|
|
* For comparison, this test also renders the visible portions of the
|
|
|
|
|
* same lines, (this is the "long-lines-cropped" report).
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-30 10:35:11 +01:00
|
|
|
typedef enum {
|
|
|
|
|
LONG_LINES_CROPPED = 0x1,
|
|
|
|
|
LONG_LINES_ONCE = 0x2,
|
|
|
|
|
} long_lines_crop_t;
|
2007-01-03 16:27:52 -08:00
|
|
|
#define NUM_LINES 20
|
|
|
|
|
#define LONG_FACTOR 50.0
|
|
|
|
|
|
2011-08-31 17:55:07 +02:00
|
|
|
static cairo_time_t
|
2009-08-03 22:23:19 +01:00
|
|
|
do_long_lines (cairo_t *cr, int width, int height, int loops, long_lines_crop_t crop)
|
2007-01-03 16:27:52 -08:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
double x, y, dx, dy, min_x, min_y, max_x, max_y;
|
|
|
|
|
double outer_width, outer_height;
|
|
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
|
|
cairo_translate (cr, width / 2, height / 2);
|
|
|
|
|
|
2009-07-30 10:35:11 +01:00
|
|
|
if (crop & LONG_LINES_CROPPED) {
|
2007-01-03 16:27:52 -08:00
|
|
|
outer_width = width;
|
|
|
|
|
outer_height = height;
|
|
|
|
|
cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); /* green */
|
2009-07-30 10:35:11 +01:00
|
|
|
} else {
|
|
|
|
|
outer_width = LONG_FACTOR * width;
|
|
|
|
|
outer_height = LONG_FACTOR * height;
|
|
|
|
|
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* red */
|
2007-01-03 16:27:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
min_x = x = - outer_width / 2.0;
|
|
|
|
|
min_y = y = - outer_height / 2.0;
|
|
|
|
|
max_x = outer_width / 2.0;
|
2009-07-30 09:36:28 +01:00
|
|
|
max_y = outer_height / 2.0;
|
2007-01-03 16:27:52 -08:00
|
|
|
dx = outer_width / NUM_LINES;
|
|
|
|
|
dy = outer_height / NUM_LINES;
|
|
|
|
|
|
|
|
|
|
cairo_perf_timer_start ();
|
|
|
|
|
|
2009-08-03 22:23:19 +01:00
|
|
|
while (loops--) {
|
|
|
|
|
for (i = 0; i <= NUM_LINES; i++) {
|
|
|
|
|
cairo_move_to (cr, 0, 0);
|
|
|
|
|
cairo_line_to (cr, x, min_y);
|
|
|
|
|
if ((crop & LONG_LINES_ONCE) == 0)
|
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
|
|
cairo_move_to (cr, 0, 0);
|
|
|
|
|
cairo_line_to (cr, x, max_y);
|
|
|
|
|
if ((crop & LONG_LINES_ONCE) == 0)
|
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
|
|
cairo_move_to (cr, 0, 0);
|
|
|
|
|
cairo_line_to (cr, min_x, y);
|
|
|
|
|
if ((crop & LONG_LINES_ONCE) == 0)
|
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
|
|
cairo_move_to (cr, 0, 0);
|
|
|
|
|
cairo_line_to (cr, max_x, y);
|
|
|
|
|
if ((crop & LONG_LINES_ONCE) == 0)
|
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
|
|
x += dx;
|
|
|
|
|
y += dy;
|
|
|
|
|
}
|
|
|
|
|
if (crop & LONG_LINES_ONCE)
|
2009-07-30 10:35:11 +01:00
|
|
|
cairo_stroke (cr);
|
2007-01-03 16:27:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_perf_timer_stop ();
|
|
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
|
|
return cairo_perf_timer_elapsed ();
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-31 17:55:07 +02:00
|
|
|
static cairo_time_t
|
2009-08-03 22:23:19 +01:00
|
|
|
long_lines_uncropped (cairo_t *cr, int width, int height, int loops)
|
2007-01-03 16:27:52 -08:00
|
|
|
{
|
2009-08-03 22:23:19 +01:00
|
|
|
return do_long_lines (cr, width, height, loops, 0);
|
2009-07-30 10:35:11 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-31 17:55:07 +02:00
|
|
|
static cairo_time_t
|
2009-08-03 22:23:19 +01:00
|
|
|
long_lines_uncropped_once (cairo_t *cr, int width, int height, int loops)
|
2009-07-30 10:35:11 +01:00
|
|
|
{
|
2009-08-03 22:23:19 +01:00
|
|
|
return do_long_lines (cr, width, height, loops, LONG_LINES_ONCE);
|
2007-01-03 16:27:52 -08:00
|
|
|
}
|
|
|
|
|
|
2011-08-31 17:55:07 +02:00
|
|
|
static cairo_time_t
|
2009-08-03 22:23:19 +01:00
|
|
|
long_lines_cropped (cairo_t *cr, int width, int height, int loops)
|
2007-01-03 16:27:52 -08:00
|
|
|
{
|
2009-08-03 22:23:19 +01:00
|
|
|
return do_long_lines (cr, width, height, loops, LONG_LINES_CROPPED);
|
2007-01-03 16:27:52 -08:00
|
|
|
}
|
|
|
|
|
|
2011-08-31 17:55:07 +02:00
|
|
|
static cairo_time_t
|
2009-08-03 22:23:19 +01:00
|
|
|
long_lines_cropped_once (cairo_t *cr, int width, int height, int loops)
|
2009-07-30 10:35:11 +01:00
|
|
|
{
|
2009-08-03 22:23:19 +01:00
|
|
|
return do_long_lines (cr, width, height, loops, LONG_LINES_CROPPED | LONG_LINES_ONCE);
|
2009-07-30 10:35:11 +01:00
|
|
|
}
|
|
|
|
|
|
2011-07-30 17:28:21 +01:00
|
|
|
cairo_bool_t
|
|
|
|
|
long_lines_enabled (cairo_perf_t *perf)
|
|
|
|
|
{
|
|
|
|
|
return cairo_perf_can_run (perf, "long-lines", NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-03 16:27:52 -08:00
|
|
|
void
|
|
|
|
|
long_lines (cairo_perf_t *perf, cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
2010-03-30 04:10:28 +01:00
|
|
|
cairo_perf_run (perf, "long-lines-uncropped", long_lines_uncropped, NULL);
|
|
|
|
|
cairo_perf_run (perf, "long-lines-uncropped-once", long_lines_uncropped_once, NULL);
|
|
|
|
|
cairo_perf_run (perf, "long-lines-cropped", long_lines_cropped, NULL);
|
|
|
|
|
cairo_perf_run (perf, "long-lines-cropped-once", long_lines_cropped_once, NULL);
|
2007-01-03 16:27:52 -08:00
|
|
|
}
|