From c2946ee00f6b5ec8205dd2fcb5b6d2ace2907436 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 11 Mar 2014 07:36:09 -0400 Subject: [PATCH] don't queue redraws when various canvas item properties are "reset" to the same value, plus supporting functions --- libs/canvas/canvas.cc | 2 +- libs/canvas/canvas/rectangle.h | 7 ++- libs/canvas/canvas/types.h | 3 ++ libs/canvas/line.cc | 98 +++++++++++++++++----------------- libs/canvas/poly_item.cc | 15 +++--- libs/canvas/rectangle.cc | 97 ++++++++++++++++----------------- libs/canvas/types.cc | 16 ++++++ 7 files changed, 131 insertions(+), 107 deletions(-) diff --git a/libs/canvas/canvas.cc b/libs/canvas/canvas.cc index 8ad608ea5e..d5d8562361 100644 --- a/libs/canvas/canvas.cc +++ b/libs/canvas/canvas.cc @@ -262,7 +262,7 @@ void Canvas::queue_draw_item_area (Item* item, Rect area) { ArdourCanvas::Rect canvas_area = item->item_to_canvas (area); - // cerr << "CANVAS " << this << " for " << item->whatami() << ' ' << item->name << " invalidate " << area << " TRANSLATE AS " << canvas_area << " window = " << canvas_to_window (canvas_area) << std::endl; + // cerr << "CANVAS " << this << " for " << item << ' ' << item->whatami() << ' ' << item->name << " invalidate " << area << " TRANSLATE AS " << canvas_area << " window = " << canvas_to_window (canvas_area) << std::endl; request_redraw (canvas_area); } diff --git a/libs/canvas/canvas/rectangle.h b/libs/canvas/canvas/rectangle.h index ff2ff994b7..91f23f9336 100644 --- a/libs/canvas/canvas/rectangle.h +++ b/libs/canvas/canvas/rectangle.h @@ -72,7 +72,12 @@ public: }; void set_outline_what (What); - void set_outline_what (int); + void set_outline_all () { + set_outline_what (ArdourCanvas::Rectangle::What (ArdourCanvas::Rectangle::TOP| + ArdourCanvas::Rectangle::LEFT| + ArdourCanvas::Rectangle::RIGHT| + ArdourCanvas::Rectangle::BOTTOM)); + } private: /** Our rectangle; note that x0 may not always be less than x1 diff --git a/libs/canvas/canvas/types.h b/libs/canvas/canvas/types.h index 1e8b7b145f..2800ccc91b 100644 --- a/libs/canvas/canvas/types.h +++ b/libs/canvas/canvas/types.h @@ -64,6 +64,7 @@ struct LIBCANVAS_API Duple extern LIBCANVAS_API Duple operator- (Duple const &); extern LIBCANVAS_API Duple operator+ (Duple const &, Duple const &); extern LIBCANVAS_API bool operator== (Duple const &, Duple const &); +extern LIBCANVAS_API bool operator!= (Duple const &, Duple const &); extern LIBCANVAS_API Duple operator- (Duple const &, Duple const &); extern LIBCANVAS_API Duple operator/ (Duple const &, double); extern LIBCANVAS_API std::ostream & operator<< (std::ostream &, Duple const &); @@ -106,6 +107,8 @@ struct LIBCANVAS_API Rect } }; +extern LIBCANVAS_API bool operator!= (Rect const &, Rect const &); + extern LIBCANVAS_API std::ostream & operator<< (std::ostream &, Rect const &); typedef std::vector Points; diff --git a/libs/canvas/line.cc b/libs/canvas/line.cc index 09f9061c85..8f04e2b278 100644 --- a/libs/canvas/line.cc +++ b/libs/canvas/line.cc @@ -77,53 +77,55 @@ Line::render (Rect const & /*area*/, Cairo::RefPtr context) cons void Line::set (Duple a, Duple b) { - begin_change (); - - _points[0] = a; - _points[1] = b; - - _bounding_box_dirty = true; - end_change (); - - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); + if (a != _points[0] || b != _points[1]) { + begin_change (); + + _points[0] = a; + _points[1] = b; + + _bounding_box_dirty = true; + end_change (); + } } void Line::set_x (Coord x0, Coord x1) { - begin_change (); - - _points[0].x = x0; - _points[1].x = x1; - - _bounding_box_dirty = true; - end_change (); - - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); + if (x0 != _points[0].x || x1 != _points[1].x) { + begin_change (); + + _points[0].x = x0; + _points[1].x = x1; + + _bounding_box_dirty = true; + end_change (); + } } void Line::set_x0 (Coord x0) { - begin_change (); - - _points[0].x = x0; - - _bounding_box_dirty = true; - end_change (); - - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); + if (x0 != _points[0].x) { + begin_change (); + + _points[0].x = x0; + + _bounding_box_dirty = true; + end_change (); + } } void Line::set_y0 (Coord y0) { - begin_change (); - - _points[0].y = y0; - - _bounding_box_dirty = true; - end_change (); + if (y0 != _points[0].y) { + begin_change (); + + _points[0].y = y0; + + _bounding_box_dirty = true; + end_change (); + } DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); } @@ -131,27 +133,27 @@ Line::set_y0 (Coord y0) void Line::set_x1 (Coord x1) { - begin_change (); - - _points[1].x = x1; - - _bounding_box_dirty = true; - end_change (); - - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); + if (x1 != _points[1].x) { + begin_change (); + + _points[1].x = x1; + + _bounding_box_dirty = true; + end_change (); + } } void Line::set_y1 (Coord y1) { - begin_change (); - - _points[1].y = y1; - - _bounding_box_dirty = true; - end_change (); - - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); + if (y1 != _points[1].y) { + begin_change (); + + _points[1].y = y1; + + _bounding_box_dirty = true; + end_change (); + } } bool diff --git a/libs/canvas/poly_item.cc b/libs/canvas/poly_item.cc index 88b9af7878..0d3369f70b 100644 --- a/libs/canvas/poly_item.cc +++ b/libs/canvas/poly_item.cc @@ -127,12 +127,15 @@ PolyItem::render_curve (Rect const & area, Cairo::RefPtr context void PolyItem::set (Points const & points) { - begin_change (); - - _points = points; - - _bounding_box_dirty = true; - end_change (); + if (_points != points) { + + begin_change (); + + _points = points; + + _bounding_box_dirty = true; + end_change (); + } } Points const & diff --git a/libs/canvas/rectangle.cc b/libs/canvas/rectangle.cc index 7fd61e6cc4..57c26874c4 100644 --- a/libs/canvas/rectangle.cc +++ b/libs/canvas/rectangle.cc @@ -139,82 +139,77 @@ Rectangle::set (Rect const & r) /* We don't update the bounding box here; it's just as cheap to do it when asked. */ - - begin_change (); - - _rect = r; - - _bounding_box_dirty = true; - end_change (); - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (set)\n"); + if (r != _rect) { + + begin_change (); + + _rect = r; + + _bounding_box_dirty = true; + end_change (); + } } void Rectangle::set_x0 (Coord x0) { - begin_change (); - - _rect.x0 = x0; - - _bounding_box_dirty = true; - end_change (); - - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x0)\n"); + if (x0 != _rect.x0) { + begin_change (); + + _rect.x0 = x0; + + _bounding_box_dirty = true; + end_change (); + } } void Rectangle::set_y0 (Coord y0) { - begin_change (); - - _rect.y0 = y0; - - _bounding_box_dirty = true; - end_change(); - - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y0)\n"); + if (y0 != _rect.y0) { + begin_change (); + + _rect.y0 = y0; + + _bounding_box_dirty = true; + end_change(); + } } void Rectangle::set_x1 (Coord x1) { - begin_change (); - - _rect.x1 = x1; - - _bounding_box_dirty = true; - end_change (); - - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x1)\n"); + if (x1 != _rect.x1) { + begin_change (); + + _rect.x1 = x1; + + _bounding_box_dirty = true; + end_change (); + } } void Rectangle::set_y1 (Coord y1) { - begin_change (); - - _rect.y1 = y1; - - _bounding_box_dirty = true; - end_change (); - - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y1)\n"); + if (y1 != _rect.y1) { + begin_change (); + + _rect.y1 = y1; + + _bounding_box_dirty = true; + end_change (); + } } void Rectangle::set_outline_what (What what) { - begin_change (); - - _outline_what = what; - - end_change (); -} - -void -Rectangle::set_outline_what (int what) -{ - set_outline_what ((What) what); + if (what != _outline_what) { + begin_visual_change (); + _outline_what = what; + end_visual_change (); + } } diff --git a/libs/canvas/types.cc b/libs/canvas/types.cc index 7d7a495df5..4fd064d746 100644 --- a/libs/canvas/types.cc +++ b/libs/canvas/types.cc @@ -121,6 +121,16 @@ Rect::fix () const return r; } +bool +ArdourCanvas::operator!= (Rect const& a, Rect const& b) +{ + return a.x0 != b.x0 || + a.x1 != b.x1 || + a.y0 != b.y0 || + a.y1 != b.y1; +} + + Duple ArdourCanvas::operator- (Duple const & o) { @@ -139,6 +149,12 @@ ArdourCanvas::operator== (Duple const & a, Duple const & b) return a.x == b.x && a.y == b.y; } +bool +ArdourCanvas::operator!= (Duple const & a, Duple const & b) +{ + return a.x != b.x || a.y != b.y; +} + Duple ArdourCanvas::operator- (Duple const & a, Duple const & b) {