This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Adeneo Embedded Seattle3150 Richards Road, Suite 210 Bellevue, WA 98005, USAPhone : +1 425 749-4335Fax : +1 425 818-1911
• Adeneo Embedded• France, Germany (Franckfurt), USA• BSPs and OS porting to ARM (Linux, Windows, Android, QNX)• Embedded software architecture and development• Mobile expertise (cloud, internet of things)
3
• People expect the best out of UIs
Today’s UIs
Sensors
Animations Effects
Graphical acceleration
Touch Gestures
Modernfeeling
4
• Reminder: custom components can be QML files or C++ classes
• QML file: collection of QML components• Quick & easy• Limited to existing components
Your own components
[MyComponent.qml]
Rectangle { width: 100 height: 100 color: “blue”
MouseArea { anchors.fill: parent
onPressed: { log.message(“Pressed !”); } }}
5
• Custom Item C++ class• More effort
• More possibilities• Custom painting• Custom events handling
Your own components
[mycomponent.h]
class MyComponent : public QQuickItem { Q_OBJECTpublic: MyComponent(); mousePressEvent(QMouseEvent*);};
Adeneo Embedded Seattle3150 Richards Road, Suite 210 Bellevue, WA 98005, USAPhone : +1 425 749-4335Fax : +1 425 818-1911
• Scene graph• Relies on Opengl / Opengl ES• State aware to minimize overhead• Render thread• Performs optimizations
• Material sorting• Ignore obstructed items
Scene graph
Scene
22
• Scene graph nodes• Each item is internally a node• Each node contains all its children
• A node can be a visible item, or provide functionality• Opacity, transformation
Scene
Scene graph
23
How to leverage Qt Quick2 performances?
• Inherit QQuickItem• setFlag, ItemHasContents• Implement updatePaintNode method• Use Scene Graph classes (QSG*)• update() to trigger updatePaintNode when needed
Qt Quick 2 item class
24
• oldNode holds the previous state of the node• Null until initialized• Contains its type and hierarchy
• Set its color and geometry
QSGNode *MyItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *){ QSGSimpleRectNode *n = static_cast<QSGSimpleRectNode *>(oldNode); if ( ! n ) { n = new QSGSimpleRectNode(); n->setColor(Qt::red); } n->setRect(boundingRect()); return n;}
First accelerated item
25
• Draw exclusively in the render thread, avoid classes other than QSG*
• Main thread is blocked during rendering, access to items data is safe
• Newly created QObject-based classes are running on rendering thread
• Signals targeting main thread will be queued
Caveats
26
QSGNodeQSGTransformNode
QSGOpacityNode
QSGClipNode
QSGGeometryNode
Text text text
• setMatrix()
• setOpacity()
• setClipRect()
• setMaterial()• setGeometry()
Node classes
27
QSGNode QSGGeometryNode
- Base class of visual elements- Holds Geometry and materials
QSGSimpleRectNode- Rectangle, color
QSGSimpleTextureNode- Rectangle, texture
Node classes
28
• QSGGeometryNode• Geometry (vertices)
• QSGGeometry• Points, lines, triangles
QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2);geometry->setDrawingMode(GL_LINES);geometry->setLineWidth(3);geometry->vertexDataAsPoint2D()[0].set(0, 0);geometry->vertexDataAsPoint2D()[1].set(width(), height());
QSGGeometryNode *node = new QSGGeometryNode;node->setGeometry(geometry);node->setFlag(QSGNode::OwnsGeometry);
Geometry node
29
• QSGGeometryNode• Material (shader)
• QSGMaterial, QSGFlatColorMaterial, QSGSimpleMaterialShader• Vertex and fragment shaders• Attributes, uniforms
QSGFlatColorMaterial *material = new QSGFlatColorMaterial;material->setColor(QColor(255, 0, 0));
QSGGeometryNode *node = new QSGGeometryNode;node->setMaterial(material);node->setFlag(QSGNode::OwnsMaterial);
Geometry node
30
• Fully leveraging OpenGL acceleration require some work
• Needs some basic knowledge of OpenGL (vertices, textures, shaders)
• QQuickPaintedItem when performance is not critical
Sum up
Adeneo Embedded Seattle3150 Richards Road, Suite 210 Bellevue, WA 98005, USAPhone : +1 425 749-4335Fax : +1 425 818-1911