summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-02-25 09:04:10 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-02-25 10:03:10 +0100
commit570be56b37e4ff105649e604ff4c8a6c368e2e79 (patch)
tree1c27a73f269ce4c7d548f3d2455f9c350ad21182
parentd0487363753960faccb8ba464414e18786dcd915 (diff)
svx: cache PNG export of graphic shapes
One scenario where this is useful is: manipulate a JPEG photo in Online's Impress, e.g. resize it multiple times. Each time we generate an SVG preview of the shape, which includes the PNG export of the bitmap itself. This helps with a desktop CPU: debug:9976:9974: SVGFilter::filter finished in 3422 ms debug:9976:9974: SVGFilter::filter finished in 176 ms But it is meant to help on mobile, too, where writing such a bitmap as PNG takes 16-17 seconds without this. (This works because SVG writes the original bitmap, even if it's scaled. If that invariant will be broken in the future, we still emit correct output, but then the cache will be less useful.) Change-Id: I7204b04efeeb42c6eec67f04dfdb8a4ed50443a9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89377 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--filter/source/svg/svgwriter.cxx58
-rw-r--r--filter/source/svg/svgwriter.hxx2
-rw-r--r--include/svx/svdograf.hxx9
-rw-r--r--include/svx/unoshape.hxx2
-rw-r--r--svx/source/svdraw/svdograf.cxx22
5 files changed, 82 insertions, 11 deletions
diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx
index f70d11200be7..7706e2c26e44 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -34,6 +34,8 @@
#include <xmloff/nmspmap.hxx>
#include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
#include <i18nlangtag/languagetag.hxx>
+#include <svx/unoshape.hxx>
+#include <svx/svdograf.hxx>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XIndexReplace.hpp>
@@ -2684,10 +2686,29 @@ void SVGActionWriter::ImplWriteText( const Point& rPos, const OUString& rText,
}
}
+namespace
+{
+SdrGrafObj* GetSdrGrafObjFromXShape(const css::uno::Reference<css::drawing::XShape>* pShape)
+{
+ if (!pShape)
+ {
+ return nullptr;
+ }
+
+ auto pObject = dynamic_cast<SvxGraphicObject*>(pShape->get());
+ if (!pObject)
+ {
+ return nullptr;
+ }
+
+ return dynamic_cast<SdrGrafObj*>(pObject->GetSdrObject());
+}
+}
void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx,
const Point& rPt, const Size& rSz,
- const Point& rSrcPt, const Size& rSrcSz )
+ const Point& rSrcPt, const Size& rSrcSz,
+ const css::uno::Reference<css::drawing::XShape>* pShape )
{
if( !!rBmpEx )
{
@@ -2702,8 +2723,27 @@ void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx,
{
SvMemoryStream aOStm( 65535, 65535 );
- if( GraphicConverter::Export( aOStm, rBmpEx, ConvertDataFormat::PNG ) == ERRCODE_NONE )
+ bool bCached = false;
+ SdrGrafObj* pGrafObj = nullptr;
+ if (pShape)
{
+ pGrafObj = GetSdrGrafObjFromXShape(pShape);
+ if (pGrafObj && pGrafObj->GetPNGPreviewChecksum() == rBmpEx.GetChecksum())
+ {
+ const std::vector<sal_Int8>& rPreviewData = pGrafObj->GetPNGPreviewData();
+ aOStm.WriteBytes(rPreviewData.data(), rPreviewData.size());
+ bCached = true;
+ }
+ }
+
+ if( bCached || GraphicConverter::Export( aOStm, rBmpEx, ConvertDataFormat::PNG ) == ERRCODE_NONE )
+ {
+ if (!bCached && pGrafObj)
+ {
+ pGrafObj->SetPNGPreviewChecksum(rBmpEx.GetChecksum());
+ pGrafObj->SetPNGPreviewData(aOStm);
+ }
+
Point aPt;
Size aSz;
Sequence< sal_Int8 > aSeq( static_cast<sal_Int8 const *>(aOStm.GetData()), aOStm.Tell() );
@@ -3047,7 +3087,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
const MetaBmpScaleAction* pBmpScaleAction = static_cast<const MetaBmpScaleAction*>(pSubstAct);
ImplWriteBmp( BitmapEx(pBmpScaleAction->GetBitmap()),
pA->GetPoint(), pA->GetSize(),
- Point(), pBmpScaleAction->GetBitmap().GetSizePixel() );
+ Point(), pBmpScaleAction->GetBitmap().GetSizePixel(), pxShape );
}
}
}
@@ -3430,7 +3470,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
ImplWriteBmp( BitmapEx(pA->GetBitmap()),
pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmap().GetSizePixel() ),
- Point(), pA->GetBitmap().GetSizePixel() );
+ Point(), pA->GetBitmap().GetSizePixel(), pxShape );
}
}
break;
@@ -3450,7 +3490,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
{
ImplWriteBmp( BitmapEx(pA->GetBitmap()),
pA->GetPoint(), pA->GetSize(),
- Point(), pA->GetBitmap().GetSizePixel() );
+ Point(), pA->GetBitmap().GetSizePixel(), pxShape );
}
}
}
@@ -3464,7 +3504,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
ImplWriteBmp( BitmapEx(pA->GetBitmap()),
pA->GetDestPoint(), pA->GetDestSize(),
- pA->GetSrcPoint(), pA->GetSrcSize() );
+ pA->GetSrcPoint(), pA->GetSrcSize(), pxShape );
}
}
break;
@@ -3477,7 +3517,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
ImplWriteBmp( pA->GetBitmapEx(),
pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmapEx().GetSizePixel() ),
- Point(), pA->GetBitmapEx().GetSizePixel() );
+ Point(), pA->GetBitmapEx().GetSizePixel(), pxShape );
}
}
break;
@@ -3497,7 +3537,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
{
ImplWriteBmp( pA->GetBitmapEx(),
pA->GetPoint(), pA->GetSize(),
- Point(), pA->GetBitmapEx().GetSizePixel() );
+ Point(), pA->GetBitmapEx().GetSizePixel(), pxShape );
}
}
}
@@ -3511,7 +3551,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
ImplWriteBmp( pA->GetBitmapEx(),
pA->GetDestPoint(), pA->GetDestSize(),
- pA->GetSrcPoint(), pA->GetSrcSize() );
+ pA->GetSrcPoint(), pA->GetSrcSize(), pxShape );
}
}
break;
diff --git a/filter/source/svg/svgwriter.hxx b/filter/source/svg/svgwriter.hxx
index 4a94cee30ae0..065d0585bb88 100644
--- a/filter/source/svg/svgwriter.hxx
+++ b/filter/source/svg/svgwriter.hxx
@@ -340,7 +340,7 @@ private:
void ImplWriteMask( GDIMetaFile& rMtf, const Point& rDestPt, const Size& rDestSize, const Gradient& rGradient, sal_uInt32 nWriteFlags );
void ImplWriteText( const Point& rPos, const OUString& rText, const long* pDXArray, long nWidth );
void ImplWriteText( const Point& rPos, const OUString& rText, const long* pDXArray, long nWidth, Color aTextColor );
- void ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz );
+ void ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz, const css::uno::Reference<css::drawing::XShape>* pShape);
void ImplWriteActions( const GDIMetaFile& rMtf,
sal_uInt32 nWriteFlags,
diff --git a/include/svx/svdograf.hxx b/include/svx/svdograf.hxx
index 8944db82bc2d..098ae70d73a2 100644
--- a/include/svx/svdograf.hxx
+++ b/include/svx/svdograf.hxx
@@ -29,6 +29,7 @@
#include <vcl/GraphicObject.hxx>
#include <svx/svxdllapi.h>
#include <o3tl/typed_flags_set.hxx>
+#include <tools/stream.hxx>
#include <memory>
#include <cstddef>
@@ -122,6 +123,9 @@ private:
void onGraphicChanged();
GDIMetaFile GetMetaFile(GraphicType &rGraphicType) const;
+ BitmapChecksum mnPNGPreviewChecksum = 0;
+ std::vector<sal_Int8> maPNGPreviewData;
+
protected:
// protected destructor
virtual ~SdrGrafObj() override;
@@ -297,6 +301,11 @@ public:
{
return mpQrCode.get();
};
+
+ void SetPNGPreviewChecksum(BitmapChecksum nPNGPreviewChecksum);
+ BitmapChecksum GetPNGPreviewChecksum() const;
+ void SetPNGPreviewData(SvMemoryStream& rPNGPreviewData);
+ const std::vector<sal_Int8>& GetPNGPreviewData() const;
};
#endif // INCLUDED_SVX_SVDOGRAF_HXX
diff --git a/include/svx/unoshape.hxx b/include/svx/unoshape.hxx
index 7c6b60291886..27c767d5e819 100644
--- a/include/svx/unoshape.hxx
+++ b/include/svx/unoshape.hxx
@@ -641,7 +641,7 @@ public:
* *
***********************************************************************/
-class SvxGraphicObject final : public SvxShapeText
+class SVXCORE_DLLPUBLIC SvxGraphicObject final : public SvxShapeText
{
using SvxUnoTextRangeBase::setPropertyValue;
using SvxUnoTextRangeBase::getPropertyValue;
diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx
index 127de6a0c6f5..f7c089d2232e 100644
--- a/svx/source/svdraw/svdograf.cxx
+++ b/svx/source/svdraw/svdograf.cxx
@@ -1276,4 +1276,26 @@ void SdrGrafObj::addCropHandles(SdrHdlList& rTarget) const
rTarget.AddHdl(std::make_unique<SdrCropHdl>(Point(basegfx::fround(aPos.getX()), basegfx::fround(aPos.getY())), SdrHdlKind::LowerRight, fShearX, fRotate));
}
+void SdrGrafObj::SetPNGPreviewChecksum(BitmapChecksum nPNGPreviewChecksum)
+{
+ mnPNGPreviewChecksum = nPNGPreviewChecksum;
+}
+
+BitmapChecksum SdrGrafObj::GetPNGPreviewChecksum() const
+{
+ return mnPNGPreviewChecksum;
+}
+
+void SdrGrafObj::SetPNGPreviewData(SvMemoryStream& rPNGPreviewData)
+{
+ rPNGPreviewData.Seek(0);
+ maPNGPreviewData.resize(rPNGPreviewData.remainingSize());
+ rPNGPreviewData.ReadBytes(maPNGPreviewData.data(), maPNGPreviewData.size());
+}
+
+const std::vector<sal_Int8>& SdrGrafObj::GetPNGPreviewData() const
+{
+ return maPNGPreviewData;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */