Commit 465f02a5 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner.NodeInstances: Extra socket for slow connection

Pixmaps can be very large, so they are slow down the pipeline. Now there
is a extra socket for images.
parent 250b1905
......@@ -40,15 +40,19 @@ NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent)
m_nodeinstanceServer(new NodeInstanceServer(this)),
m_blockSize(0)
{
m_socket = new QLocalSocket(this);
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readDataStream()));
connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), QCoreApplication::instance(), SLOT(quit()));
connect(m_socket, SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit()));
m_socket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered);
m_socket->waitForConnected(-1);
m_slowSocket = new QLocalSocket(this);
m_slowSocket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered);
m_slowSocket->waitForConnected(-1);
m_fastSocket = new QLocalSocket(this);
connect(m_fastSocket, SIGNAL(readyRead()), this, SLOT(readDataStream()));
connect(m_fastSocket, SIGNAL(error(QLocalSocket::LocalSocketError)), QCoreApplication::instance(), SLOT(quit()));
connect(m_fastSocket, SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit()));
m_fastSocket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered);
m_fastSocket->waitForConnected(-1);
}
void NodeInstanceClientProxy::writeCommand(const QVariant &command)
void NodeInstanceClientProxy::writeSlowCommand(const QVariant &command)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
......@@ -57,37 +61,49 @@ void NodeInstanceClientProxy::writeCommand(const QVariant &command)
out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32));
m_socket->write(block);
m_slowSocket->write(block);
}
void NodeInstanceClientProxy::writeFastCommand(const QVariant &command)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << quint32(0);
out << command;
out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32));
m_fastSocket->write(block);
}
void NodeInstanceClientProxy::informationChanged(const InformationChangedCommand &command)
{
writeCommand(QVariant::fromValue(command));
writeFastCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::valuesChanged(const ValuesChangedCommand &command)
{
writeCommand(QVariant::fromValue(command));
writeFastCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::pixmapChanged(const PixmapChangedCommand &command)
{
writeCommand(QVariant::fromValue(command));
writeSlowCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::childrenChanged(const ChildrenChangedCommand &command)
{
writeCommand(QVariant::fromValue(command));
writeFastCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command)
{
writeCommand(QVariant::fromValue(command));
writeSlowCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::componentCompleted(const ComponentCompletedCommand &command)
{
writeCommand(QVariant::fromValue(command));
writeFastCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::flush()
......@@ -96,24 +112,24 @@ void NodeInstanceClientProxy::flush()
qint64 NodeInstanceClientProxy::bytesToWrite() const
{
return m_socket->bytesToWrite();
return m_slowSocket->bytesToWrite();
}
void NodeInstanceClientProxy::readDataStream()
{
QList<QVariant> commandList;
while (!m_socket->atEnd()) {
if (m_socket->bytesAvailable() < int(sizeof(quint32)))
while (!m_fastSocket->atEnd()) {
if (m_fastSocket->bytesAvailable() < int(sizeof(quint32)))
break;
QDataStream in(m_socket);
QDataStream in(m_fastSocket);
if (m_blockSize == 0) {
in >> m_blockSize;
}
if (m_socket->bytesAvailable() < m_blockSize)
if (m_fastSocket->bytesAvailable() < m_blockSize)
break;
QVariant command;
......
......@@ -31,7 +31,8 @@ public:
qint64 bytesToWrite() const;
protected:
void writeCommand(const QVariant &command);
void writeSlowCommand(const QVariant &command);
void writeFastCommand(const QVariant &command);
void dispatchCommand(const QVariant &command);
NodeInstanceServerInterface *nodeInstanceServer() const;
......@@ -39,7 +40,8 @@ private slots:
void readDataStream();
private:
QLocalSocket *m_socket;
QLocalSocket *m_slowSocket;
QLocalSocket *m_fastSocket;
NodeInstanceServerInterface *m_nodeinstanceServer;
quint32 m_blockSize;
};
......
......@@ -699,8 +699,10 @@ PixmapChangedCommand NodeInstanceServer::createPixmapChangedCommand(const QList<
{
QVector<ImageContainer> imageVector;
foreach (const ServerNodeInstance &instance, instanceList)
imageVector.append(ImageContainer(instance.instanceId(), instance.renderImage()));
foreach (const ServerNodeInstance &instance, instanceList) {
if (instance.isValid())
imageVector.append(ImageContainer(instance.instanceId(), instance.renderImage()));
}
return PixmapChangedCommand(imageVector);
}
......@@ -736,10 +738,9 @@ void NodeInstanceServer::resetAllItems()
void NodeInstanceServer::findItemChangesAndSendChangeCommands()
{
static bool inFunction = false;
if (!inFunction && nodeInstanceClient()->bytesToWrite() < 100000) {
if (!inFunction) {
inFunction = true;
QSet<ServerNodeInstance> dirtyInstanceSet;
QSet<ServerNodeInstance> informationChangedInstanceSet;
QVector<InstancePropertyPair> propertyChangedList;
QSet<ServerNodeInstance> parentChangedSet;
......@@ -756,7 +757,7 @@ void NodeInstanceServer::findItemChangesAndSendChangeCommands()
informationChangedInstanceSet.insert(instance);
if((d->dirty && d->notifyBoundingRectChanged)|| (d->dirty && !d->dirtySceneTransform) || nonInstanceChildIsDirty(graphicsObject))
dirtyInstanceSet.insert(instance);
m_dirtyInstanceSet.insert(instance);
if (d->geometryChanged) {
if (instance.isRootNodeInstance())
......@@ -777,7 +778,7 @@ void NodeInstanceServer::findItemChangesAndSendChangeCommands()
informationChangedInstanceSet.insert(instance);
if (propertyName == "width" || propertyName == "height")
dirtyInstanceSet.insert(instance);
m_dirtyInstanceSet.insert(instance);
if (propertyName == "parent") {
informationChangedInstanceSet.insert(instance);
......@@ -803,8 +804,10 @@ void NodeInstanceServer::findItemChangesAndSendChangeCommands()
nodeInstanceClient()->componentCompleted(ComponentCompletedCommand(m_componentCompletedVector));
m_componentCompletedVector.clear();
if (!dirtyInstanceSet.isEmpty())
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(dirtyInstanceSet.toList()));
if (!m_dirtyInstanceSet.isEmpty() && nodeInstanceClient()->bytesToWrite() < 100000) {
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(m_dirtyInstanceSet.toList()));
m_dirtyInstanceSet.clear();
}
if (adjustSceneRect) {
QRectF boundingRect = m_rootNodeInstance.boundingRect();
......
......@@ -3,6 +3,7 @@
#include <QUrl>
#include <QVector>
#include <QSet>
#include <QStringList>
#include <nodeinstanceserverinterface.h>
......@@ -130,6 +131,7 @@ private:
QVector<InstancePropertyPair> m_changedPropertyList;
QVector<qint32> m_componentCompletedVector;
QStringList m_importList;
QSet<ServerNodeInstance> m_dirtyInstanceSet;
};
}
......
......@@ -41,12 +41,13 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV
: NodeInstanceServerInterface(nodeInstanceView),
m_localServer(new QLocalServer(this)),
m_nodeInstanceView(nodeInstanceView),
m_blockSize(0)
m_slowBlockSize(0),
m_fastBlockSize(0)
{
QString socketToken(QUuid::createUuid().toString());
m_localServer->listen(socketToken);
m_localServer->setMaxPendingConnections(1);
m_localServer->setMaxPendingConnections(2);
m_qmlPuppetProcess = new QProcess(QCoreApplication::instance());
connect(m_qmlPuppetProcess.data(), SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
......@@ -59,9 +60,16 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV
if (!m_localServer->hasPendingConnections())
m_localServer->waitForNewConnection(-1);
m_socket = m_localServer->nextPendingConnection();
Q_ASSERT(m_socket);
connect(m_socket.data(), SIGNAL(readyRead()), this, SLOT(readDataStream()));
m_slowSocket = m_localServer->nextPendingConnection();
Q_ASSERT(m_slowSocket);
connect(m_slowSocket.data(), SIGNAL(readyRead()), this, SLOT(readSlowDataStream()));
if (!m_localServer->hasPendingConnections())
m_localServer->waitForNewConnection(-1);
m_fastSocket = m_localServer->nextPendingConnection();
Q_ASSERT(m_fastSocket);
connect(m_fastSocket.data(), SIGNAL(readyRead()), this, SLOT(readFastDataStream()));
m_localServer->close();
}
......@@ -105,12 +113,12 @@ NodeInstanceClientInterface *NodeInstanceServerProxy::nodeInstanceClient() const
void NodeInstanceServerProxy::setBlockUpdates(bool block)
{
m_socket->blockSignals(block);
m_slowSocket->blockSignals(block);
}
void NodeInstanceServerProxy::writeCommand(const QVariant &command)
{
Q_ASSERT(m_socket.data());
Q_ASSERT(m_fastSocket.data());
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
......@@ -119,35 +127,67 @@ void NodeInstanceServerProxy::writeCommand(const QVariant &command)
out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32));
m_socket->write(block);
m_fastSocket->write(block);
}
void NodeInstanceServerProxy::processFinished(int /*exitCode*/, QProcess::ExitStatus /* exitStatus */)
{
m_socket->close();
m_slowSocket->close();
emit processCrashed();
}
void NodeInstanceServerProxy::readDataStream()
void NodeInstanceServerProxy::readFastDataStream()
{
QList<QVariant> commandList;
while (!m_fastSocket->atEnd()) {
if (m_fastSocket->bytesAvailable() < int(sizeof(quint32)))
break;
QDataStream in(m_fastSocket.data());
if (m_fastBlockSize == 0) {
in >> m_fastBlockSize;
}
if (m_fastSocket->bytesAvailable() < m_fastBlockSize)
break;
QVariant command;
in >> command;
m_fastBlockSize = 0;
Q_ASSERT(in.status() == QDataStream::Ok);
commandList.append(command);
}
foreach (const QVariant &command, commandList) {
dispatchCommand(command);
}
}
void NodeInstanceServerProxy::readSlowDataStream()
{
QList<QVariant> commandList;
while (!m_socket->atEnd()) {
if (m_socket->bytesAvailable() < int(sizeof(quint32)))
while (!m_slowSocket->atEnd()) {
if (m_slowSocket->bytesAvailable() < int(sizeof(quint32)))
break;
QDataStream in(m_socket.data());
QDataStream in(m_slowSocket.data());
if (m_blockSize == 0) {
in >> m_blockSize;
if (m_slowBlockSize == 0) {
in >> m_slowBlockSize;
}
if (m_socket->bytesAvailable() < m_blockSize)
if (m_slowSocket->bytesAvailable() < m_slowBlockSize)
break;
QVariant command;
in >> command;
m_blockSize = 0;
m_slowBlockSize = 0;
Q_ASSERT(in.status() == QDataStream::Ok);
......
......@@ -51,14 +51,17 @@ signals:
private slots:
void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
void readDataStream();
void readFastDataStream();
void readSlowDataStream();
private:
QWeakPointer<QLocalServer> m_localServer;
QWeakPointer<QLocalSocket> m_socket;
QWeakPointer<QLocalSocket> m_slowSocket;
QWeakPointer<QLocalSocket> m_fastSocket;
QWeakPointer<NodeInstanceView> m_nodeInstanceView;
QWeakPointer<QProcess> m_qmlPuppetProcess;
quint32 m_blockSize;
quint32 m_slowBlockSize;
quint32 m_fastBlockSize;
};
} // namespace QmlDesigner
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment