[librsvg] Move add_clipping_rect() to Rust; remove it from the render vtable
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Move add_clipping_rect() to Rust; remove it from the render vtable
- Date: Thu, 29 Mar 2018 01:18:21 +0000 (UTC)
commit 38a7b5a83bdfdb3d8b3a122d59c968ea1edf7c6e
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Mar 28 15:43:21 2018 -0600
Move add_clipping_rect() to Rust; remove it from the render vtable
librsvg/rsvg-base.c | 6 ------
librsvg/rsvg-cairo-clip.c | 6 ------
librsvg/rsvg-cairo-draw.c | 22 ++++++++--------------
librsvg/rsvg-cairo-draw.h | 4 +---
librsvg/rsvg-cairo-render.c | 1 -
librsvg/rsvg-private.h | 5 +----
rsvg_internals/src/draw.rs | 21 +++++++++++++++++++++
rsvg_internals/src/drawing_ctx.rs | 14 --------------
rsvg_internals/src/image.rs | 4 ++--
rsvg_internals/src/lib.rs | 2 ++
rsvg_internals/src/marker.rs | 11 +++--------
rsvg_internals/src/viewport.rs | 7 ++++---
12 files changed, 42 insertions(+), 61 deletions(-)
---
diff --git a/librsvg/rsvg-base.c b/librsvg/rsvg-base.c
index 30df80ea..e2bee7d0 100644
--- a/librsvg/rsvg-base.c
+++ b/librsvg/rsvg-base.c
@@ -558,12 +558,6 @@ rsvg_get_end_marker (RsvgDrawingCtx *ctx)
return state->endMarker;
}
-void
-rsvg_drawing_ctx_add_clipping_rect (RsvgDrawingCtx * ctx, double x, double y, double w, double h)
-{
- ctx->render->add_clipping_rect (ctx, x, y, w, h);
-}
-
cairo_surface_t *
rsvg_get_surface_of_node (RsvgDrawingCtx * ctx, RsvgNode * drawable, double w, double h)
{
diff --git a/librsvg/rsvg-cairo-clip.c b/librsvg/rsvg-cairo-clip.c
index 4e7ed54d..2e841230 100644
--- a/librsvg/rsvg-cairo-clip.c
+++ b/librsvg/rsvg-cairo-clip.c
@@ -57,11 +57,6 @@ rsvg_cairo_clip_render_free (RsvgRender * self)
g_free (clip_render);
}
-static void
-rsvg_cairo_clip_add_clipping_rect (RsvgDrawingCtx * ctx, double x, double y, double w, double h)
-{
-}
-
static RsvgRender *
rsvg_cairo_clip_render_new (cairo_t *cr, RsvgCairoRender *parent)
{
@@ -74,7 +69,6 @@ rsvg_cairo_clip_render_new (cairo_t *cr, RsvgCairoRender *parent)
render->type = RSVG_RENDER_TYPE_CAIRO_CLIP;
render->free = rsvg_cairo_clip_render_free;
render->set_affine_on_cr = rsvg_cairo_set_affine_on_cr;
- render->add_clipping_rect = rsvg_cairo_clip_add_clipping_rect;
render->get_surface_of_node = NULL;
cairo_render->initial_cr = parent->initial_cr;
diff --git a/librsvg/rsvg-cairo-draw.c b/librsvg/rsvg-cairo-draw.c
index eb441a2b..82ede64f 100644
--- a/librsvg/rsvg-cairo-draw.c
+++ b/librsvg/rsvg-cairo-draw.c
@@ -53,6 +53,14 @@ gboolean rsvg_set_source_rsvg_paint_server (RsvgDrawingCtx * ctx,
RsvgBbox bbox,
guint32 current_color);
+/* Implemented in rsvg_internals/src/draw.rs */
+G_GNUC_INTERNAL
+void rsvg_cairo_add_clipping_rect (RsvgDrawingCtx *ctx,
+ double x,
+ double y,
+ double w,
+ double h);
+
void
rsvg_cairo_set_affine_on_cr (RsvgDrawingCtx *ctx, cairo_t *cr, cairo_matrix_t *affine)
{
@@ -517,20 +525,6 @@ rsvg_cairo_pop_discrete_layer (RsvgDrawingCtx * ctx, gboolean clipping)
cairo_restore (render->cr);
}
-void
-rsvg_cairo_add_clipping_rect (RsvgDrawingCtx * ctx, double x, double y, double w, double h)
-{
- RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render);
- cairo_t *cr = render->cr;
- cairo_matrix_t affine;
-
- affine = rsvg_state_get_affine (rsvg_current_state (ctx));
- rsvg_drawing_ctx_set_affine_on_cr (ctx, cr, &affine);
-
- cairo_rectangle (cr, x, y, w, h);
- cairo_clip (cr);
-}
-
cairo_surface_t *
rsvg_cairo_get_surface_of_node (RsvgDrawingCtx *ctx,
RsvgNode *drawable,
diff --git a/librsvg/rsvg-cairo-draw.h b/librsvg/rsvg-cairo-draw.h
index 99487306..cfd6ae09 100644
--- a/librsvg/rsvg-cairo-draw.h
+++ b/librsvg/rsvg-cairo-draw.h
@@ -47,9 +47,7 @@ G_GNUC_INTERNAL
void rsvg_cairo_push_discrete_layer (RsvgDrawingCtx *ctx, gboolean clipping);
G_GNUC_INTERNAL
void rsvg_cairo_pop_discrete_layer (RsvgDrawingCtx *ctx, gboolean clipping);
-G_GNUC_INTERNAL
-void rsvg_cairo_add_clipping_rect (RsvgDrawingCtx *ctx,
- double x, double y, double width, double height);
+
G_GNUC_INTERNAL
cairo_surface_t*rsvg_cairo_get_surface_of_node (RsvgDrawingCtx *ctx, RsvgNode *drawable,
double width, double height);
diff --git a/librsvg/rsvg-cairo-render.c b/librsvg/rsvg-cairo-render.c
index b3454bf0..d4326aca 100644
--- a/librsvg/rsvg-cairo-render.c
+++ b/librsvg/rsvg-cairo-render.c
@@ -74,7 +74,6 @@ rsvg_cairo_render_new (cairo_t * cr, double width, double height)
cairo_render->super.type = RSVG_RENDER_TYPE_CAIRO;
cairo_render->super.free = rsvg_cairo_render_free;
cairo_render->super.set_affine_on_cr = rsvg_cairo_set_affine_on_cr;
- cairo_render->super.add_clipping_rect = rsvg_cairo_add_clipping_rect;
cairo_render->super.get_surface_of_node = rsvg_cairo_get_surface_of_node;
cairo_render->width = width;
cairo_render->height = height;
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index ec4b1c35..091660bc 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -207,8 +207,6 @@ struct RsvgRender {
void (*free) (RsvgRender * self);
void (*set_affine_on_cr) (RsvgDrawingCtx *ctx, cairo_t *cr, cairo_matrix_t *affine);
- void (*add_clipping_rect) (RsvgDrawingCtx *ctx, double x, double y,
- double w, double h);
cairo_surface_t *(*get_surface_of_node) (RsvgDrawingCtx *ctx, RsvgNode * drawable,
double w, double h);
void (*insert_bbox) (RsvgDrawingCtx *ctx, RsvgBbox *bbox);
@@ -476,8 +474,7 @@ const char *rsvg_get_end_marker (RsvgDrawingCtx *ctx);
G_GNUC_INTERNAL
void rsvg_render_free (RsvgRender * render);
-G_GNUC_INTERNAL
-void rsvg_drawing_ctx_add_clipping_rect (RsvgDrawingCtx * ctx, double x, double y, double w, double h);
+
G_GNUC_INTERNAL
cairo_surface_t *rsvg_cairo_surface_from_pixbuf (const GdkPixbuf *pixbuf);
G_GNUC_INTERNAL
diff --git a/rsvg_internals/src/draw.rs b/rsvg_internals/src/draw.rs
index 59e65752..42421324 100644
--- a/rsvg_internals/src/draw.rs
+++ b/rsvg_internals/src/draw.rs
@@ -374,3 +374,24 @@ pub fn draw_surface(
drawing_ctx::insert_bbox(draw_ctx, &bbox);
}
+
+pub fn add_clipping_rect(draw_ctx: *mut RsvgDrawingCtx, x: f64, y: f64, w: f64, h: f64) {
+ let cr = drawing_ctx::get_cairo_context(draw_ctx);
+ let affine = drawing_ctx::get_current_state_affine(draw_ctx);
+
+ drawing_ctx::set_affine_on_cr(draw_ctx, &cr, &affine);
+
+ cr.rectangle(x, y, w, h);
+ cr.clip();
+}
+
+#[no_mangle]
+pub extern "C" fn rsvg_cairo_add_clipping_rect(
+ draw_ctx: *mut RsvgDrawingCtx,
+ x: f64,
+ y: f64,
+ w: f64,
+ h: f64,
+) {
+ add_clipping_rect(draw_ctx, x, y, w, h);
+}
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index ddd50e9f..c2bafd46 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -63,14 +63,6 @@ extern "C" {
draw_ctx: *const RsvgDrawingCtx,
) -> *mut pango_sys::PangoContext;
- fn rsvg_drawing_ctx_add_clipping_rect(
- draw_ctx: *const RsvgDrawingCtx,
- x: f64,
- y: f64,
- w: f64,
- h: f64,
- );
-
fn rsvg_drawing_ctx_insert_bbox(draw_ctx: *const RsvgDrawingCtx, bbox: *const RsvgBbox);
fn rsvg_drawing_ctx_draw_node_from_stack(
@@ -224,12 +216,6 @@ pub fn get_pango_context(draw_ctx: *const RsvgDrawingCtx) -> pango::Context {
unsafe { from_glib_full(rsvg_drawing_ctx_get_pango_context(draw_ctx)) }
}
-pub fn add_clipping_rect(draw_ctx: *const RsvgDrawingCtx, x: f64, y: f64, w: f64, h: f64) {
- unsafe {
- rsvg_drawing_ctx_add_clipping_rect(draw_ctx, x, y, w, h);
- }
-}
-
pub fn insert_bbox(draw_ctx: *const RsvgDrawingCtx, bbox: &RsvgBbox) {
unsafe {
rsvg_drawing_ctx_insert_bbox(draw_ctx, bbox as *const _);
diff --git a/rsvg_internals/src/image.rs b/rsvg_internals/src/image.rs
index feb1d284..2f77f2f5 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -9,7 +9,7 @@ use std::ptr;
use aspect_ratio::AspectRatio;
use attributes::Attribute;
-use draw::draw_surface;
+use draw::{add_clipping_rect, draw_surface};
use drawing_ctx::{self, RsvgDrawingCtx};
use handle::RsvgHandle;
use length::*;
@@ -111,7 +111,7 @@ impl NodeTrait for NodeImage {
let aspect = self.aspect.get();
if !state::is_overflow(state) && aspect.is_slice() {
- drawing_ctx::add_clipping_rect(draw_ctx, x, y, w, h);
+ add_clipping_rect(draw_ctx, x, y, w, h);
}
let (x, y, w, h) = aspect.compute(
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index b07fae78..b3fe0f1c 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -37,6 +37,8 @@ pub use cond::{
rsvg_cond_check_system_language,
};
+pub use draw::rsvg_cairo_add_clipping_rect;
+
pub use gradient::{rsvg_node_linear_gradient_new, rsvg_node_radial_gradient_new};
pub use length::{
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 21a11eca..d3a2818a 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -7,6 +7,7 @@ use cairo::MatrixTrait;
use aspect_ratio::*;
use attributes::Attribute;
+use draw::add_clipping_rect;
use drawing_ctx;
use drawing_ctx::RsvgDrawingCtx;
use error::*;
@@ -177,15 +178,9 @@ impl NodeMarker {
if !state::is_overflow(state) {
if let Some(vbox) = self.vbox.get() {
- drawing_ctx::add_clipping_rect(
- draw_ctx,
- vbox.0.x,
- vbox.0.y,
- vbox.0.width,
- vbox.0.height,
- );
+ add_clipping_rect(draw_ctx, vbox.0.x, vbox.0.y, vbox.0.width, vbox.0.height);
} else {
- drawing_ctx::add_clipping_rect(draw_ctx, 0.0, 0.0, marker_width, marker_height);
+ add_clipping_rect(draw_ctx, 0.0, 0.0, marker_width, marker_height);
}
}
diff --git a/rsvg_internals/src/viewport.rs b/rsvg_internals/src/viewport.rs
index 82619f3d..2bb999c2 100644
--- a/rsvg_internals/src/viewport.rs
+++ b/rsvg_internals/src/viewport.rs
@@ -2,6 +2,7 @@ use cairo;
use cairo::MatrixTrait;
use aspect_ratio::AspectRatio;
+use draw::add_clipping_rect;
use drawing_ctx::{self, RsvgDrawingCtx};
use float_eq_cairo::ApproxEqCairo;
use viewbox::*;
@@ -22,7 +23,7 @@ pub fn draw_in_viewport<F>(
vbox: Option<ViewBox>,
preserve_aspect_ratio: AspectRatio,
affine: cairo::Matrix,
- draw_ctx: *const RsvgDrawingCtx,
+ draw_ctx: *mut RsvgDrawingCtx,
clipping: bool,
draw_fn: F,
) where
@@ -55,7 +56,7 @@ trait ViewportCtx {
fn set_affine(&mut self, affine: cairo::Matrix);
}
-struct RsvgDrawingCtxWrapper(pub *const RsvgDrawingCtx);
+struct RsvgDrawingCtxWrapper(pub *mut RsvgDrawingCtx);
impl ViewportCtx for RsvgDrawingCtxWrapper {
fn push_view_box(&mut self, width: f64, height: f64) {
@@ -75,7 +76,7 @@ impl ViewportCtx for RsvgDrawingCtxWrapper {
}
fn add_clipping_rect(&mut self, x: f64, y: f64, w: f64, h: f64) {
- drawing_ctx::add_clipping_rect(self.0, x, y, w, h);
+ add_clipping_rect(self.0, x, y, w, h);
}
fn set_affine(&mut self, affine: cairo::Matrix) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]