]> git.sesse.net Git - nageru/commitdiff
When dropping CEF frames, ask for invalidation only a bit later.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 18 Mar 2018 22:10:24 +0000 (23:10 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 18 Mar 2018 22:10:24 +0000 (23:10 +0100)
cef_capture.cpp
cef_capture.h

index ff978f288640d8036cb33e1479b5e5c39c6a07d8..853c6b4916a6b1ddcfb4aa4b715f574f51e7cb40 100644 (file)
@@ -39,11 +39,15 @@ CEFCapture::~CEFCapture()
        }
 }
 
-void CEFCapture::post_to_cef_ui_thread(std::function<void()> &&func)
+void CEFCapture::post_to_cef_ui_thread(std::function<void()> &&func, int64_t delay_ms)
 {
        lock_guard<recursive_mutex> lock(browser_mutex);
        if (browser != nullptr) {
-               CefPostTask(TID_UI, new CEFTaskAdapter(std::move(func)));
+               if (delay_ms <= 0) {
+                       CefPostTask(TID_UI, new CEFTaskAdapter(std::move(func)));
+               } else {
+                       CefPostDelayedTask(TID_UI, new CEFTaskAdapter(std::move(func)), delay_ms);
+               }
        } else {
                deferred_tasks.push_back(std::move(func));
        }
@@ -112,12 +116,16 @@ void CEFCapture::OnPaint(const void *buffer, int width, int height)
                // (CEF only sends OnPaint when there are actual changes,
                // so we need to do this explicitly, or we could be stuck on an
                // old frame forever if the image doesn't change.)
+               //
+               // By adding a delay, we make sure we don't get a new frame
+               // delivered immediately (we probably already are on the UI thread),
+               // where we couldn't really deal with it.
                post_to_cef_ui_thread([this] {
                        lock_guard<recursive_mutex> lock(browser_mutex);
                        if (browser != nullptr) {  // Could happen if we are shutting down.
                                browser->GetHost()->Invalidate(PET_VIEW);
                        }
-               });
+               }, 16);
                ++timecode;
        } else {
                assert(video_frame.size >= unsigned(width * height * 4));
index 9e231c9d6fc654e3c9e769669bafceebf4abd816..0d9bd525b03d6bb330ea614499cbb52fdf74f3e2 100644 (file)
@@ -166,7 +166,7 @@ public:
        uint32_t get_current_audio_input() const override { return 0; }
 
 private:
-       void post_to_cef_ui_thread(std::function<void()> &&func);
+       void post_to_cef_ui_thread(std::function<void()> &&func, int64_t delay_ms = 0);
 
        CefRefPtr<NageruCEFClient> cef_client;