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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Mon Apr 27 04:57:29 UTC 2020


 vcl/inc/impgraph.hxx        |    1 
 vcl/source/gdi/impgraph.cxx |   61 ++++++++++++++++++--------------------------
 2 files changed, 26 insertions(+), 36 deletions(-)

New commits:
commit b50cbd7c7fd807af34d5140eaf94c57133148768
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Apr 22 19:21:22 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Apr 27 06:56:53 2020 +0200

    ImpGraphic: move content of swapOutToStream into swapOut
    
    Change-Id: Iec0227b1e1ceebda961e158315ea5e56c2d33204
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92946
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index 6ba07295f9a3..24112ca03dbe 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -177,7 +177,6 @@ private:
     bool                ImplWriteEmbedded( SvStream& rOStream );
 
     bool                swapInFromStream(SvStream* pIStm);
-    bool                swapOutToStream(SvStream* pOStm);
 
     bool                ImplIsDummyContext() const { return mbDummyContext; }
     void                ImplSetLink( const std::shared_ptr<GfxLink>& );
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 4a3e26946678..1b0797889525 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1356,59 +1356,50 @@ bool ImpGraphic::swapOut()
     if (isSwappedOut())
         return false;
 
+    // Create a temp filename for the swap file
     utl::TempFile aTempFile;
     const INetURLObject aTempFileURL(aTempFile.GetURL());
 
+    // Create a swap file
     std::shared_ptr<ImpSwapFile> pSwapFile(new ImpSwapFile(aTempFileURL, getOriginURL()), o3tl::default_delete<ImpSwapFile>());
 
-    std::unique_ptr<SvStream> xOutputStream = pSwapFile->openOutputStream();
+    bool bResult = false;
 
-    if (!xOutputStream)
-        return false;
+    // Open a stream to write the swap file to
+    {
+        std::unique_ptr<SvStream> xOutputStream = pSwapFile->openOutputStream();
 
-    xOutputStream->SetVersion(SOFFICE_FILEFORMAT_50);
-    xOutputStream->SetCompressMode(SvStreamCompressFlags::NATIVE);
+        if (!xOutputStream)
+            return false;
 
-    bool bResult = swapOutToStream(xOutputStream.get());
+        // Write to stream
+        xOutputStream->SetVersion(SOFFICE_FILEFORMAT_50);
+        xOutputStream->SetCompressMode(SvStreamCompressFlags::NATIVE);
+        xOutputStream->SetBufferSize(GRAPHIC_STREAMBUFSIZE);
 
-    xOutputStream.reset();
+        if (!xOutputStream->GetError() && ImplWriteEmbedded(*xOutputStream))
+        {
+            xOutputStream->Flush();
+            bResult = !xOutputStream->GetError();
+        }
+    }
 
+    // Check if writing was successfull
     if (bResult)
     {
-        mpSwapFile = pSwapFile;
+        // We have swapped out, so can clean memory
+        mbSwapOut = true;
+        mpSwapFile = std::move(pSwapFile);
+        ImplCreateSwapInfo();
+        ImplClearGraphics();
+
+        // Signal to manager that we have swapped out
         vcl::graphic::Manager::get().swappedOut(this);
     }
 
     return bResult;
 }
 
-bool ImpGraphic::swapOutToStream(SvStream* xOStm)
-{
-    if( !xOStm )
-    {
-        SAL_WARN("vcl.gdi", "Graphic SwapOut: No stream for swap out!");
-        return false;
-    }
-
-    xOStm->SetBufferSize( GRAPHIC_STREAMBUFSIZE );
-
-    bool bRet = false;
-
-    if( !xOStm->GetError() && ImplWriteEmbedded( *xOStm ) )
-    {
-        xOStm->Flush();
-
-        if( !xOStm->GetError() )
-        {
-            ImplCreateSwapInfo();
-            ImplClearGraphics();
-            bRet = mbSwapOut = true;
-        }
-    }
-
-    return bRet;
-}
-
 bool ImpGraphic::ensureAvailable() const
 {
     auto pThis = const_cast<ImpGraphic*>(this);


More information about the Libreoffice-commits mailing list