[librsvg: 3/15] state: add C getters for some of the fields



commit a4f9a1e56447bb7c7cff952d88b6ae00164c6b71
Author: Paolo Borelli <pborelli gnome org>
Date:   Fri Apr 6 10:32:35 2018 +0200

    state: add C getters for some of the fields

 librsvg/rsvg-cairo-draw.c | 85 +++++++++++++++++++++++++++++++----------------
 librsvg/rsvg-styles.c     | 24 +++++++++++++
 librsvg/rsvg-styles.h     | 12 +++++++
 3 files changed, 92 insertions(+), 29 deletions(-)
---
diff --git a/librsvg/rsvg-cairo-draw.c b/librsvg/rsvg-cairo-draw.c
index f3cac6f1..9fe52025 100644
--- a/librsvg/rsvg-cairo-draw.c
+++ b/librsvg/rsvg-cairo-draw.c
@@ -196,7 +196,8 @@ rsvg_cairo_generate_mask (cairo_t * cr, RsvgNode *mask, RsvgDrawingCtx *ctx, Rsv
     RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
     cairo_surface_t *surface;
     cairo_t *mask_cr, *save_cr;
-    RsvgState *state = rsvg_drawing_ctx_get_current_state (ctx);
+    RsvgState *state;
+    guint8 opacity;
     guint8 *pixels;
     guint32 width = render->width, height = render->height;
     guint32 rowstride = width * 4, row, i;
@@ -286,6 +287,9 @@ rsvg_cairo_generate_mask (cairo_t * cr, RsvgNode *mask, RsvgDrawingCtx *ctx, Rsv
 
     render->cr = save_cr;
 
+    state = rsvg_drawing_ctx_get_current_state (ctx);
+    opacity = rsvg_state_get_opacity (state);
+
     for (row = 0; row < height; row++) {
         guint8 *row_data = (pixels + (row * rowstride));
         for (i = 0; i < width; i++) {
@@ -311,7 +315,7 @@ rsvg_cairo_generate_mask (cairo_t * cr, RsvgNode *mask, RsvgDrawingCtx *ctx, Rsv
              */
             *pixel = ((((*pixel & 0x00ff0000) >> 16) * 14042 +
                        ((*pixel & 0x0000ff00) >>  8) * 47240 +
-                       ((*pixel & 0x000000ff)      ) * 4769    ) * state->opacity);
+                       ((*pixel & 0x000000ff)      ) * 4769    ) * opacity);
         }
     }
 
@@ -328,17 +332,28 @@ static void
 rsvg_cairo_push_render_stack (RsvgDrawingCtx * ctx)
 {
     RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
+    RsvgState *state;
+    const char *clip_path;
+    const char *filter;
+    const char *mask;
+    guint8 opacity;
+    cairo_operator_t comp_op;
     cairo_surface_t *surface;
     cairo_t *child_cr;
     RsvgBbox *bbox;
-    RsvgState *state = rsvg_drawing_ctx_get_current_state (ctx);
-    cairo_operator_t comp_op = rsvg_state_get_comp_op (state);
     gboolean lateclip = FALSE;
     cairo_matrix_t affine;
 
-    if (state->clip_path) {
+    state = rsvg_drawing_ctx_get_current_state (ctx);
+    clip_path = rsvg_state_get_clip_path (state);
+    filter = rsvg_state_get_filter (state);
+    mask = rsvg_state_get_mask (state);
+    opacity = rsvg_state_get_opacity (state);
+    comp_op = rsvg_state_get_comp_op (state);
+
+    if (clip_path) {
         RsvgNode *node;
-        node = rsvg_drawing_ctx_acquire_node_of_type (ctx, state->clip_path, RSVG_NODE_TYPE_CLIP_PATH);
+        node = rsvg_drawing_ctx_acquire_node_of_type (ctx, clip_path, RSVG_NODE_TYPE_CLIP_PATH);
         if (node) {
             switch (rsvg_node_clip_path_get_units (node)) {
             case userSpaceOnUse:
@@ -357,12 +372,12 @@ rsvg_cairo_push_render_stack (RsvgDrawingCtx * ctx)
         }
     }
 
-    if (state->opacity == 0xFF
-        && !state->filter && !state->mask && !lateclip && (comp_op == CAIRO_OPERATOR_OVER)
+    if (opacity == 0xFF
+        && !filter && !mask && !lateclip && (comp_op == CAIRO_OPERATOR_OVER)
         && (state->enable_background == RSVG_ENABLE_BACKGROUND_ACCUMULATE))
         return;
 
-    if (!state->filter) {
+    if (!filter) {
         surface = cairo_surface_create_similar (cairo_get_target (render->cr),
                                                 CAIRO_CONTENT_COLOR_ALPHA,
                                                 render->width, render->height);
@@ -412,16 +427,28 @@ static void
 rsvg_cairo_pop_render_stack (RsvgDrawingCtx * ctx)
 {
     RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
+    RsvgState *state;
+    const char *clip_path;
+    const char *filter;
+    const char *mask;
+    guint8 opacity;
+    cairo_operator_t comp_op;
     cairo_t *child_cr = render->cr;
     RsvgNode *lateclip = NULL;
     cairo_surface_t *surface = NULL;
-    RsvgState *state = rsvg_drawing_ctx_get_current_state (ctx);
-    cairo_operator_t comp_op = rsvg_state_get_comp_op (state);
     gboolean nest, needs_destroy = FALSE;
 
-    if (state->clip_path) {
+    state = rsvg_drawing_ctx_get_current_state (ctx);
+    clip_path = rsvg_state_get_clip_path (state);
+    filter = rsvg_state_get_filter (state);
+    mask = rsvg_state_get_mask (state);
+    opacity = rsvg_state_get_opacity (state);
+    comp_op = rsvg_state_get_comp_op (state);
+
+    if (clip_path) {
         RsvgNode *node;
-        node = rsvg_drawing_ctx_acquire_node_of_type (ctx, state->clip_path, RSVG_NODE_TYPE_CLIP_PATH);
+
+        node = rsvg_drawing_ctx_acquire_node_of_type (ctx, clip_path, RSVG_NODE_TYPE_CLIP_PATH);
         if (node) {
             if (rsvg_node_clip_path_get_units (node) == objectBoundingBox) {
                 lateclip = node;
@@ -431,25 +458,25 @@ rsvg_cairo_pop_render_stack (RsvgDrawingCtx * ctx)
         }
     }
 
-    if (state->opacity == 0xFF
-        && !state->filter && !state->mask && !lateclip && (comp_op == CAIRO_OPERATOR_OVER)
+    if (opacity == 0xFF
+        && !filter && !mask && !lateclip && (comp_op == CAIRO_OPERATOR_OVER)
         && (state->enable_background == RSVG_ENABLE_BACKGROUND_ACCUMULATE))
         return;
 
     surface = cairo_get_target (child_cr);
 
-    if (state->filter) {
-        RsvgNode *filter;
+    if (filter) {
+        RsvgNode *node;
         cairo_surface_t *output;
 
         output = render->surfaces_stack->data;
         render->surfaces_stack = g_list_delete_link (render->surfaces_stack, render->surfaces_stack);
 
-        filter = rsvg_drawing_ctx_acquire_node_of_type (ctx, state->filter, RSVG_NODE_TYPE_FILTER);
-        if (filter) {
+        node = rsvg_drawing_ctx_acquire_node_of_type (ctx, filter, RSVG_NODE_TYPE_FILTER);
+        if (node) {
             needs_destroy = TRUE;
-            surface = rsvg_filter_render (filter, output, ctx, &render->bbox, "2103");
-            rsvg_drawing_ctx_release_node (ctx, filter);
+            surface = rsvg_filter_render (node, output, ctx, &render->bbox, "2103");
+            rsvg_drawing_ctx_release_node (ctx, node);
 
             /* Don't destroy the output surface, it's owned by child_cr */
         }
@@ -471,16 +498,16 @@ rsvg_cairo_pop_render_stack (RsvgDrawingCtx * ctx)
 
     cairo_set_operator (render->cr, comp_op);
 
-    if (state->mask) {
-        RsvgNode *mask;
+    if (mask) {
+        RsvgNode *node;
 
-        mask = rsvg_drawing_ctx_acquire_node_of_type (ctx, state->mask, RSVG_NODE_TYPE_MASK);
-        if (mask) {
-            rsvg_cairo_generate_mask (render->cr, mask, ctx, &render->bbox);
-            rsvg_drawing_ctx_release_node (ctx, mask);
+        node = rsvg_drawing_ctx_acquire_node_of_type (ctx, mask, RSVG_NODE_TYPE_MASK);
+        if (node) {
+            rsvg_cairo_generate_mask (render->cr, node, ctx, &render->bbox);
+            rsvg_drawing_ctx_release_node (ctx, node);
         }
-    } else if (state->opacity != 0xFF)
-        cairo_paint_with_alpha (render->cr, (double) state->opacity / 255.0);
+    } else if (opacity != 0xFF)
+        cairo_paint_with_alpha (render->cr, (double) opacity / 255.0);
     else
         cairo_paint (render->cr);
 
diff --git a/librsvg/rsvg-styles.c b/librsvg/rsvg-styles.c
index 84c7d6b3..c709b33d 100644
--- a/librsvg/rsvg-styles.c
+++ b/librsvg/rsvg-styles.c
@@ -1495,12 +1495,36 @@ rsvg_state_get_affine (const RsvgState *state)
     return rsvg_state_rust_get_affine (state->state_rust);
 }
 
+const char *
+rsvg_state_get_clip_path (RsvgState *state)
+{
+    return state->clip_path;
+}
+
 void
 rsvg_state_set_affine (RsvgState *state, cairo_matrix_t affine)
 {
     rsvg_state_rust_set_affine (state->state_rust, affine);
 }
 
+const char *
+rsvg_state_get_filter (RsvgState *state)
+{
+    return state->filter;
+}
+
+const char *
+rsvg_state_get_mask (RsvgState *state)
+{
+    return state->mask;
+}
+
+guint8
+rsvg_state_get_opacity (RsvgState *state)
+{
+    return state->opacity;
+}
+
 RsvgPaintServer *
 rsvg_state_get_stroke (RsvgState *state)
 {
diff --git a/librsvg/rsvg-styles.h b/librsvg/rsvg-styles.h
index b66005e1..e51d2510 100644
--- a/librsvg/rsvg-styles.h
+++ b/librsvg/rsvg-styles.h
@@ -170,6 +170,18 @@ cairo_matrix_t rsvg_state_get_affine (const RsvgState *state);
 G_GNUC_INTERNAL
 void rsvg_state_set_affine (RsvgState *state, cairo_matrix_t affine);
 
+G_GNUC_INTERNAL
+const char *rsvg_state_get_clip_path (RsvgState *state);
+
+G_GNUC_INTERNAL
+const char *rsvg_state_get_filter (RsvgState *state);
+
+G_GNUC_INTERNAL
+const char *rsvg_state_get_mask (RsvgState *state);
+
+G_GNUC_INTERNAL
+guint8 rsvg_state_get_opacity (RsvgState *state);
+
 G_GNUC_INTERNAL
 RsvgPaintServer *rsvg_state_get_stroke (RsvgState *state);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]