add new canvas Image item, with somewhat optimized API for asynchronous, threaded...
[ardour.git] / libs / canvas / canvas / image.h
1 #ifndef __CANVAS_IMAGE__
2 #define __CANVAS_IMAGE__
3
4 #include <stdint.h>
5 #include <boost/shared_ptr.hpp>
6 #include <boost/shared_array.hpp>
7
8 #include "canvas/item.h"
9
10 namespace ArdourCanvas {
11
12 class Image : public Item
13 {
14 public:
15     Image (Group *, Cairo::Format, int width, int height);
16     
17     struct Data {
18         Data (boost::shared_array<uint8_t> d, int w, int h, int s, Cairo::Format fmt)
19                 : data (d)
20                 , width (w)
21                 , height (h)
22                 , stride (s)
23                 , format (fmt)
24         {}
25
26         boost::shared_array<uint8_t> data;
27         int width;
28         int height;
29         int stride;
30         Cairo::Format format;
31     };
32
33     boost::shared_ptr<Data> get_image ();
34     void put_image (boost::shared_ptr<Data>);
35
36     void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
37     void compute_bounding_box () const;
38     XMLNode* get_state () const;
39     void set_state (XMLNode const *);
40     
41 private:
42     Cairo::Format            _format;
43     int                      _width;
44     int                      _height;
45     int                      _data;
46     mutable boost::shared_ptr<Data>  _current;
47     boost::shared_ptr<Data>  _pending;
48     mutable bool             _need_render;
49     mutable Cairo::RefPtr<Cairo::Surface> _surface;
50
51     void accept_data ();
52     PBD::Signal0<void> DataReady;
53     PBD::ScopedConnectionList data_connections;
54 };
55
56 }
57 #endif