Code

Initial reworking of forced redraw to work better with interruptible display
authorjohncoswell <johncoswell@users.sourceforge.net>
Wed, 6 Sep 2006 12:31:16 +0000 (12:31 +0000)
committerjohncoswell <johncoswell@users.sourceforge.net>
Wed, 6 Sep 2006 12:31:16 +0000 (12:31 +0000)
src/arc-context.cpp
src/display/sp-canvas.cpp
src/display/sp-canvas.h
src/nodepath.cpp
src/pen-context.cpp
src/rect-context.cpp
src/rubberband.cpp
src/spiral-context.cpp
src/star-context.cpp

index 032d7febb7375f75f29cc257806bd02033e483ff..0b0aad79e563890d2fcea8120b8a992e920f0593 100644 (file)
@@ -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);
     }
 }
 
index 6cb3990ddd498f875b3485b2c4c3fe6654cec69a..1f89e8bae5e51469ff25a0f61554325492ad7b8f 100644 (file)
@@ -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;
 }
 
 /**
index f9f4330fc4f48194261292020cebfc98c14a6131..ebc9845f38feea4fff8b96cc284b243cbfe93936 100644 (file)
@@ -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);
index 12de70eda760e5b856dcefd627f0171d09b518bc..257071a42ae2b455caeb75e766512e2a91d57893 100644 (file)
@@ -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);
 }
 
 /**
index adfc5eb7aa061ec27418968ed6ae774b91d20baa..96140a06cd2b7c2cd0f3d4ed181d742c826fcafb 100644 (file)
@@ -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);
 }
index b337b53a1f5bd5e3e819f4c5cb2d677bdfee5883..b03cdeead7c08dc5aee4bd0a3be52900a8587bfc 100644 (file)
@@ -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);
     }
 }
 
index 49fb34592bd935cf5d283e01b2c594dfa233ed03..cc0e70a7444c564dc72cacd8e58f3288b33ead26 100644 (file)
@@ -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));
 }
 
index e878154ba47dc493328aa8f14c64e87081ae4aad..1dc6bd6cbbd9064e8a89ef8b2cc35a075477452c 100644 (file)
@@ -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);
     }
 }
 
index fc1d710528ed07b5df78ee3a3b58428f0eb3eb25..74b252860ee13c083eec82d085e8abb5f9573f9b 100644 (file)
@@ -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);
     }
 }