X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cef_capture.h;h=29dededf7b60ad8696dfaec10c71c7f7e84844f4;hb=327534a3031a332423411c9599c741f2f81657df;hp=c497179d72e127077e4abb193e34f720ed7ea141;hpb=a1fac4049d79171dc40f0cd416c1358fd4dc2d3c;p=nageru diff --git a/cef_capture.h b/cef_capture.h index c497179..29deded 100644 --- a/cef_capture.h +++ b/cef_capture.h @@ -35,8 +35,8 @@ class CEFCapture; class NageruCEFClient : public CefClient, public CefRenderHandler, public CefLoadHandler { public: - NageruCEFClient(int width, int height, CEFCapture *parent) - : width(width), height(height), parent(parent) {} + NageruCEFClient(CEFCapture *parent) + : parent(parent) {} CefRefPtr GetRenderHandler() override { @@ -52,14 +52,13 @@ public: void OnPaint(CefRefPtr browser, PaintElementType type, const RectList &dirtyRects, const void *buffer, int width, int height) override; - bool GetViewRect(CefRefPtr browser, CefRect &rect); + bool GetViewRect(CefRefPtr browser, CefRect &rect) override; // CefLoadHandler. void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) override; private: - int width, height; CEFCapture *parent; IMPLEMENT_REFCOUNTING(NageruCEFClient); @@ -85,9 +84,12 @@ public: void reload(); void set_max_fps(int max_fps); void execute_javascript_async(const std::string &js); + void resize(unsigned width, unsigned height); + void request_new_frame(); + // Callbacks from NageruCEFClient. void OnPaint(const void *buffer, int width, int height); - + bool GetViewRect(CefRect &rect); void OnLoadEnd(); // CaptureInterface. @@ -146,7 +148,7 @@ public: assert(pixel_format == bmusb::PixelFormat_8BitBGRA); } - bmusb::PixelFormat get_current_pixel_format() const + bmusb::PixelFormat get_current_pixel_format() const override { return bmusb::PixelFormat_8BitBGRA; } @@ -164,10 +166,16 @@ public: uint32_t get_current_audio_input() const override { return 0; } private: - void post_to_cef_ui_thread(std::function &&func); + void post_to_cef_ui_thread(std::function &&func, int64_t delay_ms = 0); 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; @@ -181,7 +189,9 @@ private: std::string description, start_url; std::atomic max_fps{60}; - std::mutex browser_mutex; + // Needs to be recursive because the lambda in OnPaint could cause + // OnPaint itself to be called. + std::recursive_mutex browser_mutex; CefRefPtr browser; // Under . // Tasks waiting for to get ready. Under .