Merge lp:~mardy/ubuntu-ui-toolkit/lp1296728 into lp:ubuntu-ui-toolkit/staging

Proposed by Alberto Mardegan
Status: Merged
Approved by: Loïc Molinari
Approved revision: 978
Merged at revision: 1063
Proposed branch: lp:~mardy/ubuntu-ui-toolkit/lp1296728
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 165 lines (+57/-16)
3 files modified
modules/Ubuntu/Components/plugin/shapeitem.cpp (+47/-13)
modules/Ubuntu/Components/plugin/shapeitem.h (+8/-0)
modules/Ubuntu/Components/plugin/shapeitemtexture.h (+2/-3)
To merge this branch: bzr merge lp:~mardy/ubuntu-ui-toolkit/lp1296728
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Loïc Molinari (community) Approve
Review via email: mp+218617@code.launchpad.net

This proposal supersedes a proposal from 2014-03-24.

Description of the change

Keep a map of windows and associated textures

It seems it's not possible to use a texture which was created for another
window; therefore, each window must keep record of its textures.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:977
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/181/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/61
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/55
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/13
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/13
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/13/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/13
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/569
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/165
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/165/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/6885
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/54
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/82
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/82/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/181/rebuild

review: Approve (continuous-integration)
Revision history for this message
Loïc Molinari (loic.molinari) wrote :

Hi Alberto,

QtQuick used to create one OpenGL context for all the windows (QQuickViews), now it creates one context per window, which breaks our static allocation. I guess that's the main reason for that change.

1) I think we should handle that per context (window()->openglContext() with the right NULL checks) instead of per window and use the context pointer as the hash key to prevent further changes.

2) We should also clean up the created textures when the context is (about to be) destroyed so that there are no false positives when debugging with QML_LEAK_CHECK on, the only thing to do is to connect to the aboutToBeDestroyed() signal of the QOpenGLContext instance and delete "high" and "low" in the callback. Note that this signal is emitted from the rendering thread (with has the OpenGL context bound) and for delete not to crash, the connection must be direct (adding Qt:DirectConnection as last parameter of connect()). No need to connect to the destroyed() signal on the QQuickWindow instance anymore.

3) Can you please replace the comment from line 359 to something like "OpenGL allocates textures per context, so we store textures reused by all shape instances per context as well".

4) Now for the cosmetics, can you please use C++ style comments and "type* pointer" instead of "type *pointer" in the shape code (as it used to be when I first wrote that stuff).

Have fun ;)

review: Needs Fixing
Revision history for this message
Loïc Molinari (loic.molinari) wrote :

1) By further changes, I meant further changes in the QtQuick rendering engine.

978. By Alberto Mardegan

Address review comments

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:978
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/193/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/108
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/96
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/25
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/25
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/25/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/25
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/620
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/268
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/268/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/6992
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/89
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/139
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/139/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/193/rebuild

review: Approve (continuous-integration)
Revision history for this message
Loïc Molinari (loic.molinari) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/plugin/shapeitem.cpp'
2--- modules/Ubuntu/Components/plugin/shapeitem.cpp 2014-04-08 18:41:31 +0000
3+++ modules/Ubuntu/Components/plugin/shapeitem.cpp 2014-05-09 08:10:26 +0000
4@@ -32,6 +32,9 @@
5 // Threshold in grid unit defining the texture quality to be used.
6 const float lowHighTextureThreshold = 11.0f;
7
8+// Map of windows and associated textures.
9+QHash<QOpenGLContext*, ShapeItem::TextureHandles> ShapeItem::textures_;
10+
11 static const char* const shapeVertexShader =
12 "uniform lowp mat4 matrix; \n"
13 "attribute lowp vec4 positionAttrib; \n"
14@@ -338,6 +341,21 @@
15 update();
16 }
17
18+void ShapeItem::onOpenglContextDestroyed()
19+{
20+ QOpenGLContext* context = qobject_cast<QOpenGLContext*>(sender());
21+ if (Q_UNLIKELY(!context)) return;
22+
23+ QHash<QOpenGLContext*, TextureHandles>::iterator it =
24+ textures_.find(context);
25+ if (it != textures_.end()) {
26+ TextureHandles &textureHandles = it.value();
27+ delete textureHandles.high;
28+ delete textureHandles.low;
29+ textures_.erase(it);
30+ }
31+}
32+
33 QSGNode* ShapeItem::updatePaintNode(QSGNode* old_node, UpdatePaintNodeData* data)
34 {
35 Q_UNUSED(data);
36@@ -345,19 +363,28 @@
37 // FIXME(loicm) Shape textures are stored in the read-only data section of the plugin as it
38 // avoids having to deal with paths for now. It should preferably be loaded from a file.
39
40- /* Textures created with QWindow::createTextureFromImage() become invalid
41- * when the window is destroyed; therefore, we must keep track of which
42- * window was used to create them and be ready to re-create them if that
43- * window goes away. */
44- static QPointer<QWindow> textureOwner = 0;
45- if (!textureOwner) {
46- shapeTextureHigh.texture = window()->createTextureFromImage(
47+ // OpenGL allocates textures per context, so we store textures reused by
48+ // all shape instances per context as well
49+ QOpenGLContext* openglContext = window() ? window()->openglContext() : NULL;
50+ if (Q_UNLIKELY(!openglContext)) {
51+ qCritical() << "Window has no GL context!";
52+ delete old_node;
53+ return NULL;
54+ }
55+
56+ TextureHandles &textureHandles = textures_[openglContext];
57+ // If the hash table didn't contain an entry for the current context, the
58+ // line above has just caused the creation of a default-constructed value.
59+ if (!textureHandles.high) {
60+ textureHandles.high = window()->createTextureFromImage(
61 QImage(shapeTextureHigh.data, shapeTextureHigh.width, shapeTextureHigh.height,
62 QImage::Format_ARGB32_Premultiplied));
63- shapeTextureLow.texture = window()->createTextureFromImage(
64+ textureHandles.low = window()->createTextureFromImage(
65 QImage(shapeTextureLow.data, shapeTextureLow.width, shapeTextureLow.height,
66 QImage::Format_ARGB32_Premultiplied));
67- textureOwner = window();
68+ QObject::connect(openglContext, SIGNAL(aboutToBeDestroyed()),
69+ this, SLOT(onOpenglContextDestroyed()),
70+ Qt::DirectConnection);
71 }
72
73 // The image item sets its texture in its updatePaintNode() method when QtQuick iterates through
74@@ -387,8 +414,15 @@
75
76 ShapeTexturedMaterial* texturedMaterial = node->texturedMaterial();
77 ShapeColoredMaterial* coloredMaterial = node->coloredMaterial();
78- TextureData* textureData = (gridUnit_ > lowHighTextureThreshold) ?
79- &shapeTextureHigh : &shapeTextureLow;
80+ TextureData* textureData;
81+ QSGTexture* textureHandle;
82+ if (gridUnit_ > lowHighTextureThreshold) {
83+ textureData = &shapeTextureHigh;
84+ textureHandle = textureHandles.high;
85+ } else {
86+ textureData = &shapeTextureLow;
87+ textureHandle = textureHandles.low;
88+ }
89
90 // Set the shape texture to be used by the materials depending on current grid unit. The radius
91 // is set considering the current grid unit and the texture raster grid unit. When the item size
92@@ -406,8 +440,8 @@
93 radius = halfMinWidthHeight;
94 scaledDown |= 1;
95 }
96- coloredMaterial->setShapeTexture(textureData->texture, !!scaledDown);
97- texturedMaterial->setShapeTexture(textureData->texture, !!scaledDown);
98+ coloredMaterial->setShapeTexture(textureHandle, !!scaledDown);
99+ texturedMaterial->setShapeTexture(textureHandle, !!scaledDown);
100
101 // Update the other material properties.
102 coloredMaterial->setColor(color_);
103
104=== modified file 'modules/Ubuntu/Components/plugin/shapeitem.h'
105--- modules/Ubuntu/Components/plugin/shapeitem.h 2013-10-18 08:56:39 +0000
106+++ modules/Ubuntu/Components/plugin/shapeitem.h 2014-05-09 08:10:26 +0000
107@@ -91,6 +91,7 @@
108
109 private Q_SLOTS:
110 void onImagePropertiesChanged();
111+ void onOpenglContextDestroyed();
112
113 private:
114 enum DirtyFlags {
115@@ -110,6 +111,12 @@
116 | DirtyGridUnit | DirtyGeometry)
117 };
118
119+ struct TextureHandles {
120+ TextureHandles(): high(0), low(0) {}
121+ QSGTexture* high;
122+ QSGTexture* low;
123+ };
124+
125 QColor color_;
126 QColor gradientColor_;
127 bool gradientColorSet_;
128@@ -124,6 +131,7 @@
129 float gridUnit_;
130 QRectF geometry_;
131 QFlags<DirtyFlags> dirtyFlags_;
132+ static QHash<QOpenGLContext*, TextureHandles> textures_;
133
134 Q_DISABLE_COPY(ShapeItem)
135 };
136
137=== modified file 'modules/Ubuntu/Components/plugin/shapeitemtexture.h'
138--- modules/Ubuntu/Components/plugin/shapeitemtexture.h 2013-01-07 07:59:56 +0000
139+++ modules/Ubuntu/Components/plugin/shapeitemtexture.h 2014-05-09 08:10:26 +0000
140@@ -20,7 +20,6 @@
141
142 struct TextureData {
143 const unsigned char* const data;
144- QSGTexture* texture;
145 int width;
146 int height;
147 int bytesPerPixel;
148@@ -5160,7 +5159,7 @@
149
150 // High resolution shape texture.
151 TextureData shapeTextureHigh __attribute__((aligned(16))) = {
152- shapeTextureHighData, NULL, 256, 128, 4, 32.0f, 64.0f, 18.0f,
153+ shapeTextureHighData, 256, 128, 4, 32.0f, 64.0f, 18.0f,
154 {
155 { // Medium raw coords.
156 { hh, 0.0f }, { 0.25f-hh, 0.0f }, { 0.25f-hh, 0.0f }, { hh, 0.0f },
157@@ -6484,7 +6483,7 @@
158
159 // Low resolution shape texture.
160 TextureData shapeTextureLow __attribute__((aligned(16))) = {
161- shapeTextureLowData, NULL, 128, 64, 4, 16.0f, 32.0f, 9.0f,
162+ shapeTextureLowData, 128, 64, 4, 16.0f, 32.0f, 9.0f,
163 {
164 { // Medium raw coords.
165 { hl, 0.0f }, { 0.25f-hl, 0.0f }, { 0.25f-hl, 0.0f }, { hl, 0.0f },

Subscribers

People subscribed via source and target branches