bump product version to 7.6.3.2-android
[LibreOffice.git] / canvas / source / vcl / spritecanvashelper.cxx
blob37f70a364267b4fdd5ea623d903a05f182ff40d8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <boost/cast.hpp>
25 #include <basegfx/range/b2drectangle.hxx>
26 #include <rtl/math.hxx>
27 #include <comphelper/diagnose_ex.hxx>
28 #include <vcl/canvastools.hxx>
29 #include <vcl/outdev.hxx>
30 #include <vcl/window.hxx>
32 #include <canvas/canvastools.hxx>
34 #include "canvascustomsprite.hxx"
35 #include "spritecanvashelper.hxx"
36 #include "spritecanvas.hxx"
38 using namespace ::com::sun::star;
40 #define FPS_BOUNDS ::tools::Rectangle(0,0,130,90)
41 #define INFO_COLOR COL_RED
43 namespace vclcanvas
45 namespace
47 /** Sprite redraw at original position
49 Used to repaint the whole canvas (background and all
50 sprites)
52 void spriteRedraw( OutputDevice& rOutDev,
53 const ::canvas::Sprite::Reference& rSprite )
55 // downcast to derived vclcanvas::Sprite interface, which
56 // provides the actual redraw methods.
57 ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->redraw(rOutDev,
58 true);
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();
69 void repaintBackground( OutputDevice& rOutDev,
70 OutputDevice const & rBackBuffer,
71 const ::basegfx::B2DRange& rArea )
73 const ::Point& rPos( vcl::unotools::pointFromB2DPoint( rArea.getMinimum()) );
74 const ::Size& rSize( vcl::unotools::sizeFromB2DSize( rArea.getRange()) );
76 rOutDev.DrawOutDev( rPos, rSize, rPos, rSize, rBackBuffer );
79 void opaqueUpdateSpriteArea( const ::canvas::Sprite::Reference& rSprite,
80 OutputDevice& rOutDev,
81 const ::basegfx::B2IRange& rArea )
83 const ::tools::Rectangle& rRequestedArea(
84 vcl::unotools::rectangleFromB2IRectangle( rArea ) );
86 // clip output to actual update region (otherwise a)
87 // wouldn't save much render time, and b) will clutter
88 // scrolled sprite content outside this area)
89 rOutDev.EnableMapMode( false );
90 rOutDev.SetAntialiasing( AntialiasingFlags::Enable );
91 rOutDev.SetClipRegion(vcl::Region(rRequestedArea));
93 // repaint affected sprite directly to output device (at
94 // the actual screen output position)
95 ::boost::polymorphic_downcast< Sprite* >(
96 rSprite.get() )->redraw( rOutDev,
97 false ); // rendering
98 // directly to
99 // frontbuffer
102 void renderInfoText( OutputDevice& rOutDev,
103 const OUString& rStr,
104 const Point& rPos )
106 vcl::Font aVCLFont;
107 aVCLFont.SetFontHeight( 20 );
108 aVCLFont.SetColor( INFO_COLOR );
110 rOutDev.SetTextAlign(ALIGN_TOP);
111 rOutDev.SetTextColor( INFO_COLOR );
112 rOutDev.SetFont( aVCLFont );
114 rOutDev.DrawText( rPos, rStr );
119 SpriteCanvasHelper::SpriteCanvasHelper() :
120 mpRedrawManager( nullptr ),
121 mpOwningSpriteCanvas( nullptr ),
122 maVDev(VclPtr<VirtualDevice>::Create()),
123 mbShowFrameInfo( false ),
124 mbShowSpriteBounds( false ),
125 mbIsUnsafeScrolling( false )
127 #if OSL_DEBUG_LEVEL > 0
128 // inverse defaults for verbose debug mode
129 mbShowFrameInfo = true;
130 // this looks like drawing errors, enable only if explicitly asked for
131 static bool enableShowSpriteBounds = getenv("CANVAS_SPRITE_BOUNDS") != nullptr;
132 mbShowSpriteBounds = enableShowSpriteBounds;
133 #endif
136 SpriteCanvasHelper::~SpriteCanvasHelper()
138 SolarMutexGuard aGuard;
139 maVDev.disposeAndClear();
142 void SpriteCanvasHelper::init( const OutDevProviderSharedPtr& rOutDev,
143 SpriteCanvas& rOwningSpriteCanvas,
144 ::canvas::SpriteRedrawManager& rManager,
145 bool bProtect,
146 bool bHaveAlpha )
148 mpOwningSpriteCanvas = &rOwningSpriteCanvas;
149 mpRedrawManager = &rManager;
151 CanvasHelper::init(rOwningSpriteCanvas,rOutDev,bProtect,bHaveAlpha);
154 void SpriteCanvasHelper::disposing()
156 mpRedrawManager = nullptr;
157 mpOwningSpriteCanvas = nullptr;
159 // forward to base
160 CanvasHelper::disposing();
163 uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromAnimation(
164 const uno::Reference< rendering::XAnimation >& )
166 return uno::Reference< rendering::XAnimatedSprite >();
169 uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromBitmaps(
170 const uno::Sequence< uno::Reference< rendering::XBitmap > >& ,
171 sal_Int8 )
173 return uno::Reference< rendering::XAnimatedSprite >();
176 uno::Reference< rendering::XCustomSprite > SpriteCanvasHelper::createCustomSprite( const geometry::RealSize2D& spriteSize )
178 if( !mpRedrawManager || !mpDevice )
179 return uno::Reference< rendering::XCustomSprite >(); // we're disposed
181 return uno::Reference< rendering::XCustomSprite >(
182 new CanvasCustomSprite( spriteSize,
183 *mpDevice,
184 mpOwningSpriteCanvas,
185 mpOwningSpriteCanvas->getFrontBuffer(),
186 mbShowSpriteBounds ) );
189 uno::Reference< rendering::XSprite > SpriteCanvasHelper::createClonedSprite( const uno::Reference< rendering::XSprite >& )
191 return uno::Reference< rendering::XSprite >();
194 bool SpriteCanvasHelper::updateScreen( bool bUpdateAll,
195 bool& io_bSurfaceDirty )
197 if( !mpRedrawManager ||
198 !mpOwningSpriteCanvas ||
199 !mpOwningSpriteCanvas->getFrontBuffer() ||
200 !mpOwningSpriteCanvas->getBackBuffer() )
202 return false; // disposed, or otherwise dysfunctional
205 // commit to backbuffer
206 flush();
208 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
209 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
210 OutputDevice& rBackOutDev( pBackBuffer->getOutDev() );
212 // actual OutputDevice is a shared resource - restore its
213 // state when done.
214 tools::OutDevStateKeeper aStateKeeper( rOutDev );
216 const Size aOutDevSize( rBackOutDev.GetOutputSizePixel() );
217 const Point aEmptyPoint(0,0);
219 vcl::Window* pTargetWindow = nullptr;
220 if( rOutDev.GetOutDevType() == OUTDEV_WINDOW )
222 pTargetWindow = rOutDev.GetOwnerWindow(); // TODO(Q3): Evil downcast.
224 // we're double-buffered, thus no need for paint area-limiting
225 // clips. besides that, will interfere with animations (as for
226 // Window-invalidate repaints, only parts of the window will
227 // be redrawn otherwise)
228 const vcl::Region aFullWindowRegion( ::tools::Rectangle(aEmptyPoint,
229 aOutDevSize) );
230 pTargetWindow->ExpandPaintClipRegion(aFullWindowRegion);
233 // TODO(P1): Might be worthwhile to track areas of background
234 // changes, too.
235 if( !bUpdateAll && !io_bSurfaceDirty )
237 if( mbShowFrameInfo )
239 // also repaint background below frame counter (fake
240 // that as a sprite vanishing in this area)
241 mpRedrawManager->updateSprite( ::canvas::Sprite::Reference(),
242 ::basegfx::B2DPoint(),
243 ::basegfx::B2DRectangle( 0.0, 0.0,
244 FPS_BOUNDS.Right(),
245 FPS_BOUNDS.Bottom() ) );
248 // background has not changed, so we're free to optimize
249 // repaint to areas where a sprite has changed
251 // process each independent area of overlapping sprites
252 // separately.
253 mpRedrawManager->forEachSpriteArea( *this );
255 else
257 // background has changed, so we currently have no choice
258 // but repaint everything (or caller requested that)
260 maVDev->SetOutputSizePixel( aOutDevSize );
261 maVDev->EnableMapMode( false );
262 maVDev->DrawOutDev( aEmptyPoint, aOutDevSize,
263 aEmptyPoint, aOutDevSize,
264 rBackOutDev );
266 // repaint all active sprites on top of background into
267 // VDev.
268 OutputDevice& rTmpOutDev( *maVDev );
269 mpRedrawManager->forEachSprite(
270 [&rTmpOutDev]( const ::canvas::Sprite::Reference& rSprite )
271 { spriteRedraw( rTmpOutDev, rSprite ); }
274 // flush to screen
275 rOutDev.EnableMapMode( false );
276 rOutDev.SetAntialiasing( AntialiasingFlags::Enable );
277 rOutDev.SetClipRegion();
278 rOutDev.DrawOutDev( aEmptyPoint, aOutDevSize,
279 aEmptyPoint, aOutDevSize,
280 *maVDev );
283 // change record vector must be cleared, for the next turn of
284 // rendering and sprite changing
285 mpRedrawManager->clearChangeRecords();
287 io_bSurfaceDirty = false;
289 if( mbShowFrameInfo )
291 renderFrameCounter( rOutDev );
292 renderSpriteCount( rOutDev );
293 renderMemUsage( rOutDev );
296 #if OSL_DEBUG_LEVEL > 0
297 static ::canvas::tools::ElapsedTime aElapsedTime;
299 // log time immediately after surface flip
300 SAL_INFO("canvas.vcl", "SpriteCanvasHelper::updateScreen(): flip done at " <<
301 aElapsedTime.getElapsedTime() );
302 #endif
304 // sync output with screen, to ensure that we don't queue up
305 // render requests (calling code might rely on timing,
306 // i.e. assume that things are visible on screen after
307 // updateScreen() returns).
308 if( pTargetWindow )
310 // commit to screen
311 pTargetWindow->GetOutDev()->Flush();
314 return true;
317 void SpriteCanvasHelper::backgroundPaint( const ::basegfx::B2DRange& rUpdateRect )
319 ENSURE_OR_THROW( mpOwningSpriteCanvas &&
320 mpOwningSpriteCanvas->getBackBuffer() &&
321 mpOwningSpriteCanvas->getFrontBuffer(),
322 "SpriteCanvasHelper::backgroundPaint(): NULL device pointer " );
324 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
325 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
326 OutputDevice& rBackOutDev( pBackBuffer->getOutDev() );
328 repaintBackground( rOutDev, rBackOutDev, rUpdateRect );
331 void SpriteCanvasHelper::scrollUpdate( const ::basegfx::B2DRange& rMoveStart,
332 const ::basegfx::B2DRange& rMoveEnd,
333 const ::canvas::SpriteRedrawManager::UpdateArea& rUpdateArea )
335 ENSURE_OR_THROW( mpOwningSpriteCanvas &&
336 mpOwningSpriteCanvas->getBackBuffer() &&
337 mpOwningSpriteCanvas->getFrontBuffer(),
338 "SpriteCanvasHelper::scrollUpdate(): NULL device pointer " );
340 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
341 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
342 OutputDevice& rBackOutDev( pBackBuffer->getOutDev() );
344 const Size& rTargetSizePixel( rOutDev.GetOutputSizePixel() );
345 const ::basegfx::B2IRange aOutputBounds( 0,0,
346 rTargetSizePixel.Width(),
347 rTargetSizePixel.Height() );
349 // round rectangles to integer pixel. Note: have to be
350 // extremely careful here, to avoid off-by-one errors for
351 // the destination area: otherwise, the next scroll update
352 // would copy pixel that are not supposed to be part of
353 // the sprite.
354 ::basegfx::B2IRange aSourceRect(
355 ::canvas::tools::spritePixelAreaFromB2DRange( rMoveStart ) );
356 const ::basegfx::B2IRange& rDestRect(
357 ::canvas::tools::spritePixelAreaFromB2DRange( rMoveEnd ) );
358 ::basegfx::B2IPoint aDestPos( rDestRect.getMinimum() );
360 std::vector< ::basegfx::B2IRange > aUnscrollableAreas;
362 // Since strictly speaking, this scroll algorithm is plain
363 // buggy, the scrolled area might actually lie _below_ another
364 // window - we've made this feature configurable via
365 // mbIsUnsafeScrolling.
367 // clip to output bounds (cannot properly scroll stuff
368 // _outside_ our screen area)
369 if( !mbIsUnsafeScrolling ||
370 !::canvas::tools::clipScrollArea( aSourceRect,
371 aDestPos,
372 aUnscrollableAreas,
373 aOutputBounds ) )
375 // fully clipped scroll area: cannot simply scroll
376 // then. Perform normal opaque update (can use that, since
377 // one of the preconditions for scrollable update is
378 // opaque sprite content)
380 // repaint all affected sprites directly to output device
381 for( const auto& rComponent : rUpdateArea.maComponentList )
383 const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() );
385 if( rSprite.is() )
386 ::boost::polymorphic_downcast< Sprite* >(
387 rSprite.get() )->redraw( rOutDev,
388 false );
391 else
393 // scroll rOutDev content
394 rOutDev.CopyArea( vcl::unotools::pointFromB2IPoint( aDestPos ),
395 vcl::unotools::pointFromB2IPoint( aSourceRect.getMinimum() ),
396 // TODO(Q2): use numeric_cast to check range
397 ::Size( static_cast<sal_Int32>(aSourceRect.getRange().getX()),
398 static_cast<sal_Int32>(aSourceRect.getRange().getY()) ) );
400 const ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
401 aFirst( rUpdateArea.maComponentList.begin() );
403 ENSURE_OR_THROW( aFirst->second.getSprite().is(),
404 "VCLCanvas::scrollUpdate(): no sprite" );
406 // repaint uncovered areas from sprite. Need to actually
407 // clip here, since we're only repainting _parts_ of the
408 // sprite
409 rOutDev.Push( vcl::PushFlags::CLIPREGION );
411 for( const auto& rArea : aUnscrollableAreas )
412 opaqueUpdateSpriteArea( aFirst->second.getSprite(),
413 rOutDev, rArea );
415 rOutDev.Pop();
418 // repaint uncovered areas from backbuffer - take the
419 // _rounded_ rectangles from above, to have the update
420 // consistent with the scroll above.
421 std::vector< ::basegfx::B2DRange > aUncoveredAreas;
422 ::basegfx::computeSetDifference( aUncoveredAreas,
423 rUpdateArea.maTotalBounds,
424 ::basegfx::B2DRange( rDestRect ) );
426 for( const auto& rArea : aUncoveredAreas )
427 repaintBackground( rOutDev, rBackOutDev, rArea );
430 void SpriteCanvasHelper::opaqueUpdate( SAL_UNUSED_PARAMETER const ::basegfx::B2DRange&,
431 const std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
433 ENSURE_OR_THROW( mpOwningSpriteCanvas &&
434 mpOwningSpriteCanvas->getBackBuffer() &&
435 mpOwningSpriteCanvas->getFrontBuffer(),
436 "SpriteCanvasHelper::opaqueUpdate(): NULL device pointer " );
438 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
440 // no need to clip output to actual update region - there will
441 // always be ALL sprites contained in the rectangular update
442 // area contained in rTotalArea (that's the way
443 // B2DConnectedRanges work). If rTotalArea appears to be
444 // smaller than the sprite - then this sprite carries a clip,
445 // and the update will be constrained to that rect.
447 // repaint all affected sprites directly to output device
448 for( const auto& rSprite : rSortedUpdateSprites )
450 if( rSprite.is() )
451 ::boost::polymorphic_downcast< Sprite* >(
452 rSprite.get() )->redraw( rOutDev,
453 false );
457 void SpriteCanvasHelper::genericUpdate( const ::basegfx::B2DRange& rRequestedArea,
458 const std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
460 ENSURE_OR_THROW( mpOwningSpriteCanvas &&
461 mpOwningSpriteCanvas->getBackBuffer() &&
462 mpOwningSpriteCanvas->getFrontBuffer(),
463 "SpriteCanvasHelper::genericUpdate(): NULL device pointer " );
465 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
466 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
467 OutputDevice& rBackOutDev( pBackBuffer->getOutDev() );
469 // limit size of update VDev to target outdev's size
470 const Size& rTargetSizePixel( rOutDev.GetOutputSizePixel() );
472 // round output position towards zero. Don't want to truncate
473 // a fraction of a sprite pixel... Clip position at origin,
474 // otherwise, truncation of size below might leave visible
475 // areas uncovered by VDev.
476 const ::Point aOutputPosition(
477 std::max( sal_Int32( 0 ),
478 static_cast< sal_Int32 >(rRequestedArea.getMinX()) ),
479 std::max( sal_Int32( 0 ),
480 static_cast< sal_Int32 >(rRequestedArea.getMinY()) ) );
481 // round output size towards +infty. Don't want to truncate a
482 // fraction of a sprite pixel... Limit coverage of VDev to
483 // output device's area (i.e. not only to total size, but to
484 // cover _only_ the visible parts).
485 const ::Size aOutputSize(
486 std::max( sal_Int32( 0 ),
487 std::min( static_cast< sal_Int32 >(rTargetSizePixel.Width() - aOutputPosition.X()),
488 ::canvas::tools::roundUp( rRequestedArea.getMaxX() - aOutputPosition.X() ))),
489 std::max( sal_Int32( 0 ),
490 std::min( static_cast< sal_Int32 >(rTargetSizePixel.Height() - aOutputPosition.Y()),
491 ::canvas::tools::roundUp( rRequestedArea.getMaxY() - aOutputPosition.Y() ))));
493 // early exit for empty output area.
494 if( aOutputSize.Width() == 0 &&
495 aOutputSize.Height() == 0 )
497 return;
500 const Point aEmptyPoint(0,0);
501 const Size aCurrOutputSize( maVDev->GetOutputSizePixel() );
503 // adapt maVDev's size to the area that actually needs the
504 // repaint.
505 if( aCurrOutputSize.Width() < aOutputSize.Width() ||
506 aCurrOutputSize.Height() < aOutputSize.Height() )
508 // TODO(P1): Come up with a clever tactic to reduce maVDev
509 // from time to time. Reduction with threshold (say, if
510 // maVDev is more than twice too large) is not wise, as
511 // this might then toggle within the same updateScreen(),
512 // but for different disjunct sprite areas.
513 maVDev->SetOutputSizePixel( aOutputSize );
516 // paint background
517 maVDev->EnableMapMode( false );
518 maVDev->SetAntialiasing( AntialiasingFlags::Enable );
519 maVDev->SetClipRegion();
520 maVDev->DrawOutDev( aEmptyPoint, aOutputSize,
521 aOutputPosition, aOutputSize,
522 rBackOutDev );
524 // repaint all affected sprites on top of background into
525 // VDev.
526 for( const auto& rSprite : rSortedUpdateSprites )
528 if( rSprite.is() )
530 Sprite* pSprite = ::boost::polymorphic_downcast< Sprite* >( rSprite.get() );
532 // calc relative sprite position in rUpdateArea (which
533 // need not be the whole screen!)
534 const ::basegfx::B2DPoint& rSpriteScreenPos( pSprite->getPosPixel() );
535 const ::basegfx::B2DPoint& rSpriteRenderPos(
536 rSpriteScreenPos - vcl::unotools::b2DPointFromPoint(aOutputPosition)
539 pSprite->redraw( *maVDev, rSpriteRenderPos, true );
543 // flush to screen
544 rOutDev.EnableMapMode( false );
545 rOutDev.SetAntialiasing( AntialiasingFlags::Enable );
546 rOutDev.DrawOutDev( aOutputPosition, aOutputSize,
547 aEmptyPoint, aOutputSize,
548 *maVDev );
551 void SpriteCanvasHelper::renderFrameCounter( OutputDevice& rOutDev )
553 const double denominator( maLastUpdate.getElapsedTime() );
554 maLastUpdate.reset();
556 OUString text( ::rtl::math::doubleToUString( denominator == 0.0 ? 100.0 : 1.0/denominator,
557 rtl_math_StringFormat_F,
558 2,'.',nullptr,' ') );
560 // pad with leading space
561 while( text.getLength() < 6 )
562 text = " " + text;
564 text += " fps";
566 renderInfoText( rOutDev,
567 text,
568 Point(0, 0) );
571 namespace
573 template< typename T > struct Adder
575 typedef void result_type;
577 Adder( T& rAdderTarget,
578 T nIncrement ) :
579 mpTarget( &rAdderTarget ),
580 mnIncrement( nIncrement )
584 void operator()( const ::canvas::Sprite::Reference& ) { *mpTarget += mnIncrement; }
585 void operator()( T nIncrement ) { *mpTarget += nIncrement; }
587 T* mpTarget;
588 T mnIncrement;
591 template< typename T> Adder<T> makeAdder( T& rAdderTarget,
592 T nIncrement )
594 return Adder<T>(rAdderTarget, nIncrement);
598 void SpriteCanvasHelper::renderSpriteCount( OutputDevice& rOutDev )
600 if( !mpRedrawManager )
601 return;
603 sal_Int32 nCount(0);
605 mpRedrawManager->forEachSprite( makeAdder(nCount,sal_Int32(1)) );
606 OUString text( OUString::number(nCount) );
608 // pad with leading space
609 while( text.getLength() < 3 )
610 text = " " + text;
612 text = "Sprites: " + text;
614 renderInfoText( rOutDev,
615 text,
616 Point(0, 30) );
619 void SpriteCanvasHelper::renderMemUsage( OutputDevice& rOutDev )
621 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
623 if( !(mpRedrawManager &&
624 pBackBuffer) )
625 return;
627 double nPixel(0.0);
629 // accumulate pixel count for each sprite into fCount
630 mpRedrawManager->forEachSprite(
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,' ') );
649 // pad with leading space
650 while( text.getLength() < 4 )
651 text = " " + text;
653 text = "Mem: " + text + "MB";
655 renderInfoText( rOutDev,
656 text,
657 Point(0, 60) );
661 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */