diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2013-04-10 15:27:55 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2013-04-10 15:27:55 -0400 |
commit | ae2b39b2e346548e2bf9f6cb308d8bd0b9d64005 (patch) | |
tree | 11e6fbec50a2fbcc62b6a8601ad7dd99f4ed020f | |
parent | 204da61f98906ef737b4e32b467cb2857622a711 (diff) |
remove intermediate GdkPixbuf from waveview rendering, and use shared_array<> to manage peak data
-rw-r--r-- | libs/canvas/canvas/wave_view.h | 33 | ||||
-rw-r--r-- | libs/canvas/wave_view.cc | 53 |
2 files changed, 62 insertions, 24 deletions
diff --git a/libs/canvas/canvas/wave_view.h b/libs/canvas/canvas/wave_view.h index b8c96cb672..97753c597d 100644 --- a/libs/canvas/canvas/wave_view.h +++ b/libs/canvas/canvas/wave_view.h @@ -1,4 +1,25 @@ +/* + Copyright (C) 2011-2013 Paul Davis + Author: Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #include <boost/shared_ptr.hpp> +#include <boost/shared_array.hpp> #include "pbd/properties.h" @@ -88,12 +109,12 @@ private: return _end; } - ARDOUR::PeakData* peaks () const { + boost::shared_array<ARDOUR::PeakData> peaks () const { return _peaks; } - Glib::RefPtr<Gdk::Pixbuf> pixbuf (); - void clear_pixbuf (); + Cairo::RefPtr<Cairo::ImageSurface> image(); + void clear_image (); private: Coord position (float) const; @@ -102,15 +123,15 @@ private: int _start; int _end; int _n_peaks; - ARDOUR::PeakData* _peaks; - Glib::RefPtr<Gdk::Pixbuf> _pixbuf; + boost::shared_array<ARDOUR::PeakData> _peaks; + Cairo::RefPtr<Cairo::ImageSurface> _image; }; friend class CacheEntry; friend class ::WaveViewTest; void invalidate_whole_cache (); - void invalidate_pixbuf_cache (); + void invalidate_image_cache (); boost::shared_ptr<ARDOUR::AudioRegion> _region; int _channel; diff --git a/libs/canvas/wave_view.cc b/libs/canvas/wave_view.cc index 030aeb7ecc..53aca22316 100644 --- a/libs/canvas/wave_view.cc +++ b/libs/canvas/wave_view.cc @@ -1,3 +1,23 @@ +/* + Copyright (C) 2011-2013 Paul Davis + Author: Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #include <cairomm/cairomm.h> #include "gtkmm2ext/utils.h" @@ -124,7 +144,7 @@ WaveView::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) cons context->translate (left, 0); - Gdk::Cairo::set_source_pixbuf (context, render->pixbuf (), render->start() - p, 0); + context->set_source (render->image(), render->start() - p, 0); context->paint (); context->restore (); @@ -168,7 +188,7 @@ WaveView::set_height (Distance height) _bounding_box_dirty = true; end_change (); - invalidate_pixbuf_cache (); + invalidate_image_cache (); } void @@ -195,10 +215,10 @@ WaveView::invalidate_whole_cache () } void -WaveView::invalidate_pixbuf_cache () +WaveView::invalidate_image_cache () { for (list<CacheEntry*>::iterator i = _cache.begin(); i != _cache.end(); ++i) { - (*i)->clear_pixbuf (); + (*i)->clear_image (); } } @@ -228,10 +248,10 @@ WaveView::CacheEntry::CacheEntry ( , _end (end) { _n_peaks = _end - _start; - _peaks = new PeakData[_n_peaks]; + _peaks.reset (new PeakData[_n_peaks]); _wave_view->_region->read_peaks ( - _peaks, + _peaks.get(), _n_peaks, _start * _wave_view->_frames_per_pixel, (_end - _start) * _wave_view->_frames_per_pixel, @@ -242,16 +262,15 @@ WaveView::CacheEntry::CacheEntry ( WaveView::CacheEntry::~CacheEntry () { - delete[] _peaks; } -Glib::RefPtr<Gdk::Pixbuf> -WaveView::CacheEntry::pixbuf () +Cairo::RefPtr<Cairo::ImageSurface> +WaveView::CacheEntry::image () { - if (!_pixbuf) { - _pixbuf = Gdk::Pixbuf::create (Gdk::COLORSPACE_RGB, true, 8, _n_peaks, _wave_view->_height); - Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, _n_peaks, _wave_view->_height); - Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (surface); + if (!_image) { + + _image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, _n_peaks, _wave_view->_height); + Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (_image); _wave_view->setup_outline_context (context); context->move_to (0.5, position (_peaks[0].min)); @@ -272,11 +291,9 @@ WaveView::CacheEntry::pixbuf () context->line_to (i + 0.5, position (_peaks[i].min) + 1); context->stroke (); } - - Gtkmm2ext::convert_bgra_to_rgba (surface->get_data(), _pixbuf->get_pixels(), _n_peaks, _wave_view->_height); } - return _pixbuf; + return _image; } @@ -287,9 +304,9 @@ WaveView::CacheEntry::position (float s) const } void -WaveView::CacheEntry::clear_pixbuf () +WaveView::CacheEntry::clear_image () { - _pixbuf.reset (); + _image.clear (); } |