on xenial help sign in
Save texture memory by limiting sourceSize Fixes: 1338430
c137cebMichał Sawicz
plugins/Dash/CardCreator.js+4−7
@@ -82,13 +82,13 @@ var kArtShapeHolderCode = 'Item { \n\
82 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height }); \n\
82 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height }); \n\
83 } \n\
83 } \n\
84 } \n\
84 } \n\
85− image: Image { \n\
85+ image: CroppedImageMinimumSourceSize { \n\
86 objectName: "artImage"; \n\
86 objectName: "artImage"; \n\
87 property bool doLoadSource: !NetworkingStatus.limitedBandwith; \n\
87 property bool doLoadSource: !NetworkingStatus.limitedBandwith; \n\
88 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; } \n\
88 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; } \n\
89 cache: true; \n\
89 cache: true; \n\
90 asynchronous: root.asynchronous; \n\
90 asynchronous: root.asynchronous; \n\
91− fillMode: Image.PreserveAspectCrop; \n\
91+ visible: false; \n\
92 width: %2; \n\
92 width: %2; \n\
93 height: %3; \n\
93 height: %3; \n\
94 } \n\
94 } \n\
@@ -191,17 +191,14 @@ var kMascotShapeLoaderCode = 'Loader { \n\
191
191
192// %1 is used as anchors of mascotImage
192// %1 is used as anchors of mascotImage
193// %2 is used as visible of mascotImage
193// %2 is used as visible of mascotImage
194−var kMascotImageCode = 'Image { \n\
194+var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
195 id: mascotImage; \n\
195 id: mascotImage; \n\
196 objectName: "mascotImage"; \n\
196 objectName: "mascotImage"; \n\
197 anchors { %1 } \n\
197 anchors { %1 } \n\
198− readonly property int maxSize: Math.max(width, height) * 4; \n\
199 property bool doLoadSource: !NetworkingStatus.limitedBandwith; \n\
198 property bool doLoadSource: !NetworkingStatus.limitedBandwith; \n\
200 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; } \n\
199 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; } \n\
201 width: units.gu(6); \n\
200 width: units.gu(6); \n\
202 height: units.gu(5.625); \n\
201 height: units.gu(5.625); \n\
203− sourceSize { width: maxSize; height: maxSize } \n\
204− fillMode: Image.PreserveAspectCrop; \n\
205 horizontalAlignment: Image.AlignHCenter; \n\
202 horizontalAlignment: Image.AlignHCenter; \n\
206 verticalAlignment: Image.AlignVCenter; \n\
203 verticalAlignment: Image.AlignVCenter; \n\
207 visible: %2; \n\
204 visible: %2; \n\
@@ -436,7 +433,7 @@ function cardString(template, components) {
436 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
433 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
437 }
434 }
438
435
439− var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
436+ var mascotImageVisible = useMascotShape ? 'false' : 'showHeader && resized';
440 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
437 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
441 }
438 }
442
439
plugins/Dash/CroppedImageMinimumSourceSize.qmlnew file+38
@@ -0,0 +1,38 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.3
18+
19+Image {
20+ property bool resized: false
21+ property bool resizing: false
22+ fillMode: Image.PreserveAspectCrop
23+ visible: resized
24+ onSourceSizeChanged: {
25+ if (!resized && !resizing) {
26+ resizing = true;
27+ var ar = width / height;
28+ var ssar = sourceSize.width / sourceSize.height;
29+ if (ar > ssar) {
30+ sourceSize = Qt.size(width, 0);
31+ } else {
32+ sourceSize = Qt.size(0, height);
33+ }
34+ resizing = false;
35+ resized = true;
36+ }
37+ }
38+}
plugins/Dash/qmldir+2−1
@@ -3,4 +3,5 @@ plugin Dash-qml
3typeinfo Dash.qmltypes
3typeinfo Dash.qmltypes
4singleton CardCreatorCache 0.1 CardCreatorCache.qml
4singleton CardCreatorCache 0.1 CardCreatorCache.qml
5ScopeStyle 0.1 ScopeStyle.qml
5ScopeStyle 0.1 ScopeStyle.qml
6−CardAttributes 0.1 CardAttributes.qml
6+CardAttributes 0.1 CardAttributes.qml
7+CroppedImageMinimumSourceSize 0.1 CroppedImageMinimumSourceSize.qml
tests/plugins/Dash/cardcreator/1.res+2−2
@@ -44,13 +44,13 @@ Item {
44 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
44 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
45 }
45 }
46 }
46 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
48 objectName: "artImage";
48 objectName: "artImage";
49 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
49 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
50 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; }
50 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; }
51 cache: true;
51 cache: true;
52 asynchronous: root.asynchronous;
52 asynchronous: root.asynchronous;
53− fillMode: Image.PreserveAspectCrop;
53+ visible: false;
54 width: root.width;
54 width: root.width;
55 height: width / artShape.aspect;
55 height: width / artShape.aspect;
56 }
56 }
tests/plugins/Dash/cardcreator/2.res+2−5
@@ -62,20 +62,17 @@ Row {
62 anchors.margins: margins;
62 anchors.margins: margins;
63 anchors.rightMargin: 0;
63 anchors.rightMargin: 0;
64 data: [
64 data: [
65−Image {
65+CroppedImageMinimumSourceSize {
66 id: mascotImage;
66 id: mascotImage;
67 objectName: "mascotImage";
67 objectName: "mascotImage";
68 anchors { verticalCenter: parent.verticalCenter; }
68 anchors { verticalCenter: parent.verticalCenter; }
69− readonly property int maxSize: Math.max(width, height) * 4;
70 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
69 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
71 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; }
70 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; }
72 width: units.gu(6);
71 width: units.gu(6);
73 height: units.gu(5.625);
72 height: units.gu(5.625);
74− sourceSize { width: maxSize; height: maxSize }
75− fillMode: Image.PreserveAspectCrop;
76 horizontalAlignment: Image.AlignHCenter;
73 horizontalAlignment: Image.AlignHCenter;
77 verticalAlignment: Image.AlignVCenter;
74 verticalAlignment: Image.AlignVCenter;
78− visible: showHeader;
75+ visible: showHeader && resized;
79 }
76 }
80,Item {
77,Item {
81 id: headerTitleContainer;
78 id: headerTitleContainer;
tests/plugins/Dash/cardcreator/3.res+2−2
@@ -44,13 +44,13 @@ Item {
44 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
44 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
45 }
45 }
46 }
46 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
48 objectName: "artImage";
48 objectName: "artImage";
49 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
49 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
50 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; }
50 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; }
51 cache: true;
51 cache: true;
52 asynchronous: root.asynchronous;
52 asynchronous: root.asynchronous;
53− fillMode: Image.PreserveAspectCrop;
53+ visible: false;
54 width: root.width;
54 width: root.width;
55 height: width / artShape.aspect;
55 height: width / artShape.aspect;
56 }
56 }
tests/plugins/Dash/cardcreator/4.res+1−4
@@ -41,17 +41,14 @@ Loader {
41 anchors { verticalCenter: parent.verticalCenter; }
41 anchors { verticalCenter: parent.verticalCenter; }
42 }
42 }
43
43
44−,Image {
44+,CroppedImageMinimumSourceSize {
45 id: mascotImage;
45 id: mascotImage;
46 objectName: "mascotImage";
46 objectName: "mascotImage";
47 anchors { verticalCenter: parent.verticalCenter; }
47 anchors { verticalCenter: parent.verticalCenter; }
48− readonly property int maxSize: Math.max(width, height) * 4;
49 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
48 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
50 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; }
49 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; }
51 width: units.gu(6);
50 width: units.gu(6);
52 height: units.gu(5.625);
51 height: units.gu(5.625);
53− sourceSize { width: maxSize; height: maxSize }
54− fillMode: Image.PreserveAspectCrop;
55 horizontalAlignment: Image.AlignHCenter;
52 horizontalAlignment: Image.AlignHCenter;
56 verticalAlignment: Image.AlignVCenter;
53 verticalAlignment: Image.AlignVCenter;
57 visible: false;
54 visible: false;
tests/plugins/Dash/cardcreator/5.res+2−2
@@ -44,13 +44,13 @@ Item {
44 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
44 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
45 }
45 }
46 }
46 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
48 objectName: "artImage";
48 objectName: "artImage";
49 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
49 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
50 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; }
50 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; }
51 cache: true;
51 cache: true;
52 asynchronous: root.asynchronous;
52 asynchronous: root.asynchronous;
53− fillMode: Image.PreserveAspectCrop;
53+ visible: false;
54 width: root.width;
54 width: root.width;
55 height: width / artShape.aspect;
55 height: width / artShape.aspect;
56 }
56 }
tests/plugins/Dash/cardcreator/7.res+2−5
@@ -62,20 +62,17 @@ Row {
62 anchors.margins: margins;
62 anchors.margins: margins;
63 anchors.rightMargin: 0;
63 anchors.rightMargin: 0;
64 data: [
64 data: [
65−Image {
65+CroppedImageMinimumSourceSize {
66 id: mascotImage;
66 id: mascotImage;
67 objectName: "mascotImage";
67 objectName: "mascotImage";
68 anchors { verticalCenter: parent.verticalCenter; }
68 anchors { verticalCenter: parent.verticalCenter; }
69− readonly property int maxSize: Math.max(width, height) * 4;
70 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
69 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
71 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; }
70 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; }
72 width: units.gu(6);
71 width: units.gu(6);
73 height: units.gu(5.625);
72 height: units.gu(5.625);
74− sourceSize { width: maxSize; height: maxSize }
75− fillMode: Image.PreserveAspectCrop;
76 horizontalAlignment: Image.AlignHCenter;
73 horizontalAlignment: Image.AlignHCenter;
77 verticalAlignment: Image.AlignVCenter;
74 verticalAlignment: Image.AlignVCenter;
78− visible: showHeader;
75+ visible: showHeader && resized;
79 }
76 }
80
77
81,Item {
78,Item {