Ardour  9.0-pre0-582-g084a23a80d
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 "canvas/visibility.h"
27 #include "canvas/item.h"
28 
29 typedef void (*ImageReleaseCallback)(uint8_t *d, void *arg);
30 
31 namespace ArdourCanvas {
32 
33 
34 class LIBCANVAS_API Image : public Item
35 {
36 public:
37  Image (Canvas *, Cairo::Format, int width, int height);
38  Image (Item*, Cairo::Format, int width, int height);
39 
40  struct Data {
41  Data (uint8_t *d, int w, int h, int s, Cairo::Format fmt)
42  : data (d)
43  , width (w)
44  , height (h)
45  , stride (s)
46  , format (fmt)
47  , destroy_callback(NULL)
48  , destroy_arg(NULL)
49  {}
50 
51  virtual ~Data () {
52  if (destroy_callback) {
53  destroy_callback(data, destroy_arg);
54  } else {
55  delete [] data;
56  }
57  }
58 
59  uint8_t* data;
60  int width;
61  int height;
62  int stride;
63  Cairo::Format format;
65  void* destroy_arg;
66  };
67 
79  std::shared_ptr<Data> get_image (bool allocate_data = true);
80 
81 
91  void put_image (std::shared_ptr<Data>);
92 
93  void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
94  void compute_bounding_box () const;
95 
96 private:
97  Cairo::Format _format;
98  int _width;
99  int _height;
100  mutable std::shared_ptr<Data> _current;
101  std::shared_ptr<Data> _pending;
102  mutable bool _need_render;
103  mutable Cairo::RefPtr<Cairo::Surface> _surface;
104 
105  void accept_data ();
108 };
109 
110 }
111 #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
std::shared_ptr< Data > _pending
PBD::Signal< void()> DataReady
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