23#include <boost/cast.hpp>
26#include <rtl/math.hxx>
40#define FPS_BOUNDS ::tools::Rectangle(0,0,130,90)
41#define INFO_COLOR COL_RED
53 const ::canvas::Sprite::Reference& rSprite )
57 ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->redraw(rOutDev,
61 double calcNumPixel( const ::canvas::Sprite::Reference& rSprite )
63 const ::basegfx::B2DVector& rSize(
64 ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->getSizePixel() );
66 return rSize.getX() * rSize.getY();
71 const ::basegfx::B2DRange& rArea )
76 rOutDev.
DrawOutDev( rPos, rSize, rPos, rSize, rBackBuffer );
79 void opaqueUpdateSpriteArea( const ::canvas::Sprite::Reference& rSprite,
81 const ::basegfx::B2IRange& rArea )
83 const ::tools::Rectangle& rRequestedArea(
95 ::boost::polymorphic_downcast< Sprite* >(
96 rSprite.get() )->redraw( rOutDev,
103 const OUString& rStr,
120 mpRedrawManager( nullptr ),
121 mpOwningSpriteCanvas( nullptr ),
123 mbShowFrameInfo( false ),
124 mbShowSpriteBounds( false ),
125 mbIsUnsafeScrolling( false )
127#if OSL_DEBUG_LEVEL > 0
131 static bool enableShowSpriteBounds = getenv(
"CANVAS_SPRITE_BOUNDS") !=
nullptr;
164 const uno::Reference< rendering::XAnimation >& )
166 return uno::Reference< rendering::XAnimatedSprite >();
170 const uno::Sequence< uno::Reference< rendering::XBitmap > >& ,
173 return uno::Reference< rendering::XAnimatedSprite >();
179 return uno::Reference< rendering::XCustomSprite >();
181 return uno::Reference< rendering::XCustomSprite >(
182 new CanvasCustomSprite( spriteSize,
191 return uno::Reference< rendering::XSprite >();
195 bool& io_bSurfaceDirty )
217 const Point aEmptyPoint(0,0);
235 if( !bUpdateAll && !io_bSurfaceDirty )
260 maVDev->SetOutputSizePixel( aOutDevSize );
261 maVDev->EnableMapMode(
false );
262 maVDev->DrawOutDev( aEmptyPoint, aOutDevSize,
263 aEmptyPoint, aOutDevSize,
270 [&rTmpOutDev]( const ::canvas::Sprite::Reference& rSprite )
271 { spriteRedraw( rTmpOutDev, rSprite ); }
279 aEmptyPoint, aOutDevSize,
287 io_bSurfaceDirty =
false;
296#if OSL_DEBUG_LEVEL > 0
297 static ::canvas::tools::ElapsedTime aElapsedTime;
300 SAL_INFO(
"canvas.vcl",
"SpriteCanvasHelper::updateScreen(): flip done at " <<
301 aElapsedTime.getElapsedTime() );
322 "SpriteCanvasHelper::backgroundPaint(): NULL device pointer " );
328 repaintBackground( rOutDev, rBackOutDev, rUpdateRect );
332 const ::basegfx::B2DRange& rMoveEnd,
333 const ::canvas::SpriteRedrawManager::UpdateArea& rUpdateArea )
338 "SpriteCanvasHelper::scrollUpdate(): NULL device pointer " );
345 const ::basegfx::B2IRange aOutputBounds( 0,0,
346 rTargetSizePixel.
Width(),
347 rTargetSizePixel.
Height() );
356 const ::basegfx::B2IRange& rDestRect(
360 std::vector< ::basegfx::B2IRange > aUnscrollableAreas;
381 for(
const auto& rComponent : rUpdateArea.maComponentList )
383 const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() );
386 ::boost::polymorphic_downcast< Sprite* >(
387 rSprite.get() )->redraw( rOutDev,
398 static_cast<sal_Int32
>(aSourceRect.
getRange().
getY()) ) );
400 const ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
401 aFirst( rUpdateArea.maComponentList.begin() );
404 "VCLCanvas::scrollUpdate(): no sprite" );
411 for(
const auto& rArea : aUnscrollableAreas )
412 opaqueUpdateSpriteArea( aFirst->second.getSprite(),
421 std::vector< ::basegfx::B2DRange > aUncoveredAreas;
422 ::basegfx::computeSetDifference( aUncoveredAreas,
423 rUpdateArea.maTotalBounds,
426 for(
const auto& rArea : aUncoveredAreas )
427 repaintBackground( rOutDev, rBackOutDev, rArea );
431 const std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
436 "SpriteCanvasHelper::opaqueUpdate(): NULL device pointer " );
448 for(
const auto& rSprite : rSortedUpdateSprites )
451 ::boost::polymorphic_downcast< Sprite* >(
452 rSprite.get() )->redraw( rOutDev,
458 const std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
463 "SpriteCanvasHelper::genericUpdate(): NULL device pointer " );
476 const ::Point aOutputPosition(
478 static_cast< sal_Int32
>(rRequestedArea.getMinX()) ),
480 static_cast< sal_Int32
>(rRequestedArea.getMinY()) ) );
485 const ::Size aOutputSize(
487 std::min(
static_cast< sal_Int32
>(rTargetSizePixel.
Width() - aOutputPosition.X()),
488 ::canvas::tools::roundUp( rRequestedArea.getMaxX() - aOutputPosition.X() ))),
490 std::min(
static_cast< sal_Int32
>(rTargetSizePixel.
Height() - aOutputPosition.Y()),
491 ::canvas::tools::roundUp( rRequestedArea.getMaxY() - aOutputPosition.Y() ))));
494 if( aOutputSize.Width() == 0 &&
495 aOutputSize.Height() == 0 )
500 const Point aEmptyPoint(0,0);
501 const Size aCurrOutputSize(
maVDev->GetOutputSizePixel() );
505 if( aCurrOutputSize.
Width() < aOutputSize.Width() ||
506 aCurrOutputSize.
Height() < aOutputSize.Height() )
513 maVDev->SetOutputSizePixel( aOutputSize );
517 maVDev->EnableMapMode(
false );
518 maVDev->SetAntialiasing( AntialiasingFlags::Enable );
520 maVDev->DrawOutDev( aEmptyPoint, aOutputSize,
521 aOutputPosition, aOutputSize,
526 for(
const auto& rSprite : rSortedUpdateSprites )
530 Sprite* pSprite = ::boost::polymorphic_downcast< Sprite* >( rSprite.get() );
534 const ::basegfx::B2DPoint& rSpriteScreenPos( pSprite->
getPosPixel() );
535 const ::basegfx::B2DPoint& rSpriteRenderPos(
546 rOutDev.
DrawOutDev( aOutputPosition, aOutputSize,
547 aEmptyPoint, aOutputSize,
556 OUString
text( ::rtl::math::doubleToUString( denominator == 0.0 ? 100.0 : 1.0/denominator,
557 rtl_math_StringFormat_F,
558 2,
'.',
nullptr,
' ') );
561 while(
text.getLength() < 6 )
566 renderInfoText( rOutDev,
573 template<
typename T >
struct Adder
575 typedef void result_type;
577 Adder( T& rAdderTarget,
585 void operator()( T nIncrement ) { *
mpTarget += nIncrement; }
591 template<
typename T> Adder<T> makeAdder( T& rAdderTarget,
594 return Adder<T>(rAdderTarget, nIncrement);
609 while(
text.getLength() < 3 )
614 renderInfoText( rOutDev,
631 [&
nPixel]( const ::canvas::Sprite::Reference& rSprite )
632 { makeAdder(
nPixel, 1.0 )( calcNumPixel(rSprite) ); }
635 static const int NUM_VIRDEV(2);
636 static const int BYTES_PER_PIXEL(3);
638 const Size& rVDevSize(
maVDev->GetOutputSizePixel() );
639 const Size& rBackBufferSize( pBackBuffer->getOutDev().GetOutputSizePixel() );
641 const double nMemUsage(
nPixel * NUM_VIRDEV * BYTES_PER_PIXEL +
642 rVDevSize.
Width()*rVDevSize.
Height() * BYTES_PER_PIXEL +
643 rBackBufferSize.
Width()*rBackBufferSize.
Height() * BYTES_PER_PIXEL );
645 OUString
text( ::rtl::math::doubleToUString( nMemUsage / 1048576.0,
646 rtl_math_StringFormat_F,
647 2,
'.',
nullptr,
' ') );
650 while(
text.getLength() < 4 )
655 renderInfoText( rOutDev,
void EnableMapMode(bool bEnable=true)
void SetAntialiasing(AntialiasingFlags nMode)
void SetFont(const vcl::Font &rNewFont)
void SetTextAlign(TextAlign eAlign)
Size GetOutputSizePixel() const
void SetTextColor(const Color &rColor)
SAL_DLLPRIVATE void DrawOutDev(const Point &, const Size &, const Point &, const Size &, const Printer &)=delete
virtual void CopyArea(const Point &rDestPt, const Point &rSrcPt, const Size &rSrcSize, bool bWindowInvalidate=false)
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
OutDevType GetOutDevType() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
virtual vcl::Window * GetOwnerWindow() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
B2IPoint getMinimum() const
B2I64Tuple getRange() 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.
void updateSprite(const Sprite::Reference &rSprite, const ::basegfx::B2DPoint &rPos, const ::basegfx::B2DRange &rUpdateArea)
virtual ::basegfx::B2DPoint getPosPixel() const =0
Query position of the left, top pixel of the sprite.
void SetColor(const Color &)
void SetFontHeight(tools::Long nHeight)
::OutputDevice const * GetOutDev() const
void ExpandPaintClipRegion(const vcl::Region &rRegion)
css::rendering::XGraphicDevice * mpDevice
Phyical output device.
void flush() const
Flush drawing queue.
void disposing()
Release all references.
void init(css::rendering::XGraphicDevice &rDevice, const OutDevProviderSharedPtr &rOutDev, bool bProtect, bool bHaveAlpha)
Initialize canvas helper.
::canvas::SpriteRedrawManager * mpRedrawManager
Set from the SpriteCanvas: instance coordinating sprite redraw.
void renderFrameCounter(OutputDevice &rOutDev)
css::uno::Reference< css::rendering::XSprite > createClonedSprite(const css::uno::Reference< css::rendering::XSprite > &original)
bool mbIsUnsafeScrolling
When true, canvas uses the scroll optimization (direct scrolls in front buffer)
void renderMemUsage(OutputDevice &rOutDev)
bool mbShowFrameInfo
When true, canvas displays debug info on each frame.
css::uno::Reference< css::rendering::XAnimatedSprite > createSpriteFromAnimation(const css::uno::Reference< css::rendering::XAnimation > &animation)
::canvas::tools::ElapsedTime maLastUpdate
For the frame counter timings.
css::uno::Reference< css::rendering::XAnimatedSprite > createSpriteFromBitmaps(const css::uno::Sequence< css::uno::Reference< css::rendering::XBitmap > > &animationBitmaps, sal_Int8 interpolationMode)
void renderSpriteCount(OutputDevice &rOutDev)
css::uno::Reference< css::rendering::XCustomSprite > createCustomSprite(const css::geometry::RealSize2D &spriteSize)
bool mbShowSpriteBounds
When true, canvas creates all new sprites with red lines in the corners.
void backgroundPaint(const ::basegfx::B2DRange &rUpdateRect)
Gets called for simple background repaints.
void scrollUpdate(const ::basegfx::B2DRange &rMoveStart, const ::basegfx::B2DRange &rMoveEnd, const ::canvas::SpriteRedrawManager::UpdateArea &rUpdateArea)
Gets called when area can be handled by scrolling.
void genericUpdate(const ::basegfx::B2DRange &rTotalArea, const std::vector< ::canvas::Sprite::Reference > &rSortedUpdateSprites)
void opaqueUpdate(const ::basegfx::B2DRange &rTotalArea, const std::vector< ::canvas::Sprite::Reference > &rSortedUpdateSprites)
void init(const OutDevProviderSharedPtr &rOutDev, SpriteCanvas &rOwningSpriteCanvas, ::canvas::SpriteRedrawManager &rManager, bool bProtect, bool bHaveAlpha)
void disposing()
Dispose all internal references.
SpriteCanvas * mpOwningSpriteCanvas
Set from the init method. used to generate sprites.
bool updateScreen(bool bUpdateAll, bool &io_bSurfaceDirty)
Actually perform the screen update.
VclPtr< VirtualDevice > maVDev
Background compositing surface.
Product of this component's factory.
BackBufferSharedPtr const & getBackBuffer() const
Get window for this canvas.
OutDevProviderSharedPtr const & getFrontBuffer() const
Get backbuffer for this canvas.
Specialization of canvas::Sprite interface, to also provide redraw methods.
virtual void redraw(OutputDevice &rOutDev, bool bBufferedUpdate) const =0
Redraw sprite at the stored position.
#define ENSURE_OR_THROW(c, m)
#define SAL_INFO(area, stream)
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr
std::shared_ptr< BackBuffer > BackBufferSharedPtr