filter/source/svg/svgwriter.cxx | 58 +++++++++++++++++++++++++++++++++------- filter/source/svg/svgwriter.hxx | 2 - include/svx/svdograf.hxx | 9 ++++++ include/svx/unoshape.hxx | 2 - svx/source/svdraw/svdograf.cxx | 22 +++++++++++++++ 5 files changed, 82 insertions(+), 11 deletions(-)
New commits: commit 22394a468eb8d594501e443bdb84608b6552a8a1 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Feb 25 09:04:10 2020 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Feb 25 10:59:18 2020 +0100 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.) Conflicts: filter/source/svg/svgwriter.cxx include/svx/svdograf.hxx include/svx/unoshape.hxx Change-Id: I7204b04efeeb42c6eec67f04dfdb8a4ed50443a9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89411 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index 1030c041ff1c..956651e41d01 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -30,6 +30,8 @@ #include <tools/helpers.hxx> #include <xmloff/unointerfacetouniqueidentifiermapper.hxx> #include <sax/tools/converter.hxx> +#include <svx/unoshape.hxx> +#include <svx/svdograf.hxx> #include <memory> @@ -2675,10 +2677,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 ) { @@ -2693,8 +2714,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() ); @@ -3038,7 +3078,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 ); } } } @@ -3421,7 +3461,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; @@ -3441,7 +3481,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, { ImplWriteBmp( BitmapEx(pA->GetBitmap()), pA->GetPoint(), pA->GetSize(), - Point(), pA->GetBitmap().GetSizePixel() ); + Point(), pA->GetBitmap().GetSizePixel(), pxShape ); } } } @@ -3455,7 +3495,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; @@ -3468,7 +3508,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; @@ -3488,7 +3528,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, { ImplWriteBmp( pA->GetBitmapEx(), pA->GetPoint(), pA->GetSize(), - Point(), pA->GetBitmapEx().GetSizePixel() ); + Point(), pA->GetBitmapEx().GetSizePixel(), pxShape ); } } } @@ -3502,7 +3542,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 68339d2a43c2..687f6cae5676 100644 --- a/filter/source/svg/svgwriter.hxx +++ b/filter/source/svg/svgwriter.hxx @@ -360,7 +360,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 c3e2ae0c1874..966cb3893b9b 100644 --- a/include/svx/svdograf.hxx +++ b/include/svx/svdograf.hxx @@ -28,6 +28,7 @@ #include <vcl/GraphicObject.hxx> #include <svx/svxdllapi.h> #include <o3tl/typed_flags_set.hxx> +#include <tools/stream.hxx> namespace sdr { @@ -121,6 +122,9 @@ private: void onGraphicChanged(); GDIMetaFile GetMetaFile(GraphicType &rGraphicType) const; + BitmapChecksum mnPNGPreviewChecksum = 0; + std::vector<sal_Int8> maPNGPreviewData; + protected: // protected destructor virtual ~SdrGrafObj() override; @@ -283,6 +287,11 @@ public: }; bool isSignatureLineSigned() const { return mbSignatureLineIsSigned; }; void setSignatureLineIsSigned(bool bIsSigned) { mbSignatureLineIsSigned = bIsSigned; } + + 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 60917bf7d893..9b7dff1eb991 100644 --- a/include/svx/unoshape.hxx +++ b/include/svx/unoshape.hxx @@ -640,7 +640,7 @@ public: * * ***********************************************************************/ -class SvxGraphicObject : public SvxShapeText +class SVX_DLLPUBLIC SvxGraphicObject : public SvxShapeText { protected: using SvxUnoTextRangeBase::setPropertyValue; diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx index 0e4413b3764f..b68aec25b2a3 100644 --- a/svx/source/svdraw/svdograf.cxx +++ b/svx/source/svdraw/svdograf.cxx @@ -1265,4 +1265,26 @@ void SdrGrafObj::addCropHandles(SdrHdlList& rTarget) const rTarget.AddHdl(o3tl::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: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits