nss: upgrade to release 3.73
[LibreOffice.git] / vcl / backendtest / VisualBackendTest.cxx
blob5f7a7517a8d03ac7bd54a1f0921962470cd42263
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/.
8 */
10 #include <math.h>
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/event.hxx>
20 #include <vcl/gradient.hxx>
21 #include <vcl/vclmain.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/wrkwin.hxx>
25 #include <vcl/virdev.hxx>
27 #include <basegfx/numeric/ftools.hxx>
28 #include <tools/diagnose_ex.h>
30 #include <chrono>
31 #include <iostream>
33 #include <test/outputdevice.hxx>
35 using namespace css;
37 static void drawBitmapCentered(tools::Rectangle const& rRect, const Bitmap& aBitmap,
38 vcl::RenderContext& rRenderContext)
40 tools::Long nWidth = rRect.GetWidth();
41 tools::Long nHeight = rRect.GetHeight();
43 Size aBitmapSize(aBitmap.GetSizePixel());
45 Point aPoint(rRect.TopLeft());
47 aPoint.AdjustX((nWidth - aBitmapSize.Width()) / 2 );
48 aPoint.AdjustY((nHeight - aBitmapSize.Height()) / 2 );
50 rRenderContext.DrawBitmap(aPoint, aBitmap);
53 static void drawBitmapScaledAndCentered(tools::Rectangle const & rRect, Bitmap aBitmap, vcl::RenderContext& rRenderContext, BmpScaleFlag aFlag = BmpScaleFlag::Fast)
55 tools::Long nWidth = rRect.GetWidth();
56 tools::Long nHeight = rRect.GetHeight();
58 Size aBitmapSize(aBitmap.GetSizePixel());
60 double fWidthHeight = std::min(nWidth, nHeight);
61 double fScale = fWidthHeight / aBitmapSize.Width();
62 aBitmap.Scale(fScale, fScale, aFlag);
64 drawBitmapCentered(rRect, aBitmap, rRenderContext);
67 static void drawBackgroundRect(tools::Rectangle const & rRect, Color aColor, vcl::RenderContext& rRenderContext)
69 rRenderContext.Push(PushFlags::LINECOLOR | PushFlags::FILLCOLOR);
70 rRenderContext.SetFillColor(aColor);
71 rRenderContext.SetLineColor(aColor);
72 rRenderContext.DrawRect(rRect);
73 rRenderContext.Pop();
76 static void assertAndSetBackground(vcl::test::TestResult eResult, tools::Rectangle const & rRect, vcl::RenderContext& rRenderContext)
78 if (eResult == vcl::test::TestResult::Passed)
79 drawBackgroundRect(rRect, COL_GREEN, rRenderContext);
80 else if (eResult == vcl::test::TestResult::PassedWithQuirks)
81 drawBackgroundRect(rRect, COL_YELLOW, rRenderContext);
82 else if (eResult == vcl::test::TestResult::Failed)
83 drawBackgroundRect(rRect, COL_RED, rRenderContext);
86 namespace {
88 class VisualBackendTestWindow : public WorkWindow
90 private:
91 Timer maUpdateTimer;
92 std::vector<std::chrono::high_resolution_clock::time_point> mTimePoints;
93 static constexpr unsigned char gnNumberOfTests = 11;
94 unsigned char mnTest;
95 bool mbAnimate;
96 ScopedVclPtr<VirtualDevice> mpVDev;
98 public:
99 VisualBackendTestWindow()
100 : WorkWindow(nullptr, WB_APP | WB_STDWORK)
101 , mnTest(10 * gnNumberOfTests)
102 , mbAnimate(mnTest % gnNumberOfTests == gnNumberOfTests - 1)
103 , mpVDev(VclPtr<VirtualDevice>::Create())
105 maUpdateTimer.SetInvokeHandler(LINK(this, VisualBackendTestWindow, updateHdl));
106 maUpdateTimer.SetPriority(TaskPriority::DEFAULT_IDLE);
107 if (mbAnimate)
109 maUpdateTimer.SetTimeout(1000.0);
110 maUpdateTimer.Start();
114 virtual ~VisualBackendTestWindow() override
116 disposeOnce();
119 DECL_LINK(updateHdl, Timer*, void);
121 virtual void KeyInput(const KeyEvent& rKEvt) override
123 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
125 if (nCode == KEY_BACKSPACE)
126 mnTest--;
127 else if(nCode == KEY_SPACE)
128 mnTest++;
130 if (nCode != KEY_BACKSPACE && nCode != KEY_SPACE)
131 return;
133 if (mnTest % gnNumberOfTests == gnNumberOfTests - 1)
135 mbAnimate = true;
136 maUpdateTimer.Start();
138 else
140 mbAnimate = false;
141 Invalidate();
145 static std::vector<tools::Rectangle> setupRegions(int nPartitionsX, int nPartitionsY, int nWidth, int nHeight)
147 std::vector<tools::Rectangle> aRegions;
149 for (int y = 0; y < nPartitionsY; y++)
151 for (int x = 0; x < nPartitionsX; x++)
153 tools::Long x1 = x * (nWidth / nPartitionsX);
154 tools::Long y1 = y * (nHeight / nPartitionsY);
155 tools::Long x2 = (x+1) * (nWidth / nPartitionsX);
156 tools::Long y2 = (y+1) * (nHeight / nPartitionsY);
158 aRegions.emplace_back(x1 + 1, y1 + 1, x2 - 6, y2 - 2);
161 return aRegions;
164 static void testRectangles(vcl::RenderContext& rRenderContext, int nWidth, int nHeight, bool AA)
166 tools::Rectangle aRectangle;
167 size_t index = 0;
169 std::vector<tools::Rectangle> aRegions = setupRegions(4, 2, nWidth, nHeight);
171 aRectangle = aRegions[index++];
173 vcl::test::OutputDeviceTestRect aOutDevTest;
174 Bitmap aBitmap = aOutDevTest.setupRectangle(AA);
175 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangle(aBitmap), aRectangle, rRenderContext);
176 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
179 aRectangle = aRegions[index++];
181 vcl::test::OutputDeviceTestPixel aOutDevTest;
182 Bitmap aBitmap = aOutDevTest.setupRectangle(AA);
183 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangle(aBitmap), aRectangle, rRenderContext);
184 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
187 aRectangle = aRegions[index++];
189 vcl::test::OutputDeviceTestLine aOutDevTest;
190 Bitmap aBitmap = aOutDevTest.setupRectangle(AA);
191 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangle(aBitmap), aRectangle, rRenderContext);
192 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
195 aRectangle = aRegions[index++];
197 vcl::test::OutputDeviceTestPolygon aOutDevTest;
198 Bitmap aBitmap = aOutDevTest.setupRectangle(AA);
199 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangle(aBitmap), aRectangle, rRenderContext);
200 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
203 aRectangle = aRegions[index++];
205 vcl::test::OutputDeviceTestPolyLine aOutDevTest;
206 Bitmap aBitmap = aOutDevTest.setupRectangle(AA);
207 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangle(aBitmap), aRectangle, rRenderContext);
208 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
211 aRectangle = aRegions[index++];
213 vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest;
214 Bitmap aBitmap = aOutDevTest.setupRectangle(AA);
215 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangle(aBitmap), aRectangle, rRenderContext);
216 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
219 aRectangle = aRegions[index++];
221 vcl::test::OutputDeviceTestPolyPolygon aOutDevTest;
222 Bitmap aBitmap = aOutDevTest.setupRectangle(AA);
223 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangle(aBitmap), aRectangle, rRenderContext);
224 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
227 aRectangle = aRegions[index++];
229 vcl::test::OutputDeviceTestPolyPolygonB2D aOutDevTest;
230 Bitmap aBitmap = aOutDevTest.setupRectangle(AA);
231 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkRectangle(aBitmap), aRectangle, rRenderContext);
232 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
236 static void testFilledRectangles(vcl::RenderContext& rRenderContext, int nWidth, int nHeight)
238 tools::Rectangle aRectangle;
239 size_t index = 0;
241 std::vector<tools::Rectangle> aRegions = setupRegions(4, 2, nWidth, nHeight);
243 aRectangle = aRegions[index++];
245 vcl::test::OutputDeviceTestRect aOutDevTest;
246 Bitmap aBitmap = aOutDevTest.setupFilledRectangle(false);
247 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, false), aRectangle, rRenderContext);
248 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
251 aRectangle = aRegions[index++];
253 vcl::test::OutputDeviceTestPolygon aOutDevTest;
254 Bitmap aBitmap = aOutDevTest.setupFilledRectangle(false);
255 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, false), aRectangle, rRenderContext);
256 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
259 aRectangle = aRegions[index++];
261 vcl::test::OutputDeviceTestPolyPolygon aOutDevTest;
262 Bitmap aBitmap = aOutDevTest.setupFilledRectangle(false);
263 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, false), aRectangle, rRenderContext);
264 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
267 aRectangle = aRegions[index++];
269 vcl::test::OutputDeviceTestPolyPolygonB2D aOutDevTest;
270 Bitmap aBitmap = aOutDevTest.setupFilledRectangle(false);
271 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, false), aRectangle, rRenderContext);
272 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
275 aRectangle = aRegions[index++];
277 vcl::test::OutputDeviceTestRect aOutDevTest;
278 Bitmap aBitmap = aOutDevTest.setupFilledRectangle(true);
279 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, true), aRectangle, rRenderContext);
280 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
283 aRectangle = aRegions[index++];
285 vcl::test::OutputDeviceTestPolygon aOutDevTest;
286 Bitmap aBitmap = aOutDevTest.setupFilledRectangle(true);
287 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, true), aRectangle, rRenderContext);
288 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
291 aRectangle = aRegions[index++];
293 vcl::test::OutputDeviceTestPolyPolygon aOutDevTest;
294 Bitmap aBitmap = aOutDevTest.setupFilledRectangle(true);
295 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, true), aRectangle, rRenderContext);
296 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
299 aRectangle = aRegions[index++];
301 vcl::test::OutputDeviceTestPolyPolygonB2D aOutDevTest;
302 Bitmap aBitmap = aOutDevTest.setupFilledRectangle(true);
303 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, true), aRectangle, rRenderContext);
304 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
308 static void testDiamondsAndBezier(vcl::RenderContext& rRenderContext, int nWidth, int nHeight)
310 tools::Rectangle aRectangle;
311 size_t index = 0;
313 std::vector<tools::Rectangle> aRegions = setupRegions(3, 2, nWidth, nHeight);
315 aRectangle = aRegions[index++];
317 vcl::test::OutputDeviceTestPolygon aOutDevTest;
318 Bitmap aBitmap = aOutDevTest.setupDiamond();
319 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkDiamond(aBitmap), aRectangle, rRenderContext);
320 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
322 aRectangle = aRegions[index++];
324 vcl::test::OutputDeviceTestLine aOutDevTest;
325 Bitmap aBitmap = aOutDevTest.setupDiamond();
326 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkDiamond(aBitmap), aRectangle, rRenderContext);
327 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
329 aRectangle = aRegions[index++];
331 vcl::test::OutputDeviceTestPolyLine aOutDevTest;
332 Bitmap aBitmap = aOutDevTest.setupDiamond();
333 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkDiamond(aBitmap), aRectangle, rRenderContext);
334 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
336 aRectangle = aRegions[index++];
338 vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest;
339 Bitmap aBitmap = aOutDevTest.setupDiamond();
340 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkDiamond(aBitmap), aRectangle, rRenderContext);
341 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
344 aRectangle = aRegions[index++];
346 vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest;
347 Bitmap aBitmap = aOutDevTest.setupBezier();
348 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkBezier(aBitmap), aRectangle, rRenderContext);
349 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
351 aRectangle = aRegions[index++];
353 vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest;
354 Bitmap aBitmap = aOutDevTest.setupAABezier();
355 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkBezier(aBitmap), aRectangle, rRenderContext);
356 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
360 static void testLines(vcl::RenderContext& rRenderContext, int nWidth, int nHeight)
362 tools::Rectangle aRectangle;
363 size_t index = 0;
365 std::vector<tools::Rectangle> aRegions = setupRegions(3, 2, nWidth, nHeight);
367 aRectangle = aRegions[index++];
369 vcl::test::OutputDeviceTestLine aOutDevTest;
370 Bitmap aBitmap = aOutDevTest.setupLines();
371 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkLines(aBitmap), aRectangle, rRenderContext);
372 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
374 aRectangle = aRegions[index++];
376 vcl::test::OutputDeviceTestPolyLine aOutDevTest;
377 Bitmap aBitmap = aOutDevTest.setupLines();
378 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkLines(aBitmap), aRectangle, rRenderContext);
379 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
381 aRectangle = aRegions[index++];
383 vcl::test::OutputDeviceTestPolygon aOutDevTest;
384 Bitmap aBitmap = aOutDevTest.setupLines();
385 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkLines(aBitmap), aRectangle, rRenderContext);
386 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
388 aRectangle = aRegions[index++];
390 vcl::test::OutputDeviceTestLine aOutDevTest;
391 Bitmap aBitmap = aOutDevTest.setupAALines();
392 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkAALines(aBitmap), aRectangle, rRenderContext);
393 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
395 aRectangle = aRegions[index++];
397 vcl::test::OutputDeviceTestPolyLine aOutDevTest;
398 Bitmap aBitmap = aOutDevTest.setupAALines();
399 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkAALines(aBitmap), aRectangle, rRenderContext);
400 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
402 aRectangle = aRegions[index++];
404 vcl::test::OutputDeviceTestPolygon aOutDevTest;
405 Bitmap aBitmap = aOutDevTest.setupAALines();
406 assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkAALines(aBitmap), aRectangle, rRenderContext);
407 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
411 static void testBitmaps(vcl::RenderContext& rRenderContext, int nWidth, int nHeight)
413 tools::Rectangle aRectangle;
414 size_t index = 0;
416 std::vector<tools::Rectangle> aRegions = setupRegions(3, 2, nWidth, nHeight);
418 aRectangle = aRegions[index++];
420 vcl::test::OutputDeviceTestBitmap aOutDevTest;
421 Bitmap aBitmap = aOutDevTest.setupDrawBitmap();
422 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkTransformedBitmap(aBitmap), aRectangle, rRenderContext);
423 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
425 aRectangle = aRegions[index++];
427 vcl::test::OutputDeviceTestBitmap aOutDevTest;
428 Bitmap aBitmap = aOutDevTest.setupDrawTransformedBitmap();
429 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkTransformedBitmap(aBitmap), aRectangle, rRenderContext);
430 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
432 aRectangle = aRegions[index++];
434 vcl::test::OutputDeviceTestBitmap aOutDevTest;
435 Bitmap aBitmap = aOutDevTest.setupDrawBitmapExWithAlpha();
436 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkBitmapExWithAlpha(aBitmap), aRectangle, rRenderContext);
437 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
439 aRectangle = aRegions[index++];
441 vcl::test::OutputDeviceTestBitmap aOutDevTest;
442 Bitmap aBitmap = aOutDevTest.setupDrawMask();
443 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkMask(aBitmap), aRectangle, rRenderContext);
444 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
446 aRectangle = aRegions[index++];
448 vcl::test::OutputDeviceTestBitmap aOutDevTest;
449 BitmapEx aBitmap = aOutDevTest.setupDrawBlend();
450 assertAndSetBackground(vcl::test::OutputDeviceTestBitmap::checkBlend(aBitmap), aRectangle, rRenderContext);
451 drawBitmapScaledAndCentered(aRectangle, aBitmap.GetBitmap(), rRenderContext);
455 static void testInvert(vcl::RenderContext& rRenderContext, int nWidth, int nHeight)
457 tools::Rectangle aRectangle;
458 size_t index = 0;
460 std::vector<tools::Rectangle> aRegions = setupRegions(2, 2, nWidth, nHeight);
462 aRectangle = aRegions[index++];
464 vcl::test::OutputDeviceTestRect aOutDevTest;
465 Bitmap aBitmap = aOutDevTest.setupInvert_NONE();
466 assertAndSetBackground(vcl::test::OutputDeviceTestRect::checkInvertRectangle(aBitmap), aRectangle, rRenderContext);
467 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
469 aRectangle = aRegions[index++];
471 vcl::test::OutputDeviceTestRect aOutDevTest;
472 Bitmap aBitmap = aOutDevTest.setupInvert_N50();
473 assertAndSetBackground(vcl::test::OutputDeviceTestRect::checkInvertN50Rectangle(aBitmap), aRectangle, rRenderContext);
474 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
476 aRectangle = aRegions[index++];
478 vcl::test::OutputDeviceTestRect aOutDevTest;
479 Bitmap aBitmap = aOutDevTest.setupInvert_TrackFrame();
480 assertAndSetBackground(vcl::test::OutputDeviceTestRect::checkInvertTrackFrameRectangle(aBitmap), aRectangle, rRenderContext);
481 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
483 aRectangle = aRegions[index++];
485 vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest;
486 Bitmap aBitmap = aOutDevTest.setupXOR();
487 assertAndSetBackground(vcl::test::OutputDeviceTestAnotherOutDev::checkXOR(aBitmap), aRectangle, rRenderContext);
488 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
492 static void testClip(vcl::RenderContext& rRenderContext, int nWidth, int nHeight)
494 tools::Rectangle aRectangle;
495 size_t index = 0;
497 std::vector<tools::Rectangle> aRegions = setupRegions(2, 2, nWidth, nHeight);
499 aRectangle = aRegions[index++];
501 vcl::test::OutputDeviceTestClip aOutDevTest;
502 Bitmap aBitmap = aOutDevTest.setupClipRectangle();
503 assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap), aRectangle, rRenderContext);
504 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
506 aRectangle = aRegions[index++];
508 vcl::test::OutputDeviceTestClip aOutDevTest;
509 Bitmap aBitmap = aOutDevTest.setupClipPolygon();
510 assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap), aRectangle, rRenderContext);
511 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
513 aRectangle = aRegions[index++];
515 vcl::test::OutputDeviceTestClip aOutDevTest;
516 Bitmap aBitmap = aOutDevTest.setupClipPolyPolygon();
517 assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap), aRectangle, rRenderContext);
518 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
520 aRectangle = aRegions[index++];
522 vcl::test::OutputDeviceTestClip aOutDevTest;
523 Bitmap aBitmap = aOutDevTest.setupClipB2DPolyPolygon();
524 assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap), aRectangle, rRenderContext);
525 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
529 static void testGradients(vcl::RenderContext& rRenderContext, int nWidth, int nHeight)
531 tools::Rectangle aRectangle;
532 size_t index = 0;
534 std::vector<tools::Rectangle> aRegions = setupRegions(4, 2, nWidth, nHeight);
536 aRectangle = aRegions[index++];
538 vcl::test::OutputDeviceTestGradient aOutDevTest;
539 Bitmap aBitmap = aOutDevTest.setupLinearGradient();
540 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradient(aBitmap), aRectangle, rRenderContext);
541 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
543 aRectangle = aRegions[index++];
545 vcl::test::OutputDeviceTestGradient aOutDevTest;
546 Bitmap aBitmap = aOutDevTest.setupLinearGradientAngled();
547 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradientAngled(aBitmap), aRectangle, rRenderContext);
548 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
550 aRectangle = aRegions[index++];
552 vcl::test::OutputDeviceTestGradient aOutDevTest;
553 Bitmap aBitmap = aOutDevTest.setupLinearGradientBorder();
554 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradientBorder(aBitmap), aRectangle, rRenderContext);
555 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
557 aRectangle = aRegions[index++];
559 vcl::test::OutputDeviceTestGradient aOutDevTest;
560 Bitmap aBitmap = aOutDevTest.setupLinearGradientIntensity();
561 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradientIntensity(aBitmap), aRectangle, rRenderContext);
562 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
564 aRectangle = aRegions[index++];
566 vcl::test::OutputDeviceTestGradient aOutDevTest;
567 Bitmap aBitmap = aOutDevTest.setupLinearGradientSteps();
568 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkLinearGradientSteps(aBitmap), aRectangle, rRenderContext);
569 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
571 aRectangle = aRegions[index++];
573 vcl::test::OutputDeviceTestGradient aOutDevTest;
574 Bitmap aBitmap = aOutDevTest.setupAxialGradient();
575 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkAxialGradient(aBitmap), aRectangle, rRenderContext);
576 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
578 aRectangle = aRegions[index++];
580 vcl::test::OutputDeviceTestGradient aOutDevTest;
581 Bitmap aBitmap = aOutDevTest.setupRadialGradient();
582 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkRadialGradient(aBitmap), aRectangle, rRenderContext);
583 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
585 aRectangle = aRegions[index++];
587 vcl::test::OutputDeviceTestGradient aOutDevTest;
588 Bitmap aBitmap = aOutDevTest.setupRadialGradientOfs();
589 assertAndSetBackground(vcl::test::OutputDeviceTestGradient::checkRadialGradientOfs(aBitmap), aRectangle, rRenderContext);
590 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
594 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/) override
596 if (mnTest % gnNumberOfTests == gnNumberOfTests - 1)
598 rRenderContext.SetBackground(Wallpaper(COL_GREEN));
600 static size_t nTimeIndex = 0;
601 static const size_t constSamplesFPS = 120;
602 double fps = 0.0;
604 if (mTimePoints.size() < constSamplesFPS)
606 mTimePoints.push_back(std::chrono::high_resolution_clock::now());
607 nTimeIndex++;
609 else
611 size_t current = nTimeIndex % constSamplesFPS;
612 mTimePoints[current] = std::chrono::high_resolution_clock::now();
613 size_t last = (nTimeIndex + 1) % constSamplesFPS;
614 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(mTimePoints[current] - mTimePoints[last]).count();
615 fps = constSamplesFPS * 1000.0 / ms;
616 nTimeIndex++;
619 double fTime = 0.5 + std::sin(nTimeIndex / 100.0) / 2.0;
621 Size aSizePixel = GetSizePixel();
623 mpVDev->SetAntialiasing(AntialiasingFlags::Enable | AntialiasingFlags::PixelSnapHairline);
624 mpVDev->SetOutputSizePixel(aSizePixel);
625 mpVDev->SetBackground(Wallpaper(COL_LIGHTGRAY));
626 mpVDev->Erase();
627 mpVDev->SetFillColor(COL_LIGHTRED);
628 mpVDev->SetLineColor(COL_LIGHTBLUE);
630 basegfx::B2DPolyPolygon polyPolygon;
632 for (int b=10; b<14; b++)
634 basegfx::B2DPolygon polygon;
635 for (double a=0.0; a<360.0; a+=0.5)
637 double x = std::sin(basegfx::deg2rad(a)) * (b+1) * 20;
638 double y = std::cos(basegfx::deg2rad(a)) * (b+1) * 20;
639 polygon.append(basegfx::B2DPoint(x + 200 + 500 * fTime, y + 200 + 500 * fTime));
641 polygon.setClosed(true);
642 polyPolygon.append(polygon);
645 mpVDev->DrawPolyPolygon(polyPolygon);
647 tools::Rectangle aGradientRect(Point(200, 200), Size(200 + fTime * 300, 200 + fTime * 300));
648 mpVDev->DrawGradient(aGradientRect, Gradient(GradientStyle::Linear, COL_YELLOW, COL_BLUE));
650 rRenderContext.DrawOutDev(Point(), mpVDev->GetOutputSizePixel(),
651 Point(), mpVDev->GetOutputSizePixel(),
652 *mpVDev);
653 rRenderContext.SetTextColor(COL_LIGHTRED);
654 rRenderContext.DrawText(Point(10, 10), "FPS: " + OUString::number(int(fps)));
655 return;
658 rRenderContext.SetBackground(Wallpaper(COL_GREEN));
660 Size aSize = GetOutputSizePixel();
662 tools::Long nWidth = aSize.Width();
663 tools::Long nHeight = aSize.Height();
665 if (mnTest % gnNumberOfTests == 0)
667 testRectangles(rRenderContext, nWidth, nHeight, false);
669 else if (mnTest % gnNumberOfTests == 1)
671 testRectangles(rRenderContext, nWidth, nHeight, true);
673 else if (mnTest % gnNumberOfTests == 2)
675 testFilledRectangles(rRenderContext, nWidth, nHeight);
677 else if (mnTest % gnNumberOfTests == 3)
679 testDiamondsAndBezier(rRenderContext, nWidth, nHeight);
681 else if (mnTest % gnNumberOfTests == 4)
683 testLines(rRenderContext, nWidth, nHeight);
685 else if (mnTest % gnNumberOfTests == 5)
687 testBitmaps(rRenderContext, nWidth, nHeight);
689 else if (mnTest % gnNumberOfTests == 6)
691 testInvert(rRenderContext, nWidth, nHeight);
693 else if (mnTest % gnNumberOfTests == 7)
695 testClip(rRenderContext, nWidth, nHeight);
697 else if (mnTest % gnNumberOfTests == 8)
699 testGradients(rRenderContext, nWidth, nHeight);
701 else if (mnTest % gnNumberOfTests == 9)
703 std::vector<tools::Rectangle> aRegions = setupRegions(2, 1, nWidth, nHeight);
704 size_t index = 0;
706 tools::Rectangle aRectangle = aRegions[index++];
708 vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest;
709 Bitmap aBitmap = aOutDevTest.setupDrawOutDev();
710 assertAndSetBackground(vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDev(aBitmap), aRectangle, rRenderContext);
711 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
713 aRectangle = aRegions[index++];
715 vcl::test::OutputDeviceTestLine aOutDevTest;
716 Bitmap aBitmap = aOutDevTest.setupDashedLine();
717 assertAndSetBackground(vcl::test::OutputDeviceTestLine::checkDashedLine(aBitmap), aRectangle, rRenderContext);
718 drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
726 IMPL_LINK_NOARG(VisualBackendTestWindow, updateHdl, Timer *, void)
728 if (mbAnimate)
730 maUpdateTimer.SetTimeout(1.0);
731 maUpdateTimer.Start();
732 Invalidate();
736 namespace {
738 class VisualBackendTestApp : public Application
741 public:
742 VisualBackendTestApp()
745 virtual int Main() override
749 ScopedVclPtrInstance<VisualBackendTestWindow> aMainWindow;
751 aMainWindow->SetText("VCL Test");
752 aMainWindow->Show();
754 Application::Execute();
756 catch (const css::uno::Exception&)
758 DBG_UNHANDLED_EXCEPTION("vcl.app", "Fatal");
759 return 1;
761 catch (const std::exception& rException)
763 SAL_WARN("vcl.app", "Fatal exception: " << rException.what());
764 return 1;
766 return 0;
769 protected:
770 void Init() override
774 uno::Reference<uno::XComponentContext> xComponentContext = ::cppu::defaultBootstrap_InitialComponentContext();
775 uno::Reference<lang::XMultiServiceFactory> xMSF(xComponentContext->getServiceManager(), uno::UNO_QUERY);
777 if (!xMSF.is())
778 Application::Abort("Bootstrap failure - no service manager");
780 comphelper::setProcessServiceFactory(xMSF);
782 catch (const uno::Exception &e)
784 Application::Abort("Bootstrap exception " + e.Message);
788 void DeInit() override
790 uno::Reference<lang::XComponent> xComponent(comphelper::getProcessComponentContext(), uno::UNO_QUERY_THROW);
791 xComponent->dispose();
792 comphelper::setProcessServiceFactory(nullptr);
798 void vclmain::createApplication()
800 static VisualBackendTestApp aApplication;
803 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */