diff options
author | Thorsten Behrens <tbehrens@suse.com> | 2011-11-02 12:28:13 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2011-11-02 23:58:27 +0100 |
commit | 3c1b4b6ef70b049bc5242149e727dd5d94111d86 (patch) | |
tree | 3b0182990f092b363a00f2bdae2b32c61730ae9d | |
parent | 207bcfc5b9d3e857741cd973c3ee9615bdeb2563 (diff) |
Keep basebmp free of naked ptrs.
Moved the implementation detail that SalFrames lifetime is handled
manually in vcl out of basebmp & into vcl. Added lightweight wrapper
class to decouple damagetracker lifetime from GtkFrame lifetime.
-rw-r--r-- | basebmp/inc/basebmp/bitmapdevice.hxx | 46 | ||||
-rw-r--r-- | basebmp/source/bitmapdevice.cxx | 144 | ||||
-rw-r--r-- | vcl/inc/unx/gtk/gtkframe.hxx | 2 | ||||
-rw-r--r-- | vcl/unx/gtk/window/gtkframe.cxx | 19 |
4 files changed, 123 insertions, 88 deletions
diff --git a/basebmp/inc/basebmp/bitmapdevice.hxx b/basebmp/inc/basebmp/bitmapdevice.hxx index 56101f34c5b9..99bb1b6a141a 100644 --- a/basebmp/inc/basebmp/bitmapdevice.hxx +++ b/basebmp/inc/basebmp/bitmapdevice.hxx @@ -55,15 +55,18 @@ namespace basebmp // Temporary. Use like the tools color object class Color; -typedef boost::shared_ptr< class BitmapDevice > BitmapDeviceSharedPtr; -typedef boost::shared_array< sal_uInt8 > RawMemorySharedArray; -typedef boost::shared_ptr< const std::vector<Color> > PaletteMemorySharedVector; +typedef boost::shared_ptr< class BitmapDevice > BitmapDeviceSharedPtr; +typedef boost::shared_ptr< class IBitmapDeviceDamageTracker > IBitmapDeviceDamageTrackerSharedPtr; +typedef boost::shared_array< sal_uInt8 > RawMemorySharedArray; +typedef boost::shared_ptr< const std::vector<Color> > PaletteMemorySharedVector; struct ImplBitmapDevice; -class BitmapDeviceDamageTracker { - public: - virtual void damaged (const basegfx::B2IRange& rDamageRect) = 0; +/// Interface for getting damage tracking events +struct IBitmapDeviceDamageTracker +{ + /// gets called when said region is clobbered + virtual void damaged(const basegfx::B2IRange& rDamageRect) const = 0; }; /** Definition of BitmapDevice interface @@ -114,7 +117,17 @@ public: */ RawMemorySharedArray getBuffer() const; - BitmapDeviceDamageTracker *getDamageTracker() const; + /// Query current damage tracking object (if any) + IBitmapDeviceDamageTrackerSharedPtr getDamageTracker() const; + + /** Set new damage tracking object + + @param rDamage + Object implementing the IBitmapDeviceDamageTracker interface - + everytime some area of the surface gets clobbered, that object + gets notified. + */ + void setDamageTracker( const IBitmapDeviceDamageTrackerSharedPtr& rDamage ); /** Get pointer to palette @@ -544,13 +557,12 @@ public: const BitmapDeviceSharedPtr& rClip ); protected: - BitmapDevice( const basegfx::B2IRange& rBounds, - sal_Int32 nScanlineFormat, - sal_Int32 nScanlineStride, - sal_uInt8* pFirstScanline, - const RawMemorySharedArray& rMem, - const PaletteMemorySharedVector& rPalette, - BitmapDeviceDamageTracker* pDamage = NULL ); + BitmapDevice( const basegfx::B2IRange& rBounds, + sal_Int32 nScanlineFormat, + sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, + const RawMemorySharedArray& rMem, + const PaletteMemorySharedVector& rPalette ); virtual ~BitmapDevice(); @@ -641,6 +653,9 @@ private: DrawMode drawMode, const BitmapDeviceSharedPtr& rClip ) = 0; + virtual IBitmapDeviceDamageTrackerSharedPtr getDamageTracker_i() const = 0; + virtual void setDamageTracker_i( const IBitmapDeviceDamageTrackerSharedPtr& rDamage ) = 0; + BitmapDeviceSharedPtr getGenericRenderer() const; boost::scoped_ptr< ImplBitmapDevice > mpImpl; @@ -650,8 +665,7 @@ private: */ BASEBMP_DLLPUBLIC BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, bool bTopDown, - sal_Int32 nScanlineFormat, - BitmapDeviceDamageTracker* pDamage = NULL ); + sal_Int32 nScanlineFormat ); /** Factory method to create a BitmapDevice for given scanline format with the given palette diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx index a483197aa54d..04829832af73 100644 --- a/basebmp/source/bitmapdevice.cxx +++ b/basebmp/source/bitmapdevice.cxx @@ -273,7 +273,7 @@ namespace dest_iterator_type maBegin; typename accessor_traits::color_lookup maColorLookup; - BitmapDeviceDamageTracker *mpDamage; + IBitmapDeviceDamageTrackerSharedPtr mpDamage; to_uint32_functor maToUInt32Converter; dest_accessor_type maAccessor; colorblend_accessor_type maColorBlendAccessor; @@ -292,22 +292,21 @@ namespace // ------------------------------------------------------- - BitmapRenderer( const basegfx::B2IRange& rBounds, - sal_Int32 nScanlineFormat, - sal_Int32 nScanlineStride, - sal_uInt8* pFirstScanline, - dest_iterator_type begin, - raw_accessor_type rawAccessor, - dest_accessor_type accessor, - const RawMemorySharedArray& rMem, - const PaletteMemorySharedVector& rPalette, - BitmapDeviceDamageTracker* pDamage ) : + BitmapRenderer( const basegfx::B2IRange& rBounds, + sal_Int32 nScanlineFormat, + sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, + dest_iterator_type begin, + raw_accessor_type rawAccessor, + dest_accessor_type accessor, + const RawMemorySharedArray& rMem, + const PaletteMemorySharedVector& rPalette, + const IBitmapDeviceDamageTrackerSharedPtr& rDamage ) : BitmapDevice( rBounds, nScanlineFormat, - nScanlineStride, pFirstScanline, rMem, rPalette, - pDamage ), + nScanlineStride, pFirstScanline, rMem, rPalette ), maBegin( begin ), maColorLookup(), - mpDamage( pDamage ), + mpDamage(rDamage), maToUInt32Converter(), maAccessor( accessor ), maColorBlendAccessor( accessor ), @@ -477,7 +476,7 @@ namespace col, begin, rawAcc ); - // FIXME: perhaps this needs pushing up the stack a bit + // TODO(P2): perhaps this needs pushing up the stack a bit // to make more complex polygons more efficient ... damaged( basegfx::B2IRange( rPt1, rPt2 ) ); } @@ -1023,6 +1022,15 @@ namespace } damaged( rDstRect ); } + + IBitmapDeviceDamageTrackerSharedPtr getDamageTracker_i() const + { + return mpDamage; + } + void setDamageTracker_i( const IBitmapDeviceDamageTrackerSharedPtr& rDamage ) + { + mpDamage = rDamage; + } }; } // namespace @@ -1034,8 +1042,6 @@ struct ImplBitmapDevice */ RawMemorySharedArray mpMem; - BitmapDeviceDamageTracker *mpDamage; - /// Palette memory plus deleter (might be NULL) PaletteMemorySharedVector mpPalette; @@ -1092,12 +1098,10 @@ BitmapDevice::BitmapDevice( const basegfx::B2IRange& rBounds, sal_Int32 nScanlineStride, sal_uInt8* pFirstScanline, const RawMemorySharedArray& rMem, - const PaletteMemorySharedVector& rPalette, - BitmapDeviceDamageTracker* pDamage ) : + const PaletteMemorySharedVector& rPalette ) : mpImpl( new ImplBitmapDevice ) { mpImpl->mpMem = rMem; - mpImpl->mpDamage = pDamage; mpImpl->mpPalette = rPalette; mpImpl->maBounds = rBounds; mpImpl->maLineClipRect = basegfx::B2IRange( rBounds.getMinX(), @@ -1142,14 +1146,19 @@ RawMemorySharedArray BitmapDevice::getBuffer() const return mpImpl->mpMem; } -PaletteMemorySharedVector BitmapDevice::getPalette() const +IBitmapDeviceDamageTrackerSharedPtr BitmapDevice::getDamageTracker() const { - return mpImpl->mpPalette; + return getDamageTracker_i(); +} + +void BitmapDevice::setDamageTracker( const IBitmapDeviceDamageTrackerSharedPtr& rDamage ) +{ + setDamageTracker_i(rDamage); } -BitmapDeviceDamageTracker *BitmapDevice::getDamageTracker() const +PaletteMemorySharedVector BitmapDevice::getPalette() const { - return mpImpl->mpDamage; + return mpImpl->mpPalette; } sal_Int32 BitmapDevice::getPaletteEntryCount() const @@ -1703,7 +1712,7 @@ BitmapDeviceSharedPtr createRenderer( typename FormatTraits::raw_accessor_type>::type const& rAccessor, boost::shared_array< sal_uInt8 > pMem, const PaletteMemorySharedVector& pPal, - BitmapDeviceDamageTracker* pDamage ) + const IBitmapDeviceDamageTrackerSharedPtr& pDamage ) #else template< class FormatTraits, class MaskTraits, class Accessor > @@ -1716,7 +1725,7 @@ BitmapDeviceSharedPtr createRenderer( Accessor const& rAccessor, boost::shared_array< sal_uInt8 > pMem, const PaletteMemorySharedVector& pPal, - BitmapDeviceDamageTracker* pDamage ) + const IBitmapDeviceDamageTrackerSharedPtr& pDamage ) #endif { @@ -1765,13 +1774,13 @@ PaletteMemorySharedVector createStandardPalette( template< class FormatTraits, class MaskTraits > BitmapDeviceSharedPtr createRenderer( - const basegfx::B2IRange& rBounds, - sal_Int32 nScanlineFormat, - sal_Int32 nScanlineStride, - sal_uInt8* pFirstScanline, - boost::shared_array< sal_uInt8 > pMem, - const PaletteMemorySharedVector& pPal, - BitmapDeviceDamageTracker* pDamage ) + const basegfx::B2IRange& rBounds, + sal_Int32 nScanlineFormat, + sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, + boost::shared_array< sal_uInt8 > pMem, + const PaletteMemorySharedVector& pPal, + const IBitmapDeviceDamageTrackerSharedPtr& pDamage ) { return createRenderer<FormatTraits, MaskTraits>(rBounds, @@ -1789,14 +1798,14 @@ BitmapDeviceSharedPtr createRenderer( template< class FormatTraits, class MaskTraits > BitmapDeviceSharedPtr createRenderer( - const basegfx::B2IRange& rBounds, - sal_Int32 nScanlineFormat, - sal_Int32 nScanlineStride, - sal_uInt8* pFirstScanline, - boost::shared_array< sal_uInt8 > pMem, - PaletteMemorySharedVector pPal, - int nBitsPerPixel, - BitmapDeviceDamageTracker* pDamage ) + const basegfx::B2IRange& rBounds, + sal_Int32 nScanlineFormat, + sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, + boost::shared_array< sal_uInt8 > pMem, + PaletteMemorySharedVector pPal, + int nBitsPerPixel, + const IBitmapDeviceDamageTrackerSharedPtr& pDamage ) { pPal = createStandardPalette(pPal, 1UL << nBitsPerPixel); @@ -1846,13 +1855,13 @@ inline sal_uInt32 nextPow2( sal_uInt32 x ) namespace { -BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& rSize, - bool bTopDown, - sal_Int32 nScanlineFormat, - boost::shared_array< sal_uInt8 > pMem, - PaletteMemorySharedVector pPal, - const basegfx::B2IRange* pSubset, - BitmapDeviceDamageTracker* pDamage ) +BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& rSize, + bool bTopDown, + sal_Int32 nScanlineFormat, + boost::shared_array< sal_uInt8 > pMem, + PaletteMemorySharedVector pPal, + const basegfx::B2IRange* pSubset, + const IBitmapDeviceDamageTrackerSharedPtr& rDamage ) { if( nScanlineFormat <= Format::NONE || nScanlineFormat > Format::MAX ) @@ -1920,24 +1929,24 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r case Format::ONE_BIT_MSB_GREY: return createRenderer<PixelFormatTraits_GREY1_MSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); case Format::ONE_BIT_LSB_GREY: return createRenderer<PixelFormatTraits_GREY1_LSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); case Format::ONE_BIT_MSB_PAL: return createRenderer<PixelFormatTraits_PAL1_MSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, pFirstScanline, pMem, pPal, - bitsPerPixel[nScanlineFormat], pDamage ); + bitsPerPixel[nScanlineFormat], rDamage ); case Format::ONE_BIT_LSB_PAL: return createRenderer<PixelFormatTraits_PAL1_LSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, pFirstScanline, pMem, pPal, - bitsPerPixel[nScanlineFormat], pDamage ); + bitsPerPixel[nScanlineFormat], rDamage ); // ---------------------------------------------------------------------- @@ -1946,24 +1955,24 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r case Format::FOUR_BIT_MSB_GREY: return createRenderer<PixelFormatTraits_GREY4_MSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); case Format::FOUR_BIT_LSB_GREY: return createRenderer<PixelFormatTraits_GREY4_LSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); case Format::FOUR_BIT_MSB_PAL: return createRenderer<PixelFormatTraits_PAL4_MSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, pFirstScanline, pMem, pPal, - bitsPerPixel[nScanlineFormat], pDamage ); + bitsPerPixel[nScanlineFormat], rDamage ); case Format::FOUR_BIT_LSB_PAL: return createRenderer<PixelFormatTraits_PAL4_LSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, pFirstScanline, pMem, pPal, - bitsPerPixel[nScanlineFormat], pDamage ); + bitsPerPixel[nScanlineFormat], rDamage ); // ---------------------------------------------------------------------- @@ -1972,13 +1981,13 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r case Format::EIGHT_BIT_GREY: return createRenderer<PixelFormatTraits_GREY8,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); case Format::EIGHT_BIT_PAL: return createRenderer<PixelFormatTraits_PAL8,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, pFirstScanline, pMem, pPal, - bitsPerPixel[nScanlineFormat], pDamage ); + bitsPerPixel[nScanlineFormat], rDamage ); // ---------------------------------------------------------------------- @@ -1987,12 +1996,12 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r case Format::SIXTEEN_BIT_LSB_TC_MASK: return createRenderer<PixelFormatTraits_RGB16_565_LSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); case Format::SIXTEEN_BIT_MSB_TC_MASK: return createRenderer<PixelFormatTraits_RGB16_565_MSB,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); // ---------------------------------------------------------------------- @@ -2000,7 +2009,7 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r case Format::TWENTYFOUR_BIT_TC_MASK: return createRenderer<PixelFormatTraits_BGR24,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); // ---------------------------------------------------------------------- @@ -2009,12 +2018,12 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r case Format::THIRTYTWO_BIT_TC_MASK: return createRenderer<PixelFormatTraits_RGB32_888,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); case Format::THIRTYTWO_BIT_TC_MASK_ARGB: return createRenderer<PixelFormatTraits_BGR32_888,StdMasks>( aBounds, nScanlineFormat, nScanlineStride, - pFirstScanline, pMem, pPal, pDamage ); + pFirstScanline, pMem, pPal, rDamage ); } // TODO(F3): other formats not yet implemented @@ -2025,8 +2034,7 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, bool bTopDown, - sal_Int32 nScanlineFormat, - BitmapDeviceDamageTracker* pDamage ) + sal_Int32 nScanlineFormat ) { return createBitmapDeviceImpl( rSize, bTopDown, @@ -2034,7 +2042,7 @@ BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, boost::shared_array< sal_uInt8 >(), PaletteMemorySharedVector(), NULL, - pDamage ); + IBitmapDeviceDamageTrackerSharedPtr() ); } BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, @@ -2048,7 +2056,7 @@ BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize boost::shared_array< sal_uInt8 >(), rPalette, NULL, - NULL ); + IBitmapDeviceDamageTrackerSharedPtr() ); } BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, @@ -2063,7 +2071,7 @@ BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize rMem, rPalette, NULL, - NULL ); + IBitmapDeviceDamageTrackerSharedPtr() ); } BitmapDeviceSharedPtr subsetBitmapDevice( const BitmapDeviceSharedPtr& rProto, diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index e4cf0bed97c6..43f420d895ee 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -61,7 +61,7 @@ typedef XLIB_Window GdkNativeWindow; #define gdk_window_foreign_new_for_display(a,b) gdk_x11_window_foreign_new_for_display(a,b) #endif -class GtkSalFrame : public SalFrame, basebmp::BitmapDeviceDamageTracker +class GtkSalFrame : public SalFrame { static const int nMaxGraphics = 2; diff --git a/vcl/unx/gtk/window/gtkframe.cxx b/vcl/unx/gtk/window/gtkframe.cxx index 5c6414835ab0..cb780e97df92 100644 --- a/vcl/unx/gtk/window/gtkframe.cxx +++ b/vcl/unx/gtk/window/gtkframe.cxx @@ -346,6 +346,19 @@ GetAlternateKeyCode( const sal_uInt16 nKeyCode ) #if GTK_CHECK_VERSION(3,0,0) static int debugQueuePureRedraw = 0; static int debugRedboxRedraws = 0; + +/// Decouple SalFrame lifetime from damagetracker lifetime +struct DamageTracker : public basebmp::IBitmapDeviceDamageTracker +{ + DamageTracker(GtkSalFrame& rFrame) : m_rFrame(rFrame) + {} + virtual void damaged(const basegfx::B2IRange& rDamageRect) const + { + m_rFrame.damaged(rDamageRect); + } + + GtkSalFrame& m_rFrame; +}; #endif void GtkSalFrame::doKeyCallback( guint state, @@ -1567,9 +1580,9 @@ void GtkSalFrame::AllocateFrame() if( aFrameSize.getY() == 0 ) aFrameSize.setY( 1 ); m_aFrame = basebmp::createBitmapDevice( aFrameSize, true, - basebmp::Format::TWENTYFOUR_BIT_TC_MASK, - this ); -// basebmp::Format::THIRTYTWO_BIT_TC_MASK_ARGB ); + basebmp::Format::TWENTYFOUR_BIT_TC_MASK ); + m_aFrame->setDamageTracker( + basebmp::IBitmapDeviceDamageTrackerSharedPtr(new DamageTracker(*this)) ); fprintf( stderr, "allocated m_aFrame size of %dx%d \n", (int)maGeometry.nWidth, (int)maGeometry.nHeight ); |