summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2020-08-31 15:48:42 +0200
committerCaolán McNamara <caolanm@redhat.com>2020-09-02 10:15:30 +0200
commit51771f90a115ff30ebebb3c14f1df20bb1efba12 (patch)
treea5667eb36448b9e0a548763a8bd97eb547737303 /vcl
parentad438942a43141f8530e70552dda06df2a371c9d (diff)
no polygon merge in Skia if they contain no straight lines (tdf#136240)
Merging polygons with beziers is even more expensive, and those are very unlikely to be parts of a larger polygon that are meant to line up perfectly. Change-Id: Ic9d641d3264b962896347ed52addeca2a0d5ea22 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101742 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com> (cherry picked from commit 7957a3c6ab6ba4b61b0a237b680e6393029cc426) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101859 Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/skia/gdiimpl.cxx53
1 files changed, 53 insertions, 0 deletions
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index 9eefb5e814d8..2cd92c5412ba 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -127,6 +127,54 @@ void addPolyPolygonToPath(const basegfx::B2DPolyPolygon& rPolyPolygon, SkPath& r
}
}
+// Check if the given polygon contains a straight line. If not, it consists
+// solely of curves.
+bool polygonContainsLine(const basegfx::B2DPolyPolygon& rPolyPolygon)
+{
+ if (!rPolyPolygon.areControlPointsUsed())
+ return true; // no curves at all
+ for (const auto& rPolygon : rPolyPolygon)
+ {
+ const sal_uInt32 nPointCount(rPolygon.count());
+ bool bFirst = true;
+
+ const bool bClosePath(rPolygon.isClosed());
+
+ sal_uInt32 nCurrentIndex = 0;
+ sal_uInt32 nPreviousIndex = nPointCount - 1;
+
+ basegfx::B2DPoint aCurrentPoint;
+ basegfx::B2DPoint aPreviousPoint;
+
+ for (sal_uInt32 nIndex = 0; nIndex <= nPointCount; nIndex++)
+ {
+ if (nIndex == nPointCount && !bClosePath)
+ continue;
+
+ // Make sure we loop the last point to first point
+ nCurrentIndex = nIndex % nPointCount;
+ if (bFirst)
+ bFirst = false;
+ else
+ {
+ basegfx::B2DPoint aPreviousControlPoint
+ = rPolygon.getNextControlPoint(nPreviousIndex);
+ basegfx::B2DPoint aCurrentControlPoint
+ = rPolygon.getPrevControlPoint(nCurrentIndex);
+
+ if (aPreviousControlPoint.equal(aPreviousPoint)
+ && aCurrentControlPoint.equal(aCurrentPoint))
+ {
+ return true; // found a straight line
+ }
+ }
+ aPreviousPoint = aCurrentPoint;
+ nPreviousIndex = nCurrentIndex;
+ }
+ }
+ return false; // no straight line found
+}
+
SkColor toSkColor(Color color)
{
return SkColorSetARGB(255 - color.GetTransparency(), color.GetRed(), color.GetGreen(),
@@ -810,6 +858,11 @@ bool SkiaSalGraphicsImpl::delayDrawPolyPolygon(const basegfx::B2DPolyPolygon& aP
// so they do not need joining.
if (aPolyPolygon.count() != 1)
return false;
+ // If a polygon does not contain a straight line, i.e. it's all curves, then do not merge.
+ // First of all that's even more expensive, and second it's very unlikely that it's a polygon
+ // split into more polygons.
+ if (!polygonContainsLine(aPolyPolygon))
+ return false;
if (mLastPolyPolygonInfo.polygons.size() != 0
&& (mLastPolyPolygonInfo.transparency != fTransparency