[cairo-commit] src/cairo-gstate.c src/cairo-gstate-private.h src/cairoint.h src/cairo-observer.c src/cairo-surface.c src/cairo-surface-private.h src/cairo-types-private.h src/Makefile.sources
Chris Wilson
ickle at kemper.freedesktop.org
Fri Jun 11 08:10:26 PDT 2010
src/Makefile.sources | 1
src/cairo-gstate-private.h | 3 ++
src/cairo-gstate.c | 28 +++++++++++++++++++++---
src/cairo-observer.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
src/cairo-surface-private.h | 1
src/cairo-surface.c | 6 +++++
src/cairo-types-private.h | 6 +++++
src/cairoint.h | 5 ++++
8 files changed, 96 insertions(+), 4 deletions(-)
New commits:
commit 1a544361e845e4881990624a597f9dc2b82d1c73
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Fri Jun 11 16:04:41 2010 +0100
gstate: Update cached matrix state after device transform changes on the target
Commit 8d67186cb291cb877e52b987e2ac18c2a1175a57 caches whether the device
transform is identity on context creation. However, the api is quite lax
and allows the user to modify the device transform *after* he has
started to use the surface in a context, as apparently WebKit does.
Since this is not the only instance where we may need to invalidate
caches if the user modifies state, introduce a simple mechanism for
hooking into notifications of property changes.
Fixes test/clip-device-offset.
diff --git a/src/Makefile.sources b/src/Makefile.sources
index 957e108..6e7c511 100644
--- a/src/Makefile.sources
+++ b/src/Makefile.sources
@@ -138,6 +138,7 @@ cairo_sources = \
cairo-recording-surface.c \
cairo-misc.c \
cairo-mutex.c \
+ cairo-observer.c \
cairo-output-stream.c \
cairo-paginated-surface.c \
cairo-path-bounds.c \
diff --git a/src/cairo-gstate-private.h b/src/cairo-gstate-private.h
index e706024..b41c7a2 100644
--- a/src/cairo-gstate-private.h
+++ b/src/cairo-gstate-private.h
@@ -60,6 +60,9 @@ struct _cairo_gstate {
cairo_surface_t *parent_target; /* The previous target which was receiving rendering */
cairo_surface_t *original_target; /* The original target the initial gstate was created with */
+ /* the user is allowed to update the device after we have cached the matrices... */
+ cairo_observer_t device_transform_observer;
+
cairo_matrix_t ctm;
cairo_matrix_t ctm_inverse;
cairo_matrix_t source_ctm_inverse; /* At the time ->source was set */
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 28266dd..baf6145 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -70,6 +70,18 @@ _cairo_gstate_transform_glyphs_to_backend (cairo_gstate_t *gstate,
int *num_transformed_glyphs,
cairo_text_cluster_t *transformed_clusters);
+static void
+_cairo_gstate_update_device_transform (cairo_observer_t *observer,
+ void *arg)
+{
+ cairo_gstate_t *gstate = cairo_container_of (observer,
+ cairo_gstate_t,
+ device_transform_observer);
+
+ gstate->is_identity = (_cairo_matrix_is_identity (&gstate->ctm) &&
+ _cairo_matrix_is_identity (&gstate->target->device_transform));
+}
+
cairo_status_t
_cairo_gstate_init (cairo_gstate_t *gstate,
cairo_surface_t *target)
@@ -105,6 +117,10 @@ _cairo_gstate_init (cairo_gstate_t *gstate,
gstate->parent_target = NULL;
gstate->original_target = cairo_surface_reference (target);
+ gstate->device_transform_observer.callback = _cairo_gstate_update_device_transform;
+ cairo_list_add (&gstate->device_transform_observer.link,
+ &gstate->target->device_transform_observers);
+
gstate->is_identity = _cairo_matrix_is_identity (&gstate->target->device_transform);
cairo_matrix_init_identity (&gstate->ctm);
gstate->ctm_inverse = gstate->ctm;
@@ -115,10 +131,6 @@ _cairo_gstate_init (cairo_gstate_t *gstate,
/* Now that the gstate is fully initialized and ready for the eventual
* _cairo_gstate_fini(), we can check for errors (and not worry about
* the resource deallocation). */
-
- if (target == NULL)
- return _cairo_error (CAIRO_STATUS_NULL_POINTER);
-
status = target->status;
if (unlikely (status))
return status;
@@ -171,6 +183,10 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
gstate->parent_target = NULL;
gstate->original_target = cairo_surface_reference (other->original_target);
+ gstate->device_transform_observer.callback = _cairo_gstate_update_device_transform;
+ cairo_list_add (&gstate->device_transform_observer.link,
+ &gstate->target->device_transform_observers);
+
gstate->is_identity = other->is_identity;
gstate->ctm = other->ctm;
gstate->ctm_inverse = other->ctm_inverse;
@@ -199,6 +215,8 @@ _cairo_gstate_fini (cairo_gstate_t *gstate)
_cairo_clip_reset (&gstate->clip);
+ cairo_list_del (&gstate->device_transform_observer.link);
+
cairo_surface_destroy (gstate->target);
gstate->target = NULL;
@@ -309,6 +327,8 @@ _cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child)
* since its ref is now owned by gstate->parent_target */
gstate->target = cairo_surface_reference (child);
gstate->is_identity &= _cairo_matrix_is_identity (&child->device_transform);
+ cairo_list_move (&gstate->device_transform_observer.link,
+ &gstate->target->device_transform_observers);
/* The clip is in surface backend coordinates for the previous target;
* translate it into the child's backend coordinates. */
diff --git a/src/cairo-observer.c b/src/cairo-observer.c
new file mode 100644
index 0000000..7c7b69c
--- /dev/null
+++ b/src/cairo-observer.c
@@ -0,0 +1,50 @@
+/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2010 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * The Initial Developer of the Original Code is Intel Corporation
+ *
+ * Contributor(s):
+ * Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairoint.h"
+
+void
+_cairo_observers_notify (cairo_list_t *observers, void *arg)
+{
+ cairo_observer_t *obs, *next;
+
+ cairo_list_foreach_entry_safe (obs, next,
+ cairo_observer_t,
+ observers, link)
+ {
+ obs->callback (obs, arg);
+ }
+}
diff --git a/src/cairo-surface-private.h b/src/cairo-surface-private.h
index 19a93c2..31ddb8c 100644
--- a/src/cairo-surface-private.h
+++ b/src/cairo-surface-private.h
@@ -72,6 +72,7 @@ struct _cairo_surface {
cairo_matrix_t device_transform;
cairo_matrix_t device_transform_inverse;
+ cairo_list_t device_transform_observers;
/* The actual resolution of the device, in dots per inch. */
double x_resolution;
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 9d5f7b8..581e755 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -63,6 +63,7 @@ const cairo_surface_t name = { \
{ 0, 0, 0, NULL, }, /* mime_data */ \
{ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform */ \
{ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform_inverse */ \
+ { NULL, NULL }, /* device_transform_observers */ \
0.0, /* x_resolution */ \
0.0, /* y_resolution */ \
0.0, /* x_fallback_resolution */ \
@@ -364,6 +365,7 @@ _cairo_surface_init (cairo_surface_t *surface,
cairo_matrix_init_identity (&surface->device_transform);
cairo_matrix_init_identity (&surface->device_transform_inverse);
+ cairo_list_init (&surface->device_transform_observers);
surface->x_resolution = CAIRO_SURFACE_RESOLUTION_DEFAULT;
surface->y_resolution = CAIRO_SURFACE_RESOLUTION_DEFAULT;
@@ -1150,6 +1152,8 @@ _cairo_surface_set_device_scale (cairo_surface_t *surface,
status = cairo_matrix_invert (&surface->device_transform_inverse);
/* should always be invertible unless given pathological input */
assert (status == CAIRO_STATUS_SUCCESS);
+
+ _cairo_observers_notify (&surface->device_transform_observers, surface);
}
/**
@@ -1196,6 +1200,8 @@ cairo_surface_set_device_offset (cairo_surface_t *surface,
status = cairo_matrix_invert (&surface->device_transform_inverse);
/* should always be invertible unless given pathological input */
assert (status == CAIRO_STATUS_SUCCESS);
+
+ _cairo_observers_notify (&surface->device_transform_observers, surface);
}
slim_hidden_def (cairo_surface_set_device_offset);
diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h
index dbfdd79..8b5a94b 100644
--- a/src/cairo-types-private.h
+++ b/src/cairo-types-private.h
@@ -60,6 +60,7 @@ typedef struct _cairo_hash_entry cairo_hash_entry_t;
typedef struct _cairo_hash_table cairo_hash_table_t;
typedef struct _cairo_image_surface cairo_image_surface_t;
typedef struct _cairo_mime_data cairo_mime_data_t;
+typedef struct _cairo_observer cairo_observer_t;
typedef struct _cairo_output_stream cairo_output_stream_t;
typedef struct _cairo_paginated_surface_backend cairo_paginated_surface_backend_t;
typedef struct _cairo_path_fixed cairo_path_fixed_t;
@@ -76,6 +77,11 @@ typedef struct _cairo_xlib_screen_info cairo_xlib_screen_info_t;
typedef cairo_array_t cairo_user_data_array_t;
+struct _cairo_observer {
+ cairo_list_t link;
+ void (*callback) (cairo_observer_t *self, void *arg);
+};
+
/**
* cairo_hash_entry_t:
*
diff --git a/src/cairoint.h b/src/cairoint.h
index 8ff9f61..e160c2b 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -2340,6 +2340,11 @@ _cairo_utf8_to_utf16 (const char *str,
int *items_written);
#endif
+/* cairo-observer.c */
+
+cairo_private void
+_cairo_observers_notify (cairo_list_t *observers, void *arg);
+
/* Avoid unnecessary PLT entries. */
slim_hidden_proto (cairo_clip_preserve);
slim_hidden_proto (cairo_close_path);
More information about the cairo-commit
mailing list