summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-08 22:54:48 -0400
committerAshod Nakashian <ashnakash@gmail.com>2018-06-18 02:26:27 +0200
commitc8d95ccecfcd31b720fdff67bbd6acbdceaf2546 (patch)
tree7309ba29c7ded6c00015fa1254bd10f2d92c1dea /vcl
parentcbd0d1da85a7ae6b35023274c7267872b3d920e7 (diff)
vcl: share GfxLink
When importing PDF as images, we store the PDF stream in the GfxLink. For large PDFs storing a copy of the full PDF with each page is overkill. For example a 10MB PDF with 200 pages will consume 2GB of memory! Change-Id: I99913514cf5c562683080bc817668095bee69427 Reviewed-on: https://gerrit.libreoffice.org/55571 Tested-by: Jenkins Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/impgraph.hxx4
-rw-r--r--vcl/source/filter/graphicfilter.cxx6
-rw-r--r--vcl/source/gdi/graph.cxx2
-rw-r--r--vcl/source/gdi/impgraph.cxx19
-rw-r--r--vcl/source/gdi/pdfextoutdevdata.cxx2
5 files changed, 14 insertions, 19 deletions
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index 3d63d1ed04d8..f24c6fe34255 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -77,7 +77,7 @@ private:
std::unique_ptr<Animation> mpAnimation;
std::shared_ptr<GraphicReader> mpContext;
std::shared_ptr<ImpSwapFile> mpSwapFile;
- std::unique_ptr<GfxLink> mpGfxLink;
+ std::shared_ptr<GfxLink> mpGfxLink;
GraphicType meType;
mutable sal_uLong mnSizeBytes;
bool mbSwapOut;
@@ -210,7 +210,7 @@ private:
bool ImplIsSwapOut() const { return mbSwapOut;}
bool ImplIsDummyContext() const { return mbDummyContext; }
- void ImplSetLink( const GfxLink& );
+ void ImplSetLink( const std::shared_ptr<GfxLink>& );
GfxLink ImplGetLink();
bool ImplIsLink() const;
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index f713264cacfb..e26dc197c004 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1429,7 +1429,7 @@ void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGra
}
if (rContext.m_nStatus == ERRCODE_NONE)
- rContext.m_pGraphic->SetGfxLink(GfxLink(std::move(pGraphicContent), nGraphicContentSize, rContext.m_eLinkType));
+ rContext.m_pGraphic->SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, rContext.m_eLinkType));
}
if (rContext.m_nStatus != ERRCODE_NONE)
@@ -1661,7 +1661,7 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream)
SvMemoryStream aMemoryStream(pGraphicContent.get(), nGraphicContentSize, StreamMode::READ);
bAnimated = IsGIFAnimated(aMemoryStream);
}
- aGraphic.SetGfxLink(GfxLink(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
+ aGraphic.SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
aGraphic.ImplGetImpGraphic()->ImplSetPrepared(bAnimated);
}
}
@@ -2090,7 +2090,7 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
}
if( nStatus == ERRCODE_NONE )
{
- rGraphic.SetGfxLink( GfxLink( std::move(pGraphicContent), nGraphicContentSize, eLinkType ) );
+ rGraphic.SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
}
}
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index 52e4e9e74ae8..0b2c043572db 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -515,7 +515,7 @@ bool Graphic::IsDummyContext()
return mxImpGraphic->ImplIsDummyContext();
}
-void Graphic::SetGfxLink( const GfxLink& rGfxLink )
+void Graphic::SetGfxLink( const std::shared_ptr<GfxLink>& rGfxLink )
{
ImplTestRefCount();
mxImpGraphic->ImplSetLink( rGfxLink );
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 87a7bd64a398..792e46d27f27 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -191,6 +191,7 @@ ImpGraphic::ImpGraphic(const ImpGraphic& rImpGraphic)
, maSwapInfo(rImpGraphic.maSwapInfo)
, mpContext(rImpGraphic.mpContext)
, mpSwapFile(rImpGraphic.mpSwapFile)
+ , mpGfxLink(rImpGraphic.mpGfxLink)
, meType(rImpGraphic.meType)
, mnSizeBytes(rImpGraphic.mnSizeBytes)
, mbSwapOut(rImpGraphic.mbSwapOut)
@@ -202,9 +203,6 @@ ImpGraphic::ImpGraphic(const ImpGraphic& rImpGraphic)
, mbPrepared (rImpGraphic.mbPrepared)
, mnPageNumber(rImpGraphic.mnPageNumber)
{
- if( rImpGraphic.mpGfxLink )
- mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink );
-
if( rImpGraphic.mpAnimation )
{
mpAnimation = o3tl::make_unique<Animation>( *rImpGraphic.mpAnimation );
@@ -345,10 +343,7 @@ ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic )
mpSwapFile = rImpGraphic.mpSwapFile;
mbPrepared = rImpGraphic.mbPrepared;
- mpGfxLink.reset();
-
- if( rImpGraphic.mpGfxLink )
- mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink );
+ mpGfxLink = rImpGraphic.mpGfxLink;
maVectorGraphicData = rImpGraphic.maVectorGraphicData;
mpPdfData = rImpGraphic.mpPdfData;
@@ -1642,13 +1637,13 @@ bool ImpGraphic::ImplSwapIn( SvStream* xIStm )
return bRet;
}
-void ImpGraphic::ImplSetLink( const GfxLink& rGfxLink )
+void ImpGraphic::ImplSetLink(const std::shared_ptr<GfxLink>& rGfxLink)
{
ensureAvailable();
- mpGfxLink = o3tl::make_unique<GfxLink>( rGfxLink );
+ mpGfxLink = rGfxLink;
- if( mpGfxLink->IsNative() )
+ if (mpGfxLink && mpGfxLink->IsNative())
mpGfxLink->SwapOut();
}
@@ -1769,7 +1764,7 @@ void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
// set dummy link to avoid creation of additional link after filtering;
// we set a default link to avoid unnecessary swapping of native data
- aGraphic.SetGfxLink( GfxLink() );
+ aGraphic.SetGfxLink(std::make_shared<GfxLink>());
if( !rIStm.GetError() && aLink.LoadNative( aGraphic ) )
{
@@ -1786,7 +1781,7 @@ void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
rImpGraphic.ImplSetPrefSize( aLink.GetPrefSize() );
if( bSetLink )
- rImpGraphic.ImplSetLink( aLink );
+ rImpGraphic.ImplSetLink(std::make_shared<GfxLink>(aLink));
}
else
{
diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx
index 7e0f06c8deb9..f486584f9103 100644
--- a/vcl/source/gdi/pdfextoutdevdata.cxx
+++ b/vcl/source/gdi/pdfextoutdevdata.cxx
@@ -848,7 +848,7 @@ bool PDFExtOutDevData::HasAdequateCompression( const Graphic &rGraphic,
// 4 means CMYK, which is not handled.
return false;
- Size aSize = rGraphic.GetSizePixel();
+ const Size aSize = rGraphic.GetSizePixel();
// small items better off as PNG anyway
if ( aSize.Width() < 32 &&