Kaydet (Commit) 8307ecbd authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

cache file based widget images and draw commands

It is wasteful to parse svg icons all the time so lets cache the
result when this make sense in a LRU map.

Change-Id: I95cc317c9301138a9e384d270223ba147a123e59
Reviewed-on: https://gerrit.libreoffice.org/69055
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 805b15ce)
üst 8a828146
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
#include "ControlCacheKey.hxx" #include "ControlCacheKey.hxx"
#include "schedulerimpl.hxx" #include "schedulerimpl.hxx"
#include <basegfx/DrawCommands.hxx>
struct ImplPostEventData; struct ImplPostEventData;
struct ImplTimerData; struct ImplTimerData;
...@@ -191,6 +192,9 @@ struct ImplSVGDIData ...@@ -191,6 +192,9 @@ struct ImplSVGDIData
long mnAppFontX = 0; // AppFont X-Numenator for 40/tel Width long mnAppFontX = 0; // AppFont X-Numenator for 40/tel Width
long mnAppFontY = 0; // AppFont Y-Numenator for 80/tel Height long mnAppFontY = 0; // AppFont Y-Numenator for 80/tel Height
bool mbFontSubChanged = false; // true: FontSubstitution was changed between Begin/End bool mbFontSubChanged = false; // true: FontSubstitution was changed between Begin/End
o3tl::lru_map<OUString, BitmapEx> maThemeImageCache = o3tl::lru_map<OUString, BitmapEx>(10);
o3tl::lru_map<OUString, gfx::DrawRoot> maThemeDrawCommandsCache = o3tl::lru_map<OUString, gfx::DrawRoot>(50);
}; };
struct ImplSVWinData struct ImplSVWinData
......
...@@ -701,6 +701,9 @@ void DeInitVCL() ...@@ -701,6 +701,9 @@ void DeInitVCL()
delete pSVData->maGDIData.mpScreenFontCache; delete pSVData->maGDIData.mpScreenFontCache;
pSVData->maGDIData.mpScreenFontCache = nullptr; pSVData->maGDIData.mpScreenFontCache = nullptr;
pSVData->maGDIData.maThemeDrawCommandsCache.clear();
pSVData->maGDIData.maThemeImageCache.clear();
// Deinit Sal // Deinit Sal
if (pSVData->mpDefInst) if (pSVData->mpDefInst)
{ {
......
...@@ -342,9 +342,26 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom ...@@ -342,9 +342,26 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom
nScaleFactor = comphelper::LibreOfficeKit::getDPIScale(); nScaleFactor = comphelper::LibreOfficeKit::getDPIScale();
auto const& rDrawCommand = static_cast<ImageDrawCommand const&>(*pDrawCommand); auto const& rDrawCommand = static_cast<ImageDrawCommand const&>(*pDrawCommand);
SvFileStream aFileStream(rDrawCommand.msSource, StreamMode::READ); auto& rCacheImages = ImplGetSVData()->maGDIData.maThemeImageCache;
OUString rCacheKey = rDrawCommand.msSource + "@" + OUString::number(nScaleFactor);
auto& aIterator = rCacheImages.find(rCacheKey);
BitmapEx aBitmap; BitmapEx aBitmap;
vcl::bitmap::loadFromSvg(aFileStream, "", aBitmap, nScaleFactor); if (aIterator == rCacheImages.end())
{
SvFileStream aFileStream(rDrawCommand.msSource, StreamMode::READ);
vcl::bitmap::loadFromSvg(aFileStream, "", aBitmap, nScaleFactor);
if (!!aBitmap)
{
rCacheImages.insert(std::make_pair(rCacheKey, aBitmap));
}
}
else
{
aBitmap = aIterator->second;
}
long nImageWidth = aBitmap.GetSizePixel().Width(); long nImageWidth = aBitmap.GetSizePixel().Width();
long nImageHeight = aBitmap.GetSizePixel().Height(); long nImageHeight = aBitmap.GetSizePixel().Height();
SalTwoRect aTR(0, 0, nImageWidth, nImageHeight, nX, nY, nImageWidth / nScaleFactor, SalTwoRect aTR(0, 0, nImageWidth, nImageHeight, nX, nY, nImageWidth / nScaleFactor,
...@@ -369,27 +386,46 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom ...@@ -369,27 +386,46 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom
case DrawCommandType::EXTERNAL: case DrawCommandType::EXTERNAL:
{ {
auto const& rDrawCommand = static_cast<ImageDrawCommand const&>(*pDrawCommand); auto const& rDrawCommand = static_cast<ImageDrawCommand const&>(*pDrawCommand);
SvFileStream aFileStream(rDrawCommand.msSource, StreamMode::READ);
uno::Reference<uno::XComponentContext> xContext( auto& rCacheDrawCommands = ImplGetSVData()->maGDIData.maThemeDrawCommandsCache;
comphelper::getProcessComponentContext());
const uno::Reference<graphic::XSvgParser> xSvgParser
= graphic::SvgTools::create(xContext);
std::size_t nSize = aFileStream.remainingSize(); auto& aIterator = rCacheDrawCommands.find(rDrawCommand.msSource);
std::vector<sal_Int8> aBuffer(nSize + 1);
aFileStream.ReadBytes(aBuffer.data(), nSize);
aBuffer[nSize] = 0;
uno::Sequence<sal_Int8> aData(aBuffer.data(), nSize + 1); gfx::DrawRoot aDrawRoot;
uno::Reference<io::XInputStream> aInputStream(
new comphelper::SequenceInputStream(aData));
uno::Any aAny = xSvgParser->getDrawCommands(aInputStream, ""); if (aIterator == rCacheDrawCommands.end())
if (aAny.has<sal_uInt64>()) {
SvFileStream aFileStream(rDrawCommand.msSource, StreamMode::READ);
uno::Reference<uno::XComponentContext> xContext(
comphelper::getProcessComponentContext());
const uno::Reference<graphic::XSvgParser> xSvgParser
= graphic::SvgTools::create(xContext);
std::size_t nSize = aFileStream.remainingSize();
std::vector<sal_Int8> aBuffer(nSize + 1);
aFileStream.ReadBytes(aBuffer.data(), nSize);
aBuffer[nSize] = 0;
uno::Sequence<sal_Int8> aData(aBuffer.data(), nSize + 1);
uno::Reference<io::XInputStream> aInputStream(
new comphelper::SequenceInputStream(aData));
uno::Any aAny = xSvgParser->getDrawCommands(aInputStream, "");
if (aAny.has<sal_uInt64>())
{
auto* pDrawRoot = reinterpret_cast<gfx::DrawRoot*>(aAny.get<sal_uInt64>());
if (pDrawRoot)
{
rCacheDrawCommands.insert(
std::make_pair(rDrawCommand.msSource, *pDrawRoot));
drawFromDrawCommands(*pDrawRoot, rGraphics, nX, nY, nWidth, nHeight);
}
}
}
else
{ {
auto* pDrawRoot = reinterpret_cast<gfx::DrawRoot*>(aAny.get<sal_uInt64>()); drawFromDrawCommands(aIterator->second, rGraphics, nX, nY, nWidth, nHeight);
drawFromDrawCommands(*pDrawRoot, rGraphics, nX, nY, nWidth, nHeight);
} }
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment