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

Noel Grandin noel.grandin at collabora.co.uk
Wed May 2 06:26:36 UTC 2018


 vcl/inc/unx/salbmp.h                 |    2 +-
 vcl/inc/unx/salgdi.h                 |    2 +-
 vcl/unx/generic/gdi/salbmp.cxx       |   27 +++++++--------------------
 vcl/unx/generic/gdi/salgdi.cxx       |    4 ++--
 vcl/unx/generic/gdi/salvd.cxx        |   12 +++++-------
 vcl/unx/gtk/salnativewidgets-gtk.cxx |   35 ++++++++++++++++-------------------
 6 files changed, 32 insertions(+), 50 deletions(-)

New commits:
commit c4b8edefcf452ad80254b1f76bcfba743b0b486f
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Apr 30 19:03:33 2018 +0200

    loplugin:useuniqueptr in NWPixmapCacheData
    
    Change-Id: Ie71583f2fb1f2471ddeaf7a10572c679a4e5cbe0
    Reviewed-on: https://gerrit.libreoffice.org/53707
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/vcl/unx/gtk/salnativewidgets-gtk.cxx b/vcl/unx/gtk/salnativewidgets-gtk.cxx
index 2bd434c862b0..539d8cb5d897 100644
--- a/vcl/unx/gtk/salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk/salnativewidgets-gtk.cxx
@@ -329,13 +329,11 @@ public:
     ControlType    m_nType;
     ControlState   m_nState;
     tools::Rectangle      m_pixmapRect;
-    GdkX11Pixmap*  m_pixmap;
-    GdkX11Pixmap*  m_mask;
+    std::unique_ptr<GdkX11Pixmap> m_pixmap;
+    std::unique_ptr<GdkX11Pixmap> m_mask;
 
-    NWPixmapCacheData() : m_nType(ControlType::Generic), m_nState(ControlState::NONE), m_pixmap(nullptr), m_mask(nullptr) {}
-    ~NWPixmapCacheData()
-        { SetPixmap( nullptr, nullptr ); };
-    void SetPixmap( GdkX11Pixmap* pPixmap, GdkX11Pixmap* pMask );
+    NWPixmapCacheData() : m_nType(ControlType::Generic), m_nState(ControlState::NONE) {}
+    void SetPixmap( std::unique_ptr<GdkX11Pixmap> pPixmap, std::unique_ptr<GdkX11Pixmap> pMask );
 };
 
 class NWPixmapCache
@@ -353,7 +351,7 @@ public:
     int GetSize() const { return m_size; }
 
     bool Find( ControlType aType, ControlState aState, const tools::Rectangle& r_pixmapRect, GdkX11Pixmap** pPixmap, GdkX11Pixmap** pMask );
-    void Fill( ControlType aType, ControlState aState, const tools::Rectangle& r_pixmapRect, GdkX11Pixmap* pPixmap, GdkX11Pixmap* pMask );
+    void Fill( ControlType aType, ControlState aState, const tools::Rectangle& r_pixmapRect, std::unique_ptr<GdkX11Pixmap> pPixmap, std::unique_ptr<GdkX11Pixmap> pMask );
 
     void ThemeChanged();
 };
@@ -370,13 +368,10 @@ public:
 
 // --- implementation ---
 
-void NWPixmapCacheData::SetPixmap( GdkX11Pixmap* pPixmap, GdkX11Pixmap* pMask )
+void NWPixmapCacheData::SetPixmap( std::unique_ptr<GdkX11Pixmap> pPixmap, std::unique_ptr<GdkX11Pixmap> pMask )
 {
-    delete m_pixmap;
-    delete m_mask;
-
-    m_pixmap = pPixmap;
-    m_mask = pMask;
+    m_pixmap = std::move(pPixmap);
+    m_mask = std::move(pMask);
 }
 
 NWPixmapCache::NWPixmapCache( SalX11Screen nScreen )
@@ -412,15 +407,17 @@ bool  NWPixmapCache::Find( ControlType aType, ControlState aState, const tools::
             pData[i].m_pixmapRect.GetHeight() == r_pixmapRect.GetHeight() &&
             pData[i].m_pixmap != nullptr )
         {
-            *pPixmap = pData[i].m_pixmap;
-            *pMask = pData[i].m_mask;
+            *pPixmap = pData[i].m_pixmap.get();
+            *pMask = pData[i].m_mask.get();
             return true;
         }
     }
     return false;
 }
 
-void NWPixmapCache::Fill( ControlType aType, ControlState aState, const tools::Rectangle& r_pixmapRect, GdkX11Pixmap* pPixmap, GdkX11Pixmap* pMask )
+void NWPixmapCache::Fill( ControlType aType, ControlState aState, const tools::Rectangle& r_pixmapRect,
+                         std::unique_ptr<GdkX11Pixmap> pPixmap,
+                         std::unique_ptr<GdkX11Pixmap> pMask )
 {
     if( !(aState & ControlState::CACHING_ALLOWED) )
         return;
@@ -430,7 +427,7 @@ void NWPixmapCache::Fill( ControlType aType, ControlState aState, const tools::R
     pData[m_idx].m_nType = aType;
     pData[m_idx].m_nState = aState;
     pData[m_idx].m_pixmapRect = r_pixmapRect;
-    pData[m_idx].SetPixmap( pPixmap, pMask );
+    pData[m_idx].SetPixmap( std::move(pPixmap), std::move(pMask) );
 }
 
 void NWPixmapCacheList::AddCache( NWPixmapCache* pCache )
@@ -2805,9 +2802,9 @@ bool GtkSalGraphics::NWPaintGTKTabItem( ControlType nType,
 
     // cache data
     if( nType == ControlType::TabItem )
-        aCacheItems.Fill( nType, nState, pixmapRect, pixmap, mask );
+        aCacheItems.Fill( nType, nState, pixmapRect, std::unique_ptr<GdkX11Pixmap>(pixmap), std::unique_ptr<GdkX11Pixmap>(mask) );
     else
-        aCachePage.Fill( nType, nState, pixmapRect, pixmap, mask );
+        aCachePage.Fill( nType, nState, pixmapRect, std::unique_ptr<GdkX11Pixmap>(pixmap), std::unique_ptr<GdkX11Pixmap>(mask) );
 
     return true;
 }
commit cee2ccb38f0b6d223d9c60da6538f06a84ad6192
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Apr 30 18:46:04 2018 +0200

    loplugin:useuniqueptr in X11SalBitmap
    
    Change-Id: I3fedb4b25683bafbdb7c761387d47a8b30ef8083
    Reviewed-on: https://gerrit.libreoffice.org/53706
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/vcl/inc/unx/salbmp.h b/vcl/inc/unx/salbmp.h
index 8e1b7d5a6bf6..34c7ff076156 100644
--- a/vcl/inc/unx/salbmp.h
+++ b/vcl/inc/unx/salbmp.h
@@ -71,7 +71,7 @@ public:
 private:
 
     std::unique_ptr<BitmapBuffer> mpDIB;
-    ImplSalDDB*     mpDDB;
+    mutable std::unique_ptr<ImplSalDDB> mpDDB;
     bool            mbGrey;
 
 public:
diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h
index dded647ab97d..8cfc5abb2add 100644
--- a/vcl/inc/unx/salgdi.h
+++ b/vcl/inc/unx/salgdi.h
@@ -318,7 +318,7 @@ protected:
     SalVirtualDevice*               m_pVDev;  // the SalVirtualDevice which created this Graphics or NULL
 
     const SalColormap*              m_pColormap;
-    SalColormap*                    m_pDeleteColormap;
+    std::unique_ptr<SalColormap>    m_pDeleteColormap;
     Drawable                        hDrawable_;     // use
     SalX11Screen                    m_nXScreen;
     mutable XRenderPictFormat*      m_pXRenderFormat;
diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx
index 121290a90abc..d50c92feba90 100644
--- a/vcl/unx/generic/gdi/salbmp.cxx
+++ b/vcl/unx/generic/gdi/salbmp.cxx
@@ -94,11 +94,7 @@ void X11SalBitmap::ImplDestroyCache()
 
 void X11SalBitmap::ImplRemovedFromCache()
 {
-    if( mpDDB )
-    {
-        delete mpDDB;
-        mpDDB = nullptr;
-    }
+    mpDDB.reset();
 }
 
 #if defined HAVE_VALGRIND_HEADERS
@@ -590,7 +586,7 @@ bool X11SalBitmap::ImplCreateFromDrawable(
     Destroy();
 
     if( aDrawable && nWidth && nHeight && nDrawableDepth )
-        mpDDB = new ImplSalDDB( aDrawable, nScreen, nDrawableDepth, nX, nY, nWidth, nHeight );
+        mpDDB.reset(new ImplSalDDB( aDrawable, nScreen, nDrawableDepth, nX, nY, nWidth, nHeight ));
 
     return( mpDDB != nullptr );
 }
@@ -618,8 +614,7 @@ ImplSalDDB* X11SalBitmap::ImplGetDDB(
                                                                         mbGrey );
             }
 
-            delete mpDDB;
-            const_cast<X11SalBitmap*>(this)->mpDDB = nullptr;
+            mpDDB.reset();
         }
 
         if( mpCache )
@@ -681,7 +676,7 @@ ImplSalDDB* X11SalBitmap::ImplGetDDB(
 
         if( pImage )
         {
-            const_cast<X11SalBitmap*>(this)->mpDDB = new ImplSalDDB( pImage, aDrawable, nXScreen, aTwoRect );
+            mpDDB.reset(new ImplSalDDB( pImage, aDrawable, nXScreen, aTwoRect ));
             delete[] pImage->data;
             pImage->data = nullptr;
             XDestroyImage( pImage );
@@ -691,7 +686,7 @@ ImplSalDDB* X11SalBitmap::ImplGetDDB(
         }
     }
 
-    return mpDDB;
+    return mpDDB.get();
 }
 
 void X11SalBitmap::ImplDraw(
@@ -809,11 +804,7 @@ void X11SalBitmap::Destroy()
         mpDIB.reset();
     }
 
-    if( mpDDB )
-    {
-        delete mpDDB;
-        mpDDB = nullptr;
-    }
+    mpDDB.reset();
 
     if( mpCache )
         mpCache->ImplRemove( this );
@@ -873,11 +864,7 @@ void X11SalBitmap::ReleaseBuffer( BitmapBuffer*, BitmapAccessMode nMode )
 {
     if( nMode == BitmapAccessMode::Write )
     {
-        if( mpDDB )
-        {
-            delete mpDDB;
-            mpDDB = nullptr;
-        }
+        mpDDB.reset();
 
         if( mpCache )
             mpCache->ImplRemove( this );
diff --git a/vcl/unx/generic/gdi/salgdi.cxx b/vcl/unx/generic/gdi/salgdi.cxx
index 005cbf4be7d6..80dc7ecad17c 100644
--- a/vcl/unx/generic/gdi/salgdi.cxx
+++ b/vcl/unx/generic/gdi/salgdi.cxx
@@ -132,8 +132,8 @@ void X11SalGraphics::freeResources()
     }
     if( m_pDeleteColormap )
     {
-        delete m_pDeleteColormap;
-        m_pColormap = m_pDeleteColormap = nullptr;
+        m_pDeleteColormap.reset();
+        m_pColormap = nullptr;
     }
     if( m_aXRenderPicture )
     {
diff --git a/vcl/unx/generic/gdi/salvd.cxx b/vcl/unx/generic/gdi/salvd.cxx
index 3bbe0fde016b..d7223df9de8b 100644
--- a/vcl/unx/generic/gdi/salvd.cxx
+++ b/vcl/unx/generic/gdi/salvd.cxx
@@ -55,8 +55,6 @@ std::unique_ptr<SalVirtualDevice> X11SalInstance::CreateVirtualDevice(SalGraphic
 void X11SalGraphics::Init( X11SalVirtualDevice *pDevice, SalColormap* pColormap,
                            bool bDeleteColormap )
 {
-    SalColormap *pOrigDeleteColormap = m_pDeleteColormap;
-
     SalDisplay *pDisplay  = pDevice->GetDisplay();
     m_nXScreen = pDevice->GetXScreenNumber();
 
@@ -67,15 +65,15 @@ void X11SalGraphics::Init( X11SalVirtualDevice *pDevice, SalColormap* pColormap,
     {
         m_pColormap = pColormap;
         if( bDeleteColormap )
-            m_pDeleteColormap = pColormap;
+            m_pDeleteColormap.reset(pColormap);
     }
     else if( nDeviceDepth == nVisualDepth )
         m_pColormap = &pDisplay->GetColormap( m_nXScreen );
     else if( nDeviceDepth == 1 )
-        m_pColormap = m_pDeleteColormap = new SalColormap();
-
-    if (m_pDeleteColormap != pOrigDeleteColormap)
-        delete pOrigDeleteColormap;
+    {
+        m_pDeleteColormap.reset(new SalColormap());
+        m_pColormap = m_pDeleteColormap.get();
+    }
 
     m_pVDev      = pDevice;
     m_pFrame     = nullptr;


More information about the Libreoffice-commits mailing list