X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cef_capture.cpp;h=e46f0c065f7287e0dce70992a070cea557a0497d;hb=6cc6c194b3eb245a04af531c7a6adb582673f2e7;hp=76c5c7f753c8630ff6a796de58ac660daff65bf1;hpb=a1fac4049d79171dc40f0cd416c1358fd4dc2d3c;p=nageru diff --git a/cef_capture.cpp b/cef_capture.cpp index 76c5c7f..e46f0c0 100644 --- a/cef_capture.cpp +++ b/cef_capture.cpp @@ -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 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 browser, PaintElementType ty bool NageruCEFClient::GetViewRect(CefRefPtr browser, CefRect &rect) { + return parent->GetViewRect(rect); +} + +bool CEFCapture::GetViewRect(CefRect &rect) +{ + lock_guard lock(resolution_mutex); rect = CefRect(0, 0, width, height); return true; }