[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - vcl/inc vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 22 17:25:07 UTC 2020


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

New commits:
commit 78e74b0f9c1995a83aa52639e594112dc49b60a4
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Apr 22 19:21:22 2020 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Wed Apr 22 19:21:22 2020 +0200

    ImpGraphic: move content of swapOutToStream into swapOut
    
    Change-Id: Iec0227b1e1ceebda961e158315ea5e56c2d33204

diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index fd9ae31d358c..47bc06d0ce6b 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -179,7 +179,6 @@ private:
     bool                swapInFromStream(SvStream* pIStm);
 
     bool                swapOut();
-    bool                swapOutToStream(SvStream* pOStm);
 
     bool                isSwappedOut() const { return mbSwapOut;}
 
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 9c5325ac528c..ef63bb9e8cb2 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1348,57 +1348,49 @@ 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
     auto pSwapFile = std::make_shared<ImpSwapFile>(aTempFileURL, getOriginURL());
 
-    std::unique_ptr<SvStream> xOutputStream = mpSwapFile->openOutputStream();
-
-    if (!xOutputStream)
-        return false;
-
-    xOutputStream->SetVersion(SOFFICE_FILEFORMAT_50);
-    xOutputStream->SetCompressMode(SvStreamCompressFlags::NATIVE);
-
-    bool bResult = swapOutToStream(xOutputStream.get());
-
-    xOutputStream.reset();
+    bool bResult = false;
 
-    if (bResult)
+    // Open a stream to write the swap file to
     {
-        mpSwapFile = pSwapFile;
-        vcl::graphic::Manager::get().swappedOut(this);
-    }
+        std::unique_ptr<SvStream> xOutputStream = mpSwapFile->openOutputStream();
 
-    return bResult;
-}
+        if (!xOutputStream)
+            return false;
 
-bool ImpGraphic::swapOutToStream(SvStream* xOStm)
-{
-    if( !xOStm )
-    {
-        SAL_WARN("vcl.gdi", "Graphic SwapOut: No stream for swap out!");
-        return false;
-    }
 
-    xOStm->SetBufferSize( GRAPHIC_STREAMBUFSIZE );
+        // Write to stream
+        xOutputStream->SetVersion(SOFFICE_FILEFORMAT_50);
+        xOutputStream->SetCompressMode(SvStreamCompressFlags::NATIVE);
+        xOutputStream->SetBufferSize(GRAPHIC_STREAMBUFSIZE);
 
-    bool bRet = false;
+        if (!xOutputStream->GetError() && ImplWriteEmbedded(*xOutputStream))
+        {
+            xOutputStream->Flush();
+            bResult = !xOutputStream->GetError();
+        }
+    }
 
-    if( !xOStm->GetError() && ImplWriteEmbedded( *xOStm ) )
+    // Check if writing was successfull
+    if (bResult)
     {
-        xOStm->Flush();
+        // We have swapped out, so can clean memory
+        mbSwapOut = true;
+        mpSwapFile = std::move(pSwapFile);
+        ImplCreateSwapInfo();
+        ImplClearGraphics();
 
-        if( !xOStm->GetError() )
-        {
-            ImplCreateSwapInfo();
-            ImplClearGraphics();
-            bRet = mbSwapOut = true;
-        }
+        // Signal to manager that we have swapped out
+        vcl::graphic::Manager::get().swappedOut(this);
     }
 
-    return bRet;
+    return bResult;
 }
 
 bool ImpGraphic::ensureAvailable() const


More information about the Libreoffice-commits mailing list