summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-07-23 15:32:13 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-07-23 15:32:14 +0100
commitbed2701e1c89095878d549cbca8f22d84f3dda3c (patch)
tree974807761b6d839839ecad9961eae8d567898dcc /util
parentf5a1cdf283a6aa1f4409ccbf3c2274fb587724fe (diff)
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 ▏
Diffstat (limited to 'util')
-rw-r--r--util/cairo-script/cairo-script-file.c39
-rw-r--r--util/cairo-script/cairo-script-objects.c22
-rw-r--r--util/cairo-script/cairo-script-private.h9
-rw-r--r--util/cairo-script/cairo-script-scanner.c52
-rw-r--r--util/cairo-trace/trace.c119
5 files changed, 152 insertions, 89 deletions
diff --git a/util/cairo-script/cairo-script-file.c b/util/cairo-script/cairo-script-file.c
index 18b5b862..2a7296d2 100644
--- a/util/cairo-script/cairo-script-file.c
+++ b/util/cairo-script/cairo-script-file.c
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <limits.h> /* INT_MAX */
#include <string.h>
+#include <zlib.h>
#define CHUNK_SIZE 32768
@@ -148,17 +149,43 @@ csi_file_new_from_string (csi_t *ctx,
csi_file_t *file;
file = _csi_slab_alloc (ctx, sizeof (csi_file_t));
- if (file == NULL)
+ if (_csi_unlikely (file == NULL))
return _csi_error (CAIRO_STATUS_NO_MEMORY);
file->base.type = CSI_OBJECT_TYPE_FILE;
file->base.ref = 1;
- file->type = BYTES;
- file->src = src; src->base.ref++;
- file->data = src->string;
- file->bp = file->data;
- file->rem = src->len;
+ if (src->deflate) {
+ uLongf len = src->deflate;
+ csi_object_t tmp_obj;
+ csi_string_t *tmp_str;
+ csi_status_t status;
+
+ status = csi_string_new (ctx, &tmp_obj, NULL, src->deflate);
+ if (_csi_unlikely (status))
+ return status;
+
+ tmp_str = tmp_obj.datum.string;
+ if (uncompress ((Bytef *) tmp_str->string, &len,
+ (Bytef *) src->string, src->len) != Z_OK)
+ {
+ csi_string_free (ctx, tmp_str);
+ _csi_slab_free (ctx, file, sizeof (csi_file_t));
+ return _csi_error (CAIRO_STATUS_NO_MEMORY);
+ }
+
+ file->type = BYTES;
+ file->src = tmp_str;
+ file->data = tmp_str->string;
+ file->bp = file->data;
+ file->rem = tmp_str->len;
+ } else {
+ file->type = BYTES;
+ file->src = src; src->base.ref++;
+ file->data = src->string;
+ file->bp = file->data;
+ file->rem = src->len;
+ }
obj->type = CSI_OBJECT_TYPE_FILE;
obj->datum.file = file;
diff --git a/util/cairo-script/cairo-script-objects.c b/util/cairo-script/cairo-script-objects.c
index 784376b2..9cc59c90 100644
--- a/util/cairo-script/cairo-script-objects.c
+++ b/util/cairo-script/cairo-script-objects.c
@@ -507,6 +507,7 @@ csi_string_new (csi_t *ctx,
string->string[len] = '\0';
}
string->len = len;
+ string->deflate = 0;
string->base.type = CSI_OBJECT_TYPE_STRING;
string->base.ref = 1;
@@ -518,6 +519,26 @@ csi_string_new (csi_t *ctx,
}
csi_status_t
+csi_string_deflate_new (csi_t *ctx,
+ csi_object_t *obj,
+ void *bytes,
+ int in_len,
+ int out_len)
+{
+ csi_status_t status;
+ csi_string_t *string;
+
+ status = csi_string_new (ctx, obj, bytes, in_len);
+ if (_csi_unlikely (status))
+ return status;
+
+ string = obj->datum.string;
+ string->deflate = out_len;
+
+ return CSI_STATUS_SUCCESS;
+}
+
+csi_status_t
csi_string_new_from_bytes (csi_t *ctx,
csi_object_t *obj,
char *bytes,
@@ -534,6 +555,7 @@ csi_string_new_from_bytes (csi_t *ctx,
string->string = bytes;
string->len = len;
+ string->deflate = 0;
string->base.type = CSI_OBJECT_TYPE_STRING;
string->base.ref = 1;
diff --git a/util/cairo-script/cairo-script-private.h b/util/cairo-script/cairo-script-private.h
index 996b40d7..54a840f2 100644
--- a/util/cairo-script/cairo-script-private.h
+++ b/util/cairo-script/cairo-script-private.h
@@ -386,6 +386,7 @@ struct _csi_matrix {
struct _csi_string {
csi_compound_object_t base;
csi_integer_t len;
+ csi_integer_t deflate;
char *string;
};
@@ -435,7 +436,6 @@ struct _csi_scanner {
csi_stack_t procedure_stack;
csi_object_t build_procedure;
- int string_p;
unsigned int accumulator;
unsigned int accumulator_count;
@@ -757,6 +757,13 @@ csi_string_new (csi_t *ctx,
int len);
csi_private csi_status_t
+csi_string_deflate_new (csi_t *ctx,
+ csi_object_t *obj,
+ void *bytes,
+ int in_len,
+ int out_len);
+
+csi_private csi_status_t
csi_string_new_from_bytes (csi_t *ctx,
csi_object_t *obj,
char *bytes,
diff --git a/util/cairo-script/cairo-script-scanner.c b/util/cairo-script/cairo-script-scanner.c
index b3217cd7..3cc39575 100644
--- a/util/cairo-script/cairo-script-scanner.c
+++ b/util/cairo-script/cairo-script-scanner.c
@@ -39,6 +39,7 @@
#include <stdio.h> /* EOF */
#include <string.h> /* memset */
#include <assert.h>
+#include <zlib.h>
#define DEBUG_SCAN 0
@@ -488,18 +489,6 @@ token_end (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
}
static void
-string_inc_p (csi_scanner_t *scan)
-{
- scan->string_p++;
-}
-
-static int
-string_dec_p (csi_scanner_t *scan)
-{
- return --scan->string_p == 0;
-}
-
-static void
string_add (csi_t *ctx, csi_scanner_t *scan, int c)
{
buffer_check (ctx, scan, 1);
@@ -616,7 +605,7 @@ base85_add (csi_t *ctx, csi_scanner_t *scan, int c)
}
static void
-base85_end (csi_t *ctx, csi_scanner_t *scan)
+base85_end (csi_t *ctx, csi_scanner_t *scan, cairo_bool_t deflate)
{
csi_object_t obj;
cairo_status_t status;
@@ -647,12 +636,24 @@ base85_end (csi_t *ctx, csi_scanner_t *scan)
break;
}
- status = csi_string_new (ctx,
- &obj,
- scan->buffer.base,
- scan->buffer.ptr - scan->buffer.base);
- if (_csi_unlikely (status))
- longjmp (scan->jmpbuf, status);
+ if (deflate) {
+ uLongf len = *(uint32_t *) scan->buffer.base;
+ Bytef *source = (Bytef *) (scan->buffer.base + sizeof (uint32_t));
+
+ status = csi_string_deflate_new (ctx, &obj,
+ source,
+ (Bytef *) scan->buffer.ptr - source,
+ len);
+ if (_csi_unlikely (status))
+ longjmp (scan->jmpbuf, status);
+ } else {
+ status = csi_string_new (ctx,
+ &obj,
+ scan->buffer.base,
+ scan->buffer.ptr - scan->buffer.base);
+ if (_csi_unlikely (status))
+ longjmp (scan->jmpbuf, status);
+ }
if (scan->build_procedure.type != CSI_OBJECT_TYPE_NULL)
status = csi_array_append (ctx,
@@ -714,6 +715,8 @@ _scan_file (csi_t *ctx, csi_file_t *src)
uint32_t u32;
float f;
} u;
+ int deflate = 0;
+ int string_p;
scan_none:
while ((c = csi_file_getc (src)) != EOF) {
@@ -757,6 +760,8 @@ scan_none:
token_add_unchecked (scan, '<');
token_end (ctx, scan, src);
goto scan_none;
+ case '|':
+ deflate = 1;
case '~':
goto scan_base85;
default:
@@ -1000,7 +1005,7 @@ scan_comment:
scan_string:
buffer_reset (&scan->buffer);
- scan->string_p = 1;
+ string_p = 1;
while ((c = csi_file_getc (src)) != EOF) {
switch (c) {
case '\\': /* escape */
@@ -1086,12 +1091,12 @@ scan_string:
break;
case '(':
- string_inc_p (scan);
+ string_p++;
string_add (ctx, scan, c);
break;
case ')':
- if (string_dec_p (scan)) {
+ if (--string_p == 0) {
string_end (ctx, scan);
goto scan_none;
}
@@ -1166,7 +1171,8 @@ scan_base85:
return;
case '>':
- base85_end (ctx, scan);
+ base85_end (ctx, scan, deflate);
+ deflate = 0;
goto scan_none;
}
csi_file_putc (src, next);
diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index 3af1fffd..2775d46e 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -1189,15 +1189,6 @@ _write_base85_data_start (struct _data_stream *stream)
stream->base85_pending = 0;
}
-static void
-_write_data_start (struct _data_stream *stream)
-{
- _write_zlib_data_start (stream);
- _write_base85_data_start (stream);
-
- _trace_printf ("<~");
-}
-
static bool
_expand_four_tuple_to_five (unsigned char four_tuple[4],
unsigned char five_tuple[5])
@@ -1271,6 +1262,16 @@ _write_zlib_data (struct _data_stream *stream, bool flush)
}
static void
+_write_data_start (struct _data_stream *stream, uint32_t len)
+{
+ _write_zlib_data_start (stream);
+ _write_base85_data_start (stream);
+
+ _trace_printf ("<|");
+ _write_base85_data (stream, (unsigned char *) &len, len);
+}
+
+static void
_write_data (struct _data_stream *stream,
const void *data,
unsigned int length)
@@ -1328,7 +1329,7 @@ _emit_data (const void *data, unsigned int length)
{
struct _data_stream stream;
- _write_data_start (&stream);
+ _write_data_start (&stream, length);
_write_data (&stream, data, length);
_write_data_end (&stream);
}
@@ -1391,6 +1392,7 @@ _emit_image (cairo_surface_t *image,
...)
{
int stride, row, width, height;
+ uint32_t len;
cairo_format_t format;
uint8_t row_stack[BUFFER_SIZE];
uint8_t *rowdata;
@@ -1400,9 +1402,7 @@ _emit_image (cairo_surface_t *image,
status = DLCALL (cairo_surface_status, image);
if (status) {
- _trace_printf ("dict\n"
- " /status //%s set\n"
- " image",
+ _trace_printf ("<< /status //%s >> image",
_status_to_string (status));
return;
}
@@ -1430,6 +1430,7 @@ _emit_image (cairo_surface_t *image,
if (DLCALL (cairo_version) >= CAIRO_VERSION_ENCODE (1, 9, 0)) {
const char *mime_types[] = {
CAIRO_MIME_TYPE_JPEG,
+ CAIRO_MIME_TYPE_JP2,
CAIRO_MIME_TYPE_PNG,
NULL
}, **mime_type;
@@ -1454,8 +1455,16 @@ _emit_image (cairo_surface_t *image,
}
}
+ switch (format) {
+ case CAIRO_FORMAT_A1: len = (width + 7)/8; break;
+ case CAIRO_FORMAT_A8: len = width; break;
+ case CAIRO_FORMAT_RGB24: len = 3*width; break;
+ default:
+ case CAIRO_FORMAT_ARGB32: len = 4*width; break;
+ }
+
_trace_printf (" /source ");
- _write_data_start (&stream);
+ _write_data_start (&stream, len * height);
#ifdef WORDS_BIGENDIAN
switch (format) {
@@ -1549,8 +1558,7 @@ _emit_image (cairo_surface_t *image,
BAIL:
_write_data_end (&stream);
#endif
- _trace_printf (" /deflate filter set\n"
- " image");
+ _trace_printf (" set\n image");
}
static void
@@ -2658,31 +2666,33 @@ _emit_font_options (const cairo_font_options_t *options)
cairo_hint_style_t hint_style;
cairo_hint_metrics_t hint_metrics;
- _trace_printf ("dict\n");
+ _trace_printf ("<<");
antialias = DLCALL (cairo_font_options_get_antialias, options);
if (antialias != CAIRO_ANTIALIAS_DEFAULT) {
- _trace_printf (" /antialias //%s set\n",
+ _trace_printf (" /antialias //%s",
_antialias_to_string (antialias));
}
subpixel_order = DLCALL (cairo_font_options_get_subpixel_order, options);
if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) {
- _trace_printf (" /subpixel-order //%s set\n",
+ _trace_printf (" /subpixel-order //%s",
_subpixel_order_to_string (subpixel_order));
}
hint_style = DLCALL (cairo_font_options_get_hint_style, options);
if (hint_style != CAIRO_HINT_STYLE_DEFAULT) {
- _trace_printf (" /hint-style //%s set\n",
+ _trace_printf (" /hint-style //%s",
_hint_style_to_string (hint_style));
}
hint_metrics = DLCALL (cairo_font_options_get_hint_metrics, options);
if (hint_style != CAIRO_HINT_METRICS_DEFAULT) {
- _trace_printf (" /hint-metrics //%s set\n",
+ _trace_printf (" /hint-metrics //%s",
_hint_metrics_to_string (hint_metrics));
}
+
+ _trace_printf (" >>");
}
void
@@ -2692,7 +2702,7 @@ cairo_set_font_options (cairo_t *cr, const cairo_font_options_t *options)
if (cr != NULL && options != NULL && _write_lock ()) {
_emit_context (cr);
_emit_font_options (options);
- _trace_printf (" set-font-options\n");
+ _trace_printf (" set-font-options\n");
_write_unlock ();
}
@@ -3621,16 +3631,10 @@ cairo_ft_font_face_create_for_ft_face (FT_Face face, int load_flags)
if (obj->operand != -1)
_object_remove (obj);
- _trace_printf ("dict\n"
- " /type 42 set\n"
- " /source ");
+ _trace_printf ("<< /type 42 /source ");
_emit_data (data->data, data->size);
- _trace_printf (" /deflate filter set\n"
- " /size %lu set\n"
- " /index %lu set\n"
- " /flags %d set\n"
- " font\n",
- data->size, data->index, load_flags);
+ _trace_printf (" /index %lu /flags %d font\n",
+ data->index, load_flags);
_push_operand (FONT_FACE, ret);
_write_unlock ();
}
@@ -4245,17 +4249,12 @@ _cairo_test_fallback_surface_create (cairo_content_t content,
#include <test-paginated-surface.h>
cairo_surface_t *
-_cairo_test_paginated_surface_create_for_data (unsigned char *data,
- cairo_content_t content,
- int width,
- int height,
- int stride)
+_cairo_test_paginated_surface_create (cairo_surface_t *surface)
{
cairo_surface_t *ret;
long surface_id;
- ret = DLCALL (_cairo_test_paginated_surface_create_for_data,
- data, content, width, height, stride);
+ ret = DLCALL (_cairo_test_paginated_surface_create, surface);
surface_id = _create_surface_id (ret);
_emit_line_info ();
@@ -4263,16 +4262,10 @@ _cairo_test_paginated_surface_create_for_data (unsigned char *data,
/* XXX store initial data? */
_trace_printf ("dict\n"
" /type /test-paginated set\n"
- " /content //%s set\n"
- " /width %d set\n"
- " /height %d set\n"
- " /stride %d set\n"
+ " /target s%ld set\n"
" surface dup /s%ld exch def\n",
- _content_to_string (content),
- width, height, stride,
+ _get_surface_id (surface),
surface_id);
- _surface_object_set_size (ret, width, height);
- _get_object (SURFACE, ret)->defined = true;
_push_operand (SURFACE, ret);
_write_unlock ();
}
@@ -4310,27 +4303,35 @@ _cairo_test_null_surface_create (cairo_content_t content)
cairo_surface_t *
cairo_meta_surface_create (cairo_content_t content,
- double width,
- double height)
+ const cairo_rectangle_t *extents)
{
cairo_surface_t *ret;
long surface_id;
- ret = DLCALL (cairo_meta_surface_create, content, width, height);
+ ret = DLCALL (cairo_meta_surface_create, content, extents);
surface_id = _create_surface_id (ret);
_emit_line_info ();
if (_write_lock ()) {
- _trace_printf ("dict\n"
- " /type /meta set\n"
- " /content //%s set\n"
- " /width %f set\n"
- " /height %f set\n"
- " surface dup /s%ld exch def\n",
- _content_to_string (content),
- width, height,
- surface_id);
- _surface_object_set_size (ret, width, height);
+ if (extents) {
+ _trace_printf ("dict\n"
+ " /type /meta set\n"
+ " /content //%s set\n"
+ " /extents [%f %f %f %f] set\n"
+ " surface dup /s%ld exch def\n",
+ _content_to_string (content),
+ extents->x, extents->y,
+ extents->width, extents->height,
+ surface_id);
+ _surface_object_set_size (ret, extents->width, extents->height);
+ } else {
+ _trace_printf ("dict\n"
+ " /type /meta set\n"
+ " /content //%s set\n"
+ " surface dup /s%ld exch def\n",
+ _content_to_string (content),
+ surface_id);
+ }
_get_object (SURFACE, ret)->defined = true;
_push_operand (SURFACE, ret);
_write_unlock ();