Title: [188987] trunk/Source/WebCore
Revision
188987
Author
ander...@apple.com
Date
2015-08-26 13:44:04 -0700 (Wed, 26 Aug 2015)

Log Message

Use WorkQueue::concurrentApply in FEConvolveMatrix
https://bugs.webkit.org/show_bug.cgi?id=148490

Reviewed by Tim Horton.

Using WorkQueue::concurrentApply lets us simplify the code a lot, and measurements show
no difference in performance. The striding has been slightly tweaked to make more sense
(we no longer divide up the remainder across some of the iterations, instead we just process
it separately last).

* platform/graphics/filters/FEConvolveMatrix.cpp:
(WebCore::FEConvolveMatrix::platformApplySoftware):
(WebCore::FEConvolveMatrix::setInteriorPixelsWorker): Deleted.
* platform/graphics/filters/FEConvolveMatrix.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (188986 => 188987)


--- trunk/Source/WebCore/ChangeLog	2015-08-26 20:43:35 UTC (rev 188986)
+++ trunk/Source/WebCore/ChangeLog	2015-08-26 20:44:04 UTC (rev 188987)
@@ -1,3 +1,20 @@
+2015-08-26  Anders Carlsson  <ander...@apple.com>
+
+        Use WorkQueue::concurrentApply in FEConvolveMatrix
+        https://bugs.webkit.org/show_bug.cgi?id=148490
+
+        Reviewed by Tim Horton.
+
+        Using WorkQueue::concurrentApply lets us simplify the code a lot, and measurements show
+        no difference in performance. The striding has been slightly tweaked to make more sense
+        (we no longer divide up the remainder across some of the iterations, instead we just process 
+        it separately last).
+
+        * platform/graphics/filters/FEConvolveMatrix.cpp:
+        (WebCore::FEConvolveMatrix::platformApplySoftware):
+        (WebCore::FEConvolveMatrix::setInteriorPixelsWorker): Deleted.
+        * platform/graphics/filters/FEConvolveMatrix.h:
+
 2015-08-26  Eric Carlson  <eric.carl...@apple.com>
 
         Media Session: make MediaSessionMetadata a class

Modified: trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp (188986 => 188987)


--- trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp	2015-08-26 20:43:35 UTC (rev 188986)
+++ trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp	2015-08-26 20:44:04 UTC (rev 188987)
@@ -29,6 +29,7 @@
 
 #include <runtime/Uint8ClampedArray.h>
 #include <wtf/ParallelJobs.h>
+#include <wtf/WorkQueue.h>
 
 namespace WebCore {
 
@@ -408,11 +409,6 @@
         fastSetOuterPixels<false>(paintingData, x1, y1, x2, y2);
 }
 
-void FEConvolveMatrix::setInteriorPixelsWorker(InteriorPixelParameters* param)
-{
-    param->filter->setInteriorPixels(*param->paintingData, param->clipRight, param->clipBottom, param->yStart, param->yEnd);
-}
-
 void FEConvolveMatrix::platformApplySoftware()
 {
     FilterEffect* in = inputEffect(0);
@@ -445,50 +441,33 @@
     int clipRight = paintSize.width() - m_kernelSize.width();
     int clipBottom = paintSize.height() - m_kernelSize.height();
 
-    if (clipRight >= 0 && clipBottom >= 0) {
+    if (clipRight < 0 || clipBottom < 0) {
+        // Rare situation, not optimizied for speed
+        setOuterPixels(paintingData, 0, 0, paintSize.width(), paintSize.height());
+        return;
+    }
 
-        int optimalThreadNumber = (absolutePaintRect().width() * absolutePaintRect().height()) / s_minimalRectDimension;
-        if (optimalThreadNumber > 1) {
-            WTF::ParallelJobs<InteriorPixelParameters> parallelJobs(&WebCore::FEConvolveMatrix::setInteriorPixelsWorker, optimalThreadNumber);
-            const int numOfThreads = parallelJobs.numberOfJobs();
+    int iterations = (absolutePaintRect().width() * absolutePaintRect().height()) / s_minimalRectDimension;
+    int stride = clipBottom / iterations;
+    int chunkCount = (clipBottom + stride - 1) / stride;
 
-            // Split the job into "heightPerThread" jobs but there a few jobs that need to be slightly larger since
-            // heightPerThread * jobs < total size. These extras are handled by the remainder "jobsWithExtra".
-            const int heightPerThread = clipBottom / numOfThreads;
-            const int jobsWithExtra = clipBottom % numOfThreads;
+    WorkQueue::concurrentApply(chunkCount, [&](size_t index) {
+        int yStart = (stride * index);
+        int yEnd = std::min<int>(stride * (index + 1), clipBottom);
 
-            int startY = 0;
-            for (int job = 0; job < numOfThreads; ++job) {
-                InteriorPixelParameters& param = parallelJobs.parameter(job);
-                param.filter = this;
-                param.paintingData = &paintingData;
-                param.clipRight = clipRight;
-                param.clipBottom = clipBottom;
-                param.yStart = startY;
-                startY += job < jobsWithExtra ? heightPerThread + 1 : heightPerThread;
-                param.yEnd = startY;
-            }
+        setInteriorPixels(paintingData, clipRight, clipBottom, yStart, yEnd);
+    });
 
-            parallelJobs.execute();
-        } else {
-            // Fallback to single threaded mode.
-            setInteriorPixels(paintingData, clipRight, clipBottom, 0, clipBottom);
-        }
-
-        clipRight += m_targetOffset.x() + 1;
-        clipBottom += m_targetOffset.y() + 1;
-        if (m_targetOffset.y() > 0)
-            setOuterPixels(paintingData, 0, 0, paintSize.width(), m_targetOffset.y());
-        if (clipBottom < paintSize.height())
-            setOuterPixels(paintingData, 0, clipBottom, paintSize.width(), paintSize.height());
-        if (m_targetOffset.x() > 0)
-            setOuterPixels(paintingData, 0, m_targetOffset.y(), m_targetOffset.x(), clipBottom);
-        if (clipRight < paintSize.width())
-            setOuterPixels(paintingData, clipRight, m_targetOffset.y(), paintSize.width(), clipBottom);
-    } else {
-        // Rare situation, not optimizied for speed
-        setOuterPixels(paintingData, 0, 0, paintSize.width(), paintSize.height());
-    }
+    clipRight += m_targetOffset.x() + 1;
+    clipBottom += m_targetOffset.y() + 1;
+    if (m_targetOffset.y() > 0)
+        setOuterPixels(paintingData, 0, 0, paintSize.width(), m_targetOffset.y());
+    if (clipBottom < paintSize.height())
+        setOuterPixels(paintingData, 0, clipBottom, paintSize.width(), paintSize.height());
+    if (m_targetOffset.x() > 0)
+        setOuterPixels(paintingData, 0, m_targetOffset.y(), m_targetOffset.x(), clipBottom);
+    if (clipRight < paintSize.width())
+        setOuterPixels(paintingData, clipRight, m_targetOffset.y(), paintSize.width(), clipBottom);
 }
 
 void FEConvolveMatrix::dump()

Modified: trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.h (188986 => 188987)


--- trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.h	2015-08-26 20:43:35 UTC (rev 188986)
+++ trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.h	2015-08-26 20:44:04 UTC (rev 188987)
@@ -103,20 +103,6 @@
     // Parallelization parts
     static const int s_minimalRectDimension = (100 * 100); // Empirical data limit for parallel jobs
 
-    template<typename Type>
-    friend class ParallelJobs;
-
-    struct InteriorPixelParameters {
-        FEConvolveMatrix* filter;
-        PaintingData* paintingData;
-        int clipBottom;
-        int clipRight;
-        int yStart;
-        int yEnd;
-    };
-
-    static void setInteriorPixelsWorker(InteriorPixelParameters*);
-
     IntSize m_kernelSize;
     float m_divisor;
     float m_bias;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to