[Libreoffice-commits] core.git: Branch 'libreoffice-7-0' - vcl/skia

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 2 08:16:03 UTC 2020


 vcl/skia/gdiimpl.cxx |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

New commits:
commit 51771f90a115ff30ebebb3c14f1df20bb1efba12
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Mon Aug 31 15:48:42 2020 +0200
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Sep 2 10:15:30 2020 +0200

    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 at collabora.com>
    (cherry picked from commit 7957a3c6ab6ba4b61b0a237b680e6393029cc426)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101859
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

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


More information about the Libreoffice-commits mailing list