first compiling and theoretically correct version of Push2 canvas display.
[ardour.git] / libs / surfaces / push2 / canvas.h
1 /*
2     Copyright (C) 2016 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_push2_canvas_h__
21 #define __ardour_push2_canvas_h__
22
23 #include <cairomm/refptr.h>
24 #include <glibmm/threads.h>
25
26 #include "canvas/canvas.h"
27
28 namespace Cairo {
29         class ImageSurface;
30         class Context;
31         class Region;
32 }
33
34 namespace ArdourSurface {
35
36 class Push2;
37
38 /* A canvas which renders to the Push2 display */
39
40 class Push2Canvas : public ArdourCanvas::Canvas
41 {
42   public:
43         Push2Canvas (Push2& p2, int cols, int rows);
44         ~Push2Canvas();
45
46         void request_redraw ();
47         void request_redraw (ArdourCanvas::Rect const &);
48         bool vblank ();
49
50         void splash ();
51
52         Cairo::RefPtr<Cairo::Context> image_context() { return context; }
53
54         int rows() const { return _rows; }
55         int cols() const { return _cols; }
56
57         static double inter_button_spacing() { return 120.0; }
58
59         ArdourCanvas::Coord width() const { return cols(); }
60         ArdourCanvas::Coord height() const { return rows(); }
61         void request_size (ArdourCanvas::Duple);
62         ArdourCanvas::Rect visible_area () const;
63
64         /* API that does nothing since we have no input events */
65         void ungrab () {}
66         void grab (ArdourCanvas::Item*) {}
67         void focus (ArdourCanvas::Item*) {}
68         void unfocus (ArdourCanvas::Item*) {}
69         void re_enter() {}
70         void pick_current_item (int) {}
71         void pick_current_item (ArdourCanvas::Duple const &, int) {}
72         bool get_mouse_position (ArdourCanvas::Duple&) const { return false; }
73
74   private:
75         Push2& p2;
76         int _cols;
77         int _rows;
78
79         static const int pixels_per_row;
80         int pixel_area () const { return _rows * pixels_per_row; }
81
82         uint8_t   frame_header[16];
83         uint16_t* device_frame_buffer;
84
85         Cairo::RefPtr<Cairo::ImageSurface> frame_buffer;
86         Cairo::RefPtr<Cairo::Context> context;
87         Cairo::RefPtr<Cairo::Region> expose_region;
88
89         bool expose ();
90         int blit_to_device_frame_buffer ();
91 };
92
93 } /* namespace ArdourSurface */
94
95 #endif /* __ardour_push2_canvas_h__ */