2006-08-31 07:19:05 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2006 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
* appear in supporting documentation, and that the name of
|
|
|
|
|
* Red Hat, Inc. not be used in advertising or publicity pertaining to
|
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
|
* permission. Red Hat, Inc. makes no representations about the
|
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
|
|
|
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Author: Carl D. Worth <cworth@cworth.org>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "cairo-perf.h"
|
|
|
|
|
|
2006-09-06 00:15:49 -07:00
|
|
|
static cairo_perf_ticks_t
|
2006-09-06 00:53:52 -07:00
|
|
|
do_paint (cairo_t *cr, int size)
|
2006-08-31 07:19:05 -07:00
|
|
|
{
|
2006-09-05 22:58:33 -07:00
|
|
|
cairo_perf_timer_start ();
|
2006-08-31 17:43:40 -07:00
|
|
|
|
2006-10-03 17:27:27 -07:00
|
|
|
cairo_paint (cr);
|
2006-08-31 11:42:51 -07:00
|
|
|
|
2006-09-05 22:58:33 -07:00
|
|
|
cairo_perf_timer_stop ();
|
2006-08-31 17:43:40 -07:00
|
|
|
|
2006-09-06 00:15:49 -07:00
|
|
|
return cairo_perf_timer_elapsed ();
|
2006-08-31 07:19:05 -07:00
|
|
|
}
|
|
|
|
|
|
2006-09-14 12:59:31 -07:00
|
|
|
/*
|
|
|
|
|
* paint with solid color
|
|
|
|
|
*/
|
|
|
|
|
|
2006-09-29 16:42:44 -07:00
|
|
|
static cairo_perf_ticks_t
|
2006-09-14 12:59:31 -07:00
|
|
|
paint_over_solid (cairo_t *cr, int width, int height)
|
2006-08-31 07:19:05 -07:00
|
|
|
{
|
|
|
|
|
cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
|
2006-08-31 11:42:51 -07:00
|
|
|
|
2006-09-06 00:53:52 -07:00
|
|
|
return do_paint (cr, width);
|
2006-08-31 07:19:05 -07:00
|
|
|
}
|
|
|
|
|
|
2006-09-29 16:42:44 -07:00
|
|
|
static cairo_perf_ticks_t
|
2006-09-14 12:59:31 -07:00
|
|
|
paint_over_solid_alpha (cairo_t *cr, int width, int height)
|
2006-08-31 07:19:05 -07:00
|
|
|
{
|
2006-09-14 12:59:31 -07:00
|
|
|
cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7);
|
|
|
|
|
|
|
|
|
|
return do_paint (cr, width);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-29 16:42:44 -07:00
|
|
|
static cairo_perf_ticks_t
|
2006-09-14 12:59:31 -07:00
|
|
|
paint_source_solid (cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
2006-08-31 11:42:51 -07:00
|
|
|
cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
|
2006-08-31 10:27:20 -07:00
|
|
|
|
2006-09-06 00:53:52 -07:00
|
|
|
return do_paint (cr, width);
|
2006-08-31 07:19:05 -07:00
|
|
|
}
|
2006-08-31 11:42:51 -07:00
|
|
|
|
2006-09-29 16:42:44 -07:00
|
|
|
static cairo_perf_ticks_t
|
2006-09-14 12:59:31 -07:00
|
|
|
paint_source_solid_alpha (cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
|
cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7);
|
|
|
|
|
|
|
|
|
|
return do_paint (cr, width);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* paint with surface
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int cached_surface_width = 0;
|
|
|
|
|
int cached_surface_height = 0;
|
|
|
|
|
cairo_content_t cached_surface_content = 0;
|
|
|
|
|
cairo_surface_t *cached_surface = NULL;
|
|
|
|
|
|
2006-09-29 16:42:44 -07:00
|
|
|
static void
|
2006-09-14 12:59:31 -07:00
|
|
|
ensure_cached_surface (cairo_t *cr, cairo_content_t content, int w, int h)
|
|
|
|
|
{
|
|
|
|
|
cairo_surface_t *target_surface = cairo_get_target (cr);
|
|
|
|
|
|
|
|
|
|
cairo_t *cr2;
|
|
|
|
|
|
|
|
|
|
if (w == cached_surface_width && h == cached_surface_height &&
|
|
|
|
|
content == cached_surface_content &&
|
|
|
|
|
cached_surface &&
|
|
|
|
|
cairo_surface_get_type (target_surface) == cairo_surface_get_type (cached_surface))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cached_surface)
|
|
|
|
|
cairo_surface_destroy (cached_surface);
|
|
|
|
|
|
|
|
|
|
cached_surface = cairo_surface_create_similar (target_surface, content, w, h);
|
|
|
|
|
|
|
|
|
|
cached_surface_width = w;
|
|
|
|
|
cached_surface_height = h;
|
|
|
|
|
cached_surface_content = content;
|
|
|
|
|
|
|
|
|
|
/* Fill it with something known */
|
|
|
|
|
cr2 = cairo_create (cached_surface);
|
|
|
|
|
cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
|
|
|
|
|
cairo_paint (cr2);
|
|
|
|
|
|
|
|
|
|
cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
|
|
|
|
|
cairo_set_source_rgb (cr2, 0, 0, 1);
|
|
|
|
|
cairo_paint (cr2);
|
|
|
|
|
|
|
|
|
|
cairo_set_source_rgba (cr2, 1, 0, 0, 0.5);
|
|
|
|
|
cairo_new_path (cr2);
|
|
|
|
|
cairo_rectangle (cr2, 0, 0, w/2.0, h/2.0);
|
|
|
|
|
cairo_rectangle (cr2, w/2.0, h/2.0, w/2.0, h/2.0);
|
|
|
|
|
cairo_fill (cr2);
|
|
|
|
|
cairo_destroy (cr2);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-29 16:42:44 -07:00
|
|
|
static cairo_perf_ticks_t
|
2006-09-14 12:59:31 -07:00
|
|
|
paint_over_surface_rgb24 (cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
ensure_cached_surface (cr, CAIRO_CONTENT_COLOR, width, height);
|
|
|
|
|
|
|
|
|
|
cairo_set_source_surface (cr, cached_surface, 0, 0);
|
|
|
|
|
|
|
|
|
|
return do_paint (cr, width);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-29 16:42:44 -07:00
|
|
|
static cairo_perf_ticks_t
|
2006-09-14 12:59:31 -07:00
|
|
|
paint_over_surface_argb32 (cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
ensure_cached_surface (cr, CAIRO_CONTENT_COLOR_ALPHA, width, height);
|
|
|
|
|
|
|
|
|
|
cairo_set_source_surface (cr, cached_surface, 0, 0);
|
|
|
|
|
|
|
|
|
|
return do_paint (cr, width);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-29 16:42:44 -07:00
|
|
|
static cairo_perf_ticks_t
|
2006-09-14 12:59:31 -07:00
|
|
|
paint_source_surface_rgb24 (cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
ensure_cached_surface (cr, CAIRO_CONTENT_COLOR, width, height);
|
|
|
|
|
|
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
|
cairo_set_source_surface (cr, cached_surface, 0, 0);
|
|
|
|
|
|
|
|
|
|
return do_paint (cr, width);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-29 16:42:44 -07:00
|
|
|
static cairo_perf_ticks_t
|
2006-09-14 12:59:31 -07:00
|
|
|
paint_source_surface_argb32 (cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
ensure_cached_surface (cr, CAIRO_CONTENT_COLOR_ALPHA, width, height);
|
|
|
|
|
|
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
|
cairo_set_source_surface (cr, cached_surface, 0, 0);
|
|
|
|
|
|
|
|
|
|
return do_paint (cr, width);
|
|
|
|
|
}
|
2006-09-29 16:42:44 -07:00
|
|
|
|
|
|
|
|
void
|
2006-10-04 13:23:50 -07:00
|
|
|
paint (cairo_perf_t *perf, cairo_t *cr, int width, int height)
|
2006-09-29 16:42:44 -07:00
|
|
|
{
|
|
|
|
|
cairo_perf_run (perf, "paint_over_solid", paint_over_solid);
|
|
|
|
|
cairo_perf_run (perf, "paint_over_solid_alpha", paint_over_solid_alpha);
|
|
|
|
|
cairo_perf_run (perf, "paint_source_solid", paint_source_solid);
|
|
|
|
|
cairo_perf_run (perf, "paint_source_solid_alpha", paint_source_solid_alpha);
|
|
|
|
|
cairo_perf_run (perf, "paint_over_surf_rgb24", paint_over_surface_rgb24);
|
|
|
|
|
cairo_perf_run (perf, "paint_over_surf_argb32", paint_over_surface_argb32);
|
|
|
|
|
cairo_perf_run (perf, "paint_source_surf_rgb24", paint_source_surface_rgb24);
|
|
|
|
|
cairo_perf_run (perf, "paint_source_surf_argb32", paint_source_surface_argb32);
|
|
|
|
|
}
|