Commit b65a3539 authored by Paolo Borelli's avatar Paolo Borelli

drawing_ctx: move push/pop state to rust

parent fbfc8c4a
......@@ -134,9 +134,9 @@ Then, `rsvg_handle_render_cairo_sub()` starts the recursive drawing
process by calling
`rsvg_drawing_ctx_draw_node_from_stack()`, starting at the tree root
(`handle->priv->treebase`). In turn, that function creates a
temporary `state` struct by calling `rsvg_state_push()`, calls
`rsvg_node_draw()` on the current node, and destroys the temporary
`state` struct with `rsvg_state_pop()`.
temporary `state` struct by calling `rsvg_drawing_ctx_state_push()`,
calls `rsvg_node_draw()` on the current node, and destroys the temporary
`state` struct with `rsvg_drawing_ctx_state_pop()`.
Each node draws itself in the following way:
......
......@@ -512,11 +512,9 @@ rsvg_drawing_ctx_draw_node_from_stack (RsvgDrawingCtx *ctx,
state = rsvg_node_get_state (node);
if (state->visible) {
rsvg_state_push (ctx);
rsvg_drawing_ctx_state_push (ctx);
rsvg_node_draw (node, ctx, dominate, clipping);
rsvg_state_pop (ctx);
rsvg_drawing_ctx_state_pop (ctx);
}
ctx->drawsub_stack = stacksave;
......
......@@ -81,9 +81,9 @@ rsvg_cairo_clip (RsvgDrawingCtx * ctx, RsvgNode *node_clip_path, RsvgBbox * bbox
orig_bbox = save->bbox;
rsvg_state_push (ctx);
rsvg_drawing_ctx_state_push (ctx);
rsvg_node_draw_children (node_clip_path, ctx, 0, TRUE);
rsvg_state_pop (ctx);
rsvg_drawing_ctx_state_pop (ctx);
if (clip_units == objectBoundingBox) {
rsvg_state_set_affine (clip_path_state, affinesave);
......
......@@ -272,9 +272,9 @@ rsvg_cairo_generate_mask (cairo_t * cr, RsvgNode *mask, RsvgDrawingCtx *ctx, Rsv
rsvg_drawing_ctx_push_view_box (ctx, 1, 1);
}
rsvg_state_push (ctx);
rsvg_drawing_ctx_state_push (ctx);
rsvg_node_draw_children (mask, ctx, 0, FALSE);
rsvg_state_pop (ctx);
rsvg_drawing_ctx_state_pop (ctx);
if (content_units == objectBoundingBox) {
RsvgState *mask_state;
......
......@@ -175,7 +175,7 @@ rsvg_cairo_new_drawing_ctx (cairo_t * cr, RsvgHandle * handle)
draw->acquired_nodes = NULL;
draw->is_testing = handle->priv->is_testing;
rsvg_state_push (draw);
rsvg_drawing_ctx_state_push (draw);
state = rsvg_drawing_ctx_get_current_state (draw);
state_affine = rsvg_state_get_affine (state);
......
......@@ -450,6 +450,12 @@ RsvgState *rsvg_drawing_ctx_get_current_state (RsvgDrawingCtx * ctx);
G_GNUC_INTERNAL
void rsvg_drawing_ctx_set_current_state (RsvgDrawingCtx * ctx, RsvgState *state);
/* Implemented in rust/src/drawing_ctx.rs */
G_GNUC_INTERNAL
void rsvg_drawing_ctx_state_pop (RsvgDrawingCtx * ctx);
G_GNUC_INTERNAL
void rsvg_drawing_ctx_state_push (RsvgDrawingCtx * ctx);
G_GNUC_INTERNAL
RsvgNode *rsvg_drawing_ctx_acquire_node (RsvgDrawingCtx * ctx, const char *url);
G_GNUC_INTERNAL
......
......@@ -194,7 +194,7 @@ rsvg_state_init (RsvgState * state)
state->state_rust = rsvg_state_rust_new();
}
static RsvgState *
RsvgState *
rsvg_state_new_with_parent (RsvgState *parent)
{
RsvgState *state;
......@@ -1649,22 +1649,6 @@ rsvg_state_free_all (RsvgState * state)
}
}
void
rsvg_state_push (RsvgDrawingCtx * ctx)
{
ctx->state = rsvg_state_new_with_parent (ctx->state);
}
void
rsvg_state_pop (RsvgDrawingCtx * ctx)
{
RsvgState *dead_state = ctx->state;
ctx->state = dead_state->parent;
rsvg_state_free (dead_state);
}
cairo_matrix_t
rsvg_state_get_affine (const RsvgState *state)
{
......
......@@ -159,6 +159,9 @@ struct _RsvgState {
G_GNUC_INTERNAL
RsvgState *rsvg_state_new (void);
G_GNUC_INTERNAL
RsvgState *rsvg_state_new_with_parent (RsvgState *parent);
G_GNUC_INTERNAL
void rsvg_state_free (RsvgState *state);
......@@ -187,11 +190,6 @@ gboolean rsvg_parse_transform (cairo_matrix_t *matrix, const char *src) G_GNUC
G_GNUC_INTERNAL
RsvgState *rsvg_state_parent (RsvgState * state);
G_GNUC_INTERNAL
void rsvg_state_pop (RsvgDrawingCtx * ctx);
G_GNUC_INTERNAL
void rsvg_state_push (RsvgDrawingCtx * ctx);
/* Implemented in rust/src/state.rs */
G_GNUC_INTERNAL
void rsvg_state_reconstruct (RsvgState *state, RsvgNode *current);
......
......@@ -6,6 +6,7 @@ use glib_sys;
use libc;
use pango;
use pango_sys;
use std::ptr;
use bbox::RsvgBbox;
use length::LengthUnit;
......@@ -17,6 +18,9 @@ pub enum RsvgDrawingCtx {}
#[allow(improper_ctypes)]
extern "C" {
fn rsvg_drawing_ctx_get_current_state(draw_ctx: *const RsvgDrawingCtx) -> *mut RsvgState;
fn rsvg_drawing_ctx_set_current_state(draw_ctx: *mut RsvgDrawingCtx, state: *mut RsvgState);
fn rsvg_drawing_ctx_get_dpi(
draw_ctx: *const RsvgDrawingCtx,
out_dpi_x: *mut f64,
......@@ -72,11 +76,6 @@ extern "C" {
clipping: glib_sys::gboolean,
);
fn rsvg_drawing_ctx_get_current_state(draw_ctx: *const RsvgDrawingCtx) -> *mut RsvgState;
fn rsvg_state_push(draw_ctx: *const RsvgDrawingCtx);
fn rsvg_state_pop(draw_ctx: *const RsvgDrawingCtx);
fn rsvg_push_discrete_layer(draw_ctx: *const RsvgDrawingCtx, clipping: glib_sys::gboolean);
fn rsvg_pop_discrete_layer(draw_ctx: *const RsvgDrawingCtx, clipping: glib_sys::gboolean);
......@@ -301,15 +300,21 @@ pub fn get_current_state(draw_ctx: *const RsvgDrawingCtx) -> *mut RsvgState {
unsafe { rsvg_drawing_ctx_get_current_state(draw_ctx) }
}
pub fn state_push(draw_ctx: *const RsvgDrawingCtx) {
pub fn state_push(draw_ctx: *mut RsvgDrawingCtx) {
let state = state::new_with_parent(get_current_state(draw_ctx));
unsafe {
rsvg_state_push(draw_ctx);
rsvg_drawing_ctx_set_current_state(draw_ctx, state);
}
}
pub fn state_pop(draw_ctx: *const RsvgDrawingCtx) {
pub fn state_pop(draw_ctx: *mut RsvgDrawingCtx) {
let state = get_current_state(draw_ctx);
unsafe {
rsvg_state_pop(draw_ctx);
let parent = state::parent(state).unwrap_or(ptr::null_mut());
rsvg_drawing_ctx_set_current_state(draw_ctx, parent);
state::free(state);
}
}
......@@ -328,3 +333,13 @@ impl AcquiredNode {
unsafe { (*self.1).clone() }
}
}
#[no_mangle]
pub extern "C" fn rsvg_drawing_ctx_state_push(draw_ctx: *mut RsvgDrawingCtx) {
state_push(draw_ctx);
}
#[no_mangle]
pub extern "C" fn rsvg_drawing_ctx_state_pop(draw_ctx: *mut RsvgDrawingCtx) {
state_pop(draw_ctx);
}
......@@ -39,6 +39,8 @@ pub use cond::{
pub use draw::rsvg_cairo_add_clipping_rect;
pub use drawing_ctx::{rsvg_drawing_ctx_state_pop, rsvg_drawing_ctx_state_push};
pub use gradient::{rsvg_node_linear_gradient_new, rsvg_node_radial_gradient_new};
pub use length::{
......
......@@ -173,6 +173,7 @@ impl From<TextDecoration> for FontDecor {
#[allow(improper_ctypes)]
extern "C" {
fn rsvg_state_new() -> *mut RsvgState;
fn rsvg_state_new_with_parent(parent: *mut RsvgState) -> *mut RsvgState;
fn rsvg_state_free(state: *mut RsvgState);
fn rsvg_state_reinit(state: *mut RsvgState);
fn rsvg_state_clone(state: *mut RsvgState, src: *const RsvgState);
......@@ -218,6 +219,10 @@ pub fn new() -> *mut RsvgState {
unsafe { rsvg_state_new() }
}
pub fn new_with_parent(parent: *mut RsvgState) -> *mut RsvgState {
unsafe { rsvg_state_new_with_parent(parent) }
}
pub fn free(state: *mut RsvgState) {
unsafe {
rsvg_state_free(state);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment