3675b8ddcb6025dce1c84b37a917e6b3d7ee2e57
[dcpomatic.git] / src / wx / gl_video_view.h
1 /*
2     Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "video_view.h"
22 #include "lib/signaller.h"
23 #include "lib/position.h"
24 #include <wx/wx.h>
25 #include <wx/glcanvas.h>
26 #include <dcp/util.h>
27 #include <boost/atomic.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/thread.hpp>
30 #include <boost/thread/condition.hpp>
31 #undef None
32 #undef Success
33
34 class GLVideoView : public VideoView
35 {
36 public:
37         GLVideoView (FilmViewer* viewer, wxWindow* parent);
38         ~GLVideoView ();
39
40         wxWindow* get () const {
41                 return _canvas;
42         }
43         void update ();
44         void start ();
45         void stop ();
46
47         bool display_next_frame (bool);
48
49         bool vsync_enabled () const {
50                 return _vsync_enabled;
51         }
52
53 private:
54         void set_image (boost::shared_ptr<const Image> image);
55         void set_image_and_draw ();
56         void draw (Position<int> inter_position, dcp::Size inter_size);
57         void thread ();
58         void thread_playing ();
59         void request_one_shot ();
60         void create ();
61         void check_for_butler_errors ();
62
63         /* Mutex for use of _canvas; it's only contended when our ::thread
64            is started up so this may be overkill.
65          */
66         boost::mutex _canvas_mutex;
67         wxGLCanvas* _canvas;
68         wxGLContext* _context;
69
70         GLuint _id;
71         boost::optional<dcp::Size> _size;
72         bool _have_storage;
73         bool _vsync_enabled;
74         boost::thread _thread;
75
76         boost::mutex _playing_mutex;
77         boost::condition _thread_work_condition;
78         boost::atomic<bool> _playing;
79         boost::atomic<bool> _one_shot;
80
81         boost::shared_ptr<wxTimer> _timer;
82 };