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
=== modified file 'modules/Ubuntu/Components/plugin/shapeitem.cpp'
--- modules/Ubuntu/Components/plugin/shapeitem.cpp 2014-04-08 18:41:31 +0000
+++ modules/Ubuntu/Components/plugin/shapeitem.cpp 2014-05-09 08:10:26 +0000
@@ -32,6 +32,9 @@
32// Threshold in grid unit defining the texture quality to be used.32// Threshold in grid unit defining the texture quality to be used.
33const float lowHighTextureThreshold = 11.0f;33const float lowHighTextureThreshold = 11.0f;
3434
35// Map of windows and associated textures.
36QHash<QOpenGLContext*, ShapeItem::TextureHandles> ShapeItem::textures_;
37
35static const char* const shapeVertexShader =38static const char* const shapeVertexShader =
36 "uniform lowp mat4 matrix; \n"39 "uniform lowp mat4 matrix; \n"
37 "attribute lowp vec4 positionAttrib; \n"40 "attribute lowp vec4 positionAttrib; \n"
@@ -338,6 +341,21 @@
338 update();341 update();
339}342}
340343
344void ShapeItem::onOpenglContextDestroyed()
345{
346 QOpenGLContext* context = qobject_cast<QOpenGLContext*>(sender());
347 if (Q_UNLIKELY(!context)) return;
348
349 QHash<QOpenGLContext*, TextureHandles>::iterator it =
350 textures_.find(context);
351 if (it != textures_.end()) {
352 TextureHandles &textureHandles = it.value();
353 delete textureHandles.high;
354 delete textureHandles.low;
355 textures_.erase(it);
356 }
357}
358
341QSGNode* ShapeItem::updatePaintNode(QSGNode* old_node, UpdatePaintNodeData* data)359QSGNode* ShapeItem::updatePaintNode(QSGNode* old_node, UpdatePaintNodeData* data)
342{360{
343 Q_UNUSED(data);361 Q_UNUSED(data);
@@ -345,19 +363,28 @@
345 // FIXME(loicm) Shape textures are stored in the read-only data section of the plugin as it363 // FIXME(loicm) Shape textures are stored in the read-only data section of the plugin as it
346 // avoids having to deal with paths for now. It should preferably be loaded from a file.364 // avoids having to deal with paths for now. It should preferably be loaded from a file.
347365
348 /* Textures created with QWindow::createTextureFromImage() become invalid366 // OpenGL allocates textures per context, so we store textures reused by
349 * when the window is destroyed; therefore, we must keep track of which367 // all shape instances per context as well
350 * window was used to create them and be ready to re-create them if that368 QOpenGLContext* openglContext = window() ? window()->openglContext() : NULL;
351 * window goes away. */369 if (Q_UNLIKELY(!openglContext)) {
352 static QPointer<QWindow> textureOwner = 0;370 qCritical() << "Window has no GL context!";
353 if (!textureOwner) {371 delete old_node;
354 shapeTextureHigh.texture = window()->createTextureFromImage(372 return NULL;
373 }
374
375 TextureHandles &textureHandles = textures_[openglContext];
376 // If the hash table didn't contain an entry for the current context, the
377 // line above has just caused the creation of a default-constructed value.
378 if (!textureHandles.high) {
379 textureHandles.high = window()->createTextureFromImage(
355 QImage(shapeTextureHigh.data, shapeTextureHigh.width, shapeTextureHigh.height,380 QImage(shapeTextureHigh.data, shapeTextureHigh.width, shapeTextureHigh.height,
356 QImage::Format_ARGB32_Premultiplied));381 QImage::Format_ARGB32_Premultiplied));
357 shapeTextureLow.texture = window()->createTextureFromImage(382 textureHandles.low = window()->createTextureFromImage(
358 QImage(shapeTextureLow.data, shapeTextureLow.width, shapeTextureLow.height,383 QImage(shapeTextureLow.data, shapeTextureLow.width, shapeTextureLow.height,
359 QImage::Format_ARGB32_Premultiplied));384 QImage::Format_ARGB32_Premultiplied));
360 textureOwner = window();385 QObject::connect(openglContext, SIGNAL(aboutToBeDestroyed()),
386 this, SLOT(onOpenglContextDestroyed()),
387 Qt::DirectConnection);
361 }388 }
362389
363 // The image item sets its texture in its updatePaintNode() method when QtQuick iterates through390 // The image item sets its texture in its updatePaintNode() method when QtQuick iterates through
@@ -387,8 +414,15 @@
387414
388 ShapeTexturedMaterial* texturedMaterial = node->texturedMaterial();415 ShapeTexturedMaterial* texturedMaterial = node->texturedMaterial();
389 ShapeColoredMaterial* coloredMaterial = node->coloredMaterial();416 ShapeColoredMaterial* coloredMaterial = node->coloredMaterial();
390 TextureData* textureData = (gridUnit_ > lowHighTextureThreshold) ?417 TextureData* textureData;
391 &shapeTextureHigh : &shapeTextureLow;418 QSGTexture* textureHandle;
419 if (gridUnit_ > lowHighTextureThreshold) {
420 textureData = &shapeTextureHigh;
421 textureHandle = textureHandles.high;
422 } else {
423 textureData = &shapeTextureLow;
424 textureHandle = textureHandles.low;
425 }
392426
393 // Set the shape texture to be used by the materials depending on current grid unit. The radius427 // Set the shape texture to be used by the materials depending on current grid unit. The radius
394 // is set considering the current grid unit and the texture raster grid unit. When the item size428 // is set considering the current grid unit and the texture raster grid unit. When the item size
@@ -406,8 +440,8 @@
406 radius = halfMinWidthHeight;440 radius = halfMinWidthHeight;
407 scaledDown |= 1;441 scaledDown |= 1;
408 }442 }
409 coloredMaterial->setShapeTexture(textureData->texture, !!scaledDown);443 coloredMaterial->setShapeTexture(textureHandle, !!scaledDown);
410 texturedMaterial->setShapeTexture(textureData->texture, !!scaledDown);444 texturedMaterial->setShapeTexture(textureHandle, !!scaledDown);
411445
412 // Update the other material properties.446 // Update the other material properties.
413 coloredMaterial->setColor(color_);447 coloredMaterial->setColor(color_);
414448
=== modified file 'modules/Ubuntu/Components/plugin/shapeitem.h'
--- modules/Ubuntu/Components/plugin/shapeitem.h 2013-10-18 08:56:39 +0000
+++ modules/Ubuntu/Components/plugin/shapeitem.h 2014-05-09 08:10:26 +0000
@@ -91,6 +91,7 @@
9191
92private Q_SLOTS:92private Q_SLOTS:
93 void onImagePropertiesChanged();93 void onImagePropertiesChanged();
94 void onOpenglContextDestroyed();
9495
95private:96private:
96 enum DirtyFlags {97 enum DirtyFlags {
@@ -110,6 +111,12 @@
110 | DirtyGridUnit | DirtyGeometry)111 | DirtyGridUnit | DirtyGeometry)
111 };112 };
112113
114 struct TextureHandles {
115 TextureHandles(): high(0), low(0) {}
116 QSGTexture* high;
117 QSGTexture* low;
118 };
119
113 QColor color_;120 QColor color_;
114 QColor gradientColor_;121 QColor gradientColor_;
115 bool gradientColorSet_;122 bool gradientColorSet_;
@@ -124,6 +131,7 @@
124 float gridUnit_;131 float gridUnit_;
125 QRectF geometry_;132 QRectF geometry_;
126 QFlags<DirtyFlags> dirtyFlags_;133 QFlags<DirtyFlags> dirtyFlags_;
134 static QHash<QOpenGLContext*, TextureHandles> textures_;
127135
128 Q_DISABLE_COPY(ShapeItem)136 Q_DISABLE_COPY(ShapeItem)
129};137};
130138
=== modified file 'modules/Ubuntu/Components/plugin/shapeitemtexture.h'
--- modules/Ubuntu/Components/plugin/shapeitemtexture.h 2013-01-07 07:59:56 +0000
+++ modules/Ubuntu/Components/plugin/shapeitemtexture.h 2014-05-09 08:10:26 +0000
@@ -20,7 +20,6 @@
2020
21struct TextureData {21struct TextureData {
22 const unsigned char* const data;22 const unsigned char* const data;
23 QSGTexture* texture;
24 int width;23 int width;
25 int height;24 int height;
26 int bytesPerPixel;25 int bytesPerPixel;
@@ -5160,7 +5159,7 @@
51605159
5161// High resolution shape texture.5160// High resolution shape texture.
5162TextureData shapeTextureHigh __attribute__((aligned(16))) = {5161TextureData shapeTextureHigh __attribute__((aligned(16))) = {
5163 shapeTextureHighData, NULL, 256, 128, 4, 32.0f, 64.0f, 18.0f,5162 shapeTextureHighData, 256, 128, 4, 32.0f, 64.0f, 18.0f,
5164 {5163 {
5165 { // Medium raw coords.5164 { // Medium raw coords.
5166 { hh, 0.0f }, { 0.25f-hh, 0.0f }, { 0.25f-hh, 0.0f }, { hh, 0.0f },5165 { hh, 0.0f }, { 0.25f-hh, 0.0f }, { 0.25f-hh, 0.0f }, { hh, 0.0f },
@@ -6484,7 +6483,7 @@
64846483
6485// Low resolution shape texture.6484// Low resolution shape texture.
6486TextureData shapeTextureLow __attribute__((aligned(16))) = {6485TextureData shapeTextureLow __attribute__((aligned(16))) = {
6487 shapeTextureLowData, NULL, 128, 64, 4, 16.0f, 32.0f, 9.0f,6486 shapeTextureLowData, 128, 64, 4, 16.0f, 32.0f, 9.0f,
6488 {6487 {
6489 { // Medium raw coords.6488 { // Medium raw coords.
6490 { hl, 0.0f }, { 0.25f-hl, 0.0f }, { 0.25f-hl, 0.0f }, { hl, 0.0f },6489 { hl, 0.0f }, { 0.25f-hl, 0.0f }, { 0.25f-hl, 0.0f }, { hl, 0.0f },

Subscribers

People subscribed via source and target branches