diff options
author | Mark Page <aptitude@btconnect.com> | 2016-12-01 13:53:30 +0000 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2016-12-02 11:18:16 +0000 |
commit | 677246466c471fbe3522c35be3639afa008a46c0 (patch) | |
tree | ccee5e72c1b274d3c51c0f4d11c369270de11fe4 /vcl | |
parent | 4d2c210c74567d9af6bededf3fae6bfd62406f14 (diff) |
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@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/canvasbitmap.hxx | 4 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapProcessor.cxx | 25 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapScaleConvolution.cxx | 14 | ||||
-rw-r--r-- | vcl/source/helper/canvasbitmap.cxx | 9 | ||||
-rw-r--r-- | vcl/source/outdev/bitmap.cxx | 34 | ||||
-rw-r--r-- | vcl/source/outdev/text.cxx | 4 | ||||
-rw-r--r-- | vcl/source/outdev/transparent.cxx | 8 |
7 files changed, 43 insertions, 55 deletions
diff --git a/vcl/inc/canvasbitmap.hxx b/vcl/inc/canvasbitmap.hxx index 292c432debcf..0b5dba96f6c7 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 91b46bcb8100..b3cdf86783d0 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 abdc475d45cb..6149573953f4 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 3c1b95129303..cbf05245d343 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 e536b22ec5b3..cbf44167608a 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 e27974b060c0..6e034a122ca6 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 ace38d6f944d..cfb3572e36bb 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 ); |