X-Git-Url: https://git.sesse.net/?p=nageru;a=blobdiff_plain;f=nageru_cef_app.cpp;fp=nageru_cef_app.cpp;h=bd8b9d6dd49d4a8b434730a6a86b230995df1a56;hp=0000000000000000000000000000000000000000;hb=b68d8a25951faf5b967b7a35fa0a363b4b68fbc0;hpb=25ea462c2847313afd702cea1db29199b845fbd4 diff --git a/nageru_cef_app.cpp b/nageru_cef_app.cpp new file mode 100644 index 0000000..bd8b9d6 --- /dev/null +++ b/nageru_cef_app.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include + +#include "nageru_cef_app.h" + +using namespace std; + +void NageruCefApp::OnBeforeCommandLineProcessing( + const CefString& process_type, + CefRefPtr command_line) +{ + command_line->AppendSwitch("disable-gpu"); + command_line->AppendSwitch("disable-gpu-compositing"); + command_line->AppendSwitch("enable-begin-frame-scheduling"); +} + +void NageruCefApp::OnBrowserDestroyed(CefRefPtr browser) +{ + lock_guard lock(cef_mutex); + pending_browsers.erase(browser.get()); + browser_closed_cond.notify_all(); +} + +void NageruCefApp::initialize_cef() +{ + unique_lock lock(cef_mutex); + if (cef_thread_refcount++ == 0) { + cef_thread = thread(&NageruCefApp::cef_thread_func, this); + } + cef_initialized_cond.wait(lock, [this]{ return cef_initialized; }); +} + +void NageruCefApp::close_browser(CefRefPtr browser) +{ + unique_lock lock(cef_mutex); + CefBrowser *raw_ptr = browser.get(); + pending_browsers.insert(raw_ptr); + browser->GetHost()->CloseBrowser(/*force_close=*/true); + browser = nullptr; + browser_closed_cond.wait(lock, [this, raw_ptr]{ return pending_browsers.count(raw_ptr) != 0; }); +} + +void NageruCefApp::unref_cef() +{ + unique_lock lock(cef_mutex); + if (--cef_thread_refcount == 0) { + CefPostTask(TID_UI, new CEFTaskAdapter(&CefQuitMessageLoop)); + cef_thread.join(); + } +} + +void NageruCefApp::cef_thread_func() +{ + CefMainArgs main_args; + CefSettings settings; + //settings.log_severity = LOGSEVERITY_VERBOSE; + settings.windowless_rendering_enabled = true; + settings.no_sandbox = true; + settings.command_line_args_disabled = false; + CefInitialize(main_args, settings, this, nullptr); + + { + lock_guard lock(cef_mutex); + cef_initialized = true; + } + cef_initialized_cond.notify_all(); + + CefRunMessageLoop(); + + CefShutdown(); +} +