[Libreoffice-commits] core.git: include/vcl sd/source vcl/inc vcl/source

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Jun 18 00:26:52 UTC 2018


 include/vcl/graph.hxx                |    2 +-
 sd/source/filter/pdf/sdpdffilter.cxx |    5 +++--
 vcl/inc/impgraph.hxx                 |    4 ++--
 vcl/source/filter/graphicfilter.cxx  |    6 +++---
 vcl/source/gdi/graph.cxx             |    2 +-
 vcl/source/gdi/impgraph.cxx          |   19 +++++++------------
 vcl/source/gdi/pdfextoutdevdata.cxx  |    2 +-
 7 files changed, 18 insertions(+), 22 deletions(-)

New commits:
commit c8d95ccecfcd31b720fdff67bbd6acbdceaf2546
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri Jun 8 22:54:48 2018 -0400

    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 at gmail.com>

diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx
index 24c3f4e796a2..ab9713daff9b 100644
--- a/include/vcl/graph.hxx
+++ b/include/vcl/graph.hxx
@@ -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;
 
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 7f58ba6c8d1f..db7af07b58ce 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -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);
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 &&


More information about the Libreoffice-commits mailing list