[librsvg/next: 4/31] Add RsvgRender type checking
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/next: 4/31] Add RsvgRender type checking
- Date: Fri, 21 Oct 2011 21:21:12 +0000 (UTC)
commit 5212118a0b2ba4230c14a4610249792b0454024a
Author: Christian Persch <chpe gnome org>
Date: Wed Sep 7 14:40:50 2011 +0200
Add RsvgRender type checking
rsvg-base.c | 13 ++-----------
rsvg-cairo-clip.c | 12 +++++++++---
rsvg-cairo-draw.c | 35 +++++++++++++++++++++--------------
rsvg-cairo-render.c | 3 ++-
rsvg-cairo-render.h | 2 ++
rsvg-filter.c | 2 +-
rsvg-private.h | 21 +++++++++++++++++++++
7 files changed, 58 insertions(+), 30 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index b1a2d8b..52d822c 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -1359,7 +1359,6 @@ rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimensi
cairo_t *cr;
cairo_surface_t *target;
RsvgDrawingCtx *draw;
- RsvgCairoRender *render;
RsvgNodeSvg *root = NULL;
RsvgNode *sself = NULL;
RsvgBbox bbox;
@@ -1420,12 +1419,7 @@ rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimensi
cairo_save (cr);
rsvg_node_draw ((RsvgNode *) handle->priv->treebase, draw, 0);
- render = (RsvgCairoRender *) draw->render;
-
- bbox.x = render->bbox.x;
- bbox.y = render->bbox.y;
- bbox.w = render->bbox.w;
- bbox.h = render->bbox.h;
+ bbox = RSVG_CAIRO_RENDER (draw->render)->bbox;
cairo_restore (cr);
rsvg_state_pop (draw);
@@ -1523,10 +1517,7 @@ rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_d
cairo_save (cr);
rsvg_node_draw ((RsvgNode *) handle->priv->treebase, draw, 0);
- bbox.x = ((RsvgCairoRender *) draw->render)->bbox.x;
- bbox.y = ((RsvgCairoRender *) draw->render)->bbox.y;
- bbox.w = ((RsvgCairoRender *) draw->render)->bbox.w;
- bbox.h = ((RsvgCairoRender *) draw->render)->bbox.h;
+ bbox = RSVG_CAIRO_RENDER (draw->render)->bbox;
cairo_restore (cr);
rsvg_state_pop (draw);
diff --git a/rsvg-cairo-clip.c b/rsvg-cairo-clip.c
index c928836..d843842 100644
--- a/rsvg-cairo-clip.c
+++ b/rsvg-cairo-clip.c
@@ -45,6 +45,8 @@ struct RsvgCairoClipRender {
RsvgCairoRender *parent;
};
+#define RSVG_CAIRO_CLIP_RENDER(render) (_RSVG_RENDER_CIC ((render), RSVG_RENDER_TYPE_CAIRO_CLIP, RsvgCairoClipRender))
+
static void
rsvg_cairo_clip_apply_affine (RsvgCairoClipRender *render, const double affine[6])
{
@@ -62,7 +64,7 @@ rsvg_cairo_clip_apply_affine (RsvgCairoClipRender *render, const double affine[6
static void
rsvg_cairo_clip_render_path (RsvgDrawingCtx * ctx, const RsvgBpathDef * bpath_def)
{
- RsvgCairoClipRender *render = (RsvgCairoClipRender *) ctx->render;
+ RsvgCairoClipRender *render = RSVG_CAIRO_CLIP_RENDER (ctx->render);
RsvgState *state = rsvg_current_state (ctx);
cairo_t *cr;
RsvgBpath *bpath;
@@ -110,7 +112,8 @@ rsvg_cairo_clip_render_image (RsvgDrawingCtx * ctx,
static void
rsvg_cairo_clip_render_free (RsvgRender * self)
{
- RsvgCairoClipRender *me = (RsvgCairoClipRender *) self;
+ RsvgCairoClipRender *me = RSVG_CAIRO_CLIP_RENDER (self);
+
g_free (me);
}
@@ -134,6 +137,9 @@ rsvg_cairo_clip_render_new (cairo_t * cr, RsvgCairoRender *parent)
{
RsvgCairoClipRender *cairo_render = g_new0 (RsvgCairoClipRender, 1);
+ g_assert (parent->super.type == RSVG_RENDER_TYPE_CAIRO);
+
+ cairo_render->super.type = RSVG_RENDER_TYPE_CAIRO_CLIP;
cairo_render->super.free = rsvg_cairo_clip_render_free;
cairo_render->super.create_pango_context = rsvg_cairo_create_pango_context;
cairo_render->super.render_pango_layout = rsvg_cairo_render_pango_layout;
@@ -152,7 +158,7 @@ rsvg_cairo_clip_render_new (cairo_t * cr, RsvgCairoRender *parent)
void
rsvg_cairo_clip (RsvgDrawingCtx * ctx, RsvgClipPath * clip, RsvgBbox * bbox)
{
- RsvgCairoRender *save = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *save = RSVG_CAIRO_RENDER (ctx->render);
double affinesave[6];
int i;
ctx->render = rsvg_cairo_clip_render_new (save->cr, save);
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index c01cd17..7f1cf74 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -164,7 +164,8 @@ _set_source_rsvg_linear_gradient (RsvgDrawingCtx * ctx,
RsvgLinearGradient * linear,
guint32 current_color_rgb, guint8 opacity, RsvgBbox bbox)
{
- cairo_t *cr = ((RsvgCairoRender *) ctx->render)->cr;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
+ cairo_t *cr = render->cr;
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
RsvgLinearGradient statlinear;
@@ -212,7 +213,8 @@ _set_source_rsvg_radial_gradient (RsvgDrawingCtx * ctx,
RsvgRadialGradient * radial,
guint32 current_color_rgb, guint8 opacity, RsvgBbox bbox)
{
- cairo_t *cr = ((RsvgCairoRender *) ctx->render)->cr;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
+ cairo_t *cr = render->cr;
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
RsvgRadialGradient statradial;
@@ -261,7 +263,8 @@ static void
_set_source_rsvg_solid_colour (RsvgDrawingCtx * ctx,
RsvgSolidColour * colour, guint8 opacity, guint32 current_colour)
{
- cairo_t *cr = ((RsvgCairoRender *) ctx->render)->cr;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
+ cairo_t *cr = render->cr;
guint32 rgb = colour->rgb;
double r, g, b;
@@ -282,7 +285,7 @@ static void
_set_source_rsvg_pattern (RsvgDrawingCtx * ctx,
RsvgPattern * rsvg_pattern, guint8 opacity, RsvgBbox bbox)
{
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
RsvgPattern local_pattern = *rsvg_pattern;
cairo_t *cr_render, *cr_pattern;
cairo_pattern_t *pattern;
@@ -463,7 +466,7 @@ rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
{
PangoFontMap *fontmap;
PangoContext *context;
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
fontmap = pango_cairo_font_map_get_default ();
context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
@@ -475,7 +478,7 @@ rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
void
rsvg_cairo_render_pango_layout (RsvgDrawingCtx * ctx, PangoLayout * layout, double x, double y)
{
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
RsvgState *state = rsvg_current_state (ctx);
PangoRectangle ink;
RsvgBbox bbox;
@@ -529,7 +532,7 @@ rsvg_cairo_render_pango_layout (RsvgDrawingCtx * ctx, PangoLayout * layout, doub
void
rsvg_cairo_render_path (RsvgDrawingCtx * ctx, const RsvgBpathDef * bpath_def)
{
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
RsvgState *state = rsvg_current_state (ctx);
cairo_t *cr;
RsvgBpath *bpath;
@@ -659,7 +662,7 @@ void
rsvg_cairo_render_image (RsvgDrawingCtx * ctx, const GdkPixbuf * pixbuf,
double pixbuf_x, double pixbuf_y, double w, double h)
{
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
RsvgState *state = rsvg_current_state (ctx);
gint width = gdk_pixbuf_get_width (pixbuf);
@@ -781,9 +784,9 @@ rsvg_cairo_render_image (RsvgDrawingCtx * ctx, const GdkPixbuf * pixbuf,
static void
rsvg_cairo_generate_mask (cairo_t * cr, RsvgMask * self, RsvgDrawingCtx * ctx, RsvgBbox * bbox)
{
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
cairo_surface_t *surface;
cairo_t *mask_cr, *save_cr;
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
RsvgState *state = rsvg_current_state (ctx);
guint8 *pixels;
guint32 width = render->width, height = render->height;
@@ -871,7 +874,9 @@ rsvg_cairo_generate_mask (cairo_t * cr, RsvgMask * self, RsvgDrawingCtx * ctx, R
static void
rsvg_cairo_push_early_clips (RsvgDrawingCtx * ctx)
{
- cairo_save (((RsvgCairoRender *) ctx->render)->cr);
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
+
+ cairo_save (render->cr);
if (rsvg_current_state (ctx)->clip_path_ref)
if (((RsvgClipPath *) rsvg_current_state (ctx)->clip_path_ref)->units == userSpaceOnUse)
rsvg_cairo_clip (ctx, rsvg_current_state (ctx)->clip_path_ref, NULL);
@@ -883,7 +888,7 @@ rsvg_cairo_push_render_stack (RsvgDrawingCtx * ctx)
{
/* XXX: Untested, probably needs help wrt filters */
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
cairo_surface_t *surface;
cairo_t *child_cr;
RsvgBbox *bbox;
@@ -953,7 +958,7 @@ rsvg_cairo_push_discrete_layer (RsvgDrawingCtx * ctx)
static void
rsvg_cairo_pop_render_stack (RsvgDrawingCtx * ctx)
{
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
cairo_t *child_cr = render->cr;
gboolean lateclip = FALSE;
cairo_surface_t *surface = NULL;
@@ -1029,14 +1034,16 @@ rsvg_cairo_pop_render_stack (RsvgDrawingCtx * ctx)
void
rsvg_cairo_pop_discrete_layer (RsvgDrawingCtx * ctx)
{
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
+
rsvg_cairo_pop_render_stack (ctx);
- cairo_restore (((RsvgCairoRender *) ctx->render)->cr);
+ cairo_restore (render->cr);
}
void
rsvg_cairo_add_clipping_rect (RsvgDrawingCtx * ctx, double x, double y, double w, double h)
{
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
cairo_t *cr = render->cr;
_set_rsvg_affine (render, rsvg_current_state (ctx)->affine);
diff --git a/rsvg-cairo-render.c b/rsvg-cairo-render.c
index 6007b5e..83ed99e 100644
--- a/rsvg-cairo-render.c
+++ b/rsvg-cairo-render.c
@@ -41,7 +41,7 @@
static void
rsvg_cairo_render_free (RsvgRender * self)
{
- RsvgCairoRender *me = (RsvgCairoRender *) self;
+ RsvgCairoRender *me = RSVG_CAIRO_RENDER (self);
/* TODO */
@@ -53,6 +53,7 @@ rsvg_cairo_render_new (cairo_t * cr, double width, double height)
{
RsvgCairoRender *cairo_render = g_new0 (RsvgCairoRender, 1);
+ cairo_render->super.type = RSVG_RENDER_TYPE_CAIRO;
cairo_render->super.free = rsvg_cairo_render_free;
cairo_render->super.create_pango_context = rsvg_cairo_create_pango_context;
cairo_render->super.render_pango_layout = rsvg_cairo_render_pango_layout;
diff --git a/rsvg-cairo-render.h b/rsvg-cairo-render.h
index f1e5323..e26b7d3 100644
--- a/rsvg-cairo-render.h
+++ b/rsvg-cairo-render.h
@@ -50,6 +50,8 @@ struct _RsvgCairoRender {
GList *pixbuf_stack;
};
+#define RSVG_CAIRO_RENDER(render) (_RSVG_RENDER_CIC ((render), RSVG_RENDER_TYPE_CAIRO, RsvgCairoRender))
+
RsvgCairoRender *rsvg_cairo_render_new (cairo_t * cr, double width, double height);
void rsvg_cairo_render_rsvg_handle (cairo_t * cr, RsvgHandle * handle);
RsvgDrawingCtx *rsvg_cairo_new_drawing_ctx (cairo_t * cr, RsvgHandle * handle);
diff --git a/rsvg-filter.c b/rsvg-filter.c
index ce96c4f..e38abbb 100644
--- a/rsvg-filter.c
+++ b/rsvg-filter.c
@@ -579,7 +579,7 @@ pixbuf_get_alpha (GdkPixbuf * pb, RsvgFilterContext * ctx)
static GdkPixbuf *
rsvg_compile_bg (RsvgDrawingCtx * ctx)
{
- RsvgCairoRender *render = (RsvgCairoRender *) ctx->render;
+ RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
cairo_t *cr;
cairo_surface_t *surface;
GList *i;
diff --git a/rsvg-private.h b/rsvg-private.h
index 162917a..9003f13 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -199,7 +199,18 @@ struct RsvgDrawingCtx {
/*Abstract base class for context for our backends (one as yet)*/
+typedef enum {
+ RSVG_RENDER_TYPE_INVALID,
+
+ RSVG_RENDER_TYPE_BASE,
+
+ RSVG_RENDER_TYPE_CAIRO = 8,
+ RSVG_RENDER_TYPE_CAIRO_CLIP
+} RsvgRenderType;
+
struct RsvgRender {
+ RsvgRenderType type;
+
void (*free) (RsvgRender * self);
PangoContext *(*create_pango_context) (RsvgDrawingCtx * ctx);
@@ -216,6 +227,16 @@ struct RsvgRender {
double w, double h);
};
+static inline RsvgRender *
+_rsvg_render_check_type (RsvgRender *render,
+ RsvgRenderType type)
+{
+ g_assert (render->type == type);
+ return render;
+}
+
+#define _RSVG_RENDER_CIC(render, render_type, RenderCType) \
+ ((RenderCType*) _rsvg_render_check_type ((render), (render_type)))
typedef struct {
double length;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]