on xenial help sign in
Reduce texture memory used

By making sure the sourceSize of dash images is as small as possible

commitfea8816d4a8c25a924abe37fa0026ce89bbd22d1 authorAlbert Astals <albert.astals@canonical.com> dateMon 25 Aug 2014, 10:25 (12 years ago) parente95909e
9 files changed+53−30
plugins/Dash/CardCreator.js+3−7 plugins/Dash/CroppedImageMinimumSourceSize.qml+38 plugins/Dash/qmldir+2−1 tests/plugins/Dash/cardcreator/1.res+1−2 tests/plugins/Dash/cardcreator/2.res+2−5 tests/plugins/Dash/cardcreator/3.res+2−3 tests/plugins/Dash/cardcreator/4.res+2−5 tests/plugins/Dash/cardcreator/5.res+1−2 tests/plugins/Dash/cardcreator/7.res+2−5
plugins/Dash/CardCreator.js+3−7
@@ -82,12 +82,11 @@ var kArtShapeHolderCode = 'Item { \n\
8282 height = Qt.binding(function() { return !visible ? 0 : image.height }); \n\
8383 } \n\
8484 } \n\
85− image: Image { \n\
85+ image: CroppedImageMinimumSourceSize { \n\
8686 objectName: "artImage"; \n\
8787 source: cardData && cardData["art"] || ""; \n\
8888 cache: true; \n\
8989 asynchronous: root.asynchronous; \n\
90− fillMode: Image.PreserveAspectCrop; \n\
9190 width: %2; \n\
9291 height: %3; \n\
9392 } \n\
@@ -190,16 +189,13 @@ var kMascotShapeLoaderCode = 'Loader { \n\
190189
191190// %1 is used as anchors of mascotImage
192191// %2 is used as visible of mascotImage
193−var kMascotImageCode = 'Image { \n\
192+var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
194193 id: mascotImage; \n\
195194 objectName: "mascotImage"; \n\
196195 anchors { %1 } \n\
197− readonly property int maxSize: Math.max(width, height) * 4; \n\
198196 source: cardData && cardData["mascot"] || ""; \n\
199197 width: units.gu(6); \n\
200198 height: units.gu(5.625); \n\
201− sourceSize { width: maxSize; height: maxSize } \n\
202− fillMode: Image.PreserveAspectCrop; \n\
203199 horizontalAlignment: Image.AlignHCenter; \n\
204200 verticalAlignment: Image.AlignVCenter; \n\
205201 visible: %2; \n\
@@ -435,7 +431,7 @@ function cardString(template, components) {
435431 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
436432 }
437433
438− var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
434+ var mascotImageVisible = useMascotShape ? 'false' : 'showHeader && resized';
439435 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
440436 }
441437
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
33typeinfo Dash.qmltypes
44singleton CardCreatorCache 0.1 CardCreatorCache.qml
55ScopeStyle 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 {
4444 height = Qt.binding(function() { return !visible ? 0 : image.height });
4545 }
4646 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
4848 objectName: "artImage";
4949 source: cardData && cardData["art"] || "";
5050 cache: true;
5151 asynchronous: root.asynchronous;
52− fillMode: Image.PreserveAspectCrop;
5352 width: root.width;
5453 height: width / artShape.aspect;
5554 }
tests/plugins/Dash/cardcreator/2.res+2−5
@@ -62,19 +62,16 @@ Row {
6262 anchors.margins: margins;
6363 anchors.rightMargin: 0;
6464 data: [
65−Image {
65+CroppedImageMinimumSourceSize {
6666 id: mascotImage;
6767 objectName: "mascotImage";
6868 anchors { verticalCenter: parent.verticalCenter; }
69− readonly property int maxSize: Math.max(width, height) * 4;
7069 source: cardData && cardData["mascot"] || "";
7170 width: units.gu(6);
7271 height: units.gu(5.625);
73− sourceSize { width: maxSize; height: maxSize }
74− fillMode: Image.PreserveAspectCrop;
7572 horizontalAlignment: Image.AlignHCenter;
7673 verticalAlignment: Image.AlignVCenter;
77− visible: showHeader;
74+ visible: showHeader && resized;
7875 }
7976,Item {
8077 id: headerTitleContainer;
tests/plugins/Dash/cardcreator/3.res+2−3
@@ -1,4 +1,4 @@
1−AbstractButton {
1+AbstractButton {
22 id: root;
33 property var template;
44 property var components;
@@ -44,12 +44,11 @@ Item {
4444 height = Qt.binding(function() { return !visible ? 0 : image.height });
4545 }
4646 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
4848 objectName: "artImage";
4949 source: cardData && cardData["art"] || "";
5050 cache: true;
5151 asynchronous: root.asynchronous;
52− fillMode: Image.PreserveAspectCrop;
5352 width: root.width;
5453 height: width / artShape.aspect;
5554 }
tests/plugins/Dash/cardcreator/4.res+2−5
@@ -41,19 +41,16 @@ Loader {
4141 anchors { verticalCenter: parent.verticalCenter; }
4242 }
4343
44−,Image {
44+,CroppedImageMinimumSourceSize {
4545 id: mascotImage;
4646 objectName: "mascotImage";
4747 anchors { verticalCenter: parent.verticalCenter; }
48− readonly property int maxSize: Math.max(width, height) * 4;
4948 source: cardData && cardData["mascot"] || "";
5049 width: units.gu(6);
5150 height: units.gu(5.625);
52− sourceSize { width: maxSize; height: maxSize }
53− fillMode: Image.PreserveAspectCrop;
5451 horizontalAlignment: Image.AlignHCenter;
5552 verticalAlignment: Image.AlignVCenter;
56− visible: false;
53+ visible: false;
5754 }
5855
5956,Item {
tests/plugins/Dash/cardcreator/5.res+1−2
@@ -44,12 +44,11 @@ Item {
4444 height = Qt.binding(function() { return !visible ? 0 : image.height });
4545 }
4646 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
4848 objectName: "artImage";
4949 source: cardData && cardData["art"] || "";
5050 cache: true;
5151 asynchronous: root.asynchronous;
52− fillMode: Image.PreserveAspectCrop;
5352 width: root.width;
5453 height: width / artShape.aspect;
5554 }
tests/plugins/Dash/cardcreator/7.res+2−5
@@ -62,19 +62,16 @@ Row {
6262 anchors.margins: margins;
6363 anchors.rightMargin: 0;
6464 data: [
65−Image {
65+CroppedImageMinimumSourceSize {
6666 id: mascotImage;
6767 objectName: "mascotImage";
6868 anchors { verticalCenter: parent.verticalCenter; }
69− readonly property int maxSize: Math.max(width, height) * 4;
7069 source: cardData && cardData["mascot"] || "";
7170 width: units.gu(6);
7271 height: units.gu(5.625);
73− sourceSize { width: maxSize; height: maxSize }
74− fillMode: Image.PreserveAspectCrop;
7572 horizontalAlignment: Image.AlignHCenter;
7673 verticalAlignment: Image.AlignVCenter;
77− visible: showHeader;
74+ visible: showHeader && resized;
7875 }
7976
8077,Item {