[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - vcl/inc vcl/source

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Wed Feb 26 09:06:35 UTC 2020


 vcl/inc/svdata.hxx                           |   31 ++++++++++++++++++++++++++-
 vcl/source/app/salvtables.cxx                |    4 +--
 vcl/source/app/svmain.cxx                    |    2 -
 vcl/source/bitmap/BitmapScaleSuperFilter.cxx |   11 ++++++---
 4 files changed, 40 insertions(+), 8 deletions(-)

New commits:
commit 4d50456f1c8a54095c136ca14114e38a78f90c09
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Wed Feb 26 06:59:09 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Wed Feb 26 10:01:31 2020 +0100

    lru_scale_cache - cache the same bitmap at multiple scales.
    
    Helps accelerate different views at different scales, as well as
    document / image thumbnailing on save, as well as stray views that
    can get rendered behind the scenes at odd scales on mobile.
    
    Each scale + bitmap combination is another key in the LRU table.
    
    Change-Id: Id82ce2e4180608082c9ca16fad35bba9e8c2e81a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89497
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index 1fae7681f8e7..45d9bee12955 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -177,7 +177,36 @@ struct ImplSVAppData
     DECL_LINK(VclEventTestingHdl, Timer*, void);
 };
 
-typedef o3tl::lru_map<SalBitmap*, BitmapEx> lru_scale_cache;
+/// Cache multiple scalings for the same bitmap
+struct ScaleCacheKey {
+    SalBitmap *mpBitmap;
+    Size       maDestSize;
+    ScaleCacheKey(SalBitmap *pBitmap, const Size &aDestSize)
+    {
+        mpBitmap = pBitmap;
+        maDestSize = aDestSize;
+    }
+    ScaleCacheKey(const ScaleCacheKey &key)
+    {
+        mpBitmap = key.mpBitmap;
+        maDestSize = key.maDestSize;
+    }
+    struct KeyHash {
+        std::size_t operator()(const ScaleCacheKey& k) const
+        {
+            return ((std::size_t) k.mpBitmap) ^ k.maDestSize.getWidth() ^
+                    (k.maDestSize.getHeight() << 16);
+        }
+    };
+    struct KeyEqual {
+        bool operator()(const ScaleCacheKey& l, const ScaleCacheKey& r) const
+        {
+            return l.mpBitmap == r.mpBitmap && l.maDestSize == r.maDestSize;
+        }
+    };
+};
+
+typedef o3tl::lru_map<ScaleCacheKey, BitmapEx, ScaleCacheKey::KeyHash, ScaleCacheKey::KeyEqual> lru_scale_cache;
 
 struct ImplSVGDIData
 {
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 856f6745b300..55ceb47ee7f0 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -144,8 +144,8 @@ void SalBitmap::DropScaledCache()
     if (ImplSVData* pSVData = ImplGetSVData())
     {
         auto& rCache = pSVData->maGDIData.maScaleCache;
-        rCache.remove_if([this] (const o3tl::lru_map<SalBitmap*, BitmapEx>::key_value_pair_t& rKeyValuePair)
-                         { return rKeyValuePair.first == this; });
+        rCache.remove_if([this] (const lru_scale_cache::key_value_pair_t& rKeyValuePair)
+                         { return rKeyValuePair.first.mpBitmap == this; });
     }
 }
 
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 74b7fa6a0789..14feb2b103fc 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -583,7 +583,7 @@ void DeInitVCL()
 
     pSVData->maGDIData.mxScreenFontList.reset();
     pSVData->maGDIData.mxScreenFontCache.reset();
-    pSVData->maGDIData.maScaleCache.remove_if([](const o3tl::lru_map<SalBitmap*, BitmapEx>::key_value_pair_t&)
+    pSVData->maGDIData.maScaleCache.remove_if([](const lru_scale_cache::key_value_pair_t&)
                                                 { return true; });
 
     pSVData->maGDIData.maThemeDrawCommandsCache.clear();
diff --git a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
index 14b18e9f7a02..ce5a968379fa 100644
--- a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
+++ b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
@@ -936,8 +936,6 @@ BitmapScaleSuperFilter::~BitmapScaleSuperFilter()
 BitmapEx BitmapScaleSuperFilter::execute(BitmapEx const& rBitmap) const
 {
     Bitmap aBitmap(rBitmap.GetBitmap());
-    SalBitmap* pKey = aBitmap.ImplGetSalBitmap().get();
-
     bool bRet = false;
 
     const Size aSizePix(rBitmap.GetSizePixel());
@@ -957,13 +955,18 @@ BitmapEx BitmapScaleSuperFilter::execute(BitmapEx const& rBitmap) const
         return BitmapEx();
 
     // check cache for a previously scaled version of this
+    ScaleCacheKey aKey(aBitmap.ImplGetSalBitmap().get(),
+                       Size(nDstW, nDstH));
+
     ImplSVData* pSVData = ImplGetSVData();
     auto& rCache = pSVData->maGDIData.maScaleCache;
-    auto aFind = rCache.find(pKey);
+    auto aFind = rCache.find(aKey);
     if (aFind != rCache.end())
     {
         if (aFind->second.GetSizePixel().Width() == nDstW && aFind->second.GetSizePixel().Height() == nDstH)
             return aFind->second;
+        else
+            SAL_WARN("vcl.gdi", "Error: size mismatch in scale cache");
     }
 
     {
@@ -1090,7 +1093,7 @@ BitmapEx BitmapScaleSuperFilter::execute(BitmapEx const& rBitmap) const
         tools::Rectangle aRect(Point(0, 0), Point(nDstW, nDstH));
         aBitmap.Crop(aRect);
         BitmapEx aRet(aBitmap);
-        rCache.insert(std::make_pair(pKey, aRet));
+        rCache.insert(std::make_pair(aKey, aRet));
         return aRet;
     }
 


More information about the Libreoffice-commits mailing list