Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / vcl / workben / outdevgrind.cxx
blob04889307c8ce4f8b407e49d7149104e04ff47241
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/main.h>
21 #include <tools/extendapplicationenvironment.hxx>
23 #include <cppuhelper/bootstrap.hxx>
24 #include <comphelper/processfactory.hxx>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <vcl/svapp.hxx>
29 #include <vcl/window.hxx>
30 #include <vcl/dialog.hxx>
31 #include <vcl/outdev.hxx>
32 #include <vcl/virdev.hxx>
33 #include <vcl/hatch.hxx>
34 #include <vcl/bitmap.hxx>
35 #include <vcl/BitmapEmbossGreyFilter.hxx>
36 #include <vcl/wall.hxx>
37 #include <vcl/image.hxx>
38 #include <vcl/gdimtf.hxx>
39 #include <vcl/metaact.hxx>
40 #include <vcl/bitmapex.hxx>
41 #include <vcl/gradient.hxx>
42 #include <vcl/lineinfo.hxx>
44 #include <rtl/bootstrap.hxx>
46 #include <osl/time.h>
48 #include <functional>
50 #include <stdio.h>
52 using namespace ::com::sun::star;
54 namespace
57 class GrindApp : public Application
59 public:
60 virtual int Main() override;
61 virtual void Exception( ExceptionCategory nCategory ) override;
64 class TestWindow : public Dialog
66 public:
67 TestWindow() : Dialog( nullptr )
69 SetText( "OutDev grinding" );
70 SetSizePixel( Size( 1024, 1024 ) );
71 EnablePaint( true );
72 Show();
75 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
78 typedef std::function<void (OutputDevice*)> functor_type;
79 typedef std::vector< std::pair<const char*,
80 functor_type> > functor_vector_type;
82 template< typename Functor > void add( functor_vector_type& res,
83 const char* pStr,
84 const Functor& func )
86 res.emplace_back(pStr,functor_type(func) );
89 void setupMethodStubs( functor_vector_type& res )
91 const Color aWhiteColor( COL_WHITE );
92 const Color aBlackColor( COL_BLACK );
94 const Point aPt1(10,10);
95 const Point aPt2(500,500);
96 const Point aPt3(0,0);
97 const Point aPt4(450,450);
99 const tools::Rectangle aRect(aPt1,aPt2);
100 const tools::Rectangle aRect2(aPt3,aPt4);
101 const tools::Polygon aPoly(aRect);
102 const tools::Polygon aPoly2(aRect2);
103 tools::PolyPolygon aPolyPoly(aPoly);
104 aPolyPoly.Insert( aPoly2 );
105 tools::Polygon aPoly3(aPoly2);
106 aPoly3.Rotate( aPoly3.GetBoundRect().Center(), 900 );
107 const LineInfo aLineInfo(LineStyle::Solid,5);
109 #ifdef FIXME_VDEV
110 const OUString aString("This is a test");
112 // unfortunately, VDevs have inaccessible copy constructors
113 static VirtualDevice aVDev;
114 static VirtualDevice aVDevBW(1);
116 const Size aVDevSize;
117 aVDev.SetOutputSizePixel(aVDevSize);
118 aVDevBW.SetOutputSizePixel(aVDevSize);
120 const Bitmap aBitmap( aVDev.GetBitmap(aPt1,aVDevSize) );
121 const Bitmap aBitmapBW( aVDevBW.GetBitmap(aPt1,aVDevSize) );
122 const Bitmap aBitmapAlien( aVDevSize, 8 );
123 #else
124 BitmapEx aIntro;
125 rtl::Bootstrap::set("BRAND_BASE_DIR", ".");
126 if (Application::LoadBrandBitmap ("intro", aIntro))
127 Application::Abort( "Failed to load intro image, run inside program/" );
129 const Bitmap aBitmap( aIntro.GetBitmap() );
130 Bitmap aBitmapBW( aBitmap );
132 BitmapEx aTmpBmpEx(aBitmapBW);
133 BitmapFilter::Filter(aTmpBmpEx, BitmapEmbossGreyFilter(0, 0));
134 aBitmapBW = aTmpBmpEx.GetBitmap();
136 Bitmap aBitmapAlien( Size( 100, 100 ), 8 );
137 aBitmapAlien.Erase( COL_RED );
138 #endif
140 const BitmapEx aBitmapEx( aBitmap, aBitmapBW );
141 (void)aBitmapEx;
142 const BitmapEx aBitmapExBW( aBitmapBW, aBitmapBW );
143 (void)aBitmapExBW;
144 const BitmapEx aBitmapExAlien( aBitmapAlien, aBitmapBW );
145 (void)aBitmapExAlien;
146 const BitmapEx aBitmapExAlpha( aBitmap, aBitmapAlien );
147 (void)aBitmapExAlpha;
148 const BitmapEx aBitmapExAlphaAlien( aBitmapAlien, aBitmapAlien );
149 (void)aBitmapExAlphaAlien;
151 #ifdef NEEDS_QUALITY_PARAMETER
152 const Image aImage( aBitmapEx );
153 #endif
154 const Gradient aGradient(GradientStyle::Elliptical,aBlackColor,aWhiteColor);
155 const Hatch aHatch(HatchStyle::Triple,aBlackColor,4,450);
156 const Wallpaper aWallpaper( aWhiteColor );
158 GDIMetaFile aMtf;
159 aMtf.AddAction( new MetaFillColorAction(COL_RED,true) );
160 aMtf.AddAction( new MetaRectAction(aRect) );
162 #ifdef FIXME_NEEDS_LOVE
163 add(res,
164 "DrawTextArray",
165 [&] (OutputDevice * pDev) {
166 return pDev->DrawTextArray(aPt1, aString, (const sal_Int32*)0, (sal_uInt16)0, aString.getLength());
168 #endif
170 /* void DrawPixel( const Point& rPt, const Color& rColor ); */
171 add(res,
172 "DrawPixel",
173 [aPt1, aBlackColor](OutputDevice *pOutDev) { return pOutDev->DrawPixel(aPt1, aBlackColor); });
175 /* void DrawLine( const Point& rStartPt, const Point& rEndPt ); */
176 add(res,
177 "DrawLine",
178 [aPt1, aPt2] (OutputDevice *pOutDev) { return pOutDev->DrawLine(aPt1, aPt2); });
180 /* void DrawLine( const Point& rStartPt, const Point& rEndPt,
181 const LineInfo& rLineInfo );
183 add(res,
184 "DrawLine(LineInfo)",
185 [aPt1, aPt2, aLineInfo] (OutputDevice *pOutDev) { return pOutDev->DrawLine(aPt1, aPt2, aLineInfo); });
187 /* void DrawPolyLine( const Polygon& rPoly ); */
188 add(res,
189 "DrawPolyLine",
190 [aPoly] (OutputDevice *pOutDev) {return pOutDev->DrawPolyLine(aPoly); });
192 /* void DrawPolyLine( const Polygon& rPoly,
193 const LineInfo& rLineInfo );
195 add(res,
196 "DrawPolyLine(LineInfo)",
197 [aPoly, aLineInfo] (OutputDevice *pOutDev) { return pOutDev->DrawPolyLine(aPoly, aLineInfo); });
199 /* void DrawPolygon( const Polygon& rPoly ); */
200 add(res,
201 "DrawPolygon",
202 [aPoly] (OutputDevice *pOutDev) { return pOutDev->DrawPolygon(aPoly); });
204 /* void DrawPolyPolygon( const tools::PolyPolygon& rPolyPoly ); */
205 add(res,
206 "DrawPolyPolygon",
207 [aPolyPoly] (OutputDevice *pOutDev) { return pOutDev->DrawPolyPolygon(aPolyPoly); });
209 /* void DrawRect( const Rectangle& rRect ); */
210 add(res,
211 "DrawRect",
212 [aRect] (OutputDevice *pOutDev) { return pOutDev->DrawRect(aRect); });
214 /* void DrawRect( const Rectangle& rRect,
215 sal_uLong nHorzRount, sal_uLong nVertRound );
217 add(res,
218 "DrawRect(round corners)",
219 [aRect2] (OutputDevice *pOutDev) { return pOutDev->DrawRect(aRect2,4,4); });
221 /* void DrawEllipse( const Rectangle& rRect ); */
222 add(res,
223 "DrawEllipse",
224 [aRect] (OutputDevice *pOutDev) { return pOutDev->DrawEllipse(aRect); });
226 /* void DrawArc( const Rectangle& rRect,
227 const Point& rStartPt, const Point& rEndPt );
229 add(res,
230 "DrawArc",
231 [aRect,aPt1,aPt2] (OutputDevice *pOutDev) { return pOutDev->DrawArc(aRect,aPt1,aPt2); });
233 /* void DrawPie( const Rectangle& rRect,
234 const Point& rStartPt, const Point& rEndPt );
236 add(res,
237 "DrawPie",
238 [aRect2,aPt3,aPt4] (OutputDevice *pOutDev) { return pOutDev->DrawPie(aRect2,aPt3,aPt4); });
240 /* void DrawChord( const Rectangle& rRect,
241 const Point& rStartPt, const Point& rEndPt );
243 add(res,
244 "DrawChord",
245 [aRect2,aPt3,aPt4] (OutputDevice *pOutDev) { return pOutDev->DrawChord(aRect2,aPt3,aPt4); });
247 /* void DrawOutDev( const Point& rDestPt, const Size& rDestSize,
248 const Point& rSrcPt, const Size& rSrcSize );
250 add(res,
251 "DrawOutDev",
252 [aRect,aRect2] (OutputDevice *pOutDev) { return pOutDev->DrawOutDev(aRect2.TopLeft(), aRect2.GetSize(),
253 aRect.TopLeft(), aRect.GetSize()); });
255 #ifdef FIXME_VDEV
256 /* void DrawOutDev( const Point& rDestPt, const Size& rDestSize,
257 const Point& rSrcPt, const Size& rSrcSize,
258 const OutputDevice& rOutDev );
260 add(res,
261 "DrawOutDev(foreign source)",
262 [&] (OutputDevice * pDev) {
263 return pDev->DrawOutDev(aRect2.TopLeft(), aRect2.GetSize(),
264 aRect.TopLeft(), aRect.GetSize(), aVDevBW);
267 /* void DrawOutDev( const Point& rDestPt, const Size& rDestSize,
268 const Point& rSrcPt, const Size& rSrcSize,
269 const OutputDevice& rOutDev );
271 add(res,
272 "DrawOutDev(foreign source, scaled)",
273 [&] (OutputDevice * pDev) {
274 return pDev->DrawOutDev(aRect2.TopLeft(), aRect2.GetSize(),
275 aRect.TopLeft(), aRect.GetSize(), aVDev);
277 #endif
279 /* void CopyArea( const Point& rDestPt,
280 const Point& rSrcPt, const Size& rSrcSize,
281 sal_uInt16 nFlags = 0 );
283 add(res,
284 "CopyArea",
285 [&] (OutputDevice * pDev) { return pDev->CopyArea(aPt1, aPt3, aRect2.GetSize()); } );
287 #ifdef NEEDS_QUALITY_PARAMETER
288 /* void DrawBitmap( const Point& rDestPt,
289 const Bitmap& rBitmap );
291 add(res,
292 "DrawBitmap(alien source)",
293 [&] (OutputDevice * pDev) { return pDev->DrawBitmap(aPt1, aBitmapAlien); });
295 /* void DrawBitmap( const Point& rDestPt,
296 const Bitmap& rBitmap );
298 add(res,
299 "DrawBitmap",
300 [&] (OutputDevice * pDev) { return pDev->DrawBitmap(aPt1, aBitmap); });
302 /* void DrawBitmap( const Point& rDestPt, const Size& rDestSize,
303 const Bitmap& rBitmap );
305 add(res,
306 "DrawBitmap(scaled,alien source)",
307 [&] (OutputDevice * pDev) {
308 return pDev->DrawBitmap(aPt1, aRect.GetSize(), aBitmapAlien);
311 /* void DrawBitmap( const Point& rDestPt, const Size& rDestSize,
312 const Bitmap& rBitmap );
314 add(res,
315 "DrawBitmap(scaled)",
316 [&] (OutputDevice * pDev) {
317 return pDev->DrawBitmap(aPt1, aRect.GetSize(), aBitmap);
320 #if 0
321 /* void DrawBitmap( const Point& rDestPt, const Size& rDestSize,
322 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
323 const Bitmap& rBitmap );
325 add(res,
326 "DrawBitmap(scaled subset,alien source)",
327 [&] (OutputDevice * pDev) {
328 return pDev->DrawBitmap(aPt1, aRect.GetSize(), aPt3,
329 aRect2.GetSize(), aBitmapAlien);
331 #endif
333 /* void DrawBitmap( const Point& rDestPt, const Size& rDestSize,
334 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
335 const Bitmap& rBitmap );
337 add(res,
338 "DrawBitmap(scaled subset)",
339 [&] (OutputDevice * pDev) {
340 return pDev->DrawBitmap(aPt1, aRect.GetSize(), aPt3, aRect2.GetSize(), aBitmap);
343 /* void DrawBitmapEx( const Point& rDestPt,
344 const BitmapEx& rBitmapEx );
346 add(res,
347 "DrawBitmapEx(alien source)",
348 [&] (OutputDevice * pDev) { return pDev->DrawBitmapEx(aPt1, aBitmapExAlien); });
350 /* void DrawBitmapEx( const Point& rDestPt,
351 const BitmapEx& rBitmapEx );
353 add(res,
354 "DrawBitmapEx",
355 [&] (OutputDevice * pDev) { return pDev->DrawBitmapEx(aPt1, aBitmapEx); });
357 /* void DrawBitmapEx( const Point& rDestPt,
358 const BitmapEx& rBitmapEx );
360 add(res,
361 "DrawBitmapEx(alpha)",
362 [&] (OutputDevice * pDev) { return pDev->DrawBitmapEx(aPt1, aBitmapExAlpha); });
364 /* void DrawBitmapEx( const Point& rDestPt,
365 const BitmapEx& rBitmapEx );
367 add(res,
368 "DrawBitmapEx(alpha, alien source)",
369 [&] (OutputDevice * pDev) { return pDev->DrawBitmapEx(aPt1, aBitmapExAlphaAlien); });
371 /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
372 const BitmapEx& rBitmapEx );
374 add(res,
375 "DrawBitmapEx(scaled,alien source)",
376 [&] (OutputDevice * pDev) {
377 return pDev->DrawBitmapEx(aPt1, aRect.GetSize(), aBitmapExAlien);
380 /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
381 const BitmapEx& rBitmapEx );
383 add(res,
384 "DrawBitmapEx(scaled)",
385 [&] (OutputDevice * pDev) {
386 return pDev->DrawBitmapEx(aPt1, aRect.GetSize(), aBitmapEx);
389 /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
390 const BitmapEx& rBitmapEx );
392 add(res,
393 "DrawBitmapEx(scaled alpha)",
394 [&] (OutputDevice * pDev) {
395 return pDev->DrawBitmapEx(aPt1, aRect.GetSize(), aBitmapExAlpha);
398 /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
399 const BitmapEx& rBitmapEx );
401 add(res,
402 "DrawBitmapEx(scaled alpha, alien source)",
403 [&] (OutputDevice * pDev) {
404 return pDev->DrawBitmapEx(aPt1, aRect.GetSize(), aBitmapExAlphaAlien);
407 /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
408 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
409 const BitmapEx& rBitmapEx );
411 add(res,
412 "DrawBitmapEx(scaled subset,alien source)",
413 [&] (OutputDevice * pDev) {
414 return pDev->DrawBitmapEx(aPt1, aRect.GetSize(), aPt3, aRect2.GetSize(), aBitmapExAlien);
417 /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
418 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
419 const BitmapEx& rBitmapEx );
421 add(res,
422 "DrawBitmapEx(scaled subset)",
423 [&] (OutputDevice * pDev) {
424 return pDev->DrawBitmapEx(aPt1, aRect.GetSize(), aPt3, aRect2.GetSize(), aBitmapEx);
427 /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
428 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
429 const BitmapEx& rBitmapEx );
431 add(res,
432 "DrawBitmapEx(scaled subset, alpha)",
433 [&] (OutputDevice * pDev) {
434 return pDev->DrawBitmapEx(aPt1, aRect.GetSize(), aPt3, aRect2.GetSize(), aBitmapExAlpha);
437 /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
438 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
439 const BitmapEx& rBitmapEx );
441 add(res,
442 "DrawBitmapEx(scaled subset, alpha alien source)",
443 [&] (OutputDevice * pDev) {
444 return pDev->DrawBitmapEx(aPt1, aRect.GetSize(), aPt3, aRect2.GetSize(), aBitmapExAlphaAlien);
447 /* void DrawMask( const Point& rDestPt,
448 const Bitmap& rBitmap, const Color& rMaskColor );
450 add(res,
451 "DrawMask(alien source)",
452 [&] (OutputDevice * pDev) {
453 return pDev->DrawMask(aPt1, aBitmapAlien, aBlackColor);
456 /* void DrawMask( const Point& rDestPt,
457 const Bitmap& rBitmap, const Color& rMaskColor );
459 add(res,
460 "DrawMask",
461 [&] (OutputDevice * pDev) {
462 return pDev->DrawMask(aPt1, aBitmap, aBlackColor);
465 /* void DrawMask( const Point& rDestPt, const Size& rDestSize,
466 const Bitmap& rBitmap, const Color& rMaskColor );
468 add(res,
469 "DrawMask(scaled,alien source)",
470 [&] (OutputDevice * pDev) {
471 return pDev->DrawMask(aPt1, aRect.GetSize(), aBitmapAlien, aBlackColor);
474 /* void DrawMask( const Point& rDestPt, const Size& rDestSize,
475 const Bitmap& rBitmap, const Color& rMaskColor );
477 add(res,
478 "DrawMask(scaled)",
479 [&] (OutputDevice * pDev) {
480 return pDev->DrawMask(aPt1, aRect.GetSize(), aBitmap, aBlackColor);
483 /* void DrawMask( const Point& rDestPt, const Size& rDestSize,
484 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
485 const Bitmap& rBitmap, const Color& rMaskColor );
487 add(res,
488 "DrawMask(scaled subset,alien source)",
489 [&] (OutputDevice * pDev) {
490 return pDev->DrawMask(aPt1, aRect.GetSize(), aPt3, aRect2.GetSize(),
491 aBitmapAlien, aBlackColor);
494 /* void DrawMask( const Point& rDestPt, const Size& rDestSize,
495 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
496 const Bitmap& rBitmap, const Color& rMaskColor );
498 add(res,
499 "DrawMask(scaled subset)",
500 [&] (OutputDevice * pDev) {
501 return pDev->DrawMask(aPt1, aRect.GetSize(), aPt3, aRect2.GetSize(), aBitmap, aBlackColor);
504 /* void DrawImage( const Point& rPos,
505 const Image& rImage, sal_uInt16 nStyle = 0 );
507 add(res,
508 "DrawImage",
509 [&] (OutputDevice * pDev) {
510 return pDev->DrawImage(aPt1, aImage, static_cast<sal_uInt16>(0));
513 /* void DrawImage( const Point& rPos, const Size& rSize,
514 const Image& rImage, sal_uInt16 nStyle = 0 );
516 add(res,
517 "DrawImage(scaled)",
518 [&] (OutputDevice * pDev) {
519 return pDev->DrawImage(aPt1, aRect.GetSize(), aImage, static_cast<sal_uInt16>(0)));
522 #endif // NEEDS_QUALITY_PARAMETER
524 /* void DrawGradient( const Rectangle& rRect, const Gradient& rGradient ); */
525 add(res,
526 "DrawGradient",
527 [&] (OutputDevice * pDev) {
528 return pDev->DrawGradient(aRect, aGradient);
531 /* void DrawGradient( const tools::PolyPolygon& rPolyPoly, const Gradient& rGradient ); */
532 add(res,
533 "DrawGradient(polygon)",
534 [&] (OutputDevice * pDev) {
535 return pDev->DrawGradient(aPoly3, aGradient);
538 /* void DrawHatch( const tools::PolyPolygon& rPolyPoly, const Hatch& rHatch ); */
539 add(res,
540 "DrawHatch",
541 [&] (OutputDevice * pDev) {
542 return pDev->DrawHatch(aPoly3, aHatch);
545 /* void DrawWallpaper( const Rectangle& rRect, const Wallpaper& rWallpaper ); */
546 add(res,
547 "DrawWallpaper",
548 [&] (OutputDevice * pDev) {
549 return pDev->DrawWallpaper(aRect2, aWallpaper);
552 #ifdef FIXME_HAVE_WAVE_NORMAL
553 /* void DrawWaveLine( const Point& rStartPos, const Point& rEndPos, sal_uInt16 nStyle ); */
554 add(res,
555 "DrawWaveLine",
556 [&] (OutputDevice * pDev) {
557 return pDev->DrawWaveLine(aPt1, aPt2, (sal_uInt16)WAVE_NORMAL);
559 #endif
561 /* void DrawGrid( const Rectangle& rRect, const Size& rDist, sal_uLong nFlags ); */
562 add(res,
563 "DrawGrid",
564 [&] (OutputDevice * pDev) {
565 return pDev->DrawGrid(aRect, Size(10,20), DrawGridFlags::HorzLines|DrawGridFlags::VertLines);
568 /* void DrawTransparent( const tools::PolyPolygon& rPolyPoly,
569 sal_uInt16 nTransparencePercent );
571 add(res,
572 "DrawTransparent",
573 [&] (OutputDevice * pDev) {
574 return pDev->DrawTransparent(aPoly3, sal_uInt16(50));
577 /* void DrawTransparent( const GDIMetaFile& rMtf,
578 const Point& rPos, const Size& rSize,
579 const Gradient& rTransparenceGradient );
581 add(res,
582 "DrawTransparent(metafile)",
583 [&] (OutputDevice * pDev) {
584 return pDev->DrawTransparent(aMtf, aPt1, aRect.GetSize(), aGradient);
587 /* void Erase(); */
588 add(res,
589 "Erase",
590 [] (OutputDevice * pDev) { return pDev->Erase(); } );
594 void grindFunc( OutputDevice& rTarget,
595 functor_vector_type::const_iterator const & iter,
596 sal_Int32 nTurns,
597 const char* pMsg )
599 const sal_uInt32 nStartTime( osl_getGlobalTimer() );
601 for( sal_Int32 i=0; i<nTurns; ++i )
602 iter->second(&rTarget);
604 if( rTarget.GetOutDevType() == OUTDEV_WINDOW )
605 static_cast< vcl::Window & >( rTarget ).Flush();
607 fprintf( stdout,
608 "Duration: %d ms (%d repetitions)\tOperation: %s\tSetup: %s\n",
609 static_cast<int>(osl_getGlobalTimer() - nStartTime),
610 static_cast<int>(nTurns),
611 iter->first,
612 pMsg );
615 /** Call OutputDevice render methods repeatedly, and output elapsed
616 time to stdout
618 void outDevGrind(vcl::RenderContext& rTarget)
620 sal_Int32 nTurns = 100;
621 // TODO(F1): also profile pure complex clip setup times!
623 // State: fill/line color, draw mode, w/o clip, rect clip, complex clip
624 functor_vector_type aMethods;
625 setupMethodStubs( aMethods );
627 const tools::Rectangle aClipRect(10,10,1000,1000);
628 const tools::Polygon aPoly1( aClipRect );
629 tools::Polygon aPoly2( aClipRect );
630 aPoly2.Rotate(aClipRect.Center(),450);
631 tools::PolyPolygon aClipPoly(aPoly1);
632 aClipPoly.Insert(aPoly2);
634 functor_vector_type::const_iterator iter = aMethods.begin();
635 const functor_vector_type::const_iterator end = aMethods.end();
636 while( iter != end )
638 rTarget.SetLineColor( COL_BLACK );
639 rTarget.SetFillColor( COL_GREEN );
640 rTarget.SetRasterOp( RasterOp::OverPaint );
641 rTarget.SetClipRegion();
642 grindFunc( rTarget, iter, nTurns, "w/o clip, w/o xor" );
644 rTarget.SetLineColor( COL_BLACK );
645 rTarget.SetFillColor( COL_GREEN );
646 rTarget.SetRasterOp( RasterOp::OverPaint );
647 rTarget.SetClipRegion( vcl::Region( aClipRect ) );
648 grindFunc( rTarget, iter, nTurns, "with rect clip, w/o xor" );
650 rTarget.SetLineColor( COL_BLACK );
651 rTarget.SetFillColor( COL_GREEN );
652 rTarget.SetRasterOp( RasterOp::OverPaint );
653 rTarget.SetClipRegion( vcl::Region( aClipPoly ) );
654 grindFunc( rTarget, iter, nTurns, "with complex clip, w/o xor" );
656 rTarget.SetLineColor( COL_BLACK );
657 rTarget.SetFillColor( COL_GREEN );
658 rTarget.SetRasterOp( RasterOp::Xor );
659 rTarget.SetClipRegion();
660 grindFunc( rTarget, iter, nTurns, "w/o clip, with xor" );
662 rTarget.SetLineColor( COL_BLACK );
663 rTarget.SetFillColor( COL_GREEN );
664 rTarget.SetRasterOp( RasterOp::Xor );
665 rTarget.SetClipRegion( vcl::Region( aClipRect ) );
666 grindFunc( rTarget, iter, nTurns, "with rect clip, with xor" );
668 rTarget.SetLineColor( COL_BLACK );
669 rTarget.SetFillColor( COL_GREEN );
670 rTarget.SetRasterOp( RasterOp::Xor );
671 rTarget.SetClipRegion( vcl::Region( aClipPoly ) );
672 grindFunc( rTarget, iter, nTurns, "with complex clip, with xor" );
674 ++iter;
678 void TestWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
680 outDevGrind(rRenderContext);
681 fflush(stdout);
684 void GrindApp::Exception( ExceptionCategory nCategory )
686 switch( nCategory )
688 case ExceptionCategory::ResourceNotLoaded:
689 Abort( "Error: could not load language resources.\nPlease check your installation.\n" );
690 break;
691 default: break;
695 int GrindApp::Main()
697 ScopedVclPtrInstance<TestWindow> aWindow;
698 aWindow->Execute();
699 return 0;
702 } // namespace
705 SAL_IMPLEMENT_MAIN()
709 bool bHelp = false;
711 for( sal_uInt16 i = 0; i < Application::GetCommandLineParamCount(); i++ )
713 OUString aParam = Application::GetCommandLineParam( i );
715 if( aParam == "--help" || aParam == "-h" )
716 bHelp = true;
719 if( bHelp )
721 printf( "outdevgrind - Profile OutputDevice\n" );
722 return EXIT_SUCCESS;
725 tools::extendApplicationEnvironment();
727 uno::Reference< uno::XComponentContext > xContext = cppu::defaultBootstrap_InitialComponentContext();
728 uno::Reference< lang::XMultiServiceFactory > xServiceManager( xContext->getServiceManager(), uno::UNO_QUERY );
730 if( !xServiceManager.is() )
731 Application::Abort( "Failed to bootstrap" );
733 comphelper::setProcessServiceFactory( xServiceManager );
735 InitVCL();
737 GrindApp aGrindApp;
738 aGrindApp.Main();
740 DeInitVCL();
742 catch (const css::uno::Exception& e)
744 SAL_WARN("vcl.app", "Fatal: " << e);
745 return EXIT_FAILURE;
747 catch (const std::exception& e)
749 SAL_WARN("vcl.app", "Fatal: " << e.what());
750 return EXIT_FAILURE;
753 return EXIT_SUCCESS;
756 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */