summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesus Fernandez <jesus.fernandez@qt.io>2017-09-12 09:36:21 +0200
committerJesus Fernandez <Jesus.Fernandez@qt.io>2017-11-23 07:54:09 +0000
commitd5dda668b174ec59a3856b3bad9295cead5a6a6c (patch)
tree6ccdca9b999ba13f58c06343bf3972081f22bd6a
parent9e758667d828151d8aea5c4eeeeff07c10792dc9 (diff)
Send numeric identifiers instead of strings
Saves bandwidth by using a number instead of sending the full string to identify the GL command. Change-Id: I5e8010465729d7a9c320d0375582d3a92d76019d Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/plugins/platforms/webgl/qwebglcontext.cpp30
-rw-r--r--src/plugins/platforms/webgl/qwebglcontext.h3
-rw-r--r--src/plugins/platforms/webgl/qwebglwebsocketserver.cpp4
-rw-r--r--src/plugins/platforms/webgl/webqt.jsx8
4 files changed, 34 insertions, 11 deletions
diff --git a/src/plugins/platforms/webgl/qwebglcontext.cpp b/src/plugins/platforms/webgl/qwebglcontext.cpp
index 89a4283..6265f21 100644
--- a/src/plugins/platforms/webgl/qwebglcontext.cpp
+++ b/src/plugins/platforms/webgl/qwebglcontext.cpp
@@ -48,6 +48,7 @@
#include <QtWebSockets/qwebsocket.h>
#include <cstring>
+#include <limits>
QT_BEGIN_NAMESPACE
@@ -286,7 +287,6 @@ static T queryValue(int id, const T &defaultValue = T())
return variant.value<T>();
}
-struct GLFunction;
template<typename T>
struct ParameterTypeTraits {
static int typeId() { return qMetaTypeId<T>(); }
@@ -320,6 +320,7 @@ struct GLFunction
};
static QHash<QString, const GLFunction *> byName;
+ static QStringList remoteFunctionNames;
using ParameterList = QVector<Parameter>;
GLFunction(const QString &remoteName,
@@ -331,11 +332,15 @@ struct GLFunction
{
Q_ASSERT(!byName.contains(localName));
byName.insert(localName, this);
+ id = remoteFunctionNames.size();
+ Q_ASSERT(remoteFunctionNames.size() <= std::numeric_limits<quint8>::max());
+ remoteFunctionNames.append(remoteName);
+ Q_ASSERT(byName.size() == remoteFunctionNames.size());
}
GLFunction(const QString &name) : GLFunction(name, name, nullptr)
{}
-
+ quint8 id;
const QString remoteName;
const QString localName;
const QFunctionPointer functionPointer;
@@ -343,6 +348,7 @@ struct GLFunction
};
QHash<QString, const GLFunction *> GLFunction::byName;
+QStringList GLFunction::remoteFunctionNames;
template<const GLFunction *Function>
static QWebGLFunctionCall *createEventImpl(bool wait)
@@ -355,7 +361,7 @@ static QWebGLFunctionCall *createEventImpl(bool wait)
if (!clientData || !clientData->socket
|| clientData->socket->state() != QAbstractSocket::ConnectedState)
return nullptr;
- return new QWebGLFunctionCall(Function->remoteName, handle->currentSurface(), wait);
+ return new QWebGLFunctionCall(Function->localName, handle->currentSurface(), wait);
}
static void postEventImpl(QWebGLFunctionCall *event)
@@ -667,7 +673,7 @@ QWEBGL_FUNCTION(disableVertexAttribArray, void, glDisableVertexAttribArray,
QWEBGL_FUNCTION(drawArrays, void, glDrawArrays,
(GLenum) mode, (GLint) first, (GLsizei) count)
{
- auto event = currentContext()->createEvent(QStringLiteral("drawArrays"));
+ auto event = currentContext()->createEvent(QStringLiteral("glDrawArrays"));
if (!event)
return;
event->addParameters(mode, first, count);
@@ -681,7 +687,7 @@ QWEBGL_FUNCTION(drawArrays, void, glDrawArrays,
QWEBGL_FUNCTION(drawElements, void, glDrawElements,
(GLenum) mode, (GLsizei) count, (GLenum) type, (const void *) indices)
{
- auto event = currentContext()->createEvent(QStringLiteral("drawElements"));
+ auto event = currentContext()->createEvent(QStringLiteral("glDrawElements"));
if (!event)
return;
event->addParameters(mode, count, type);
@@ -1177,7 +1183,7 @@ QWEBGL_FUNCTION(shaderSource, void, glShaderSource,
(GLuint) shader, (GLsizei) count,
(const GLchar *const *) string, (const GLint *) length)
{
- auto event = currentContext()->createEvent(QStringLiteral("shaderSource"));
+ auto event = currentContext()->createEvent(QStringLiteral("glShaderSource"));
if (!event)
return;
event->addParameters(shader, count);
@@ -1578,4 +1584,16 @@ QVariant QWebGLContext::queryValue(int id)
return variant;
}
+QStringList QWebGLContext::supportedFunctions()
+{
+ return GLFunction::remoteFunctionNames;
+}
+
+quint8 QWebGLContext::functionIndex(const QString &functionName)
+{
+ const auto it = GLFunction::byName.find(functionName);
+ Q_ASSERT(it != GLFunction::byName.end());
+ return (*it)->id;
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/webgl/qwebglcontext.h b/src/plugins/platforms/webgl/qwebglcontext.h
index 7f7b7d7..4ba312d 100644
--- a/src/plugins/platforms/webgl/qwebglcontext.h
+++ b/src/plugins/platforms/webgl/qwebglcontext.h
@@ -60,6 +60,9 @@ public:
static QWebGLFunctionCall *createEvent(const QString &functionName, bool wait = false);
static QVariant queryValue(int id);
+ static QStringList supportedFunctions();
+ static quint8 functionIndex(const QString &functionName);
+
private:
Q_DISABLE_COPY(QWebGLContext)
Q_DECLARE_PRIVATE(QWebGLContext)
diff --git a/src/plugins/platforms/webgl/qwebglwebsocketserver.cpp b/src/plugins/platforms/webgl/qwebglwebsocketserver.cpp
index f41d2fe..b9b3201 100644
--- a/src/plugins/platforms/webgl/qwebglwebsocketserver.cpp
+++ b/src/plugins/platforms/webgl/qwebglwebsocketserver.cpp
@@ -175,7 +175,7 @@ void QWebGLWebSocketServer::sendMessage(QWebSocket *socket,
QByteArray data;
{
QDataStream stream(&data, QIODevice::WriteOnly);
- stream << functionName;
+ stream << QWebGLContext::functionIndex(functionName);
if (values.contains("id")) {
auto ok = false;
stream << quint32(values["id"].toUInt(&ok));
@@ -295,6 +295,8 @@ void QWebGLWebSocketServer::onNewConnection()
#endif
},
{ QStringLiteral("loadingScreen"), qgetenv("QT_WEBGL_LOADINGSCREEN") },
+ { QStringLiteral("supportedFunctions"),
+ QVariant::fromValue(QWebGLContext::supportedFunctions()) },
{ "sysinfo",
QVariantMap {
{ QStringLiteral("buildAbi"), QSysInfo::buildAbi() },
diff --git a/src/plugins/platforms/webgl/webqt.jsx b/src/plugins/platforms/webgl/webqt.jsx
index 74e081d..0c58a6b 100644
--- a/src/plugins/platforms/webgl/webqt.jsx
+++ b/src/plugins/platforms/webgl/webqt.jsx
@@ -65,6 +65,7 @@ window.onload = function () {
}
};
}
+ var supportedFunctions;
var sendObject = function (obj) { socket.send(JSON.stringify(obj)); }
@@ -967,10 +968,8 @@ window.onload = function () {
var offset = 0;
var obj = { "parameters" : [] };
- obj["functionNameSize"] = view.getUint32(offset);
- offset += 4;
- obj["function"] = textDecoder.decode(new Uint8Array(buffer, offset, obj.functionNameSize));
- offset += obj.functionNameSize;
+ obj["function"] = supportedFunctions[view.getUint8(offset)];
+ offset += 1;
if (obj.function in commandsNeedingResponse) {
obj["id"] = view.getUint32(offset);
offset += 4;
@@ -1153,6 +1152,7 @@ window.onload = function () {
} else if (obj.type === "change_title") {
document.title = obj.text;
} else if (obj.type === "connect") {
+ supportedFunctions = obj["supportedFunctions"];
var sysinfo = obj["sysinfo"];
if (obj["debug"])
DEBUG = 1;