Kaydet (Commit) 6a6201e0 authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Jan Holesovsky

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: 's avatarAshod Nakashian <ashnakash@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/69624Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
Tested-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst 9d8003b1
......@@ -111,7 +111,8 @@ bool SdPdfFilter::Import()
const size_t nGraphicContentSize = aPdfData.getLength();
std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]);
memcpy(pGraphicContent.get(), aPdfData.get(), nGraphicContentSize);
GfxLink aGfxLink(std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf);
std::shared_ptr<GfxLink> pGfxLink(std::make_shared<GfxLink>(
std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf));
auto pPdfData = std::make_shared<uno::Sequence<sal_Int8>>(aPdfData);
mrDocument.CreateFirstPages();
......
......@@ -45,7 +45,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;
......@@ -160,7 +160,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;
......
......@@ -1854,7 +1854,7 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
}
if( nStatus == ERRCODE_NONE )
{
rGraphic.SetLink( GfxLink( std::move(pGraphicContent), nGraphicContentSize, eLinkType ) );
rGraphic.SetLink(GfxLink(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
}
}
......
......@@ -115,6 +115,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)
......@@ -124,9 +125,6 @@ ImpGraphic::ImpGraphic(const ImpGraphic& rImpGraphic)
, maGraphicExternalLink(rImpGraphic.maGraphicExternalLink)
, mnPageNumber(rImpGraphic.mnPageNumber)
{
if( rImpGraphic.mpGfxLink )
mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink );
if( rImpGraphic.mpAnimation )
{
mpAnimation = o3tl::make_unique<Animation>( *rImpGraphic.mpAnimation );
......@@ -239,10 +237,7 @@ ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic )
mbSwapOut = rImpGraphic.mbSwapOut;
mpSwapFile = rImpGraphic.mpSwapFile;
mpGfxLink.reset();
if( rImpGraphic.mpGfxLink )
mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink );
mpGfxLink = rImpGraphic.mpGfxLink;
maVectorGraphicData = rImpGraphic.maVectorGraphicData;
mpPdfData = rImpGraphic.mpPdfData;
......@@ -1370,11 +1365,11 @@ bool ImpGraphic::ImplSwapIn( SvStream* xIStm )
return bRet;
}
void ImpGraphic::ImplSetLink( const GfxLink& rGfxLink )
void ImpGraphic::ImplSetLink(const GfxLink& rGfxLink)
{
mpGfxLink = o3tl::make_unique<GfxLink>( rGfxLink );
mpGfxLink = rGfxLink;
if( mpGfxLink->IsNative() )
if (mpGfxLink && mpGfxLink->IsNative())
mpGfxLink->SwapOut();
}
......@@ -1489,7 +1484,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.SetLink( GfxLink() );
aGraphic.SetLink(GfxLink());
if( !rIStm.GetError() && aLink.LoadNative( aGraphic ) )
{
......@@ -1506,7 +1501,7 @@ void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
rImpGraphic.ImplSetPrefSize( aLink.GetPrefSize() );
if( bSetLink )
rImpGraphic.ImplSetLink( aLink );
rImpGraphic.ImplSetLink(aLink);
}
else
{
......
......@@ -846,7 +846,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 &&
......
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