include/vcl/graph.hxx                |    1 +
 sd/source/filter/pdf/sdpdffilter.cxx |    4 ++--
 vcl/inc/impgraph.hxx                 |    3 ++-
 vcl/source/gdi/graph.cxx             |    6 ++++++
 vcl/source/gdi/impgraph.cxx          |   30 +++++++++++++++++++++++++-----
 5 files changed, 36 insertions(+), 8 deletions(-)

New commits:
commit 121052be218f15d81772a1cbb2208189563a8aa6
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Thu Jun 21 21:33:56 2018 +0200

    pdfium: Share the GfxLink for PDF files.
    
    Partially based on work by Ashod Nakashian, thanks!
    
    Change-Id: Id7e8c4543368b0caf3e459abaff8c53997779c83
    Reviewed-on: https://gerrit.libreoffice.org/56265
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx
index 1902da49d60f..e7e1708e5c26 100644
--- a/include/vcl/graph.hxx
+++ b/include/vcl/graph.hxx
@@ -211,6 +211,7 @@ private:
 
 public:
     void            SetLink( const GfxLink& );
+    void            SetSharedLink(const std::shared_ptr<GfxLink>& pGfxLink);
     GfxLink         GetLink() const;
     bool            IsLink() const;
 
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx 
b/sd/source/filter/pdf/sdpdffilter.cxx
index 01e6ee5623de..8ca237fd6345 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -111,7 +111,7 @@ 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();
@@ -127,7 +127,7 @@ bool SdPdfFilter::Import()
         Graphic aGraphic(aBitmap);
         aGraphic.setPdfData(pPdfData);
         aGraphic.setPageNumber(nPageNumber);
-        aGraphic.SetLink(aGfxLink);
+        aGraphic.SetSharedLink(pGfxLink);
         aGraphic.setOriginURL(aFileName);
 
         // Create the page and insert the Graphic.
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index 33b591a81a6c..80a12e20d124 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -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;
@@ -158,6 +158,7 @@ private:
     bool                ImplIsSwapOut() const { return mbSwapOut;}
     bool                ImplIsDummyContext() const { return mbDummyContext; }
     void                ImplSetLink( const GfxLink& );
+    void                ImplSetSharedLink(const std::shared_ptr<GfxLink>& 
pGfxLink);
     GfxLink             ImplGetLink();
     bool                ImplIsLink() const;
 
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index cbdf5df56ea5..cbf28e755c8f 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -552,6 +552,12 @@ void Graphic::SetLink( const GfxLink& rGfxLink )
     mxImpGraphic->ImplSetLink( rGfxLink );
 }
 
+void Graphic::SetSharedLink(const std::shared_ptr<GfxLink>& pGfxLink)
+{
+    ImplTestRefCount();
+    mxImpGraphic->ImplSetSharedLink(pGfxLink);
+}
+
 GfxLink Graphic::GetLink() const
 {
     return mxImpGraphic->ImplGetLink();
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 798b7c85f745..9332af115ece 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -125,7 +125,12 @@ ImpGraphic::ImpGraphic(const ImpGraphic& rImpGraphic)
     , mnPageNumber(rImpGraphic.mnPageNumber)
 {
     if( rImpGraphic.mpGfxLink )
-        mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink );
+    {
+        if (rImpGraphic.mpGfxLink->GetType() == GfxLinkType::NativePdf)
+            mpGfxLink = rImpGraphic.mpGfxLink;
+        else
+            mpGfxLink = std::make_shared<GfxLink>(*rImpGraphic.mpGfxLink);
+    }
 
     if( rImpGraphic.mpAnimation )
     {
@@ -239,10 +244,17 @@ ImpGraphic& ImpGraphic::operator=( const ImpGraphic& 
rImpGraphic )
         mbSwapOut = rImpGraphic.mbSwapOut;
         mpSwapFile = rImpGraphic.mpSwapFile;
 
-        mpGfxLink.reset();
+        if (rImpGraphic.mpGfxLink)
+        {
+            if (rImpGraphic.mpGfxLink->GetType() == GfxLinkType::NativePdf)
+                mpGfxLink = rImpGraphic.mpGfxLink;
+            else
+            {
+                mpGfxLink.reset();
 
-        if( rImpGraphic.mpGfxLink )
-            mpGfxLink = o3tl::make_unique<GfxLink>( *rImpGraphic.mpGfxLink );
+                mpGfxLink = std::make_shared<GfxLink>(*rImpGraphic.mpGfxLink);
+            }
+        }
 
         maSvgData = rImpGraphic.maSvgData;
         mpPdfData = rImpGraphic.mpPdfData;
@@ -1347,12 +1359,20 @@ bool ImpGraphic::ImplSwapIn( SvStream* xIStm )
 
 void ImpGraphic::ImplSetLink( const GfxLink& rGfxLink )
 {
-    mpGfxLink = o3tl::make_unique<GfxLink>( rGfxLink );
+    mpGfxLink = std::make_shared<GfxLink>( rGfxLink );
 
     if( mpGfxLink->IsNative() )
         mpGfxLink->SwapOut();
 }
 
+void ImpGraphic::ImplSetSharedLink(const std::shared_ptr<GfxLink>& pGfxLink)
+{
+    mpGfxLink = pGfxLink;
+
+    if (mpGfxLink->IsNative())
+        mpGfxLink->SwapOut();
+}
+
 GfxLink ImpGraphic::ImplGetLink()
 {
     return( mpGfxLink ? *mpGfxLink : GfxLink() );
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to