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

Mark Page aptitude at btconnect.com
Thu Jun 30 07:01:19 UTC 2016


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

New commits:
commit f160d8c879b7184b2a41f2310a09c0432c14379a
Author: Mark Page <aptitude at btconnect.com>
Date:   Tue Jun 28 11:55:51 2016 +0100

    Modify the ImpGraphic class SwapFile to use a shared pointer
    
    Change-Id: I2cf85f91d9022a4ea10804efe2e986e95a63419f
    Reviewed-on: https://gerrit.libreoffice.org/26284
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index a41d684..884b6a6 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -42,7 +42,7 @@ private:
     ImpSwapInfo         maSwapInfo;
     Animation*          mpAnimation;
     GraphicReader*      mpContext;
-    ImpSwapFile*        mpSwapFile;
+    std::shared_ptr<ImpSwapFile> mpSwapFile;
     GfxLink*            mpGfxLink;
     GraphicType         meType;
     mutable sal_uLong   mnSizeBytes;
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 82e6b74..ba92a25 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -39,6 +39,7 @@
 #include <com/sun/star/ucb/CommandAbortedException.hpp>
 #include <vcl/dibtools.hxx>
 #include <memory>
+#include <o3tl/make_unique.hxx>
 
 #define GRAPHIC_MTFTOBMP_MAXEXT     2048
 #define GRAPHIC_STREAMBUFSIZE       8192UL
@@ -58,7 +59,7 @@ using namespace com::sun::star;
 struct ImpSwapFile
 {
     INetURLObject   aSwapURL;
-    sal_uLong           nRefCount;
+    ~ImpSwapFile();
 };
 
 class ReaderData
@@ -96,7 +97,6 @@ Size GraphicReader::GetPreviewSize() const
 ImpGraphic::ImpGraphic() :
         mpAnimation     ( nullptr ),
         mpContext       ( nullptr ),
-        mpSwapFile      ( nullptr ),
         mpGfxLink       ( nullptr ),
         meType          ( GraphicType::NONE ),
         mnSizeBytes     ( 0UL ),
@@ -119,9 +119,6 @@ ImpGraphic::ImpGraphic( const ImpGraphic& rImpGraphic ) :
         mbSwapUnderway  ( false ),
         mbDummyContext  ( rImpGraphic.mbDummyContext )
 {
-    if( mpSwapFile )
-        mpSwapFile->nRefCount++;
-
     if( rImpGraphic.mpGfxLink )
         mpGfxLink = new GfxLink( *rImpGraphic.mpGfxLink );
     else
@@ -143,7 +140,6 @@ ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) :
         maEx            ( rBitmap ),
         mpAnimation     ( nullptr ),
         mpContext       ( nullptr ),
-        mpSwapFile      ( nullptr ),
         mpGfxLink       ( nullptr ),
         meType          ( !rBitmap.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ),
         mnSizeBytes     ( 0UL ),
@@ -158,7 +154,6 @@ ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) :
         maEx            ( rBitmapEx ),
         mpAnimation     ( nullptr ),
         mpContext       ( nullptr ),
-        mpSwapFile      ( nullptr ),
         mpGfxLink       ( nullptr ),
         meType          ( !rBitmapEx.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ),
         mnSizeBytes     ( 0UL ),
@@ -172,7 +167,6 @@ ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) :
 ImpGraphic::ImpGraphic(const SvgDataPtr& rSvgDataPtr)
 :   mpAnimation( nullptr ),
     mpContext( nullptr ),
-    mpSwapFile( nullptr ),
     mpGfxLink( nullptr ),
     meType( rSvgDataPtr.get() ? GraphicType::Bitmap : GraphicType::NONE ),
     mnSizeBytes( 0UL ),
@@ -188,7 +182,6 @@ ImpGraphic::ImpGraphic( const Animation& rAnimation ) :
         maEx            ( rAnimation.GetBitmapEx() ),
         mpAnimation     ( new Animation( rAnimation ) ),
         mpContext       ( nullptr ),
-        mpSwapFile      ( nullptr ),
         mpGfxLink       ( nullptr ),
         meType          ( GraphicType::Bitmap ),
         mnSizeBytes     ( 0UL ),
@@ -203,7 +196,6 @@ ImpGraphic::ImpGraphic( const GDIMetaFile& rMtf ) :
         maMetaFile      ( rMtf ),
         mpAnimation     ( nullptr ),
         mpContext       ( nullptr ),
-        mpSwapFile      ( nullptr ),
         mpGfxLink       ( nullptr ),
         meType          ( GraphicType::GdiMetafile ),
         mnSizeBytes     ( 0UL ),
@@ -248,9 +240,6 @@ ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic )
         {
             mbSwapOut = rImpGraphic.mbSwapOut;
             mpSwapFile = rImpGraphic.mpSwapFile;
-
-            if( mpSwapFile )
-                mpSwapFile->nRefCount++;
         }
 
         delete mpGfxLink;
@@ -362,42 +351,33 @@ void ImpGraphic::ImplClearGraphics( bool bCreateSwapInfo )
     maPdfData = uno::Sequence<sal_Int8>();
 }
 
-void ImpGraphic::ImplClear()
+ImpSwapFile::~ImpSwapFile()
 {
-    if( mpSwapFile )
+    try
     {
-        if( mpSwapFile->nRefCount > 1 )
-            mpSwapFile->nRefCount--;
-        else
-        {
-            try
-            {
-                ::ucbhelper::Content aCnt( mpSwapFile->aSwapURL.GetMainURL( INetURLObject::NO_DECODE ),
-                                     css::uno::Reference< css::ucb::XCommandEnvironment >(),
-                                     comphelper::getProcessComponentContext() );
+        ::ucbhelper::Content aCnt( aSwapURL.GetMainURL( INetURLObject::NO_DECODE ),
+            css::uno::Reference< css::ucb::XCommandEnvironment >(),
+            comphelper::getProcessComponentContext() );
 
-                aCnt.executeCommand( "delete",
-                                     css::uno::makeAny( true ) );
-            }
-            catch( const css::ucb::ContentCreationException& )
-            {
-            }
-            catch( const css::uno::RuntimeException& )
-            {
-            }
-            catch( const css::ucb::CommandAbortedException& )
-            {
-            }
-            catch( const css::uno::Exception& )
-            {
-            }
-
-            delete mpSwapFile;
-        }
-
-        mpSwapFile = nullptr;
+        aCnt.executeCommand( "delete", css::uno::makeAny( true ) );
+    }
+    catch( const css::ucb::ContentCreationException& )
+    {
     }
+    catch( const css::uno::RuntimeException& )
+    {
+    }
+    catch( const css::ucb::CommandAbortedException& )
+    {
+    }
+    catch( const css::uno::Exception& )
+    {
+    }
+}
 
+void ImpGraphic::ImplClear()
+{
+    mpSwapFile.reset();
     mbSwapOut = false;
 
     // cleanup
@@ -1194,8 +1174,7 @@ bool ImpGraphic::ImplSwapOut()
 
                 if( ( bRet = ImplSwapOut( xOStm.get() ) ) )
                 {
-                    mpSwapFile = new ImpSwapFile;
-                    mpSwapFile->nRefCount = 1;
+                    mpSwapFile = o3tl::make_unique<ImpSwapFile>();
                     mpSwapFile->aSwapURL = aTmpURL;
                 }
                 else
@@ -1293,38 +1272,7 @@ bool ImpGraphic::ImplSwapIn()
                 bRet = ImplSwapIn( xIStm.get() );
                 xIStm.reset();
 
-                if( mpSwapFile )
-                {
-                    if( mpSwapFile->nRefCount > 1 )
-                        mpSwapFile->nRefCount--;
-                    else
-                    {
-                        try
-                        {
-                            ::ucbhelper::Content aCnt( aSwapURL,
-                                                 css::uno::Reference< css::ucb::XCommandEnvironment >(),
-                                                 comphelper::getProcessComponentContext() );
-
-                            aCnt.executeCommand( "delete", css::uno::makeAny( true ) );
-                        }
-                        catch( const css::ucb::ContentCreationException& )
-                        {
-                        }
-                        catch( const css::uno::RuntimeException& )
-                        {
-                        }
-                        catch( const css::ucb::CommandAbortedException& )
-                        {
-                        }
-                        catch( const css::uno::Exception& )
-                        {
-                        }
-
-                        delete mpSwapFile;
-                    }
-
-                    mpSwapFile = nullptr;
-                }
+                mpSwapFile.reset();
             }
         }
     }


More information about the Libreoffice-commits mailing list