Kaydet (Commit) 3e6052ce authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

vcl: Adds backend tests to check for correct rendering

Collection of test that check rendering of VCL backend. This works
by rendering primitives to the VirtualDevice, outputing the result
to a Bitmap and checking the rendering by comparing pixels. This
should warn when the primitive is drawn to a wrong position or if
it is the wrong size or color. It also test some rendering tricks
like XOR drawing.

Currently this is not implemented as a CPPUnit test but separately,
as its own executable file so we can check the results visually.
The idea is also to add the tests into LO for the user to test or
automatically to test the backend on first start (especially
useful to test the OpenGL backend as some drivers could have
unexpected behaviour).

Change-Id: I2a565b9986ca68850e2752466e3cd5fc71991ba6
üst 129c0d63
......@@ -74,6 +74,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \
vcldemo \
tiledrendering \
mtfdemo \
visualbackendtest \
$(if $(and $(ENABLE_GTK3), $(filter LINUX %BSD SOLARIS,$(OS))), gtktiledviewer) \
))
......
......@@ -379,6 +379,7 @@ public:
* Expands the rectangle in all directions by the input value.
*/
inline void expand(long nExpandBy);
inline void shrink(long nShrinkBy);
private:
long nLeft;
......@@ -620,6 +621,13 @@ inline void Rectangle::expand(long nExpandBy)
nBottom += nExpandBy;
}
inline void Rectangle::shrink(long nShrinkBy)
{
nLeft += nShrinkBy;
nTop += nShrinkBy;
nRight -= nShrinkBy;
nBottom -= nShrinkBy;
}
template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<(
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
#
# 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/.
#
$(eval $(call gb_Executable_Executable,visualbackendtest))
$(eval $(call gb_Executable_use_api,visualbackendtest,\
offapi \
udkapi \
))
$(eval $(call gb_Executable_use_external,visualbackendtest,boost_headers))
$(eval $(call gb_Executable_set_include,visualbackendtest,\
$$(INCLUDE) \
-I$(SRCDIR)/vcl/inc \
))
$(eval $(call gb_Executable_use_libraries,visualbackendtest,\
basegfx \
comphelper \
cppu \
cppuhelper \
tl \
sal \
salhelper \
vcl \
))
$(eval $(call gb_Executable_add_exception_objects,visualbackendtest,\
vcl/backendtest/VisualBackendTest \
))
$(eval $(call gb_Executable_use_static_libraries,visualbackendtest,\
vclmain \
))
ifeq ($(OS),LINUX)
$(eval $(call gb_Executable_add_libs,visualbackendtest,\
-lm \
-ldl \
-lpthread \
-lGL \
-lX11 \
))
$(eval $(call gb_Executable_use_static_libraries,visualbackendtest,\
glxtest \
))
endif
# vim: set noet sw=4 ts=4:
......@@ -399,6 +399,16 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/uitest/uitest \
vcl/source/uitest/uno/uiobject_uno \
vcl/source/uitest/uno/uitest_uno \
vcl/backendtest/outputdevice/bitmap \
vcl/backendtest/outputdevice/common \
vcl/backendtest/outputdevice/gradient \
vcl/backendtest/outputdevice/line \
vcl/backendtest/outputdevice/outputdevice \
vcl/backendtest/outputdevice/pixel \
vcl/backendtest/outputdevice/polygon \
vcl/backendtest/outputdevice/polypolygon \
vcl/backendtest/outputdevice/polyline \
vcl/backendtest/outputdevice/rectangle \
))
$(eval $(call gb_Library_add_cobjects,vcl,\
......
......@@ -35,6 +35,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
$(if $(ENABLE_HEADLESS),, \
Executable_vcldemo \
Executable_icontest \
Executable_visualbackendtest \
Executable_mtfdemo ))) \
$(if $(filter-out ANDROID IOS WNT,$(OS)), \
Executable_svdemo \
......
This diff is collapsed.
/* -*- 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"
#include <basegfx/matrix/b2dhommatrix.hxx>
namespace vcl {
namespace test {
Bitmap OutputDeviceTestBitmap::setupDrawTransformedBitmap()
{
Size aBitmapSize(9, 9);
Bitmap aBitmap(aBitmapSize, 24);
{
Bitmap::ScopedWriteAccess aWriteAccess(aBitmap);
aWriteAccess->Erase(constFillColor);
aWriteAccess->SetLineColor(COL_YELLOW);
aWriteAccess->DrawRect(Rectangle(0, 0, 8, 8));
aWriteAccess->DrawRect(Rectangle(2, 2, 6, 6));
}
initialSetup(13, 13, constBackgroundColor);
basegfx::B2DHomMatrix aTransform;
aTransform.scale(aBitmapSize.Width(), aBitmapSize.Height());
aTransform.translate((maVDRectangle.GetWidth() / 2.0) - (aBitmapSize.Width() / 2.0),
(maVDRectangle.GetHeight() / 2.0) - (aBitmapSize.Height() / 2.0));
mpVirtualDevice->DrawTransformedBitmapEx(aTransform, BitmapEx(aBitmap));
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestBitmap::setupDrawBitmap()
{
Size aBitmapSize(9, 9);
Bitmap aBitmap(aBitmapSize, 24);
{
Bitmap::ScopedWriteAccess aWriteAccess(aBitmap);
aWriteAccess->Erase(constFillColor);
aWriteAccess->SetLineColor(COL_YELLOW);
aWriteAccess->DrawRect(Rectangle(0, 0, 8, 8));
aWriteAccess->DrawRect(Rectangle(2, 2, 6, 6));
}
initialSetup(13, 13, constBackgroundColor);
Point aPoint((maVDRectangle.GetWidth() / 2.0) - (aBitmapSize.Width() / 2.0),
(maVDRectangle.GetHeight() / 2.0) - (aBitmapSize.Height() / 2.0));
mpVirtualDevice->DrawBitmapEx(aPoint, BitmapEx(aBitmap));
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestBitmap::setupDrawBitmapExWithAlpha()
{
Size aBitmapSize(9, 9);
Bitmap aBitmap(aBitmapSize, 24);
{
Bitmap::ScopedWriteAccess aWriteAccess(aBitmap);
aWriteAccess->Erase(COL_WHITE);
aWriteAccess->SetLineColor(Color(0xFF, 0xFF, 0x00));
aWriteAccess->DrawRect(Rectangle(0, 0, 8, 8));
aWriteAccess->DrawRect(Rectangle(3, 3, 5, 5));
}
AlphaMask aAlpha(aBitmapSize);
{
AlphaMask::ScopedWriteAccess aWriteAccess(aAlpha);
aWriteAccess->Erase(COL_WHITE);
aWriteAccess->SetLineColor(Color(0x44, 0x44, 0x44));
aWriteAccess->DrawRect(Rectangle(0, 0, 8, 8));
aWriteAccess->DrawRect(Rectangle(3, 3, 5, 5));
}
initialSetup(13, 13, constBackgroundColor);
Point aPoint(alignToCenter(maVDRectangle, Rectangle(Point(), aBitmapSize)).TopLeft());
mpVirtualDevice->DrawBitmapEx(aPoint, BitmapEx(aBitmap, aAlpha));
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestBitmap::setupDrawMask()
{
Size aBitmapSize(9, 9);
Bitmap aBitmap(aBitmapSize, 24);
{
Bitmap::ScopedWriteAccess aWriteAccess(aBitmap);
aWriteAccess->Erase(COL_WHITE);
aWriteAccess->SetLineColor(COL_BLACK);
aWriteAccess->DrawRect(Rectangle(0, 0, 8, 8));
aWriteAccess->DrawRect(Rectangle(3, 3, 5, 5));
}
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->DrawMask(Point(2, 2), aBitmap, constFillColor);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
TestResult OutputDeviceTestBitmap::checkBitmap(Bitmap& rBitmap)
{
std::vector<Color> aExpected
{
constBackgroundColor, constBackgroundColor,
COL_YELLOW, constFillColor, COL_YELLOW, constFillColor, constFillColor
};
return checkRectangles(rBitmap, aExpected);
}
TestResult OutputDeviceTestBitmap::checkTransformedBitmap(Bitmap& rBitmap)
{
std::vector<Color> aExpected
{
constBackgroundColor, constBackgroundColor,
COL_YELLOW, constFillColor, COL_YELLOW, constFillColor, constFillColor
};
return checkRectangles(rBitmap, aExpected);
}
TestResult OutputDeviceTestBitmap::checkBitmapExWithAlpha(Bitmap& rBitmap)
{
const Color aBlendedColor(0xEE, 0xEE, 0x33);
std::vector<Color> aExpected
{
constBackgroundColor, constBackgroundColor,
aBlendedColor, constBackgroundColor, constBackgroundColor,
aBlendedColor, constBackgroundColor
};
return checkRectangles(rBitmap, aExpected);
}
TestResult OutputDeviceTestBitmap::checkMask(Bitmap& rBitmap)
{
return checkRectangle(rBitmap);
}
}} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
/* -*- 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 {
namespace test {
Bitmap OutputDeviceTestGradient::setupLinearGradient()
{
initialSetup(12, 12, constBackgroundColor);
Gradient aGradient(GradientStyle_LINEAR, Color(0xFF, 0xFF, 0xFF), Color(0x00, 0x00, 0x00));
aGradient.SetAngle(900);
Rectangle aDrawRect(maVDRectangle.Left() + 1, maVDRectangle.Top() + 1,
maVDRectangle.Right() - 1, maVDRectangle.Bottom() - 1);
mpVirtualDevice->DrawGradient(aDrawRect, aGradient);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestGradient::setupRadialGradient()
{
initialSetup(12, 12, constBackgroundColor);
Gradient aGradient(GradientStyle_RADIAL, Color(0xFF, 0xFF, 0xFF), Color(0x00, 0x00, 0x00));
Rectangle aDrawRect(maVDRectangle.Left() + 1, maVDRectangle.Top() + 1,
maVDRectangle.Right() - 1, maVDRectangle.Bottom() - 1);
mpVirtualDevice->DrawGradient(aDrawRect, aGradient);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
}} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 {
namespace test {
namespace
{
void drawLineOffset(OutputDevice& rDevice, Rectangle& rRect, int nOffset)
{
Point aLeftTop (rRect.Left() + nOffset, rRect.Top() + nOffset);
Point aRightTop (rRect.Right() - nOffset, rRect.Top() + nOffset);
Point aLeftBottom (rRect.Left() + nOffset, rRect.Bottom() - nOffset);
Point aRightBottom (rRect.Right() - nOffset, rRect.Bottom() - nOffset);
rDevice.DrawLine(aLeftTop, aRightTop);
rDevice.DrawLine(aRightTop, aRightBottom);
rDevice.DrawLine(aRightBottom, aLeftBottom);
rDevice.DrawLine(aLeftBottom, aLeftTop);
}
} // end anonymous namespace
Bitmap OutputDeviceTestLine::setupRectangle()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
drawLineOffset(*mpVirtualDevice, maVDRectangle, 2);
drawLineOffset(*mpVirtualDevice, maVDRectangle, 5);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestLine::setupDiamond()
{
initialSetup(11, 11, constBackgroundColor);
mpVirtualDevice->SetLineColor(constFillColor);
mpVirtualDevice->SetFillColor();
Point aPoint1, aPoint2, aPoint3, aPoint4;
OutputDeviceTestCommon::createDiamondPoints(maVDRectangle, 4, aPoint1, aPoint2, aPoint3, aPoint4);
mpVirtualDevice->DrawLine(aPoint1, aPoint2);
mpVirtualDevice->DrawLine(aPoint2, aPoint3);
mpVirtualDevice->DrawLine(aPoint3, aPoint4);
mpVirtualDevice->DrawLine(aPoint4, aPoint1);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestLine::setupLines()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
Point aHorizontalLinePoint1, aHorizontalLinePoint2;
Point aVerticalLinePoint1, aVerticalLinePoint2;
Point aDiagonalLinePoint1, aDiagonalLinePoint2;
OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
maVDRectangle, aHorizontalLinePoint1, aHorizontalLinePoint2,
aVerticalLinePoint1, aVerticalLinePoint2,
aDiagonalLinePoint1, aDiagonalLinePoint2);
mpVirtualDevice->DrawLine(aHorizontalLinePoint1, aHorizontalLinePoint2);
mpVirtualDevice->DrawLine(aVerticalLinePoint1, aVerticalLinePoint2);
mpVirtualDevice->DrawLine(aDiagonalLinePoint1, aDiagonalLinePoint2);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestLine::setupAALines()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetAntialiasing(AntialiasingFlags::EnableB2dDraw);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
Point aHorizontalLinePoint1, aHorizontalLinePoint2;
Point aVerticalLinePoint1, aVerticalLinePoint2;
Point aDiagonalLinePoint1, aDiagonalLinePoint2;
OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
maVDRectangle, aHorizontalLinePoint1, aHorizontalLinePoint2,
aVerticalLinePoint1, aVerticalLinePoint2,
aDiagonalLinePoint1, aDiagonalLinePoint2);
mpVirtualDevice->DrawLine(aHorizontalLinePoint1, aHorizontalLinePoint2);
mpVirtualDevice->DrawLine(aVerticalLinePoint1, aVerticalLinePoint2);
mpVirtualDevice->DrawLine(aDiagonalLinePoint1, aDiagonalLinePoint2);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
}} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 {
namespace test {
Bitmap OutputDeviceTestAnotherOutDev::setupDrawOutDev()
{
ScopedVclPtrInstance<VirtualDevice> pSourceDev;
Size aSourceSize(9, 9);
pSourceDev->SetOutputSizePixel(aSourceSize);
pSourceDev->SetBackground(Wallpaper(constFillColor));
pSourceDev->Erase();
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->DrawOutDev(Point(2, 2), aSourceSize, Point(), aSourceSize, *pSourceDev.get());
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestAnotherOutDev::setupXOR()
{
initialSetup(13, 13, constBackgroundColor);
Rectangle aDrawRectangle(maVDRectangle);
aDrawRectangle.shrink(2);
Rectangle aScissorRectangle(maVDRectangle);
aScissorRectangle.shrink(4);
mpVirtualDevice->SetRasterOp(ROP_XOR);
mpVirtualDevice->SetFillColor(constFillColor);
mpVirtualDevice->DrawRect(aDrawRectangle);
mpVirtualDevice->SetRasterOp(ROP_0);
mpVirtualDevice->SetFillColor(COL_BLACK);
mpVirtualDevice->DrawRect(aScissorRectangle);
mpVirtualDevice->SetRasterOp(ROP_XOR);
mpVirtualDevice->SetFillColor(constFillColor);
mpVirtualDevice->DrawRect(aDrawRectangle);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
TestResult OutputDeviceTestAnotherOutDev::checkDrawOutDev(Bitmap& rBitmap)
{
return checkFilledRectangle(rBitmap);
}
TestResult OutputDeviceTestAnotherOutDev::checkXOR(Bitmap& rBitmap)
{
std::vector<Color> aExpected
{
constBackgroundColor, constBackgroundColor,
constBackgroundColor, constBackgroundColor,
constFillColor, constFillColor,
constFillColor
};
return checkRectangles(rBitmap, aExpected);
}
}} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 {
namespace test {
namespace
{
void drawPixelOffset(OutputDevice& rDevice, Rectangle& rRect, int nOffset)
{
for (long x = 0 + nOffset; x < (rRect.GetWidth() - nOffset); ++x)
{
long y1 = nOffset;
long y2 = rRect.GetHeight() - nOffset - 1;
rDevice.DrawPixel(Point(x, y1));
rDevice.DrawPixel(Point(x, y2));
}
for (long y = 0 + nOffset; y < (rRect.GetHeight() - nOffset); ++y)
{
long x1 = nOffset;
long x2 = rRect.GetWidth() - nOffset - 1;
rDevice.DrawPixel(Point(x1, y));
rDevice.DrawPixel(Point(x2, y));
}
}
} // end anonymous namespace
Bitmap OutputDeviceTestPixel::setupRectangle()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
drawPixelOffset(*mpVirtualDevice, maVDRectangle, 2);
drawPixelOffset(*mpVirtualDevice, maVDRectangle, 5);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
}} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 {
namespace test {
namespace
{
void drawPolygonOffset(OutputDevice& rDevice, Rectangle& rRect, int nOffset)
{
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.Optimize(PolyOptimizeFlags::CLOSE);
rDevice.DrawPolygon(aPolygon);
}
} // end anonymous namespace
Bitmap OutputDeviceTestPolygon::setupRectangle()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 2);
drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 5);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestPolygon::setupFilledRectangle()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constFillColor);
mpVirtualDevice->SetFillColor(constFillColor);
drawPolygonOffset(*mpVirtualDevice, maVDRectangle, 2);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestPolygon::setupDiamond()
{
initialSetup(11, 11, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
Point aPoint1, aPoint2, aPoint3, aPoint4;
OutputDeviceTestCommon::createDiamondPoints(maVDRectangle, 4, aPoint1, aPoint2, aPoint3, aPoint4);
tools::Polygon aPolygon(4);
aPolygon.SetPoint(aPoint1, 0);
aPolygon.SetPoint(aPoint2, 1);
aPolygon.SetPoint(aPoint3, 2);
aPolygon.SetPoint(aPoint4, 3);
aPolygon.Optimize(PolyOptimizeFlags::CLOSE);
mpVirtualDevice->DrawPolygon(aPolygon);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestPolygon::setupLines()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
Point aHorizontalLinePoint1, aHorizontalLinePoint2;
Point aVerticalLinePoint1, aVerticalLinePoint2;
Point aDiagonalLinePoint1, aDiagonalLinePoint2;
OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
maVDRectangle, aHorizontalLinePoint1, aHorizontalLinePoint2,
aVerticalLinePoint1, aVerticalLinePoint2,
aDiagonalLinePoint1, aDiagonalLinePoint2);
tools::Polygon aHorizontalPolygon(2);
aHorizontalPolygon.SetPoint(aHorizontalLinePoint1, 0);
aHorizontalPolygon.SetPoint(aHorizontalLinePoint2, 1);
mpVirtualDevice->DrawPolygon(aHorizontalPolygon);
tools::Polygon aVerticalPolygon(2);
aVerticalPolygon.SetPoint(aVerticalLinePoint1, 0);
aVerticalPolygon.SetPoint(aVerticalLinePoint2, 1);
mpVirtualDevice->DrawPolygon(aVerticalPolygon);
tools::Polygon aDiagonalPolygon(2);
aDiagonalPolygon.SetPoint(aDiagonalLinePoint1, 0);
aDiagonalPolygon.SetPoint(aDiagonalLinePoint2, 1);
mpVirtualDevice->DrawPolygon(aDiagonalPolygon);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestPolygon::setupAALines()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetAntialiasing(AntialiasingFlags::EnableB2dDraw);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
Point aHorizontalLinePoint1, aHorizontalLinePoint2;
Point aVerticalLinePoint1, aVerticalLinePoint2;
Point aDiagonalLinePoint1, aDiagonalLinePoint2;
OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
maVDRectangle, aHorizontalLinePoint1, aHorizontalLinePoint2,
aVerticalLinePoint1, aVerticalLinePoint2,
aDiagonalLinePoint1, aDiagonalLinePoint2);
tools::Polygon aHorizontalPolygon(2);
aHorizontalPolygon.SetPoint(aHorizontalLinePoint1, 0);
aHorizontalPolygon.SetPoint(aHorizontalLinePoint2, 1);
mpVirtualDevice->DrawPolygon(aHorizontalPolygon);
tools::Polygon aVerticalPolygon(2);
aVerticalPolygon.SetPoint(aVerticalLinePoint1, 0);
aVerticalPolygon.SetPoint(aVerticalLinePoint2, 1);
mpVirtualDevice->DrawPolygon(aVerticalPolygon);
tools::Polygon aDiagonalPolygon(2);
aDiagonalPolygon.SetPoint(aDiagonalLinePoint1, 0);
aDiagonalPolygon.SetPoint(aDiagonalLinePoint2, 1);
mpVirtualDevice->DrawPolygon(aDiagonalPolygon);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
}} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 {
namespace test {
namespace
{
void drawPolyLineOffset(OutputDevice& rDevice, Rectangle& rRect, int nOffset)
{
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.Optimize(PolyOptimizeFlags::CLOSE);
rDevice.DrawPolyLine(aPolygon);
}
} // end anonymous namespace
Bitmap OutputDeviceTestPolyLine::setupRectangle()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
drawPolyLineOffset(*mpVirtualDevice, maVDRectangle, 2);
drawPolyLineOffset(*mpVirtualDevice, maVDRectangle, 5);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestPolyLine::setupDiamond()
{
initialSetup(11, 11, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
Point aPoint1, aPoint2, aPoint3, aPoint4;
OutputDeviceTestCommon::createDiamondPoints(maVDRectangle, 4, aPoint1, aPoint2, aPoint3, aPoint4);
tools::Polygon aPolygon(4);
aPolygon.SetPoint(aPoint1, 0);
aPolygon.SetPoint(aPoint2, 1);
aPolygon.SetPoint(aPoint3, 2);
aPolygon.SetPoint(aPoint4, 3);
aPolygon.Optimize(PolyOptimizeFlags::CLOSE);
mpVirtualDevice->DrawPolyLine(aPolygon);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestPolyLine::setupLines()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
Point aHorizontalLinePoint1, aHorizontalLinePoint2;
Point aVerticalLinePoint1, aVerticalLinePoint2;
Point aDiagonalLinePoint1, aDiagonalLinePoint2;
OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
maVDRectangle, aHorizontalLinePoint1, aHorizontalLinePoint2,
aVerticalLinePoint1, aVerticalLinePoint2,
aDiagonalLinePoint1, aDiagonalLinePoint2);
tools::Polygon aHorizontalPolygon(2);
aHorizontalPolygon.SetPoint(aHorizontalLinePoint1, 0);
aHorizontalPolygon.SetPoint(aHorizontalLinePoint2, 1);
mpVirtualDevice->DrawPolyLine(aHorizontalPolygon);
tools::Polygon aVerticalPolygon(2);
aVerticalPolygon.SetPoint(aVerticalLinePoint1, 0);
aVerticalPolygon.SetPoint(aVerticalLinePoint2, 1);
mpVirtualDevice->DrawPolyLine(aVerticalPolygon);
tools::Polygon aDiagonalPolygon(2);
aDiagonalPolygon.SetPoint(aDiagonalLinePoint1, 0);
aDiagonalPolygon.SetPoint(aDiagonalLinePoint2, 1);
mpVirtualDevice->DrawPolyLine(aDiagonalPolygon);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestPolyLine::setupAALines()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetAntialiasing(AntialiasingFlags::EnableB2dDraw);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
Point aHorizontalLinePoint1, aHorizontalLinePoint2;
Point aVerticalLinePoint1, aVerticalLinePoint2;
Point aDiagonalLinePoint1, aDiagonalLinePoint2;
OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(
maVDRectangle, aHorizontalLinePoint1, aHorizontalLinePoint2,
aVerticalLinePoint1, aVerticalLinePoint2,
aDiagonalLinePoint1, aDiagonalLinePoint2);
tools::Polygon aHorizontalPolygon(2);
aHorizontalPolygon.SetPoint(aHorizontalLinePoint1, 0);
aHorizontalPolygon.SetPoint(aHorizontalLinePoint2, 1);
mpVirtualDevice->DrawPolyLine(aHorizontalPolygon);
tools::Polygon aVerticalPolygon(2);
aVerticalPolygon.SetPoint(aVerticalLinePoint1, 0);
aVerticalPolygon.SetPoint(aVerticalLinePoint2, 1);
mpVirtualDevice->DrawPolyLine(aVerticalPolygon);
tools::Polygon aDiagonalPolygon(2);
aDiagonalPolygon.SetPoint(aDiagonalLinePoint1, 0);
aDiagonalPolygon.SetPoint(aDiagonalLinePoint2, 1);
mpVirtualDevice->DrawPolyLine(aDiagonalPolygon);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
}} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 {
namespace test {
namespace
{
tools::Polygon createPolygonOffset(Rectangle& rRect, int nOffset)
{
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.Optimize(PolyOptimizeFlags::CLOSE);
return aPolygon;
}
} // end anonymous namespace
Bitmap OutputDeviceTestPolyPolygon::setupRectangle()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
tools::PolyPolygon aPolyPolygon(2);
aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 2));
aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 5));
mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestPolyPolygon::setupFilledRectangle()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constFillColor);
mpVirtualDevice->SetFillColor(constFillColor);
tools::PolyPolygon aPolyPolygon(3);
aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 2));
aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 4));
aPolyPolygon.Insert(createPolygonOffset(maVDRectangle, 4));
mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
}} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 {
namespace test {
namespace
{
void drawRectOffset(OutputDevice& rDevice, Rectangle& rRect, int nOffset)
{
rDevice.DrawRect(Rectangle(rRect.Left() + nOffset, rRect.Top() + nOffset,
rRect.Right() - nOffset, rRect.Bottom() - nOffset));
}
} // end anonymous namespace
Bitmap OutputDeviceTestRect::setupFilledRectangle()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constFillColor);
mpVirtualDevice->SetFillColor(constFillColor);
drawRectOffset(*mpVirtualDevice, maVDRectangle, 2);
drawRectOffset(*mpVirtualDevice, maVDRectangle, 5);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
Bitmap OutputDeviceTestRect::setupRectangle()
{
initialSetup(13, 13, constBackgroundColor);
mpVirtualDevice->SetLineColor(constLineColor);
mpVirtualDevice->SetFillColor();
drawRectOffset(*mpVirtualDevice, maVDRectangle, 2);
drawRectOffset(*mpVirtualDevice, maVDRectangle, 5);
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
}} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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/.
*
*/
#ifndef INCLUDED_VCL_OUTDEVTESTS_HXX
#define INCLUDED_VCL_OUTDEVTESTS_HXX
#include <vcl/virdev.hxx>
#include <vcl/bitmapaccess.hxx>
namespace vcl {
namespace test {
/** Rendering test result.
*
* Test either "Passed", "Failed" or "PassedWithQuirks" which means
* the test passed but at least one rendering quirk was detected.
*/
enum class TestResult
{
Failed,
PassedWithQuirks,
Passed
};
/** Common subclass for output device rendering tests.
*/
class VCL_DLLPUBLIC OutputDeviceTestCommon
{
protected:
ScopedVclPtr<VirtualDevice> mpVirtualDevice;
Rectangle maVDRectangle;
static const Color constBackgroundColor;
static const Color constLineColor;
static const Color constFillColor;
public:
OutputDeviceTestCommon();
void initialSetup(long nWidth, long nHeight, Color aColor);
static TestResult checkRectangle(Bitmap& rBitmap);
static TestResult checkFilledRectangle(Bitmap& rBitmap);
static TestResult checkLines(Bitmap& rBitmap);
static TestResult checkAALines(Bitmap& rBitmap);
static TestResult checkDiamond(Bitmap& rBitmap);
static TestResult checkRectangles(Bitmap& rBitmap, std::vector<Color>& aExpectedColors);
static void createDiamondPoints(Rectangle rRect, int nOffset,
Point& rPoint1, Point& rPoint2,
Point& rPoint3, Point& rPoint4);
static void createHorizontalVerticalDiagonalLinePoints(Rectangle rRect,
Point& rHorizontalLinePoint1, Point& rHorizontalLinePoint2,
Point& rVerticalLinePoint1, Point& rVerticalLinePoint2,
Point& rDiagonalLinePoint1, Point& rDiagonalLinePoint2);
// tools
static Rectangle alignToCenter(Rectangle aRect1, Rectangle aRect2);
};
class VCL_DLLPUBLIC OutputDeviceTestBitmap : public OutputDeviceTestCommon
{
public:
OutputDeviceTestBitmap() = default;
Bitmap setupDrawTransformedBitmap();
Bitmap setupDrawBitmap();
Bitmap setupDrawBitmapExWithAlpha();
Bitmap setupDrawMask();
static TestResult checkBitmap(Bitmap& rBitmap);
static TestResult checkTransformedBitmap(Bitmap& rBitmap);
static TestResult checkBitmapExWithAlpha(Bitmap& rBitmap);
static TestResult checkMask(Bitmap& rBitmap);
};
class VCL_DLLPUBLIC OutputDeviceTestAnotherOutDev : public OutputDeviceTestCommon
{
public:
OutputDeviceTestAnotherOutDev() = default;
Bitmap setupDrawOutDev();
Bitmap setupXOR();
static TestResult checkDrawOutDev(Bitmap& rBitmap);
static TestResult checkXOR(Bitmap& rBitmap);
};
class VCL_DLLPUBLIC OutputDeviceTestPixel : public OutputDeviceTestCommon
{
public:
OutputDeviceTestPixel() = default;
Bitmap setupRectangle();
};
class VCL_DLLPUBLIC OutputDeviceTestLine : public OutputDeviceTestCommon
{
public:
OutputDeviceTestLine() = default;
Bitmap setupRectangle();
Bitmap setupDiamond();
Bitmap setupLines();
Bitmap setupAALines();
};
class VCL_DLLPUBLIC OutputDeviceTestPolyLine : public OutputDeviceTestCommon
{
public:
OutputDeviceTestPolyLine() = default;
Bitmap setupRectangle();
Bitmap setupDiamond();
Bitmap setupLines();
Bitmap setupAALines();
};
class VCL_DLLPUBLIC OutputDeviceTestRect : public OutputDeviceTestCommon
{
public:
OutputDeviceTestRect() = default;
Bitmap setupFilledRectangle();
Bitmap setupRectangle();
};
class VCL_DLLPUBLIC OutputDeviceTestPolygon : public OutputDeviceTestCommon
{
public:
OutputDeviceTestPolygon() = default;
Bitmap setupFilledRectangle();
Bitmap setupRectangle();
Bitmap setupDiamond();
Bitmap setupLines();
Bitmap setupAALines();
};
class VCL_DLLPUBLIC OutputDeviceTestPolyPolygon : public OutputDeviceTestCommon
{
public:
OutputDeviceTestPolyPolygon() = default;
Bitmap setupFilledRectangle();
Bitmap setupRectangle();
};
class VCL_DLLPUBLIC OutputDeviceTestGradient : public OutputDeviceTestCommon
{
public:
OutputDeviceTestGradient() = default;
Bitmap setupLinearGradient();
Bitmap setupRadialGradient();
};
}} // end namespace vcl::test
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment