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

Xisco Fauli anistenis at gmail.com
Wed May 4 12:24:12 UTC 2016


 include/vcl/wall.hxx            |   15 ++-
 vcl/inc/wall2.hxx               |   17 +---
 vcl/source/gdi/wall.cxx         |  161 ++++++++++------------------------------
 vcl/source/outdev/wallpaper.cxx |    6 -
 4 files changed, 60 insertions(+), 139 deletions(-)

New commits:
commit b6f3b2b0ab9404917b7805bb89701c110b468768
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Mon May 2 03:16:10 2016 +0200

    tdf#62525 vcl: use cow_wrapper for wall
    
    Change-Id: Iaf0b288a4c40f1e471a0a59b6baf17c317810d23
    Reviewed-on: https://gerrit.libreoffice.org/24575
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/include/vcl/wall.hxx b/include/vcl/wall.hxx
index f727dc7..282a1db 100644
--- a/include/vcl/wall.hxx
+++ b/include/vcl/wall.hxx
@@ -23,6 +23,7 @@
 #include <tools/color.hxx>
 #include <tools/gen.hxx>
 #include <vcl/dllapi.h>
+#include <o3tl/cow_wrapper.hxx>
 
 class Gradient;
 class BitmapEx;
@@ -48,15 +49,17 @@ enum class WallpaperStyle
 
 class VCL_DLLPUBLIC Wallpaper
 {
-private:
-    ImplWallpaper*  mpImplWallpaper;
+public:
+    typedef o3tl::cow_wrapper<ImplWallpaper> ImplType;
 
-    SAL_DLLPRIVATE void           ImplMakeUnique( bool bReleaseCache = true );
-    SAL_DLLPRIVATE Gradient       ImplGetApplicationGradient() const;
+    SAL_DLLPRIVATE void             ImplSetCachedBitmap( BitmapEx& rBmp ) const;
+    SAL_DLLPRIVATE const BitmapEx*  ImplGetCachedBitmap() const;
+    SAL_DLLPRIVATE void             ImplReleaseCachedBitmap() const;
 
-public:
-    SAL_DLLPRIVATE ImplWallpaper* ImplGetImpWallpaper() const { return mpImplWallpaper; }
+private:
+    ImplType  mpImplWallpaper;
 
+    SAL_DLLPRIVATE Gradient       ImplGetApplicationGradient() const;
 
 public:
                     Wallpaper();
diff --git a/vcl/inc/wall2.hxx b/vcl/inc/wall2.hxx
index 60cbd68..59f2ebb 100644
--- a/vcl/inc/wall2.hxx
+++ b/vcl/inc/wall2.hxx
@@ -30,20 +30,17 @@ private:
     Gradient*       mpGradient;
     Rectangle*      mpRect;
     WallpaperStyle  meStyle;
-    sal_uLong       mnRefCount;
     BitmapEx*       mpCache;
 
-    friend SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper );
-    friend SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpaper );
-
 public:
-                    ImplWallpaper();
-                    ImplWallpaper( const ImplWallpaper& rImplWallpaper );
-                    ~ImplWallpaper();
+    ImplWallpaper();
+    ImplWallpaper( const ImplWallpaper& rImplWallpaper );
+    ~ImplWallpaper();
 
-    void            ImplSetCachedBitmap( BitmapEx& rBmp );
-    const BitmapEx* ImplGetCachedBitmap() { return mpCache; }
-    void            ImplReleaseCachedBitmap();
+    bool operator==( const ImplWallpaper& rImplWallpaper ) const;
+
+    friend SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper );
+    friend SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpaper );
 };
 
 #endif // INCLUDED_VCL_INC_WALL2_HXX
diff --git a/vcl/source/gdi/wall.cxx b/vcl/source/gdi/wall.cxx
index 4065877..f69e3ab 100644
--- a/vcl/source/gdi/wall.cxx
+++ b/vcl/source/gdi/wall.cxx
@@ -31,7 +31,6 @@
 ImplWallpaper::ImplWallpaper() :
     maColor( COL_TRANSPARENT )
 {
-    mnRefCount      = 1;
     mpBitmap        = nullptr;
     mpCache         = nullptr;
     mpGradient      = nullptr;
@@ -42,7 +41,6 @@ ImplWallpaper::ImplWallpaper() :
 ImplWallpaper::ImplWallpaper( const ImplWallpaper& rImplWallpaper ) :
     maColor( rImplWallpaper.maColor )
 {
-    mnRefCount = 1;
     meStyle = rImplWallpaper.meStyle;
 
     if ( rImplWallpaper.mpBitmap )
@@ -71,18 +69,15 @@ ImplWallpaper::~ImplWallpaper()
     delete mpRect;
 }
 
-void ImplWallpaper::ImplSetCachedBitmap( BitmapEx& rBmp )
+bool ImplWallpaper::operator==( const ImplWallpaper& rImplWallpaper ) const
 {
-    if( !mpCache )
-        mpCache = new BitmapEx( rBmp );
-    else
-        *mpCache = rBmp;
-}
-
-void ImplWallpaper::ImplReleaseCachedBitmap()
-{
-    delete mpCache;
-    mpCache = nullptr;
+    if ( meStyle == rImplWallpaper.meStyle &&
+         maColor == rImplWallpaper.maColor &&
+         mpRect == rImplWallpaper.mpRect &&
+         mpBitmap == rImplWallpaper.mpBitmap &&
+         mpGradient == rImplWallpaper.mpGradient )
+        return true;
+    return false;
 }
 
 SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper )
@@ -168,81 +163,66 @@ SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpap
     return rOStm;
 }
 
-inline void Wallpaper::ImplMakeUnique( bool bReleaseCache )
+namespace
 {
-    // copy them if other references exist
-    if ( mpImplWallpaper->mnRefCount != 1 )
-    {
-        if ( mpImplWallpaper->mnRefCount )
-            mpImplWallpaper->mnRefCount--;
-        mpImplWallpaper = new ImplWallpaper( *(mpImplWallpaper) );
-    }
-
-    if( bReleaseCache )
-        mpImplWallpaper->ImplReleaseCachedBitmap();
+    struct theGlobalDefault :
+        public rtl::Static< Wallpaper::ImplType, theGlobalDefault > {};
 }
 
-Wallpaper::Wallpaper()
+Wallpaper::Wallpaper() : mpImplWallpaper(theGlobalDefault::get())
 {
-
-    static ImplWallpaper aStaticImplWallpaper;
-
-    aStaticImplWallpaper.mnRefCount = 0;
-    mpImplWallpaper = &aStaticImplWallpaper;
 }
 
 Wallpaper::Wallpaper( const Wallpaper& rWallpaper )
+    : mpImplWallpaper( rWallpaper.mpImplWallpaper)
 {
-    DBG_ASSERT( rWallpaper.mpImplWallpaper->mnRefCount < 0xFFFFFFFE, "Wallpaper: RefCount overflow" );
-
-    // use Instance data and increment reference counter
-    mpImplWallpaper = rWallpaper.mpImplWallpaper;
-    // RefCount == 0 for static objekts
-    if ( mpImplWallpaper->mnRefCount )
-        mpImplWallpaper->mnRefCount++;
 }
 
-Wallpaper::Wallpaper( const Color& rColor )
+Wallpaper::Wallpaper( const Color& rColor ) : mpImplWallpaper()
 {
-
-    mpImplWallpaper             = new ImplWallpaper;
     mpImplWallpaper->maColor    = rColor;
     mpImplWallpaper->meStyle    = WallpaperStyle::Tile;
 }
 
-Wallpaper::Wallpaper( const BitmapEx& rBmpEx )
+Wallpaper::Wallpaper( const BitmapEx& rBmpEx ) : mpImplWallpaper()
 {
-
-    mpImplWallpaper             = new ImplWallpaper;
     mpImplWallpaper->mpBitmap   = new BitmapEx( rBmpEx );
     mpImplWallpaper->meStyle    = WallpaperStyle::Tile;
 }
 
-Wallpaper::Wallpaper( const Gradient& rGradient )
+Wallpaper::Wallpaper( const Gradient& rGradient ) : mpImplWallpaper()
 {
-
-    mpImplWallpaper             = new ImplWallpaper;
     mpImplWallpaper->mpGradient = new Gradient( rGradient );
     mpImplWallpaper->meStyle    = WallpaperStyle::Tile;
 }
 
 Wallpaper::~Wallpaper()
 {
-    // if ImpData are not static then delete them if it is the last reference,
-    // otherwise decrement reference counter
-    if ( mpImplWallpaper->mnRefCount )
-    {
-        if ( mpImplWallpaper->mnRefCount == 1 )
-            delete mpImplWallpaper;
-        else
-            mpImplWallpaper->mnRefCount--;
-    }
 }
 
-void Wallpaper::SetColor( const Color& rColor )
+void Wallpaper::ImplSetCachedBitmap( BitmapEx& rBmp ) const
 {
+    if( !mpImplWallpaper->mpCache )
+        const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = new BitmapEx( rBmp );
+    else
+        const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = &rBmp;
+}
 
-    ImplMakeUnique();
+const BitmapEx* Wallpaper::ImplGetCachedBitmap() const
+{
+    return mpImplWallpaper->mpCache;
+}
+
+void Wallpaper::ImplReleaseCachedBitmap() const
+{
+    delete mpImplWallpaper->mpCache;
+    const_cast< ImplWallpaper* >(mpImplWallpaper.get())->mpCache = nullptr;
+}
+
+
+void Wallpaper::SetColor( const Color& rColor )
+{
+    ImplReleaseCachedBitmap();
     mpImplWallpaper->maColor = rColor;
 
     if( WallpaperStyle::NONE == mpImplWallpaper->meStyle || WallpaperStyle::ApplicationGradient == mpImplWallpaper->meStyle )
@@ -251,15 +231,11 @@ void Wallpaper::SetColor( const Color& rColor )
 
 const Color& Wallpaper::GetColor() const
 {
-
     return mpImplWallpaper->maColor;
 }
 
 void Wallpaper::SetStyle( WallpaperStyle eStyle )
 {
-
-    ImplMakeUnique( false );
-
     if( eStyle == WallpaperStyle::ApplicationGradient )
         // set a dummy gradient, the correct gradient
         // will be created dynamically in GetGradient()
@@ -270,25 +246,23 @@ void Wallpaper::SetStyle( WallpaperStyle eStyle )
 
 WallpaperStyle Wallpaper::GetStyle() const
 {
-
     return mpImplWallpaper->meStyle;
 }
 
 void Wallpaper::SetBitmap( const BitmapEx& rBitmap )
 {
-
     if ( !rBitmap )
     {
         if ( mpImplWallpaper->mpBitmap )
         {
-            ImplMakeUnique();
+            ImplReleaseCachedBitmap();
             delete mpImplWallpaper->mpBitmap;
             mpImplWallpaper->mpBitmap = nullptr;
         }
     }
     else
     {
-        ImplMakeUnique();
+        ImplReleaseCachedBitmap();
         if ( mpImplWallpaper->mpBitmap )
             *(mpImplWallpaper->mpBitmap) = rBitmap;
         else
@@ -301,7 +275,6 @@ void Wallpaper::SetBitmap( const BitmapEx& rBitmap )
 
 BitmapEx Wallpaper::GetBitmap() const
 {
-
     if ( mpImplWallpaper->mpBitmap )
         return *(mpImplWallpaper->mpBitmap);
     else
@@ -313,14 +286,12 @@ BitmapEx Wallpaper::GetBitmap() const
 
 bool Wallpaper::IsBitmap() const
 {
-
     return (mpImplWallpaper->mpBitmap != nullptr);
 }
 
 void Wallpaper::SetGradient( const Gradient& rGradient )
 {
-
-    ImplMakeUnique();
+    ImplReleaseCachedBitmap();
 
     if ( mpImplWallpaper->mpGradient )
         *(mpImplWallpaper->mpGradient) = rGradient;
@@ -333,7 +304,6 @@ void Wallpaper::SetGradient( const Gradient& rGradient )
 
 Gradient Wallpaper::GetGradient() const
 {
-
     if( WallpaperStyle::ApplicationGradient == mpImplWallpaper->meStyle )
         return ImplGetApplicationGradient();
     else if ( mpImplWallpaper->mpGradient )
@@ -347,7 +317,6 @@ Gradient Wallpaper::GetGradient() const
 
 bool Wallpaper::IsGradient() const
 {
-
     return (mpImplWallpaper->mpGradient != nullptr);
 }
 
@@ -367,9 +336,6 @@ Gradient Wallpaper::ImplGetApplicationGradient() const
 
 void Wallpaper::SetRect( const Rectangle& rRect )
 {
-
-    ImplMakeUnique( false );
-
     if ( rRect.IsEmpty() )
     {
         if ( mpImplWallpaper->mpRect )
@@ -389,7 +355,6 @@ void Wallpaper::SetRect( const Rectangle& rRect )
 
 Rectangle Wallpaper::GetRect() const
 {
-
     if ( mpImplWallpaper->mpRect )
         return *(mpImplWallpaper->mpRect);
     else
@@ -427,61 +392,17 @@ bool Wallpaper::IsScrollable() const
 
 Wallpaper& Wallpaper::operator=( const Wallpaper& rWallpaper )
 {
-    DBG_ASSERT( rWallpaper.mpImplWallpaper->mnRefCount < 0xFFFFFFFE, "Wallpaper: RefCount overflow" );
-
-    // first increment reference counter, in order to self assign
-    if ( rWallpaper.mpImplWallpaper->mnRefCount )
-        rWallpaper.mpImplWallpaper->mnRefCount++;
-
-    // if ImpData are not static then delete them if it is the last reference,
-    // otherwise decrement reference counter
-    if ( mpImplWallpaper->mnRefCount )
-    {
-        if ( mpImplWallpaper->mnRefCount == 1 )
-            delete mpImplWallpaper;
-        else
-            mpImplWallpaper->mnRefCount--;
-    }
-
     mpImplWallpaper = rWallpaper.mpImplWallpaper;
-
     return *this;
 }
 
 bool Wallpaper::operator==( const Wallpaper& rWallpaper ) const
 {
-
-    if ( mpImplWallpaper == rWallpaper.mpImplWallpaper )
-        return true;
-
-    if ( ( mpImplWallpaper->meStyle != rWallpaper.mpImplWallpaper->meStyle ) ||
-         ( mpImplWallpaper->maColor != rWallpaper.mpImplWallpaper->maColor ) )
-        return false;
-
-    if ( mpImplWallpaper->mpRect != rWallpaper.mpImplWallpaper->mpRect
-         && ( !mpImplWallpaper->mpRect
-              || !rWallpaper.mpImplWallpaper->mpRect
-              || *(mpImplWallpaper->mpRect) != *(rWallpaper.mpImplWallpaper->mpRect) ) )
-        return false;
-
-    if ( mpImplWallpaper->mpBitmap != rWallpaper.mpImplWallpaper->mpBitmap
-         && ( !mpImplWallpaper->mpBitmap
-              || !rWallpaper.mpImplWallpaper->mpBitmap
-              || *(mpImplWallpaper->mpBitmap) != *(rWallpaper.mpImplWallpaper->mpBitmap) ) )
-        return false;
-
-    if ( mpImplWallpaper->mpGradient != rWallpaper.mpImplWallpaper->mpGradient
-         && ( !mpImplWallpaper->mpGradient
-              || !rWallpaper.mpImplWallpaper->mpGradient
-              || *(mpImplWallpaper->mpGradient) != *(rWallpaper.mpImplWallpaper->mpGradient) ) )
-        return false;
-
-    return true;
+    return mpImplWallpaper == rWallpaper.mpImplWallpaper;
 }
 
 SvStream& ReadWallpaper( SvStream& rIStm, Wallpaper& rWallpaper )
 {
-    rWallpaper.ImplMakeUnique();
     return ReadImplWallpaper( rIStm, *rWallpaper.mpImplWallpaper );
 }
 
diff --git a/vcl/source/outdev/wallpaper.cxx b/vcl/source/outdev/wallpaper.cxx
index d2c01db..057089b 100644
--- a/vcl/source/outdev/wallpaper.cxx
+++ b/vcl/source/outdev/wallpaper.cxx
@@ -112,7 +112,7 @@ void OutputDevice::DrawBitmapWallpaper( long nX, long nY,
     assert(!is_double_buffered_window());
 
     BitmapEx aBmpEx;
-    const BitmapEx* pCached = rWallpaper.ImplGetImpWallpaper()->ImplGetCachedBitmap();
+    const BitmapEx* pCached = rWallpaper.ImplGetCachedBitmap();
     Point aPos;
     Size aSize;
     GDIMetaFile* pOldMetaFile = mpMetaFile;
@@ -191,7 +191,7 @@ void OutputDevice::DrawBitmapWallpaper( long nX, long nY,
         if( !pCached || ( pCached->GetSizePixel() != aSize ) )
         {
             if( pCached )
-                rWallpaper.ImplGetImpWallpaper()->ImplReleaseCachedBitmap();
+                rWallpaper.ImplReleaseCachedBitmap();
 
             aBmpEx = rWallpaper.GetBitmap();
             aBmpEx.Scale( aSize );
@@ -336,7 +336,7 @@ void OutputDevice::DrawBitmapWallpaper( long nX, long nY,
         DrawBitmapEx( aPos, aBmpEx );
     }
 
-    rWallpaper.ImplGetImpWallpaper()->ImplSetCachedBitmap( aBmpEx );
+    rWallpaper.ImplSetCachedBitmap( aBmpEx );
 
     Pop();
     EnableMapMode( bOldMap );


More information about the Libreoffice-commits mailing list