23#include <boost/cast.hpp>
35using namespace ::
cairo;
48 const ::canvas::Sprite::Reference& rSprite )
52 ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->redraw( pCairo,
true);
57 const ::basegfx::B2DRange& rArea )
59 cairo_save( pCairo.get() );
60 cairo_rectangle( pCairo.get(), ceil( rArea.getMinX() ), ceil( rArea.getMinY() ),
61 floor( rArea.getWidth() ), floor( rArea.getHeight() ) );
62 cairo_clip( pCairo.get() );
63 cairo_set_source_surface( pCairo.get(), pBackgroundSurface->getCairoSurface().get(), 0, 0 );
64 cairo_set_operator( pCairo.get(), CAIRO_OPERATOR_SOURCE );
65 cairo_paint( pCairo.get() );
66 cairo_restore( pCairo.get() );
69 void opaqueUpdateSpriteArea( const ::canvas::Sprite::Reference& rSprite,
71 const ::basegfx::B2IRange& rArea )
76 cairo_save( pCairo.get() );
77 cairo_rectangle( pCairo.get(), rArea.getMinX(), rArea.getMinY(),
78 sal::static_int_cast<sal_Int32>(rArea.getWidth()),
79 sal::static_int_cast<sal_Int32>(rArea.getHeight()) );
80 cairo_clip( pCairo.get() );
85 ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo,
false );
87 cairo_restore( pCairo.get() );
92 mpRedrawManager( nullptr ),
93 mpOwningSpriteCanvas( nullptr ),
94 mbCompositingSurfaceDirty(true)
100 const ::basegfx::B2ISize& rSize )
119 const uno::Reference< rendering::XAnimation >& )
121 return uno::Reference< rendering::XAnimatedSprite >();
125 const uno::Sequence< uno::Reference< rendering::XBitmap > >& ,
128 return uno::Reference< rendering::XAnimatedSprite >();
134 return uno::Reference< rendering::XCustomSprite >();
136 return uno::Reference< rendering::XCustomSprite >(
137 new CanvasCustomSprite( spriteSize,
142 const uno::Reference< rendering::XSprite >& )
144 return uno::Reference< rendering::XSprite >();
149 bool& io_bSurfaceDirty )
159 SAL_INFO(
"canvas.cairo",
"SpriteCanvasHelper::updateScreen called");
167 CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo();
183 SAL_INFO(
"canvas.cairo",
"SpriteCanvasHelper::updateScreen update ALL");
188 cairo_rectangle( pCompositingCairo.get(), 0, 0, rSize.getWidth(), rSize.getHeight() );
189 cairo_clip( pCompositingCairo.get() );
190 cairo_save( pCompositingCairo.get() );
191 cairo_set_source_surface( pCompositingCairo.get(),
194 cairo_set_operator( pCompositingCairo.get(), CAIRO_OPERATOR_SOURCE );
195 cairo_paint( pCompositingCairo.get() );
196 cairo_restore( pCompositingCairo.get() );
202 { spriteRedraw( pCompositingCairo, rSprite ); }
206 cairo_rectangle( pWindowCairo.get(), 0, 0, rSize.getWidth(), rSize.getHeight() );
207 cairo_clip( pWindowCairo.get() );
208 cairo_set_source_surface( pWindowCairo.get(),
209 pCompositingSurface->getCairoSurface().get(),
211 cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE );
212 cairo_paint( pWindowCairo.get() );
220 io_bSurfaceDirty =
false;
237 const ::basegfx::B2DRange& rMoveEnd,
238 const ::canvas::SpriteRedrawManager::UpdateArea& rUpdateArea )
242 "SpriteCanvasHelper::scrollUpdate(): NULL device pointer " );
244 SAL_INFO(
"canvas.cairo",
"SpriteCanvasHelper::scrollUpdate called");
247 const ::basegfx::B2IRange aOutputBounds( 0,0,
253 CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo();
263 const ::basegfx::B2IRange& rDestRect(
267 std::vector< ::basegfx::B2IRange > aUnscrollableAreas;
286 for(
const auto& rComponent : rUpdateArea.maComponentList )
288 const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() );
290 ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw(
291 pCompositingCairo,
true );
296 const ::basegfx::B2IVector aSourceUpperLeftPos( aSourceRect.
getMinimum() );
306 cairo_save( pScrollCairo.get() );
309 cairo_set_source_surface( pScrollCairo.get(),
310 pCompositingSurface->getCairoSurface().get(),
311 aDestPos.
getX() - aSourceUpperLeftPos.getX(),
312 aDestPos.
getY() - aSourceUpperLeftPos.getY() );
313 cairo_rectangle( pScrollCairo.get(),
316 cairo_clip( pScrollCairo.get() );
317 cairo_set_operator( pScrollCairo.get(), CAIRO_OPERATOR_SOURCE );
318 cairo_paint( pScrollCairo.get() );
319 cairo_restore( pScrollCairo.get() );
321 cairo_save( pCompositingCairo.get() );
323 cairo_set_source_surface( pCompositingCairo.get(),
324 pScrollSurface->getCairoSurface().get(),
326 cairo_rectangle( pCompositingCairo.get(),
329 cairo_clip( pCompositingCairo.get() );
330 cairo_set_operator( pCompositingCairo.get(), CAIRO_OPERATOR_SOURCE );
331 cairo_paint( pCompositingCairo.get() );
332 cairo_restore( pCompositingCairo.get() );
334 const ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
335 aFirst( rUpdateArea.maComponentList.begin() );
336 ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
341 "VCLCanvas::scrollUpdate(): no sprite" );
346 for(
const auto& rArea : aUnscrollableAreas )
347 opaqueUpdateSpriteArea( aFirst->second.getSprite(),
348 pCompositingCairo, rArea );
354 std::vector< ::basegfx::B2DRange > aUncoveredAreas;
355 ::basegfx::computeSetDifference( aUncoveredAreas,
356 rUpdateArea.maTotalBounds,
358 for(
const auto& rArea : aUncoveredAreas )
359 repaintBackground( pCompositingCairo,
362 cairo_rectangle( pWindowCairo.get(), 0, 0, rSize.getWidth(), rSize.getHeight() );
363 cairo_clip( pWindowCairo.get() );
364 cairo_set_source_surface( pWindowCairo.get(),
365 pCompositingSurface->getCairoSurface().get(),
367 cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE );
368 cairo_paint( pWindowCairo.get() );
372 const std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
376 "SpriteCanvasHelper::opaqueUpdate(): NULL device pointer " );
378 SAL_INFO(
"canvas.cairo",
"SpriteCanvasHelper::opaqueUpdate called");
384 CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo();
387 cairo_rectangle( pCompositingCairo.get(), 0, 0, rDeviceSize.getWidth(), rDeviceSize.getHeight() );
388 cairo_clip( pCompositingCairo.get() );
393 cairo_rectangle( pCompositingCairo.get(), aPos.
getX(), aPos.
getY(), aSize.
getX(), aSize.
getY() );
394 cairo_clip( pCompositingCairo.get() );
397 for(
const auto& rSprite : rSortedUpdateSprites )
400 ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw(
401 pCompositingCairo,
false );
405 cairo_rectangle( pWindowCairo.get(), 0, 0, rDeviceSize.getWidth(), rDeviceSize.getHeight() );
406 cairo_clip( pWindowCairo.get() );
407 cairo_rectangle( pWindowCairo.get(), aPos.
getX(), aPos.
getY(), aSize.
getX(), aSize.
getY() );
408 cairo_clip( pWindowCairo.get() );
409 cairo_set_source_surface( pWindowCairo.get(),
410 pCompositingSurface->getCairoSurface().get(),
412 cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE );
413 cairo_paint( pWindowCairo.get() );
417 const std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
420 SAL_INFO(
"canvas.cairo",
"SpriteCanvasHelper::genericUpdate called");
424 "SpriteCanvasHelper::genericUpdate(): NULL device pointer " );
431 CairoSharedPtr pCompositingCairo = pCompositingSurface->getCairo();
438 const Point aOutputPosition(
440 static_cast< sal_Int32
>(rRequestedArea.getMinX()) ),
442 static_cast< sal_Int32
>(rRequestedArea.getMinY()) ) );
446 const Size aOutputSize(
447 std::min( rSize.getWidth(),
448 ::canvas::tools::roundUp( rRequestedArea.getMaxX() - aOutputPosition.
X()) ),
449 std::min( rSize.getHeight(),
450 ::canvas::tools::roundUp( rRequestedArea.getMaxY() - aOutputPosition.
Y()) ) );
452 cairo_rectangle( pCompositingCairo.get(), aOutputPosition.
X(), aOutputPosition.
Y(), aOutputSize.
Width(), aOutputSize.
Height() );
453 cairo_clip( pCompositingCairo.get() );
456 cairo_save( pCompositingCairo.get() );
457 cairo_set_source_surface( pCompositingCairo.get(),
460 cairo_set_operator( pCompositingCairo.get(), CAIRO_OPERATOR_SOURCE );
461 cairo_paint( pCompositingCairo.get() );
462 cairo_restore( pCompositingCairo.get() );
466 for(
const auto& rSprite : rSortedUpdateSprites )
469 ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw(
470 pCompositingCairo,
true );
474 cairo_rectangle( pWindowCairo.get(), aOutputPosition.
X(), aOutputPosition.
Y(), aOutputSize.
Width(), aOutputSize.
Height() );
475 cairo_clip( pWindowCairo.get() );
476 cairo_set_source_surface( pWindowCairo.get(),
477 pCompositingSurface->getCairoSurface().get(),
479 cairo_set_operator( pWindowCairo.get(), CAIRO_OPERATOR_SOURCE );
480 cairo_paint( pWindowCairo.get() );
514 rNeededSize.getWidth(), rNeededSize.getHeight() );
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
B2IPoint getMinimum() const
void intersect(const Range2D &rRange)
void disposing()
Release all references.
void init(const ::basegfx::B2ISize &rSizePixel, SurfaceProvider &rSurfaceProvider, css::rendering::XGraphicDevice *pDevice)
Initialize canvas helper.
css::uno::Reference< css::rendering::XSprite > createClonedSprite(const css::uno::Reference< css::rendering::XSprite > &original)
SpriteCanvas * mpOwningSpriteCanvas
Set from the init method. used to generate sprites.
void disposing()
Dispose all internal references.
void opaqueUpdate(const ::basegfx::B2DRange &rTotalArea, const std::vector< ::canvas::Sprite::Reference > &rSortedUpdateSprites)
::basegfx::B2ISize maCompositingSurfaceSize
css::uno::Reference< css::rendering::XAnimatedSprite > createSpriteFromAnimation(const css::uno::Reference< css::rendering::XAnimation > &animation)
void init(::canvas::SpriteRedrawManager &rManager, SpriteCanvas &rOwningSpriteCanvas, const ::basegfx::B2ISize &rSize)
bool mbCompositingSurfaceDirty
::cairo::SurfaceSharedPtr createSurface(const ::basegfx::B2ISize &rNeededSize) const
::cairo::SurfaceSharedPtr const & getTemporarySurface()
::cairo::SurfaceSharedPtr mpTemporarySurface
a temporary surface that is guaranteed to be the same size
::cairo::SurfaceSharedPtr const & getCompositingSurface(const ::basegfx::B2ISize &rNeededSize)
::cairo::SurfaceSharedPtr mpCompositingSurface
a surface used to composite the frontbuffer image
void backgroundPaint(const ::basegfx::B2DRange &rUpdateRect)
Gets called for simple background repaints.
::canvas::SpriteRedrawManager * mpRedrawManager
Set from the SpriteCanvas: instance coordinating sprite redraw.
void scrollUpdate(const ::basegfx::B2DRange &rMoveStart, const ::basegfx::B2DRange &rMoveEnd, const ::canvas::SpriteRedrawManager::UpdateArea &rUpdateArea)
Gets called when area can be handled by scrolling.
css::uno::Reference< css::rendering::XAnimatedSprite > createSpriteFromBitmaps(const css::uno::Sequence< css::uno::Reference< css::rendering::XBitmap > > &animationBitmaps, sal_Int8 interpolationMode)
void genericUpdate(const ::basegfx::B2DRange &rTotalArea, const std::vector< ::canvas::Sprite::Reference > &rSortedUpdateSprites)
css::uno::Reference< css::rendering::XCustomSprite > createCustomSprite(const css::geometry::RealSize2D &spriteSize)
bool updateScreen(const ::basegfx::B2IRange &rCurrArea, bool bUpdateAll, bool &io_bSurfaceDirty)
Actually perform the screen update.
Product of this component's factory.
::cairo::SurfaceSharedPtr const & getWindowSurface() const
::cairo::SurfaceSharedPtr const & getBufferSurface() const
const ::basegfx::B2ISize & getSizePixel() const
This class manages smooth SpriteCanvas updates.
void forEachSpriteArea(Functor &rFunc) const
Call given functor for each sprite area that needs an update.
void clearChangeRecords()
Clear sprite change records (typically directly after a screen update)
void forEachSprite(const Functor &rFunc) const
Call given functor for each active sprite.
#define ENSURE_OR_THROW(c, m)
#define SAL_INFO(area, stream)
std::shared_ptr< Surface > SurfaceSharedPtr
std::shared_ptr< cairo_t > CairoSharedPtr