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

Tamas Bunth tamas.bunth at collabora.co.uk
Wed Jun 7 11:52:38 UTC 2017


 vcl/inc/sallayout.hxx             |    6 +-----
 vcl/source/gdi/pdfwriter_impl.cxx |    6 +++---
 vcl/source/gdi/print2.cxx         |    4 ++--
 vcl/source/gdi/sallayout.cxx      |   14 ++------------
 vcl/source/outdev/font.cxx        |    4 ++--
 vcl/source/outdev/text.cxx        |   32 ++++++++++++++++----------------
 vcl/source/outdev/textline.cxx    |    4 ++--
 7 files changed, 28 insertions(+), 42 deletions(-)

New commits:
commit cb9be0e492d047648185ae80553220fd9b538746
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date:   Wed Jun 7 04:38:27 2017 +0200

    Replace vcl::SalLayout Release with destructor
    
    Replace SalLayout::Release() with normal destructor mechanism. Release()
    uses reference counting for the layout. But in practice, the reference
    counting variable is initialized in ctor and is not incremented elsewhere.
    So I removed the Release() method and replaced all the Release() calls with
    'delete'. It will make easier the use of smart pointers and decrease the
    chance of memory leaks.
    
    Change-Id: Ia2e142dea10b87e232d5757d84778e62d87cf081
    Reviewed-on: https://gerrit.libreoffice.org/38488
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/vcl/inc/sallayout.hxx b/vcl/inc/sallayout.hxx
index d4a960d63432..c90f029f7d70 100644
--- a/vcl/inc/sallayout.hxx
+++ b/vcl/inc/sallayout.hxx
@@ -151,6 +151,7 @@ std::ostream &operator <<(std::ostream& s, ImplLayoutArgs &rArgs);
 class VCL_PLUGIN_PUBLIC SalLayout
 {
 public:
+    virtual         ~SalLayout();
     // used by upper layers
     Point&          DrawBase()                              { return maDrawBase; }
     const Point&    DrawBase() const                        { return maDrawBase; }
@@ -179,9 +180,6 @@ public:
     virtual bool    GetOutline( SalGraphics&, basegfx::B2DPolyPolygonVector& ) const;
     virtual bool    GetBoundRect( SalGraphics&, tools::Rectangle& ) const;
 
-    // reference counting
-    void            Release() const;
-
     // used by glyph+font+script fallback
     virtual void    MoveGlyph( int nStart, long nNewXPos ) = 0;
     virtual void    DropGlyph( int nStart ) = 0;
@@ -193,7 +191,6 @@ public:
 protected:
     // used by layout engines
                     SalLayout();
-    virtual         ~SalLayout();
 
     static int      CalcAsianKerning( sal_UCS4, bool bLeft, bool bVertical );
 
@@ -209,7 +206,6 @@ protected:
     int             mnUnitsPerPixel;
     int             mnOrientation;
 
-    mutable int     mnRefCount;
     mutable Point   maDrawOffset;
     Point           maDrawBase;
 };
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 41749131ace9..87d536b8f848 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8877,7 +8877,7 @@ void PDFWriterImpl::drawText( const Point& rPos, const OUString& rText, sal_Int3
     if( pLayout )
     {
         drawLayout( *pLayout, rText, bTextLines );
-        pLayout->Release();
+        delete pLayout;
     }
 }
 
@@ -8893,7 +8893,7 @@ void PDFWriterImpl::drawTextArray( const Point& rPos, const OUString& rText, con
     if( pLayout )
     {
         drawLayout( *pLayout, rText, true );
-        pLayout->Release();
+        delete pLayout;
     }
 }
 
@@ -8909,7 +8909,7 @@ void PDFWriterImpl::drawStretchText( const Point& rPos, sal_uLong nWidth, const
     if( pLayout )
     {
         drawLayout( *pLayout, rText, true );
-        pLayout->Release();
+        delete pLayout;
     }
 }
 
diff --git a/vcl/source/gdi/print2.cxx b/vcl/source/gdi/print2.cxx
index 74ab167ecbdd..576c564652ec 100644
--- a/vcl/source/gdi/print2.cxx
+++ b/vcl/source/gdi/print2.cxx
@@ -592,7 +592,7 @@ tools::Rectangle ImplCalcActionBounds( const MetaAction& rAct, const OutputDevic
                 {
                     tools::Rectangle aBoundRect( const_cast<OutputDevice&>(rOut).ImplGetTextBoundRect( *pSalLayout ) );
                     aActionBounds = rOut.PixelToLogic( aBoundRect );
-                    pSalLayout->Release();
+                    delete pSalLayout;
                 }
             }
         }
@@ -622,7 +622,7 @@ tools::Rectangle ImplCalcActionBounds( const MetaAction& rAct, const OutputDevic
                 {
                     tools::Rectangle aBoundRect( const_cast<OutputDevice&>(rOut).ImplGetTextBoundRect( *pSalLayout ) );
                     aActionBounds = rOut.PixelToLogic( aBoundRect );
-                    pSalLayout->Release();
+                    delete pSalLayout;
                 }
             }
         }
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx
index 11e1d307eb73..30907d8a62ad 100644
--- a/vcl/source/gdi/sallayout.cxx
+++ b/vcl/source/gdi/sallayout.cxx
@@ -545,7 +545,6 @@ SalLayout::SalLayout()
     mnLayoutFlags( SalLayoutFlags::NONE ),
     mnUnitsPerPixel( 1 ),
     mnOrientation( 0 ),
-    mnRefCount( 1 ),
     maDrawOffset( 0, 0 )
 {}
 
@@ -560,15 +559,6 @@ void SalLayout::AdjustLayout( ImplLayoutArgs& rArgs )
     mnOrientation = rArgs.mnOrientation;
 }
 
-void SalLayout::Release() const
-{
-    // TODO: protect when multiple threads can access this
-    if( --mnRefCount > 0 )
-        return;
-    // const_cast because some compilers violate ANSI C++ spec
-    delete this;
-}
-
 Point SalLayout::GetDrawPosition( const Point& rRelative ) const
 {
     Point aPos = maDrawBase;
@@ -1056,7 +1046,7 @@ void MultiSalLayout::SetIncomplete(bool bIncomplete)
 MultiSalLayout::~MultiSalLayout()
 {
     for( int i = 0; i < mnLevel; ++i )
-        mpLayouts[ i ]->Release();
+        delete mpLayouts[ i ];
 }
 
 void MultiSalLayout::AddFallback( SalLayout& rFallback,
@@ -1199,7 +1189,7 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs )
         if( (n > 0) && !nValid[ nLevel ] )
         {
             // an empty fallback layout can be released
-            mpLayouts[n]->Release();
+            delete mpLayouts[n];
         }
         else
         {
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 5bad32a22e44..f588853feb3c 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -1334,7 +1334,7 @@ SalLayout* OutputDevice::getFallbackFont(
     if (!pFallback->LayoutText(rLayoutArgs))
     {
         // there is no need for a font that couldn't resolve anything
-        pFallback->Release();
+        delete pFallback;
         return nullptr;
     }
 
@@ -1457,7 +1457,7 @@ sal_Int32 OutputDevice::ValidateKashidas ( const OUString& rTxt,
             ++nDropped;
         }
     }
-    pSalLayout->Release();
+    delete pSalLayout;
     return nDropped;
 }
 
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index f99cf54a9cb3..15eaeb434433 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -878,7 +878,7 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
     if( pSalLayout )
     {
         ImplDrawText( *pSalLayout );
-        pSalLayout->Release();
+        delete pSalLayout;
     }
 
     if( mpAlphaVDev )
@@ -943,7 +943,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
     if( pSalLayout )
     {
         ImplDrawText( *pSalLayout );
-        pSalLayout->Release();
+        delete pSalLayout;
     }
 
     if( mpAlphaVDev )
@@ -986,7 +986,7 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
     }
     DeviceCoordinate nWidth = pSalLayout->FillDXArray( pDXPixelArray.get() );
     int nWidthFactor = pSalLayout->GetUnitsPerPixel();
-    pSalLayout->Release();
+    delete pSalLayout;
 
     // convert virtual char widths to virtual absolute positions
     if( pDXPixelArray )
@@ -1031,7 +1031,7 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
 
     long nWidth = pSalLayout->FillDXArray( pDXAry );
     int nWidthFactor = pSalLayout->GetUnitsPerPixel();
-    pSalLayout->Release();
+    delete pSalLayout;
 
     // convert virtual char widths to virtual absolute positions
     if( pDXAry )
@@ -1075,7 +1075,7 @@ bool OutputDevice::GetCaretPositions( const OUString& rStr, long* pCaretXArray,
     int nWidthFactor = pSalLayout->GetUnitsPerPixel();
     pSalLayout->GetCaretPositions( 2*nLen, pCaretXArray );
     long nWidth = pSalLayout->GetTextWidth();
-    pSalLayout->Release();
+    delete pSalLayout;
 
     // fixup unknown caret positions
     int i;
@@ -1135,7 +1135,7 @@ void OutputDevice::DrawStretchText( const Point& rStartPt, sal_uLong nWidth,
     if( pSalLayout )
     {
         ImplDrawText( *pSalLayout );
-        pSalLayout->Release();
+        delete pSalLayout;
     }
 
     if( mpAlphaVDev )
@@ -1313,7 +1313,7 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
     // layout text
     if( pSalLayout && !pSalLayout->LayoutText( aLayoutArgs ) )
     {
-        pSalLayout->Release();
+        delete pSalLayout;
         pSalLayout = nullptr;
     }
 
@@ -1358,7 +1358,7 @@ std::shared_ptr<vcl::TextLayoutCache> OutputDevice::CreateTextLayoutCache(
         return nullptr;
     std::shared_ptr<vcl::TextLayoutCache> const ret(
             pSalLayout->CreateTextLayoutCache(copyBecausePrepareModifiesIt));
-    pSalLayout->Release();
+    delete pSalLayout;
     return ret;
 }
 
@@ -1399,7 +1399,7 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
         }
         nRetVal = pSalLayout->GetTextBreak( nTextPixelWidth, nExtraPixelWidth, nSubPixelFactor );
 
-        pSalLayout->Release();
+        delete pSalLayout;
     }
 
     return nRetVal;
@@ -1445,7 +1445,7 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
         {
             // calculate subpixel width of hyphenation character
             long nHyphenPixelWidth = pHyphenLayout->GetTextWidth() * nSubPixelFactor;
-            pHyphenLayout->Release();
+            delete pHyphenLayout;
 
             // calculate hyphenated break position
             nTextPixelWidth -= nHyphenPixelWidth;
@@ -1458,7 +1458,7 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
                 rHyphenPos = nRetVal;
         }
 
-        pSalLayout->Release();
+        delete pSalLayout;
     }
 
     return nRetVal;
@@ -2326,7 +2326,7 @@ SystemTextLayoutData OutputDevice::GetSysTextLayoutData(const Point& rStartPt, c
     // Get font data
     aSysLayoutData.orientation = pLayout->GetOrientation();
 
-    pLayout->Release();
+    delete pLayout;
 
     return aSysLayoutData;
 }
@@ -2352,7 +2352,7 @@ bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect,
         {
             nXOffset = pSalLayout->GetTextWidth();
             nXOffset /= pSalLayout->GetUnitsPerPixel();
-            pSalLayout->Release();
+            delete pSalLayout;
             // TODO: fix offset calculation for Bidi case
             if( nBase < nIndex)
                 nXOffset = -nXOffset;
@@ -2390,7 +2390,7 @@ bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect,
                 rRect += Point( maMapRes.mnMapOfsX, maMapRes.mnMapOfsY );
         }
 
-        pSalLayout->Release();
+        delete pSalLayout;
     }
 
     return bRet;
@@ -2438,7 +2438,7 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector,
         if( pSalLayout )
         {
             nXOffset = pSalLayout->GetTextWidth();
-            pSalLayout->Release();
+            delete pSalLayout;
             // TODO: fix offset calculation for Bidi case
             if( nBase > nIndex)
                 nXOffset = -nXOffset;
@@ -2476,7 +2476,7 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector,
             }
         }
 
-        pSalLayout->Release();
+        delete pSalLayout;
     }
 
     if( bOldMap )
diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx
index 69e473810f74..427a8d95e595 100644
--- a/vcl/source/outdev/textline.cxx
+++ b/vcl/source/outdev/textline.cxx
@@ -604,7 +604,7 @@ void OutputDevice::ImplDrawStrikeoutChar( long nBaseX, long nBaseY,
     if( pLayout )
     {
         nStrikeoutWidth = pLayout->GetTextWidth() / (nTestStrLen * pLayout->GetUnitsPerPixel());
-        pLayout->Release();
+        delete pLayout;
     }
     if( nStrikeoutWidth <= 0 ) // sanity check
         return;
@@ -664,7 +664,7 @@ void OutputDevice::ImplDrawStrikeoutChar( long nBaseX, long nBaseY,
 
     pLayout->DrawText( *mpGraphics );
 
-    pLayout->Release();
+    delete pLayout;
     Pop();
 
     SetTextColor( aOldColor );


More information about the Libreoffice-commits mailing list