mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 09:00:44 +00:00
Add helper to invoke back onto the UI thread from the replay thread
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user