1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
11 #include <sal/log.hxx>
13 #include <comphelper/processfactory.hxx>
14 #include <cppuhelper/bootstrap.hxx>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/uno/XComponentContext.hpp>
17 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
19 #include <vcl/bitmapex.hxx>
20 #include <vcl/event.hxx>
21 #include <vcl/gradient.hxx>
22 #include <vcl/vclmain.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/wrkwin.hxx>
26 #include <vcl/virdev.hxx>
28 #include <basegfx/numeric/ftools.hxx>
29 #include <comphelper/diagnose_ex.hxx>
34 #include <test/outputdevice.hxx>
38 static void drawBitmapCentered(tools::Rectangle
const& rRect
, const Bitmap
& aBitmap
,
39 vcl::RenderContext
& rRenderContext
)
41 tools::Long nWidth
= rRect
.GetWidth();
42 tools::Long nHeight
= rRect
.GetHeight();
44 Size
aBitmapSize(aBitmap
.GetSizePixel());
46 Point
aPoint(rRect
.TopLeft());
48 aPoint
.AdjustX((nWidth
- aBitmapSize
.Width()) / 2 );
49 aPoint
.AdjustY((nHeight
- aBitmapSize
.Height()) / 2 );
51 rRenderContext
.DrawBitmap(aPoint
, aBitmap
);
54 static void drawBitmapScaledAndCentered(tools::Rectangle
const & rRect
, Bitmap aBitmap
, vcl::RenderContext
& rRenderContext
, BmpScaleFlag aFlag
= BmpScaleFlag::Fast
)
56 tools::Long nWidth
= rRect
.GetWidth();
57 tools::Long nHeight
= rRect
.GetHeight();
59 Size
aBitmapSize(aBitmap
.GetSizePixel());
61 double fWidthHeight
= std::min(nWidth
, nHeight
);
62 double fScale
= fWidthHeight
/ aBitmapSize
.Width();
63 aBitmap
.Scale(fScale
, fScale
, aFlag
);
65 drawBitmapCentered(rRect
, aBitmap
, rRenderContext
);
68 static void drawBackgroundRect(tools::Rectangle
const & rRect
, Color aColor
, vcl::RenderContext
& rRenderContext
)
70 rRenderContext
.Push(vcl::PushFlags::LINECOLOR
| vcl::PushFlags::FILLCOLOR
);
71 rRenderContext
.SetFillColor(aColor
);
72 rRenderContext
.SetLineColor(aColor
);
73 rRenderContext
.DrawRect(rRect
);
77 static void assertAndSetBackground(vcl::test::TestResult eResult
, tools::Rectangle
const & rRect
, vcl::RenderContext
& rRenderContext
)
79 if (eResult
== vcl::test::TestResult::Passed
)
80 drawBackgroundRect(rRect
, COL_GREEN
, rRenderContext
);
81 else if (eResult
== vcl::test::TestResult::PassedWithQuirks
)
82 drawBackgroundRect(rRect
, COL_YELLOW
, rRenderContext
);
83 else if (eResult
== vcl::test::TestResult::Failed
)
84 drawBackgroundRect(rRect
, COL_RED
, rRenderContext
);
89 class VisualBackendTestWindow
: public WorkWindow
93 std::vector
<std::chrono::high_resolution_clock::time_point
> mTimePoints
;
94 static constexpr unsigned char gnNumberOfTests
= 12;
97 ScopedVclPtr
<VirtualDevice
> mpVDev
;
100 VisualBackendTestWindow()
101 : WorkWindow(nullptr, WB_APP
| WB_STDWORK
)
102 , maUpdateTimer("VisualBackendTestWindow maUpdateTimer")
103 , mnTest(10 * gnNumberOfTests
)
104 , mbAnimate(mnTest
% gnNumberOfTests
== gnNumberOfTests
- 1)
105 , mpVDev(VclPtr
<VirtualDevice
>::Create())
107 maUpdateTimer
.SetInvokeHandler(LINK(this, VisualBackendTestWindow
, updateHdl
));
108 maUpdateTimer
.SetPriority(TaskPriority::DEFAULT_IDLE
);
111 maUpdateTimer
.SetTimeout(1000.0);
112 maUpdateTimer
.Start();
116 virtual ~VisualBackendTestWindow() override
121 DECL_LINK(updateHdl
, Timer
*, void);
123 virtual void KeyInput(const KeyEvent
& rKEvt
) override
125 sal_uInt16 nCode
= rKEvt
.GetKeyCode().GetCode();
127 if (nCode
== KEY_BACKSPACE
)
129 else if(nCode
== KEY_SPACE
)
132 if (nCode
!= KEY_BACKSPACE
&& nCode
!= KEY_SPACE
)
135 if (mnTest
% gnNumberOfTests
== gnNumberOfTests
- 1)
138 maUpdateTimer
.Start();
147 static std::vector
<tools::Rectangle
> setupRegions(int nPartitionsX
, int nPartitionsY
, int nWidth
, int nHeight
)
149 std::vector
<tools::Rectangle
> aRegions
;
151 for (int y
= 0; y
< nPartitionsY
; y
++)
153 for (int x
= 0; x
< nPartitionsX
; x
++)
155 tools::Long x1
= x
* (nWidth
/ nPartitionsX
);
156 tools::Long y1
= y
* (nHeight
/ nPartitionsY
);
157 tools::Long x2
= (x
+1) * (nWidth
/ nPartitionsX
);
158 tools::Long y2
= (y
+1) * (nHeight
/ nPartitionsY
);
160 aRegions
.emplace_back(x1
+ 1, y1
+ 1, x2
- 6, y2
- 2);
166 static void testRectangles(vcl::RenderContext
& rRenderContext
, int nWidth
, int nHeight
, bool AA
)
168 tools::Rectangle aRectangle
;
171 std::vector
<tools::Rectangle
> aRegions
= setupRegions(4, 2, nWidth
, nHeight
);
173 aRectangle
= aRegions
[index
++];
175 vcl::test::OutputDeviceTestRect aOutDevTest
;
176 Bitmap aBitmap
= aOutDevTest
.setupRectangle(AA
);
177 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangles(aBitmap
, AA
), aRectangle
, rRenderContext
);
178 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
181 aRectangle
= aRegions
[index
++];
183 vcl::test::OutputDeviceTestPixel aOutDevTest
;
184 Bitmap aBitmap
= aOutDevTest
.setupRectangle(AA
);
185 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangles(aBitmap
, AA
), aRectangle
, rRenderContext
);
186 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
189 aRectangle
= aRegions
[index
++];
191 vcl::test::OutputDeviceTestLine aOutDevTest
;
192 Bitmap aBitmap
= aOutDevTest
.setupRectangle(AA
);
193 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangles(aBitmap
, AA
), aRectangle
, rRenderContext
);
194 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
197 aRectangle
= aRegions
[index
++];
199 vcl::test::OutputDeviceTestPolygon aOutDevTest
;
200 Bitmap aBitmap
= aOutDevTest
.setupRectangle(AA
);
201 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangles(aBitmap
, AA
), aRectangle
, rRenderContext
);
202 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
205 aRectangle
= aRegions
[index
++];
207 vcl::test::OutputDeviceTestPolyLine aOutDevTest
;
208 Bitmap aBitmap
= aOutDevTest
.setupRectangle(AA
);
209 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangles(aBitmap
, AA
), aRectangle
, rRenderContext
);
210 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
213 aRectangle
= aRegions
[index
++];
215 vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest
;
216 Bitmap aBitmap
= aOutDevTest
.setupRectangle(AA
);
217 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangles(aBitmap
, AA
), aRectangle
, rRenderContext
);
218 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
221 aRectangle
= aRegions
[index
++];
223 vcl::test::OutputDeviceTestPolyPolygon aOutDevTest
;
224 Bitmap aBitmap
= aOutDevTest
.setupRectangle(AA
);
225 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangles(aBitmap
, AA
), aRectangle
, rRenderContext
);
226 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
229 aRectangle
= aRegions
[index
++];
231 vcl::test::OutputDeviceTestPolyPolygonB2D aOutDevTest
;
232 Bitmap aBitmap
= aOutDevTest
.setupRectangle(AA
);
233 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangles(aBitmap
, AA
), aRectangle
, rRenderContext
);
234 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
238 static void testFilledRectangles(vcl::RenderContext
& rRenderContext
, int nWidth
, int nHeight
)
240 tools::Rectangle aRectangle
;
243 std::vector
<tools::Rectangle
> aRegions
= setupRegions(4, 2, nWidth
, nHeight
);
245 aRectangle
= aRegions
[index
++];
247 vcl::test::OutputDeviceTestRect aOutDevTest
;
248 Bitmap aBitmap
= aOutDevTest
.setupFilledRectangle(false);
249 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap
, false), aRectangle
, rRenderContext
);
250 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
253 aRectangle
= aRegions
[index
++];
255 vcl::test::OutputDeviceTestPolygon aOutDevTest
;
256 Bitmap aBitmap
= aOutDevTest
.setupFilledRectangle(false);
257 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap
, false), aRectangle
, rRenderContext
);
258 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
261 aRectangle
= aRegions
[index
++];
263 vcl::test::OutputDeviceTestPolyPolygon aOutDevTest
;
264 Bitmap aBitmap
= aOutDevTest
.setupFilledRectangle(false);
265 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap
, false), aRectangle
, rRenderContext
);
266 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
269 aRectangle
= aRegions
[index
++];
271 vcl::test::OutputDeviceTestPolyPolygonB2D aOutDevTest
;
272 Bitmap aBitmap
= aOutDevTest
.setupFilledRectangle(false);
273 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap
, false), aRectangle
, rRenderContext
);
274 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
277 aRectangle
= aRegions
[index
++];
279 vcl::test::OutputDeviceTestRect aOutDevTest
;
280 Bitmap aBitmap
= aOutDevTest
.setupFilledRectangle(true);
281 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap
, true), aRectangle
, rRenderContext
);
282 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
285 aRectangle
= aRegions
[index
++];
287 vcl::test::OutputDeviceTestPolygon aOutDevTest
;
288 Bitmap aBitmap
= aOutDevTest
.setupFilledRectangle(true);
289 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap
, true), aRectangle
, rRenderContext
);
290 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
293 aRectangle
= aRegions
[index
++];
295 vcl::test::OutputDeviceTestPolyPolygon aOutDevTest
;
296 Bitmap aBitmap
= aOutDevTest
.setupFilledRectangle(true);
297 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap
, true), aRectangle
, rRenderContext
);
298 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
301 aRectangle
= aRegions
[index
++];
303 vcl::test::OutputDeviceTestPolyPolygonB2D aOutDevTest
;
304 Bitmap aBitmap
= aOutDevTest
.setupFilledRectangle(true);
305 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap
, true), aRectangle
, rRenderContext
);
306 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
310 static void testDiamondsAndBezier(vcl::RenderContext
& rRenderContext
, int nWidth
, int nHeight
)
312 tools::Rectangle aRectangle
;
315 std::vector
<tools::Rectangle
> aRegions
= setupRegions(3, 2, nWidth
, nHeight
);
317 aRectangle
= aRegions
[index
++];
319 vcl::test::OutputDeviceTestPolygon aOutDevTest
;
320 Bitmap aBitmap
= aOutDevTest
.setupDiamond();
321 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkDiamond(aBitmap
), aRectangle
, rRenderContext
);
322 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
324 aRectangle
= aRegions
[index
++];
326 vcl::test::OutputDeviceTestLine aOutDevTest
;
327 Bitmap aBitmap
= aOutDevTest
.setupDiamond();
328 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkDiamond(aBitmap
), aRectangle
, rRenderContext
);
329 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
331 aRectangle
= aRegions
[index
++];
333 vcl::test::OutputDeviceTestPolyLine aOutDevTest
;
334 Bitmap aBitmap
= aOutDevTest
.setupDiamond();
335 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkDiamond(aBitmap
), aRectangle
, rRenderContext
);
336 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
338 aRectangle
= aRegions
[index
++];
340 vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest
;
341 Bitmap aBitmap
= aOutDevTest
.setupDiamond();
342 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkDiamond(aBitmap
), aRectangle
, rRenderContext
);
343 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
346 aRectangle
= aRegions
[index
++];
348 vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest
;
349 Bitmap aBitmap
= aOutDevTest
.setupOpenBezier();
350 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkOpenBezier(aBitmap
), aRectangle
, rRenderContext
);
351 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
353 aRectangle
= aRegions
[index
++];
355 vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest
;
356 Bitmap aBitmap
= aOutDevTest
.setupAABezier();
357 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkBezier(aBitmap
), aRectangle
, rRenderContext
);
358 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
362 static void testLines(vcl::RenderContext
& rRenderContext
, int nWidth
, int nHeight
)
364 tools::Rectangle aRectangle
;
367 std::vector
<tools::Rectangle
> aRegions
= setupRegions(3, 2, nWidth
, nHeight
);
369 aRectangle
= aRegions
[index
++];
371 vcl::test::OutputDeviceTestLine aOutDevTest
;
372 Bitmap aBitmap
= aOutDevTest
.setupLines();
373 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkLines(aBitmap
), aRectangle
, rRenderContext
);
374 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
376 aRectangle
= aRegions
[index
++];
378 vcl::test::OutputDeviceTestPolyLine aOutDevTest
;
379 Bitmap aBitmap
= aOutDevTest
.setupLines();
380 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkLines(aBitmap
), aRectangle
, rRenderContext
);
381 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
383 aRectangle
= aRegions
[index
++];
385 vcl::test::OutputDeviceTestPolygon aOutDevTest
;
386 Bitmap aBitmap
= aOutDevTest
.setupLines();
387 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkLines(aBitmap
), aRectangle
, rRenderContext
);
388 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
390 aRectangle
= aRegions
[index
++];
392 vcl::test::OutputDeviceTestLine aOutDevTest
;
393 Bitmap aBitmap
= aOutDevTest
.setupAALines();
394 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkAALines(aBitmap
), aRectangle
, rRenderContext
);
395 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
397 aRectangle
= aRegions
[index
++];
399 vcl::test::OutputDeviceTestPolyLine aOutDevTest
;
400 Bitmap aBitmap
= aOutDevTest
.setupAALines();
401 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkAALines(aBitmap
), aRectangle
, rRenderContext
);
402 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
404 aRectangle
= aRegions
[index
++];
406 vcl::test::OutputDeviceTestPolygon aOutDevTest
;
407 Bitmap aBitmap
= aOutDevTest
.setupAALines();
408 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkAALines(aBitmap
), aRectangle
, rRenderContext
);
409 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
413 static void testLineTypes(vcl::RenderContext
& rRenderContext
, int nWidth
, int nHeight
)
415 tools::Rectangle aRectangle
;
418 std::vector
<tools::Rectangle
> aRegions
= setupRegions(4, 2, nWidth
, nHeight
);
420 aRectangle
= aRegions
[index
++];
422 vcl::test::OutputDeviceTestLine aOutDevTest
;
423 Bitmap aBitmap
= aOutDevTest
.setupLineJoinBevel();
424 assertAndSetBackground(vcl::test::OutputDeviceTestLine::checkLineJoinBevel(aBitmap
), aRectangle
, rRenderContext
);
425 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
427 aRectangle
= aRegions
[index
++];
429 vcl::test::OutputDeviceTestLine aOutDevTest
;
430 Bitmap aBitmap
= aOutDevTest
.setupLineJoinRound();
431 assertAndSetBackground(vcl::test::OutputDeviceTestLine::checkLineJoinRound(aBitmap
), aRectangle
, rRenderContext
);
432 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
434 aRectangle
= aRegions
[index
++];
436 vcl::test::OutputDeviceTestLine aOutDevTest
;
437 Bitmap aBitmap
= aOutDevTest
.setupLineJoinMiter();
438 assertAndSetBackground(vcl::test::OutputDeviceTestLine::checkLineJoinMiter(aBitmap
), aRectangle
, rRenderContext
);
439 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
441 aRectangle
= aRegions
[index
++];
443 vcl::test::OutputDeviceTestLine aOutDevTest
;
444 Bitmap aBitmap
= aOutDevTest
.setupLineJoinNone();
445 assertAndSetBackground(vcl::test::OutputDeviceTestLine::checkLineJoinNone(aBitmap
), aRectangle
, rRenderContext
);
446 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
448 aRectangle
= aRegions
[index
++];
450 vcl::test::OutputDeviceTestLine aOutDevTest
;
451 Bitmap aBitmap
= aOutDevTest
.setupLineCapRound();
452 assertAndSetBackground(vcl::test::OutputDeviceTestLine::checkLineCapRound(aBitmap
), aRectangle
, rRenderContext
);
453 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
455 aRectangle
= aRegions
[index
++];
457 vcl::test::OutputDeviceTestLine aOutDevTest
;
458 Bitmap aBitmap
= aOutDevTest
.setupLineCapSquare();
459 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkLineCapSquare(aBitmap
), aRectangle
, rRenderContext
);
460 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
462 aRectangle
= aRegions
[index
++];
464 vcl::test::OutputDeviceTestLine aOutDevTest
;
465 Bitmap aBitmap
= aOutDevTest
.setupLineCapButt();
466 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkLineCapButt(aBitmap
), aRectangle
, rRenderContext
);
467 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
471 static void testBitmaps(vcl::RenderContext
& rRenderContext
, int nWidth
, int nHeight
)
473 tools::Rectangle aRectangle
;
476 std::vector
<tools::Rectangle
> aRegions
= setupRegions(3, 2, nWidth
, nHeight
);
478 aRectangle
= aRegions
[index
++];
480 vcl::test::OutputDeviceTestBitmap aOutDevTest
;
481 Bitmap aBitmap
= aOutDevTest
.setupDrawBitmap(vcl::PixelFormat::N24_BPP
);
482 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkTransformedBitmap(aBitmap
), aRectangle
, rRenderContext
);
483 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
485 aRectangle
= aRegions
[index
++];
487 vcl::test::OutputDeviceTestBitmap aOutDevTest
;
488 Bitmap aBitmap
= aOutDevTest
.setupDrawTransformedBitmap(vcl::PixelFormat::N24_BPP
);
489 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkTransformedBitmap(aBitmap
), aRectangle
, rRenderContext
);
490 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
492 aRectangle
= aRegions
[index
++];
494 vcl::test::OutputDeviceTestBitmap aOutDevTest
;
495 Bitmap aBitmap
= aOutDevTest
.setupComplexDrawTransformedBitmap(vcl::PixelFormat::N24_BPP
);
496 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkComplexTransformedBitmap(aBitmap
), aRectangle
, rRenderContext
);
497 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
499 aRectangle
= aRegions
[index
++];
501 vcl::test::OutputDeviceTestBitmap aOutDevTest
;
502 Bitmap aBitmap
= aOutDevTest
.setupDrawBitmapExWithAlpha(vcl::PixelFormat::N24_BPP
);
503 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkBitmapExWithAlpha(aBitmap
), aRectangle
, rRenderContext
);
504 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
506 aRectangle
= aRegions
[index
++];
508 vcl::test::OutputDeviceTestBitmap aOutDevTest
;
509 Bitmap aBitmap
= aOutDevTest
.setupDrawMask(vcl::PixelFormat::N24_BPP
);
510 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkMask(aBitmap
), aRectangle
, rRenderContext
);
511 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
513 aRectangle
= aRegions
[index
++];
515 vcl::test::OutputDeviceTestBitmap aOutDevTest
;
516 BitmapEx aBitmap
= aOutDevTest
.setupDrawBlend(vcl::PixelFormat::N24_BPP
);
517 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkBlend(aBitmap
), aRectangle
, rRenderContext
);
518 drawBitmapScaledAndCentered(aRectangle
, aBitmap
.GetBitmap(), rRenderContext
);
522 static void testInvert(vcl::RenderContext
& rRenderContext
, int nWidth
, int nHeight
)
524 tools::Rectangle aRectangle
;
527 std::vector
<tools::Rectangle
> aRegions
= setupRegions(2, 2, nWidth
, nHeight
);
529 aRectangle
= aRegions
[index
++];
531 vcl::test::OutputDeviceTestRect aOutDevTest
;
532 Bitmap aBitmap
= aOutDevTest
.setupInvert_NONE();
533 assertAndSetBackground(vcl::test::OutputDeviceTestRect::checkInvertRectangle(aBitmap
), aRectangle
, rRenderContext
);
534 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
536 aRectangle
= aRegions
[index
++];
538 vcl::test::OutputDeviceTestRect aOutDevTest
;
539 Bitmap aBitmap
= aOutDevTest
.setupInvert_N50();
540 assertAndSetBackground(vcl::test::OutputDeviceTestRect::checkInvertN50Rectangle(aBitmap
), aRectangle
, rRenderContext
);
541 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
543 aRectangle
= aRegions
[index
++];
545 vcl::test::OutputDeviceTestRect aOutDevTest
;
546 Bitmap aBitmap
= aOutDevTest
.setupInvert_TrackFrame();
547 assertAndSetBackground(vcl::test::OutputDeviceTestRect::checkInvertTrackFrameRectangle(aBitmap
), aRectangle
, rRenderContext
);
548 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
550 aRectangle
= aRegions
[index
++];
552 vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest
;
553 Bitmap aBitmap
= aOutDevTest
.setupXOR();
554 assertAndSetBackground(vcl::test::OutputDeviceTestAnotherOutDev::checkXOR(aBitmap
), aRectangle
, rRenderContext
);
555 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
559 static void testClip(vcl::RenderContext
& rRenderContext
, int nWidth
, int nHeight
)
561 tools::Rectangle aRectangle
;
564 std::vector
<tools::Rectangle
> aRegions
= setupRegions(2, 2, nWidth
, nHeight
);
566 aRectangle
= aRegions
[index
++];
568 vcl::test::OutputDeviceTestClip aOutDevTest
;
569 Bitmap aBitmap
= aOutDevTest
.setupClipRectangle();
570 assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap
), aRectangle
, rRenderContext
);
571 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
573 aRectangle
= aRegions
[index
++];
575 vcl::test::OutputDeviceTestClip aOutDevTest
;
576 Bitmap aBitmap
= aOutDevTest
.setupClipPolygon();
577 assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap
), aRectangle
, rRenderContext
);
578 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
580 aRectangle
= aRegions
[index
++];
582 vcl::test::OutputDeviceTestClip aOutDevTest
;
583 Bitmap aBitmap
= aOutDevTest
.setupClipPolyPolygon();
584 assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap
), aRectangle
, rRenderContext
);
585 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
587 aRectangle
= aRegions
[index
++];
589 vcl::test::OutputDeviceTestClip aOutDevTest
;
590 Bitmap aBitmap
= aOutDevTest
.setupClipB2DPolyPolygon();
591 assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap
), aRectangle
, rRenderContext
);
592 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
596 static void testGradients(vcl::RenderContext
& rRenderContext
, int nWidth
, int nHeight
)
598 tools::Rectangle aRectangle
;
601 std::vector
<tools::Rectangle
> aRegions
= setupRegions(4, 2, nWidth
, nHeight
);
603 aRectangle
= aRegions
[index
++];
605 vcl::test::OutputDeviceTestGradient aOutDevTest
;
606 Bitmap aBitmap
= aOutDevTest
.setupLinearGradient();
607 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradient(aBitmap
), aRectangle
, rRenderContext
);
608 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
610 aRectangle
= aRegions
[index
++];
612 vcl::test::OutputDeviceTestGradient aOutDevTest
;
613 Bitmap aBitmap
= aOutDevTest
.setupLinearGradientAngled();
614 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradientAngled(aBitmap
), aRectangle
, rRenderContext
);
615 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
617 aRectangle
= aRegions
[index
++];
619 vcl::test::OutputDeviceTestGradient aOutDevTest
;
620 Bitmap aBitmap
= aOutDevTest
.setupLinearGradientBorder();
621 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradientBorder(aBitmap
), aRectangle
, rRenderContext
);
622 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
624 aRectangle
= aRegions
[index
++];
626 vcl::test::OutputDeviceTestGradient aOutDevTest
;
627 Bitmap aBitmap
= aOutDevTest
.setupLinearGradientIntensity();
628 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradientIntensity(aBitmap
), aRectangle
, rRenderContext
);
629 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
631 aRectangle
= aRegions
[index
++];
633 vcl::test::OutputDeviceTestGradient aOutDevTest
;
634 Bitmap aBitmap
= aOutDevTest
.setupLinearGradientSteps();
635 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradientSteps(aBitmap
), aRectangle
, rRenderContext
);
636 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
638 aRectangle
= aRegions
[index
++];
640 vcl::test::OutputDeviceTestGradient aOutDevTest
;
641 Bitmap aBitmap
= aOutDevTest
.setupAxialGradient();
642 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkAxialGradient(aBitmap
), aRectangle
, rRenderContext
);
643 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
645 aRectangle
= aRegions
[index
++];
647 vcl::test::OutputDeviceTestGradient aOutDevTest
;
648 Bitmap aBitmap
= aOutDevTest
.setupRadialGradient();
649 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkRadialGradient(aBitmap
), aRectangle
, rRenderContext
);
650 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
652 aRectangle
= aRegions
[index
++];
654 vcl::test::OutputDeviceTestGradient aOutDevTest
;
655 Bitmap aBitmap
= aOutDevTest
.setupRadialGradientOfs();
656 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkRadialGradientOfs(aBitmap
), aRectangle
, rRenderContext
);
657 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
661 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& /*rRect*/) override
663 if (mnTest
% gnNumberOfTests
== gnNumberOfTests
- 1)
665 rRenderContext
.SetBackground(Wallpaper(COL_GREEN
));
667 static size_t nTimeIndex
= 0;
668 static const size_t constSamplesFPS
= 120;
671 if (mTimePoints
.size() < constSamplesFPS
)
673 mTimePoints
.push_back(std::chrono::high_resolution_clock::now());
678 size_t current
= nTimeIndex
% constSamplesFPS
;
679 mTimePoints
[current
] = std::chrono::high_resolution_clock::now();
680 size_t last
= (nTimeIndex
+ 1) % constSamplesFPS
;
681 auto ms
= std::chrono::duration_cast
<std::chrono::milliseconds
>(mTimePoints
[current
] - mTimePoints
[last
]).count();
682 fps
= constSamplesFPS
* 1000.0 / ms
;
686 double fTime
= 0.5 + std::sin(nTimeIndex
/ 100.0) / 2.0;
688 Size aSizePixel
= GetSizePixel();
690 mpVDev
->SetAntialiasing(AntialiasingFlags::Enable
| AntialiasingFlags::PixelSnapHairline
);
691 mpVDev
->SetOutputSizePixel(aSizePixel
);
692 mpVDev
->SetBackground(Wallpaper(COL_LIGHTGRAY
));
694 mpVDev
->SetFillColor(COL_LIGHTRED
);
695 mpVDev
->SetLineColor(COL_LIGHTBLUE
);
697 basegfx::B2DPolyPolygon polyPolygon
;
699 for (int b
=10; b
<14; b
++)
701 basegfx::B2DPolygon polygon
;
702 for (double a
=0.0; a
<360.0; a
+=0.5)
704 double x
= std::sin(basegfx::deg2rad(a
)) * (b
+1) * 20;
705 double y
= std::cos(basegfx::deg2rad(a
)) * (b
+1) * 20;
706 polygon
.append(basegfx::B2DPoint(x
+ 200 + 500 * fTime
, y
+ 200 + 500 * fTime
));
708 polygon
.setClosed(true);
709 polyPolygon
.append(polygon
);
712 mpVDev
->DrawPolyPolygon(polyPolygon
);
714 tools::Rectangle
aGradientRect(Point(200, 200), Size(200 + fTime
* 300, 200 + fTime
* 300));
715 mpVDev
->DrawGradient(aGradientRect
, Gradient(css::awt::GradientStyle_LINEAR
, COL_YELLOW
, COL_BLUE
));
717 rRenderContext
.DrawOutDev(Point(), mpVDev
->GetOutputSizePixel(),
718 Point(), mpVDev
->GetOutputSizePixel(),
720 rRenderContext
.SetTextColor(COL_LIGHTRED
);
721 rRenderContext
.DrawText(Point(10, 10), "FPS: " + OUString::number(int(fps
)));
725 rRenderContext
.SetBackground(Wallpaper(COL_GREEN
));
727 Size aSize
= GetOutputSizePixel();
729 tools::Long nWidth
= aSize
.Width();
730 tools::Long nHeight
= aSize
.Height();
732 if (mnTest
% gnNumberOfTests
== 0)
734 testRectangles(rRenderContext
, nWidth
, nHeight
, false);
736 else if (mnTest
% gnNumberOfTests
== 1)
738 testRectangles(rRenderContext
, nWidth
, nHeight
, true);
740 else if (mnTest
% gnNumberOfTests
== 2)
742 testFilledRectangles(rRenderContext
, nWidth
, nHeight
);
744 else if (mnTest
% gnNumberOfTests
== 3)
746 testDiamondsAndBezier(rRenderContext
, nWidth
, nHeight
);
748 else if (mnTest
% gnNumberOfTests
== 4)
750 testLines(rRenderContext
, nWidth
, nHeight
);
752 else if (mnTest
% gnNumberOfTests
== 5)
754 testLineTypes(rRenderContext
, nWidth
, nHeight
);
756 else if (mnTest
% gnNumberOfTests
== 6)
758 testBitmaps(rRenderContext
, nWidth
, nHeight
);
760 else if (mnTest
% gnNumberOfTests
== 7)
762 testInvert(rRenderContext
, nWidth
, nHeight
);
764 else if (mnTest
% gnNumberOfTests
== 8)
766 testClip(rRenderContext
, nWidth
, nHeight
);
768 else if (mnTest
% gnNumberOfTests
== 9)
770 testGradients(rRenderContext
, nWidth
, nHeight
);
772 else if (mnTest
% gnNumberOfTests
== 10)
774 std::vector
<tools::Rectangle
> aRegions
= setupRegions(2, 2, nWidth
, nHeight
);
777 tools::Rectangle aRectangle
= aRegions
[index
++];
779 vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest
;
780 Bitmap aBitmap
= aOutDevTest
.setupDrawOutDev();
781 assertAndSetBackground(vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDev(aBitmap
), aRectangle
, rRenderContext
);
782 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
784 aRectangle
= aRegions
[index
++];
786 vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest
;
787 Bitmap aBitmap
= aOutDevTest
.setupDrawOutDevScaledClipped();
788 assertAndSetBackground(vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDevScaledClipped(aBitmap
), aRectangle
, rRenderContext
);
789 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
791 aRectangle
= aRegions
[index
++];
793 vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest
;
794 Bitmap aBitmap
= aOutDevTest
.setupDrawOutDevSelf();
795 assertAndSetBackground(vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDevSelf(aBitmap
), aRectangle
, rRenderContext
);
796 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
798 aRectangle
= aRegions
[index
++];
800 vcl::test::OutputDeviceTestLine aOutDevTest
;
801 Bitmap aBitmap
= aOutDevTest
.setupDashedLine();
802 assertAndSetBackground(vcl::test::OutputDeviceTestLine::checkDashedLine(aBitmap
), aRectangle
, rRenderContext
);
803 drawBitmapScaledAndCentered(aRectangle
, aBitmap
, rRenderContext
);
811 IMPL_LINK_NOARG(VisualBackendTestWindow
, updateHdl
, Timer
*, void)
815 maUpdateTimer
.SetTimeout(1.0);
816 maUpdateTimer
.Start();
823 class VisualBackendTestApp
: public Application
827 VisualBackendTestApp()
830 virtual int Main() override
834 ScopedVclPtrInstance
<VisualBackendTestWindow
> aMainWindow
;
836 aMainWindow
->SetText("VCL Test");
839 Application::Execute();
841 catch (const css::uno::Exception
&)
843 DBG_UNHANDLED_EXCEPTION("vcl.app", "Fatal");
846 catch (const std::exception
& rException
)
848 SAL_WARN("vcl.app", "Fatal exception: " << rException
.what());
859 uno::Reference
<uno::XComponentContext
> xComponentContext
= ::cppu::defaultBootstrap_InitialComponentContext();
860 uno::Reference
<lang::XMultiServiceFactory
> xMSF(xComponentContext
->getServiceManager(), uno::UNO_QUERY
);
863 Application::Abort("Bootstrap failure - no service manager");
865 comphelper::setProcessServiceFactory(xMSF
);
867 catch (const uno::Exception
&e
)
869 Application::Abort("Bootstrap exception " + e
.Message
);
873 void DeInit() override
875 comphelper::setProcessServiceFactory(nullptr);
881 void vclmain::createApplication()
883 static VisualBackendTestApp aApplication
;
886 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */