diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2020-05-22 18:59:33 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-05-22 22:10:00 +0200 |
commit | 7f264f4beec931833b390ae1bbb93b2e22b4ad8a (patch) | |
tree | bb52e49618173c48d67103b0233bbc1dcf832925 /vcl/backendtest | |
parent | ec11b7330fab72dc56d847c7c3691fddbb18096e (diff) |
always use region band in Skia's setClipRegion (tdf#133208)
Do like other VCL backends do.
Change-Id: I64b5d5a2fb131b41c70aa63eaf84022e9aa9fab5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94702
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/backendtest')
-rw-r--r-- | vcl/backendtest/VisualBackendTest.cxx | 43 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/clip.cxx | 83 |
2 files changed, 125 insertions, 1 deletions
diff --git a/vcl/backendtest/VisualBackendTest.cxx b/vcl/backendtest/VisualBackendTest.cxx index fb39156714a7..5daa9a642d55 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 = 8; + static constexpr unsigned char gnNumberOfTests = 9; unsigned char mnTest; bool mbAnimate; ScopedVclPtr<VirtualDevice> mpVDev; @@ -435,6 +435,43 @@ public: } } + static void testClip(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) + { + tools::Rectangle aRectangle; + size_t index = 0; + + std::vector<tools::Rectangle> aRegions = setupRegions(2, 2, nWidth, nHeight); + + aRectangle = aRegions[index++]; + { + vcl::test::OutputDeviceTestClip aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupClipRectangle(); + assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + aRectangle = aRegions[index++]; + { + vcl::test::OutputDeviceTestClip aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupClipPolygon(); + assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + aRectangle = aRegions[index++]; + { + vcl::test::OutputDeviceTestClip aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupClipPolyPolygon(); + assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + aRectangle = aRegions[index++]; + { + vcl::test::OutputDeviceTestClip aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupClipB2DPolyPolygon(); + assertAndSetBackground(vcl::test::OutputDeviceTestClip::checkClip(aBitmap), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + } + virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/) override { if (mnTest % gnNumberOfTests == gnNumberOfTests - 1) @@ -535,6 +572,10 @@ public: } else if (mnTest % gnNumberOfTests == 6) { + testClip(rRenderContext, nWidth, nHeight); + } + else if (mnTest % gnNumberOfTests == 7) + { std::vector<tools::Rectangle> aRegions = setupRegions(3, 1, nWidth, nHeight); aRectangle = aRegions[index++]; diff --git a/vcl/backendtest/outputdevice/clip.cxx b/vcl/backendtest/outputdevice/clip.cxx new file mode 100644 index 000000000000..86064b583610 --- /dev/null +++ b/vcl/backendtest/outputdevice/clip.cxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <test/outputdevice.hxx> + +namespace vcl::test +{ +Bitmap OutputDeviceTestClip::setupClipRectangle() +{ + initialSetup(13, 13, constBackgroundColor); + + tools::Rectangle rectangle = maVDRectangle; + rectangle.shrink(2); + mpVirtualDevice->SetClipRegion(vcl::Region(rectangle)); + mpVirtualDevice->SetBackground(constFillColor); + mpVirtualDevice->Erase(maVDRectangle); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + +Bitmap OutputDeviceTestClip::setupClipPolygon() +{ + initialSetup(13, 13, constBackgroundColor); + + tools::Rectangle rectangle = maVDRectangle; + rectangle.shrink(2); + mpVirtualDevice->SetClipRegion(vcl::Region(tools::Polygon(rectangle))); + mpVirtualDevice->SetBackground(constFillColor); + mpVirtualDevice->Erase(maVDRectangle); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + +Bitmap OutputDeviceTestClip::setupClipPolyPolygon() +{ + initialSetup(13, 13, constBackgroundColor); + + tools::Rectangle rectangle = maVDRectangle; + rectangle.shrink(2); + mpVirtualDevice->SetClipRegion(vcl::Region(tools::PolyPolygon(rectangle))); + mpVirtualDevice->SetBackground(constFillColor); + mpVirtualDevice->Erase(maVDRectangle); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + +Bitmap OutputDeviceTestClip::setupClipB2DPolyPolygon() +{ + initialSetup(13, 13, constBackgroundColor); + + tools::Rectangle rectangle = maVDRectangle; + rectangle.shrink(2); + mpVirtualDevice->SetClipRegion(vcl::Region(basegfx::B2DPolyPolygon(basegfx::B2DPolygon{ + basegfx::B2DPoint(rectangle.getX(), rectangle.getY()), + basegfx::B2DPoint(rectangle.getX(), rectangle.getY() + rectangle.getHeight()), + basegfx::B2DPoint(rectangle.getX() + rectangle.getWidth(), + rectangle.getY() + rectangle.getHeight()), + basegfx::B2DPoint(rectangle.getX() + rectangle.getWidth(), rectangle.getY()), + }))); + mpVirtualDevice->SetBackground(constFillColor); + mpVirtualDevice->Erase(maVDRectangle); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + +TestResult OutputDeviceTestClip::checkClip(Bitmap& aBitmap) +{ + std::vector<Color> aExpected{ constBackgroundColor, constBackgroundColor, constFillColor, + constFillColor, constFillColor, constFillColor, + constFillColor }; + return checkRectangles(aBitmap, aExpected); +} + +} // end namespace vcl::test + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |