2 #include <cef_browser.h>
3 #include <cef_client.h>
4 #include <cef_version.h>
8 #include "nageru_cef_app.h"
12 void NageruCefApp::OnBeforeCommandLineProcessing(
13 const CefString& process_type,
14 CefRefPtr<CefCommandLine> command_line)
16 command_line->AppendSwitch("disable-gpu");
17 command_line->AppendSwitch("disable-gpu-compositing");
18 command_line->AppendSwitch("enable-begin-frame-scheduling");
21 void NageruCefApp::OnBrowserDestroyed(CefRefPtr<CefBrowser> browser)
23 lock_guard<mutex> lock(cef_mutex);
24 pending_browsers.erase(browser.get());
25 browser_closed_cond.notify_all();
28 void NageruCefApp::initialize_cef()
30 unique_lock<mutex> lock(cef_mutex);
31 if (cef_thread_refcount++ == 0) {
32 cef_thread = thread(&NageruCefApp::cef_thread_func, this);
34 cef_initialized_cond.wait(lock, [this]{ return cef_initialized; });
37 void NageruCefApp::close_browser(CefRefPtr<CefBrowser> browser)
39 unique_lock<mutex> lock(cef_mutex);
40 CefBrowser *raw_ptr = browser.get();
41 pending_browsers.insert(raw_ptr);
42 browser->GetHost()->CloseBrowser(/*force_close=*/true);
44 browser_closed_cond.wait(lock, [this, raw_ptr]{ return pending_browsers.count(raw_ptr) != 0; });
47 void NageruCefApp::unref_cef()
49 unique_lock<mutex> lock(cef_mutex);
50 if (--cef_thread_refcount == 0) {
51 CefPostTask(TID_UI, new CEFTaskAdapter(&CefQuitMessageLoop));
56 void NageruCefApp::cef_thread_func()
58 CefMainArgs main_args;
60 //settings.log_severity = LOGSEVERITY_VERBOSE;
61 settings.windowless_rendering_enabled = true;
62 settings.no_sandbox = true;
63 settings.command_line_args_disabled = false;
64 CefInitialize(main_args, settings, this, nullptr);
67 lock_guard<mutex> lock(cef_mutex);
68 cef_initialized = true;
70 cef_initialized_cond.notify_all();