2006-09-13 14:48:40 -07:00
|
|
|
/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
|
2006-08-30 22:56:36 -07:00
|
|
|
/*
|
2006-08-30 23:41:48 -07:00
|
|
|
* Copyright © 2004,2006 Red Hat, Inc.
|
2006-08-30 22:56:36 -07:00
|
|
|
*
|
|
|
|
|
* 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>
|
|
|
|
|
*/
|
|
|
|
|
|
2008-09-02 21:56:37 -04:00
|
|
|
#define CAIRO_VERSION_H 1
|
|
|
|
|
|
2009-07-04 21:43:27 +01:00
|
|
|
#include "cairo-boilerplate-private.h"
|
2007-04-21 03:43:04 -04:00
|
|
|
#include "cairo-boilerplate-scaled-font.h"
|
2007-04-13 12:02:11 -07:00
|
|
|
|
2010-07-03 02:54:28 +02:00
|
|
|
#include <pixman.h>
|
|
|
|
|
|
2007-04-21 03:43:04 -04:00
|
|
|
#include <cairo-types-private.h>
|
|
|
|
|
#include <cairo-scaled-font-private.h>
|
|
|
|
|
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
#if CAIRO_HAS_SCRIPT_SURFACE
|
|
|
|
|
#include <cairo-script.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-09-02 21:56:37 -04:00
|
|
|
/* get the "real" version info instead of dummy cairo-version.h */
|
|
|
|
|
#undef CAIRO_VERSION_H
|
|
|
|
|
#include "../cairo-version.h"
|
|
|
|
|
|
2007-04-20 00:13:25 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <assert.h>
|
2009-03-30 16:50:10 +01:00
|
|
|
#include <errno.h>
|
2007-04-20 00:13:25 -04:00
|
|
|
|
2009-09-13 17:35:29 -06:00
|
|
|
#if HAVE_DLFCN_H
|
2009-08-23 15:25:42 +01:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-08-18 18:50:00 +01:00
|
|
|
#if HAVE_UNISTD_H && HAVE_FCNTL_H && HAVE_SIGNAL_H && HAVE_SYS_STAT_H && HAVE_SYS_SOCKET_H && HAVE_SYS_UN_H
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
|
|
|
|
|
#define HAS_DAEMON 1
|
|
|
|
|
#define SOCKET_PATH "./.any2ppm"
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-04-11 11:36:24 +01:00
|
|
|
cairo_content_t
|
|
|
|
|
cairo_boilerplate_content (cairo_content_t content)
|
|
|
|
|
{
|
|
|
|
|
if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
|
|
|
|
|
content = CAIRO_CONTENT_COLOR_ALPHA;
|
|
|
|
|
|
|
|
|
|
return content;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-30 22:56:36 -07:00
|
|
|
const char *
|
2007-04-18 19:15:16 -04:00
|
|
|
cairo_boilerplate_content_name (cairo_content_t content)
|
2006-08-30 22:56:36 -07:00
|
|
|
{
|
|
|
|
|
/* For the purpose of the content name, we don't distinguish the
|
|
|
|
|
* flattened content value.
|
|
|
|
|
*/
|
2008-04-11 11:36:24 +01:00
|
|
|
switch (cairo_boilerplate_content (content)) {
|
2006-08-30 22:56:36 -07:00
|
|
|
case CAIRO_CONTENT_COLOR:
|
|
|
|
|
return "rgb24";
|
|
|
|
|
case CAIRO_CONTENT_COLOR_ALPHA:
|
|
|
|
|
return "argb32";
|
|
|
|
|
case CAIRO_CONTENT_ALPHA:
|
|
|
|
|
default:
|
|
|
|
|
assert (0); /* not reached */
|
|
|
|
|
return "---";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-05 05:02:00 +03:00
|
|
|
static const char *
|
|
|
|
|
_cairo_boilerplate_content_visible_name (cairo_content_t content)
|
|
|
|
|
{
|
|
|
|
|
switch (cairo_boilerplate_content (content)) {
|
|
|
|
|
case CAIRO_CONTENT_COLOR:
|
|
|
|
|
return "rgb";
|
|
|
|
|
case CAIRO_CONTENT_COLOR_ALPHA:
|
|
|
|
|
return "rgba";
|
|
|
|
|
case CAIRO_CONTENT_ALPHA:
|
|
|
|
|
return "a";
|
|
|
|
|
default:
|
|
|
|
|
assert (0); /* not reached */
|
|
|
|
|
return "---";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 00:50:48 -04:00
|
|
|
cairo_format_t
|
|
|
|
|
cairo_boilerplate_format_from_content (cairo_content_t content)
|
|
|
|
|
{
|
|
|
|
|
cairo_format_t format;
|
|
|
|
|
|
|
|
|
|
switch (content) {
|
|
|
|
|
case CAIRO_CONTENT_COLOR: format = CAIRO_FORMAT_RGB24; break;
|
|
|
|
|
case CAIRO_CONTENT_COLOR_ALPHA: format = CAIRO_FORMAT_ARGB32; break;
|
|
|
|
|
case CAIRO_CONTENT_ALPHA: format = CAIRO_FORMAT_A8; break;
|
|
|
|
|
default:
|
|
|
|
|
assert (0); /* not reached */
|
2010-02-28 23:31:06 +02:00
|
|
|
format = CAIRO_FORMAT_INVALID;
|
2007-04-20 00:50:48 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return format;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-30 22:56:36 -07:00
|
|
|
static cairo_surface_t *
|
2010-06-24 14:59:18 +03:00
|
|
|
_cairo_boilerplate_image_create_surface (const char *name,
|
|
|
|
|
cairo_content_t content,
|
|
|
|
|
double width,
|
|
|
|
|
double height,
|
|
|
|
|
double max_width,
|
|
|
|
|
double max_height,
|
|
|
|
|
cairo_boilerplate_mode_t mode,
|
|
|
|
|
void **closure)
|
2006-08-30 22:56:36 -07:00
|
|
|
{
|
|
|
|
|
cairo_format_t format;
|
2008-08-11 21:12:45 +01:00
|
|
|
|
2006-08-30 22:56:36 -07:00
|
|
|
*closure = NULL;
|
|
|
|
|
|
|
|
|
|
if (content == CAIRO_CONTENT_COLOR_ALPHA) {
|
|
|
|
|
format = CAIRO_FORMAT_ARGB32;
|
|
|
|
|
} else if (content == CAIRO_CONTENT_COLOR) {
|
|
|
|
|
format = CAIRO_FORMAT_RGB24;
|
|
|
|
|
} else {
|
|
|
|
|
assert (0); /* not reached */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-27 17:53:18 +01:00
|
|
|
return cairo_image_surface_create (format, ceil (width), ceil (height));
|
2006-08-30 22:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
2011-06-01 23:03:36 +01:00
|
|
|
static const cairo_user_data_key_t key;
|
|
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
|
|
|
|
_cairo_boilerplate_image_create_similar (cairo_surface_t *other,
|
|
|
|
|
cairo_content_t content,
|
|
|
|
|
int width, int height)
|
|
|
|
|
{
|
|
|
|
|
cairo_format_t format;
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
int stride;
|
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
|
|
switch (content) {
|
|
|
|
|
case CAIRO_CONTENT_ALPHA: format = CAIRO_FORMAT_A8; break;
|
|
|
|
|
case CAIRO_CONTENT_COLOR: format = CAIRO_FORMAT_RGB24; break;
|
|
|
|
|
default:
|
|
|
|
|
case CAIRO_CONTENT_COLOR_ALPHA: format = CAIRO_FORMAT_ARGB32; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stride = cairo_format_stride_for_width(format, width);
|
|
|
|
|
ptr = malloc (stride* height);
|
|
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create_for_data (ptr, format,
|
|
|
|
|
width, height, stride);
|
|
|
|
|
cairo_surface_set_user_data (surface, &key, ptr, free);
|
|
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-27 21:52:16 +00:00
|
|
|
static cairo_surface_t *
|
2010-06-24 14:59:18 +03:00
|
|
|
_cairo_boilerplate_image16_create_surface (const char *name,
|
|
|
|
|
cairo_content_t content,
|
|
|
|
|
double width,
|
|
|
|
|
double height,
|
|
|
|
|
double max_width,
|
|
|
|
|
double max_height,
|
|
|
|
|
cairo_boilerplate_mode_t mode,
|
2011-06-01 23:03:36 +01:00
|
|
|
void **closure)
|
2010-03-27 21:52:16 +00:00
|
|
|
{
|
|
|
|
|
*closure = NULL;
|
|
|
|
|
|
|
|
|
|
/* XXX force CAIRO_CONTENT_COLOR */
|
|
|
|
|
return cairo_image_surface_create (CAIRO_FORMAT_RGB16_565, ceil (width), ceil (height));
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-01 23:03:36 +01:00
|
|
|
static cairo_surface_t *
|
|
|
|
|
_cairo_boilerplate_image16_create_similar (cairo_surface_t *other,
|
|
|
|
|
cairo_content_t content,
|
|
|
|
|
int width, int height)
|
|
|
|
|
{
|
|
|
|
|
cairo_format_t format;
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
int stride;
|
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
|
|
switch (content) {
|
|
|
|
|
case CAIRO_CONTENT_ALPHA: format = CAIRO_FORMAT_A8; break;
|
|
|
|
|
case CAIRO_CONTENT_COLOR: format = CAIRO_FORMAT_RGB16_565; break;
|
|
|
|
|
default:
|
|
|
|
|
case CAIRO_CONTENT_COLOR_ALPHA: format = CAIRO_FORMAT_ARGB32; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stride = cairo_format_stride_for_width(format, width);
|
|
|
|
|
ptr = malloc (stride* height);
|
|
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create_for_data (ptr, format,
|
|
|
|
|
width, height, stride);
|
|
|
|
|
cairo_surface_set_user_data (surface, &key, ptr, free);
|
|
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-03 02:54:28 +02:00
|
|
|
static char *
|
|
|
|
|
_cairo_boilerplate_image_describe (void *closure)
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
xasprintf (&s, "pixman %s", pixman_version_string ());
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-22 02:13:36 +03:00
|
|
|
#if CAIRO_HAS_RECORDING_SURFACE
|
2009-07-04 22:00:09 +01:00
|
|
|
static cairo_surface_t *
|
2010-06-24 14:59:18 +03:00
|
|
|
_cairo_boilerplate_recording_create_surface (const char *name,
|
|
|
|
|
cairo_content_t content,
|
|
|
|
|
double width,
|
|
|
|
|
double height,
|
|
|
|
|
double max_width,
|
|
|
|
|
double max_height,
|
|
|
|
|
cairo_boilerplate_mode_t mode,
|
|
|
|
|
void **closure)
|
2009-07-04 22:00:09 +01:00
|
|
|
{
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
cairo_rectangle_t extents;
|
|
|
|
|
|
|
|
|
|
extents.x = 0;
|
|
|
|
|
extents.y = 0;
|
|
|
|
|
extents.width = width;
|
|
|
|
|
extents.height = height;
|
2010-04-30 12:37:16 +01:00
|
|
|
return *closure = cairo_surface_reference (cairo_recording_surface_create (content, &extents));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_cairo_boilerplate_recording_surface_cleanup (void *closure)
|
|
|
|
|
{
|
|
|
|
|
cairo_surface_finish (closure);
|
|
|
|
|
cairo_surface_destroy (closure);
|
2009-07-04 22:00:09 +01:00
|
|
|
}
|
2009-07-20 23:17:07 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
const cairo_user_data_key_t cairo_boilerplate_output_basename_key;
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
|
2008-08-18 12:53:43 +01:00
|
|
|
cairo_surface_t *
|
|
|
|
|
_cairo_boilerplate_get_image_surface (cairo_surface_t *src,
|
2010-06-24 14:59:18 +03:00
|
|
|
int page,
|
|
|
|
|
int width,
|
|
|
|
|
int height)
|
2008-08-18 12:53:43 +01:00
|
|
|
{
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
cairo_surface_t *surface, *image;
|
2008-08-18 12:53:43 +01:00
|
|
|
cairo_t *cr;
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
cairo_status_t status;
|
2011-08-13 11:05:45 +01:00
|
|
|
cairo_format_t format;
|
2008-08-18 12:53:43 +01:00
|
|
|
|
2009-03-30 16:50:10 +01:00
|
|
|
if (cairo_surface_status (src))
|
|
|
|
|
return cairo_surface_reference (src);
|
|
|
|
|
|
2008-09-28 13:34:50 +01:00
|
|
|
if (page != 0)
|
|
|
|
|
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
|
|
|
|
|
|
2008-08-18 12:53:43 +01:00
|
|
|
/* extract sub-surface */
|
2011-08-13 11:05:45 +01:00
|
|
|
switch (cairo_surface_get_content (src)) {
|
|
|
|
|
case CAIRO_CONTENT_ALPHA:
|
|
|
|
|
format = CAIRO_FORMAT_A8;
|
|
|
|
|
break;
|
|
|
|
|
case CAIRO_CONTENT_COLOR:
|
|
|
|
|
format = CAIRO_FORMAT_RGB24;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case CAIRO_CONTENT_COLOR_ALPHA:
|
|
|
|
|
format = CAIRO_FORMAT_ARGB32;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
surface = cairo_image_surface_create (format, width, height);
|
|
|
|
|
assert (cairo_surface_get_content (surface) == cairo_surface_get_content (src));
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
image = cairo_surface_reference (surface);
|
|
|
|
|
|
2009-10-22 02:13:36 +03:00
|
|
|
/* open a logging channel (only interesting for recording surfaces) */
|
|
|
|
|
#if CAIRO_HAS_SCRIPT_SURFACE && CAIRO_HAS_RECORDING_SURFACE
|
|
|
|
|
if (cairo_surface_get_type (src) == CAIRO_SURFACE_TYPE_RECORDING) {
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
const char *test_name;
|
|
|
|
|
|
|
|
|
|
test_name = cairo_surface_get_user_data (src,
|
|
|
|
|
&cairo_boilerplate_output_basename_key);
|
|
|
|
|
if (test_name != NULL) {
|
2010-01-18 22:43:24 +00:00
|
|
|
cairo_device_t *ctx;
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
char *filename;
|
|
|
|
|
|
2010-06-24 14:59:18 +03:00
|
|
|
cairo_surface_destroy (surface);
|
2010-04-29 20:34:56 +01:00
|
|
|
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
xasprintf (&filename, "%s.out.trace", test_name);
|
2010-01-18 22:43:24 +00:00
|
|
|
ctx = cairo_script_create (filename);
|
2009-08-13 17:21:05 +01:00
|
|
|
surface = cairo_script_surface_create_for_target (ctx, image);
|
2010-01-18 22:43:24 +00:00
|
|
|
cairo_device_destroy (ctx);
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
free (filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-08-18 12:53:43 +01:00
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
cairo_set_source_surface (cr, src, 0, 0);
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
status = cairo_status (cr);
|
|
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
image = cairo_surface_reference (cairo_get_target (cr));
|
|
|
|
|
}
|
2008-08-18 12:53:43 +01:00
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
return image;
|
2008-08-18 12:53:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_surface_t *
|
2010-06-24 14:59:18 +03:00
|
|
|
cairo_boilerplate_get_image_surface_from_png (const char *filename,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
cairo_bool_t flatten)
|
2008-08-18 12:53:43 +01:00
|
|
|
{
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create_from_png (filename);
|
2009-06-28 01:17:13 +01:00
|
|
|
if (cairo_surface_status (surface))
|
|
|
|
|
return surface;
|
2008-08-18 12:53:43 +01:00
|
|
|
|
|
|
|
|
if (flatten) {
|
|
|
|
|
cairo_t *cr;
|
|
|
|
|
cairo_surface_t *flattened;
|
|
|
|
|
|
|
|
|
|
flattened = cairo_image_surface_create (cairo_image_surface_get_format (surface),
|
|
|
|
|
width,
|
|
|
|
|
height);
|
|
|
|
|
cr = cairo_create (flattened);
|
|
|
|
|
cairo_surface_destroy (flattened);
|
|
|
|
|
|
|
|
|
|
cairo_set_source_rgb (cr, 1, 1, 1);
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
|
|
cairo_set_source_surface (cr, surface,
|
|
|
|
|
width - cairo_image_surface_get_width (surface),
|
|
|
|
|
height - cairo_image_surface_get_height (surface));
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
surface = cairo_surface_reference (cairo_get_target (cr));
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
} else if (cairo_image_surface_get_width (surface) != width ||
|
|
|
|
|
cairo_image_surface_get_height (surface) != height)
|
|
|
|
|
{
|
|
|
|
|
cairo_t *cr;
|
|
|
|
|
cairo_surface_t *sub;
|
|
|
|
|
|
|
|
|
|
sub = cairo_image_surface_create (cairo_image_surface_get_format (surface),
|
|
|
|
|
width,
|
|
|
|
|
height);
|
|
|
|
|
cr = cairo_create (sub);
|
|
|
|
|
cairo_surface_destroy (sub);
|
|
|
|
|
|
|
|
|
|
cairo_set_source_surface (cr, surface,
|
|
|
|
|
width - cairo_image_surface_get_width (surface),
|
|
|
|
|
height - cairo_image_surface_get_height (surface));
|
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
surface = cairo_surface_reference (cairo_get_target (cr));
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
|
}
|
2006-08-30 22:56:36 -07:00
|
|
|
|
2009-07-04 21:43:27 +01:00
|
|
|
static const cairo_boilerplate_target_t builtin_targets[] = {
|
2006-09-05 22:25:21 -07:00
|
|
|
/* I'm uncompromising about leaving the image backend as 0
|
|
|
|
|
* for tolerance. There shouldn't ever be anything that is out of
|
|
|
|
|
* our control here. */
|
2008-09-03 16:38:03 +01:00
|
|
|
{
|
2009-06-19 18:40:43 +01:00
|
|
|
"image", "image", NULL, NULL,
|
2008-09-03 16:38:03 +01:00
|
|
|
CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR_ALPHA, 0,
|
2011-06-01 23:03:36 +01:00
|
|
|
NULL,
|
|
|
|
|
_cairo_boilerplate_image_create_surface,
|
|
|
|
|
_cairo_boilerplate_image_create_similar,
|
2009-06-19 18:40:43 +01:00
|
|
|
NULL, NULL,
|
2008-09-03 16:38:03 +01:00
|
|
|
_cairo_boilerplate_get_image_surface,
|
2010-03-27 21:52:16 +00:00
|
|
|
cairo_surface_write_to_png,
|
2010-07-03 02:54:28 +02:00
|
|
|
NULL, NULL,
|
|
|
|
|
_cairo_boilerplate_image_describe,
|
2010-03-27 21:52:16 +00:00
|
|
|
TRUE, FALSE, FALSE
|
2008-09-03 16:38:03 +01:00
|
|
|
},
|
|
|
|
|
{
|
2009-06-19 18:40:43 +01:00
|
|
|
"image", "image", NULL, NULL,
|
2008-09-03 16:38:03 +01:00
|
|
|
CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
|
2011-06-01 23:03:36 +01:00
|
|
|
NULL,
|
|
|
|
|
_cairo_boilerplate_image_create_surface,
|
|
|
|
|
_cairo_boilerplate_image_create_similar,
|
2009-06-19 18:40:43 +01:00
|
|
|
NULL, NULL,
|
2008-09-03 16:38:03 +01:00
|
|
|
_cairo_boilerplate_get_image_surface,
|
2010-03-27 21:52:16 +00:00
|
|
|
cairo_surface_write_to_png,
|
2010-07-03 02:54:28 +02:00
|
|
|
NULL, NULL,
|
|
|
|
|
_cairo_boilerplate_image_describe,
|
2010-03-27 21:52:16 +00:00
|
|
|
FALSE, FALSE, FALSE
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"image16", "image", NULL, NULL,
|
|
|
|
|
CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
|
2011-06-01 23:03:36 +01:00
|
|
|
NULL,
|
|
|
|
|
_cairo_boilerplate_image16_create_surface,
|
|
|
|
|
_cairo_boilerplate_image16_create_similar,
|
2010-03-27 21:52:16 +00:00
|
|
|
NULL, NULL,
|
|
|
|
|
_cairo_boilerplate_get_image_surface,
|
|
|
|
|
cairo_surface_write_to_png,
|
2010-07-03 02:54:28 +02:00
|
|
|
NULL, NULL,
|
|
|
|
|
_cairo_boilerplate_image_describe,
|
2010-03-27 21:52:16 +00:00
|
|
|
TRUE, FALSE, FALSE
|
2008-09-03 16:38:03 +01:00
|
|
|
},
|
2009-10-22 02:13:36 +03:00
|
|
|
#if CAIRO_HAS_RECORDING_SURFACE
|
2009-07-04 22:00:09 +01:00
|
|
|
{
|
2009-10-22 02:13:36 +03:00
|
|
|
"recording", "image", NULL, NULL,
|
|
|
|
|
CAIRO_SURFACE_TYPE_RECORDING, CAIRO_CONTENT_COLOR_ALPHA, 0,
|
|
|
|
|
"cairo_recording_surface_create",
|
|
|
|
|
_cairo_boilerplate_recording_create_surface,
|
2011-06-01 23:03:36 +01:00
|
|
|
cairo_surface_create_similar,
|
2009-07-04 22:00:09 +01:00
|
|
|
NULL, NULL,
|
|
|
|
|
_cairo_boilerplate_get_image_surface,
|
|
|
|
|
cairo_surface_write_to_png,
|
2010-04-30 12:37:16 +01:00
|
|
|
_cairo_boilerplate_recording_surface_cleanup,
|
2010-06-30 18:27:54 +02:00
|
|
|
NULL, NULL,
|
2010-03-27 21:52:16 +00:00
|
|
|
FALSE, FALSE, TRUE
|
2009-07-04 22:00:09 +01:00
|
|
|
},
|
|
|
|
|
{
|
2009-10-22 02:13:36 +03:00
|
|
|
"recording", "image", NULL, NULL,
|
|
|
|
|
CAIRO_SURFACE_TYPE_RECORDING, CAIRO_CONTENT_COLOR, 0,
|
|
|
|
|
"cairo_recording_surface_create",
|
|
|
|
|
_cairo_boilerplate_recording_create_surface,
|
2011-06-01 23:03:36 +01:00
|
|
|
cairo_surface_create_similar,
|
2009-07-04 22:00:09 +01:00
|
|
|
NULL, NULL,
|
|
|
|
|
_cairo_boilerplate_get_image_surface,
|
|
|
|
|
cairo_surface_write_to_png,
|
2010-04-30 12:37:16 +01:00
|
|
|
_cairo_boilerplate_recording_surface_cleanup,
|
2010-06-30 18:27:54 +02:00
|
|
|
NULL, NULL,
|
2010-03-27 21:52:16 +00:00
|
|
|
FALSE, FALSE, TRUE
|
2009-07-04 22:00:09 +01:00
|
|
|
},
|
2009-07-20 23:17:07 +01:00
|
|
|
#endif
|
2006-08-30 22:56:36 -07:00
|
|
|
};
|
2009-07-04 21:43:27 +01:00
|
|
|
CAIRO_BOILERPLATE (builtin, builtin_targets)
|
|
|
|
|
|
|
|
|
|
static struct cairo_boilerplate_target_list {
|
|
|
|
|
struct cairo_boilerplate_target_list *next;
|
|
|
|
|
const cairo_boilerplate_target_t *target;
|
|
|
|
|
} *cairo_boilerplate_targets;
|
|
|
|
|
|
2009-08-23 15:25:42 +01:00
|
|
|
static cairo_bool_t
|
|
|
|
|
probe_target (const cairo_boilerplate_target_t *target)
|
|
|
|
|
{
|
|
|
|
|
if (target->probe == NULL)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2009-09-13 17:35:29 -06:00
|
|
|
#if HAVE_DLSYM
|
2009-08-23 15:25:42 +01:00
|
|
|
return dlsym (NULL, target->probe) != NULL;
|
|
|
|
|
#else
|
|
|
|
|
return TRUE;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-04 21:43:27 +01:00
|
|
|
void
|
|
|
|
|
_cairo_boilerplate_register_backend (const cairo_boilerplate_target_t *targets,
|
2010-06-24 14:59:18 +03:00
|
|
|
unsigned int count)
|
2009-07-04 21:43:27 +01:00
|
|
|
{
|
|
|
|
|
targets += count;
|
|
|
|
|
while (count--) {
|
|
|
|
|
struct cairo_boilerplate_target_list *list;
|
|
|
|
|
|
2009-08-23 15:25:42 +01:00
|
|
|
--targets;
|
|
|
|
|
if (! probe_target (targets))
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-07-04 21:43:27 +01:00
|
|
|
list = xmalloc (sizeof (*list));
|
|
|
|
|
list->next = cairo_boilerplate_targets;
|
2009-08-23 15:25:42 +01:00
|
|
|
list->target = targets;
|
2009-07-04 21:43:27 +01:00
|
|
|
cairo_boilerplate_targets = list;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-30 22:56:36 -07:00
|
|
|
|
2009-09-05 05:02:00 +03:00
|
|
|
static cairo_bool_t
|
|
|
|
|
_cairo_boilerplate_target_matches_name (const cairo_boilerplate_target_t *target,
|
2010-06-24 14:59:18 +03:00
|
|
|
const char *tname,
|
|
|
|
|
const char *end)
|
2009-09-05 05:02:00 +03:00
|
|
|
{
|
|
|
|
|
char const *content_name;
|
|
|
|
|
const char *content_start = strpbrk (tname, ".");
|
|
|
|
|
const char *content_end = end;
|
|
|
|
|
size_t name_len;
|
|
|
|
|
size_t content_len;
|
|
|
|
|
|
|
|
|
|
if (content_start != NULL)
|
|
|
|
|
end = content_start++;
|
|
|
|
|
|
|
|
|
|
name_len = end - tname;
|
|
|
|
|
|
|
|
|
|
/* Check name. */
|
2009-09-05 05:07:25 +03:00
|
|
|
if (! (name_len == 1 && 0 == strncmp (tname, "?", 1))) { /* wildcard? */
|
|
|
|
|
if (0 != strncmp (target->name, tname, name_len)) /* exact match? */
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (isalnum (target->name[name_len]))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2009-09-05 05:02:00 +03:00
|
|
|
|
|
|
|
|
/* Check optional content. */
|
|
|
|
|
if (content_start == NULL) /* none given? */
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
/* Exact content match? */
|
|
|
|
|
content_name = _cairo_boilerplate_content_visible_name (target->content);
|
|
|
|
|
content_len = content_end - content_start;
|
|
|
|
|
if (strlen(content_name) != content_len)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (0 == strncmp (content_name, content_start, content_len))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-12 12:32:51 +01:00
|
|
|
const cairo_boilerplate_target_t **
|
2010-06-24 14:59:18 +03:00
|
|
|
cairo_boilerplate_get_targets (int *pnum_targets,
|
|
|
|
|
cairo_bool_t *plimited_targets)
|
2007-04-18 19:46:30 -04:00
|
|
|
{
|
|
|
|
|
size_t i, num_targets;
|
|
|
|
|
cairo_bool_t limited_targets = FALSE;
|
|
|
|
|
const char *tname;
|
2009-06-12 12:32:51 +01:00
|
|
|
const cairo_boilerplate_target_t **targets_to_test;
|
2009-07-04 21:43:27 +01:00
|
|
|
struct cairo_boilerplate_target_list *list;
|
|
|
|
|
|
|
|
|
|
if (cairo_boilerplate_targets == NULL)
|
|
|
|
|
_cairo_boilerplate_register_all ();
|
2007-04-18 19:46:30 -04:00
|
|
|
|
|
|
|
|
if ((tname = getenv ("CAIRO_TEST_TARGET")) != NULL && *tname) {
|
2007-09-03 14:33:11 +01:00
|
|
|
/* check the list of targets specified by the user */
|
2007-04-18 19:46:30 -04:00
|
|
|
limited_targets = TRUE;
|
|
|
|
|
|
|
|
|
|
num_targets = 0;
|
|
|
|
|
targets_to_test = NULL;
|
|
|
|
|
|
|
|
|
|
while (*tname) {
|
|
|
|
|
int found = 0;
|
|
|
|
|
const char *end = strpbrk (tname, " \t\r\n;:,");
|
|
|
|
|
if (!end)
|
2010-06-24 14:59:18 +03:00
|
|
|
end = tname + strlen (tname);
|
2007-04-18 19:46:30 -04:00
|
|
|
|
|
|
|
|
if (end == tname) {
|
|
|
|
|
tname = end + 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-04 21:43:27 +01:00
|
|
|
for (list = cairo_boilerplate_targets;
|
|
|
|
|
list != NULL;
|
|
|
|
|
list = list->next)
|
|
|
|
|
{
|
|
|
|
|
const cairo_boilerplate_target_t *target = list->target;
|
2009-09-05 05:02:00 +03:00
|
|
|
if (_cairo_boilerplate_target_matches_name (target, tname, end)) {
|
2007-04-18 19:46:30 -04:00
|
|
|
/* realloc isn't exactly the best thing here, but meh. */
|
2007-04-20 19:08:07 +01:00
|
|
|
targets_to_test = xrealloc (targets_to_test, sizeof(cairo_boilerplate_target_t *) * (num_targets+1));
|
2009-07-04 21:43:27 +01:00
|
|
|
targets_to_test[num_targets++] = target;
|
2007-04-18 19:46:30 -04:00
|
|
|
found = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found) {
|
2009-07-04 21:43:27 +01:00
|
|
|
const char *last_name = NULL;
|
|
|
|
|
|
2009-06-09 12:45:53 +01:00
|
|
|
fprintf (stderr, "Cannot find target '%.*s'.\n",
|
|
|
|
|
(int)(end - tname), tname);
|
|
|
|
|
fprintf (stderr, "Known targets:");
|
2009-07-04 21:43:27 +01:00
|
|
|
for (list = cairo_boilerplate_targets;
|
|
|
|
|
list != NULL;
|
|
|
|
|
list = list->next)
|
|
|
|
|
{
|
|
|
|
|
const cairo_boilerplate_target_t *target = list->target;
|
|
|
|
|
if (last_name != NULL) {
|
|
|
|
|
if (strcmp (target->name, last_name) == 0) {
|
2009-06-09 12:45:53 +01:00
|
|
|
/* filter out repeats that differ in content */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
fprintf (stderr, ",");
|
|
|
|
|
}
|
2009-07-04 21:43:27 +01:00
|
|
|
fprintf (stderr, " %s", target->name);
|
|
|
|
|
last_name = target->name;
|
2009-06-09 12:45:53 +01:00
|
|
|
}
|
|
|
|
|
fprintf (stderr, "\n");
|
2007-04-18 19:46:30 -04:00
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*end)
|
|
|
|
|
end++;
|
|
|
|
|
tname = end;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2007-09-03 14:33:11 +01:00
|
|
|
/* check all compiled in targets */
|
2009-07-04 21:43:27 +01:00
|
|
|
num_targets = 0;
|
|
|
|
|
for (list = cairo_boilerplate_targets; list != NULL; list = list->next)
|
|
|
|
|
num_targets++;
|
|
|
|
|
|
2007-04-20 19:08:07 +01:00
|
|
|
targets_to_test = xmalloc (sizeof(cairo_boilerplate_target_t*) * num_targets);
|
2009-07-04 21:43:27 +01:00
|
|
|
num_targets = 0;
|
|
|
|
|
for (list = cairo_boilerplate_targets;
|
|
|
|
|
list != NULL;
|
|
|
|
|
list = list->next)
|
|
|
|
|
{
|
|
|
|
|
const cairo_boilerplate_target_t *target = list->target;
|
|
|
|
|
targets_to_test[num_targets++] = target;
|
2007-04-18 19:46:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-03 14:33:11 +01:00
|
|
|
/* exclude targets as specified by the user */
|
|
|
|
|
if ((tname = getenv ("CAIRO_TEST_TARGET_EXCLUDE")) != NULL && *tname) {
|
|
|
|
|
limited_targets = TRUE;
|
|
|
|
|
|
|
|
|
|
while (*tname) {
|
2008-08-17 15:28:49 +01:00
|
|
|
int j;
|
2007-09-03 14:33:11 +01:00
|
|
|
const char *end = strpbrk (tname, " \t\r\n;:,");
|
|
|
|
|
if (!end)
|
2010-06-24 14:59:18 +03:00
|
|
|
end = tname + strlen (tname);
|
2007-09-03 14:33:11 +01:00
|
|
|
|
|
|
|
|
if (end == tname) {
|
|
|
|
|
tname = end + 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = j = 0; i < num_targets; i++) {
|
2009-09-05 05:02:00 +03:00
|
|
|
const cairo_boilerplate_target_t *target = targets_to_test[i];
|
|
|
|
|
if (! _cairo_boilerplate_target_matches_name (target,
|
|
|
|
|
tname, end))
|
2008-08-17 15:28:49 +01:00
|
|
|
{
|
2007-09-03 14:33:11 +01:00
|
|
|
targets_to_test[j++] = targets_to_test[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
num_targets = j;
|
|
|
|
|
|
|
|
|
|
if (*end)
|
|
|
|
|
end++;
|
|
|
|
|
tname = end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-18 19:46:30 -04:00
|
|
|
if (pnum_targets)
|
|
|
|
|
*pnum_targets = num_targets;
|
|
|
|
|
|
|
|
|
|
if (plimited_targets)
|
|
|
|
|
*plimited_targets = limited_targets;
|
|
|
|
|
|
|
|
|
|
return targets_to_test;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-12 12:25:22 +01:00
|
|
|
const cairo_boilerplate_target_t *
|
|
|
|
|
cairo_boilerplate_get_image_target (cairo_content_t content)
|
|
|
|
|
{
|
2009-07-04 21:43:27 +01:00
|
|
|
if (cairo_boilerplate_targets == NULL)
|
|
|
|
|
_cairo_boilerplate_register_all ();
|
2009-06-12 12:25:22 +01:00
|
|
|
|
2011-07-30 17:28:21 +01:00
|
|
|
switch (content) {
|
|
|
|
|
default:
|
|
|
|
|
case CAIRO_CONTENT_ALPHA: return NULL;
|
|
|
|
|
case CAIRO_CONTENT_COLOR: return &builtin_targets[1];
|
|
|
|
|
case CAIRO_CONTENT_COLOR_ALPHA: return &builtin_targets[0];
|
2009-06-12 12:25:22 +01:00
|
|
|
}
|
2009-06-19 18:40:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const cairo_boilerplate_target_t *
|
2010-06-24 14:59:18 +03:00
|
|
|
cairo_boilerplate_get_target_by_name (const char *name,
|
|
|
|
|
cairo_content_t content)
|
2009-06-19 18:40:43 +01:00
|
|
|
{
|
2009-07-04 21:43:27 +01:00
|
|
|
struct cairo_boilerplate_target_list *list;
|
2009-06-19 18:40:43 +01:00
|
|
|
|
2009-07-04 21:43:27 +01:00
|
|
|
if (cairo_boilerplate_targets == NULL)
|
|
|
|
|
_cairo_boilerplate_register_all ();
|
2009-06-19 18:40:43 +01:00
|
|
|
|
|
|
|
|
/* first return an exact match */
|
2009-07-04 21:43:27 +01:00
|
|
|
for (list = cairo_boilerplate_targets; list != NULL; list = list->next) {
|
|
|
|
|
const cairo_boilerplate_target_t *target = list->target;
|
|
|
|
|
if (strcmp (target->name, name) == 0 &&
|
|
|
|
|
target->content == content)
|
2009-06-19 18:40:43 +01:00
|
|
|
{
|
2009-07-04 21:43:27 +01:00
|
|
|
return target;
|
2009-06-19 18:40:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* otherwise just return a match that may differ in content */
|
2009-07-04 21:43:27 +01:00
|
|
|
for (list = cairo_boilerplate_targets; list != NULL; list = list->next) {
|
|
|
|
|
const cairo_boilerplate_target_t *target = list->target;
|
|
|
|
|
if (strcmp (target->name, name) == 0)
|
|
|
|
|
return target;
|
2009-06-19 18:40:43 +01:00
|
|
|
}
|
|
|
|
|
|
2009-06-12 12:25:22 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-18 19:46:30 -04:00
|
|
|
void
|
2009-06-12 12:32:51 +01:00
|
|
|
cairo_boilerplate_free_targets (const cairo_boilerplate_target_t **targets)
|
2007-04-18 19:46:30 -04:00
|
|
|
{
|
|
|
|
|
free (targets);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_surface_t *
|
|
|
|
|
cairo_boilerplate_surface_create_in_error (cairo_status_t status)
|
2007-04-19 22:08:24 -04:00
|
|
|
{
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_surface_t *surface = NULL;
|
2008-09-15 17:07:11 +01:00
|
|
|
int loop = 5;
|
2008-08-11 21:12:45 +01:00
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
cairo_surface_t *intermediate;
|
|
|
|
|
cairo_t *cr;
|
|
|
|
|
cairo_path_t path;
|
|
|
|
|
|
|
|
|
|
intermediate = cairo_image_surface_create (CAIRO_FORMAT_A8, 0, 0);
|
|
|
|
|
cr = cairo_create (intermediate);
|
|
|
|
|
cairo_surface_destroy (intermediate);
|
|
|
|
|
|
|
|
|
|
path.status = status;
|
|
|
|
|
cairo_append_path (cr, &path);
|
|
|
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
2008-09-15 17:07:11 +01:00
|
|
|
surface = cairo_surface_reference (cairo_get_target (cr));
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_destroy (cr);
|
2008-09-15 17:07:11 +01:00
|
|
|
} while (cairo_surface_status (surface) != status && --loop);
|
2008-08-11 21:12:45 +01:00
|
|
|
|
|
|
|
|
return surface;
|
2007-04-19 22:08:24 -04:00
|
|
|
}
|
2007-04-21 03:43:04 -04:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
cairo_boilerplate_scaled_font_set_max_glyphs_cached (cairo_scaled_font_t *scaled_font,
|
2010-06-24 14:59:18 +03:00
|
|
|
int max_glyphs)
|
2007-04-21 03:43:04 -04:00
|
|
|
{
|
2008-11-21 15:04:47 +00:00
|
|
|
/* XXX CAIRO_DEBUG */
|
2007-04-21 03:43:04 -04:00
|
|
|
}
|
2008-08-18 18:50:00 +01:00
|
|
|
|
|
|
|
|
#if HAS_DAEMON
|
|
|
|
|
static int
|
|
|
|
|
any2ppm_daemon_exists (void)
|
|
|
|
|
{
|
|
|
|
|
struct stat st;
|
|
|
|
|
int fd;
|
|
|
|
|
char buf[80];
|
|
|
|
|
int pid;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (stat (SOCKET_PATH, &st) < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
fd = open (SOCKET_PATH ".pid", O_RDONLY);
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
pid = 0;
|
|
|
|
|
ret = read (fd, buf, sizeof (buf) - 1);
|
|
|
|
|
if (ret > 0) {
|
|
|
|
|
buf[ret] = '\0';
|
|
|
|
|
pid = atoi (buf);
|
|
|
|
|
}
|
|
|
|
|
close (fd);
|
|
|
|
|
|
|
|
|
|
return pid > 0 && kill (pid, 0) != -1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
FILE *
|
2010-06-24 14:59:18 +03:00
|
|
|
cairo_boilerplate_open_any2ppm (const char *filename,
|
|
|
|
|
int page,
|
2011-11-11 12:20:28 +01:00
|
|
|
unsigned int flags,
|
|
|
|
|
int (**close_cb) (FILE *))
|
2008-08-18 18:50:00 +01:00
|
|
|
{
|
|
|
|
|
char command[4096];
|
|
|
|
|
#if HAS_DAEMON
|
|
|
|
|
int sk;
|
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
|
int len;
|
|
|
|
|
|
2008-09-25 13:24:58 +01:00
|
|
|
if (flags & CAIRO_BOILERPLATE_OPEN_NO_DAEMON)
|
|
|
|
|
goto POPEN;
|
|
|
|
|
|
2008-08-18 18:50:00 +01:00
|
|
|
if (! any2ppm_daemon_exists ()) {
|
|
|
|
|
if (system ("./any2ppm") != 0)
|
|
|
|
|
goto POPEN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sk = socket (PF_UNIX, SOCK_STREAM, 0);
|
|
|
|
|
if (sk == -1)
|
|
|
|
|
goto POPEN;
|
|
|
|
|
|
|
|
|
|
memset (&addr, 0, sizeof (addr));
|
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
|
|
|
strcpy (addr.sun_path, SOCKET_PATH);
|
|
|
|
|
|
|
|
|
|
if (connect (sk, (struct sockaddr *) &addr, sizeof (addr)) == -1) {
|
|
|
|
|
close (sk);
|
|
|
|
|
goto POPEN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = sprintf (command, "%s %d\n", filename, page);
|
|
|
|
|
if (write (sk, command, len) != len) {
|
|
|
|
|
close (sk);
|
|
|
|
|
goto POPEN;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-11 12:20:28 +01:00
|
|
|
*close_cb = fclose;
|
2008-08-18 18:50:00 +01:00
|
|
|
return fdopen (sk, "r");
|
|
|
|
|
|
|
|
|
|
POPEN:
|
|
|
|
|
#endif
|
2011-11-11 12:20:28 +01:00
|
|
|
|
|
|
|
|
*close_cb = pclose;
|
2008-08-18 18:50:00 +01:00
|
|
|
sprintf (command, "./any2ppm %s %d", filename, page);
|
|
|
|
|
return popen (command, "r");
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-25 00:16:45 +01:00
|
|
|
static cairo_bool_t
|
2010-06-24 14:59:18 +03:00
|
|
|
freadn (unsigned char *buf,
|
|
|
|
|
int len,
|
|
|
|
|
FILE *file)
|
2008-09-25 00:16:45 +01:00
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
|
ret = fread (buf, 1, len, file);
|
|
|
|
|
if (ret != len) {
|
|
|
|
|
if (ferror (file) || feof (file))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
len -= ret;
|
|
|
|
|
buf += len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-18 18:50:00 +01:00
|
|
|
cairo_surface_t *
|
|
|
|
|
cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file)
|
|
|
|
|
{
|
|
|
|
|
char format;
|
|
|
|
|
int width, height, stride;
|
|
|
|
|
int x, y;
|
|
|
|
|
unsigned char *data;
|
|
|
|
|
cairo_surface_t *image = NULL;
|
|
|
|
|
|
|
|
|
|
if (fscanf (file, "P%c %d %d 255\n", &format, &width, &height) != 3)
|
|
|
|
|
goto FAIL;
|
|
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
|
case '7': /* XXX */
|
|
|
|
|
image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
|
|
|
|
|
break;
|
|
|
|
|
case '6':
|
|
|
|
|
image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
|
|
|
|
|
break;
|
|
|
|
|
case '5':
|
|
|
|
|
image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
goto FAIL;
|
|
|
|
|
}
|
|
|
|
|
if (cairo_surface_status (image))
|
2009-03-30 16:50:10 +01:00
|
|
|
return image;
|
2008-08-18 18:50:00 +01:00
|
|
|
|
|
|
|
|
data = cairo_image_surface_get_data (image);
|
|
|
|
|
stride = cairo_image_surface_get_stride (image);
|
|
|
|
|
for (y = 0; y < height; y++) {
|
2009-07-04 18:30:24 +01:00
|
|
|
unsigned char *buf = data + y*stride;
|
2008-08-18 18:50:00 +01:00
|
|
|
switch (format) {
|
|
|
|
|
case '7':
|
2008-09-25 00:16:45 +01:00
|
|
|
if (! freadn (buf, 4 * width, file))
|
2008-08-18 18:50:00 +01:00
|
|
|
goto FAIL;
|
|
|
|
|
break;
|
|
|
|
|
case '6':
|
2009-07-04 18:30:24 +01:00
|
|
|
if (! freadn (buf, 3*width, file))
|
|
|
|
|
goto FAIL;
|
|
|
|
|
buf += 3*width;
|
|
|
|
|
for (x = width; x--; ) {
|
|
|
|
|
buf -= 3;
|
|
|
|
|
((uint32_t *) (data + y*stride))[x] =
|
2008-11-07 18:35:39 +00:00
|
|
|
(buf[0] << 16) | (buf[1] << 8) | (buf[2] << 0);
|
2008-08-18 18:50:00 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '5':
|
2008-09-25 00:16:45 +01:00
|
|
|
if (! freadn (buf, width, file))
|
2008-08-18 18:50:00 +01:00
|
|
|
goto FAIL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-11-29 15:56:26 +02:00
|
|
|
cairo_surface_mark_dirty (image);
|
2008-08-18 18:50:00 +01:00
|
|
|
|
|
|
|
|
return image;
|
|
|
|
|
|
|
|
|
|
FAIL:
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
|
|
|
|
|
}
|
2008-09-02 21:56:37 -04:00
|
|
|
|
2008-09-25 13:24:58 +01:00
|
|
|
cairo_surface_t *
|
2010-06-24 14:59:18 +03:00
|
|
|
cairo_boilerplate_convert_to_image (const char *filename,
|
|
|
|
|
int page)
|
2008-09-25 13:24:58 +01:00
|
|
|
{
|
|
|
|
|
FILE *file;
|
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
cairo_surface_t *image;
|
2011-11-11 12:20:28 +01:00
|
|
|
int (*close_cb) (FILE *);
|
2009-01-02 17:45:26 +00:00
|
|
|
int ret;
|
2008-09-25 13:24:58 +01:00
|
|
|
|
|
|
|
|
RETRY:
|
2011-11-11 12:20:28 +01:00
|
|
|
file = cairo_boilerplate_open_any2ppm (filename, page, flags, &close_cb);
|
2009-03-30 16:50:10 +01:00
|
|
|
if (file == NULL) {
|
|
|
|
|
switch (errno) {
|
|
|
|
|
case ENOMEM:
|
|
|
|
|
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_NO_MEMORY);
|
|
|
|
|
default:
|
|
|
|
|
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-25 13:24:58 +01:00
|
|
|
|
|
|
|
|
image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
|
2011-11-11 12:20:28 +01:00
|
|
|
ret = close_cb (file);
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
/* check for fatal errors from the interpreter */
|
|
|
|
|
if (ret) { /* any2pmm should never die... */
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_INVALID_STATUS);
|
|
|
|
|
}
|
2008-09-25 13:24:58 +01:00
|
|
|
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
if (ret == 0 && cairo_surface_status (image) == CAIRO_STATUS_READ_ERROR) {
|
2008-09-25 13:24:58 +01:00
|
|
|
if (flags == 0) {
|
2009-01-02 17:45:26 +00:00
|
|
|
/* Try again in a standalone process. */
|
2008-09-25 13:24:58 +01:00
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
flags = CAIRO_BOILERPLATE_OPEN_NO_DAEMON;
|
|
|
|
|
goto RETRY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return image;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-02 21:56:37 -04:00
|
|
|
int
|
|
|
|
|
cairo_boilerplate_version (void)
|
|
|
|
|
{
|
|
|
|
|
return CAIRO_VERSION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
|
cairo_boilerplate_version_string (void)
|
|
|
|
|
{
|
|
|
|
|
return CAIRO_VERSION_STRING;
|
|
|
|
|
}
|
2010-03-23 16:49:21 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
cairo_boilerplate_fini (void)
|
|
|
|
|
{
|
|
|
|
|
while (cairo_boilerplate_targets != NULL) {
|
|
|
|
|
struct cairo_boilerplate_target_list *next;
|
|
|
|
|
|
|
|
|
|
next = cairo_boilerplate_targets->next;
|
|
|
|
|
|
|
|
|
|
free (cairo_boilerplate_targets);
|
|
|
|
|
cairo_boilerplate_targets = next;
|
|
|
|
|
}
|
|
|
|
|
}
|