From ae2b39b2e346548e2bf9f6cb308d8bd0b9d64005 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 10 Apr 2013 15:27:55 -0400 Subject: remove intermediate GdkPixbuf from waveview rendering, and use shared_array<> to manage peak data --- libs/canvas/canvas/wave_view.h | 33 +++++++++++++++++++++----- 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 + + 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 +#include #include "pbd/properties.h" @@ -88,12 +109,12 @@ private: return _end; } - ARDOUR::PeakData* peaks () const { + boost::shared_array peaks () const { return _peaks; } - Glib::RefPtr pixbuf (); - void clear_pixbuf (); + Cairo::RefPtr 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 _pixbuf; + boost::shared_array _peaks; + Cairo::RefPtr _image; }; friend class CacheEntry; friend class ::WaveViewTest; void invalidate_whole_cache (); - void invalidate_pixbuf_cache (); + void invalidate_image_cache (); boost::shared_ptr _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 + + 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 #include "gtkmm2ext/utils.h" @@ -124,7 +144,7 @@ WaveView::render (Rect const & area, Cairo::RefPtr 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::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 -WaveView::CacheEntry::pixbuf () +Cairo::RefPtr +WaveView::CacheEntry::image () { - if (!_pixbuf) { - _pixbuf = Gdk::Pixbuf::create (Gdk::COLORSPACE_RGB, true, 8, _n_peaks, _wave_view->_height); - Cairo::RefPtr surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, _n_peaks, _wave_view->_height); - Cairo::RefPtr context = Cairo::Context::create (surface); + if (!_image) { + + _image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, _n_peaks, _wave_view->_height); + Cairo::RefPtr 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 (); } -- cgit v1.2.3