From 5045667528089f505cb0b2e2d32650715129d194 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Wed, 26 Jan 2022 11:37:07 -0500
Subject: [PATCH] datatransferimage: improve memory usage

+ Reduce listview caching' size by 50%
+ use sourceSize to compress images and speedup loading
+ use autoTransform: true to rotate images when needed

Change-Id: Idf1babdc73f43aa6a79b89428c25c5d06856c0ef
GitLab: #649
---
 .../DataTransferMessageDelegate.qml              | 16 +++++++++++-----
 src/mainview/components/MessageListView.qml      |  4 ++--
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/commoncomponents/DataTransferMessageDelegate.qml b/src/commoncomponents/DataTransferMessageDelegate.qml
index d017c03ad..ca5913efc 100644
--- a/src/commoncomponents/DataTransferMessageDelegate.qml
+++ b/src/commoncomponents/DataTransferMessageDelegate.qml
@@ -255,9 +255,13 @@ Loader {
                     asynchronous: true
                     width: sourceComponent.width
                     height: sourceComponent.height
-                    sourceComponent: mediaInfo.isImage !== undefined ?
-                                         imageComp : mediaInfo.isAnimatedImage !== undefined ? animatedImageComp :
-                                         avComp
+                    sourceComponent: {
+                        if (mediaInfo.isImage)
+                            return imageComp
+                        if (mediaInfo.isAnimatedImage)
+                            return animatedImageComp
+                        return avComp
+                    }
                     Component {
                         id: avComp
                         WebEngineView {
@@ -316,7 +320,7 @@ Loader {
                             fillMode: Image.PreserveAspectCrop
                             mipmap: true
                             antialiasing: true
-                            autoTransform: false
+                            autoTransform: true
                             asynchronous: true
                             source: "file:///" + Body
                             property real aspectRatio: implicitWidth / implicitHeight
@@ -361,8 +365,10 @@ Loader {
                             fillMode: Image.PreserveAspectCrop
                             mipmap: true
                             antialiasing: true
-                            autoTransform: false
+                            autoTransform: true
                             asynchronous: true
+                            sourceSize.width: width
+                            sourceSize.height: height
                             source: "file:///" + Body
                             property real aspectRatio: implicitWidth / implicitHeight
                             property real adjustedWidth: Math.min(maxSize,
diff --git a/src/mainview/components/MessageListView.qml b/src/mainview/components/MessageListView.qml
index 2b7c32648..f65e67b16 100644
--- a/src/mainview/components/MessageListView.qml
+++ b/src/mainview/components/MessageListView.qml
@@ -174,8 +174,8 @@ JamiListView {
     width: parent.width
     // this offscreen caching is pretty huge
     // displayMarginEnd may be removed
-    displayMarginBeginning: 4096
-    displayMarginEnd: 4096
+    displayMarginBeginning: 2048
+    displayMarginEnd: 2048
     maximumFlickVelocity: 2048
     verticalLayoutDirection: ListView.BottomToTop
     boundsBehavior: Flickable.StopAtBounds
-- 
GitLab