Kaydet (Commit) c8d95cce authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Ashod Nakashian

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>
üst cbd0d1da
......@@ -217,7 +217,7 @@ private:
friend class GraphicObject;
public:
void SetGfxLink(const GfxLink& rGfxLink);
void SetGfxLink(const std::shared_ptr<GfxLink>& rGfxLink);
GfxLink GetGfxLink() const;
bool IsGfxLink() const;
......
......@@ -112,7 +112,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();
......@@ -128,7 +129,7 @@ bool SdPdfFilter::Import()
Graphic aGraphic(aBitmap);
aGraphic.setPdfData(pPdfData);
aGraphic.setPageNumber(nPageNumber);
aGraphic.SetGfxLink(aGfxLink);
aGraphic.SetGfxLink(pGfxLink);
// Create the page and insert the Graphic.
SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard);
......
......@@ -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;
......
......@@ -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));
}
}
......
......@@ -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 );
......
......@@ -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
{
......
......@@ -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 &&
......
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