Handle pending player changes more efficiently.
authorCarl Hetherington <cth@carlh.net>
Tue, 9 Feb 2021 13:05:46 +0000 (14:05 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 9 Feb 2021 13:05:46 +0000 (14:05 +0100)
Rather than looping over all changes, possibly calling a refresh
method for each, coalesce them.

src/wx/film_viewer.cc
src/wx/film_viewer.h

index 1993f00117aae3c13a6a45458c74ce9334d550b3..b9e9bd5331ae07c9b2959446a5a50a8ae9b69e4c 100644 (file)
@@ -67,6 +67,7 @@ using std::make_pair;
 using std::exception;
 using std::shared_ptr;
 using std::dynamic_pointer_cast;
+using std::vector;
 using std::weak_ptr;
 using boost::optional;
 #if BOOST_VERSION >= 106100
@@ -384,25 +385,40 @@ FilmViewer::player_change (ChangeType type, int property, bool frequent)
                return;
        }
 
+       player_change ({property});
+}
+
+void
+FilmViewer::player_change (vector<int> properties)
+{
        calculate_sizes ();
-       bool refreshed = false;
-       if (
-               property == VideoContentProperty::CROP ||
-               property == VideoContentProperty::SCALE ||
-               property == VideoContentProperty::FADE_IN ||
-               property == VideoContentProperty::FADE_OUT ||
-               property == VideoContentProperty::COLOUR_CONVERSION ||
-               property == PlayerProperty::VIDEO_CONTAINER_SIZE ||
-               property == PlayerProperty::FILM_CONTAINER
-               ) {
-               refreshed = quick_refresh ();
-       }
-
-       if (!refreshed) {
+
+       bool try_quick_refresh = false;
+       bool update_ccap_tracks = false;
+
+       for (auto i: properties) {
+               if (
+                       i == VideoContentProperty::CROP ||
+                       i == VideoContentProperty::SCALE ||
+                       i == VideoContentProperty::FADE_IN ||
+                       i == VideoContentProperty::FADE_OUT ||
+                       i == VideoContentProperty::COLOUR_CONVERSION ||
+                       i == PlayerProperty::VIDEO_CONTAINER_SIZE ||
+                       i == PlayerProperty::FILM_CONTAINER
+                  ) {
+                       try_quick_refresh = true;
+               }
+
+               if (i == TextContentProperty::USE || i == TextContentProperty::TYPE || i == TextContentProperty::DCP_TRACK) {
+                       update_ccap_tracks = true;
+               }
+       }
+
+       if (!try_quick_refresh || !quick_refresh()) {
                slow_refresh ();
        }
 
-       if (property == TextContentProperty::USE || property == TextContentProperty::TYPE || property == TextContentProperty::DCP_TRACK) {
+       if (update_ccap_tracks) {
                _closed_captions_dialog->update_tracks (_film);
        }
 }
@@ -466,9 +482,7 @@ FilmViewer::set_coalesce_player_changes (bool c)
        _coalesce_player_changes = c;
 
        if (!c) {
-               for (auto i: _pending_player_changes) {
-                       player_change (ChangeType::DONE, i, false);
-               }
+               player_change (_pending_player_changes);
                _pending_player_changes.clear ();
        }
 }
index 125e4fd2d958787585be3ffe667e91063a1fa0a9..8024bb1bfc16ff9020b5596e057c1dbd0b9fb3df 100644 (file)
@@ -153,6 +153,7 @@ private:
        void video_view_sized ();
        void calculate_sizes ();
        void player_change (ChangeType type, int, bool);
+       void player_change (std::vector<int> properties);
        void idle_handler ();
        void request_idle_display_next_frame ();
        void film_change (ChangeType, Film::Property);