X-Git-Url: https://git.sesse.net/?p=nageru;a=blobdiff_plain;f=cef_capture.cpp;fp=cef_capture.cpp;h=a2f230aae9af610ec6710278b33f1ccbbe462472;hp=c05c2953deff7cc3837f1f203917eee8f734b843;hb=cd48c8ab6d7425d4b4d9fdb2493da69b44848c9e;hpb=b68d8a25951faf5b967b7a35fa0a363b4b68fbc0 diff --git a/cef_capture.cpp b/cef_capture.cpp index c05c295..a2f230a 100644 --- a/cef_capture.cpp +++ b/cef_capture.cpp @@ -39,6 +39,23 @@ CEFCapture::~CEFCapture() } } +void CEFCapture::post_to_cef_ui_thread(std::function &&func) +{ + lock_guard lock(browser_mutex); + if (browser != nullptr) { + CefPostTask(TID_UI, new CEFTaskAdapter(std::move(func))); + } else { + deferred_tasks.push_back(std::move(func)); + } +} + +void CEFCapture::set_url(const string &url) +{ + post_to_cef_ui_thread([this, url] { + browser->GetMainFrame()->LoadURL(url); + }); +} + void CEFCapture::OnPaint(const void *buffer, int width, int height) { steady_clock::time_point timestamp = steady_clock::now(); @@ -79,14 +96,22 @@ void CEFCapture::start_bm_capture() { cef_app->initialize_cef(); - CefBrowserSettings browser_settings; - browser_settings.web_security = cef_state_t::STATE_DISABLED; - browser_settings.webgl = cef_state_t::STATE_ENABLED; - browser_settings.windowless_frame_rate = 60; - - CefWindowInfo window_info; - window_info.SetAsWindowless(0); - CefBrowserHost::CreateBrowser(window_info, cef_client, start_url, browser_settings, nullptr); + CefPostTask(TID_UI, new CEFTaskAdapter([this]{ + lock_guard lock(browser_mutex); + + CefBrowserSettings browser_settings; + browser_settings.web_security = cef_state_t::STATE_DISABLED; + browser_settings.webgl = cef_state_t::STATE_ENABLED; + browser_settings.windowless_frame_rate = 60; + + CefWindowInfo window_info; + window_info.SetAsWindowless(0); + browser = CefBrowserHost::CreateBrowserSync(window_info, cef_client, start_url, browser_settings, nullptr); + for (function &task : deferred_tasks) { + task(); + } + deferred_tasks.clear(); + })); } void CEFCapture::stop_dequeue_thread()