diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2013-01-17 15:36:35 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2013-01-17 15:36:35 +0000 |
commit | d0272c4558539706abf015c32f0032641474fda2 (patch) | |
tree | c515aec3bead8ea52eff2f566a2092968a53c4a2 /libs | |
parent | a3bd17970ef1f168d7d942a130ec4934251f45fe (diff) |
cache cairo_pattern_t's for PixFader so that we don't generate one per fader, but rather one per size+color combination
git-svn-id: svn://localhost/ardour2/branches/3.0@13874 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/pixfader.h | 48 | ||||
-rw-r--r-- | libs/gtkmm2ext/pixfader.cc | 33 |
2 files changed, 65 insertions, 16 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/pixfader.h b/libs/gtkmm2ext/gtkmm2ext/pixfader.h index 039a822bcd..1e1a76d744 100644 --- a/libs/gtkmm2ext/gtkmm2ext/pixfader.h +++ b/libs/gtkmm2ext/gtkmm2ext/pixfader.h @@ -70,9 +70,52 @@ class PixFader : public Gtk::DrawingArea private: int span, girth; int _orien; + cairo_pattern_t* pattern; + + struct FaderImage { + cairo_pattern_t* pattern; + double fr; + double fg; + double fb; + double br; + double bg; + double bb; + int width; + int height; + + FaderImage (cairo_pattern_t* p, + double afr, double afg, double afb, + double abr, double abg, double abb, + int w, int h) + : pattern (p) + , fr (afr) + , fg (afg) + , fb (afb) + , br (abr) + , bg (abg) + , bb (abb) + , width (w) + , height (h) + {} + + bool matches (double afr, double afg, double afb, + double abr, double abg, double abb, + int w, int h) { + return width == w && + height == h && + afr == fr && + afg == fg && + afb == fb && + abr == br && + abg == bg && + abb == bb; + } + }; - cairo_pattern_t* pattern; - cairo_pattern_t* texture_pattern; + static std::list<FaderImage*> _patterns; + static cairo_pattern_t* find_pattern (double afr, double afg, double afb, + double abr, double abg, double abb, + int w, int h); bool _hovering; @@ -88,7 +131,6 @@ class PixFader : public Gtk::DrawingArea int display_span (); void set_adjustment_from_event (GdkEventButton *); void update_unity_position (); - void free_patterns (); void create_patterns(); }; diff --git a/libs/gtkmm2ext/pixfader.cc b/libs/gtkmm2ext/pixfader.cc index 43657a5902..994c719cd3 100644 --- a/libs/gtkmm2ext/pixfader.cc +++ b/libs/gtkmm2ext/pixfader.cc @@ -33,13 +33,14 @@ using namespace std; #define CORNER_RADIUS 4 #define FADER_RESERVE (2*CORNER_RADIUS) +std::list<PixFader::FaderImage*> PixFader::_patterns; + PixFader::PixFader (Gtk::Adjustment& adj, int orientation, int fader_length, int fader_girth) : adjustment (adj) , span (fader_length) , girth (fader_girth) , _orien (orientation) , pattern (0) - , texture_pattern (0) , _hovering (false) , last_drawn (-1) , dragging (false) @@ -55,27 +56,24 @@ PixFader::PixFader (Gtk::Adjustment& adj, int orientation, int fader_length, int PixFader::~PixFader () { - free_patterns (); } -void -PixFader::free_patterns () +cairo_pattern_t* +PixFader::find_pattern (double afr, double afg, double afb, + double abr, double abg, double abb, + int w, int h) { - if (pattern) { - cairo_pattern_destroy (pattern); - pattern = 0; - } - if (texture_pattern) { - cairo_pattern_destroy (texture_pattern); - texture_pattern = 0; + for (list<FaderImage*>::iterator f = _patterns.begin(); f != _patterns.end(); ++f) { + if ((*f)->matches (afr, afg, afb, abr, abg, abb, w, h)) { + return (*f)->pattern; + } } + return 0; } void PixFader::create_patterns () { - free_patterns (); - Gdk::Color c = get_style()->get_fg (get_state()); float fr, fg, fb; float br, bg, bb; @@ -96,6 +94,11 @@ PixFader::create_patterns () double w = get_width(); + if ((pattern = find_pattern (fr, fg, fb, br, bg, bb, get_width(), get_height())) != 0) { + /* found it - use it */ + return; + } + if (_orien == VERT) { surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, get_width(), get_height() * 2.0); @@ -154,6 +157,10 @@ PixFader::create_patterns () pattern = cairo_pattern_create_for_surface (surface); } + /* cache it for others to use */ + + _patterns.push_back (new FaderImage (pattern, fr, fg, fb, br, bg, bb, get_width(), get_height())); + cairo_destroy (tc); cairo_surface_destroy (surface); |