[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: add cache property to RoundImage

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Apr 13 17:45:48 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
31449414 by Pierre Lamot at 2024-04-13T16:28:40+00:00
qt: add cache property to RoundImage

- - - - -
41d61e8d by Prince Gupta at 2024-04-13T16:28:40+00:00
qml: expose image cache property from GridItem

- - - - -
35210a54 by Prince Gupta at 2024-04-13T16:28:40+00:00
qml: don't cache large medialibrary covers

don't cache large media covers of GridItem to save on memory
prioritize caching small and frequently used images like 'fallbackImage'

- - - - -


7 changed files:

- modules/gui/qt/medialibrary/qml/MusicGenres.qml
- modules/gui/qt/network/qml/NetworkGridItem.qml
- modules/gui/qt/widgets/native/roundimage.cpp
- modules/gui/qt/widgets/native/roundimage.hpp
- modules/gui/qt/widgets/native/roundimage_p.hpp
- modules/gui/qt/widgets/qml/GridItem.qml
- modules/gui/qt/widgets/qml/MediaCover.qml


Changes:

=====================================
modules/gui/qt/medialibrary/qml/MusicGenres.qml
=====================================
@@ -136,7 +136,10 @@ MainInterface.MainViewLoader {
                 height: width / 2
                 pictureWidth: width
                 pictureHeight: height
+
                 image: model.cover || ""
+                cacheImage: true // for this view, we generate custom covers, cache it
+
                 fallbackImage: VLCStyle.noArtAlbumCover
 
                 playCoverBorderWidth: VLCStyle.dp(3, VLCStyle.scale)


=====================================
modules/gui/qt/network/qml/NetworkGridItem.qml
=====================================
@@ -50,6 +50,8 @@ Widgets.GridItem {
         return ""
     }
 
+    cacheImage: true // we may have network thumbnail
+
     fallbackImage: {
         const f = function(type) {
             switch (type) {


=====================================
modules/gui/qt/widgets/native/roundimage.cpp
=====================================
@@ -231,6 +231,11 @@ RoundImageRequest::~RoundImageRequest()
     g_imageCache.removeRequest(m_key);
 }
 
+void RoundImageRequest::saveInCache()
+{
+    m_saveInCache = true;
+}
+
 void RoundImageRequest::handleImageResponseFinished()
 {
     m_cancelOnDelete = false;
@@ -255,7 +260,8 @@ void RoundImageRequest::handleImageResponseFinished()
 
     image.setDevicePixelRatio(m_dpr);
 
-    g_imageCache.insert(m_key, new QImage(image), image.sizeInBytes());
+    if (m_saveInCache)
+        g_imageCache.insert(m_key, new QImage(image), image.sizeInBytes());
     emit requestCompleted(RoundImage::Status::Ready, image);
 }
 
@@ -416,6 +422,11 @@ RoundImage::Status RoundImage::status() const
     return m_status;
 }
 
+bool RoundImage::cache() const
+{
+    return m_cache;
+}
+
 void RoundImage::setSource(const QUrl& source)
 {
     if (m_source == source)
@@ -435,6 +446,14 @@ void RoundImage::setRadius(qreal radius)
     emit radiusChanged(m_radius);
 }
 
+void RoundImage::setCache(bool cache)
+{
+    if (m_cache == cache)
+        return;
+    m_cache = cache;
+    emit cacheChanged();
+}
+
 void RoundImage::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
 {
     if (change == QQuickItem::ItemDevicePixelRatioHasChanged)
@@ -479,6 +498,9 @@ void RoundImage::load()
         return;
     }
 
+    if (m_cache)
+        m_activeImageResponse->saveInCache();
+
     connect(m_activeImageResponse.get(), &RoundImageRequest::requestCompleted, this, &RoundImage::onRequestCompleted);
     //at this point m_activeImageResponse is either in Loading or Error status
     onRequestCompleted(RoundImage::Loading, {});


=====================================
modules/gui/qt/widgets/native/roundimage.hpp
=====================================
@@ -42,6 +42,8 @@ class RoundImage : public QQuickItem
 
     Q_PROPERTY(Status status READ status NOTIFY statusChanged FINAL)
 
+    Q_PROPERTY(bool cache READ cache WRITE setCache NOTIFY cacheChanged FINAL)
+
 public:
     enum Status
     {
@@ -61,15 +63,18 @@ public:
     QUrl source() const;
     qreal radius() const;
     Status status() const;
+    bool cache() const;
 
 public slots:
     void setSource(const QUrl& source);
     void setRadius(qreal radius);
+    void setCache(bool cache);
 
 signals:
     void sourceChanged(const QUrl&);
     void radiusChanged(qreal);
     void statusChanged();
+    void cacheChanged();;
 
 protected:
     void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) override;
@@ -96,6 +101,7 @@ private:
     QUrl m_source;
     qreal m_radius = 0.0;
     qreal m_dpr = 1.0; // device pixel ratio
+    bool m_cache = true;
 
     QImage m_roundImage;
     std::shared_ptr<RoundImageRequest> m_activeImageResponse;


=====================================
modules/gui/qt/widgets/native/roundimage_p.hpp
=====================================
@@ -78,6 +78,8 @@ public:
 
     void handleImageResponseFinished();
 
+    void saveInCache();
+
 signals:
     void requestCompleted(RoundImage::Status status, QImage image);
 
@@ -89,6 +91,7 @@ private:
     qreal m_dpr;
     QQuickImageResponse* m_imageResponse = nullptr;
     RoundImage::Status m_status = RoundImage::Status::Loading;
+    bool m_saveInCache = false;
 };
 
 /**


=====================================
modules/gui/qt/widgets/qml/GridItem.qml
=====================================
@@ -50,6 +50,7 @@ T.ItemDelegate {
     // Aliases
 
     property alias image: picture.source
+    property alias cacheImage: picture.cacheImage
     property alias isImageReady: picture.isImageReady
     property alias fallbackImage: picture.fallbackImageSource
 


=====================================
modules/gui/qt/widgets/qml/MediaCover.qml
=====================================
@@ -42,8 +42,12 @@ Rectangle {
     // Aliases
 
     property alias source: image.source
+
+    property alias cacheImage: image.cache
+
     property bool isImageReady: image.status == RoundImage.Ready
 
+
     property string fallbackImageSource
 
     property alias imageOverlay: overlay.sourceComponent
@@ -71,6 +75,8 @@ Rectangle {
         anchors.fill: parent
 
         radius: root.radius
+
+        cache: false
     }
 
     RoundImage {
@@ -85,6 +91,8 @@ Rectangle {
         // we only keep this image till there is no main image
         // try to release the resources otherwise
         source: !root.isImageReady ? root.fallbackImageSource : ""
+
+        cache: true
     }
 
     Loader {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d28d827465b5dda15f4e0105d9512086cd727426...35210a54fb6b466bb2fec4c7cdd5a8fe0388fa66

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d28d827465b5dda15f4e0105d9512086cd727426...35210a54fb6b466bb2fec4c7cdd5a8fe0388fa66
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list