[Libreoffice-commits] core.git: vcl/headless

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Tue Jan 7 09:06:29 UTC 2020


 vcl/headless/svpgdi.cxx |   97 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 64 insertions(+), 33 deletions(-)

New commits:
commit cebeafbf0f9efde6e17604cf2557b8490e7f5347
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Jan 6 20:49:40 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 7 10:05:59 2020 +0100

    tdf#129845 vcl: avoid expensive system caching of trivial lines & polygons
    
    Interestingly the cache map lookup is rather expensive; why:
    
    polyline output for some trivial impress edits:
            count   # of polylines
            2       2134
            3       141
            4       41
            9       4
    
    polypolygon output for some trivial impress edits:
    
            count   # of polypolygons       geometry.
            3       54    all single polygon
            4       583   ~all single
            9       52    ~ all paired with a 4 node polygon
            13      2     both single
            32      22    all single
    
    Change-Id: I15c0053a84399eaf153b2119b2c28d1f168f16b1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86314
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index 1bd55104c491..c792bb98a6b8 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -119,6 +119,18 @@ namespace
         aDamageRect.intersect(getClipBox(cr));
         return aDamageRect;
     }
+
+    // The caching logic is surprsingly expensive - so avoid it sometimes.
+    inline bool isTrivial(const basegfx::B2DPolyPolygon& rPolyPolygon)
+    {
+        return rPolyPolygon.count() == 1 && rPolyPolygon.begin()->count() <= 4;
+    }
+
+    // The caching logic is surprsingly expensive - so avoid it sometimes.
+    inline bool isTrivial(const basegfx::B2DPolygon& rPolyLine)
+    {
+        return rPolyLine.count() <= 4;
+    }
 }
 
 bool SvpSalGraphics::blendBitmap( const SalTwoRect&, const SalBitmap& /*rBitmap*/ )
@@ -1279,29 +1291,37 @@ bool SvpSalGraphics::drawPolyLine(
     cairo_set_line_width(cr, aLineWidths.getX());
     cairo_set_miter_limit(cr, fMiterLimit);
 
-    // try to access buffered data
-    std::shared_ptr<SystemDependentData_CairoPath> pSystemDependentData_CairoPath(
-        rPolyLine.getSystemDependentData<SystemDependentData_CairoPath>());
+    bool bDone = false;
+    bool bIsTrivial = isTrivial(rPolyLine);
 
-    if(pSystemDependentData_CairoPath)
+    if (!bIsTrivial)
     {
-        // check data validity
-        if(nullptr == pSystemDependentData_CairoPath->getCairoPath()
-            || pSystemDependentData_CairoPath->getNoJoin() != bNoJoin
-            || pSystemDependentData_CairoPath->getAntiAliasB2DDraw() != bAntiAliasB2DDraw
-            || bPixelSnapHairline /*tdf#124700*/ )
+        // try to access buffered data
+        std::shared_ptr<SystemDependentData_CairoPath> pSystemDependentData_CairoPath(
+            rPolyLine.getSystemDependentData<SystemDependentData_CairoPath>());
+
+        if(pSystemDependentData_CairoPath)
         {
-            // data invalid, forget
-            pSystemDependentData_CairoPath.reset();
+            // check data validity
+            if(nullptr == pSystemDependentData_CairoPath->getCairoPath()
+               || pSystemDependentData_CairoPath->getNoJoin() != bNoJoin
+               || pSystemDependentData_CairoPath->getAntiAliasB2DDraw() != bAntiAliasB2DDraw
+               || bPixelSnapHairline /*tdf#124700*/ )
+            {
+                // data invalid, forget
+                pSystemDependentData_CairoPath.reset();
+            }
         }
-    }
 
-    if(pSystemDependentData_CairoPath)
-    {
-        // re-use data
-        cairo_append_path(cr, pSystemDependentData_CairoPath->getCairoPath());
+        if(pSystemDependentData_CairoPath)
+        {
+            // re-use data
+            cairo_append_path(cr, pSystemDependentData_CairoPath->getCairoPath());
+            bDone = true;
+        }
     }
-    else
+
+    if (!bDone)
     {
         // create data
         if (!bNoJoin)
@@ -1344,9 +1364,9 @@ bool SvpSalGraphics::drawPolyLine(
         }
 
         // copy and add to buffering mechanism
-        if (!bPixelSnapHairline /*tdf#124700*/)
+        if (!bIsTrivial && !bPixelSnapHairline /*tdf#124700*/)
         {
-            pSystemDependentData_CairoPath = rPolyLine.addOrReplaceSystemDependentData<SystemDependentData_CairoPath>(
+            rPolyLine.addOrReplaceSystemDependentData<SystemDependentData_CairoPath>(
                 ImplGetSystemDependentDataManager(),
                 cairo_copy_path(cr),
                 bNoJoin,
@@ -1397,16 +1417,24 @@ namespace
 {
     void add_polygon_path(cairo_t* cr, const basegfx::B2DPolyPolygon& rPolyPolygon, const basegfx::B2DHomMatrix& rObjectToDevice, bool bPixelSnap)
     {
-        // try to access buffered data
-        std::shared_ptr<SystemDependentData_CairoPath> pSystemDependentData_CairoPath(
-            rPolyPolygon.getSystemDependentData<SystemDependentData_CairoPath>());
+        bool bDone = false;
+        bool bIsTrivial = isTrivial(rPolyPolygon);
 
-        if(pSystemDependentData_CairoPath)
+        if (!bIsTrivial)
         {
-            // re-use data
-            cairo_append_path(cr, pSystemDependentData_CairoPath->getCairoPath());
+            // try to access buffered data
+            std::shared_ptr<SystemDependentData_CairoPath> pSystemDependentData_CairoPath(
+                rPolyPolygon.getSystemDependentData<SystemDependentData_CairoPath>());
+
+            if(pSystemDependentData_CairoPath)
+            {
+                // re-use data
+                cairo_append_path(cr, pSystemDependentData_CairoPath->getCairoPath());
+                bDone = true;
+            }
         }
-        else
+
+        if (!bDone)
         {
             // create data
             for (const auto & rPoly : rPolyPolygon)
@@ -1421,13 +1449,16 @@ namespace
                     false);
             }
 
-            // copy and add to buffering mechanism
-            // for decisions how/what to buffer, see Note in WinSalGraphicsImpl::drawPolyPolygon
-            pSystemDependentData_CairoPath = rPolyPolygon.addOrReplaceSystemDependentData<SystemDependentData_CairoPath>(
-                ImplGetSystemDependentDataManager(),
-                cairo_copy_path(cr),
-                false,
-                false);
+            if (!bIsTrivial)
+            {
+                // copy and add to buffering mechanism
+                // for decisions how/what to buffer, see Note in WinSalGraphicsImpl::drawPolyPolygon
+                rPolyPolygon.addOrReplaceSystemDependentData<SystemDependentData_CairoPath>(
+                    ImplGetSystemDependentDataManager(),
+                    cairo_copy_path(cr),
+                    false,
+                    false);
+            }
         }
     }
 }


More information about the Libreoffice-commits mailing list