From: Steinar H. Gunderson Date: Thu, 1 Mar 2018 08:30:23 +0000 (+0100) Subject: Add resize(), so that HTML inputs do not need to be locked to the video resolution. X-Git-Tag: 1.7.0~3 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=4ed8afda0ec060a66ca6af76d15afe62af543849;p=nageru Add resize(), so that HTML inputs do not need to be locked to the video resolution. --- diff --git a/cef_capture.cpp b/cef_capture.cpp index 9dc454b..e46f0c0 100644 --- a/cef_capture.cpp +++ b/cef_capture.cpp @@ -86,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(); @@ -224,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; } diff --git a/cef_capture.h b/cef_capture.h index c497179..311076e 100644 --- a/cef_capture.h +++ b/cef_capture.h @@ -85,9 +85,11 @@ public: void reload(); void set_max_fps(int max_fps); void execute_javascript_async(const std::string &js); + void resize(unsigned width, unsigned height); + // Callbacks from NageruCEFClient. void OnPaint(const void *buffer, int width, int height); - + bool GetViewRect(CefRect &rect); void OnLoadEnd(); // CaptureInterface. @@ -167,7 +169,13 @@ private: void post_to_cef_ui_thread(std::function &&func); CefRefPtr cef_client; - unsigned width, height; + + // Needs to be different from browser_mutex below, since GetViewRect + // can be called unpredictably from when we are already holding + // . + std::mutex resolution_mutex; + unsigned width, height; // Under . + int card_index = -1; bool has_dequeue_callbacks = false; diff --git a/theme.cpp b/theme.cpp index 8b2f6b6..5fc5a75 100644 --- a/theme.cpp +++ b/theme.cpp @@ -535,6 +535,16 @@ int HTMLInput_execute_javascript_async(lua_State* L) return 0; } +int HTMLInput_resize(lua_State* L) +{ + assert(lua_gettop(L) == 3); + CEFCapture **video_input = (CEFCapture **)luaL_checkudata(L, 1, "HTMLInput"); + unsigned width = lrint(luaL_checknumber(L, 2)); + unsigned height = lrint(luaL_checknumber(L, 3)); + (*video_input)->resize(width, height); + return 0; +} + int HTMLInput_get_signal_num(lua_State* L) { assert(lua_gettop(L) == 1); @@ -761,6 +771,7 @@ const luaL_Reg HTMLInput_funcs[] = { { "reload", HTMLInput_reload }, { "set_max_fps", HTMLInput_set_max_fps }, { "execute_javascript_async", HTMLInput_execute_javascript_async }, + { "resize", HTMLInput_resize }, { "get_signal_num", HTMLInput_get_signal_num }, #endif { NULL, NULL }