summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2019-10-07 21:40:27 +0100
committerMike Krus <mike.krus@kdab.com>2019-10-11 07:23:14 +0100
commit02ec5db08128030ce0891ebbd86fccd0b82e3c0c (patch)
tree3f3cbbf6b5d35a0cd1f65f9442b8f6c01810e980 /src/input
parent8db80eb521e5a439cb9b499bd17253059b3b340d (diff)
Update LoadProxyDeviceJob to use direct sync
Change-Id: I6d49abd28a665f89096ec2baaa861490c071d3d3 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r--src/input/backend/loadproxydevicejob.cpp43
-rw-r--r--src/input/backend/loadproxydevicejob_p.h3
-rw-r--r--src/input/backend/physicaldeviceproxy.cpp7
-rw-r--r--src/input/frontend/qabstractphysicaldeviceproxy.cpp51
-rw-r--r--src/input/frontend/qabstractphysicaldeviceproxy_p.h3
-rw-r--r--src/input/frontend/qabstractphysicaldeviceproxy_p_p.h2
6 files changed, 65 insertions, 44 deletions
diff --git a/src/input/backend/loadproxydevicejob.cpp b/src/input/backend/loadproxydevicejob.cpp
index 2ea29b4a9..69f14beae 100644
--- a/src/input/backend/loadproxydevicejob.cpp
+++ b/src/input/backend/loadproxydevicejob.cpp
@@ -38,7 +38,9 @@
****************************************************************************/
#include "loadproxydevicejob_p.h"
-
+#include <Qt3DCore/private/qaspectmanager_p.h>
+#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p.h>
+#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p_p.h>
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/job_common_p.h>
@@ -48,12 +50,22 @@ QT_BEGIN_NAMESPACE
namespace Qt3DInput {
namespace Input {
+class LoadProxyDeviceJobPrivate : public Qt3DCore::QAspectJobPrivate
+{
+public:
+ LoadProxyDeviceJobPrivate() { }
+ ~LoadProxyDeviceJobPrivate() override { }
+
+ void postFrame(Qt3DCore::QAspectManager *manager) override;
+
+ QVector<QPair<Qt3DCore::QNodeId, QAbstractPhysicalDevice *>> updates;
+};
+
LoadProxyDeviceJob::LoadProxyDeviceJob()
- : Qt3DCore::QAspectJob()
+ : Qt3DCore::QAspectJob(*new LoadProxyDeviceJobPrivate)
, m_inputHandler(nullptr)
{
- SET_JOB_RUN_STAT_TYPE(this, JobTypes::DeviceProxyLoading, 0);
-
+ SET_JOB_RUN_STAT_TYPE(this, JobTypes::DeviceProxyLoading, 0)
}
LoadProxyDeviceJob::~LoadProxyDeviceJob()
@@ -82,6 +94,9 @@ QVector<Qt3DCore::QNodeId> LoadProxyDeviceJob::proxies() const
void LoadProxyDeviceJob::run()
{
+ Q_D(LoadProxyDeviceJob);
+ d->updates.reserve(m_proxies.size());
+
Q_ASSERT(m_inputHandler);
for (const Qt3DCore::QNodeId id : qAsConst(m_proxies)) {
PhysicalDeviceProxy *proxy = m_inputHandler->physicalDeviceProxyManager()->lookupResource(id);
@@ -89,9 +104,27 @@ void LoadProxyDeviceJob::run()
if (device != nullptr)
proxy->setDevice(device);
}
- m_proxies.clear();
}
+void LoadProxyDeviceJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
+{
+ for (const auto &res : qAsConst(updates)) {
+ QAbstractPhysicalDeviceProxy *node = qobject_cast<QAbstractPhysicalDeviceProxy *>(manager->lookupNode(res.first));
+ if (!node)
+ continue;
+
+ auto *device = res.second;
+ QAbstractPhysicalDeviceProxyPrivate *dnode = static_cast<QAbstractPhysicalDeviceProxyPrivate *>(QAbstractPhysicalDeviceProxyPrivate::get(node));
+ QAbstractPhysicalDevice *oldDevice = dnode->m_device;
+ dnode->setDevice(device);
+ // Delete the old device if it existed
+ delete oldDevice;
+ }
+
+ updates.clear();
+}
+
+
} // namespace Input
} // namespace Qt3DInput
diff --git a/src/input/backend/loadproxydevicejob_p.h b/src/input/backend/loadproxydevicejob_p.h
index f9b343b2e..0848c8529 100644
--- a/src/input/backend/loadproxydevicejob_p.h
+++ b/src/input/backend/loadproxydevicejob_p.h
@@ -60,6 +60,7 @@ namespace Qt3DInput {
namespace Input {
class InputHandler;
+class LoadProxyDeviceJobPrivate;
class Q_AUTOTEST_EXPORT LoadProxyDeviceJob : public Qt3DCore::QAspectJob
{
@@ -75,6 +76,8 @@ public:
void run() final;
private:
+ Q_DECLARE_PRIVATE(LoadProxyDeviceJob)
+
InputHandler *m_inputHandler;
QVector<Qt3DCore::QNodeId> m_proxies;
};
diff --git a/src/input/backend/physicaldeviceproxy.cpp b/src/input/backend/physicaldeviceproxy.cpp
index d0ed4356a..390b525eb 100644
--- a/src/input/backend/physicaldeviceproxy.cpp
+++ b/src/input/backend/physicaldeviceproxy.cpp
@@ -40,7 +40,6 @@
#include "physicaldeviceproxy_p.h"
#include <Qt3DInput/qabstractphysicaldevice.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
#include <QtCore/QCoreApplication>
#include <Qt3DInput/private/inputmanagers_p.h>
@@ -90,12 +89,6 @@ void PhysicalDeviceProxy::setDevice(QAbstractPhysicalDevice *device)
m_physicalDeviceId = device->id();
device->moveToThread(QCoreApplication::instance()->thread());
}
-
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
- e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
- e->setPropertyName("device");
- e->setValue(QVariant::fromValue(device));
- notifyObservers(e);
}
Qt3DCore::QNodeId PhysicalDeviceProxy::physicalDeviceId() const
diff --git a/src/input/frontend/qabstractphysicaldeviceproxy.cpp b/src/input/frontend/qabstractphysicaldeviceproxy.cpp
index 34b7db2a4..a7930ed76 100644
--- a/src/input/frontend/qabstractphysicaldeviceproxy.cpp
+++ b/src/input/frontend/qabstractphysicaldeviceproxy.cpp
@@ -160,26 +160,6 @@ int QAbstractPhysicalDeviceProxy::buttonIdentifier(const QString &name) const
/*!
\internal
*/
-void QAbstractPhysicalDeviceProxy::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change)
-{
- Q_D(QAbstractPhysicalDeviceProxy);
- Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change);
- if (e->type() == Qt3DCore::PropertyUpdated) {
- if (e->propertyName() == QByteArrayLiteral("device")) {
- QAbstractPhysicalDevice *device = e->value().value<Qt3DInput::QAbstractPhysicalDevice *>();
- QAbstractPhysicalDevice *oldDevice = d->m_device;
- setDevice(device);
- // Delete the old device if it existed
- if (oldDevice != nullptr)
- delete oldDevice;
- }
- }
- QAbstractPhysicalDevice::sceneChangeEvent(change);
-}
-
-/*!
- \internal
- */
QAbstractPhysicalDeviceProxy::QAbstractPhysicalDeviceProxy(QAbstractPhysicalDeviceProxyPrivate &dd, Qt3DCore::QNode *parent)
: QAbstractPhysicalDevice(dd, parent)
{
@@ -202,32 +182,45 @@ Qt3DCore::QNodeCreatedChangeBasePtr QAbstractPhysicalDeviceProxy::createNodeCrea
/*!
\internal
*/
-void QAbstractPhysicalDeviceProxy::setDevice(QAbstractPhysicalDevice *device)
+void QAbstractPhysicalDeviceProxyPrivate::setDevice(QAbstractPhysicalDevice *device)
{
- Q_D(QAbstractPhysicalDeviceProxy);
+ Q_Q(QAbstractPhysicalDeviceProxy);
// Note: technically book keeping could be optional since we are the parent
// of the device. But who knows if someone plays with the object tree...
// Unset bookkeeper
- if (d->m_device != nullptr) {
+ if (m_device != nullptr) {
// Note: we cannot delete the device here as we don't how if we are
// called by the bookkeeper (in which case we would do a double free)
// or by the sceneChangeEvent
- d->unregisterDestructionHelper(d->m_device);
- d->setStatus(QAbstractPhysicalDeviceProxy::NotFound);
+ unregisterDestructionHelper(m_device);
+ setStatus(QAbstractPhysicalDeviceProxy::NotFound);
}
// Set parent so that node is created in the backend
if (device != nullptr && device->parent() == nullptr)
- device->setParent(this);
+ device->setParent(q);
- d->m_device = device;
+ m_device = device;
// Set bookkeeper
if (device != nullptr) {
- d->setStatus(QAbstractPhysicalDeviceProxy::Ready);
- d->registerDestructionHelper(d->m_device, &QAbstractPhysicalDeviceProxy::setDevice, d->m_device);
+ setStatus(QAbstractPhysicalDeviceProxy::Ready);
+ registerPrivateDestructionHelper(m_device, &QAbstractPhysicalDeviceProxyPrivate::resetDevice);
+ }
+}
+
+void QAbstractPhysicalDeviceProxyPrivate::resetDevice(QAbstractPhysicalDevice *device)
+{
+ if (m_device == device) {
+ // Note: we cannot delete the device here as we don't how if we are
+ // called by the bookkeeper (in which case we would do a double free)
+ // or by the sceneChangeEvent
+ unregisterDestructionHelper(m_device);
+ setStatus(QAbstractPhysicalDeviceProxy::NotFound);
+
+ m_device = nullptr;
}
}
diff --git a/src/input/frontend/qabstractphysicaldeviceproxy_p.h b/src/input/frontend/qabstractphysicaldeviceproxy_p.h
index e250b9eb9..4a7b1dfc5 100644
--- a/src/input/frontend/qabstractphysicaldeviceproxy_p.h
+++ b/src/input/frontend/qabstractphysicaldeviceproxy_p.h
@@ -88,13 +88,10 @@ Q_SIGNALS:
void statusChanged(QAbstractPhysicalDeviceProxy::DeviceStatus status);
protected:
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override;
-
QAbstractPhysicalDeviceProxy(QAbstractPhysicalDeviceProxyPrivate &dd, Qt3DCore::QNode *parent = nullptr);
Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const override;
private:
- void setDevice(QAbstractPhysicalDevice *device);
Q_DECLARE_PRIVATE(QAbstractPhysicalDeviceProxy)
};
diff --git a/src/input/frontend/qabstractphysicaldeviceproxy_p_p.h b/src/input/frontend/qabstractphysicaldeviceproxy_p_p.h
index 8f8d1bea3..fc8645272 100644
--- a/src/input/frontend/qabstractphysicaldeviceproxy_p_p.h
+++ b/src/input/frontend/qabstractphysicaldeviceproxy_p_p.h
@@ -73,6 +73,8 @@ public:
QAbstractPhysicalDeviceProxy::DeviceStatus m_status;
QAbstractPhysicalDevice *m_device;
+ void setDevice(QAbstractPhysicalDevice *device);
+ void resetDevice(QAbstractPhysicalDevice *device);
void setStatus(QAbstractPhysicalDeviceProxy::DeviceStatus status);
};