diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-06-23 10:37:03 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-07-05 08:00:21 +0000 |
commit | 8c745d808527684836d04da9014ee33c7cf8b6f1 (patch) | |
tree | 7f1ab16a2639f91afe153e1d897ed36ac091d446 /src/quick/items/qquickopenglshadereffect_p.h | |
parent | 5b470b6b6ad07975f9f9a56425a09b4827e87650 (diff) |
QtQuick: clean up shader effect property connections
- Don't use a signal mapper, but handle the mapping using a custom slot
object and a lambda to do the dispatching ourselves.
- Don't do meta-calls by property name, but by index.
- Cache the meta-object.
- Resolve the property indices by using the QML property cache.
For a shader with 6 property connections, the time spent goes from 320k
instructions to 80k instructions (valgrind on x86_64).
Task-number: QTBUG-53901
Change-Id: I2809198cf62f9716b3683798222203fc3e97fbb3
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Diffstat (limited to 'src/quick/items/qquickopenglshadereffect_p.h')
-rw-r--r-- | src/quick/items/qquickopenglshadereffect_p.h | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/quick/items/qquickopenglshadereffect_p.h b/src/quick/items/qquickopenglshadereffect_p.h index 062eedd744..44b60c97d9 100644 --- a/src/quick/items/qquickopenglshadereffect_p.h +++ b/src/quick/items/qquickopenglshadereffect_p.h @@ -61,6 +61,7 @@ #include "qquickshadereffectmesh_p.h" #include <QtCore/qpointer.h> +#include <functional> QT_BEGIN_NAMESPACE @@ -69,32 +70,39 @@ class QSignalMapper; class QFileSelector; class QQuickOpenGLCustomMaterialShader; +namespace QtPrivate { +class MappedSlotObject; +} + // Common class for QQuickOpenGLShaderEffect and QQuickCustomParticle. struct Q_QUICK_PRIVATE_EXPORT QQuickOpenGLShaderEffectCommon { typedef QQuickOpenGLShaderEffectMaterialKey Key; typedef QQuickOpenGLShaderEffectMaterial::UniformData UniformData; - QQuickOpenGLShaderEffectCommon(QObject *host) : host(host), fileSelector(nullptr) { } - ~QQuickOpenGLShaderEffectCommon(); + QQuickOpenGLShaderEffectCommon(QObject *host, std::function<void(int)> mappedPropertyChanged) + : host(host), mappedPropertyChanged(mappedPropertyChanged), fileSelector(nullptr) + { } + void disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType); - void connectPropertySignals(QQuickItem *item, Key::ShaderType shaderType); + void connectPropertySignals(QQuickItem *item, const QMetaObject *itemMetaObject, Key::ShaderType shaderType); void updateParseLog(bool ignoreAttributes); - void lookThroughShaderCode(QQuickItem *item, Key::ShaderType shaderType, const QByteArray &code); - void updateShader(QQuickItem *item, Key::ShaderType shaderType); + void lookThroughShaderCode(QQuickItem *item, const QMetaObject *itemMetaObject, Key::ShaderType shaderType, const QByteArray &code); + void updateShader(QQuickItem *item, const QMetaObject *itemMetaObject, Key::ShaderType shaderType); void updateMaterial(QQuickOpenGLShaderEffectNode *node, QQuickOpenGLShaderEffectMaterial *material, bool updateUniforms, bool updateUniformValues, bool updateTextureProviders); void updateWindow(QQuickWindow *window); // Called by slots in QQuickOpenGLShaderEffect: void sourceDestroyed(QObject *object); - void propertyChanged(QQuickItem *item, int mappedId, bool *textureProviderChanged); + void propertyChanged(QQuickItem *item, const QMetaObject *itemMetaObject, int mappedId, bool *textureProviderChanged); QObject *host; + std::function<void(int)> mappedPropertyChanged; Key source; QVector<QByteArray> attributes; QVector<UniformData> uniformData[Key::ShaderTypeCount]; - QVector<QSignalMapper *> signalMappers[Key::ShaderTypeCount]; + QVector<QtPrivate::MappedSlotObject *> signalMappers[Key::ShaderTypeCount]; QString parseLog; QFileSelector *fileSelector; }; @@ -142,9 +150,10 @@ private Q_SLOTS: void updateGeometryIfAtlased(); void updateLogAndStatus(const QString &log, int status); void sourceDestroyed(QObject *object); - void propertyChanged(int mappedId); private: + void propertyChanged(int mappedId); + friend class QQuickCustomMaterialShader; friend class QQuickOpenGLShaderEffectNode; @@ -152,6 +161,7 @@ private: typedef QQuickOpenGLShaderEffectMaterial::UniformData UniformData; QQuickShaderEffect *m_item; + const QMetaObject *m_itemMetaObject; QSize m_meshResolution; QQuickShaderEffectMesh *m_mesh; QQuickGridMesh m_defaultMesh; |