diff options
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/svdata.hxx | 40 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 7 | ||||
-rw-r--r-- | vcl/source/app/svmain.cxx | 2 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapScaleSuperFilter.cxx | 11 |
4 files changed, 50 insertions, 10 deletions
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; } |