on xenial help sign in
Reduce texture memory used
fea8816Albert Astals
plugins/Dash/CardCreator.js+3−7
@@ -82,12 +82,11 @@ var kArtShapeHolderCode = 'Item { \n\
82 height = Qt.binding(function() { return !visible ? 0 : image.height }); \n\
82 height = Qt.binding(function() { return !visible ? 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 source: cardData && cardData["art"] || ""; \n\
87 source: cardData && cardData["art"] || ""; \n\
88 cache: true; \n\
88 cache: true; \n\
89 asynchronous: root.asynchronous; \n\
89 asynchronous: root.asynchronous; \n\
90− fillMode: Image.PreserveAspectCrop; \n\
91 width: %2; \n\
90 width: %2; \n\
92 height: %3; \n\
91 height: %3; \n\
93 } \n\
92 } \n\
@@ -190,16 +189,13 @@ var kMascotShapeLoaderCode = 'Loader { \n\
190
189
191// %1 is used as anchors of mascotImage
190// %1 is used as anchors of mascotImage
192// %2 is used as visible of mascotImage
191// %2 is used as visible of mascotImage
193−var kMascotImageCode = 'Image { \n\
192+var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
194 id: mascotImage; \n\
193 id: mascotImage; \n\
195 objectName: "mascotImage"; \n\
194 objectName: "mascotImage"; \n\
196 anchors { %1 } \n\
195 anchors { %1 } \n\
197− readonly property int maxSize: Math.max(width, height) * 4; \n\
198 source: cardData && cardData["mascot"] || ""; \n\
196 source: cardData && cardData["mascot"] || ""; \n\
199 width: units.gu(6); \n\
197 width: units.gu(6); \n\
200 height: units.gu(5.625); \n\
198 height: units.gu(5.625); \n\
201− sourceSize { width: maxSize; height: maxSize } \n\
202− fillMode: Image.PreserveAspectCrop; \n\
203 horizontalAlignment: Image.AlignHCenter; \n\
199 horizontalAlignment: Image.AlignHCenter; \n\
204 verticalAlignment: Image.AlignVCenter; \n\
200 verticalAlignment: Image.AlignVCenter; \n\
205 visible: %2; \n\
201 visible: %2; \n\
@@ -435,7 +431,7 @@ function cardString(template, components) {
435 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
431 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
436 }
432 }
437
433
438− var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
434+ var mascotImageVisible = useMascotShape ? 'false' : 'showHeader && resized';
439 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
435 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
440 }
436 }
441
437
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+ fillMode: Image.PreserveAspectCrop
21+ property bool resized: false
22+ property bool resizing: false
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+1−2
@@ -44,12 +44,11 @@ Item {
44 height = Qt.binding(function() { return !visible ? 0 : image.height });
44 height = Qt.binding(function() { return !visible ? 0 : image.height });
45 }
45 }
46 }
46 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
48 objectName: "artImage";
48 objectName: "artImage";
49 source: cardData && cardData["art"] || "";
49 source: cardData && cardData["art"] || "";
50 cache: true;
50 cache: true;
51 asynchronous: root.asynchronous;
51 asynchronous: root.asynchronous;
52− fillMode: Image.PreserveAspectCrop;
53 width: root.width;
52 width: root.width;
54 height: width / artShape.aspect;
53 height: width / artShape.aspect;
55 }
54 }
tests/plugins/Dash/cardcreator/2.res+2−5
@@ -62,19 +62,16 @@ 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 source: cardData && cardData["mascot"] || "";
69 source: cardData && cardData["mascot"] || "";
71 width: units.gu(6);
70 width: units.gu(6);
72 height: units.gu(5.625);
71 height: units.gu(5.625);
73− sourceSize { width: maxSize; height: maxSize }
74− fillMode: Image.PreserveAspectCrop;
75 horizontalAlignment: Image.AlignHCenter;
72 horizontalAlignment: Image.AlignHCenter;
76 verticalAlignment: Image.AlignVCenter;
73 verticalAlignment: Image.AlignVCenter;
77− visible: showHeader;
74+ visible: showHeader && resized;
78 }
75 }
79,Item {
76,Item {
80 id: headerTitleContainer;
77 id: headerTitleContainer;
tests/plugins/Dash/cardcreator/3.res+2−3
@@ -1,4 +1,4 @@
1−AbstractButton {
1+AbstractButton {
2 id: root;
2 id: root;
3 property var template;
3 property var template;
4 property var components;
4 property var components;
@@ -44,12 +44,11 @@ Item {
44 height = Qt.binding(function() { return !visible ? 0 : image.height });
44 height = Qt.binding(function() { return !visible ? 0 : image.height });
45 }
45 }
46 }
46 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
48 objectName: "artImage";
48 objectName: "artImage";
49 source: cardData && cardData["art"] || "";
49 source: cardData && cardData["art"] || "";
50 cache: true;
50 cache: true;
51 asynchronous: root.asynchronous;
51 asynchronous: root.asynchronous;
52− fillMode: Image.PreserveAspectCrop;
53 width: root.width;
52 width: root.width;
54 height: width / artShape.aspect;
53 height: width / artShape.aspect;
55 }
54 }
tests/plugins/Dash/cardcreator/4.res+2−5
@@ -41,19 +41,16 @@ 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 source: cardData && cardData["mascot"] || "";
48 source: cardData && cardData["mascot"] || "";
50 width: units.gu(6);
49 width: units.gu(6);
51 height: units.gu(5.625);
50 height: units.gu(5.625);
52− sourceSize { width: maxSize; height: maxSize }
53− fillMode: Image.PreserveAspectCrop;
54 horizontalAlignment: Image.AlignHCenter;
51 horizontalAlignment: Image.AlignHCenter;
55 verticalAlignment: Image.AlignVCenter;
52 verticalAlignment: Image.AlignVCenter;
56− visible: false;
53+ visible: false;
57 }
54 }
58
55
59,Item {
56,Item {
tests/plugins/Dash/cardcreator/5.res+1−2
@@ -44,12 +44,11 @@ Item {
44 height = Qt.binding(function() { return !visible ? 0 : image.height });
44 height = Qt.binding(function() { return !visible ? 0 : image.height });
45 }
45 }
46 }
46 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
48 objectName: "artImage";
48 objectName: "artImage";
49 source: cardData && cardData["art"] || "";
49 source: cardData && cardData["art"] || "";
50 cache: true;
50 cache: true;
51 asynchronous: root.asynchronous;
51 asynchronous: root.asynchronous;
52− fillMode: Image.PreserveAspectCrop;
53 width: root.width;
52 width: root.width;
54 height: width / artShape.aspect;
53 height: width / artShape.aspect;
55 }
54 }
tests/plugins/Dash/cardcreator/7.res+2−5
@@ -62,19 +62,16 @@ 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 source: cardData && cardData["mascot"] || "";
69 source: cardData && cardData["mascot"] || "";
71 width: units.gu(6);
70 width: units.gu(6);
72 height: units.gu(5.625);
71 height: units.gu(5.625);
73− sourceSize { width: maxSize; height: maxSize }
74− fillMode: Image.PreserveAspectCrop;
75 horizontalAlignment: Image.AlignHCenter;
72 horizontalAlignment: Image.AlignHCenter;
76 verticalAlignment: Image.AlignVCenter;
73 verticalAlignment: Image.AlignVCenter;
77− visible: showHeader;
74+ visible: showHeader && resized;
78 }
75 }
79
76
80,Item {
77,Item {