[librsvg: 3/6] drawing_ctx: move initial rect calculation to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/6] drawing_ctx: move initial rect calculation to rust
- Date: Tue, 15 May 2018 15:08:47 +0000 (UTC)
commit 175374b7d20560dbddb46c660eaa24b8466e29d3
Author: Paolo Borelli <pborelli gnome org>
Date: Sun May 13 18:53:33 2018 +0200
drawing_ctx: move initial rect calculation to rust
librsvg/rsvg-drawing-ctx.c | 45 ++++++++-------------------------------
rsvg_internals/src/drawing_ctx.rs | 29 +++++++++++++++++++++++++
rsvg_internals/src/lib.rs | 6 +++++-
3 files changed, 43 insertions(+), 37 deletions(-)
---
diff --git a/librsvg/rsvg-drawing-ctx.c b/librsvg/rsvg-drawing-ctx.c
index 630227ff..02132cfb 100644
--- a/librsvg/rsvg-drawing-ctx.c
+++ b/librsvg/rsvg-drawing-ctx.c
@@ -52,6 +52,12 @@ void rsvg_cairo_add_clipping_rect (RsvgDrawingCtx *ctx,
double w,
double h);
+/* Implemented in rsvg_internals/src/draw.rs */
+G_GNUC_INTERNAL
+void rsvg_drawing_ctx_transformed_image_bounding_box (cairo_matrix_t *affine,
+ double width, double height,
+ double *x0, double *y0, double *x1, double *y1);
+
static void
rsvg_cairo_generate_mask (cairo_t * cr, RsvgNode *mask, RsvgDrawingCtx *ctx)
{
@@ -255,39 +261,6 @@ rsvg_cairo_clip (RsvgDrawingCtx *ctx, RsvgNode *node_clip_path, RsvgBbox *bbox)
cairo_clip (ctx->cr);
}
-static void
-rsvg_cairo_transformed_image_bounding_box (cairo_matrix_t *affine,
- double width, double height,
- double *x0, double *y0, double *x1, double *y1)
-{
- double x00 = 0, x01 = 0, x10 = width, x11 = width;
- double y00 = 0, y01 = height, y10 = 0, y11 = height;
- double t;
-
- /* transform the four corners of the image */
- cairo_matrix_transform_point (affine, &x00, &y00);
- cairo_matrix_transform_point (affine, &x01, &y01);
- cairo_matrix_transform_point (affine, &x10, &y10);
- cairo_matrix_transform_point (affine, &x11, &y11);
-
- /* find minimum and maximum coordinates */
- t = x00 < x01 ? x00 : x01;
- t = t < x10 ? t : x10;
- *x0 = floor (t < x11 ? t : x11);
-
- t = y00 < y01 ? y00 : y01;
- t = t < y10 ? t : y10;
- *y0 = floor (t < y11 ? t : y11);
-
- t = x00 > x01 ? x00 : x01;
- t = t > x10 ? t : x10;
- *x1 = ceil (t > x11 ? t : x11);
-
- t = y00 > y01 ? y00 : y01;
- t = t > y10 ? t : y10;
- *y1 = ceil (t > y11 ? t : y11);
-}
-
RsvgDrawingCtx *
rsvg_drawing_ctx_new (cairo_t *cr, RsvgHandle *handle)
{
@@ -309,9 +282,9 @@ rsvg_drawing_ctx_new (cairo_t *cr, RsvgHandle *handle)
/* find bounding box of image as transformed by the current cairo context
* The size of this bounding box determines the size of the intermediate
* surfaces allocated during drawing. */
- rsvg_cairo_transformed_image_bounding_box (&affine,
- data.width, data.height,
- &bbx0, &bby0, &bbx1, &bby1);
+ rsvg_drawing_ctx_transformed_image_bounding_box (&affine,
+ data.width, data.height,
+ &bbx0, &bby0, &bbx1, &bby1);
draw->initial_cr = cr;
draw->cr = cr;
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index c30fd7ef..7edd9e69 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -11,6 +11,7 @@ use bbox::RsvgBbox;
use length::LengthUnit;
use node::NodeType;
use node::RsvgNode;
+use rect;
use state::{self, BaselineShift, FontSize, RsvgState, State};
pub enum RsvgDrawingCtx {}
@@ -390,6 +391,34 @@ impl AcquiredNode {
}
}
+#[no_mangle]
+pub extern "C" fn rsvg_drawing_ctx_transformed_image_bounding_box(
+ affine: *const cairo::Matrix,
+ w: f64,
+ h: f64,
+ x0: *mut libc::c_double,
+ y0: *mut libc::c_double,
+ x1: *mut libc::c_double,
+ y1: *mut libc::c_double,
+) {
+ let affine = unsafe { &*affine };
+ let r = cairo::Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: w,
+ height: h,
+ };
+
+ let r_out = rect::transform(affine, &r);
+
+ unsafe {
+ *x0 = r_out.x.floor();
+ *y0 = r_out.y.floor();
+ *x1 = (r_out.x + r_out.width).ceil();
+ *y1 = (r_out.y + r_out.height).ceil();
+ }
+}
+
#[no_mangle]
pub extern "C" fn rsvg_drawing_ctx_state_push(draw_ctx: *mut RsvgDrawingCtx) {
state_push(draw_ctx);
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 5aa731a9..fc0334d0 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -33,7 +33,11 @@ pub use color::{rsvg_css_parse_color, ColorKind, ColorSpec};
pub use draw::rsvg_cairo_add_clipping_rect;
-pub use drawing_ctx::{rsvg_drawing_ctx_state_pop, rsvg_drawing_ctx_state_push};
+pub use drawing_ctx::{
+ rsvg_drawing_ctx_state_pop,
+ rsvg_drawing_ctx_state_push,
+ rsvg_drawing_ctx_transformed_image_bounding_box,
+};
pub use gradient::{rsvg_node_linear_gradient_new, rsvg_node_radial_gradient_new};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]