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>
This commit is contained in:
parent
cbd0d1da85
commit
c8d95ccecf
@ -217,7 +217,7 @@ private:
|
|||||||
friend class GraphicObject;
|
friend class GraphicObject;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetGfxLink(const GfxLink& rGfxLink);
|
void SetGfxLink(const std::shared_ptr<GfxLink>& rGfxLink);
|
||||||
GfxLink GetGfxLink() const;
|
GfxLink GetGfxLink() const;
|
||||||
bool IsGfxLink() const;
|
bool IsGfxLink() const;
|
||||||
|
|
||||||
|
@ -112,7 +112,8 @@ bool SdPdfFilter::Import()
|
|||||||
const size_t nGraphicContentSize = aPdfData.getLength();
|
const size_t nGraphicContentSize = aPdfData.getLength();
|
||||||
std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]);
|
std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]);
|
||||||
memcpy(pGraphicContent.get(), aPdfData.get(), 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);
|
auto pPdfData = std::make_shared<uno::Sequence<sal_Int8>>(aPdfData);
|
||||||
|
|
||||||
mrDocument.CreateFirstPages();
|
mrDocument.CreateFirstPages();
|
||||||
@ -128,7 +129,7 @@ bool SdPdfFilter::Import()
|
|||||||
Graphic aGraphic(aBitmap);
|
Graphic aGraphic(aBitmap);
|
||||||
aGraphic.setPdfData(pPdfData);
|
aGraphic.setPdfData(pPdfData);
|
||||||
aGraphic.setPageNumber(nPageNumber);
|
aGraphic.setPageNumber(nPageNumber);
|
||||||
aGraphic.SetGfxLink(aGfxLink);
|
aGraphic.SetGfxLink(pGfxLink);
|
||||||
|
|
||||||
// Create the page and insert the Graphic.
|
// Create the page and insert the Graphic.
|
||||||
SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard);
|
SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard);
|
||||||
|
@ -77,7 +77,7 @@ private:
|
|||||||
std::unique_ptr<Animation> mpAnimation;
|
std::unique_ptr<Animation> mpAnimation;
|
||||||
std::shared_ptr<GraphicReader> mpContext;
|
std::shared_ptr<GraphicReader> mpContext;
|
||||||
std::shared_ptr<ImpSwapFile> mpSwapFile;
|
std::shared_ptr<ImpSwapFile> mpSwapFile;
|
||||||
std::unique_ptr<GfxLink> mpGfxLink;
|
std::shared_ptr<GfxLink> mpGfxLink;
|
||||||
GraphicType meType;
|
GraphicType meType;
|
||||||
mutable sal_uLong mnSizeBytes;
|
mutable sal_uLong mnSizeBytes;
|
||||||
bool mbSwapOut;
|
bool mbSwapOut;
|
||||||
@ -210,7 +210,7 @@ private:
|
|||||||
|
|
||||||
bool ImplIsSwapOut() const { return mbSwapOut;}
|
bool ImplIsSwapOut() const { return mbSwapOut;}
|
||||||
bool ImplIsDummyContext() const { return mbDummyContext; }
|
bool ImplIsDummyContext() const { return mbDummyContext; }
|
||||||
void ImplSetLink( const GfxLink& );
|
void ImplSetLink( const std::shared_ptr<GfxLink>& );
|
||||||
GfxLink ImplGetLink();
|
GfxLink ImplGetLink();
|
||||||
bool ImplIsLink() const;
|
bool ImplIsLink() const;
|
||||||
|
|
||||||
|
@ -1429,7 +1429,7 @@ void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGra
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rContext.m_nStatus == ERRCODE_NONE)
|
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)
|
if (rContext.m_nStatus != ERRCODE_NONE)
|
||||||
@ -1661,7 +1661,7 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream)
|
|||||||
SvMemoryStream aMemoryStream(pGraphicContent.get(), nGraphicContentSize, StreamMode::READ);
|
SvMemoryStream aMemoryStream(pGraphicContent.get(), nGraphicContentSize, StreamMode::READ);
|
||||||
bAnimated = IsGIFAnimated(aMemoryStream);
|
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);
|
aGraphic.ImplGetImpGraphic()->ImplSetPrepared(bAnimated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2090,7 +2090,7 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
|
|||||||
}
|
}
|
||||||
if( nStatus == ERRCODE_NONE )
|
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();
|
return mxImpGraphic->ImplIsDummyContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphic::SetGfxLink( const GfxLink& rGfxLink )
|
void Graphic::SetGfxLink( const std::shared_ptr<GfxLink>& rGfxLink )
|
||||||
{
|
{
|
||||||
ImplTestRefCount();
|
ImplTestRefCount();
|
||||||
mxImpGraphic->ImplSetLink( rGfxLink );
|
mxImpGraphic->ImplSetLink( rGfxLink );
|
||||||
|
@ -191,6 +191,7 @@ ImpGraphic::ImpGraphic(const ImpGraphic& rImpGraphic)
|
|||||||
, maSwapInfo(rImpGraphic.maSwapInfo)
|
, maSwapInfo(rImpGraphic.maSwapInfo)
|
||||||
, mpContext(rImpGraphic.mpContext)
|
, mpContext(rImpGraphic.mpContext)
|
||||||
, mpSwapFile(rImpGraphic.mpSwapFile)
|
, mpSwapFile(rImpGraphic.mpSwapFile)
|
||||||
|
, mpGfxLink(rImpGraphic.mpGfxLink)
|
||||||
, meType(rImpGraphic.meType)
|
, meType(rImpGraphic.meType)
|
||||||
, mnSizeBytes(rImpGraphic.mnSizeBytes)
|
, mnSizeBytes(rImpGraphic.mnSizeBytes)
|
||||||
, mbSwapOut(rImpGraphic.mbSwapOut)
|
, mbSwapOut(rImpGraphic.mbSwapOut)
|
||||||
@ -202,9 +203,6 @@ ImpGraphic::ImpGraphic(const ImpGraphic& rImpGraphic)
|
|||||||
, mbPrepared (rImpGraphic.mbPrepared)
|
, mbPrepared (rImpGraphic.mbPrepared)
|
||||||
, mnPageNumber(rImpGraphic.mnPageNumber)
|
, mnPageNumber(rImpGraphic.mnPageNumber)
|
||||||
{
|
{
|
||||||
if( rImpGraphic.mpGfxLink )
|
|
||||||
mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink );
|
|
||||||
|
|
||||||
if( rImpGraphic.mpAnimation )
|
if( rImpGraphic.mpAnimation )
|
||||||
{
|
{
|
||||||
mpAnimation = o3tl::make_unique<Animation>( *rImpGraphic.mpAnimation );
|
mpAnimation = o3tl::make_unique<Animation>( *rImpGraphic.mpAnimation );
|
||||||
@ -345,10 +343,7 @@ ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic )
|
|||||||
mpSwapFile = rImpGraphic.mpSwapFile;
|
mpSwapFile = rImpGraphic.mpSwapFile;
|
||||||
mbPrepared = rImpGraphic.mbPrepared;
|
mbPrepared = rImpGraphic.mbPrepared;
|
||||||
|
|
||||||
mpGfxLink.reset();
|
mpGfxLink = rImpGraphic.mpGfxLink;
|
||||||
|
|
||||||
if( rImpGraphic.mpGfxLink )
|
|
||||||
mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink );
|
|
||||||
|
|
||||||
maVectorGraphicData = rImpGraphic.maVectorGraphicData;
|
maVectorGraphicData = rImpGraphic.maVectorGraphicData;
|
||||||
mpPdfData = rImpGraphic.mpPdfData;
|
mpPdfData = rImpGraphic.mpPdfData;
|
||||||
@ -1642,13 +1637,13 @@ bool ImpGraphic::ImplSwapIn( SvStream* xIStm )
|
|||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImpGraphic::ImplSetLink( const GfxLink& rGfxLink )
|
void ImpGraphic::ImplSetLink(const std::shared_ptr<GfxLink>& rGfxLink)
|
||||||
{
|
{
|
||||||
ensureAvailable();
|
ensureAvailable();
|
||||||
|
|
||||||
mpGfxLink = o3tl::make_unique<GfxLink>( rGfxLink );
|
mpGfxLink = rGfxLink;
|
||||||
|
|
||||||
if( mpGfxLink->IsNative() )
|
if (mpGfxLink && mpGfxLink->IsNative())
|
||||||
mpGfxLink->SwapOut();
|
mpGfxLink->SwapOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1769,7 +1764,7 @@ void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
|
|||||||
|
|
||||||
// set dummy link to avoid creation of additional link after filtering;
|
// set dummy link to avoid creation of additional link after filtering;
|
||||||
// we set a default link to avoid unnecessary swapping of native data
|
// 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 ) )
|
if( !rIStm.GetError() && aLink.LoadNative( aGraphic ) )
|
||||||
{
|
{
|
||||||
@ -1786,7 +1781,7 @@ void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
|
|||||||
rImpGraphic.ImplSetPrefSize( aLink.GetPrefSize() );
|
rImpGraphic.ImplSetPrefSize( aLink.GetPrefSize() );
|
||||||
|
|
||||||
if( bSetLink )
|
if( bSetLink )
|
||||||
rImpGraphic.ImplSetLink( aLink );
|
rImpGraphic.ImplSetLink(std::make_shared<GfxLink>(aLink));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -848,7 +848,7 @@ bool PDFExtOutDevData::HasAdequateCompression( const Graphic &rGraphic,
|
|||||||
// 4 means CMYK, which is not handled.
|
// 4 means CMYK, which is not handled.
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Size aSize = rGraphic.GetSizePixel();
|
const Size aSize = rGraphic.GetSizePixel();
|
||||||
|
|
||||||
// small items better off as PNG anyway
|
// small items better off as PNG anyway
|
||||||
if ( aSize.Width() < 32 &&
|
if ( aSize.Width() < 32 &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user