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

Mark Page aptitude at btconnect.com
Fri Dec 2 11:18:49 UTC 2016


 include/vcl/scopedbitmapaccess.hxx           |   40 +++++++++++++++++++++++----
 vcl/inc/canvasbitmap.hxx                     |    4 +-
 vcl/source/bitmap/BitmapProcessor.cxx        |   25 ++++++++--------
 vcl/source/bitmap/BitmapScaleConvolution.cxx |   14 +++------
 vcl/source/helper/canvasbitmap.cxx           |    9 +-----
 vcl/source/outdev/bitmap.cxx                 |   34 ++++++++++------------
 vcl/source/outdev/text.cxx                   |    4 +-
 vcl/source/outdev/transparent.cxx            |    8 ++---
 8 files changed, 78 insertions(+), 60 deletions(-)

New commits:
commit 677246466c471fbe3522c35be3639afa008a46c0
Author: Mark Page <aptitude at btconnect.com>
Date:   Thu Dec 1 13:53:30 2016 +0000

    Extend ScopedBitmapAccess and modify various classes to use it
    
    Exception safety, ensure the Access classes are always destroyed.
    
    Change-Id: I4889358476267853ffbd7fafc24950d84b4e9331
    Reviewed-on: https://gerrit.libreoffice.org/31494
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/scopedbitmapaccess.hxx b/include/vcl/scopedbitmapaccess.hxx
index bb5c8bf..2994136 100644
--- a/include/vcl/scopedbitmapaccess.hxx
+++ b/include/vcl/scopedbitmapaccess.hxx
@@ -51,20 +51,50 @@ template < class Access, class Bitmap, Access* (Bitmap::* Acquire)() > class Sco
 public:
     explicit ScopedBitmapAccess( Bitmap& rBitmap ) :
         mpAccess( nullptr ),
-        mrBitmap( rBitmap )
+        mpBitmap( &rBitmap )
     {
-        mpAccess = (mrBitmap.*Acquire)();
+        mpAccess = (mpBitmap->*Acquire)();
     }
 
     ScopedBitmapAccess( Access* pAccess, Bitmap& rBitmap ) :
         mpAccess( pAccess ),
-        mrBitmap( rBitmap )
+        mpBitmap( &rBitmap )
     {
     }
 
+    ScopedBitmapAccess( ) :
+        mpAccess( nullptr ),
+        mpBitmap( nullptr )
+    {
+    }
+
+    // Move semantics
+    ScopedBitmapAccess &operator=(ScopedBitmapAccess&&other)
+    {
+        mpAccess=other.mpAccess;
+        mpBitmap=other.mpBitmap;
+        other.mpAccess = nullptr;
+        other.mpBitmap = nullptr;
+        return *this;
+     }
+
+    // Disable copy from lvalue.
+    ScopedBitmapAccess(const ScopedBitmapAccess&) = delete;
+    ScopedBitmapAccess &operator=(const ScopedBitmapAccess&) = delete;
+
     ~ScopedBitmapAccess()
     {
-        mrBitmap.ReleaseAccess( mpAccess );
+        if (mpAccess)
+           mpBitmap->ReleaseAccess( mpAccess );
+    }
+
+    void reset()
+    {
+        if (mpAccess)
+        {
+           mpBitmap->ReleaseAccess( mpAccess );
+           mpAccess = nullptr;
+        }
     }
 
     bool operator!() const { return !mpAccess; }
@@ -84,7 +114,7 @@ public:
 
 private:
     Access*     mpAccess;
-    Bitmap&     mrBitmap;
+    Bitmap*     mpBitmap;
 };
 
 }
diff --git a/vcl/inc/canvasbitmap.hxx b/vcl/inc/canvasbitmap.hxx
index 292c432..0b5dba9 100644
--- a/vcl/inc/canvasbitmap.hxx
+++ b/vcl/inc/canvasbitmap.hxx
@@ -42,8 +42,8 @@ namespace unotools
         BitmapEx                                       m_aBmpEx;
         ::Bitmap                                       m_aBitmap;
         ::Bitmap                                       m_aAlpha;
-        BitmapReadAccess*                              m_pBmpAcc;
-        BitmapReadAccess*                              m_pAlphaAcc;
+        Bitmap::ScopedReadAccess                       m_pBmpAcc;
+        Bitmap::ScopedReadAccess                       m_pAlphaAcc;
         css::uno::Sequence<sal_Int8>                   m_aComponentTags;
         css::uno::Sequence<sal_Int32>                  m_aComponentBitCounts;
         css::rendering::IntegerBitmapLayout            m_aLayout;
diff --git a/vcl/source/bitmap/BitmapProcessor.cxx b/vcl/source/bitmap/BitmapProcessor.cxx
index 91b46bc..b3cdf86 100644
--- a/vcl/source/bitmap/BitmapProcessor.cxx
+++ b/vcl/source/bitmap/BitmapProcessor.cxx
@@ -19,8 +19,8 @@ BitmapEx BitmapProcessor::createLightImage(const BitmapEx& rBitmapEx)
     Bitmap aBitmap(rBitmapEx.GetBitmap());
     Bitmap aDarkBitmap(aSize, 24);
 
-    BitmapReadAccess* pRead(aBitmap.AcquireReadAccess());
-    BitmapWriteAccess* pWrite(aDarkBitmap.AcquireWriteAccess());
+    Bitmap::ScopedReadAccess pRead(aBitmap);
+    Bitmap::ScopedWriteAccess pWrite(aDarkBitmap);
 
     if (pRead && pWrite)
     {
@@ -49,8 +49,8 @@ BitmapEx BitmapProcessor::createLightImage(const BitmapEx& rBitmapEx)
             }
         }
     }
-    Bitmap::ReleaseAccess(pWrite);
-    Bitmap::ReleaseAccess(pRead);
+    pWrite.reset();
+    pRead.reset();
 
     return BitmapEx(aDarkBitmap, rBitmapEx.GetAlpha());
 }
@@ -70,17 +70,17 @@ BitmapEx BitmapProcessor::createDisabledImage(const BitmapEx& rBitmapEx)
     AlphaMask aGreyAlpha(aSize);
 
     Bitmap aBitmap(rBitmapEx.GetBitmap());
-    BitmapReadAccess* pRead(aBitmap.AcquireReadAccess());
+    Bitmap::ScopedReadAccess pRead(aBitmap);
 
-    BitmapWriteAccess* pGrey(aGrey.AcquireWriteAccess());
-    BitmapWriteAccess* pGreyAlpha(aGreyAlpha.AcquireWriteAccess());
+    Bitmap::ScopedWriteAccess pGrey(aGrey);
+    AlphaMask::ScopedWriteAccess pGreyAlpha(aGreyAlpha);
 
     BitmapEx aReturnBitmap;
 
     if (rBitmapEx.IsTransparent())
     {
         AlphaMask aBitmapAlpha(rBitmapEx.GetAlpha());
-        BitmapReadAccess* pReadAlpha(aBitmapAlpha.AcquireReadAccess());
+        AlphaMask::ScopedReadAccess pReadAlpha(aBitmapAlpha);
 
         if (pRead && pReadAlpha && pGrey && pGreyAlpha)
         {
@@ -101,7 +101,7 @@ BitmapEx BitmapProcessor::createDisabledImage(const BitmapEx& rBitmapEx)
                 }
             }
         }
-        aBitmapAlpha.ReleaseAccess(pReadAlpha);
+        pReadAlpha.reset();
         aReturnBitmap = BitmapEx(aGrey, aGreyAlpha);
     }
     else
@@ -126,10 +126,9 @@ BitmapEx BitmapProcessor::createDisabledImage(const BitmapEx& rBitmapEx)
         aReturnBitmap = BitmapEx(aGrey);
     }
 
-    Bitmap::ReleaseAccess(pRead);
-
-    Bitmap::ReleaseAccess(pGrey);
-    aGreyAlpha.ReleaseAccess(pGreyAlpha);
+    pRead.reset();
+    pGrey.reset();
+    pGreyAlpha.reset();
 
     return aReturnBitmap;
 }
diff --git a/vcl/source/bitmap/BitmapScaleConvolution.cxx b/vcl/source/bitmap/BitmapScaleConvolution.cxx
index abdc475..6149573 100644
--- a/vcl/source/bitmap/BitmapScaleConvolution.cxx
+++ b/vcl/source/bitmap/BitmapScaleConvolution.cxx
@@ -96,7 +96,7 @@ bool ImplScaleConvolutionHor(Bitmap& rSource, Bitmap& rTarget, const double& rSc
         return true;
     }
 
-    BitmapReadAccess* pReadAcc = rSource.AcquireReadAccess();
+    Bitmap::ScopedReadAccess pReadAcc(rSource);
 
     if(pReadAcc)
     {
@@ -108,7 +108,7 @@ bool ImplScaleConvolutionHor(Bitmap& rSource, Bitmap& rTarget, const double& rSc
         const long nHeight(rSource.GetSizePixel().Height());
         ImplCalculateContributions(nWidth, nNewWidth, aNumberOfContributions, pWeights, pPixels, pCount, aKernel);
         rTarget = Bitmap(Size(nNewWidth, nHeight), 24);
-        BitmapWriteAccess* pWriteAcc = rTarget.AcquireWriteAccess();
+        Bitmap::ScopedWriteAccess pWriteAcc(rTarget);
         bool bResult(nullptr != pWriteAcc);
 
         if(bResult)
@@ -154,10 +154,9 @@ bool ImplScaleConvolutionHor(Bitmap& rSource, Bitmap& rTarget, const double& rSc
                 }
             }
 
-            Bitmap::ReleaseAccess(pWriteAcc);
+            pWriteAcc.reset();
         }
 
-        Bitmap::ReleaseAccess(pReadAcc);
         delete[] pWeights;
         delete[] pCount;
         delete[] pPixels;
@@ -183,7 +182,7 @@ bool ImplScaleConvolutionVer(Bitmap& rSource, Bitmap& rTarget, const double& rSc
         return true;
     }
 
-    BitmapReadAccess* pReadAcc = rSource.AcquireReadAccess();
+    Bitmap::ScopedReadAccess pReadAcc(rSource);
 
     if(pReadAcc)
     {
@@ -195,7 +194,7 @@ bool ImplScaleConvolutionVer(Bitmap& rSource, Bitmap& rTarget, const double& rSc
         const long nWidth(rSource.GetSizePixel().Width());
         ImplCalculateContributions(nHeight, nNewHeight, aNumberOfContributions, pWeights, pPixels, pCount, aKernel);
         rTarget = Bitmap(Size(nWidth, nNewHeight), 24);
-        BitmapWriteAccess* pWriteAcc = rTarget.AcquireWriteAccess();
+        Bitmap::ScopedWriteAccess pWriteAcc(rTarget);
         bool bResult(nullptr != pWriteAcc);
 
         if(pWriteAcc)
@@ -249,9 +248,6 @@ bool ImplScaleConvolutionVer(Bitmap& rSource, Bitmap& rTarget, const double& rSc
             }
         }
 
-        Bitmap::ReleaseAccess(pWriteAcc);
-        Bitmap::ReleaseAccess(pReadAcc);
-
         delete[] pWeights;
         delete[] pCount;
         delete[] pPixels;
diff --git a/vcl/source/helper/canvasbitmap.cxx b/vcl/source/helper/canvasbitmap.cxx
index 3c1b951..cbf0524 100644
--- a/vcl/source/helper/canvasbitmap.cxx
+++ b/vcl/source/helper/canvasbitmap.cxx
@@ -98,8 +98,7 @@ VclCanvasBitmap::VclCanvasBitmap( const BitmapEx& rBitmap ) :
     m_aBmpEx( rBitmap ),
     m_aBitmap( rBitmap.GetBitmap() ),
     m_aAlpha(),
-    m_pBmpAcc( m_aBitmap.AcquireReadAccess() ),
-    m_pAlphaAcc( nullptr ),
+    m_pBmpAcc( m_aBitmap ),
     m_aComponentTags(),
     m_aComponentBitCounts(),
     m_aLayout(),
@@ -116,7 +115,7 @@ VclCanvasBitmap::VclCanvasBitmap( const BitmapEx& rBitmap ) :
     if( m_aBmpEx.IsTransparent() )
     {
         m_aAlpha = m_aBmpEx.IsAlpha() ? m_aBmpEx.GetAlpha().GetBitmap() : m_aBmpEx.GetMask();
-        m_pAlphaAcc = m_aAlpha.AcquireReadAccess();
+        m_pAlphaAcc = Bitmap::ScopedReadAccess(m_aAlpha);
     }
 
     m_aLayout.ScanLines      = 0;
@@ -423,10 +422,6 @@ VclCanvasBitmap::VclCanvasBitmap( const BitmapEx& rBitmap ) :
 
 VclCanvasBitmap::~VclCanvasBitmap()
 {
-    if( m_pAlphaAcc )
-        Bitmap::ReleaseAccess(m_pAlphaAcc);
-    if( m_pBmpAcc )
-        Bitmap::ReleaseAccess(m_pBmpAcc);
 }
 
 // XBitmap
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index e536b22..cbf4416 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -1409,14 +1409,14 @@ Bitmap OutputDevice::BlendBitmapWithAlpha(
     mpAlphaVDev->EnableMapMode(false);
 
     Bitmap aAlphaBitmap( mpAlphaVDev->GetBitmap( aDstRect.TopLeft(), aDstRect.GetSize() ) );
-    BitmapWriteAccess*  pAlphaW = aAlphaBitmap.AcquireWriteAccess();
+    Bitmap::ScopedWriteAccess pAlphaW(aAlphaBitmap);
 
     if( GetBitCount() <= 8 )
     {
         Bitmap              aDither( aBmp.GetSizePixel(), 8 );
         BitmapColor         aIndex( 0 );
-        BitmapReadAccess*   pB = aBmp.AcquireReadAccess();
-        BitmapWriteAccess*  pW = aDither.AcquireWriteAccess();
+        Bitmap::ScopedReadAccess pB(aBmp);
+        Bitmap::ScopedWriteAccess pW(aDither);
 
         if (pB && pP && pA && pW && pAlphaW)
         {
@@ -1433,7 +1433,7 @@ Bitmap OutputDevice::BlendBitmapWithAlpha(
                     const long  nMapX = pMapX[ nX ];
                     const sal_uLong nD = nVCLDitherLut[ nModY | ( nOutX & 0x0FL ) ];
 
-                    aDstCol = AlphaBlend( nX, nY, nMapX, nMapY, pP, pA, pB, pAlphaW, nResAlpha );
+                    aDstCol = AlphaBlend( nX, nY, nMapX, nMapY, pP, pA, pB.get(), pAlphaW.get(), nResAlpha );
 
                     aIndex.SetIndex( (sal_uInt8) ( nVCLRLut[ ( nVCLLut[ aDstCol.GetRed() ] + nD ) >> 16UL ] +
                                               nVCLGLut[ ( nVCLLut[ aDstCol.GetGreen() ] + nD ) >> 16UL ] +
@@ -1447,14 +1447,13 @@ Bitmap OutputDevice::BlendBitmapWithAlpha(
                 }
             }
         }
-
-        Bitmap::ReleaseAccess( pB );
-        Bitmap::ReleaseAccess( pW );
+        pB.reset();
+        pW.reset();
         res = aDither;
     }
     else
     {
-        BitmapWriteAccess*  pB = aBmp.AcquireWriteAccess();
+        Bitmap::ScopedWriteAccess pB(aBmp);
         if (pB && pP && pA && pAlphaW)
         {
             for( nY = 0; nY < nDstHeight; nY++ )
@@ -1464,19 +1463,18 @@ Bitmap OutputDevice::BlendBitmapWithAlpha(
                 for( nX = 0; nX < nDstWidth; nX++ )
                 {
                     const long nMapX = pMapX[ nX ];
-                    aDstCol = AlphaBlend( nX, nY, nMapX, nMapY, pP, pA, pB, pAlphaW, nResAlpha );
+                    aDstCol = AlphaBlend( nX, nY, nMapX, nMapY, pP, pA, pB.get(), pAlphaW.get(), nResAlpha );
 
                     pB->SetPixel( nY, nX, aDstCol );
                     pAlphaW->SetPixel( nY, nX, Color(255L-nResAlpha, 255L-nResAlpha, 255L-nResAlpha) );
                 }
             }
         }
-
-        Bitmap::ReleaseAccess( pB );
+        pB.reset();
         res = aBmp;
     }
 
-    Bitmap::ReleaseAccess( pAlphaW );
+    pAlphaW.reset();
     mpAlphaVDev->DrawBitmap( aDstRect.TopLeft(), aAlphaBitmap );
     mpAlphaVDev->EnableMapMode( bOldMapMode );
 
@@ -1506,8 +1504,8 @@ Bitmap OutputDevice::BlendBitmap(
     {
         Bitmap              aDither( aBmp.GetSizePixel(), 8 );
         BitmapColor         aIndex( 0 );
-        BitmapReadAccess*   pB = aBmp.AcquireReadAccess();
-        BitmapWriteAccess*  pW = aDither.AcquireWriteAccess();
+        Bitmap::ScopedReadAccess pB(aBmp);
+        Bitmap::ScopedWriteAccess pW(aDither);
 
         if( pB && pP && pA && pW )
         {
@@ -1542,13 +1540,13 @@ Bitmap OutputDevice::BlendBitmap(
             }
         }
 
-        Bitmap::ReleaseAccess( pB );
-        Bitmap::ReleaseAccess( pW );
+        pB.reset();
+        pW.reset();
         res = aDither;
     }
     else
     {
-        BitmapWriteAccess*  pB = aBmp.AcquireWriteAccess();
+        Bitmap::ScopedWriteAccess pB(aBmp);
 
         bool bFastBlend = false;
         if( pP && pA && pB )
@@ -1625,7 +1623,7 @@ Bitmap OutputDevice::BlendBitmap(
             }
         }
 
-        Bitmap::ReleaseAccess( pB );
+        pB.reset();
         res = aBmp;
     }
 
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index e27974b..6e034a1 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -2522,7 +2522,7 @@ bool OutputDevice::GetTextBoundRect( Rectangle& rRect,
 
     // find extents using the bitmap
     Bitmap aBmp = aVDev->GetBitmap( Point(), aOutSize );
-    BitmapReadAccess* pAcc = aBmp.AcquireReadAccess();
+    Bitmap::ScopedReadAccess pAcc(aBmp);
     if( !pAcc )
         return false;
     const BitmapColor aBlack( pAcc->GetBestMatchingColor( Color( COL_BLACK ) ) );
@@ -2575,7 +2575,7 @@ bool OutputDevice::GetTextBoundRect( Rectangle& rRect,
         nRight = nX;
     }
 
-    Bitmap::ReleaseAccess( pAcc );
+    pAcc.reset();
 
     if( nTop <= nBottom )
     {
diff --git a/vcl/source/outdev/transparent.cxx b/vcl/source/outdev/transparent.cxx
index ace38d6..cfb3572 100644
--- a/vcl/source/outdev/transparent.cxx
+++ b/vcl/source/outdev/transparent.cxx
@@ -466,8 +466,8 @@ void OutputDevice::EmulateDrawTransparent ( const tools::PolyPolygon& rPolyPoly,
                 // #107766# check for non-empty bitmaps before accessing them
                 if( !!aPaint && !!aPolyMask )
                 {
-                    BitmapWriteAccess* pW = aPaint.AcquireWriteAccess();
-                    BitmapReadAccess* pR = aPolyMask.AcquireReadAccess();
+                    Bitmap::ScopedWriteAccess pW(aPaint);
+                    Bitmap::ScopedReadAccess pR(aPolyMask);
 
                     if( pW && pR )
                     {
@@ -579,8 +579,8 @@ void OutputDevice::EmulateDrawTransparent ( const tools::PolyPolygon& rPolyPoly,
                         }
                     }
 
-                    Bitmap::ReleaseAccess( pR );
-                    Bitmap::ReleaseAccess( pW );
+                    pR.reset();
+                    pW.reset();
 
                     DrawBitmap( aDstRect.TopLeft(), aPaint );
 


More information about the Libreoffice-commits mailing list