remove intermediate GdkPixbuf from waveview rendering, and use shared_array<> to manage peak data

This commit is contained in:
Paul Davis 2013-04-10 15:27:55 -04:00
parent 204da61f98
commit ae2b39b2e3
2 changed files with 62 additions and 24 deletions

View file

@ -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_ptr.hpp>
#include <boost/shared_array.hpp>
#include "pbd/properties.h" #include "pbd/properties.h"
@ -88,12 +109,12 @@ private:
return _end; return _end;
} }
ARDOUR::PeakData* peaks () const { boost::shared_array<ARDOUR::PeakData> peaks () const {
return _peaks; return _peaks;
} }
Glib::RefPtr<Gdk::Pixbuf> pixbuf (); Cairo::RefPtr<Cairo::ImageSurface> image();
void clear_pixbuf (); void clear_image ();
private: private:
Coord position (float) const; Coord position (float) const;
@ -102,15 +123,15 @@ private:
int _start; int _start;
int _end; int _end;
int _n_peaks; int _n_peaks;
ARDOUR::PeakData* _peaks; boost::shared_array<ARDOUR::PeakData> _peaks;
Glib::RefPtr<Gdk::Pixbuf> _pixbuf; Cairo::RefPtr<Cairo::ImageSurface> _image;
}; };
friend class CacheEntry; friend class CacheEntry;
friend class ::WaveViewTest; friend class ::WaveViewTest;
void invalidate_whole_cache (); void invalidate_whole_cache ();
void invalidate_pixbuf_cache (); void invalidate_image_cache ();
boost::shared_ptr<ARDOUR::AudioRegion> _region; boost::shared_ptr<ARDOUR::AudioRegion> _region;
int _channel; int _channel;

View file

@ -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 <cairomm/cairomm.h>
#include "gtkmm2ext/utils.h" #include "gtkmm2ext/utils.h"
@ -124,7 +144,7 @@ WaveView::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) cons
context->translate (left, 0); 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->paint ();
context->restore (); context->restore ();
@ -168,7 +188,7 @@ WaveView::set_height (Distance height)
_bounding_box_dirty = true; _bounding_box_dirty = true;
end_change (); end_change ();
invalidate_pixbuf_cache (); invalidate_image_cache ();
} }
void void
@ -195,10 +215,10 @@ WaveView::invalidate_whole_cache ()
} }
void void
WaveView::invalidate_pixbuf_cache () WaveView::invalidate_image_cache ()
{ {
for (list<CacheEntry*>::iterator i = _cache.begin(); i != _cache.end(); ++i) { 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) , _end (end)
{ {
_n_peaks = _end - _start; _n_peaks = _end - _start;
_peaks = new PeakData[_n_peaks]; _peaks.reset (new PeakData[_n_peaks]);
_wave_view->_region->read_peaks ( _wave_view->_region->read_peaks (
_peaks, _peaks.get(),
_n_peaks, _n_peaks,
_start * _wave_view->_frames_per_pixel, _start * _wave_view->_frames_per_pixel,
(_end - _start) * _wave_view->_frames_per_pixel, (_end - _start) * _wave_view->_frames_per_pixel,
@ -242,16 +262,15 @@ WaveView::CacheEntry::CacheEntry (
WaveView::CacheEntry::~CacheEntry () WaveView::CacheEntry::~CacheEntry ()
{ {
delete[] _peaks;
} }
Glib::RefPtr<Gdk::Pixbuf> Cairo::RefPtr<Cairo::ImageSurface>
WaveView::CacheEntry::pixbuf () WaveView::CacheEntry::image ()
{ {
if (!_pixbuf) { if (!_image) {
_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); _image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, _n_peaks, _wave_view->_height);
Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (surface); Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (_image);
_wave_view->setup_outline_context (context); _wave_view->setup_outline_context (context);
context->move_to (0.5, position (_peaks[0].min)); 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->line_to (i + 0.5, position (_peaks[i].min) + 1);
context->stroke (); 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 void
WaveView::CacheEntry::clear_pixbuf () WaveView::CacheEntry::clear_image ()
{ {
_pixbuf.reset (); _image.clear ();
} }