diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-04-22 19:21:22 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-04-27 06:56:53 +0200 |
commit | b50cbd7c7fd807af34d5140eaf94c57133148768 (patch) | |
tree | 08a438d5a4650c5936766b2f815b2fbf39306668 | |
parent | c5b6bc45d535cdad15d0d614bc3102bdf6cfd856 (diff) |
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@gmail.com>
-rw-r--r-- | vcl/inc/impgraph.hxx | 1 | ||||
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 61 |
2 files changed, 26 insertions, 36 deletions
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); |