From e84cf433439f4d45c82a1090f84a890c13f059dc Mon Sep 17 00:00:00 2001 From: johncoswell Date: Wed, 6 Sep 2006 12:31:16 +0000 Subject: [PATCH] Initial reworking of forced redraw to work better with interruptible display --- src/arc-context.cpp | 4 ---- src/display/sp-canvas.cpp | 42 ++++++++++++++++++++------------------- src/display/sp-canvas.h | 7 ++++--- src/nodepath.cpp | 8 +++++--- src/pen-context.cpp | 6 +++--- src/rect-context.cpp | 4 ---- src/rubberband.cpp | 4 ---- src/spiral-context.cpp | 4 ---- src/star-context.cpp | 4 ---- 9 files changed, 34 insertions(+), 49 deletions(-) diff --git a/src/arc-context.cpp b/src/arc-context.cpp index 032d7febb..0b0aad79e 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -412,8 +412,6 @@ static void sp_arc_drag(SPArcContext *ac, NR::Point pt, guint state) NR::Rect const r = Inkscape::snap_rectangular_box(desktop, ac->item, pt, ac->center, state); - sp_canvas_force_full_redraws(desktop->canvas, 1); - sp_arc_position_set(SP_ARC(ac->item), r.midpoint()[NR::X], r.midpoint()[NR::Y], r.dimensions()[NR::X] / 2, r.dimensions()[NR::Y] / 2); @@ -439,8 +437,6 @@ static void sp_arc_finish(SPArcContext *ac) _("Create ellipse")); ac->item = NULL; - - sp_canvas_clear_forced_full_redraws(desktop->canvas); } } diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 6cb3990dd..1f89e8bae 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -978,7 +978,8 @@ sp_canvas_init (SPCanvas *canvas) canvas->redraw_count = 0; - canvas->forced_full_redraw_count = 0; + canvas->forced_redraw_count = 0; + canvas->forced_redraw_limit = 0; canvas->slowest_buffer = 0; } @@ -1694,8 +1695,12 @@ sp_canvas_paint_rect (SPCanvas *canvas, int xx0, int yy0, int xx1, int yy1) // Process events that may have arrived while we were busy drawing; // only if we're drawing multiple buffers, and only if this one was not very fast, // and only if we're allowed to interrupt this redraw - if (multiple_buffers && this_buffer > 25000 && !canvas->forced_full_redraw_count) { + bool ok_to_interrupt = (multiple_buffers && this_buffer > 25000); + if (ok_to_interrupt && canvas->forced_redraw_limit) { + ok_to_interrupt = (canvas->forced_redraw_count < canvas->forced_redraw_limit); + } + if (ok_to_interrupt) { // Run at most max_iterations of the main loop; we cannot process ALL events // here because some things (e.g. rubberband) flood with dirtying events but will // not redraw themselves @@ -1714,6 +1719,9 @@ sp_canvas_paint_rect (SPCanvas *canvas, int xx0, int yy0, int xx1, int yy1) // if so, force update and abort if (canvas->need_redraw || canvas->need_update) { canvas->slowest_buffer = slowest_buffer; + if (canvas->forced_redraw_limit) { + canvas->forced_redraw_count++; + } do_update (canvas); return; } @@ -1721,36 +1729,30 @@ sp_canvas_paint_rect (SPCanvas *canvas, int xx0, int yy0, int xx1, int yy1) } } - // We've finished a redraw; decrement the full redraw counter - if (canvas->forced_full_redraw_count > 0) { - canvas->forced_full_redraw_count--; - } - // Remember the slowest buffer of this paint in canvas canvas->slowest_buffer = slowest_buffer; + + // we've had a full redraw, reset the full redraw counter + if (canvas->forced_redraw_limit) { + canvas->forced_redraw_count = 0; + } } /** - * Force the next several screen redraws to not be interruptible. - * Used when having an accurate representation of the drawing canvas - * is more important than speed. - * - * In the future, this should be a toggle switch to be enabled/disabled - * when precise object drawing is necessary. + * Force a full redraw after a specified number of interrupted redraws */ void -sp_canvas_force_full_redraws(SPCanvas *canvas, unsigned int count) { - canvas->forced_full_redraw_count += count; +sp_canvas_force_full_redraw_after_interruptions(SPCanvas *canvas, unsigned int count) { + canvas->forced_redraw_limit = count; + canvas->forced_redraw_count = 0; } /** - * Flush all forced full redraw requests. - * Used when accurate representation of the drawing canvas is no - * longer needed. + * End forced full redraw requests */ void -sp_canvas_clear_forced_full_redraws(SPCanvas *canvas) { - canvas->forced_full_redraw_count = 0; +sp_canvas_end_forced_full_redraws(SPCanvas *canvas) { + canvas->forced_redraw_limit = 0; } /** diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h index f9f4330fc..ebc9845f3 100644 --- a/src/display/sp-canvas.h +++ b/src/display/sp-canvas.h @@ -161,7 +161,8 @@ struct SPCanvas { long redraw_count; glong slowest_buffer; - unsigned int forced_full_redraw_count; + unsigned int forced_redraw_count; + unsigned int forced_redraw_limit; /* For use by internal pick_current_item() function */ unsigned int left_grabbed_item : 1; @@ -189,8 +190,8 @@ void sp_canvas_scroll_to(SPCanvas *canvas, double cx, double cy, unsigned int cl void sp_canvas_update_now(SPCanvas *canvas); void sp_canvas_request_redraw(SPCanvas *canvas, int x1, int y1, int x2, int y2); -void sp_canvas_force_full_redraws(SPCanvas *canvas, unsigned int count); -void sp_canvas_clear_forced_full_redraws(SPCanvas *canvas); +void sp_canvas_force_full_redraw_after_interruptions(SPCanvas *canvas, unsigned int count); +void sp_canvas_end_forced_full_redraws(SPCanvas *canvas); void sp_canvas_window_to_world(SPCanvas const *canvas, double winx, double winy, double *worldx, double *worldy); void sp_canvas_world_to_window(SPCanvas const *canvas, double worldx, double worldy, double *winx, double *winy); diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 12de70eda..257071a42 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -441,8 +441,6 @@ static void update_object(Inkscape::NodePath::Path *np) SPCurve *curve = create_curve(np); - sp_canvas_force_full_redraws(np->desktop->canvas, 2); - sp_shape_set_curve(SP_SHAPE(np->path), curve, TRUE); sp_curve_unref(curve); @@ -485,7 +483,7 @@ void sp_nodepath_update_repr(Inkscape::NodePath::Path *np, const gchar *annotati g_return_if_fail(np != NULL); update_repr_internal(np); - sp_canvas_clear_forced_full_redraws(np->desktop->canvas); + //sp_canvas_end_forced_full_redraws(np->desktop->canvas); sp_document_done(sp_desktop_document(np->desktop), SP_VERB_CONTEXT_NODE, annotation); @@ -2990,6 +2988,7 @@ static void node_grabbed(SPKnot *knot, guint state, gpointer data) } n->is_dragging = true; + //sp_canvas_force_full_redraw_after_interruptions(n->subpath->nodepath->desktop->canvas, 5); sp_nodepath_remember_origins (n->subpath->nodepath); } @@ -3003,6 +3002,7 @@ static void node_ungrabbed(SPKnot *knot, guint state, gpointer data) n->dragging_out = NULL; n->is_dragging = false; + sp_canvas_end_forced_full_redraws(n->subpath->nodepath->desktop->canvas); sp_nodepath_update_repr(n->subpath->nodepath, _("Move nodes")); } @@ -3265,6 +3265,7 @@ static void node_handle_grabbed(SPKnot *knot, guint state, gpointer data) g_assert_not_reached(); } + //sp_canvas_force_full_redraw_after_interruptions(n->subpath->nodepath->desktop->canvas, 5); } /** @@ -3286,6 +3287,7 @@ static void node_handle_ungrabbed(SPKnot *knot, guint state, gpointer data) } sp_nodepath_update_repr(n->subpath->nodepath, _("Move node handle")); + //sp_canvas_end_forced_full_redraws(n->subpath->nodepath->desktop->canvas); } /** diff --git a/src/pen-context.cpp b/src/pen-context.cpp index adfc5eb7a..96140a06c 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -227,7 +227,7 @@ pen_cancel (SPPenContext *const pc) pc->_message_context->clear(); pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled")); - sp_canvas_clear_forced_full_redraws(pc->desktop->canvas); + //sp_canvas_clear_forced_full_redraws(pc->desktop->canvas); } /** @@ -1036,7 +1036,7 @@ spdc_pen_set_subsequent_point(SPPenContext *const pc, NR::Point const p, bool st g_assert( pc->npoints != 0 ); /* todo: Check callers to see whether 2 <= npoints is guaranteed. */ - sp_canvas_force_full_redraws(pc->desktop->canvas, 4); + //sp_canvas_force_full_redraws(pc->desktop->canvas, 4); pc->p[2] = p; pc->p[3] = p; @@ -1175,7 +1175,7 @@ spdc_pen_finish(SPPenContext *const pc, gboolean const closed) pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); } - sp_canvas_clear_forced_full_redraws(desktop->canvas); + //sp_canvas_clear_forced_full_redraws(desktop->canvas); pen_enable_events(pc); } diff --git a/src/rect-context.cpp b/src/rect-context.cpp index b337b53a1..b03cdeead 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -455,8 +455,6 @@ static void sp_rect_drag(SPRectContext &rc, NR::Point const pt, guint state) NR::Rect const r = Inkscape::snap_rectangular_box(desktop, rc.item, pt, rc.center, state); - sp_canvas_force_full_redraws(desktop->canvas, 2); - sp_rect_position_set(SP_RECT(rc.item), r.min()[NR::X], r.min()[NR::Y], r.dimensions()[NR::X], r.dimensions()[NR::Y]); if ( rc.rx != 0.0 ) { sp_rect_set_rx (SP_RECT(rc.item), TRUE, rc.rx); @@ -492,8 +490,6 @@ static void sp_rect_finish(SPRectContext *rc) _("Create rectangle")); rc->item = NULL; - - sp_canvas_clear_forced_full_redraws(dt->canvas); } } diff --git a/src/rubberband.cpp b/src/rubberband.cpp index 49fb34592..cc0e70a74 100644 --- a/src/rubberband.cpp +++ b/src/rubberband.cpp @@ -35,8 +35,6 @@ void Inkscape::Rubberband::start(SPDesktop *d, NR::Point const &p) void Inkscape::Rubberband::stop() { - sp_canvas_clear_forced_full_redraws(_desktop->canvas); - if (_canvas) { gtk_object_destroy((GtkObject *) _canvas); _canvas = NULL; @@ -52,8 +50,6 @@ void Inkscape::Rubberband::move(NR::Point const &p) _desktop->scroll_to_point(&p); _end = p; - sp_canvas_force_full_redraws(_desktop->canvas, 2); - _canvas->setRectangle(NR::Rect(_start, _end)); } diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index e878154ba..1dc6bd6cb 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -430,8 +430,6 @@ sp_spiral_drag(SPSpiralContext *sc, NR::Point p, guint state) arg = sp_round(arg, M_PI/snaps); } - sp_canvas_force_full_redraws(desktop->canvas, 1); - /* Fixme: these parameters should be got from dialog box */ sp_spiral_position_set(spiral, p0[NR::X], p0[NR::Y], /*expansion*/ sc->exp, @@ -464,8 +462,6 @@ sp_spiral_finish(SPSpiralContext *sc) /* TODO: annotate */ "spiral-context.cpp:462"); sc->item = NULL; - - sp_canvas_clear_forced_full_redraws(desktop->canvas); } } diff --git a/src/star-context.cpp b/src/star-context.cpp index fc1d71052..74b252860 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -442,8 +442,6 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state) arg1 = sp_round(arg1, M_PI / snaps); } - sp_canvas_force_full_redraws(desktop->canvas, 1); - sp_star_position_set(star, sc->magnitude, p0, r1, r1 * sc->proportion, arg1, arg1 + M_PI / sides, sc->isflatsided, sc->rounded, sc->randomized); @@ -476,8 +474,6 @@ sp_star_finish (SPStarContext * sc) /* TODO: annotate */ "star-context.cpp:474"); sc->item = NULL; - - sp_canvas_clear_forced_full_redraws(desktop->canvas); } } -- 2.30.2