]> git.sesse.net Git - nageru/blobdiff - cef_capture.cpp
Do not wait for OnBrowserDestroyed.
[nageru] / cef_capture.cpp
index 76c5c7f753c8630ff6a796de58ac660daff65bf1..e46f0c065f7287e0dce70992a070cea557a0497d 100644 (file)
@@ -60,6 +60,7 @@ void CEFCapture::set_url(const string &url)
 void CEFCapture::reload()
 {
        post_to_cef_ui_thread([this] {
+               loaded = false;
                browser->Reload();
        });
 }
@@ -85,6 +86,13 @@ void CEFCapture::execute_javascript_async(const string &js)
        });
 }
 
+void CEFCapture::resize(unsigned width, unsigned height)
+{
+       lock_guard<mutex> lock(resolution_mutex);
+       this->width = width;
+       this->height = height;
+}
+
 void CEFCapture::OnPaint(const void *buffer, int width, int height)
 {
        steady_clock::time_point timestamp = steady_clock::now();
@@ -99,16 +107,25 @@ void CEFCapture::OnPaint(const void *buffer, int width, int height)
        video_format.is_connected = true;
 
        FrameAllocator::Frame video_frame = video_frame_allocator->alloc_frame();
-       if (video_frame.data != nullptr) {
+       if (video_frame.data == nullptr) {
+               // We lost a frame, so we need to invalidate the entire thing.
+               // (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.)
+               post_to_cef_ui_thread([this] {
+                       browser->GetHost()->Invalidate(PET_VIEW);
+               });
+               ++timecode;
+       } else {
                assert(video_frame.size >= unsigned(width * height * 4));
                assert(!video_frame.interleaved);
                memcpy(video_frame.data, buffer, width * height * 4);
                video_frame.len = video_format.stride * height;
                video_frame.received_timestamp = timestamp;
+               frame_callback(timecode++,
+                       video_frame, 0, video_format,
+                       FrameAllocator::Frame(), 0, AudioFormat());
        }
-       frame_callback(timecode++,
-               video_frame, 0, video_format,
-               FrameAllocator::Frame(), 0, AudioFormat());
 }
 
 void CEFCapture::OnLoadEnd()
@@ -214,6 +231,12 @@ void NageruCEFClient::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType ty
 
 bool NageruCEFClient::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect)
 {
+       return parent->GetViewRect(rect);
+}
+
+bool CEFCapture::GetViewRect(CefRect &rect)
+{
+       lock_guard<mutex> lock(resolution_mutex);
        rect = CefRect(0, 0, width, height);
        return true;
 }