xref: /AOO41X/main/canvas/source/vcl/spritecanvashelper.cxx (revision 25ea7f451e822ec0589487f23a9b6cc31f03fcc3)
1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir #include <tools/diagnose_ex.h>
29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
30cdf0e10cSrcweir #include <canvas/canvastools.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <vcl/canvastools.hxx>
33cdf0e10cSrcweir #include <vcl/outdev.hxx>
34cdf0e10cSrcweir #include <vcl/window.hxx>
35cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx>
38cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <boost/cast.hpp>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include "spritecanvashelper.hxx"
43cdf0e10cSrcweir #include "canvascustomsprite.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using namespace ::com::sun::star;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #define FPS_BOUNDS Rectangle(0,0,130,90)
49cdf0e10cSrcweir #define INFO_COLOR COL_RED
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace vclcanvas
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     namespace
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir         /** Sprite redraw at original position
56cdf0e10cSrcweir 
57cdf0e10cSrcweir             Used to repaint the whole canvas (background and all
58cdf0e10cSrcweir             sprites)
59cdf0e10cSrcweir          */
60cdf0e10cSrcweir         void spriteRedraw( OutputDevice&                      rOutDev,
61cdf0e10cSrcweir                            const ::canvas::Sprite::Reference& rSprite )
62cdf0e10cSrcweir         {
63cdf0e10cSrcweir             // downcast to derived vclcanvas::Sprite interface, which
64cdf0e10cSrcweir             // provides the actual redraw methods.
65cdf0e10cSrcweir             ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->redraw(rOutDev,
66cdf0e10cSrcweir                                                                             true);
67cdf0e10cSrcweir         }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         double calcNumPixel( const ::canvas::Sprite::Reference&	rSprite )
70cdf0e10cSrcweir         {
71cdf0e10cSrcweir             const ::basegfx::B2DSize& rSize(
72cdf0e10cSrcweir                 ::boost::polymorphic_downcast< Sprite* >(rSprite.get())->getSizePixel() );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             return rSize.getX() * rSize.getY();
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         void repaintBackground( OutputDevice& 				rOutDev,
78cdf0e10cSrcweir                                 OutputDevice& 				rBackBuffer,
79cdf0e10cSrcweir                                 const ::basegfx::B2DRange&	rArea )
80cdf0e10cSrcweir         {
81cdf0e10cSrcweir             const ::Point& rPos( ::vcl::unotools::pointFromB2DPoint( rArea.getMinimum()) );
82cdf0e10cSrcweir             const ::Size& rSize( ::vcl::unotools::sizeFromB2DSize( rArea.getRange()) );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir             rOutDev.DrawOutDev( rPos, rSize, rPos, rSize, rBackBuffer );
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         void opaqueUpdateSpriteArea( const ::canvas::Sprite::Reference& rSprite,
88cdf0e10cSrcweir                                      OutputDevice&                      rOutDev,
89cdf0e10cSrcweir                                      const ::basegfx::B2IRange&         rArea )
90cdf0e10cSrcweir         {
91cdf0e10cSrcweir             const Rectangle& rRequestedArea(
92cdf0e10cSrcweir                 ::vcl::unotools::rectangleFromB2IRectangle( rArea ) );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir             // clip output to actual update region (otherwise a)
95cdf0e10cSrcweir             // wouldn't save much render time, and b) will clutter
96cdf0e10cSrcweir             // scrolled sprite content outside this area)
97cdf0e10cSrcweir             rOutDev.EnableMapMode( sal_False );
98cdf0e10cSrcweir             rOutDev.SetClipRegion( rRequestedArea );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             // repaint affected sprite directly to output device (at
101cdf0e10cSrcweir             // the actual screen output position)
102cdf0e10cSrcweir             ::boost::polymorphic_downcast< Sprite* >(
103cdf0e10cSrcweir                 rSprite.get() )->redraw( rOutDev,
104cdf0e10cSrcweir                                          false ); // rendering
105cdf0e10cSrcweir                                                   // directly to
106cdf0e10cSrcweir                                                   // frontbuffer
107cdf0e10cSrcweir         }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         /** Repaint sprite at original position
110cdf0e10cSrcweir 
111cdf0e10cSrcweir             Used for opaque updates, which render directly to the
112cdf0e10cSrcweir             front buffer.
113cdf0e10cSrcweir          */
114cdf0e10cSrcweir         void spriteRedrawStub( OutputDevice&                      rOutDev,
115cdf0e10cSrcweir                                const ::canvas::Sprite::Reference& rSprite )
116cdf0e10cSrcweir         {
117cdf0e10cSrcweir             if( rSprite.is() )
118cdf0e10cSrcweir             {
119cdf0e10cSrcweir                 ::boost::polymorphic_downcast< Sprite* >(
120cdf0e10cSrcweir                     rSprite.get() )->redraw( rOutDev,
121cdf0e10cSrcweir                                              false );
122cdf0e10cSrcweir             }
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         /** Repaint sprite at given position
126cdf0e10cSrcweir 
127cdf0e10cSrcweir             Used for generic update, which renders into vdev of
128cdf0e10cSrcweir             adapted size.
129cdf0e10cSrcweir          */
130cdf0e10cSrcweir         void spriteRedrawStub2( OutputDevice&                       rOutDev,
131cdf0e10cSrcweir                                 const ::basegfx::B2DPoint& 			rOutPos,
132cdf0e10cSrcweir                                 const ::canvas::Sprite::Reference&	rSprite )
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             if( rSprite.is() )
135cdf0e10cSrcweir             {
136cdf0e10cSrcweir                 Sprite* pSprite = ::boost::polymorphic_downcast< Sprite* >(
137cdf0e10cSrcweir                     rSprite.get() );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 				// calc relative sprite position in rUpdateArea (which
140cdf0e10cSrcweir 				// need not be the whole screen!)
141cdf0e10cSrcweir                 const ::basegfx::B2DPoint& rSpriteScreenPos( pSprite->getPosPixel() );
142cdf0e10cSrcweir                 const ::basegfx::B2DPoint& rSpriteRenderPos( rSpriteScreenPos - rOutPos );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir                 pSprite->redraw( rOutDev, rSpriteRenderPos, true );
145cdf0e10cSrcweir             }
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         /** Repaint sprite at original position
149cdf0e10cSrcweir 
150cdf0e10cSrcweir             Used for opaque updates from scrollUpdate(), which render
151cdf0e10cSrcweir             directly to the front buffer.
152cdf0e10cSrcweir          */
153cdf0e10cSrcweir         void spriteRedrawStub3( OutputDevice&                                       rOutDev,
154cdf0e10cSrcweir                                 const ::canvas::SpriteRedrawManager::AreaComponent& rComponent )
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir             const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             if( rSprite.is() )
159cdf0e10cSrcweir             {
160cdf0e10cSrcweir                 ::boost::polymorphic_downcast< Sprite* >(
161cdf0e10cSrcweir                     rSprite.get() )->redraw( rOutDev,
162cdf0e10cSrcweir                                              false );
163cdf0e10cSrcweir             }
164cdf0e10cSrcweir         }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         void renderInfoText( OutputDevice& 			rOutDev,
167cdf0e10cSrcweir                              const ::rtl::OUString& rStr,
168cdf0e10cSrcweir                              const Point&		    rPos )
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir             Font aVCLFont;
171cdf0e10cSrcweir             aVCLFont.SetHeight( 20 );
172cdf0e10cSrcweir             aVCLFont.SetColor( Color( INFO_COLOR ) );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir             rOutDev.SetTextAlign(ALIGN_TOP);
175cdf0e10cSrcweir             rOutDev.SetTextColor( Color( INFO_COLOR ) );
176cdf0e10cSrcweir             rOutDev.SetFont( aVCLFont );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir             rOutDev.DrawText( rPos, rStr );
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     SpriteCanvasHelper::SpriteCanvasHelper() :
184cdf0e10cSrcweir         mpRedrawManager( NULL ),
185cdf0e10cSrcweir         mpOwningSpriteCanvas( NULL ),
186cdf0e10cSrcweir         maVDev(),
187cdf0e10cSrcweir         maLastUpdate(),
188cdf0e10cSrcweir         mbShowFrameInfo( false ),
189cdf0e10cSrcweir         mbShowSpriteBounds( false ),
190cdf0e10cSrcweir         mbIsUnsafeScrolling( false )
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir #if defined(VERBOSE) && OSL_DEBUG_LEVEL > 0
193cdf0e10cSrcweir         // inverse defaults for verbose debug mode
194cdf0e10cSrcweir         mbShowSpriteBounds = mbShowFrameInfo = true;
195cdf0e10cSrcweir #endif
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     void SpriteCanvasHelper::init( const OutDevProviderSharedPtr& rOutDev,
199cdf0e10cSrcweir                                    SpriteCanvas&                  rOwningSpriteCanvas,
200cdf0e10cSrcweir                                    ::canvas::SpriteRedrawManager& rManager,
201cdf0e10cSrcweir                                    bool                           bProtect,
202cdf0e10cSrcweir                                    bool                           bHaveAlpha )
203cdf0e10cSrcweir     {
204cdf0e10cSrcweir         mpOwningSpriteCanvas = &rOwningSpriteCanvas;
205cdf0e10cSrcweir         mpRedrawManager = &rManager;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         CanvasHelper::init(rOwningSpriteCanvas,rOutDev,bProtect,bHaveAlpha);
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir     void SpriteCanvasHelper::disposing()
211cdf0e10cSrcweir     {
212cdf0e10cSrcweir         mpRedrawManager = NULL;
213cdf0e10cSrcweir         mpOwningSpriteCanvas = NULL;
214cdf0e10cSrcweir 
215cdf0e10cSrcweir         // forward to base
216cdf0e10cSrcweir         CanvasHelper::disposing();
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromAnimation(
220cdf0e10cSrcweir         const uno::Reference< rendering::XAnimation >&  )
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir         return uno::Reference< rendering::XAnimatedSprite >();
223cdf0e10cSrcweir     }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     uno::Reference< rendering::XAnimatedSprite > SpriteCanvasHelper::createSpriteFromBitmaps(
226cdf0e10cSrcweir         const uno::Sequence< uno::Reference< rendering::XBitmap > >& ,
227cdf0e10cSrcweir         sal_Int8                                                      )
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir         return uno::Reference< rendering::XAnimatedSprite >();
230cdf0e10cSrcweir     }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     uno::Reference< rendering::XCustomSprite > SpriteCanvasHelper::createCustomSprite( const geometry::RealSize2D& spriteSize )
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         if( !mpRedrawManager || !mpDevice )
235cdf0e10cSrcweir             return uno::Reference< rendering::XCustomSprite >(); // we're disposed
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         return uno::Reference< rendering::XCustomSprite >(
238cdf0e10cSrcweir             new CanvasCustomSprite( spriteSize,
239cdf0e10cSrcweir                                     *mpDevice,
240cdf0e10cSrcweir                                     mpOwningSpriteCanvas,
241cdf0e10cSrcweir                                     mpOwningSpriteCanvas->getFrontBuffer(),
242cdf0e10cSrcweir                                     mbShowSpriteBounds ) );
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     uno::Reference< rendering::XSprite > SpriteCanvasHelper::createClonedSprite( const uno::Reference< rendering::XSprite >&  )
246cdf0e10cSrcweir     {
247cdf0e10cSrcweir         return uno::Reference< rendering::XSprite >();
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     sal_Bool SpriteCanvasHelper::updateScreen( sal_Bool bUpdateAll,
251cdf0e10cSrcweir                                                bool&	io_bSurfaceDirty )
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         if( !mpRedrawManager ||
254cdf0e10cSrcweir             !mpOwningSpriteCanvas ||
255cdf0e10cSrcweir             !mpOwningSpriteCanvas->getFrontBuffer() ||
256cdf0e10cSrcweir             !mpOwningSpriteCanvas->getBackBuffer() )
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             return sal_False; // disposed, or otherwise dysfunctional
259cdf0e10cSrcweir         }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         // commit to backbuffer
262cdf0e10cSrcweir         flush();
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         OutputDevice& 		rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
265cdf0e10cSrcweir         BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
266cdf0e10cSrcweir         OutputDevice& 		rBackOutDev( pBackBuffer->getOutDev() );
267cdf0e10cSrcweir 
268cdf0e10cSrcweir         // actual OutputDevice is a shared resource - restore its
269cdf0e10cSrcweir         // state when done.
270cdf0e10cSrcweir         tools::OutDevStateKeeper aStateKeeper( rOutDev );
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         const Size 	aOutDevSize( rBackOutDev.GetOutputSizePixel() );
273cdf0e10cSrcweir         const Point aEmptyPoint(0,0);
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         Window* pTargetWindow = NULL;
276cdf0e10cSrcweir         if( rOutDev.GetOutDevType() == OUTDEV_WINDOW )
277cdf0e10cSrcweir         {
278cdf0e10cSrcweir             pTargetWindow = &static_cast<Window&>(rOutDev); // TODO(Q3): Evil downcast.
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             // we're double-buffered, thus no need for paint area-limiting
281cdf0e10cSrcweir             // clips. besides that, will interfere with animations (as for
282cdf0e10cSrcweir             // Window-invalidate repaints, only parts of the window will
283cdf0e10cSrcweir             // be redrawn otherwise)
284cdf0e10cSrcweir             const Region aFullWindowRegion( Rectangle(aEmptyPoint,
285cdf0e10cSrcweir                                                       aOutDevSize) );
286cdf0e10cSrcweir             pTargetWindow->ExpandPaintClipRegion(aFullWindowRegion);
287cdf0e10cSrcweir         }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir         // TODO(P1): Might be worthwile to track areas of background
290cdf0e10cSrcweir         // changes, too.
291cdf0e10cSrcweir         if( !bUpdateAll && !io_bSurfaceDirty )
292cdf0e10cSrcweir         {
293cdf0e10cSrcweir             if( mbShowFrameInfo )
294cdf0e10cSrcweir             {
295cdf0e10cSrcweir                 // also repaint background below frame counter (fake
296cdf0e10cSrcweir                 // that as a sprite vanishing in this area)
297cdf0e10cSrcweir                 mpRedrawManager->updateSprite( ::canvas::Sprite::Reference(),
298cdf0e10cSrcweir                                                ::basegfx::B2DPoint(),
299cdf0e10cSrcweir                                                ::basegfx::B2DRectangle( 0.0, 0.0,
300cdf0e10cSrcweir                                                                         FPS_BOUNDS.Right(),
301cdf0e10cSrcweir                                                                         FPS_BOUNDS.Bottom() ) );
302cdf0e10cSrcweir             }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir             // background has not changed, so we're free to optimize
305cdf0e10cSrcweir             // repaint to areas where a sprite has changed
306cdf0e10cSrcweir 
307cdf0e10cSrcweir             // process each independent area of overlapping sprites
308cdf0e10cSrcweir             // separately.
309cdf0e10cSrcweir             mpRedrawManager->forEachSpriteArea( *this );
310cdf0e10cSrcweir         }
311cdf0e10cSrcweir         else
312cdf0e10cSrcweir         {
313cdf0e10cSrcweir             // background has changed, so we currently have no choice
314cdf0e10cSrcweir             // but repaint everything (or caller requested that)
315cdf0e10cSrcweir 
316cdf0e10cSrcweir             maVDev->SetOutputSizePixel( aOutDevSize );
317cdf0e10cSrcweir             maVDev->EnableMapMode( sal_False );
318cdf0e10cSrcweir             maVDev->DrawOutDev( aEmptyPoint, aOutDevSize,
319cdf0e10cSrcweir                                 aEmptyPoint, aOutDevSize,
320cdf0e10cSrcweir                                 rBackOutDev );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir             // repaint all active sprites on top of background into
323cdf0e10cSrcweir             // VDev.
324cdf0e10cSrcweir             mpRedrawManager->forEachSprite(
325cdf0e10cSrcweir                 ::boost::bind(
326cdf0e10cSrcweir                     &spriteRedraw,
327cdf0e10cSrcweir                     ::boost::ref( maVDev.get() ),
328cdf0e10cSrcweir                     _1 ) );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir             // flush to screen
331cdf0e10cSrcweir             rOutDev.EnableMapMode( sal_False );
332cdf0e10cSrcweir             rOutDev.SetClipRegion();
333cdf0e10cSrcweir             rOutDev.DrawOutDev( aEmptyPoint, aOutDevSize,
334cdf0e10cSrcweir                                 aEmptyPoint, aOutDevSize,
335cdf0e10cSrcweir                                 *maVDev );
336cdf0e10cSrcweir         }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir         // change record vector must be cleared, for the next turn of
339cdf0e10cSrcweir         // rendering and sprite changing
340cdf0e10cSrcweir         mpRedrawManager->clearChangeRecords();
341cdf0e10cSrcweir 
342cdf0e10cSrcweir         io_bSurfaceDirty = false;
343cdf0e10cSrcweir 
344cdf0e10cSrcweir         if( mbShowFrameInfo )
345cdf0e10cSrcweir         {
346cdf0e10cSrcweir             renderFrameCounter( rOutDev );
347cdf0e10cSrcweir             renderSpriteCount( rOutDev );
348cdf0e10cSrcweir             renderMemUsage( rOutDev );
349cdf0e10cSrcweir         }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir #if defined(VERBOSE) && OSL_DEBUG_LEVEL > 0
352cdf0e10cSrcweir         static ::canvas::tools::ElapsedTime aElapsedTime;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         // log time immediately after surface flip
355cdf0e10cSrcweir         OSL_TRACE( "SpriteCanvasHelper::updateScreen(): flip done at %f",
356cdf0e10cSrcweir                    aElapsedTime.getElapsedTime() );
357cdf0e10cSrcweir #endif
358cdf0e10cSrcweir 
359cdf0e10cSrcweir         // sync output with screen, to ensure that we don't queue up
360cdf0e10cSrcweir         // render requests (calling code might rely on timing,
361cdf0e10cSrcweir         // i.e. assume that things are visible on screen after
362cdf0e10cSrcweir         // updateScreen() returns).
363cdf0e10cSrcweir         if( pTargetWindow )
364cdf0e10cSrcweir         {
365cdf0e10cSrcweir             // commit to screen
366cdf0e10cSrcweir             pTargetWindow->Sync();
367cdf0e10cSrcweir         }
368cdf0e10cSrcweir 
369cdf0e10cSrcweir         return sal_True;
370cdf0e10cSrcweir     }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir     void SpriteCanvasHelper::backgroundPaint( const ::basegfx::B2DRange& rUpdateRect )
373cdf0e10cSrcweir     {
374cdf0e10cSrcweir         ENSURE_OR_THROW( mpOwningSpriteCanvas &&
375cdf0e10cSrcweir                          mpOwningSpriteCanvas->getBackBuffer() &&
376cdf0e10cSrcweir                          mpOwningSpriteCanvas->getFrontBuffer(),
377cdf0e10cSrcweir                          "SpriteCanvasHelper::backgroundPaint(): NULL device pointer " );
378cdf0e10cSrcweir 
379cdf0e10cSrcweir         OutputDevice& 		rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
380cdf0e10cSrcweir         BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
381cdf0e10cSrcweir         OutputDevice& 		rBackOutDev( pBackBuffer->getOutDev() );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir         repaintBackground( rOutDev, rBackOutDev, rUpdateRect );
384cdf0e10cSrcweir     }
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     void SpriteCanvasHelper::scrollUpdate( const ::basegfx::B2DRange& 						rMoveStart,
387cdf0e10cSrcweir                                            const ::basegfx::B2DRange& 						rMoveEnd,
388cdf0e10cSrcweir                                            const ::canvas::SpriteRedrawManager::UpdateArea& rUpdateArea )
389cdf0e10cSrcweir     {
390cdf0e10cSrcweir         ENSURE_OR_THROW( mpOwningSpriteCanvas &&
391cdf0e10cSrcweir                          mpOwningSpriteCanvas->getBackBuffer() &&
392cdf0e10cSrcweir                          mpOwningSpriteCanvas->getFrontBuffer(),
393cdf0e10cSrcweir                          "SpriteCanvasHelper::scrollUpdate(): NULL device pointer " );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir         OutputDevice& 		rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
396cdf0e10cSrcweir         BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
397cdf0e10cSrcweir         OutputDevice& 		rBackOutDev( pBackBuffer->getOutDev() );
398cdf0e10cSrcweir 
399cdf0e10cSrcweir         const Size&                rTargetSizePixel( rOutDev.GetOutputSizePixel() );
400cdf0e10cSrcweir         const ::basegfx::B2IRange  aOutputBounds( 0,0,
401cdf0e10cSrcweir                                                   rTargetSizePixel.Width(),
402cdf0e10cSrcweir                                                   rTargetSizePixel.Height() );
403cdf0e10cSrcweir 
404cdf0e10cSrcweir         // round rectangles to integer pixel. Note: have to be
405cdf0e10cSrcweir         // extremely careful here, to avoid off-by-one errors for
406cdf0e10cSrcweir         // the destination area: otherwise, the next scroll update
407cdf0e10cSrcweir         // would copy pixel that are not supposed to be part of
408cdf0e10cSrcweir         // the sprite.
409cdf0e10cSrcweir         ::basegfx::B2IRange aSourceRect(
410cdf0e10cSrcweir             ::canvas::tools::spritePixelAreaFromB2DRange( rMoveStart ) );
411cdf0e10cSrcweir         const ::basegfx::B2IRange& rDestRect(
412cdf0e10cSrcweir             ::canvas::tools::spritePixelAreaFromB2DRange( rMoveEnd ) );
413cdf0e10cSrcweir         ::basegfx::B2IPoint aDestPos( rDestRect.getMinimum() );
414cdf0e10cSrcweir 
415cdf0e10cSrcweir         ::std::vector< ::basegfx::B2IRange > aUnscrollableAreas;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir         // Since strictly speaking, this scroll algorithm is plain
418cdf0e10cSrcweir         // buggy, the scrolled area might actually lie _below_ another
419cdf0e10cSrcweir         // window - we've made this feature configurable via
420cdf0e10cSrcweir         // mbIsUnsafeScrolling.
421cdf0e10cSrcweir 
422cdf0e10cSrcweir         // clip to output bounds (cannot properly scroll stuff
423cdf0e10cSrcweir         // _outside_ our screen area)
424cdf0e10cSrcweir         if( !mbIsUnsafeScrolling ||
425cdf0e10cSrcweir             !::canvas::tools::clipScrollArea( aSourceRect,
426cdf0e10cSrcweir                                               aDestPos,
427cdf0e10cSrcweir                                               aUnscrollableAreas,
428cdf0e10cSrcweir                                               aOutputBounds ) )
429cdf0e10cSrcweir         {
430cdf0e10cSrcweir             // fully clipped scroll area: cannot simply scroll
431cdf0e10cSrcweir             // then. Perform normal opaque update (can use that, since
432cdf0e10cSrcweir             // one of the preconditions for scrollable update is
433cdf0e10cSrcweir             // opaque sprite content)
434cdf0e10cSrcweir 
435cdf0e10cSrcweir             // repaint all affected sprites directly to output device
436cdf0e10cSrcweir             ::std::for_each( rUpdateArea.maComponentList.begin(),
437cdf0e10cSrcweir                              rUpdateArea.maComponentList.end(),
438cdf0e10cSrcweir                              ::boost::bind(
439cdf0e10cSrcweir                                  &spriteRedrawStub3,
440cdf0e10cSrcweir                                  ::boost::ref( rOutDev ),
441cdf0e10cSrcweir                                  _1 ) );
442cdf0e10cSrcweir         }
443cdf0e10cSrcweir         else
444cdf0e10cSrcweir         {
445cdf0e10cSrcweir             // scroll rOutDev content
446cdf0e10cSrcweir             rOutDev.CopyArea( ::vcl::unotools::pointFromB2IPoint( aDestPos ),
447cdf0e10cSrcweir                               ::vcl::unotools::pointFromB2IPoint( aSourceRect.getMinimum() ),
448cdf0e10cSrcweir                               // TODO(Q2): use numeric_cast to check range
449cdf0e10cSrcweir                               ::Size( static_cast<sal_Int32>(aSourceRect.getRange().getX()),
450cdf0e10cSrcweir                                       static_cast<sal_Int32>(aSourceRect.getRange().getY()) ) );
451cdf0e10cSrcweir 
452cdf0e10cSrcweir             const ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
453cdf0e10cSrcweir                 aFirst( rUpdateArea.maComponentList.begin() );
454cdf0e10cSrcweir             ::canvas::SpriteRedrawManager::SpriteConnectedRanges::ComponentListType::const_iterator
455cdf0e10cSrcweir                   aSecond( aFirst ); ++aSecond;
456cdf0e10cSrcweir 
457cdf0e10cSrcweir             ENSURE_OR_THROW( aFirst->second.getSprite().is(),
458cdf0e10cSrcweir                               "VCLCanvas::scrollUpdate(): no sprite" );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir             // repaint uncovered areas from sprite. Need to actually
461cdf0e10cSrcweir             // clip here, since we're only repainting _parts_ of the
462cdf0e10cSrcweir             // sprite
463cdf0e10cSrcweir             rOutDev.Push( PUSH_CLIPREGION );
464cdf0e10cSrcweir             ::std::for_each( aUnscrollableAreas.begin(),
465cdf0e10cSrcweir                              aUnscrollableAreas.end(),
466cdf0e10cSrcweir                              ::boost::bind( &opaqueUpdateSpriteArea,
467cdf0e10cSrcweir                                             ::boost::cref(aFirst->second.getSprite()),
468cdf0e10cSrcweir                                             ::boost::ref(rOutDev),
469cdf0e10cSrcweir                                             _1 ) );
470cdf0e10cSrcweir             rOutDev.Pop();
471cdf0e10cSrcweir         }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir         // repaint uncovered areas from backbuffer - take the
474cdf0e10cSrcweir         // _rounded_ rectangles from above, to have the update
475cdf0e10cSrcweir         // consistent with the scroll above.
476cdf0e10cSrcweir         ::std::vector< ::basegfx::B2DRange > aUncoveredAreas;
477cdf0e10cSrcweir         ::basegfx::computeSetDifference( aUncoveredAreas,
478cdf0e10cSrcweir                                          rUpdateArea.maTotalBounds,
479cdf0e10cSrcweir                                          ::basegfx::B2DRange( rDestRect ) );
480cdf0e10cSrcweir         ::std::for_each( aUncoveredAreas.begin(),
481cdf0e10cSrcweir                          aUncoveredAreas.end(),
482cdf0e10cSrcweir                          ::boost::bind( &repaintBackground,
483cdf0e10cSrcweir                                         ::boost::ref(rOutDev),
484cdf0e10cSrcweir                                         ::boost::ref(rBackOutDev),
485cdf0e10cSrcweir                                         _1 ) );
486cdf0e10cSrcweir     }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir     void SpriteCanvasHelper::opaqueUpdate( const ::basegfx::B2DRange&                          rTotalArea,
489cdf0e10cSrcweir                                            const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         (void)rTotalArea;
492cdf0e10cSrcweir 
493cdf0e10cSrcweir         ENSURE_OR_THROW( mpOwningSpriteCanvas &&
494cdf0e10cSrcweir                          mpOwningSpriteCanvas->getBackBuffer() &&
495cdf0e10cSrcweir                          mpOwningSpriteCanvas->getFrontBuffer(),
496cdf0e10cSrcweir                          "SpriteCanvasHelper::opaqueUpdate(): NULL device pointer " );
497cdf0e10cSrcweir 
498cdf0e10cSrcweir         OutputDevice& rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
499cdf0e10cSrcweir 
500cdf0e10cSrcweir         // no need to clip output to actual update region - there will
501cdf0e10cSrcweir         // always be ALL sprites contained in the rectangular update
502cdf0e10cSrcweir         // area containd in rTotalArea (that's the way
503cdf0e10cSrcweir         // B2DConnectedRanges work). If rTotalArea appears to be
504cdf0e10cSrcweir         // smaller than the sprite - then this sprite carries a clip,
505cdf0e10cSrcweir         // and the update will be constrained to that rect.
506cdf0e10cSrcweir 
507cdf0e10cSrcweir         // repaint all affected sprites directly to output device
508cdf0e10cSrcweir         ::std::for_each( rSortedUpdateSprites.begin(),
509cdf0e10cSrcweir                          rSortedUpdateSprites.end(),
510cdf0e10cSrcweir                          ::boost::bind(
511cdf0e10cSrcweir                              &spriteRedrawStub,
512cdf0e10cSrcweir                              ::boost::ref( rOutDev ),
513cdf0e10cSrcweir                              _1 ) );
514cdf0e10cSrcweir     }
515cdf0e10cSrcweir 
516cdf0e10cSrcweir     void SpriteCanvasHelper::genericUpdate( const ::basegfx::B2DRange&                          rRequestedArea,
517cdf0e10cSrcweir                                             const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites )
518cdf0e10cSrcweir     {
519cdf0e10cSrcweir         ENSURE_OR_THROW( mpOwningSpriteCanvas &&
520cdf0e10cSrcweir                          mpOwningSpriteCanvas->getBackBuffer() &&
521cdf0e10cSrcweir                          mpOwningSpriteCanvas->getFrontBuffer(),
522cdf0e10cSrcweir                          "SpriteCanvasHelper::genericUpdate(): NULL device pointer " );
523cdf0e10cSrcweir 
524cdf0e10cSrcweir         OutputDevice& 		rOutDev( mpOwningSpriteCanvas->getFrontBuffer()->getOutDev() );
525cdf0e10cSrcweir         BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
526cdf0e10cSrcweir         OutputDevice& 		rBackOutDev( pBackBuffer->getOutDev() );
527cdf0e10cSrcweir 
528cdf0e10cSrcweir         // limit size of update VDev to target outdev's size
529cdf0e10cSrcweir         const Size& rTargetSizePixel( rOutDev.GetOutputSizePixel() );
530cdf0e10cSrcweir 
531cdf0e10cSrcweir         // round output position towards zero. Don't want to truncate
532cdf0e10cSrcweir         // a fraction of a sprite pixel...  Clip position at origin,
533cdf0e10cSrcweir         // otherwise, truncation of size below might leave visible
534cdf0e10cSrcweir         // areas uncovered by VDev.
535cdf0e10cSrcweir         const ::Point aOutputPosition(
536cdf0e10cSrcweir             ::std::max( sal_Int32( 0 ),
537cdf0e10cSrcweir                         static_cast< sal_Int32 >(rRequestedArea.getMinX()) ),
538cdf0e10cSrcweir             ::std::max( sal_Int32( 0 ),
539cdf0e10cSrcweir                         static_cast< sal_Int32 >(rRequestedArea.getMinY()) ) );
540cdf0e10cSrcweir         // round output size towards +infty. Don't want to truncate a
541cdf0e10cSrcweir         // fraction of a sprite pixel... Limit coverage of VDev to
542cdf0e10cSrcweir         // output device's area (i.e. not only to total size, but to
543cdf0e10cSrcweir         // cover _only_ the visible parts).
544cdf0e10cSrcweir         const ::Size aOutputSize(
545cdf0e10cSrcweir             ::std::max( sal_Int32( 0 ),
546cdf0e10cSrcweir                         ::std::min( static_cast< sal_Int32 >(rTargetSizePixel.Width() - aOutputPosition.X()),
547cdf0e10cSrcweir                                     ::canvas::tools::roundUp( rRequestedArea.getMaxX() - aOutputPosition.X() ))),
548cdf0e10cSrcweir             ::std::max( sal_Int32( 0 ),
549cdf0e10cSrcweir                         ::std::min( static_cast< sal_Int32 >(rTargetSizePixel.Height() - aOutputPosition.Y()),
550cdf0e10cSrcweir                                     ::canvas::tools::roundUp( rRequestedArea.getMaxY() - aOutputPosition.Y() ))));
551cdf0e10cSrcweir 
552cdf0e10cSrcweir         // early exit for empty output area.
553cdf0e10cSrcweir         if( aOutputSize.Width() == 0 &&
554cdf0e10cSrcweir             aOutputSize.Height() == 0 )
555cdf0e10cSrcweir         {
556cdf0e10cSrcweir             return;
557cdf0e10cSrcweir         }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir         const Point aEmptyPoint(0,0);
560cdf0e10cSrcweir         const Size  aCurrOutputSize( maVDev->GetOutputSizePixel() );
561cdf0e10cSrcweir 
562cdf0e10cSrcweir         // adapt maVDev's size to the area that actually needs the
563cdf0e10cSrcweir         // repaint.
564cdf0e10cSrcweir         if( aCurrOutputSize.Width() < aOutputSize.Width() ||
565cdf0e10cSrcweir             aCurrOutputSize.Height() < aOutputSize.Height() )
566cdf0e10cSrcweir         {
567cdf0e10cSrcweir             // TODO(P1): Come up with a clever tactic to reduce maVDev
568cdf0e10cSrcweir             // from time to time. Reduction with threshold (say, if
569cdf0e10cSrcweir             // maVDev is more than twice too large) is not wise, as
570cdf0e10cSrcweir             // this might then toggle within the same updateScreen(),
571cdf0e10cSrcweir             // but for different disjunct sprite areas.
572cdf0e10cSrcweir             maVDev->SetOutputSizePixel( aOutputSize );
573cdf0e10cSrcweir         }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir         // paint background
576cdf0e10cSrcweir         maVDev->EnableMapMode( sal_False );
577cdf0e10cSrcweir         maVDev->SetClipRegion();
578cdf0e10cSrcweir         maVDev->DrawOutDev( aEmptyPoint, aOutputSize,
579cdf0e10cSrcweir                             aOutputPosition, aOutputSize,
580cdf0e10cSrcweir                             rBackOutDev );
581cdf0e10cSrcweir 
582cdf0e10cSrcweir         // repaint all affected sprites on top of background into
583cdf0e10cSrcweir         // VDev.
584cdf0e10cSrcweir         ::std::for_each( rSortedUpdateSprites.begin(),
585cdf0e10cSrcweir                          rSortedUpdateSprites.end(),
586cdf0e10cSrcweir                          ::boost::bind( &spriteRedrawStub2,
587cdf0e10cSrcweir                                         ::boost::ref( maVDev.get() ),
588cdf0e10cSrcweir                                         ::boost::cref(
589cdf0e10cSrcweir                                             ::vcl::unotools::b2DPointFromPoint(aOutputPosition)),
590cdf0e10cSrcweir                                         _1 ) );
591cdf0e10cSrcweir 
592cdf0e10cSrcweir         // flush to screen
593cdf0e10cSrcweir         rOutDev.EnableMapMode( sal_False );
594cdf0e10cSrcweir         rOutDev.DrawOutDev( aOutputPosition, aOutputSize,
595cdf0e10cSrcweir                             aEmptyPoint, aOutputSize,
596cdf0e10cSrcweir                             *maVDev );
597cdf0e10cSrcweir     }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir     void SpriteCanvasHelper::renderFrameCounter( OutputDevice& rOutDev )
600cdf0e10cSrcweir     {
601cdf0e10cSrcweir         const double denominator( maLastUpdate.getElapsedTime() );
602cdf0e10cSrcweir         maLastUpdate.reset();
603cdf0e10cSrcweir 
604cdf0e10cSrcweir         ::rtl::OUString text( ::rtl::math::doubleToUString( denominator == 0.0 ? 100.0 : 1.0/denominator,
605cdf0e10cSrcweir                                                             rtl_math_StringFormat_F,
606cdf0e10cSrcweir                                                             2,'.',NULL,' ') );
607cdf0e10cSrcweir 
608cdf0e10cSrcweir         // pad with leading space
609cdf0e10cSrcweir         while( text.getLength() < 6 )
610cdf0e10cSrcweir             text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM (" ")) + text;
611cdf0e10cSrcweir 
612cdf0e10cSrcweir         text += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM (" fps"));
613cdf0e10cSrcweir 
614cdf0e10cSrcweir         renderInfoText( rOutDev,
615cdf0e10cSrcweir                         text,
616cdf0e10cSrcweir                         Point(0, 0) );
617cdf0e10cSrcweir     }
618cdf0e10cSrcweir 
619cdf0e10cSrcweir     namespace
620cdf0e10cSrcweir     {
621cdf0e10cSrcweir         template< typename T > struct Adder
622cdf0e10cSrcweir         {
623cdf0e10cSrcweir             typedef void result_type;
624cdf0e10cSrcweir 
625cdf0e10cSrcweir             Adder( T& rAdderTarget,
626cdf0e10cSrcweir                    T  nIncrement ) :
627cdf0e10cSrcweir                 mpTarget( &rAdderTarget ),
628cdf0e10cSrcweir                 mnIncrement( nIncrement )
629cdf0e10cSrcweir             {
630cdf0e10cSrcweir             }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir             void operator()() { *mpTarget += mnIncrement; }
633cdf0e10cSrcweir             void operator()( const ::canvas::Sprite::Reference& ) { *mpTarget += mnIncrement; }
634cdf0e10cSrcweir             void operator()( T nIncrement ) { *mpTarget += nIncrement; }
635cdf0e10cSrcweir 
636cdf0e10cSrcweir             T* mpTarget;
637cdf0e10cSrcweir             T  mnIncrement;
638cdf0e10cSrcweir         };
639cdf0e10cSrcweir 
640cdf0e10cSrcweir         template< typename T> Adder<T> makeAdder( T& rAdderTarget,
641cdf0e10cSrcweir                                                   T  nIncrement )
642cdf0e10cSrcweir         {
643cdf0e10cSrcweir             return Adder<T>(rAdderTarget, nIncrement);
644cdf0e10cSrcweir         }
645cdf0e10cSrcweir     }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     void SpriteCanvasHelper::renderSpriteCount( OutputDevice& rOutDev )
648cdf0e10cSrcweir     {
649cdf0e10cSrcweir         if( mpRedrawManager )
650cdf0e10cSrcweir         {
651cdf0e10cSrcweir             sal_Int32 nCount(0);
652cdf0e10cSrcweir 
653cdf0e10cSrcweir             mpRedrawManager->forEachSprite( makeAdder(nCount,sal_Int32(1)) );
654cdf0e10cSrcweir             ::rtl::OUString text(
655cdf0e10cSrcweir                 ::rtl::OUString::valueOf(
656cdf0e10cSrcweir                     // disambiguate overload...
657cdf0e10cSrcweir                     static_cast<sal_Int64>(nCount) ) );
658cdf0e10cSrcweir 
659cdf0e10cSrcweir             // pad with leading space
660cdf0e10cSrcweir             while( text.getLength() < 3 )
661cdf0e10cSrcweir                 text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM (" ")) + text;
662cdf0e10cSrcweir 
663cdf0e10cSrcweir             text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("Sprites: ")) + text;
664cdf0e10cSrcweir 
665cdf0e10cSrcweir             renderInfoText( rOutDev,
666cdf0e10cSrcweir                             text,
667cdf0e10cSrcweir                             Point(0, 30) );
668cdf0e10cSrcweir         }
669cdf0e10cSrcweir     }
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     void SpriteCanvasHelper::renderMemUsage( OutputDevice& rOutDev )
672cdf0e10cSrcweir     {
673cdf0e10cSrcweir         BackBufferSharedPtr pBackBuffer( mpOwningSpriteCanvas->getBackBuffer() );
674cdf0e10cSrcweir 
675cdf0e10cSrcweir         if( mpRedrawManager &&
676cdf0e10cSrcweir             pBackBuffer )
677cdf0e10cSrcweir         {
678cdf0e10cSrcweir             double nPixel(0.0);
679cdf0e10cSrcweir 
680cdf0e10cSrcweir             // accumulate pixel count for each sprite into fCount
681cdf0e10cSrcweir             mpRedrawManager->forEachSprite( ::boost::bind(
682cdf0e10cSrcweir                                                 makeAdder(nPixel,1.0),
683cdf0e10cSrcweir                                                 ::boost::bind(
684cdf0e10cSrcweir                                                     &calcNumPixel,
685cdf0e10cSrcweir                                                     _1 ) ) );
686cdf0e10cSrcweir 
687cdf0e10cSrcweir             static const int NUM_VIRDEV(2);
688cdf0e10cSrcweir             static const int BYTES_PER_PIXEL(3);
689cdf0e10cSrcweir 
690cdf0e10cSrcweir             const Size& rVDevSize( maVDev->GetOutputSizePixel() );
691cdf0e10cSrcweir             const Size& rBackBufferSize( pBackBuffer->getOutDev().GetOutputSizePixel() );
692cdf0e10cSrcweir 
693cdf0e10cSrcweir             const double nMemUsage( nPixel * NUM_VIRDEV * BYTES_PER_PIXEL +
694cdf0e10cSrcweir                                     rVDevSize.Width()*rVDevSize.Height() * BYTES_PER_PIXEL +
695cdf0e10cSrcweir                                     rBackBufferSize.Width()*rBackBufferSize.Height() * BYTES_PER_PIXEL );
696cdf0e10cSrcweir 
697cdf0e10cSrcweir             ::rtl::OUString text( ::rtl::math::doubleToUString( nMemUsage / 1048576.0,
698cdf0e10cSrcweir                                                                 rtl_math_StringFormat_F,
699cdf0e10cSrcweir                                                                 2,'.',NULL,' ') );
700cdf0e10cSrcweir 
701cdf0e10cSrcweir             // pad with leading space
702cdf0e10cSrcweir             while( text.getLength() < 4 )
703cdf0e10cSrcweir                 text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM (" ")) + text;
704cdf0e10cSrcweir 
705cdf0e10cSrcweir             text = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("Mem: ")) +
706cdf0e10cSrcweir                 text +
707cdf0e10cSrcweir                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("MB"));
708cdf0e10cSrcweir 
709cdf0e10cSrcweir             renderInfoText( rOutDev,
710cdf0e10cSrcweir                             text,
711cdf0e10cSrcweir                             Point(0, 60) );
712cdf0e10cSrcweir         }
713cdf0e10cSrcweir     }
714cdf0e10cSrcweir }
715