[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Nov 27 12:17:03 UTC 2018


 include/vcl/ImageTree.hxx          |    6 ++++++
 vcl/inc/implimagetree.hxx          |   15 +++++++++++----
 vcl/source/image/ImageTree.cxx     |   10 +++++++++-
 vcl/source/image/ImplImageTree.cxx |   37 +++++++++++++++++++++++++------------
 4 files changed, 51 insertions(+), 17 deletions(-)

New commits:
commit bc8e23fc946380751447ab24587b1631eb56ef19
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Nov 26 13:24:03 2018 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Nov 27 13:16:38 2018 +0100

    Add explicit API scaling via ImageTree API.
    
    Also add image scale to in-memory cache lookup.
    
    Change-Id: I1e84b922d4a9ab2f1723c5cb8a72f295c6940504
    Reviewed-on: https://gerrit.libreoffice.org/64043
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/include/vcl/ImageTree.hxx b/include/vcl/ImageTree.hxx
index 6598c34c09e9..4b49a31f30b9 100644
--- a/include/vcl/ImageTree.hxx
+++ b/include/vcl/ImageTree.hxx
@@ -64,6 +64,12 @@ public:
         BitmapEx & bitmap, bool localized,
         const ImageLoadFlags eFlags = ImageLoadFlags::NONE);
 
+    VCL_DLLPUBLIC bool loadImage(
+        OUString const & name, OUString const & style,
+        BitmapEx & bitmap, bool localized,
+        sal_Int32 nScalePercentage,
+        const ImageLoadFlags eFlags = ImageLoadFlags::NONE);
+
     VCL_DLLPUBLIC css::uno::Reference<css::container::XNameAccess> const & getNameAccess();
 
 
diff --git a/vcl/inc/implimagetree.hxx b/vcl/inc/implimagetree.hxx
index 3768b04388b3..1e81aba8fac8 100644
--- a/vcl/inc/implimagetree.hxx
+++ b/vcl/inc/implimagetree.hxx
@@ -46,14 +46,17 @@ struct ImageRequestParameters
     bool mbLocalized;
     ImageLoadFlags const meFlags;
     bool mbWriteImageToCache;
+    sal_Int32 mnScalePercentage;
 
-    ImageRequestParameters(const OUString & rName, const OUString & rStyle, BitmapEx& rBitmap, bool bLocalized, ImageLoadFlags eFlags)
+    ImageRequestParameters(const OUString & rName, const OUString & rStyle, BitmapEx& rBitmap, bool bLocalized,
+                           ImageLoadFlags eFlags, sal_Int32 nScalePercentage)
         : msName(rName)
         , msStyle(rStyle)
         , mrBitmap(rBitmap)
         , mbLocalized(bLocalized)
         , meFlags(eFlags)
         , mbWriteImageToCache(false)
+        , mnScalePercentage(nScalePercentage)
     {}
 
     bool convertToDarkTheme();
@@ -75,7 +78,8 @@ public:
     bool loadImage(
         OUString const & name, OUString const & style,
         BitmapEx & bitmap, bool localized,
-        const ImageLoadFlags eFlags);
+        const ImageLoadFlags eFlags,
+        sal_Int32 nScalePercentage = -1);
 
     /** a crude form of life cycle control (called from DeInitVCL; otherwise,
      *  if the ImplImageTree singleton were destroyed during exit that would
@@ -88,14 +92,15 @@ private:
     ImplImageTree(const ImplImageTree&) = delete;
     ImplImageTree& operator=(const ImplImageTree&) = delete;
 
-    typedef std::unordered_map<OUString, std::pair<bool, BitmapEx>> IconCache;
+    typedef std::unordered_map<OUString, std::pair<bool,BitmapEx>> IconCache;
+    typedef std::unordered_map<sal_Int32, std::unique_ptr<IconCache>> ScaledIconCache;
     typedef std::unordered_map<OUString, OUString> IconLinkHash;
 
     struct IconSet
     {
         OUString maURL;
         css::uno::Reference<css::container::XNameAccess> maNameAccess;
-        IconCache maIconCache;
+        ScaledIconCache maScaledIconCaches;
         IconLinkHash maLinkHash;
 
         IconSet()
@@ -128,6 +133,8 @@ private:
 
     void createStyle();
 
+    IconCache &getIconCache(ImageRequestParameters& rParameters);
+
     bool iconCacheLookup(ImageRequestParameters& rParameters);
 
     bool findImage(std::vector<OUString> const & rPaths, ImageRequestParameters& rParameters);
diff --git a/vcl/source/image/ImageTree.cxx b/vcl/source/image/ImageTree.cxx
index 2e20183b0da5..826671e110ec 100644
--- a/vcl/source/image/ImageTree.cxx
+++ b/vcl/source/image/ImageTree.cxx
@@ -37,9 +37,17 @@ std::shared_ptr<SvMemoryStream> ImageTree::getImageStream(OUString const & rName
 
 bool ImageTree::loadImage(OUString const & rName, OUString const & rStyle,
                           BitmapEx & rBitmap, bool bLocalized,
+                          sal_Int32 nScalePercentage,
                           const ImageLoadFlags eFlags)
 {
-    return mpImplImageTree->loadImage(rName, rStyle, rBitmap, bLocalized, eFlags);
+    return mpImplImageTree->loadImage(rName, rStyle, rBitmap, bLocalized, eFlags, nScalePercentage);
+}
+
+bool ImageTree::loadImage(OUString const & rName, OUString const & rStyle,
+                          BitmapEx & rBitmap, bool bLocalized,
+                          const ImageLoadFlags eFlags)
+{
+    return loadImage(rName, rStyle, rBitmap, bLocalized, -1, eFlags);
 }
 
 css::uno::Reference<css::container::XNameAccess> const & ImageTree::getNameAccess()
diff --git a/vcl/source/image/ImplImageTree.cxx b/vcl/source/image/ImplImageTree.cxx
index 1fed00908365..22fd194b3a8d 100644
--- a/vcl/source/image/ImplImageTree.cxx
+++ b/vcl/source/image/ImplImageTree.cxx
@@ -69,6 +69,8 @@ sal_Int32 ImageRequestParameters::scalePercentage()
     sal_Int32 aScalePercentage = 100;
     if (!(meFlags & ImageLoadFlags::IgnoreScalingFactor))
         aScalePercentage = Application::GetDefaultDevice()->GetDPIScalePercentage();
+    else if (mnScalePercentage > 0)
+        aScalePercentage = mnScalePercentage;
     return aScalePercentage;
 }
 
@@ -96,17 +98,17 @@ OUString createPath(OUString const & name, sal_Int32 pos, OUString const & local
     return name.copy(0, pos + 1) + locale + name.copy(pos);
 }
 
-OUString getIconCacheUrl(OUString const & sStyle, OUString const & sVariant, OUString const & sName)
+OUString getIconCacheUrl(OUString const & sVariant, ImageRequestParameters const & rParameters)
 {
     OUString sUrl("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/cache/");
-    sUrl += sStyle + "/" + sVariant + "/" + sName;
+    sUrl += rParameters.msStyle + "/" + sVariant + "/" + rParameters.msName;
     rtl::Bootstrap::expandMacros(sUrl);
     return sUrl;
 }
 
-OUString createIconCacheUrl(OUString const & sStyle, OUString const & sVariant, OUString const & sName)
+OUString createIconCacheUrl(OUString const & sVariant, ImageRequestParameters const & rParameters)
 {
-    OUString sUrl(getIconCacheUrl(sStyle, sVariant, sName));
+    OUString sUrl(getIconCacheUrl(sVariant, rParameters));
     OUString sDir = sUrl.copy(0, sUrl.lastIndexOf('/'));
     osl::Directory::createPath(sDir);
     return sUrl;
@@ -315,14 +317,15 @@ OUString ImplImageTree::fallbackStyle(const OUString& rsStyle)
     return sResult;
 }
 
-bool ImplImageTree::loadImage(OUString const & rName, OUString const & rStyle, BitmapEx & rBitmap, bool localized, const ImageLoadFlags eFlags)
+bool ImplImageTree::loadImage(OUString const & rName, OUString const & rStyle, BitmapEx & rBitmap, bool localized,
+                              const ImageLoadFlags eFlags, sal_Int32 nScalePercentage)
 {
     OUString aCurrentStyle(rStyle);
     while (!aCurrentStyle.isEmpty())
     {
         try
         {
-            ImageRequestParameters aParameters(rName, aCurrentStyle, rBitmap, localized, eFlags);
+            ImageRequestParameters aParameters(rName, aCurrentStyle, rBitmap, localized, eFlags, nScalePercentage);
             if (doLoadImage(aParameters))
                 return true;
         }
@@ -349,7 +352,7 @@ static OUString createVariant(ImageRequestParameters& rParameters)
 
 static bool loadDiskCachedVersion(OUString const & sVariant, ImageRequestParameters& rParameters)
 {
-    OUString sUrl(getIconCacheUrl(rParameters.msStyle, sVariant, rParameters.msName));
+    OUString sUrl(getIconCacheUrl(sVariant, rParameters));
     if (!urlExists(sUrl))
         return false;
     SvFileStream aFileStream(sUrl, StreamMode::READ);
@@ -361,7 +364,7 @@ static bool loadDiskCachedVersion(OUString const & sVariant, ImageRequestParamet
 
 static void cacheBitmapToDisk(OUString const & sVariant, ImageRequestParameters const & rParameters)
 {
-    OUString sUrl(createIconCacheUrl(rParameters.msStyle, sVariant, rParameters.msName));
+    OUString sUrl(createIconCacheUrl(sVariant, rParameters));
     vcl::PNGWriter aWriter(rParameters.mrBitmap);
     try
     {
@@ -382,9 +385,7 @@ bool ImplImageTree::doLoadImage(ImageRequestParameters& rParameters)
 
     OUString aVariant = createVariant(rParameters);
     if (loadDiskCachedVersion(aVariant, rParameters))
-    {
         return true;
-    }
 
     if (!rParameters.mrBitmap.IsEmpty())
         rParameters.mrBitmap.SetEmpty();
@@ -414,7 +415,7 @@ bool ImplImageTree::doLoadImage(ImageRequestParameters& rParameters)
         {
             cacheBitmapToDisk(aVariant, rParameters);
         }
-        getCurrentIconSet().maIconCache[rParameters.msName] = std::make_pair(rParameters.mbLocalized, rParameters.mrBitmap);
+        getIconCache(rParameters)[rParameters.msName] = std::make_pair(rParameters.mbLocalized, rParameters.mrBitmap);
     }
 
     return bFound;
@@ -482,9 +483,20 @@ void ImplImageTree::createStyle()
     loadImageLinks();
 }
 
+/// Find an icon cache for the right scale factor
+ImplImageTree::IconCache &ImplImageTree::getIconCache(ImageRequestParameters& rParameters)
+{
+    IconSet &rSet = getCurrentIconSet();
+    auto it = rSet.maScaledIconCaches.find(rParameters.mnScalePercentage);
+    if ( it != rSet.maScaledIconCaches.end() )
+        return *it->second.get();
+    rSet.maScaledIconCaches[rParameters.mnScalePercentage] = std::unique_ptr<IconCache>(new IconCache);
+    return *rSet.maScaledIconCaches[rParameters.mnScalePercentage].get();
+}
+
 bool ImplImageTree::iconCacheLookup(ImageRequestParameters& rParameters)
 {
-    IconCache& rIconCache = getCurrentIconSet().maIconCache;
+    IconCache& rIconCache = getIconCache(rParameters);
 
     IconCache::iterator i(rIconCache.find(getRealImageName(rParameters.msName)));
     if (i != rIconCache.end() && i->second.first == rParameters.mbLocalized)
@@ -513,6 +525,7 @@ bool ImplImageTree::findImage(std::vector<OUString> const & rPaths, ImageRequest
             (void)ok; // prevent unused warning in release build
 
             loadImageFromStream(wrapStream(aStream), rPath, rParameters);
+
             return true;
         }
     }


More information about the Libreoffice-commits mailing list