[Libreoffice-commits] core.git: vcl/inc vcl/source
Michael Meeks (via logerrit)
logerrit at kemper.freedesktop.org
Wed Feb 26 19:51:52 UTC 2020
vcl/inc/svdata.hxx | 40 ++++++++++++++++++++++++++-
vcl/source/app/salvtables.cxx | 7 ++--
vcl/source/app/svmain.cxx | 2 -
vcl/source/bitmap/BitmapScaleSuperFilter.cxx | 11 ++++---
4 files changed, 50 insertions(+), 10 deletions(-)
New commits:
commit b4d1c8e884673158277cd20f9fc83b71de69d4c9
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Wed Feb 26 06:59:09 2020 +0000
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Feb 26 20:51:16 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>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89503
Tested-by: Jenkins
diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index cefc8cb124fc..59daa93cca67 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -167,6 +167,44 @@ struct ImplSVAppData
DECL_LINK(VclEventTestingHdl, Timer*, void);
};
+/// 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;
+ }
+ bool operator==(ScaleCacheKey const& rOther) const
+ {
+ return mpBitmap == rOther.mpBitmap && maDestSize == rOther.maDestSize;
+ }
+};
+
+namespace std
+{
+template <> struct hash<ScaleCacheKey>
+{
+ std::size_t operator()(ScaleCacheKey const& k) const noexcept
+ {
+ std::size_t seed = 0;
+ boost::hash_combine(seed, k.mpBitmap);
+ boost::hash_combine(seed, k.maDestSize.getWidth());
+ boost::hash_combine(seed, k.maDestSize.getHeight());
+ return seed;
+ }
+};
+
+} // end std namespace
+
+typedef o3tl::lru_map<ScaleCacheKey, BitmapEx> lru_scale_cache;
+
struct ImplSVGDIData
{
~ImplSVGDIData();
@@ -183,7 +221,7 @@ struct ImplSVGDIData
std::unique_ptr<ImplPrnQueueList> mpPrinterQueueList; // List of all printer queue
std::shared_ptr<PhysicalFontCollection> mxScreenFontList; // Screen-Font-List
std::shared_ptr<ImplFontCache> mxScreenFontCache; // Screen-Font-Cache
- o3tl::lru_map<SalBitmap*, BitmapEx> maScaleCache = o3tl::lru_map<SalBitmap*, BitmapEx>(10); // Cache for scaled images
+ lru_scale_cache maScaleCache = lru_scale_cache(10); // Cache for scaled images
ImplDirectFontSubstitution* mpDirectFontSubst = nullptr; // Font-Substitutions defined in Tools->Options->Fonts
GraphicConverter* mpGrfConverter = nullptr; // Converter for graphics
long mnAppFontX = 0; // AppFont X-Numenator for 40/tel Width
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 0dc8b989f408..943f6f1e0be4 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -137,10 +137,9 @@ 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 ca1818fc20ff..baa881d84e06 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -584,7 +584,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 263b6fdb7f0d..ed10a76a82a9 100644
--- a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
+++ b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
@@ -1016,8 +1016,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());
@@ -1037,13 +1035,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");
}
{
@@ -1188,7 +1191,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