diff options
author | David Tardon <dtardon@redhat.com> | 2011-05-17 10:03:46 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2011-05-18 06:06:35 +0200 |
commit | 87fbe86b7140a77cc6e38f063b08af9213078ca3 (patch) | |
tree | cc3dec63d481f9774ec1d7089a4c8c828c44a53f | |
parent | eaea49187f4ea29bba32042ef8aeced45304773b (diff) |
generalize ScopedBitmapAccess and simplify usage
It can be used for AlphaMask too now.
-rw-r--r-- | basebmp/test/bmpdemo.cxx | 3 | ||||
-rw-r--r-- | canvas/source/directx/dx_vcltools.cxx | 9 | ||||
-rw-r--r-- | canvas/source/vcl/canvasbitmaphelper.cxx | 20 | ||||
-rw-r--r-- | canvas/source/vcl/canvashelper.cxx | 9 | ||||
-rw-r--r-- | canvas/source/vcl/impltools.cxx | 11 | ||||
-rw-r--r-- | vcl/inc/vcl/alpha.hxx | 5 | ||||
-rw-r--r-- | vcl/inc/vcl/bitmap.hxx | 6 | ||||
-rw-r--r-- | vcl/inc/vcl/bmpacc.hxx | 67 | ||||
-rw-r--r-- | vcl/inc/vcl/scopedbitmapaccess.hxx | 94 | ||||
-rw-r--r-- | vcl/prj/d.lst | 1 | ||||
-rw-r--r-- | vcl/source/helper/canvastools.cxx | 9 | ||||
-rw-r--r-- | vcl/test/canvasbitmaptest.cxx | 12 |
12 files changed, 133 insertions, 113 deletions
diff --git a/basebmp/test/bmpdemo.cxx b/basebmp/test/bmpdemo.cxx index ab260655d968..effce214bb2f 100644 --- a/basebmp/test/bmpdemo.cxx +++ b/basebmp/test/bmpdemo.cxx @@ -1189,8 +1189,7 @@ void TestWindow::Paint( const Rectangle& /*rRect*/ ) // Fill bitmap with generated content { - ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), - aBitmap ); + Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); for( int y=0; y<aTestSize.getY(); ++y ) for( int x=0; x<aTestSize.getX(); ++x ) pWriteAccess->SetPixel(y,x, diff --git a/canvas/source/directx/dx_vcltools.cxx b/canvas/source/directx/dx_vcltools.cxx index 0801ad81c780..aec1b4307791 100644 --- a/canvas/source/directx/dx_vcltools.cxx +++ b/canvas/source/directx/dx_vcltools.cxx @@ -178,8 +178,7 @@ namespace dxcanvas Bitmap aBitmap( rBmpEx.GetBitmap() ); - ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), - aBitmap ); + Bitmap::ScopedReadAccess pReadAccess( aBitmap ); const sal_Int32 nWidth( aBmpSize.Width() ); const sal_Int32 nHeight( aBmpSize.Height() ); @@ -192,8 +191,7 @@ namespace dxcanvas { Bitmap aAlpha( rBmpEx.GetAlpha().GetBitmap() ); - ScopedBitmapReadAccess pAlphaReadAccess( aAlpha.AcquireReadAccess(), - aAlpha ); + Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha ); // By convention, the access buffer always has // one of the following formats: @@ -335,8 +333,7 @@ namespace dxcanvas { Bitmap aMask( rBmpEx.GetMask() ); - ScopedBitmapReadAccess pMaskReadAccess( aMask.AcquireReadAccess(), - aMask ); + Bitmap::ScopedReadAccess pMaskReadAccess( aMask ); // By convention, the access buffer always has // one of the following formats: diff --git a/canvas/source/vcl/canvasbitmaphelper.cxx b/canvas/source/vcl/canvasbitmaphelper.cxx index 38dcc9e844e8..2c5a9ff0f220 100644 --- a/canvas/source/vcl/canvasbitmaphelper.cxx +++ b/canvas/source/vcl/canvasbitmaphelper.cxx @@ -149,9 +149,8 @@ namespace vclcanvas Bitmap aBitmap( mpBackBuffer->getBitmapReference().GetBitmap() ); Bitmap aAlpha( mpBackBuffer->getBitmapReference().GetAlpha().GetBitmap() ); - ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), - aBitmap ); - ScopedBitmapReadAccess pAlphaReadAccess( aAlpha.IsEmpty() ? + Bitmap::ScopedReadAccess pReadAccess( aBitmap ); + Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha.IsEmpty() ? (BitmapReadAccess*)NULL : aAlpha.AcquireReadAccess(), aAlpha ); @@ -229,9 +228,8 @@ namespace vclcanvas // actually changed a pixel { - ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), - aBitmap ); - ScopedBitmapWriteAccess pAlphaWriteAccess( aAlpha.IsEmpty() ? + Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); + Bitmap::ScopedWriteAccess pAlphaWriteAccess( aAlpha.IsEmpty() ? (BitmapWriteAccess*)NULL : aAlpha.AcquireWriteAccess(), aAlpha ); @@ -471,9 +469,8 @@ namespace vclcanvas // actually changed a pixel { - ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), - aBitmap ); - ScopedBitmapWriteAccess pAlphaWriteAccess( aAlpha.IsEmpty() ? + Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); + Bitmap::ScopedWriteAccess pAlphaWriteAccess( aAlpha.IsEmpty() ? (BitmapWriteAccess*)NULL : aAlpha.AcquireWriteAccess(), aAlpha ); @@ -525,9 +522,8 @@ namespace vclcanvas Bitmap aBitmap( mpBackBuffer->getBitmapReference().GetBitmap() ); Bitmap aAlpha( mpBackBuffer->getBitmapReference().GetAlpha().GetBitmap() ); - ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), - aBitmap ); - ScopedBitmapReadAccess pAlphaReadAccess( aAlpha.IsEmpty() ? + Bitmap::ScopedReadAccess pReadAccess( aBitmap ); + Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha.IsEmpty() ? (BitmapReadAccess*)NULL : aAlpha.AcquireReadAccess(), aAlpha ); ENSURE_OR_THROW( pReadAccess.get() != NULL, diff --git a/canvas/source/vcl/canvashelper.cxx b/canvas/source/vcl/canvashelper.cxx index 6fb918df8f1c..38185d812fb5 100644 --- a/canvas/source/vcl/canvashelper.cxx +++ b/canvas/source/vcl/canvashelper.cxx @@ -948,8 +948,7 @@ namespace vclcanvas Bitmap aBitmap( rOutDev.GetBitmap(aRect.TopLeft(), aRect.GetSize()) ); - ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), - aBitmap ); + Bitmap::ScopedReadAccess pReadAccess( aBitmap ); ENSURE_OR_THROW( pReadAccess.get() != NULL, "Could not acquire read access to OutDev bitmap" ); @@ -1014,8 +1013,7 @@ namespace vclcanvas Bitmap aTmpBitmap( rOutDev.GetBitmap( aEmptyPoint, aSize ) ); - ScopedBitmapReadAccess pReadAccess( aTmpBitmap.AcquireReadAccess(), - aTmpBitmap ); + Bitmap::ScopedReadAccess pReadAccess( aTmpBitmap ); pPalette = &pReadAccess->GetPalette(); } @@ -1026,8 +1024,7 @@ namespace vclcanvas bool bCopyBack( false ); // only copy something back, if we // actually changed some pixel { - ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), - aBitmap ); + Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); ENSURE_OR_THROW( pWriteAccess.get() != NULL, "Could not acquire write access to OutDev bitmap" ); diff --git a/canvas/source/vcl/impltools.cxx b/canvas/source/vcl/impltools.cxx index 24f32aadc237..a8187766e15b 100644 --- a/canvas/source/vcl/impltools.cxx +++ b/canvas/source/vcl/impltools.cxx @@ -277,9 +277,8 @@ namespace vclcanvas aSrcAlpha = rBitmap.GetMask(); } - ScopedBitmapReadAccess pReadAccess( aSrcBitmap.AcquireReadAccess(), - aSrcBitmap ); - ScopedBitmapReadAccess pAlphaReadAccess( rBitmap.IsTransparent() ? + Bitmap::ScopedReadAccess pReadAccess( aSrcBitmap ); + Bitmap::ScopedReadAccess pAlphaReadAccess( rBitmap.IsTransparent() ? aSrcAlpha.AcquireReadAccess() : (BitmapReadAccess*)NULL, aSrcAlpha ); @@ -334,10 +333,8 @@ namespace vclcanvas // copy-constructing the resulting bitmap. This will // rule out the possibility that cached accessor data // is not yet written back. - ScopedBitmapWriteAccess pWriteAccess( aDstBitmap.AcquireWriteAccess(), - aDstBitmap ); - ScopedBitmapWriteAccess pAlphaWriteAccess( aDstAlpha.AcquireWriteAccess(), - aDstAlpha ); + Bitmap::ScopedWriteAccess pWriteAccess( aDstBitmap ); + Bitmap::ScopedWriteAccess pAlphaWriteAccess( aDstAlpha ); if( pWriteAccess.get() != NULL && diff --git a/vcl/inc/vcl/alpha.hxx b/vcl/inc/vcl/alpha.hxx index 8bcaf3789528..c6f5dd8043fe 100644 --- a/vcl/inc/vcl/alpha.hxx +++ b/vcl/inc/vcl/alpha.hxx @@ -100,6 +100,11 @@ public: BitmapWriteAccess* AcquireWriteAccess() { return Bitmap::AcquireWriteAccess(); } void ReleaseAccess( BitmapReadAccess* pAccess ); + typedef vcl::ScopedBitmapAccess< BitmapReadAccess, AlphaMask, &AlphaMask::AcquireReadAccess > + ScopedReadAccess; + typedef vcl::ScopedBitmapAccess< BitmapWriteAccess, AlphaMask, &AlphaMask::AcquireWriteAccess > + ScopedWriteAccess; + public: sal_Bool Read( SvStream& rIStm, sal_Bool bFileHeader = sal_True ) { return Bitmap::Read( rIStm, bFileHeader ); } diff --git a/vcl/inc/vcl/bitmap.hxx b/vcl/inc/vcl/bitmap.hxx index d514977fda38..a1473d8cbbf0 100644 --- a/vcl/inc/vcl/bitmap.hxx +++ b/vcl/inc/vcl/bitmap.hxx @@ -34,6 +34,7 @@ #include <vcl/mapmod.hxx> #include <tools/rc.hxx> #include <vcl/region.hxx> +#include <vcl/scopedbitmapaccess.hxx> // ----------- // - Defines - @@ -752,6 +753,11 @@ public: BitmapWriteAccess* AcquireWriteAccess(); void ReleaseAccess( BitmapReadAccess* pAccess ); + typedef vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess > + ScopedReadAccess; + typedef vcl::ScopedBitmapAccess< BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess > + ScopedWriteAccess; + public: sal_Bool Read( SvStream& rIStm, sal_Bool bFileHeader = sal_True, sal_Bool bMSOFormat = sal_False ); diff --git a/vcl/inc/vcl/bmpacc.hxx b/vcl/inc/vcl/bmpacc.hxx index 650a60a69077..d98ff2cfe8dc 100644 --- a/vcl/inc/vcl/bmpacc.hxx +++ b/vcl/inc/vcl/bmpacc.hxx @@ -34,7 +34,6 @@ #include <vcl/salbtype.hxx> #include <vcl/bitmap.hxx> - // -------------------- // - Access defines - // -------------------- @@ -226,72 +225,6 @@ private: BitmapWriteAccess& operator=( const BitmapWriteAccess& ) { return *this; } }; -// ------------------- -// - Accessor Helper - -// ------------------- - -/** This template handles BitmapAccess the RAII way. - - Please don't use directly, but the ready-made typedefs for - BitmapReadAccess and BitmapWriteAccess below. - */ -template < class Access > class ScopedBitmapAccess -{ -public: - ScopedBitmapAccess( Access* pAccess, - Bitmap& rBitmap ) : - mpAccess( pAccess ), - mrBitmap( rBitmap ) - { - } - - ~ScopedBitmapAccess() - { - mrBitmap.ReleaseAccess( mpAccess ); - } - - Access* get() { return mpAccess; } - const Access* get() const { return mpAccess; } - - Access* operator->() { return mpAccess; } - const Access* operator->() const { return mpAccess; } - - Access& operator*() { return *mpAccess; } - const Access& operator*() const { return *mpAccess; } - -private: - Access* mpAccess; - Bitmap& mrBitmap; -}; - -/** This wrapper handles BitmapReadAccess the RAII way. - - Use as follows: - Bitmap aBitmap - ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), aBitmap ); - pReadAccess->SetPixel()... - - @attention for practical reasons, ScopedBitmapReadAccess stores a - reference to the provided bitmap, thus, make sure that the bitmap - specified at construction time lives at least as long as the - ScopedBitmapReadAccess. -*/ -typedef ScopedBitmapAccess< BitmapReadAccess > ScopedBitmapReadAccess; - -/** This wrapper handles BitmapWriteAccess the RAII way. - - Use as follows: - Bitmap aBitmap - ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), aBitmap ); - pWriteAccess->SetPixel()... - - @attention for practical reasons, ScopedBitmapWriteAccess stores a - reference to the provided bitmap, thus, make sure that the bitmap - specified at construction time lives at least as long as the - ScopedBitmapWriteAccess. -*/ -typedef ScopedBitmapAccess< BitmapWriteAccess > ScopedBitmapWriteAccess; - // ----------- // - Inlines - // ----------- diff --git a/vcl/inc/vcl/scopedbitmapaccess.hxx b/vcl/inc/vcl/scopedbitmapaccess.hxx new file mode 100644 index 000000000000..130b9563c163 --- /dev/null +++ b/vcl/inc/vcl/scopedbitmapaccess.hxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VCL_SCOPEDBITMAPACCESS_HXX_INCLUDED +#define VCL_SCOPEDBITMAPACCESS_HXX_INCLUDED + +namespace vcl +{ + +/** This template handles BitmapAccess the RAII way. + + Please don't use directly, but through the ready-made typedefs + ScopedReadAccess and ScopedWriteAccess in classes Bitmap and + AlphaMask. + + Use as follows: + Bitmap aBitmap; + Bitmap::ScopedReadAccess pReadAccess( aBitmap ); + pReadAccess->SetPixel()... + + Bitmap aBitmap2; + Bitmap::ScopedWriteAccess pWriteAccess( bCond ? aBitmap2.AcquireWriteAccess() : 0, aBitmap2 ); + if ( pWriteAccess )... + + @attention for practical reasons, ScopedBitmapAccess stores a + reference to the provided bitmap, thus, make sure that the bitmap + specified at construction time lives at least as long as the + ScopedBitmapAccess. + */ +template < class Access, class Bitmap, Access* (Bitmap::* Acquire)() > class ScopedBitmapAccess +{ +public: + explicit ScopedBitmapAccess( Bitmap& rBitmap ) : + mpAccess( 0 ), + mrBitmap( rBitmap ) + { + mpAccess = (mrBitmap.*Acquire)(); + } + + ScopedBitmapAccess( Access* pAccess, Bitmap& rBitmap ) : + mpAccess( pAccess ), + mrBitmap( rBitmap ) + { + } + + ~ScopedBitmapAccess() + { + mrBitmap.ReleaseAccess( mpAccess ); + } + + Access* get() { return mpAccess; } + const Access* get() const { return mpAccess; } + + Access* operator->() { return mpAccess; } + const Access* operator->() const { return mpAccess; } + + Access& operator*() { return *mpAccess; } + const Access& operator*() const { return *mpAccess; } + +private: + Access* mpAccess; + Bitmap& mrBitmap; +}; + +} + +#endif // VCL_SCOPEDBITMAPACCESS_HXX_INCLUDED + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/prj/d.lst b/vcl/prj/d.lst index 00b703cf43b9..3626a3ee36bd 100644 --- a/vcl/prj/d.lst +++ b/vcl/prj/d.lst @@ -97,6 +97,7 @@ mkdir: %_DEST%\inc%_EXT%\vcl ..\inc\vcl\salgtype.hxx %_DEST%\inc%_EXT%\vcl\salgtype.hxx ..\inc\vcl\salstype.hxx %_DEST%\inc%_EXT%\vcl\salstype.hxx ..\inc\vcl\salnativewidgets.hxx %_DEST%\inc%_EXT%\vcl\salnativewidgets.hxx +..\inc\vcl\scopedbitmapaccess.hxx %_DEST%\inc%_EXT%\vcl\scopedbitmapaccess.hxx ..\inc\vcl\scrbar.hxx %_DEST%\inc%_EXT%\vcl\scrbar.hxx ..\inc\vcl\seleng.hxx %_DEST%\inc%_EXT%\vcl\seleng.hxx ..\inc\vcl\settings.hxx %_DEST%\inc%_EXT%\vcl\settings.hxx diff --git a/vcl/source/helper/canvastools.cxx b/vcl/source/helper/canvastools.cxx index 3bf73ca7588d..757a830b8360 100644 --- a/vcl/source/helper/canvastools.cxx +++ b/vcl/source/helper/canvastools.cxx @@ -220,8 +220,8 @@ namespace vcl sal_Int32 nHeight, const rendering::IntegerBitmapLayout& rLayout, const uno::Reference< rendering::XIntegerReadOnlyBitmap >& xInputBitmap, - ScopedBitmapWriteAccess& rWriteAcc, - ScopedBitmapWriteAccess& rAlphaAcc ) + Bitmap::ScopedWriteAccess& rWriteAcc, + Bitmap::ScopedWriteAccess& rAlphaAcc ) { rendering::IntegerBitmapLayout aCurrLayout; geometry::IntegerRectangle2D aRect; @@ -433,9 +433,8 @@ namespace vcl sal::static_int_cast<sal_uInt16>(1L << nAlphaDepth)) ); { // limit scoped access - ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), - aBitmap ); - ScopedBitmapWriteAccess pAlphaWriteAccess( nAlphaDepth ? aAlpha.AcquireWriteAccess() : NULL, + Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); + Bitmap::ScopedWriteAccess pAlphaWriteAccess( nAlphaDepth ? aAlpha.AcquireWriteAccess() : NULL, aAlpha ); ENSURE_OR_THROW(pWriteAccess.get() != NULL, diff --git a/vcl/test/canvasbitmaptest.cxx b/vcl/test/canvasbitmaptest.cxx index 3763fb5b9d02..aa3d524fdf6c 100644 --- a/vcl/test/canvasbitmaptest.cxx +++ b/vcl/test/canvasbitmaptest.cxx @@ -173,8 +173,7 @@ void checkCanvasBitmap( const rtl::Reference<VclCanvasBitmap>& xBmp, int nDepth = nOriginalDepth; { - ScopedBitmapReadAccess pAcc( aContainedBmp.AcquireReadAccess(), - aContainedBmp ); + Bitmap::ScopedReadAccess pAcc( aContainedBmp ); nDepth = pAcc->GetBitCount(); } @@ -324,8 +323,7 @@ void checkBitmapImport( const rtl::Reference<VclCanvasBitmap>& xBmp, int nDepth = nOriginalDepth; { - ScopedBitmapReadAccess pAcc( aContainedBmp.AcquireReadAccess(), - aContainedBmp ); + Bitmap::ScopedReadAccess pAcc( aContainedBmp ); nDepth = pAcc->GetBitCount(); } @@ -888,8 +886,7 @@ void TestWindow::Paint( const Rectangle& ) Bitmap aBitmap(Size(200,200),nDepth); aBitmap.Erase(COL_WHITE); { - ScopedBitmapWriteAccess pAcc(aBitmap.AcquireWriteAccess(), - aBitmap); + Bitmap::ScopedWriteAccess pAcc(aBitmap); if( pAcc.get() ) { BitmapColor aBlack(0); @@ -919,8 +916,7 @@ void TestWindow::Paint( const Rectangle& ) Bitmap aMask(Size(200,200),1); aMask.Erase(COL_WHITE); { - ScopedBitmapWriteAccess pAcc(aMask.AcquireWriteAccess(), - aMask); + Bitmap::ScopedWriteAccess pAcc(aMask); if( pAcc.get() ) { pAcc->SetFillColor(COL_BLACK); |