Only support GLVideoView when building with wxWidgets >= 3.1.0.
[dcpomatic.git] / src / wx / gl_video_view.h
index 4f509049b3d4d954b60fd748f36f7188c24f9dff..7ef7b565aaa2fa00f787a8eb212bfc4ab1a30fe0 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
+#include "lib/warnings.h"
+
+DCPOMATIC_DISABLE_WARNINGS
+#include <wx/glcanvas.h>
+#include <wx/wx.h>
+DCPOMATIC_ENABLE_WARNINGS
+
+/* The OpenGL API in wxWidgets 3.0.x is sufficiently different to make it awkward to support,
+ * and I think it may even have things missing that we require (e.g. the attributes parameter
+ * to wxGLContext).  Hence we only support the GLVideoView on wxWidgets 3.1.0 and higher
+ * (which only excludes the old macOS builds, since wxWidgets 3.1.x does not support macOS
+ * 10.9 or earlier).
+ */
+#if wxCHECK_VERSION(3,1,0)
+
 #include "video_view.h"
 #include "lib/signaller.h"
 #include "lib/position.h"
-#include <wx/wx.h>
-#include <wx/glcanvas.h>
 #include <dcp/util.h>
-#include <boost/shared_ptr.hpp>
+#include <boost/atomic.hpp>
 #include <boost/thread.hpp>
 #include <boost/thread/condition.hpp>
 #undef None
 #undef Success
+#undef Status
+
+
+class Texture
+{
+public:
+       Texture (GLint unpack_alignment);
+       ~Texture ();
+
+       Texture (Texture const&) = delete;
+       Texture& operator= (Texture const&) = delete;
+
+       void bind ();
+       void set (std::shared_ptr<const Image> image);
+
+private:
+       GLuint _name;
+       GLint _unpack_alignment;
+       boost::optional<dcp::Size> _size;
+};
+
 
 class GLVideoView : public VideoView
 {
@@ -36,39 +71,85 @@ public:
        GLVideoView (FilmViewer* viewer, wxWindow* parent);
        ~GLVideoView ();
 
-       void set_image (boost::shared_ptr<const Image> image);
-       wxWindow* get () const {
+       wxWindow* get () const override {
                return _canvas;
        }
-       void update ();
-       void start ();
-       void stop ();
+       void update () override;
+       void start () override;
+       void stop () override;
 
-       bool display_next_frame (bool);
+       NextFrameResult display_next_frame (bool) override;
 
        bool vsync_enabled () const {
                return _vsync_enabled;
        }
 
+       std::map<GLenum, std::string> information () const {
+               return _information;
+       }
+
 private:
+       void set_image (std::shared_ptr<const PlayerVideo> pv);
+       void set_image_and_draw ();
        void draw (Position<int> inter_position, dcp::Size inter_size);
        void thread ();
+       void thread_playing ();
        void request_one_shot ();
-       void create ();
        void check_for_butler_errors ();
+       void ensure_context ();
+       void size_changed (wxSizeEvent const &);
+       void setup_shaders ();
+       void set_border_colour (GLuint program);
 
        wxGLCanvas* _canvas;
        wxGLContext* _context;
 
-       GLuint _id;
-       boost::optional<dcp::Size> _size;
+       template <class T>
+       class Last
+       {
+       public:
+               void set_next (T const& next) {
+                       _next = next;
+               }
+
+               bool changed () const {
+                       return !_value || *_value != _next;
+               }
+
+               void update () {
+                       _value = _next;
+               }
+
+       private:
+               boost::optional<T> _value;
+               T _next;
+       };
+
+       Last<wxSize> _last_canvas_size;
+       Last<dcp::Size> _last_video_size;
+       Last<Position<int>> _last_inter_position;
+       Last<dcp::Size> _last_inter_size;
+       Last<dcp::Size> _last_out_size;
+
+       boost::atomic<wxSize> _canvas_size;
+       std::unique_ptr<Texture> _video_texture;
+       std::unique_ptr<Texture> _subtitle_texture;
+       bool _have_subtitle_to_render = false;
        bool _vsync_enabled;
-       boost::thread* _thread;
+       boost::thread _thread;
 
        boost::mutex _playing_mutex;
-       boost::condition _playing_condition;
-       bool _playing;
-       bool _one_shot;
+       boost::condition _thread_work_condition;
+       boost::atomic<bool> _playing;
+       boost::atomic<bool> _one_shot;
 
-       boost::shared_ptr<wxTimer> _timer;
+       GLuint _vao;
+       GLint _fragment_type;
+       bool _setup_shaders_done = false;
+
+       std::shared_ptr<wxTimer> _timer;
+
+       std::map<GLenum, std::string> _information;
 };
+
+#endif