diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-11-01 13:44:20 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-11-27 09:55:16 +0100 |
commit | 805e75bd790cd9b3e49ace69beee96d21163f7a6 (patch) | |
tree | ed4163bf3f4cf9e639e838bf7c1351ee18007b49 /vcl/backendtest | |
parent | 81a02de2387edeef0e7fbc6dfd652fcd5659f793 (diff) |
use different line and fill color in vcl backendtest
Having them the same can hide problems with them fixed up incorrectly.
And it also shows that drawPolygon() with line color unset does not
draw the right-most and bottom-most line, which is what all underlying
graphics systems do, so the test is kind of wrong and I've added
a compensation to make it visually correct (and match the checked
expected result).
Change-Id: I333f41210232c74ba55bd5c92ef5fda917ce3e59
Diffstat (limited to 'vcl/backendtest')
-rw-r--r-- | vcl/backendtest/VisualBackendTest.cxx | 54 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/bitmap.cxx | 2 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/common.cxx | 7 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/line.cxx | 2 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/outputdevice.cxx | 7 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polygon.cxx | 21 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polypolygon.cxx | 21 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polypolygon_b2d.cxx | 22 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/rectangle.cxx | 7 |
9 files changed, 105 insertions, 38 deletions
diff --git a/vcl/backendtest/VisualBackendTest.cxx b/vcl/backendtest/VisualBackendTest.cxx index b2818f42e675..4110082a6985 100644 --- a/vcl/backendtest/VisualBackendTest.cxx +++ b/vcl/backendtest/VisualBackendTest.cxx @@ -90,7 +90,7 @@ class VisualBackendTestWindow : public WorkWindow private: Timer maUpdateTimer; std::vector<std::chrono::high_resolution_clock::time_point> mTimePoints; - static constexpr unsigned char gnNumberOfTests = 6; + static constexpr unsigned char gnNumberOfTests = 7; unsigned char mnTest; bool mbAnimate; ScopedVclPtr<VirtualDevice> mpVDev; @@ -227,29 +227,61 @@ public: aRectangle = aRegions[index++]; { vcl::test::OutputDeviceTestRect aOutDevTest; - Bitmap aBitmap = aOutDevTest.setupFilledRectangle(); - assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap), aRectangle, rRenderContext); + Bitmap aBitmap = aOutDevTest.setupFilledRectangle(false); + assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, false), aRectangle, rRenderContext); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); } aRectangle = aRegions[index++]; { vcl::test::OutputDeviceTestPolygon aOutDevTest; - Bitmap aBitmap = aOutDevTest.setupFilledRectangle(); - assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap), aRectangle, rRenderContext); + Bitmap aBitmap = aOutDevTest.setupFilledRectangle(false); + assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, false), aRectangle, rRenderContext); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); } aRectangle = aRegions[index++]; { vcl::test::OutputDeviceTestPolyPolygon aOutDevTest; - Bitmap aBitmap = aOutDevTest.setupFilledRectangle(); - assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap), aRectangle, rRenderContext); + Bitmap aBitmap = aOutDevTest.setupFilledRectangle(false); + assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, false), aRectangle, rRenderContext); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); } aRectangle = aRegions[index++]; { + vcl::test::OutputDeviceTestRect aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupFilledRectangle(true); + assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, true), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + + aRectangle = aRegions[index++]; + { + vcl::test::OutputDeviceTestPolygon aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupFilledRectangle(true); + assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, true), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + + aRectangle = aRegions[index++]; + { + vcl::test::OutputDeviceTestPolyPolygon aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupFilledRectangle(true); + assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkFilledRectangle(aBitmap, true), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + } + + static void testDiamonds(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) + { + tools::Rectangle aRectangle; + size_t index = 0; + + std::vector<tools::Rectangle> aRegions = setupRegions(3, 1, nWidth, nHeight); + + aRectangle = aRegions[index++]; + { vcl::test::OutputDeviceTestPolygon aOutDevTest; Bitmap aBitmap = aOutDevTest.setupDiamond(); assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkDiamond(aBitmap), aRectangle, rRenderContext); @@ -443,14 +475,18 @@ public: } else if (mnTest % gnNumberOfTests == 2) { - testLines(rRenderContext, nWidth, nHeight); + testDiamonds(rRenderContext, nWidth, nHeight); } else if (mnTest % gnNumberOfTests == 3) { - testBitmaps(rRenderContext, nWidth, nHeight); + testLines(rRenderContext, nWidth, nHeight); } else if (mnTest % gnNumberOfTests == 4) { + testBitmaps(rRenderContext, nWidth, nHeight); + } + else if (mnTest % gnNumberOfTests == 5) + { std::vector<tools::Rectangle> aRegions = setupRegions(3, 2, nWidth, nHeight); aRectangle = aRegions[index++]; diff --git a/vcl/backendtest/outputdevice/bitmap.cxx b/vcl/backendtest/outputdevice/bitmap.cxx index 58b7c5f03ff0..66a0a64adf49 100644 --- a/vcl/backendtest/outputdevice/bitmap.cxx +++ b/vcl/backendtest/outputdevice/bitmap.cxx @@ -107,7 +107,7 @@ Bitmap OutputDeviceTestBitmap::setupDrawMask() initialSetup(13, 13, constBackgroundColor); - mpVirtualDevice->DrawMask(Point(2, 2), aBitmap, constFillColor); + mpVirtualDevice->DrawMask(Point(2, 2), aBitmap, constLineColor); return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } diff --git a/vcl/backendtest/outputdevice/common.cxx b/vcl/backendtest/outputdevice/common.cxx index 00c7b473e88a..34e37e771f1f 100644 --- a/vcl/backendtest/outputdevice/common.cxx +++ b/vcl/backendtest/outputdevice/common.cxx @@ -220,7 +220,7 @@ TestResult checkDiamondLine(Bitmap& rBitmap, int aLayerNumber, Color aExpectedCo const Color OutputDeviceTestCommon::constBackgroundColor(COL_LIGHTGRAY); const Color OutputDeviceTestCommon::constLineColor(COL_LIGHTBLUE); -const Color OutputDeviceTestCommon::constFillColor(COL_LIGHTBLUE); +const Color OutputDeviceTestCommon::constFillColor(COL_BLUE); OutputDeviceTestCommon::OutputDeviceTestCommon() {} @@ -366,12 +366,13 @@ TestResult OutputDeviceTestCommon::checkRectangleAA(Bitmap& aBitmap) return checkRectangles(aBitmap, aExpected); } -TestResult OutputDeviceTestCommon::checkFilledRectangle(Bitmap& aBitmap) +TestResult OutputDeviceTestCommon::checkFilledRectangle(Bitmap& aBitmap, bool useLineColor) { std::vector<Color> aExpected { constBackgroundColor, constBackgroundColor, - constFillColor, constFillColor, constFillColor, constFillColor, constFillColor + useLineColor ? constLineColor : constFillColor, + constFillColor, constFillColor, constFillColor, constFillColor }; return checkRectangles(aBitmap, aExpected); } diff --git a/vcl/backendtest/outputdevice/line.cxx b/vcl/backendtest/outputdevice/line.cxx index ff03a777771e..a43c72a62dc0 100644 --- a/vcl/backendtest/outputdevice/line.cxx +++ b/vcl/backendtest/outputdevice/line.cxx @@ -48,7 +48,7 @@ Bitmap OutputDeviceTestLine::setupDiamond() { initialSetup(11, 11, constBackgroundColor); - mpVirtualDevice->SetLineColor(constFillColor); + mpVirtualDevice->SetLineColor(constLineColor); mpVirtualDevice->SetFillColor(); Point aPoint1, aPoint2, aPoint3, aPoint4; diff --git a/vcl/backendtest/outputdevice/outputdevice.cxx b/vcl/backendtest/outputdevice/outputdevice.cxx index 408ce09551f7..4f31501b6f3b 100644 --- a/vcl/backendtest/outputdevice/outputdevice.cxx +++ b/vcl/backendtest/outputdevice/outputdevice.cxx @@ -55,7 +55,12 @@ Bitmap OutputDeviceTestAnotherOutDev::setupXOR() TestResult OutputDeviceTestAnotherOutDev::checkDrawOutDev(Bitmap& rBitmap) { - return checkFilledRectangle(rBitmap); + std::vector<Color> aExpected + { + constBackgroundColor, constBackgroundColor, + constFillColor, constFillColor, constFillColor, constFillColor, constFillColor + }; + return checkRectangles(rBitmap, aExpected); } TestResult OutputDeviceTestAnotherOutDev::checkXOR(Bitmap& rBitmap) diff --git a/vcl/backendtest/outputdevice/polygon.cxx b/vcl/backendtest/outputdevice/polygon.cxx index 4a0fac9f92ed..f0977abfb5f6 100644 --- a/vcl/backendtest/outputdevice/polygon.cxx +++ b/vcl/backendtest/outputdevice/polygon.cxx @@ -16,13 +16,17 @@ namespace test { namespace { -void drawPolygonOffset(OutputDevice& rDevice, tools::Rectangle const & rRect, int nOffset) +void drawPolygonOffset(OutputDevice& rDevice, tools::Rectangle const & rRect, int nOffset, int nFix = 0) { + // Note: According to https://lists.freedesktop.org/archives/libreoffice/2019-November/083709.html + // filling polygons always skips the right-most and bottom-most pixels, in order to avoid + // overlaps when drawing adjacent polygons. Specifying nFix = 1 allows to visually compensate + // for this by making the polygon explicitly larger. tools::Polygon aPolygon(4); aPolygon.SetPoint(Point(rRect.Left() + nOffset, rRect.Top() + nOffset), 0); - aPolygon.SetPoint(Point(rRect.Right() - nOffset, rRect.Top() + nOffset), 1); - aPolygon.SetPoint(Point(rRect.Right() - nOffset, rRect.Bottom() - nOffset), 2); - aPolygon.SetPoint(Point(rRect.Left() + nOffset, rRect.Bottom() - nOffset), 3); + aPolygon.SetPoint(Point(rRect.Right() - nOffset + nFix, rRect.Top() + nOffset), 1); + aPolygon.SetPoint(Point(rRect.Right() - nOffset + nFix, rRect.Bottom() - nOffset + nFix), 2); + aPolygon.SetPoint(Point(rRect.Left() + nOffset, rRect.Bottom() - nOffset + nFix), 3); aPolygon.Optimize(PolyOptimizeFlags::CLOSE); rDevice.DrawPolygon(aPolygon); @@ -43,13 +47,16 @@ Bitmap OutputDeviceTestPolygon::setupRectangle(bool bEnableAA) return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } -Bitmap OutputDeviceTestPolygon::setupFilledRectangle() +Bitmap OutputDeviceTestPolygon::setupFilledRectangle(bool useLineColor) { initialSetup(13, 13, constBackgroundColor); - mpVirtualDevice->SetLineColor(); + if(useLineColor) + mpVirtualDevice->SetLineColor(constLineColor); + else + mpVirtualDevice->SetLineColor(); mpVirtualDevice->SetFillColor(constFillColor); - drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 2); + drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 2, useLineColor ? 0 : 1); return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } diff --git a/vcl/backendtest/outputdevice/polypolygon.cxx b/vcl/backendtest/outputdevice/polypolygon.cxx index f36db1e9fd65..e5a527042bdc 100644 --- a/vcl/backendtest/outputdevice/polypolygon.cxx +++ b/vcl/backendtest/outputdevice/polypolygon.cxx @@ -17,13 +17,17 @@ namespace test { namespace { -tools::Polygon createPolygonOffset(tools::Rectangle const & rRect, int nOffset) +tools::Polygon createPolygonOffset(tools::Rectangle const & rRect, int nOffset, int nFix = 0) { + // Note: According to https://lists.freedesktop.org/archives/libreoffice/2019-November/083709.html + // filling polygons always skips the right-most and bottom-most pixels, in order to avoid + // overlaps when drawing adjacent polygons. Specifying nFix = 1 allows to visually compensate + // for this by making the polygon explicitly larger. tools::Polygon aPolygon(4); aPolygon.SetPoint(Point(rRect.Left() + nOffset, rRect.Top() + nOffset), 0); - aPolygon.SetPoint(Point(rRect.Right() - nOffset, rRect.Top() + nOffset), 1); - aPolygon.SetPoint(Point(rRect.Right() - nOffset, rRect.Bottom() - nOffset), 2); - aPolygon.SetPoint(Point(rRect.Left() + nOffset, rRect.Bottom() - nOffset), 3); + aPolygon.SetPoint(Point(rRect.Right() - nOffset + nFix, rRect.Top() + nOffset), 1); + aPolygon.SetPoint(Point(rRect.Right() - nOffset + nFix, rRect.Bottom() - nOffset + nFix), 2); + aPolygon.SetPoint(Point(rRect.Left() + nOffset, rRect.Bottom() - nOffset + nFix), 3); aPolygon.Optimize(PolyOptimizeFlags::CLOSE); return aPolygon; } @@ -46,15 +50,18 @@ Bitmap OutputDeviceTestPolyPolygon::setupRectangle(bool bEnableAA) return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } -Bitmap OutputDeviceTestPolyPolygon::setupFilledRectangle() +Bitmap OutputDeviceTestPolyPolygon::setupFilledRectangle(bool useLineColor) { initialSetup(13, 13, constBackgroundColor); - mpVirtualDevice->SetLineColor(); + if(useLineColor) + mpVirtualDevice->SetLineColor(constLineColor); + else + mpVirtualDevice->SetLineColor(); mpVirtualDevice->SetFillColor(constFillColor); tools::PolyPolygon aPolyPolygon(1); - aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 2)); + aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 2, useLineColor ? 0 : 1)); mpVirtualDevice->DrawPolyPolygon(aPolyPolygon); diff --git a/vcl/backendtest/outputdevice/polypolygon_b2d.cxx b/vcl/backendtest/outputdevice/polypolygon_b2d.cxx index 808e8637c3d8..977f73dcc1f4 100644 --- a/vcl/backendtest/outputdevice/polypolygon_b2d.cxx +++ b/vcl/backendtest/outputdevice/polypolygon_b2d.cxx @@ -16,13 +16,17 @@ namespace test { namespace { -basegfx::B2DPolygon createPolygonOffset(tools::Rectangle const& rRect, int nOffset) +basegfx::B2DPolygon createPolygonOffset(tools::Rectangle const& rRect, int nOffset, int nFix = 0) { + // Note: According to https://lists.freedesktop.org/archives/libreoffice/2019-November/083709.html + // filling polygons always skips the right-most and bottom-most pixels, in order to avoid + // overlaps when drawing adjacent polygons. Specifying nFix = 1 allows to visually compensate + // for this by making the polygon explicitly larger. basegfx::B2DPolygon aPolygon{ basegfx::B2DPoint(rRect.Left() + nOffset, rRect.Top() + nOffset), - basegfx::B2DPoint(rRect.Right() - nOffset, rRect.Top() + nOffset), - basegfx::B2DPoint(rRect.Right() - nOffset, rRect.Bottom() - nOffset), - basegfx::B2DPoint(rRect.Left() + nOffset, rRect.Bottom() - nOffset), + basegfx::B2DPoint(rRect.Right() - nOffset + nFix, rRect.Top() + nOffset), + basegfx::B2DPoint(rRect.Right() - nOffset + nFix, rRect.Bottom() - nOffset + nFix), + basegfx::B2DPoint(rRect.Left() + nOffset, rRect.Bottom() - nOffset + nFix), }; aPolygon.setClosed(true); return aPolygon; @@ -46,14 +50,18 @@ Bitmap OutputDeviceTestPolyPolygonB2D::setupRectangle(bool bEnableAA) return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } -Bitmap OutputDeviceTestPolyPolygonB2D::setupFilledRectangle() +Bitmap OutputDeviceTestPolyPolygonB2D::setupFilledRectangle(bool useLineColor) { initialSetup(13, 13, constBackgroundColor); - mpVirtualDevice->SetLineColor(); + if (useLineColor) + mpVirtualDevice->SetLineColor(constLineColor); + else + mpVirtualDevice->SetLineColor(); mpVirtualDevice->SetFillColor(constFillColor); - basegfx::B2DPolyPolygon aPolyPolygon(createPolygonOffset(maVDRectangle, 2)); + basegfx::B2DPolyPolygon aPolyPolygon( + createPolygonOffset(maVDRectangle, 2, useLineColor ? 0 : 1)); mpVirtualDevice->DrawPolyPolygon(aPolyPolygon); diff --git a/vcl/backendtest/outputdevice/rectangle.cxx b/vcl/backendtest/outputdevice/rectangle.cxx index f861cc2f05bb..033ebb3c54ae 100644 --- a/vcl/backendtest/outputdevice/rectangle.cxx +++ b/vcl/backendtest/outputdevice/rectangle.cxx @@ -31,11 +31,14 @@ namespace } // end anonymous namespace -Bitmap OutputDeviceTestRect::setupFilledRectangle() +Bitmap OutputDeviceTestRect::setupFilledRectangle(bool useLineColor) { initialSetup(13, 13, constBackgroundColor); - mpVirtualDevice->SetLineColor(); + if(useLineColor) + mpVirtualDevice->SetLineColor(constLineColor); + else + mpVirtualDevice->SetLineColor(); mpVirtualDevice->SetFillColor(constFillColor); drawRectOffset(*mpVirtualDevice, maVDRectangle, 2); |