summaryrefslogtreecommitdiff
path: root/src/cairo-script-surface.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-08-14 12:08:42 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2011-08-14 12:37:57 +0100
commit0c6b892ce355466b9b7098aadfece0383346de54 (patch)
tree0002b9aa51fe8629b6c1743c586aa07651564471 /src/cairo-script-surface.c
parent9dc9f24884e1b580448f12ccd50909b6aee3cb53 (diff)
downloadcairo-0c6b892ce355466b9b7098aadfece0383346de54.tar.gz
script: take advantage of the polymorphism of the interpreter
If a function expects a surface but receives a context, it automatically queries the context's target. We can take advantage of this to short-cut a few operations. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/cairo-script-surface.c')
-rw-r--r--src/cairo-script-surface.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/cairo-script-surface.c b/src/cairo-script-surface.c
index 44a92289b..a80654c0b 100644
--- a/src/cairo-script-surface.c
+++ b/src/cairo-script-surface.c
@@ -428,29 +428,32 @@ _get_target (cairo_script_surface_t *surface)
{
cairo_script_context_t *ctx = to_context (surface);
+ if (target_is_active (surface)) {
+ _cairo_output_stream_puts (ctx->stream, "dup ");
+ return;
+ }
+
if (surface->defined) {
_cairo_output_stream_printf (ctx->stream, "s%u ",
surface->base.unique_id);
} else {
+ int depth = target_depth (surface);
+
assert (! cairo_list_is_empty (&surface->operand.link));
- if (! target_is_active (surface)) {
- int depth = target_depth (surface);
- if (ctx->active) {
- _cairo_output_stream_printf (ctx->stream, "%d index ", depth);
- _cairo_output_stream_puts (ctx->stream, "/target get exch pop ");
+ assert (! target_is_active (surface));
+
+ if (ctx->active) {
+ _cairo_output_stream_printf (ctx->stream, "%d index ", depth);
+ _cairo_output_stream_puts (ctx->stream, "/target get exch pop ");
+ } else {
+ if (depth == 1) {
+ _cairo_output_stream_puts (ctx->stream, "exch ");
} else {
- if (depth == 1) {
- _cairo_output_stream_puts (ctx->stream,
- "exch\n");
- } else {
- _cairo_output_stream_printf (ctx->stream,
- "%d -1 roll\n",
- depth);
- }
- _cairo_output_stream_puts (ctx->stream, "/target get ");
+ _cairo_output_stream_printf (ctx->stream,
+ "%d -1 roll ", depth);
}
- } else {
- _cairo_output_stream_puts (ctx->stream, "/target get ");
+ target_push (surface);
+ _cairo_output_stream_puts (ctx->stream, "dup ");
}
}
}