update dev300-m58
[ooovba.git] / canvas / source / vcl / spritecanvashelper.cxx
blob976a1b1be68a473557d67aa4d33c704a0a94b352
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: spritecanvashelper.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <tools/diagnose_ex.h>
36 #include <canvas/verbosetrace.hxx>
37 #include <canvas/canvastools.hxx>
39 #include <vcl/canvastools.hxx>
40 #include <vcl/outdev.hxx>
41 #include <vcl/window.hxx>
42 #include <vcl/bitmapex.hxx>
44 #include <basegfx/range/b2drectangle.hxx>
45 #include <basegfx/tools/canvastools.hxx>
47 #include <boost/cast.hpp>
49 #include "spritecanvashelper.hxx"
50 #include "canvascustomsprite.hxx"
53 using namespace ::com::sun::star;
55 #define FPS_BOUNDS Rectangle(0,0,130,90)
56 #define INFO_COLOR COL_RED
58 namespace vclcanvas
60 namespace
62 /** Sprite redraw at original position
64 Used to repaint the whole canvas (background and all
65 sprites)
67 void spriteRedraw( OutputDevice& rOutDev,
68 const ::canvas::Sprite::Reference& rSprite )
70 // downcast to derived vclcanvas::Sprite interface, which
71 // provides the actual redraw methods.
72 ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->redraw(rOutDev,
73 true);
76 double calcNumPixel( const ::canvas::Sprite::Reference& rSprite )
78 const ::basegfx::B2DSize& rSize(
79 ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->getSizePixel() );
81 return rSize.getX() * rSize.getY();
84 void repaintBackground( OutputDevice& rOutDev,
85 OutputDevice& rBackBuffer,
86 const ::basegfx::B2DRange& rArea )
88 const ::Point& rPos( ::vcl::unotools::pointFromB2DPoint( rArea.getMinimum()) );
89 const ::Size& rSize( ::vcl::unotools::sizeFromB2DSize( rArea.getRange()) );
91 rOutDev.DrawOutDev( rPos, rSize, rPos, rSize, rBackBuffer );
94 void opaqueUpdateSpriteArea( const ::canvas::Sprite::Reference& rSprite,
95 OutputDevice& rOutDev,
96 const ::basegfx::B2IRange& rArea )
98 const Rectangle& rRequestedArea(
99 ::vcl::unotools::rectangleFromB2IRectangle( rArea ) );
101 // clip output to actual update region (otherwise a)
102 // wouldn't save much render time, and b) will clutter
103 // scrolled sprite content outside this area)
104 rOutDev.EnableMapMode( FALSE );
105 rOutDev.SetClipRegion( rRequestedArea );
107 // repaint affected sprite directly to output device (at
108 // the actual screen output position)
109 ::boost::polymorphic_downcast< Sprite* >(
110 rSprite.get() )->redraw( rOutDev,
111 false ); // rendering
112 // directly to
113 // frontbuffer
116 /** Repaint sprite at original position
118 Used for opaque updates, which render directly to the
119 front buffer.
121 void spriteRedrawStub( OutputDevice& rOutDev,
122 const ::canvas::Sprite::Reference& rSprite )
124 if( rSprite.is() )
126 ::boost::polymorphic_downcast< Sprite* >(
127 rSprite.get() )->redraw( rOutDev,
128 false );
132 /** Repaint sprite at given position
134 Used for generic update, which renders into vdev of
135 adapted size.
137 void spriteRedrawStub2( OutputDevice& rOutDev,
138 const ::basegfx::B2DPoint& rOutPos,
139 const ::canvas::Sprite::Reference& rSprite )
141 if( rSprite.is() )
143 Sprite* pSprite = ::boost::polymorphic_downcast< Sprite* >(
144 rSprite.get() );
146 // calc relative sprite position in rUpdateArea (which
147 // need not be the whole screen!)
148 const ::basegfx::B2DPoint& rSpriteScreenPos( pSprite->getPosPixel() );
149 const ::basegfx::B2DPoint& rSpriteRenderPos( rSpriteScreenPos - rOutPos );
151 pSprite->redraw( rOutDev, rSpriteRenderPos, true );
155 /** Repaint sprite at original position
157 Used for opaque updates from scrollUpdate(), which render
158 directly to the front buffer.
160 void spriteRedrawStub3( OutputDevice& rOutDev,
161 const ::canvas::SpriteRedrawManager::AreaComponent& rComponent )
163 const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() );
165 if( rSprite.is() )
167 ::boost::polymorphic_downcast< Sprite* >(
168 rSprite.get() )->redraw( rOutDev,
169 false );
173 void renderInfoText( OutputDevice& rOutDev,
174 const ::rtl::OUString& rStr,
175 const Point& rPos )
177 Font aVCLFont;
178 aVCLFont.SetHeight( 20 );
179 aVCLFont.SetColor( Color( INFO_COLOR ) );
181 rOutDev.SetTextAlign(ALIGN_TOP);
182 rOutDev.SetTextColor( Color( INFO_COLOR ) );
183 rOutDev.SetFont( aVCLFont );
185 rOutDev.DrawText( rPos, rStr );
190 SpriteCanvasHelper::SpriteCanvasHelper() :
191 mpRedrawManager( NULL ),
192 mpOwningSpriteCanvas( NULL ),
193 maVDev(),
194 maLastUpdate(),
195 mbShowFrameInfo( false ),
196 mbShowSpriteBounds( false ),
197 mbIsUnsafeScrolling( false )
199 #if defined(VERBOSE) && OSL_DEBUG_LEVEL > 0
200 // inverse defaults for verbose debug mode
201 mbShowSpriteBounds = mbShowFrameInfo = true;
202 #endif
205 void SpriteCanvasHelper::init( const OutDevProviderSharedPtr& rOutDev,
206 SpriteCanvas& rOwningSpriteCanvas,
207 ::canvas::SpriteRedrawManager& rManager,
208 bool bProtect,
209 bool bHaveAlpha )
211 mpOwningSpriteCanvas = &rOwningSpriteCanvas;
212 mpRedrawManager = &rManager;
214 CanvasHelper::init(rOwningSpriteCanvas,rOutDev,bProtect,bHaveAlpha);
217 void SpriteCanvasHelper::disposing()
219 mpRedrawManager = NULL;
220 mpOwningSpriteCanvas = NULL;
222 // forward to base
223 CanvasHelper::disposing();
226 uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromAnimation(
227 const uno::Reference< rendering::XAnimation >& )
229 return uno::Reference< rendering::XAnimatedSprite >();
232 uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromBitmaps(
233 const uno::Sequence< uno::Reference< rendering::XBitmap > >& ,
234 sal_Int8 )
236 return uno::Reference< rendering::XAnimatedSprite >();
239 uno::Reference< rendering::XCustomSprite > SpriteCanvasHelper::createCustomSprite( const geometry::RealSize2D& spriteSize )
241 if( !mpRedrawManager || !mpDevice )
242 return uno::Reference< rendering::XCustomSprite >(); // we're disposed
244 return uno::Reference< rendering::XCustomSprite >(
245 new CanvasCustomSprite( spriteSize,
246 *mpDevice,
247 mpOwningSpriteCanvas,
248 mpOwningSpriteCanvas->getFrontBuffer(),
249 mbShowSpriteBounds ) );
252 uno::Reference< rendering::XSprite > SpriteCanvasHelper::createClonedSprite( const uno::Reference< rendering::XSprite >& )
254 return uno::Reference< rendering::XSprite >();
257 sal_Bool SpriteCanvasHelper::updateScreen( sal_Bool bUpdateAll,
258 bool& io_bSurfaceDirty )
260 if( !mpRedrawManager ||
261 !mpOwningSpriteCanvas ||
262 !mpOwningSpriteCanvas->getFrontBuffer() ||
263 !mpOwningSpriteCanvas->getBackBuffer() )
265 return sal_False; // disposed, or otherwise dysfunctional
268 // commit to backbuffer
269 flush();
271 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
272 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
273 OutputDevice& rBackOutDev( pBackBuffer->getOutDev() );
275 // actual OutputDevice is a shared resource - restore its
276 // state when done.
277 tools::OutDevStateKeeper aStateKeeper( rOutDev );
279 const Size aOutDevSize( rBackOutDev.GetOutputSizePixel() );
280 const Point aEmptyPoint(0,0);
282 Window* pTargetWindow = NULL;
283 if( rOutDev.GetOutDevType() == OUTDEV_WINDOW )
285 pTargetWindow = &static_cast<Window&>(rOutDev); // TODO(Q3): Evil downcast.
287 // we're double-buffered, thus no need for paint area-limiting
288 // clips. besides that, will interfere with animations (as for
289 // Window-invalidate repaints, only parts of the window will
290 // be redrawn otherwise)
291 const Region aFullWindowRegion( Rectangle(aEmptyPoint,
292 aOutDevSize) );
293 pTargetWindow->ExpandPaintClipRegion(aFullWindowRegion);
296 // TODO(P1): Might be worthwile to track areas of background
297 // changes, too.
298 if( !bUpdateAll && !io_bSurfaceDirty )
300 if( mbShowFrameInfo )
302 // also repaint background below frame counter (fake
303 // that as a sprite vanishing in this area)
304 mpRedrawManager->updateSprite( ::canvas::Sprite::Reference(),
305 ::basegfx::B2DPoint(),
306 ::basegfx::B2DRectangle( 0.0, 0.0,
307 FPS_BOUNDS.Right(),
308 FPS_BOUNDS.Bottom() ) );
311 // background has not changed, so we're free to optimize
312 // repaint to areas where a sprite has changed
314 // process each independent area of overlapping sprites
315 // separately.
316 mpRedrawManager->forEachSpriteArea( *this );
318 else
320 // background has changed, so we currently have no choice
321 // but repaint everything (or caller requested that)
323 maVDev->SetOutputSizePixel( aOutDevSize );
324 maVDev->EnableMapMode( FALSE );
325 maVDev->DrawOutDev( aEmptyPoint, aOutDevSize,
326 aEmptyPoint, aOutDevSize,
327 rBackOutDev );
329 // repaint all active sprites on top of background into
330 // VDev.
331 mpRedrawManager->forEachSprite(
332 ::boost::bind(
333 &spriteRedraw,
334 ::boost::ref( maVDev.get() ),
335 _1 ) );
337 // flush to screen
338 rOutDev.EnableMapMode( FALSE );
339 rOutDev.SetClipRegion();
340 rOutDev.DrawOutDev( aEmptyPoint, aOutDevSize,
341 aEmptyPoint, aOutDevSize,
342 *maVDev );
345 // change record vector must be cleared, for the next turn of
346 // rendering and sprite changing
347 mpRedrawManager->clearChangeRecords();
349 io_bSurfaceDirty = false;
351 if( mbShowFrameInfo )
353 renderFrameCounter( rOutDev );
354 renderSpriteCount( rOutDev );
355 renderMemUsage( rOutDev );
358 #if defined(VERBOSE) && OSL_DEBUG_LEVEL > 0
359 static ::canvas::tools::ElapsedTime aElapsedTime;
361 // log time immediately after surface flip
362 OSL_TRACE( "SpriteCanvasHelper::updateScreen(): flip done at %f",
363 aElapsedTime.getElapsedTime() );
364 #endif
366 // sync output with screen, to ensure that we don't queue up
367 // render requests (calling code might rely on timing,
368 // i.e. assume that things are visible on screen after
369 // updateScreen() returns).
370 if( pTargetWindow )
372 // commit to screen
373 pTargetWindow->Sync();
376 return sal_True;
379 void SpriteCanvasHelper::backgroundPaint( const ::basegfx::B2DRange& rUpdateRect )
381 ENSURE_OR_THROW( mpOwningSpriteCanvas &&
382 mpOwningSpriteCanvas->getBackBuffer() &&
383 mpOwningSpriteCanvas->getFrontBuffer(),
384 "SpriteCanvasHelper::backgroundPaint(): NULL device pointer " );
386 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
387 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
388 OutputDevice& rBackOutDev( pBackBuffer->getOutDev() );
390 repaintBackground( rOutDev, rBackOutDev, rUpdateRect );
393 void SpriteCanvasHelper::scrollUpdate( const ::basegfx::B2DRange& rMoveStart,
394 const ::basegfx::B2DRange& rMoveEnd,
395 const ::canvas::SpriteRedrawManager::UpdateArea& rUpdateArea )
397 ENSURE_OR_THROW( mpOwningSpriteCanvas &&
398 mpOwningSpriteCanvas->getBackBuffer() &&
399 mpOwningSpriteCanvas->getFrontBuffer(),
400 "SpriteCanvasHelper::scrollUpdate(): NULL device pointer " );
402 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
403 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
404 OutputDevice& rBackOutDev( pBackBuffer->getOutDev() );
406 const Size& rTargetSizePixel( rOutDev.GetOutputSizePixel() );
407 const ::basegfx::B2IRange aOutputBounds( 0,0,
408 rTargetSizePixel.Width(),
409 rTargetSizePixel.Height() );
411 // round rectangles to integer pixel. Note: have to be
412 // extremely careful here, to avoid off-by-one errors for
413 // the destination area: otherwise, the next scroll update
414 // would copy pixel that are not supposed to be part of
415 // the sprite.
416 ::basegfx::B2IRange aSourceRect(
417 ::canvas::tools::spritePixelAreaFromB2DRange( rMoveStart ) );
418 const ::basegfx::B2IRange& rDestRect(
419 ::canvas::tools::spritePixelAreaFromB2DRange( rMoveEnd ) );
420 ::basegfx::B2IPoint aDestPos( rDestRect.getMinimum() );
422 ::std::vector< ::basegfx::B2IRange > aUnscrollableAreas;
424 // Since strictly speaking, this scroll algorithm is plain
425 // buggy, the scrolled area might actually lie _below_ another
426 // window - we've made this feature configurable via
427 // mbIsUnsafeScrolling.
429 // clip to output bounds (cannot properly scroll stuff
430 // _outside_ our screen area)
431 if( !mbIsUnsafeScrolling ||
432 !::canvas::tools::clipScrollArea( aSourceRect,
433 aDestPos,
434 aUnscrollableAreas,
435 aOutputBounds ) )
437 // fully clipped scroll area: cannot simply scroll
438 // then. Perform normal opaque update (can use that, since
439 // one of the preconditions for scrollable update is
440 // opaque sprite content)
442 // repaint all affected sprites directly to output device
443 ::std::for_each( rUpdateArea.maComponentList.begin(),
444 rUpdateArea.maComponentList.end(),
445 ::boost::bind(
446 &spriteRedrawStub3,
447 ::boost::ref( rOutDev ),
448 _1 ) );
450 else
452 // scroll rOutDev content
453 rOutDev.CopyArea( ::vcl::unotools::pointFromB2IPoint( aDestPos ),
454 ::vcl::unotools::pointFromB2IPoint( aSourceRect.getMinimum() ),
455 // TODO(Q2): use numeric_cast to check range
456 ::Size( static_cast<sal_Int32>(aSourceRect.getRange().getX()),
457 static_cast<sal_Int32>(aSourceRect.getRange().getY()) ) );
459 const ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
460 aFirst( rUpdateArea.maComponentList.begin() );
461 ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
462 aSecond( aFirst ); ++aSecond;
464 ENSURE_OR_THROW( aFirst->second.getSprite().is(),
465 "VCLCanvas::scrollUpdate(): no sprite" );
467 // repaint uncovered areas from sprite. Need to actually
468 // clip here, since we're only repainting _parts_ of the
469 // sprite
470 rOutDev.Push( PUSH_CLIPREGION );
471 ::std::for_each( aUnscrollableAreas.begin(),
472 aUnscrollableAreas.end(),
473 ::boost::bind( &opaqueUpdateSpriteArea,
474 ::boost::cref(aFirst->second.getSprite()),
475 ::boost::ref(rOutDev),
476 _1 ) );
477 rOutDev.Pop();
480 // repaint uncovered areas from backbuffer - take the
481 // _rounded_ rectangles from above, to have the update
482 // consistent with the scroll above.
483 ::std::vector< ::basegfx::B2DRange > aUncoveredAreas;
484 ::basegfx::computeSetDifference( aUncoveredAreas,
485 rUpdateArea.maTotalBounds,
486 ::basegfx::B2DRange( rDestRect ) );
487 ::std::for_each( aUncoveredAreas.begin(),
488 aUncoveredAreas.end(),
489 ::boost::bind( &repaintBackground,
490 ::boost::ref(rOutDev),
491 ::boost::ref(rBackOutDev),
492 _1 ) );
495 void SpriteCanvasHelper::opaqueUpdate( const ::basegfx::B2DRange& rTotalArea,
496 const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
498 (void)rTotalArea;
500 ENSURE_OR_THROW( mpOwningSpriteCanvas &&
501 mpOwningSpriteCanvas->getBackBuffer() &&
502 mpOwningSpriteCanvas->getFrontBuffer(),
503 "SpriteCanvasHelper::opaqueUpdate(): NULL device pointer " );
505 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
507 // no need to clip output to actual update region - there will
508 // always be ALL sprites contained in the rectangular update
509 // area containd in rTotalArea (that's the way
510 // B2DConnectedRanges work). If rTotalArea appears to be
511 // smaller than the sprite - then this sprite carries a clip,
512 // and the update will be constrained to that rect.
514 // repaint all affected sprites directly to output device
515 ::std::for_each( rSortedUpdateSprites.begin(),
516 rSortedUpdateSprites.end(),
517 ::boost::bind(
518 &spriteRedrawStub,
519 ::boost::ref( rOutDev ),
520 _1 ) );
523 void SpriteCanvasHelper::genericUpdate( const ::basegfx::B2DRange& rRequestedArea,
524 const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
526 ENSURE_OR_THROW( mpOwningSpriteCanvas &&
527 mpOwningSpriteCanvas->getBackBuffer() &&
528 mpOwningSpriteCanvas->getFrontBuffer(),
529 "SpriteCanvasHelper::genericUpdate(): NULL device pointer " );
531 OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
532 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
533 OutputDevice& rBackOutDev( pBackBuffer->getOutDev() );
535 // limit size of update VDev to target outdev's size
536 const Size& rTargetSizePixel( rOutDev.GetOutputSizePixel() );
538 // round output position towards zero. Don't want to truncate
539 // a fraction of a sprite pixel... Clip position at origin,
540 // otherwise, truncation of size below might leave visible
541 // areas uncovered by VDev.
542 const ::Point aOutputPosition(
543 ::std::max( sal_Int32( 0 ),
544 static_cast< sal_Int32 >(rRequestedArea.getMinX()) ),
545 ::std::max( sal_Int32( 0 ),
546 static_cast< sal_Int32 >(rRequestedArea.getMinY()) ) );
547 // round output size towards +infty. Don't want to truncate a
548 // fraction of a sprite pixel... Limit coverage of VDev to
549 // output device's area (i.e. not only to total size, but to
550 // cover _only_ the visible parts).
551 const ::Size aOutputSize(
552 ::std::max( sal_Int32( 0 ),
553 ::std::min( static_cast< sal_Int32 >(rTargetSizePixel.Width() - aOutputPosition.X()),
554 ::canvas::tools::roundUp( rRequestedArea.getMaxX() - aOutputPosition.X() ))),
555 ::std::max( sal_Int32( 0 ),
556 ::std::min( static_cast< sal_Int32 >(rTargetSizePixel.Height() - aOutputPosition.Y()),
557 ::canvas::tools::roundUp( rRequestedArea.getMaxY() - aOutputPosition.Y() ))));
559 // early exit for empty output area.
560 if( aOutputSize.Width() == 0 &&
561 aOutputSize.Height() == 0 )
563 return;
566 const Point aEmptyPoint(0,0);
567 const Size aCurrOutputSize( maVDev->GetOutputSizePixel() );
569 // adapt maVDev's size to the area that actually needs the
570 // repaint.
571 if( aCurrOutputSize.Width() < aOutputSize.Width() ||
572 aCurrOutputSize.Height() < aOutputSize.Height() )
574 // TODO(P1): Come up with a clever tactic to reduce maVDev
575 // from time to time. Reduction with threshold (say, if
576 // maVDev is more than twice too large) is not wise, as
577 // this might then toggle within the same updateScreen(),
578 // but for different disjunct sprite areas.
579 maVDev->SetOutputSizePixel( aOutputSize );
582 // paint background
583 maVDev->EnableMapMode( FALSE );
584 maVDev->SetClipRegion();
585 maVDev->DrawOutDev( aEmptyPoint, aOutputSize,
586 aOutputPosition, aOutputSize,
587 rBackOutDev );
589 // repaint all affected sprites on top of background into
590 // VDev.
591 ::std::for_each( rSortedUpdateSprites.begin(),
592 rSortedUpdateSprites.end(),
593 ::boost::bind( &spriteRedrawStub2,
594 ::boost::ref( maVDev.get() ),
595 ::boost::cref(
596 ::vcl::unotools::b2DPointFromPoint(aOutputPosition)),
597 _1 ) );
599 // flush to screen
600 rOutDev.EnableMapMode( FALSE );
601 rOutDev.DrawOutDev( aOutputPosition, aOutputSize,
602 aEmptyPoint, aOutputSize,
603 *maVDev );
606 void SpriteCanvasHelper::renderFrameCounter( OutputDevice& rOutDev )
608 const double denominator( maLastUpdate.getElapsedTime() );
609 maLastUpdate.reset();
611 ::rtl::OUString text( ::rtl::math::doubleToUString( denominator == 0.0 ? 100.0 : 1.0/denominator,
612 rtl_math_StringFormat_F,
613 2,'.',NULL,' ') );
615 // pad with leading space
616 while( text.getLength() < 6 )
617 text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM (" ")) + text;
619 text += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM (" fps"));
621 renderInfoText( rOutDev,
622 text,
623 Point(0, 0) );
626 namespace
628 template< typename T > struct Adder
630 typedef void result_type;
632 Adder( T& rAdderTarget,
633 T nIncrement ) :
634 mpTarget( &rAdderTarget ),
635 mnIncrement( nIncrement )
639 void operator()() { *mpTarget += mnIncrement; }
640 void operator()( const ::canvas::Sprite::Reference& ) { *mpTarget += mnIncrement; }
641 void operator()( T nIncrement ) { *mpTarget += nIncrement; }
643 T* mpTarget;
644 T mnIncrement;
647 template< typename T> Adder<T> makeAdder( T& rAdderTarget,
648 T nIncrement )
650 return Adder<T>(rAdderTarget, nIncrement);
654 void SpriteCanvasHelper::renderSpriteCount( OutputDevice& rOutDev )
656 if( mpRedrawManager )
658 sal_Int32 nCount(0);
660 mpRedrawManager->forEachSprite( makeAdder(nCount,sal_Int32(1)) );
661 ::rtl::OUString text(
662 ::rtl::OUString::valueOf(
663 // disambiguate overload...
664 static_cast<sal_Int64>(nCount) ) );
666 // pad with leading space
667 while( text.getLength() < 3 )
668 text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM (" ")) + text;
670 text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("Sprites: ")) + text;
672 renderInfoText( rOutDev,
673 text,
674 Point(0, 30) );
678 void SpriteCanvasHelper::renderMemUsage( OutputDevice& rOutDev )
680 BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
682 if( mpRedrawManager &&
683 pBackBuffer )
685 double nPixel(0.0);
687 // accumulate pixel count for each sprite into fCount
688 mpRedrawManager->forEachSprite( ::boost::bind(
689 makeAdder(nPixel,1.0),
690 ::boost::bind(
691 &calcNumPixel,
692 _1 ) ) );
694 static const int NUM_VIRDEV(2);
695 static const int BYTES_PER_PIXEL(3);
697 const Size& rVDevSize( maVDev->GetOutputSizePixel() );
698 const Size& rBackBufferSize( pBackBuffer->getOutDev().GetOutputSizePixel() );
700 const double nMemUsage( nPixel * NUM_VIRDEV * BYTES_PER_PIXEL +
701 rVDevSize.Width()*rVDevSize.Height() * BYTES_PER_PIXEL +
702 rBackBufferSize.Width()*rBackBufferSize.Height() * BYTES_PER_PIXEL );
704 ::rtl::OUString text( ::rtl::math::doubleToUString( nMemUsage / 1048576.0,
705 rtl_math_StringFormat_F,
706 2,'.',NULL,' ') );
708 // pad with leading space
709 while( text.getLength() < 4 )
710 text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM (" ")) + text;
712 text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("Mem: ")) +
713 text +
714 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("MB"));
716 renderInfoText( rOutDev,
717 text,
718 Point(0, 60) );