]> git.sesse.net Git - nageru/commitdiff
Add resize(), so that HTML inputs do not need to be locked to the video resolution.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 1 Mar 2018 08:30:23 +0000 (09:30 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 1 Mar 2018 08:30:23 +0000 (09:30 +0100)
cef_capture.cpp
cef_capture.h
theme.cpp

index 9dc454ba33d426a6abfcb86234c36e193f221c66..e46f0c065f7287e0dce70992a070cea557a0497d 100644 (file)
@@ -86,6 +86,13 @@ void CEFCapture::execute_javascript_async(const string &js)
        });
 }
 
+void CEFCapture::resize(unsigned width, unsigned height)
+{
+       lock_guard<mutex> 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<CefBrowser> browser, PaintElementType ty
 
 bool NageruCEFClient::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect)
 {
+       return parent->GetViewRect(rect);
+}
+
+bool CEFCapture::GetViewRect(CefRect &rect)
+{
+       lock_guard<mutex> lock(resolution_mutex);
        rect = CefRect(0, 0, width, height);
        return true;
 }
index c497179d72e127077e4abb193e34f720ed7ea141..311076eb9afd0fcaf2942e9d218086c1e9673539 100644 (file)
@@ -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<void()> &&func);
 
        CefRefPtr<NageruCEFClient> 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
+       // <browser_mutex>.
+       std::mutex resolution_mutex;
+       unsigned width, height;  // Under <resolution_mutex>.
+
        int card_index = -1;
 
        bool has_dequeue_callbacks = false;
index 8b2f6b6c612f101c01c7667cb1d996c71f8d3edb..5fc5a7538cee288ae7e3fc335c1550bfdfe1dd2e 100644 (file)
--- 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 }