2 Copyright (C) 2013 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include "canvas/image.h"
21 #include "gtkmm2ext/gui_thread.h"
23 using namespace ArdourCanvas;
25 Image::Image (Group* group, Cairo::Format fmt, int width, int height)
30 , _need_render (false)
32 DataReady.connect (data_connections, MISSING_INVALIDATOR, boost::bind (&Image::accept_data, this), gui_context());
36 Image::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
38 if (_need_render && _pending) {
39 _surface = Cairo::ImageSurface::create (_pending->data,
47 Rect self = item_to_window (Rect (0, 0, _width, _height));
48 boost::optional<Rect> draw = self.intersection (area);
50 if (_surface && draw) {
51 context->set_source (_surface, self.x0, self.y0);
52 context->rectangle (draw->x0, draw->y0, draw->width(), draw->height());
58 Image::compute_bounding_box () const
60 _bounding_box = boost::optional<Rect> (Rect (0, 0, _width, _height));
61 _bounding_box_dirty = false;
64 boost::shared_ptr<Image::Data>
65 Image::get_image (bool allocate_data)
67 /* can be called by any thread */
69 int stride = Cairo::ImageSurface::format_stride_for_width (_format, _width);
71 boost::shared_ptr<Data> d (new Data (new uint8_t[stride*_height], _width, _height, stride, _format));
74 boost::shared_ptr<Data> d (new Data (NULL, _width, _height, stride, _format));
80 Image::put_image (boost::shared_ptr<Data> d)
82 /* can be called by any thread */
85 DataReady (); /* EMIT SIGNAL */
91 /* must be executed in gui thread */
95 end_change (); // notify canvas that we need redrawing