Add helper to invoke back onto the UI thread from the replay thread

This commit is contained in:
baldurk
2020-12-03 14:17:42 +00:00
parent a8a40ca3d6
commit 0d1f6e3940
4 changed files with 28 additions and 0 deletions
+15
View File
@@ -338,6 +338,21 @@ struct IMiniQtHelper
{
typedef std::function<void(ICaptureContext *, QWidget *, rdcstr)> WidgetCallback;
DOCUMENT(R"(Invoke a callback on the UI thread. All widget accesses must come from the UI thread,
so if work has been done on the render thread then this function can be used to asynchronously and
safely go back to the UI thread.
This function is safe to call on the UI thread, but it will synchronously call the callback
immediately before returning.
.. note::
No parameters are provided to the callback, it is assumed that the callback will maintain its own
context as needed.
:param function callback: The callback to invoke on the UI thread.
)");
virtual void InvokeOntoUIThread(std::function<void()> callback) = 0;
// top level widgets
DOCUMENT(R"(Creates and returns a top-level widget for creating layouts.
+5
View File
@@ -58,6 +58,11 @@ MiniQtHelper::~MiniQtHelper()
});
}
void MiniQtHelper::InvokeOntoUIThread(std::function<void()> callback)
{
GUIInvoke::call(m_Ctx.GetMainWindow()->Widget(), callback);
}
void MiniQtHelper::AddWidgetCallback(QWidget *widget, QMetaObject::Connection connection)
{
// remember the connection and delete it python-safely at shutdown if it's still there
+2
View File
@@ -35,6 +35,8 @@ public:
MiniQtHelper(ICaptureContext &ctx);
virtual ~MiniQtHelper();
void InvokeOntoUIThread(std::function<void()> callback) override;
QWidget *CreateToplevelWidget(const rdcstr &windowTitle, WidgetCallback closed) override;
// widget hierarchy
+6
View File
@@ -85,6 +85,12 @@ struct MiniQtInvoker : ObjectForwarder<IMiniQtHelper>
{
MiniQtInvoker(PythonShell *shell, IMiniQtHelper &obj) : ObjectForwarder(shell, obj) {}
virtual ~MiniQtInvoker() {}
void InvokeOntoUIThread(std::function<void()> callback)
{
// this function is already thread safe since it's invoking, so just call it directly
m_Obj.InvokeOntoUIThread(callback);
}
///////////////////////////////////////////////////////////////////////
// all functions invoke onto the UI thread since they deal with widgets!
///////////////////////////////////////////////////////////////////////