Ardour  8.12
canvas/canvas/image.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013-2015 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2013 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __CANVAS_IMAGE__
21 #define __CANVAS_IMAGE__
22 
23 #include <cstdint>
24 #include <memory>
25 
26 #include <boost/shared_array.hpp>
27 
28 #include "canvas/visibility.h"
29 #include "canvas/item.h"
30 
31 typedef void (*ImageReleaseCallback)(uint8_t *d, void *arg);
32 
33 namespace ArdourCanvas {
34 
35 
36 class LIBCANVAS_API Image : public Item
37 {
38 public:
39  Image (Canvas *, Cairo::Format, int width, int height);
40  Image (Item*, Cairo::Format, int width, int height);
41 
42  struct Data {
43  Data (uint8_t *d, int w, int h, int s, Cairo::Format fmt)
44  : data (d)
45  , width (w)
46  , height (h)
47  , stride (s)
48  , format (fmt)
49  , destroy_callback(NULL)
50  , destroy_arg(NULL)
51  {}
52 
53  virtual ~Data () {
54  if (destroy_callback) {
55  destroy_callback(data, destroy_arg);
56  } else {
57  delete [] data;
58  }
59  }
60 
61  uint8_t* data;
62  int width;
63  int height;
64  int stride;
65  Cairo::Format format;
67  void* destroy_arg;
68  };
69 
81  std::shared_ptr<Data> get_image (bool allocate_data = true);
82 
83 
93  void put_image (std::shared_ptr<Data>);
94 
95  void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
96  void compute_bounding_box () const;
97 
98 private:
99  Cairo::Format _format;
100  int _width;
101  int _height;
102  mutable std::shared_ptr<Data> _current;
103  std::shared_ptr<Data> _pending;
104  mutable bool _need_render;
105  mutable Cairo::RefPtr<Cairo::Surface> _surface;
106 
107  void accept_data ();
108  PBD::Signal0<void> DataReady;
110 };
111 
112 }
113 #endif
void(* ImageReleaseCallback)(uint8_t *d, void *arg)
#define LIBCANVAS_API
void put_image(std::shared_ptr< Data >)
std::shared_ptr< Data > get_image(bool allocate_data=true)
Cairo::RefPtr< Cairo::Surface > _surface
void render(Rect const &, Cairo::RefPtr< Cairo::Context >) const
PBD::Signal0< void > DataReady
std::shared_ptr< Data > _pending
void compute_bounding_box() const
Image(Canvas *, Cairo::Format, int width, int height)
Image(Item *, Cairo::Format, int width, int height)
std::shared_ptr< Data > _current
PBD::ScopedConnectionList data_connections
ImageReleaseCallback destroy_callback
Data(uint8_t *d, int w, int h, int s, Cairo::Format fmt)
gint height
Definition: xcursors.h:1
gint width
Definition: xcursors.h:1