Kaydet (Commit) 75e152a7 authored tarafından Miklos Vajna's avatar Miklos Vajna

tdf#107966 vcl opengl: fix not drawn 1px wide polypolygons

Visible at e.g. in Calc: Format Cells/Borders/Line Styles.

The problem was that first commit
2e99e4e1 (opengl: use MVP matrix in
vertex shaders, pixel offsets, 2015-07-08) introduced the concept of
pixel offsets, setting the value (implicitly) to 0 in
OpenGLSalGraphicsImpl::DrawTrapezoid(), but using 0.5 in
OpenGLSalGraphicsImpl::FlushLinesOrTriangles().

This is fine, but then later commit
2003076c (opengl: batch draw
polypolygons, 2016-05-29) changed
OpenGLSalGraphicsImpl::drawPolyPolygon() to use deferred drawing instead
of DrawTrapezoid(), without doing any translation of the input
polypolygon. This resulted in loss of those polygons when used in the
above mentioned dialog, which has a listbox of bitmaps, where each line
style preview is drawn on a virtual device with a height of 1px. So at
the end the 1px offset meant the previews were simply missing.

('make CppunitTest_vcl_gen SAL_USE_VCLPLUGIN=gen SAL_FORCEGL=1' is
needed on Linux to see the test failing without the fix.)

Change-Id: Ia9f3d6e7cb38a43fe2f8a41746b538af68add43c
Reviewed-on: https://gerrit.libreoffice.org/69920Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst 6c29dbb7
...@@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_gen, \ ...@@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_gen, \
)) ))
$(eval $(call gb_CppunitTest_use_libraries,vcl_gen, \ $(eval $(call gb_CppunitTest_use_libraries,vcl_gen, \
basegfx \
comphelper \ comphelper \
cppu \ cppu \
cppuhelper \ cppuhelper \
......
...@@ -1606,6 +1606,11 @@ bool OpenGLSalGraphicsImpl::drawPolyPolygon( ...@@ -1606,6 +1606,11 @@ bool OpenGLSalGraphicsImpl::drawPolyPolygon(
basegfx::B2DPolyPolygon aPolyPolygon(rPolyPolygon); basegfx::B2DPolyPolygon aPolyPolygon(rPolyPolygon);
aPolyPolygon.transform(rObjectToDevice); aPolyPolygon.transform(rObjectToDevice);
// FlushLinesOrTriangles() works with a 0.5 pixel offset, compensate for that here.
basegfx::B2DHomMatrix aMatrix;
aMatrix.translate(-0.5f, -0.5f);
aPolyPolygon.transform(aMatrix);
mpRenderList->addDrawPolyPolygon( mpRenderList->addDrawPolyPolygon(
aPolyPolygon, aPolyPolygon,
fTransparency, fTransparency,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <vcl/bitmapaccess.hxx> #include <vcl/bitmapaccess.hxx>
#include <vcl/pngwrite.hxx> #include <vcl/pngwrite.hxx>
#include <vcl/gdimtf.hxx> #include <vcl/gdimtf.hxx>
#include <vcl/virdev.hxx>
#include <tools/stream.hxx> #include <tools/stream.hxx>
using namespace com::sun::star; using namespace com::sun::star;
...@@ -72,13 +73,46 @@ CPPUNIT_TEST_FIXTURE(GenTest, testTdf121120) ...@@ -72,13 +73,46 @@ CPPUNIT_TEST_FIXTURE(GenTest, testTdf121120)
const Size& rSize = aBitmap.GetPrefSize(); const Size& rSize = aBitmap.GetPrefSize();
Color aColor(pAccess->GetPixel(rSize.getWidth() / 2, rSize.getHeight() / 2).GetColor()); Color aColor(pAccess->GetPixel(rSize.getWidth() / 2, rSize.getHeight() / 2).GetColor());
// Without the accompanying fix in place, this test would have failed with 'Expected: 255; // Without the accompanying fix in place, this test would have failed with 'Expected: 255;
// Actual : 1'. I.e. center if the preview (which has the background color) was ~black, not // Actual : 1'. I.e. center of the preview (which has the background color) was ~black, not
// white. // white.
CPPUNIT_ASSERT_EQUAL(0xff, int(aColor.GetRed())); CPPUNIT_ASSERT_EQUAL(0xff, int(aColor.GetRed()));
CPPUNIT_ASSERT_EQUAL(0xff, int(aColor.GetBlue())); CPPUNIT_ASSERT_EQUAL(0xff, int(aColor.GetBlue()));
CPPUNIT_ASSERT_EQUAL(0xff, int(aColor.GetGreen())); CPPUNIT_ASSERT_EQUAL(0xff, int(aColor.GetGreen()));
} }
/// Test that drawing a line preview to a bitmap is not lost.
CPPUNIT_TEST_FIXTURE(GenTest, testTdf107966)
{
// Set up the virtual device: white background.
ScopedVclPtr<VirtualDevice> pVirtualDevice(VclPtr<VirtualDevice>::Create());
pVirtualDevice->SetLineColor();
MapMode aMapMode;
aMapMode.SetMapUnit(MapUnit::MapTwip);
pVirtualDevice->SetMapMode(aMapMode);
pVirtualDevice->SetOutputSizePixel(Size(90, 15));
pVirtualDevice->SetFillColor(Color(255, 255, 255));
pVirtualDevice->DrawRect(tools::Rectangle(Point(), Size(1350, 225)));
pVirtualDevice->SetFillColor(Color(0, 0, 0));
AntialiasingFlags nOldAA = pVirtualDevice->GetAntialiasing();
pVirtualDevice->SetAntialiasing(nOldAA & ~AntialiasingFlags::EnableB2dDraw);
// Paint a black polygon on it.
basegfx::B2DPolygon aPolygon;
aPolygon.append(basegfx::B2DPoint(0, 15));
aPolygon.append(basegfx::B2DPoint(1350, 15));
aPolygon.append(basegfx::B2DPoint(1350, 0));
aPolygon.append(basegfx::B2DPoint(0, 0));
pVirtualDevice->DrawPolygon(aPolygon);
// Make sure that the polygon is visible.
Bitmap aBitmap = pVirtualDevice->GetBitmap(Point(), Size(1350, 15));
Bitmap::ScopedReadAccess pAccess(aBitmap);
Color aPixel(pAccess->GetPixel(0, 0).GetColor());
// Without the accompanying fix in place, this test would have failed with 'Expected: 000000;
// Actual: ffffff', i.e. the top left pixel was white, not black.
CPPUNIT_ASSERT_EQUAL(OUString("000000"), aPixel.AsRGBHexString());
}
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* 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