INTEGRATION: CWS canvas05 (1.3.68); FILE MERGED

2008/05/21 13:32:03 thb 1.3.68.11: Made vcl and cairo canvas work with emf+ patches; smoothed out internal cairo makefile changes; corrected cairocanvas sprite update
2008/04/21 07:32:50 thb 1.3.68.10: RESYNC: (1.5-1.6); FILE MERGED
2008/04/09 09:35:12 thb 1.3.68.9: Improved log output, fixed wrong arg check for vclcanvas
2008/04/09 09:06:52 thb 1.3.68.8: cairo SpriteCanvasHelper was recursive in disposing; argument order changed for init
2008/04/07 14:34:18 thb 1.3.68.7: RESYNC: (1.4-1.5); FILE MERGED
2008/04/03 16:02:26 thb 1.3.68.6: Merged in cairoquartz01 changes, reworked into the polymorphic Surface concept now
2008/04/02 22:56:28 thb 1.3.68.5: Reworked Surface class to abstract interface; changed all manual refcount handling to RAII
2008/03/18 22:00:57 thb 1.3.68.4: Implementing non-backbuffered canvas for cairocanvas as well - reworked to share most of the code
2008/01/22 00:50:52 thb 1.3.68.3: RESYNC: (1.3-1.4); FILE MERGED
2007/12/20 22:18:56 thb 1.3.68.2: #i81092# #i78888# #i78925# #i79258# #i79437# #i84784# Large canvas rework, completing various areas such as color spaces, bitmap data access, true sprite and non-sprite implementations, and upstreaming the canvas parts of rodos emf+ rendering
2007/10/01 13:02:01 thb 1.3.68.1: #i78888# #i78925# #i79258# #i79437# Merge from CWS picom
This commit is contained in:
Kurt Zenker
2008-06-24 09:24:53 +00:00
parent d28bc65675
commit 8dbb835500

View File

@@ -7,7 +7,7 @@
* OpenOffice.org - a multi-platform office productivity suite * OpenOffice.org - a multi-platform office productivity suite
* *
* $RCSfile: cairo_spritecanvashelper.cxx,v $ * $RCSfile: cairo_spritecanvashelper.cxx,v $
* $Revision: 1.6 $ * $Revision: 1.7 $
* *
* This file is part of OpenOffice.org. * This file is part of OpenOffice.org.
* *
@@ -34,6 +34,7 @@
#include <canvas/debug.hxx> #include <canvas/debug.hxx>
#include <canvas/verbosetrace.hxx> #include <canvas/verbosetrace.hxx>
#include <canvas/canvastools.hxx> #include <canvas/canvastools.hxx>
#include <tools/diagnose_ex.h>
#include <vcl/canvastools.hxx> #include <vcl/canvastools.hxx>
@@ -59,46 +60,47 @@ namespace cairocanvas
Used to repaint the whole canvas (background and all Used to repaint the whole canvas (background and all
sprites) sprites)
*/ */
void spriteRedraw( Cairo* pCairo, void spriteRedraw( const CairoSharedPtr& pCairo,
const ::canvas::Sprite::Reference& rSprite ) const ::canvas::Sprite::Reference& rSprite )
{ {
// downcast to derived vclcanvas::Sprite interface, which // downcast to derived cairocanvas::Sprite interface, which
// provides the actual redraw methods. // provides the actual redraw methods.
::boost::polymorphic_downcast< Sprite* >(rSprite.get())->redraw( pCairo, true); ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->redraw( pCairo, true);
} }
void repaintBackground( Cairo* pCairo, void repaintBackground( const CairoSharedPtr& pCairo,
Surface* pBackgroundSurface, const SurfaceSharedPtr& pBackgroundSurface,
const ::basegfx::B2DRange& rArea ) const ::basegfx::B2DRange& rArea )
{ {
cairo_save( pCairo ); cairo_save( pCairo.get() );
cairo_rectangle( pCairo, ceil( rArea.getMinX() ), ceil( rArea.getMinY() ), floor( rArea.getWidth() ), floor( rArea.getHeight() ) ); cairo_rectangle( pCairo.get(), ceil( rArea.getMinX() ), ceil( rArea.getMinY() ),
cairo_clip( pCairo ); floor( rArea.getWidth() ), floor( rArea.getHeight() ) );
cairo_set_source_surface( pCairo, pBackgroundSurface->mpSurface, 0, 0 ); cairo_clip( pCairo.get() );
cairo_set_operator( pCairo, CAIRO_OPERATOR_SOURCE ); cairo_set_source_surface( pCairo.get(), pBackgroundSurface->getCairoSurface().get(), 0, 0 );
cairo_paint( pCairo ); cairo_set_operator( pCairo.get(), CAIRO_OPERATOR_SOURCE );
cairo_restore( pCairo ); cairo_paint( pCairo.get() );
cairo_restore( pCairo.get() );
} }
void opaqueUpdateSpriteArea( const ::canvas::Sprite::Reference& rSprite, void opaqueUpdateSpriteArea( const ::canvas::Sprite::Reference& rSprite,
Cairo* pCairo, const CairoSharedPtr& pCairo,
const ::basegfx::B2IRange& rArea ) const ::basegfx::B2IRange& rArea )
{ {
// clip output to actual update region (otherwise a) // clip output to actual update region (otherwise a)
// wouldn't save much render time, and b) will clutter // wouldn't save much render time, and b) will clutter
// scrolled sprite content outside this area) // scrolled sprite content outside this area)
cairo_save( pCairo ); cairo_save( pCairo.get() );
cairo_rectangle( pCairo, rArea.getMinX(), rArea.getMinY(), cairo_rectangle( pCairo.get(), rArea.getMinX(), rArea.getMinY(),
sal::static_int_cast<sal_Int32>(rArea.getWidth()), sal::static_int_cast<sal_Int32>(rArea.getWidth()),
sal::static_int_cast<sal_Int32>(rArea.getHeight()) ); sal::static_int_cast<sal_Int32>(rArea.getHeight()) );
cairo_clip( pCairo ); cairo_clip( pCairo.get() );
// repaint affected sprite directly to output device (at // repaint affected sprite directly to output device (at
// the actual screen output position) // the actual screen output position)
// rendering directly to device buffer // rendering directly to device buffer
::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo, false ); ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo, false );
cairo_restore( pCairo ); cairo_restore( pCairo.get() );
} }
/** Repaint sprite at original position /** Repaint sprite at original position
@@ -106,7 +108,7 @@ namespace cairocanvas
Used for opaque updates, which render directly to the Used for opaque updates, which render directly to the
device buffer. device buffer.
*/ */
void spriteRedrawStub( Cairo* pCairo, void spriteRedrawStub( const CairoSharedPtr& pCairo,
const ::canvas::Sprite::Reference& rSprite ) const ::canvas::Sprite::Reference& rSprite )
{ {
if( rSprite.is() ) if( rSprite.is() )
@@ -119,7 +121,7 @@ namespace cairocanvas
Used for generic update, which renders into device buffer. Used for generic update, which renders into device buffer.
*/ */
void spriteRedrawStub2( Cairo* pCairo, void spriteRedrawStub2( const CairoSharedPtr& pCairo,
const ::canvas::Sprite::Reference& rSprite ) const ::canvas::Sprite::Reference& rSprite )
{ {
if( rSprite.is() ) if( rSprite.is() )
@@ -133,7 +135,7 @@ namespace cairocanvas
Used for opaque updates from scrollUpdate(), which render Used for opaque updates from scrollUpdate(), which render
directly to the front buffer. directly to the front buffer.
*/ */
void spriteRedrawStub3( Cairo* pCairo, void spriteRedrawStub3( const CairoSharedPtr& pCairo,
const ::canvas::SpriteRedrawManager::AreaComponent& rComponent ) const ::canvas::SpriteRedrawManager::AreaComponent& rComponent )
{ {
const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() ); const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() );
@@ -144,7 +146,10 @@ namespace cairocanvas
} }
SpriteCanvasHelper::SpriteCanvasHelper() : SpriteCanvasHelper::SpriteCanvasHelper() :
mpRedrawManager( NULL ) mpRedrawManager( NULL ),
mpOwningSpriteCanvas( NULL ),
mpCompositingSurface(),
maCompositingSurfaceSize()
{ {
} }
@@ -153,12 +158,15 @@ namespace cairocanvas
const ::basegfx::B2ISize& rSize ) const ::basegfx::B2ISize& rSize )
{ {
mpRedrawManager = &rManager; mpRedrawManager = &rManager;
mpOwningSpriteCanvas = &rDevice;
CanvasHelper::init( rSize, rDevice ); CanvasHelper::init( rSize, rDevice, &rDevice );
} }
void SpriteCanvasHelper::disposing() void SpriteCanvasHelper::disposing()
{ {
mpCompositingSurface.reset();
mpOwningSpriteCanvas = NULL;
mpRedrawManager = NULL; mpRedrawManager = NULL;
// forward to base // forward to base
@@ -166,7 +174,7 @@ namespace cairocanvas
} }
uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromAnimation( uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromAnimation(
const uno::Reference< rendering::XAnimation >& /*animation*/ ) const uno::Reference< rendering::XAnimation >& )
{ {
return uno::Reference< rendering::XAnimatedSprite >(); return uno::Reference< rendering::XAnimatedSprite >();
} }
@@ -185,10 +193,11 @@ namespace cairocanvas
return uno::Reference< rendering::XCustomSprite >( return uno::Reference< rendering::XCustomSprite >(
new CanvasCustomSprite( spriteSize, new CanvasCustomSprite( spriteSize,
mpDevice ) ); mpOwningSpriteCanvas ) );
} }
uno::Reference< rendering::XSprite > SpriteCanvasHelper::createClonedSprite( const uno::Reference< rendering::XSprite >& /*original*/ ) uno::Reference< rendering::XSprite > SpriteCanvasHelper::createClonedSprite(
const uno::Reference< rendering::XSprite >& )
{ {
return uno::Reference< rendering::XSprite >(); return uno::Reference< rendering::XSprite >();
} }
@@ -198,19 +207,23 @@ namespace cairocanvas
bool& io_bSurfaceDirty ) bool& io_bSurfaceDirty )
{ {
if( !mpRedrawManager || if( !mpRedrawManager ||
!mpDevice || !mpOwningSpriteCanvas ||
!mpDevice->getWindowSurface() || !mpOwningSpriteCanvas->getWindowSurface() ||
!mpDevice->getBufferSurface() ) !mpOwningSpriteCanvas->getBufferSurface() )
{ {
return sal_False; // disposed, or otherwise dysfunctional return sal_False; // disposed, or otherwise dysfunctional
} }
OSL_TRACE("SpriteCanvasHelper::updateScreen called"); OSL_TRACE("SpriteCanvasHelper::updateScreen called");
Cairo* pBufferCairo = mpDevice->getBufferSurface()->getCairo(); const ::basegfx::B2ISize& rSize = mpOwningSpriteCanvas->getSizePixel();
Cairo* pWindowCairo = mpDevice->getWindowSurface()->getCairo();
const ::basegfx::B2ISize& rSize = mpDevice->getSizePixel(); // force compositing surface to be available before using it
// inside forEachSpriteArea
SurfaceSharedPtr pCompositingSurface = getCompositingSurface(rSize);
SurfaceSharedPtr pWindowSurface = mpOwningSpriteCanvas->getWindowSurface();
CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo();
CairoSharedPtr pWindowCairo = pWindowSurface->getCairo();
// TODO(P1): Might be worthwile to track areas of background // TODO(P1): Might be worthwile to track areas of background
// changes, too. // changes, too.
@@ -225,38 +238,39 @@ namespace cairocanvas
} }
else else
{ {
OSL_TRACE("SpriteCanvasHelper::updateScreen update ALL"); OSL_TRACE("SpriteCanvasHelper::updateScreen update ALL");
// background has changed, so we currently have no choice // background has changed, so we currently have no choice
// but repaint everything (or caller requested that) // but repaint everything (or caller requested that)
cairo_rectangle( pBufferCairo, 0, 0, rSize.getX(), rSize.getY() ); cairo_rectangle( pCompositingCairo.get(), 0, 0, rSize.getX(), rSize.getY() );
cairo_clip( pBufferCairo ); cairo_clip( pCompositingCairo.get() );
cairo_save( pBufferCairo ); cairo_save( pCompositingCairo.get() );
cairo_set_source_surface( pBufferCairo, mpDevice->getBackgroundSurface()->mpSurface, 0, 0 ); cairo_set_source_surface( pCompositingCairo.get(),
cairo_set_operator( pBufferCairo, CAIRO_OPERATOR_SOURCE ); mpOwningSpriteCanvas->getBufferSurface()->getCairoSurface().get(),
cairo_paint( pBufferCairo ); 0, 0 );
cairo_restore( pBufferCairo ); cairo_set_operator( pCompositingCairo.get(), CAIRO_OPERATOR_SOURCE );
cairo_paint( pCompositingCairo.get() );
cairo_restore( pCompositingCairo.get() );
// repaint all active sprites on top of background into // repaint all active sprites on top of background into
// VDev. // VDev.
mpRedrawManager->forEachSprite( mpRedrawManager->forEachSprite(
::boost::bind( ::boost::bind(
&spriteRedraw, &spriteRedraw,
pBufferCairo, boost::cref(pCompositingCairo),
_1 ) ); _1 ) );
// flush to screen // flush to screen
cairo_rectangle( pWindowCairo, 0, 0, rSize.getX(), rSize.getY() ); cairo_rectangle( pWindowCairo.get(), 0, 0, rSize.getX(), rSize.getY() );
cairo_clip( pWindowCairo ); cairo_clip( pWindowCairo.get() );
cairo_set_source_surface( pWindowCairo, mpDevice->getBufferSurface()->mpSurface, 0, 0 ); cairo_set_source_surface( pWindowCairo.get(),
cairo_set_operator( pWindowCairo, CAIRO_OPERATOR_SOURCE ); pCompositingSurface->getCairoSurface().get(),
cairo_paint( pWindowCairo ); 0, 0 );
cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE );
cairo_paint( pWindowCairo.get() );
} }
cairo_destroy( pBufferCairo );
cairo_destroy( pWindowCairo );
// change record vector must be cleared, for the next turn of // change record vector must be cleared, for the next turn of
// rendering and sprite changing // rendering and sprite changing
mpRedrawManager->clearChangeRecords(); mpRedrawManager->clearChangeRecords();
@@ -264,38 +278,39 @@ namespace cairocanvas
io_bSurfaceDirty = false; io_bSurfaceDirty = false;
// commit to screen // commit to screen
mpDevice->flush(); mpOwningSpriteCanvas->flush();
return sal_True; return sal_True;
} }
void SpriteCanvasHelper::backgroundPaint( const ::basegfx::B2DRange& rUpdateRect ) void SpriteCanvasHelper::backgroundPaint( const ::basegfx::B2DRange& rUpdateRect )
{ {
if( mpDevice ) { if( mpOwningSpriteCanvas && mpCompositingSurface )
Cairo* pBufferCairo = mpDevice->getBufferSurface()->getCairo(); repaintBackground( mpCompositingSurface->getCairo(),
mpOwningSpriteCanvas->getBufferSurface(),
repaintBackground( pBufferCairo, mpDevice->getBackgroundSurface(), rUpdateRect ); rUpdateRect );
cairo_destroy( pBufferCairo );
}
} }
void SpriteCanvasHelper::scrollUpdate( const ::basegfx::B2DRange& rMoveStart, void SpriteCanvasHelper::scrollUpdate( const ::basegfx::B2DRange& rMoveStart,
const ::basegfx::B2DRange& rMoveEnd, const ::basegfx::B2DRange& rMoveEnd,
const ::canvas::SpriteRedrawManager::UpdateArea& rUpdateArea ) const ::canvas::SpriteRedrawManager::UpdateArea& rUpdateArea )
{ {
ENSURE_AND_THROW( mpDevice && ENSURE_OR_THROW( mpOwningSpriteCanvas &&
mpDevice->getBufferSurface(), mpOwningSpriteCanvas->getBufferSurface(),
"SpriteCanvasHelper::scrollUpdate(): NULL device pointer " ); "SpriteCanvasHelper::scrollUpdate(): NULL device pointer " );
Cairo* pBufferCairo = mpDevice->getBufferSurface()->getCairo(); OSL_TRACE("SpriteCanvasHelper::scrollUpdate called");
OSL_TRACE("SpriteCanvasHelper::scrollUpdate called"); const ::basegfx::B2ISize& rSize = mpOwningSpriteCanvas->getSizePixel();
const ::basegfx::B2ISize& rSize = mpDevice->getSizePixel();
const ::basegfx::B2IRange aOutputBounds( 0,0, const ::basegfx::B2IRange aOutputBounds( 0,0,
rSize.getX(), rSize.getX(),
rSize.getY() ); rSize.getY() );
SurfaceSharedPtr pCompositingSurface = getCompositingSurface(rSize);
SurfaceSharedPtr pWindowSurface = mpOwningSpriteCanvas->getWindowSurface();
CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo();
CairoSharedPtr pWindowCairo = pWindowSurface->getCairo();
// round rectangles to integer pixel. Note: have to be // round rectangles to integer pixel. Note: have to be
// extremely careful here, to avoid off-by-one errors for // extremely careful here, to avoid off-by-one errors for
// the destination area: otherwise, the next scroll update // the destination area: otherwise, the next scroll update
@@ -330,38 +345,39 @@ namespace cairocanvas
rUpdateArea.maComponentList.end(), rUpdateArea.maComponentList.end(),
::boost::bind( ::boost::bind(
&spriteRedrawStub3, &spriteRedrawStub3,
pBufferCairo, boost::cref(pCompositingCairo),
_1 ) ); _1 ) );
} }
else else
{ {
const ::basegfx::B2IVector aSourceUpperLeftPos( aSourceRect.getMinimum() ); const ::basegfx::B2IVector aSourceUpperLeftPos( aSourceRect.getMinimum() );
// clip dest area (which must be inside rDestBounds) // clip dest area (which must be inside rDestBounds)
::basegfx::B2IRange aDestRect( rDestRect ); ::basegfx::B2IRange aDestRect( rDestRect );
aDestRect.intersect( aOutputBounds ); aDestRect.intersect( aOutputBounds );
cairo_save( pBufferCairo ); cairo_save( pCompositingCairo.get() );
// scroll content in device back buffer // scroll content in device back buffer
cairo_set_source_surface( pBufferCairo, mpDevice->getBufferSurface()->mpSurface, cairo_set_source_surface( pCompositingCairo.get(),
aDestPos.getX() - aSourceUpperLeftPos.getX(), mpOwningSpriteCanvas->getBufferSurface()->getCairoSurface().get(),
aDestPos.getY() - aSourceUpperLeftPos.getY() ); aDestPos.getX() - aSourceUpperLeftPos.getX(),
cairo_rectangle( pBufferCairo, aDestPos.getY() - aSourceUpperLeftPos.getY() );
aDestPos.getX(), aDestPos.getY(), cairo_rectangle( pCompositingCairo.get(),
sal::static_int_cast<sal_Int32>(aDestRect.getWidth()), aDestPos.getX(), aDestPos.getY(),
sal::static_int_cast<sal_Int32>(aDestRect.getHeight()) ); sal::static_int_cast<sal_Int32>(aDestRect.getWidth()),
cairo_clip( pBufferCairo ); sal::static_int_cast<sal_Int32>(aDestRect.getHeight()) );
cairo_set_operator( pBufferCairo, CAIRO_OPERATOR_SOURCE ); cairo_clip( pCompositingCairo.get() );
cairo_paint( pBufferCairo ); cairo_set_operator( pCompositingCairo.get(), CAIRO_OPERATOR_SOURCE );
cairo_restore( pBufferCairo ); cairo_paint( pCompositingCairo.get() );
cairo_restore( pCompositingCairo.get() );
const ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator const ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
aFirst( rUpdateArea.maComponentList.begin() ); aFirst( rUpdateArea.maComponentList.begin() );
::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
aSecond( aFirst ); ++aSecond; aSecond( aFirst ); ++aSecond;
ENSURE_AND_THROW( aFirst->second.getSprite().is(), ENSURE_OR_THROW( aFirst->second.getSprite().is(),
"VCLCanvas::scrollUpdate(): no sprite" ); "VCLCanvas::scrollUpdate(): no sprite" );
// repaint uncovered areas from sprite. Need to actually // repaint uncovered areas from sprite. Need to actually
// clip here, since we're only repainting _parts_ of the // clip here, since we're only repainting _parts_ of the
@@ -370,7 +386,7 @@ namespace cairocanvas
aUnscrollableAreas.end(), aUnscrollableAreas.end(),
::boost::bind( &opaqueUpdateSpriteArea, ::boost::bind( &opaqueUpdateSpriteArea,
::boost::cref(aFirst->second.getSprite()), ::boost::cref(aFirst->second.getSprite()),
pBufferCairo, boost::cref(pCompositingCairo),
_1 ) ); _1 ) );
} }
@@ -384,80 +400,81 @@ namespace cairocanvas
::std::for_each( aUncoveredAreas.begin(), ::std::for_each( aUncoveredAreas.begin(),
aUncoveredAreas.end(), aUncoveredAreas.end(),
::boost::bind( &repaintBackground, ::boost::bind( &repaintBackground,
pBufferCairo, boost::cref(pCompositingCairo),
mpDevice->getBackgroundSurface(), boost::cref(mpOwningSpriteCanvas->getBufferSurface()),
_1 ) ); _1 ) );
Cairo* pWindowCairo = mpDevice->getWindowSurface()->getCairo(); cairo_rectangle( pWindowCairo.get(), 0, 0, rSize.getX(), rSize.getY() );
cairo_clip( pWindowCairo.get() );
cairo_rectangle( pWindowCairo, 0, 0, rSize.getX(), rSize.getY() ); cairo_set_source_surface( pWindowCairo.get(),
cairo_clip( pWindowCairo ); pCompositingSurface->getCairoSurface().get(),
cairo_set_source_surface( pWindowCairo, mpDevice->getBufferSurface()->mpSurface, 0, 0 ); 0, 0 );
cairo_set_operator( pWindowCairo, CAIRO_OPERATOR_SOURCE ); cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE );
cairo_paint( pWindowCairo ); cairo_paint( pWindowCairo.get() );
cairo_destroy( pBufferCairo );
cairo_destroy( pWindowCairo );
} }
void SpriteCanvasHelper::opaqueUpdate( const ::basegfx::B2DRange& rTotalArea, void SpriteCanvasHelper::opaqueUpdate( const ::basegfx::B2DRange& rTotalArea,
const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites ) const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
{ {
ENSURE_AND_THROW( mpDevice && ENSURE_OR_THROW( mpOwningSpriteCanvas &&
mpDevice->getBufferSurface(), mpOwningSpriteCanvas->getBufferSurface(),
"SpriteCanvasHelper::opaqueUpdate(): NULL device pointer " ); "SpriteCanvasHelper::opaqueUpdate(): NULL device pointer " );
OSL_TRACE("SpriteCanvasHelper::opaqueUpdate called"); OSL_TRACE("SpriteCanvasHelper::opaqueUpdate called");
Cairo* pBufferCairo = mpDevice->getBufferSurface()->getCairo(); const ::basegfx::B2ISize& rDeviceSize = mpOwningSpriteCanvas->getSizePixel();
const ::basegfx::B2ISize& rDeviceSize = mpDevice->getSizePixel();
cairo_rectangle( pBufferCairo, 0, 0, rDeviceSize.getX(), rDeviceSize.getY() ); SurfaceSharedPtr pCompositingSurface = getCompositingSurface(rDeviceSize);
cairo_clip( pBufferCairo ); SurfaceSharedPtr pWindowSurface = mpOwningSpriteCanvas->getWindowSurface();
CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo();
CairoSharedPtr pWindowCairo = pWindowSurface->getCairo();
::basegfx::B2DVector aPos( ceil( rTotalArea.getMinX() ), ceil( rTotalArea.getMinY() ) ); cairo_rectangle( pCompositingCairo.get(), 0, 0, rDeviceSize.getX(), rDeviceSize.getY() );
::basegfx::B2DVector aSize( floor( rTotalArea.getMaxX() - aPos.getX() ), floor( rTotalArea.getMaxY() - aPos.getY() ) ); cairo_clip( pCompositingCairo.get() );
cairo_rectangle( pBufferCairo, aPos.getX(), aPos.getY(), aSize.getX(), aSize.getY() ); ::basegfx::B2DVector aPos( ceil( rTotalArea.getMinX() ), ceil( rTotalArea.getMinY() ) );
cairo_clip( pBufferCairo ); ::basegfx::B2DVector aSize( floor( rTotalArea.getMaxX() - aPos.getX() ), floor( rTotalArea.getMaxY() - aPos.getY() ) );
cairo_rectangle( pCompositingCairo.get(), aPos.getX(), aPos.getY(), aSize.getX(), aSize.getY() );
cairo_clip( pCompositingCairo.get() );
// repaint all affected sprites directly to output device // repaint all affected sprites directly to output device
::std::for_each( rSortedUpdateSprites.begin(), ::std::for_each( rSortedUpdateSprites.begin(),
rSortedUpdateSprites.end(), rSortedUpdateSprites.end(),
::boost::bind( ::boost::bind(
&spriteRedrawStub, &spriteRedrawStub,
pBufferCairo, boost::cref(pCompositingCairo),
_1 ) ); _1 ) );
// flush to screen // flush to screen
Cairo* pWindowCairo = mpDevice->getWindowSurface()->getCairo(); cairo_rectangle( pWindowCairo.get(), 0, 0, rDeviceSize.getX(), rDeviceSize.getY() );
cairo_clip( pWindowCairo.get() );
cairo_rectangle( pWindowCairo, 0, 0, rDeviceSize.getX(), rDeviceSize.getY() ); cairo_rectangle( pWindowCairo.get(), aPos.getX(), aPos.getY(), aSize.getX(), aSize.getY() );
cairo_clip( pWindowCairo ); cairo_clip( pWindowCairo.get() );
cairo_rectangle( pWindowCairo, aPos.getX(), aPos.getY(), aSize.getX(), aSize.getY() ); cairo_set_source_surface( pWindowCairo.get(),
cairo_clip( pWindowCairo ); pCompositingSurface->getCairoSurface().get(),
cairo_set_source_surface( pWindowCairo, mpDevice->getBufferSurface()->mpSurface, 0, 0 ); 0, 0 );
cairo_set_operator( pWindowCairo, CAIRO_OPERATOR_SOURCE ); cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE );
cairo_paint( pWindowCairo ); cairo_paint( pWindowCairo.get() );
cairo_destroy( pBufferCairo );
cairo_destroy( pWindowCairo );
} }
void SpriteCanvasHelper::genericUpdate( const ::basegfx::B2DRange& rRequestedArea, void SpriteCanvasHelper::genericUpdate( const ::basegfx::B2DRange& rRequestedArea,
const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites ) const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
{ {
// TODO // TODO
OSL_TRACE("SpriteCanvasHelper::genericUpdate called"); OSL_TRACE("SpriteCanvasHelper::genericUpdate called");
ENSURE_AND_THROW( mpDevice && ENSURE_OR_THROW( mpOwningSpriteCanvas &&
mpDevice->getBufferSurface(), mpOwningSpriteCanvas->getBufferSurface(),
"SpriteCanvasHelper::genericUpdate(): NULL device pointer " ); "SpriteCanvasHelper::genericUpdate(): NULL device pointer " );
Cairo* pBufferCairo = mpDevice->getBufferSurface()->getCairo();
// limit size of update VDev to target outdev's size // limit size of update VDev to target outdev's size
const ::basegfx::B2ISize& rSize = mpDevice->getSizePixel(); const ::basegfx::B2ISize& rSize = mpOwningSpriteCanvas->getSizePixel();
SurfaceSharedPtr pCompositingSurface = getCompositingSurface(rSize);
SurfaceSharedPtr pWindowSurface = mpOwningSpriteCanvas->getWindowSurface();
CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo();
CairoSharedPtr pWindowCairo = pWindowSurface->getCairo();
// round output position towards zero. Don't want to truncate // round output position towards zero. Don't want to truncate
// a fraction of a sprite pixel... Clip position at origin, // a fraction of a sprite pixel... Clip position at origin,
@@ -477,34 +494,54 @@ namespace cairocanvas
::std::min( rSize.getY(), ::std::min( rSize.getY(),
::canvas::tools::roundUp( rRequestedArea.getMaxY() - aOutputPosition.Y()) ) ); ::canvas::tools::roundUp( rRequestedArea.getMaxY() - aOutputPosition.Y()) ) );
cairo_rectangle( pBufferCairo, aOutputPosition.X(), aOutputPosition.Y(), aOutputSize.Width(), aOutputSize.Height() ); cairo_rectangle( pCompositingCairo.get(), aOutputPosition.X(), aOutputPosition.Y(), aOutputSize.Width(), aOutputSize.Height() );
cairo_clip( pBufferCairo ); cairo_clip( pCompositingCairo.get() );
// paint background // paint background
cairo_save( pBufferCairo ); cairo_save( pCompositingCairo.get() );
cairo_set_source_surface( pBufferCairo, mpDevice->getBackgroundSurface()->mpSurface, 0, 0 ); cairo_set_source_surface( pCompositingCairo.get(),
cairo_set_operator( pBufferCairo, CAIRO_OPERATOR_SOURCE ); mpOwningSpriteCanvas->getBufferSurface()->getCairoSurface().get(),
cairo_paint( pBufferCairo ); 0, 0 );
cairo_restore( pBufferCairo ); cairo_set_operator( pCompositingCairo.get(), CAIRO_OPERATOR_SOURCE );
cairo_paint( pCompositingCairo.get() );
cairo_restore( pCompositingCairo.get() );
// repaint all affected sprites on top of background into // repaint all affected sprites on top of background into
// VDev. // VDev.
::std::for_each( rSortedUpdateSprites.begin(), ::std::for_each( rSortedUpdateSprites.begin(),
rSortedUpdateSprites.end(), rSortedUpdateSprites.end(),
::boost::bind( &spriteRedrawStub2, ::boost::bind( &spriteRedrawStub2,
pBufferCairo, boost::cref(pCompositingCairo),
_1 ) ); _1 ) );
// flush to screen // flush to screen
Cairo* pWindowCairo = mpDevice->getWindowSurface()->getCairo(); cairo_rectangle( pWindowCairo.get(), aOutputPosition.X(), aOutputPosition.Y(), aOutputSize.Width(), aOutputSize.Height() );
cairo_clip( pWindowCairo.get() );
cairo_set_source_surface( pWindowCairo.get(),
pCompositingSurface->getCairoSurface().get(),
0, 0 );
cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE );
cairo_paint( pWindowCairo.get() );
}
cairo_rectangle( pWindowCairo, aOutputPosition.X(), aOutputPosition.Y(), aOutputSize.Width(), aOutputSize.Height() ); ::cairo::SurfaceSharedPtr SpriteCanvasHelper::getCompositingSurface( const ::basegfx::B2ISize& rNeededSize )
cairo_clip( pWindowCairo ); {
cairo_set_source_surface( pWindowCairo, mpDevice->getBufferSurface()->mpSurface, 0, 0 ); if( rNeededSize.getX() < maCompositingSurfaceSize.getX() ||
cairo_set_operator( pWindowCairo, CAIRO_OPERATOR_SOURCE ); rNeededSize.getY() < maCompositingSurfaceSize.getY() )
cairo_paint( pWindowCairo ); {
// need to give buffer more size
mpCompositingSurface.reset();
}
cairo_destroy( pBufferCairo ); if( !mpCompositingSurface )
cairo_destroy( pWindowCairo ); {
mpCompositingSurface =
mpOwningSpriteCanvas->getWindowSurface()->getSimilar(
CAIRO_CONTENT_COLOR,
rNeededSize.getX(), rNeededSize.getY() );
maCompositingSurfaceSize = rNeededSize;
}
return mpCompositingSurface;
} }
} }