Don't try opening error dialogues from the GL thread.
[dcpomatic.git] / src / wx / gl_video_view.h
1 /*
2     Copyright (C) 2019 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 <wx/wx.h>
24 #include <wx/glcanvas.h>
25 #include <dcp/util.h>
26 #include <boost/shared_ptr.hpp>
27 #include <boost/thread.hpp>
28 #include <boost/thread/condition.hpp>
29 #undef None
30 #undef Success
31
32 class GLVideoView : public VideoView
33 {
34 public:
35         GLVideoView (FilmViewer* viewer, wxWindow* parent);
36         ~GLVideoView ();
37
38         void set_image (boost::shared_ptr<const Image> image);
39         wxWindow* get () const {
40                 return _canvas;
41         }
42         void update ();
43         void start ();
44         void stop ();
45
46         bool display_next_frame (bool);
47
48         bool vsync_enabled () const {
49                 return _vsync_enabled;
50         }
51
52 private:
53         void paint ();
54         void draw ();
55         void thread ();
56         void request_one_shot ();
57         void create ();
58         void check_for_butler_errors ();
59
60         wxGLCanvas* _canvas;
61         wxGLContext* _context;
62
63         GLuint _id;
64         boost::optional<dcp::Size> _size;
65         bool _vsync_enabled;
66         boost::thread* _thread;
67
68         boost::mutex _playing_mutex;
69         boost::condition _playing_condition;
70         bool _playing;
71         bool _one_shot;
72
73         boost::shared_ptr<wxTimer> _timer;
74 };