on xenial help sign in
Save texture memory by limiting sourceSize Fixes: 1338430

Approved by: Mirco Müller

commitc137ceb1f4851553329e6d6cdfda028f12ccc451 authorMichał Sawicz <michal.sawicz@canonical.com> dateMon 6 Oct 2014, 08:01 (12 years ago) parentefcd1bae56d689
9 files changed+55−28
plugins/Dash/CardCreator.js+4−7 plugins/Dash/CroppedImageMinimumSourceSize.qml+38 plugins/Dash/qmldir+2−1 tests/plugins/Dash/cardcreator/1.res+2−2 tests/plugins/Dash/cardcreator/2.res+2−5 tests/plugins/Dash/cardcreator/3.res+2−2 tests/plugins/Dash/cardcreator/4.res+1−4 tests/plugins/Dash/cardcreator/5.res+2−2 tests/plugins/Dash/cardcreator/7.res+2−5
plugins/Dash/CardCreator.js+4−7
@@ -82,13 +82,13 @@ var kArtShapeHolderCode = 'Item { \n\
8282 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height }); \n\
8383 } \n\
8484 } \n\
85− image: Image { \n\
85+ image: CroppedImageMinimumSourceSize { \n\
8686 objectName: "artImage"; \n\
8787 property bool doLoadSource: !NetworkingStatus.limitedBandwith; \n\
8888 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; } \n\
8989 cache: true; \n\
9090 asynchronous: root.asynchronous; \n\
91− fillMode: Image.PreserveAspectCrop; \n\
91+ visible: false; \n\
9292 width: %2; \n\
9393 height: %3; \n\
9494 } \n\
@@ -191,17 +191,14 @@ var kMascotShapeLoaderCode = 'Loader { \n\
191191
192192// %1 is used as anchors of mascotImage
193193// %2 is used as visible of mascotImage
194−var kMascotImageCode = 'Image { \n\
194+var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
195195 id: mascotImage; \n\
196196 objectName: "mascotImage"; \n\
197197 anchors { %1 } \n\
198− readonly property int maxSize: Math.max(width, height) * 4; \n\
199198 property bool doLoadSource: !NetworkingStatus.limitedBandwith; \n\
200199 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; } \n\
201200 width: units.gu(6); \n\
202201 height: units.gu(5.625); \n\
203− sourceSize { width: maxSize; height: maxSize } \n\
204− fillMode: Image.PreserveAspectCrop; \n\
205202 horizontalAlignment: Image.AlignHCenter; \n\
206203 verticalAlignment: Image.AlignVCenter; \n\
207204 visible: %2; \n\
@@ -436,7 +433,7 @@ function cardString(template, components) {
436433 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
437434 }
438435
439− var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
436+ var mascotImageVisible = useMascotShape ? 'false' : 'showHeader && resized';
440437 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
441438 }
442439
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
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+2−2
@@ -44,13 +44,13 @@ Item {
4444 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
4545 }
4646 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
4848 objectName: "artImage";
4949 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
5050 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; }
5151 cache: true;
5252 asynchronous: root.asynchronous;
53− fillMode: Image.PreserveAspectCrop;
53+ visible: false;
5454 width: root.width;
5555 height: width / artShape.aspect;
5656 }
tests/plugins/Dash/cardcreator/2.res+2−5
@@ -62,20 +62,17 @@ 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 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
7170 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; }
7271 width: units.gu(6);
7372 height: units.gu(5.625);
74− sourceSize { width: maxSize; height: maxSize }
75− fillMode: Image.PreserveAspectCrop;
7673 horizontalAlignment: Image.AlignHCenter;
7774 verticalAlignment: Image.AlignVCenter;
78− visible: showHeader;
75+ visible: showHeader && resized;
7976 }
8077,Item {
8178 id: headerTitleContainer;
tests/plugins/Dash/cardcreator/3.res+2−2
@@ -44,13 +44,13 @@ Item {
4444 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
4545 }
4646 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
4848 objectName: "artImage";
4949 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
5050 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; }
5151 cache: true;
5252 asynchronous: root.asynchronous;
53− fillMode: Image.PreserveAspectCrop;
53+ visible: false;
5454 width: root.width;
5555 height: width / artShape.aspect;
5656 }
tests/plugins/Dash/cardcreator/4.res+1−4
@@ -41,17 +41,14 @@ 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 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
5049 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; }
5150 width: units.gu(6);
5251 height: units.gu(5.625);
53− sourceSize { width: maxSize; height: maxSize }
54− fillMode: Image.PreserveAspectCrop;
5552 horizontalAlignment: Image.AlignHCenter;
5653 verticalAlignment: Image.AlignVCenter;
5754 visible: false;
tests/plugins/Dash/cardcreator/5.res+2−2
@@ -44,13 +44,13 @@ Item {
4444 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
4545 }
4646 }
47− image: Image {
47+ image: CroppedImageMinimumSourceSize {
4848 objectName: "artImage";
4949 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
5050 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["art"] || ""; }
5151 cache: true;
5252 asynchronous: root.asynchronous;
53− fillMode: Image.PreserveAspectCrop;
53+ visible: false;
5454 width: root.width;
5555 height: width / artShape.aspect;
5656 }
tests/plugins/Dash/cardcreator/7.res+2−5
@@ -62,20 +62,17 @@ 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 property bool doLoadSource: !NetworkingStatus.limitedBandwith;
7170 source: { if (root.visible) doLoadSource = true; return doLoadSource && cardData && cardData["mascot"] || ""; }
7271 width: units.gu(6);
7372 height: units.gu(5.625);
74− sourceSize { width: maxSize; height: maxSize }
75− fillMode: Image.PreserveAspectCrop;
7673 horizontalAlignment: Image.AlignHCenter;
7774 verticalAlignment: Image.AlignVCenter;
78− visible: showHeader;
75+ visible: showHeader && resized;
7976 }
8077
8178,Item {