xref: /aoo42x/main/vcl/workben/outdevgrind.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 // bootstrap stuff
32 #include <rtl/bootstrap.hxx>
33 #include <comphelper/processfactory.hxx>
34 #include <comphelper/regpathhelper.hxx>
35 #include <cppuhelper/servicefactory.hxx>
36 #include <cppuhelper/bootstrap.hxx>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <com/sun/star/registry/XSimpleRegistry.hpp>
40 
41 #include <ucbhelper/contentbroker.hxx>
42 #include <ucbhelper/configurationkeys.hxx>
43 
44 #include <vcl/svapp.hxx>
45 #include <vcl/dialog.hxx>
46 #include <vcl/outdev.hxx>
47 #include <vcl/virdev.hxx>
48 #include <vcl/hatch.hxx>
49 #include <vcl/bitmap.hxx>
50 #include <vcl/wall.hxx>
51 #include <vcl/image.hxx>
52 #include <vcl/gdimtf.hxx>
53 #include <vcl/metaact.hxx>
54 #include <vcl/bitmapex.hxx>
55 #include <vcl/gradient.hxx>
56 #include <vcl/lineinfo.hxx>
57 #include <tools/string.hxx>
58 
59 #include <osl/time.h>
60 
61 #include <boost/function.hpp>
62 #include <boost/bind.hpp>
63 
64 #include <stdio.h>
65 #include <unistd.h>
66 
67 using namespace ::com::sun::star;
68 
69 
70 namespace
71 {
72 
73 class GrindApp : public Application
74 {
75 public:
76 	virtual void   Main();
77 	virtual sal_uInt16 Exception( sal_uInt16 nError );
78 };
79 
80 class TestWindow : public Dialog
81 {
82 	public:
83 		TestWindow() : Dialog( (Window *) NULL )
84 		{
85 			SetText( rtl::OUString::createFromAscii( "OutDev grinding" ) );
86 			SetSizePixel( Size( 1024, 1024 ) );
87 			EnablePaint( true );
88 			Show();
89 		}
90 
91 		virtual ~TestWindow() {}
92 		virtual void Paint( const Rectangle& rRect );
93 };
94 
95 //----------------------------------------------------------------------------------
96 
97 typedef boost::function1<void, OutputDevice*>   functor_type;
98 typedef std::vector< std::pair<const char*,
99                                functor_type> >  functor_vector_type;
100 
101 template< typename Functor > void add( functor_vector_type& res,
102                                        const char*          pStr,
103                                        const Functor&       func )
104 {
105     res.push_back( std::make_pair(pStr,functor_type(func)) );
106 }
107 
108 void setupMethodStubs( functor_vector_type& res )
109 {
110     const Color aWhiteColor( COL_WHITE );
111     const Color aBlackColor( COL_BLACK );
112 
113     const Point aPt1(10,10);
114     const Point aPt2(500,500);
115     const Point aPt3(0,0);
116     const Point aPt4(450,450);
117 
118     const Rectangle   aRect(aPt1,aPt2);
119     const Rectangle   aRect2(aPt3,aPt4);
120     const Polygon     aPoly(aRect);
121     const Polygon     aPoly2(aRect2);
122     PolyPolygon       aPolyPoly(aPoly);
123     aPolyPoly.Insert( aPoly2 );
124     Polygon           aPoly3(aPoly2);
125     aPoly3.Rotate( aPoly3.GetBoundRect().Center(),
126                    900 );
127 
128     const String      aString( ByteString("This is a test"),
129                                RTL_TEXTENCODING_ASCII_US );
130     const LineInfo    aLineInfo(LINE_SOLID,5);
131 
132     // unfortunately, VDevs have inaccessible copy constructors
133     static VirtualDevice aVDev;
134     static VirtualDevice aVDevBW(1);
135 
136     const Size aVDevSize;
137     aVDev.SetOutputSizePixel(aVDevSize);
138     aVDevBW.SetOutputSizePixel(aVDevSize);
139 
140     const Bitmap      aBitmap( aVDev.GetBitmap(aPt1,aVDevSize) );
141     const Bitmap      aBitmapBW( aVDevBW.GetBitmap(aPt1,aVDevSize) );
142     const Bitmap      aBitmapAlien( aVDevSize, 8 );
143 
144     const BitmapEx    aBitmapEx( aBitmap, aBitmapBW );
145     const BitmapEx    aBitmapExBW( aBitmapBW, aBitmapBW );
146     const BitmapEx    aBitmapExAlien( aBitmapAlien, aBitmapBW );
147     const BitmapEx    aBitmapExAlpha( aBitmap, aBitmapAlien );
148     const BitmapEx    aBitmapExAlphaAlien( aBitmapAlien, aBitmapAlien );
149 
150     const Image       aImage( aBitmapEx );
151     const Gradient    aGradient(GRADIENT_ELLIPTICAL,aBlackColor,aWhiteColor);
152     const Hatch       aHatch(HatchStyle_TRIPLE,aBlackColor,4,450);
153     const Wallpaper   aWallpaper( aWhiteColor );
154 
155     GDIMetaFile       aMtf;
156     aMtf.AddAction( new MetaFillColorAction(Color(COL_RED),sal_True) );
157     aMtf.AddAction( new MetaRectAction(aRect) );
158 
159     /* void DrawText( const Point& rStartPt, const XubString& rStr,
160                    xub_StrLen nIndex = 0, xub_StrLen nLen = STRING_LEN,
161                    MetricVector* pVector = NULL, String* pDisplayText = NULL );
162     */
163 //    add(res,
164 //        "DrawText",
165 //        boost::bind(
166 //            &OutputDevice::DrawText,
167 //            _1,
168 //            aPt1, aString, (sal_uInt16)0, aString.Len(), (MetricVector*)0, (String*)0, (vcl::ITextLayout*)0 ));
169 
170     /* void DrawTextArray( const Point& rStartPt, const XubString& rStr,
171                                        const sal_Int32* pDXAry = NULL,
172                                        xub_StrLen nIndex = 0,
173                                        xub_StrLen nLen = STRING_LEN );
174     */
175     add(res,
176         "DrawTextArray",
177         boost::bind(
178             &OutputDevice::DrawTextArray,
179             _1,
180             aPt1, aString, (const sal_Int32*)0, (sal_uInt16)0, aString.Len() ));
181 
182     /* void DrawPixel( const Point& rPt, const Color& rColor ); */
183     add(res,
184         "DrawPixel",
185         boost::bind(
186             (void (OutputDevice::*)( const Point&, const Color& ))(
187                 &OutputDevice::DrawPixel),
188             _1,
189             aPt1, aBlackColor ));
190 
191     /* void DrawLine( const Point& rStartPt, const Point& rEndPt ); */
192     add(res,
193         "DrawLine",
194         boost::bind(
195             (void (OutputDevice::*)( const Point&, const Point& ))(
196                 &OutputDevice::DrawLine),
197             _1,
198             aPt1, aPt2 ));
199 
200     /* void DrawLine( const Point& rStartPt, const Point& rEndPt,
201                                   const LineInfo& rLineInfo );
202     */
203     add(res,
204         "DrawLine(LineInfo)",
205         boost::bind(
206             (void (OutputDevice::*)( const Point&, const Point&,const LineInfo& ))(
207                 &OutputDevice::DrawLine),
208             _1,
209             aPt1, aPt2, aLineInfo ));
210 
211     /* void DrawPolyLine( const Polygon& rPoly ); */
212     add(res,
213         "DrawPolyLine",
214         boost::bind(
215             (void (OutputDevice::*)( const Polygon& ))(
216                 &OutputDevice::DrawPolyLine),
217             _1,
218             aPoly ));
219 
220     /* void DrawPolyLine( const Polygon& rPoly,
221                                       const LineInfo& rLineInfo );
222     */
223     add(res,
224         "DrawPolyLine(LineInfo)",
225         boost::bind(
226             (void (OutputDevice::*)( const Polygon&, const LineInfo& ))(
227                 &OutputDevice::DrawPolyLine),
228             _1,
229             aPoly, aLineInfo ));
230 
231     /* void DrawPolygon( const Polygon& rPoly ); */
232     add(res,
233         "DrawPolygon",
234         boost::bind(
235             (void (OutputDevice::*)( const Polygon& ))
236                 &OutputDevice::DrawPolygon,
237             _1,
238             aPoly ));
239 
240     /* void DrawPolyPolygon( const PolyPolygon& rPolyPoly ); */
241     add(res,
242         "DrawPolyPolygon",
243         boost::bind(
244             (void (OutputDevice::*)( const PolyPolygon& ))
245                 &OutputDevice::DrawPolyPolygon,
246             _1,
247             aPolyPoly ));
248 
249     /* void DrawRect( const Rectangle& rRect ); */
250     add(res,
251         "DrawRect",
252         boost::bind(
253             (void (OutputDevice::*)( const Rectangle& ))(
254                 &OutputDevice::DrawRect),
255             _1,
256             aRect ));
257 
258     /* void DrawRect( const Rectangle& rRect,
259                                   sal_uLong nHorzRount, sal_uLong nVertRound );
260     */
261     add(res,
262         "DrawRect(round corners)",
263         boost::bind(
264             (void (OutputDevice::*)( const Rectangle&, sal_uLong nHorzRount, sal_uLong nVertRound ))(
265                 &OutputDevice::DrawRect),
266             _1,
267             aRect2,
268             4,4));
269 
270     /* void DrawEllipse( const Rectangle& rRect ); */
271     add(res,
272         "DrawEllipse",
273         boost::bind(
274             &OutputDevice::DrawEllipse,
275             _1,
276             aRect ));
277 
278     /* void DrawArc( const Rectangle& rRect,
279                                  const Point& rStartPt, const Point& rEndPt );
280     */
281     add(res,
282         "DrawArc",
283         boost::bind(
284             &OutputDevice::DrawArc,
285             _1,
286             aRect,aPt1,aPt2 ));
287 
288     /* void DrawPie( const Rectangle& rRect,
289                                  const Point& rStartPt, const Point& rEndPt );
290     */
291     add(res,
292         "DrawPie",
293         boost::bind(
294             &OutputDevice::DrawPie,
295             _1,
296             aRect2,aPt3,aPt4 ));
297 
298     /* void DrawChord( const Rectangle& rRect,
299                                    const Point& rStartPt, const Point& rEndPt );
300     */
301     add(res,
302         "DrawChord",
303         boost::bind(
304             &OutputDevice::DrawChord,
305             _1,
306             aRect2,aPt3,aPt4 ));
307 
308     /* void DrawOutDev( const Point& rDestPt, const Size& rDestSize,
309                                     const Point& rSrcPt,  const Size& rSrcSize );
310     */
311     add(res,
312         "DrawOutDev",
313         boost::bind(
314             (void (OutputDevice::*)( const Point&, const Size&,
315                                      const Point&, const Size& ))(
316                 &OutputDevice::DrawOutDev),
317             _1,
318             aRect2.TopLeft(), aRect2.GetSize(),
319             aRect.TopLeft(),  aRect.GetSize()));
320 
321     /* void DrawOutDev( const Point& rDestPt, const Size& rDestSize,
322                                     const Point& rSrcPt,  const Size& rSrcSize,
323                                     const OutputDevice& rOutDev );
324     */
325     add(res,
326         "DrawOutDev(foreign source)",
327         boost::bind(
328             (void (OutputDevice::*)( const Point&, const Size&,
329                                      const Point&, const Size&,
330                                      const OutputDevice& ))(
331                 &OutputDevice::DrawOutDev),
332             _1,
333             aRect2.TopLeft(), aRect2.GetSize(),
334             aRect.TopLeft(),  aRect.GetSize(),
335             boost::cref(aVDevBW) ));
336 
337     /* void DrawOutDev( const Point& rDestPt, const Size& rDestSize,
338                                     const Point& rSrcPt,  const Size& rSrcSize,
339                                     const OutputDevice& rOutDev );
340     */
341     add(res,
342         "DrawOutDev(foreign source, scaled)",
343         boost::bind(
344             (void (OutputDevice::*)( const Point&, const Size&,
345                                      const Point&, const Size&,
346                                      const OutputDevice& ))(
347                 &OutputDevice::DrawOutDev),
348             _1,
349             aRect2.TopLeft(), aRect2.GetSize(),
350             aRect.TopLeft(),  aRect.GetSize(),
351             boost::cref(aVDev) ));
352 
353     /* void CopyArea( const Point& rDestPt,
354                                   const Point& rSrcPt,  const Size& rSrcSize,
355                                   sal_uInt16 nFlags = 0 );
356     */
357     add(res,
358         "CopyArea",
359         boost::bind(
360             &OutputDevice::CopyArea,
361             _1,
362             aPt1,aPt3,aRect2.GetSize(),(sal_uInt16)0 ));
363 
364     /* void DrawBitmap( const Point& rDestPt,
365                                     const Bitmap& rBitmap );
366     */
367     add(res,
368         "DrawBitmap(alien source)",
369         boost::bind(
370             (void (OutputDevice::*)( const Point&,
371                                      const Bitmap& ))(
372                 &OutputDevice::DrawBitmap),
373             _1,
374             aPt1,aBitmapAlien ));
375 
376     /* void DrawBitmap( const Point& rDestPt,
377                                     const Bitmap& rBitmap );
378     */
379     add(res,
380         "DrawBitmap",
381         boost::bind(
382             (void (OutputDevice::*)( const Point&,
383                                      const Bitmap& ))(
384                 &OutputDevice::DrawBitmap),
385             _1,
386             aPt1,aBitmap ));
387 
388     /* void DrawBitmap( const Point& rDestPt, const Size& rDestSize,
389                                     const Bitmap& rBitmap );
390     */
391     add(res,
392         "DrawBitmap(scaled,alien source)",
393         boost::bind(
394             (void (OutputDevice::*)( const Point&,
395                                      const Size&,
396                                      const Bitmap& ))(
397                 &OutputDevice::DrawBitmap),
398             _1,
399             aPt1,aRect.GetSize(),aBitmapAlien ));
400 
401     /* void DrawBitmap( const Point& rDestPt, const Size& rDestSize,
402                                     const Bitmap& rBitmap );
403     */
404     add(res,
405         "DrawBitmap(scaled)",
406         boost::bind(
407             (void (OutputDevice::*)( const Point&,
408                                      const Size&,
409                                      const Bitmap& ))(
410                 &OutputDevice::DrawBitmap),
411             _1,
412             aPt1,aRect.GetSize(),aBitmap ));
413 
414     /* void DrawBitmap( const Point& rDestPt, const Size& rDestSize,
415                                     const Point& rSrcPtPixel, const Size& rSrcSizePixel,
416                                     const Bitmap& rBitmap );
417     */
418     add(res,
419         "DrawBitmap(scaled subset,alien source)",
420         boost::bind(
421             (void (OutputDevice::*)( const Point&,
422                                      const Size&,
423                                      const Point&,
424                                      const Size&,
425                                      const Bitmap& ))(
426                 &OutputDevice::DrawBitmap),
427             _1,
428             aPt1,aRect.GetSize(),aPt3,aRect2.GetSize(),aBitmapAlien ));
429 
430     /* void DrawBitmap( const Point& rDestPt, const Size& rDestSize,
431                                     const Point& rSrcPtPixel, const Size& rSrcSizePixel,
432                                     const Bitmap& rBitmap );
433     */
434     add(res,
435         "DrawBitmap(scaled subset)",
436         boost::bind(
437             (void (OutputDevice::*)( const Point&,
438                                      const Size&,
439                                      const Point&,
440                                      const Size&,
441                                      const Bitmap& ))(
442                 &OutputDevice::DrawBitmap),
443             _1,
444             aPt1,aRect.GetSize(),aPt3,aRect2.GetSize(),aBitmap ));
445 
446     /* void DrawBitmapEx( const Point& rDestPt,
447                                       const BitmapEx& rBitmapEx );
448     */
449     add(res,
450         "DrawBitmapEx(alien source)",
451         boost::bind(
452             (void (OutputDevice::*)( const Point&,
453                                      const BitmapEx& ))(
454                 &OutputDevice::DrawBitmapEx),
455             _1,
456             aPt1,aBitmapExAlien ));
457 
458     /* void DrawBitmapEx( const Point& rDestPt,
459                                       const BitmapEx& rBitmapEx );
460     */
461     add(res,
462         "DrawBitmapEx",
463         boost::bind(
464             (void (OutputDevice::*)( const Point&,
465                                      const BitmapEx& ))(
466                 &OutputDevice::DrawBitmapEx),
467             _1,
468             aPt1,aBitmapEx ));
469 
470     /* void DrawBitmapEx( const Point& rDestPt,
471                                       const BitmapEx& rBitmapEx );
472     */
473     add(res,
474         "DrawBitmapEx(alpha)",
475         boost::bind(
476             (void (OutputDevice::*)( const Point&,
477                                      const BitmapEx& ))(
478                 &OutputDevice::DrawBitmapEx),
479             _1,
480             aPt1,aBitmapExAlpha ));
481 
482     /* void DrawBitmapEx( const Point& rDestPt,
483                                       const BitmapEx& rBitmapEx );
484     */
485     add(res,
486         "DrawBitmapEx(alpha, alien source)",
487         boost::bind(
488             (void (OutputDevice::*)( const Point&,
489                                      const BitmapEx& ))(
490                 &OutputDevice::DrawBitmapEx),
491             _1,
492             aPt1,aBitmapExAlphaAlien ));
493 
494     /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
495                                       const BitmapEx& rBitmapEx );
496     */
497     add(res,
498         "DrawBitmapEx(scaled,alien source)",
499         boost::bind(
500             (void (OutputDevice::*)( const Point&,
501                                      const Size&,
502                                      const BitmapEx& ))(
503                 &OutputDevice::DrawBitmapEx),
504             _1,
505             aPt1,aRect.GetSize(),aBitmapExAlien ));
506 
507     /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
508                                       const BitmapEx& rBitmapEx );
509     */
510     add(res,
511         "DrawBitmapEx(scaled)",
512         boost::bind(
513             (void (OutputDevice::*)( const Point&,
514                                      const Size&,
515                                      const BitmapEx& ))(
516                 &OutputDevice::DrawBitmapEx),
517             _1,
518             aPt1,aRect.GetSize(),aBitmapEx ));
519 
520     /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
521                                       const BitmapEx& rBitmapEx );
522     */
523     add(res,
524         "DrawBitmapEx(scaled alpha)",
525         boost::bind(
526             (void (OutputDevice::*)( const Point&,
527                                      const Size&,
528                                      const BitmapEx& ))(
529                 &OutputDevice::DrawBitmapEx),
530             _1,
531             aPt1,aRect.GetSize(),aBitmapExAlpha ));
532 
533     /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
534                                       const BitmapEx& rBitmapEx );
535     */
536     add(res,
537         "DrawBitmapEx(scaled alpha, alien source)",
538         boost::bind(
539             (void (OutputDevice::*)( const Point&,
540                                      const Size&,
541                                      const BitmapEx& ))(
542                 &OutputDevice::DrawBitmapEx),
543             _1,
544             aPt1,aRect.GetSize(),aBitmapExAlphaAlien ));
545 
546     /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
547                                       const Point& rSrcPtPixel, const Size& rSrcSizePixel,
548                                       const BitmapEx& rBitmapEx );
549     */
550     add(res,
551         "DrawBitmapEx(scaled subset,alien source)",
552         boost::bind(
553             (void (OutputDevice::*)( const Point&,
554                                      const Size&,
555                                      const Point&,
556                                      const Size&,
557                                      const BitmapEx& ))(
558                 &OutputDevice::DrawBitmapEx),
559             _1,
560             aPt1,aRect.GetSize(),aPt3,aRect2.GetSize(),aBitmapExAlien ));
561 
562     /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
563                                       const Point& rSrcPtPixel, const Size& rSrcSizePixel,
564                                       const BitmapEx& rBitmapEx );
565     */
566     add(res,
567         "DrawBitmapEx(scaled subset)",
568         boost::bind(
569             (void (OutputDevice::*)( const Point&,
570                                      const Size&,
571                                      const Point&,
572                                      const Size&,
573                                      const BitmapEx& ))(
574                 &OutputDevice::DrawBitmapEx),
575             _1,
576             aPt1,aRect.GetSize(),aPt3,aRect2.GetSize(),aBitmapEx ));
577 
578     /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
579                                       const Point& rSrcPtPixel, const Size& rSrcSizePixel,
580                                       const BitmapEx& rBitmapEx );
581     */
582     add(res,
583         "DrawBitmapEx(scaled subset, alpha)",
584         boost::bind(
585             (void (OutputDevice::*)( const Point&,
586                                      const Size&,
587                                      const Point&,
588                                      const Size&,
589                                      const BitmapEx& ))(
590                 &OutputDevice::DrawBitmapEx),
591             _1,
592             aPt1,aRect.GetSize(),aPt3,aRect2.GetSize(),aBitmapExAlpha ));
593 
594     /* void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
595                                       const Point& rSrcPtPixel, const Size& rSrcSizePixel,
596                                       const BitmapEx& rBitmapEx );
597     */
598     add(res,
599         "DrawBitmapEx(scaled subset, alpha alien source)",
600         boost::bind(
601             (void (OutputDevice::*)( const Point&,
602                                      const Size&,
603                                      const Point&,
604                                      const Size&,
605                                      const BitmapEx& ))(
606                 &OutputDevice::DrawBitmapEx),
607             _1,
608             aPt1,aRect.GetSize(),aPt3,aRect2.GetSize(),aBitmapExAlphaAlien ));
609 
610     /* void DrawMask( const Point& rDestPt,
611                                   const Bitmap& rBitmap, const Color& rMaskColor );
612     */
613     add(res,
614         "DrawMask(alien source)",
615         boost::bind(
616             (void (OutputDevice::*)( const Point&,
617                                      const Bitmap&,
618                                      const Color& ))(
619                 &OutputDevice::DrawMask),
620             _1,
621             aPt1,aBitmapAlien,aBlackColor ));
622 
623     /* void DrawMask( const Point& rDestPt,
624                                   const Bitmap& rBitmap, const Color& rMaskColor );
625     */
626     add(res,
627         "DrawMask",
628         boost::bind(
629             (void (OutputDevice::*)( const Point&,
630                                      const Bitmap&,
631                                      const Color& ))(
632                 &OutputDevice::DrawMask),
633             _1,
634             aPt1,aBitmap,aBlackColor ));
635 
636     /* void DrawMask( const Point& rDestPt, const Size& rDestSize,
637                                   const Bitmap& rBitmap, const Color& rMaskColor );
638     */
639     add(res,
640         "DrawMask(scaled,alien source)",
641         boost::bind(
642             (void (OutputDevice::*)( const Point&,
643                                      const Size&,
644                                      const Bitmap&,
645                                      const Color& ))(
646                 &OutputDevice::DrawMask),
647             _1,
648             aPt1,aRect.GetSize(),aBitmapAlien, aBlackColor ));
649 
650     /* void DrawMask( const Point& rDestPt, const Size& rDestSize,
651                                   const Bitmap& rBitmap, const Color& rMaskColor );
652     */
653     add(res,
654         "DrawMask(scaled)",
655         boost::bind(
656             (void (OutputDevice::*)( const Point&,
657                                      const Size&,
658                                      const Bitmap&,
659                                      const Color& ))(
660                 &OutputDevice::DrawMask),
661             _1,
662             aPt1,aRect.GetSize(),aBitmap,aBlackColor ));
663 
664     /* void DrawMask( const Point& rDestPt, const Size& rDestSize,
665                                   const Point& rSrcPtPixel, const Size& rSrcSizePixel,
666                                   const Bitmap& rBitmap, const Color& rMaskColor );
667     */
668     add(res,
669         "DrawMask(scaled subset,alien source)",
670         boost::bind(
671             (void (OutputDevice::*)( const Point&,
672                                      const Size&,
673                                      const Point&,
674                                      const Size&,
675                                      const Bitmap&,
676                                      const Color& ))(
677                 &OutputDevice::DrawMask),
678             _1,
679             aPt1,aRect.GetSize(),aPt3,aRect2.GetSize(),aBitmapAlien,aBlackColor ));
680 
681     /* void DrawMask( const Point& rDestPt, const Size& rDestSize,
682                                   const Point& rSrcPtPixel, const Size& rSrcSizePixel,
683                                   const Bitmap& rBitmap, const Color& rMaskColor );
684     */
685     add(res,
686         "DrawMask(scaled subset)",
687         boost::bind(
688             (void (OutputDevice::*)( const Point&,
689                                      const Size&,
690                                      const Point&,
691                                      const Size&,
692                                      const Bitmap&,
693                                      const Color& ))(
694                 &OutputDevice::DrawMask),
695             _1,
696             aPt1,aRect.GetSize(),aPt3,aRect2.GetSize(),aBitmap,aBlackColor ));
697 
698     /* void DrawImage( const Point& rPos,
699                                    const Image& rImage, sal_uInt16 nStyle = 0 );
700     */
701     add(res,
702         "DrawImage",
703         boost::bind(
704             (void (OutputDevice::*)( const Point&,
705                                      const Image&,
706                                      sal_uInt16 nStyle ))(
707                 &OutputDevice::DrawImage),
708             _1,
709             aPt1,aImage,(sal_uInt16)0 ));
710 
711     /* void DrawImage( const Point& rPos, const Size& rSize,
712                                    const Image& rImage, sal_uInt16 nStyle = 0 );
713     */
714     add(res,
715         "DrawImage(scaled)",
716         boost::bind(
717             (void (OutputDevice::*)( const Point&,
718                                      const Size&,
719                                      const Image&,
720                                      sal_uInt16 nStyle ))(
721                 &OutputDevice::DrawImage),
722             _1,
723             aPt1,aRect.GetSize(),aImage,(sal_uInt16)0 ));
724 
725     /* void DrawGradient( const Rectangle& rRect, const Gradient& rGradient ); */
726     add(res,
727         "DrawGradient",
728         boost::bind(
729             (void (OutputDevice::*)( const Rectangle&, const Gradient& ))(
730                 &OutputDevice::DrawGradient),
731             _1,
732             aRect,aGradient ));
733 
734     /* void DrawGradient( const PolyPolygon& rPolyPoly, const Gradient& rGradient ); */
735     add(res,
736         "DrawGradient(polygon)",
737         boost::bind(
738             (void (OutputDevice::*)( const PolyPolygon&, const Gradient& ))(
739                 &OutputDevice::DrawGradient),
740             _1,
741             aPoly3,aGradient ));
742 
743     /* void DrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHatch ); */
744     add(res,
745         "DrawHatch",
746         boost::bind(
747             &OutputDevice::DrawHatch,
748             _1,
749             aPoly3,aHatch ));
750 
751     /* void DrawWallpaper( const Rectangle& rRect, const Wallpaper& rWallpaper ); */
752     add(res,
753         "DrawWallpaper",
754         boost::bind(
755             &OutputDevice::DrawWallpaper,
756             _1,
757             aRect2,aWallpaper ));
758 
759     /* void DrawWaveLine( const Point& rStartPos, const Point& rEndPos, sal_uInt16 nStyle ); */
760     add(res,
761         "DrawWaveLine",
762         boost::bind(
763             &OutputDevice::DrawWaveLine,
764             _1,
765             aPt1,aPt2,(sal_uInt16)WAVE_NORMAL ));
766 
767     /* void DrawGrid( const Rectangle& rRect, const Size& rDist, sal_uLong nFlags ); */
768     add(res,
769         "DrawGrid",
770         boost::bind(
771             &OutputDevice::DrawGrid,
772             _1,
773             aRect,Size(10,20),GRID_HORZLINES|GRID_VERTLINES ));
774 
775     /* void DrawTransparent( const PolyPolygon& rPolyPoly,
776                                          sal_uInt16 nTransparencePercent );
777     */
778     add(res,
779         "DrawTransparent",
780         boost::bind(
781             (void (OutputDevice::*)( const PolyPolygon&, sal_uInt16 ))(
782                 &OutputDevice::DrawTransparent),
783             _1,
784             aPoly3,(sal_uInt16)50 ));
785 
786     /* void DrawTransparent( const GDIMetaFile& rMtf,
787                                          const Point& rPos, const Size& rSize,
788                                          const Gradient& rTransparenceGradient );
789     */
790     add(res,
791         "DrawTransparent(metafile)",
792         boost::bind(
793             (void (OutputDevice::*)( const GDIMetaFile&,
794                                      const Point&,
795                                      const Size&,
796                                      const Gradient& ))(
797                 &OutputDevice::DrawTransparent),
798             _1,
799             aMtf,aPt1,aRect.GetSize(),aGradient ));
800 
801     /* void Erase(); */
802     add(res,
803         "Erase",
804         boost::bind(
805             &OutputDevice::Erase,
806             _1 ));
807 
808 }
809 
810 //----------------------------------------------------------------------------------
811 
812 void grindFunc( OutputDevice&                       rTarget,
813                 functor_vector_type::const_iterator iter,
814                 sal_Int32                           nTurns,
815                 const char*                         pMsg )
816 {
817     const sal_uInt32 nStartTime( osl_getGlobalTimer() );
818 
819     for( sal_Int32 i=0; i<nTurns; ++i )
820         iter->second(&rTarget);
821 
822     if( rTarget.GetOutDevType() == OUTDEV_WINDOW )
823         static_cast<Window&>(rTarget).Sync();
824 
825     fprintf( stdout,
826              "Duration: %d ms (%d repetitions)\tOperation: %s\tSetup: %s\n",
827              (int)(osl_getGlobalTimer() - nStartTime),
828              (int)(nTurns),
829              iter->first,
830              pMsg );
831 }
832 
833 //----------------------------------------------------------------------------------
834 
835 /** Call OutputDevice render methods repeatedly, and output elapsed
836     time to stdout
837  */
838 void outDevGrind( OutputDevice& rTarget, sal_Int32 nTurns=100 )
839 {
840     // TODO(F1): also profile pure complex clip setup times!
841 
842     // State: fill/line color, draw mode, w/o clip, rect clip, complex clip
843     functor_vector_type aMethods;
844     setupMethodStubs( aMethods );
845 
846     const Rectangle aClipRect(10,10,1000,1000);
847     const Polygon   aPoly1( aClipRect );
848     Polygon         aPoly2( aClipRect );
849     aPoly2.Rotate(aClipRect.Center(),450);
850     PolyPolygon     aClipPoly(aPoly1);
851     aClipPoly.Insert(aPoly2);
852 
853     functor_vector_type::const_iterator       iter = aMethods.begin();
854     const functor_vector_type::const_iterator end  = aMethods.end();
855     while( iter != end )
856     {
857         rTarget.SetLineColor( Color(COL_BLACK) );
858         rTarget.SetFillColor( Color(COL_GREEN) );
859         rTarget.SetRasterOp( ROP_OVERPAINT );
860         rTarget.SetClipRegion();
861         grindFunc( rTarget, iter, nTurns, "w/o clip, w/o xor" );
862 
863         rTarget.SetLineColor( Color(COL_BLACK) );
864         rTarget.SetFillColor( Color(COL_GREEN) );
865         rTarget.SetRasterOp( ROP_OVERPAINT );
866         rTarget.SetClipRegion( aClipRect );
867         grindFunc( rTarget, iter, nTurns, "with rect clip, w/o xor" );
868 
869         rTarget.SetLineColor( Color(COL_BLACK) );
870         rTarget.SetFillColor( Color(COL_GREEN) );
871         rTarget.SetRasterOp( ROP_OVERPAINT );
872         rTarget.SetClipRegion( aClipPoly );
873         grindFunc( rTarget, iter, nTurns, "with complex clip, w/o xor" );
874 
875         rTarget.SetLineColor( Color(COL_BLACK) );
876         rTarget.SetFillColor( Color(COL_GREEN) );
877         rTarget.SetRasterOp( ROP_XOR );
878         rTarget.SetClipRegion();
879         grindFunc( rTarget, iter, nTurns, "w/o clip, with xor" );
880 
881         rTarget.SetLineColor( Color(COL_BLACK) );
882         rTarget.SetFillColor( Color(COL_GREEN) );
883         rTarget.SetRasterOp( ROP_XOR );
884         rTarget.SetClipRegion( aClipRect );
885         grindFunc( rTarget, iter, nTurns, "with rect clip, with xor" );
886 
887         rTarget.SetLineColor( Color(COL_BLACK) );
888         rTarget.SetFillColor( Color(COL_GREEN) );
889         rTarget.SetRasterOp( ROP_XOR );
890         rTarget.SetClipRegion( aClipPoly );
891         grindFunc( rTarget, iter, nTurns, "with complex clip, with xor" );
892 
893         ++iter;
894     }
895 }
896 
897 //----------------------------------------------------------------------------------
898 
899 void TestWindow::Paint( const Rectangle& )
900 {
901     outDevGrind( *this );
902     fflush( stdout );
903 }
904 
905 sal_uInt16 GrindApp::Exception( sal_uInt16 nError )
906 {
907 	switch( nError & EXC_MAJORTYPE )
908 	{
909 		case EXC_RSCNOTLOADED:
910 			Abort( String::CreateFromAscii(
911                        "Error: could not load language resources.\nPlease check your installation.\n" ) );
912 			break;
913 	}
914 	return 0;
915 }
916 
917 void GrindApp::Main()
918 {
919 	bool bHelp = false;
920 
921 	for( sal_uInt16 i = 0; i < GetCommandLineParamCount(); i++ )
922 	{
923 		::rtl::OUString aParam = GetCommandLineParam( i );
924 
925 		if( aParam.equalsAscii( "--help" ) ||
926 			aParam.equalsAscii( "-h" ) )
927 				bHelp = true;
928 	}
929 
930 	if( bHelp )
931 	{
932         printf( "outdevgrind - Profile OutputDevice\n" );
933 		return;
934 	}
935 
936 	//-------------------------------------------------
937 	// create the global service-manager
938 	//-------------------------------------------------
939     uno::Reference< lang::XMultiServiceFactory > xFactory;
940     try
941     {
942         uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
943         xFactory = uno::Reference< lang::XMultiServiceFactory >(  xCtx->getServiceManager(),
944                                                                   uno::UNO_QUERY );
945         if( xFactory.is() )
946             ::comphelper::setProcessServiceFactory( xFactory );
947     }
948     catch( uno::Exception& )
949     {
950     }
951 
952     if( !xFactory.is() )
953     {
954         fprintf( stderr,
955                  "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
956         exit( 1 );
957     }
958 
959     // Create UCB.
960     uno::Sequence< uno::Any > aArgs( 2 );
961 	aArgs[ 0 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL );
962 	aArgs[ 1 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE );
963     ::ucbhelper::ContentBroker::initialize( xFactory, aArgs );
964 
965 	TestWindow pWindow;
966 	pWindow.Execute();
967 
968     // clean up UCB
969 	::ucbhelper::ContentBroker::deinitialize();
970 }
971 
972 } // namespace
973 
974 GrindApp aGrindApp;
975