Title: [96407] trunk/Source/WebCore
Revision
96407
Author
[email protected]
Date
2011-09-30 11:09:14 -0700 (Fri, 30 Sep 2011)

Log Message

feBlend uses a table of function pointers which reduces inlineability inside the main loop
https://bugs.webkit.org/show_bug.cgi?id=69154
<rdar://problem/10215221>

Reviewed by Darin Adler.

Don't use a table of function pointers inside the feBlend inner loop, instead
use switch and inline functions, bringing a 20% performance gain across the
board to feBlend.

No new tests, minor performance improvement.

* platform/graphics/filters/FEBlend.cpp:
(WebCore::normal):
(WebCore::multiply):
(WebCore::screen):
(WebCore::darken):
(WebCore::lighten):
(WebCore::FEBlend::apply):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (96406 => 96407)


--- trunk/Source/WebCore/ChangeLog	2011-09-30 17:59:15 UTC (rev 96406)
+++ trunk/Source/WebCore/ChangeLog	2011-09-30 18:09:14 UTC (rev 96407)
@@ -1,3 +1,25 @@
+2011-09-30  Tim Horton  <[email protected]>
+
+        feBlend uses a table of function pointers which reduces inlineability inside the main loop
+        https://bugs.webkit.org/show_bug.cgi?id=69154
+        <rdar://problem/10215221>
+
+        Reviewed by Darin Adler.
+
+        Don't use a table of function pointers inside the feBlend inner loop, instead
+        use switch and inline functions, bringing a 20% performance gain across the
+        board to feBlend.
+
+        No new tests, minor performance improvement.
+
+        * platform/graphics/filters/FEBlend.cpp:
+        (WebCore::normal):
+        (WebCore::multiply):
+        (WebCore::screen):
+        (WebCore::darken):
+        (WebCore::lighten):
+        (WebCore::FEBlend::apply):
+
 2011-09-30  Mark Hahnenberg  <[email protected]>
 
         Add getCallData to MethodTable in ClassInfo

Modified: trunk/Source/WebCore/platform/graphics/filters/FEBlend.cpp (96406 => 96407)


--- trunk/Source/WebCore/platform/graphics/filters/FEBlend.cpp	2011-09-30 17:59:15 UTC (rev 96406)
+++ trunk/Source/WebCore/platform/graphics/filters/FEBlend.cpp	2011-09-30 18:09:14 UTC (rev 96407)
@@ -61,32 +61,27 @@
     return true;
 }
 
-static unsigned char unknown(unsigned char, unsigned char, unsigned char, unsigned char)
+static inline unsigned char normal(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char)
 {
-    return 0;
-}
-
-static unsigned char normal(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char)
-{
     return (((255 - alphaA) * colorB + colorA * 255) / 255);
 }
 
-static unsigned char multiply(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB)
+static inline unsigned char multiply(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB)
 {
     return (((255 - alphaA) * colorB + (255 - alphaB + colorB) * colorA) / 255);
 }
 
-static unsigned char screen(unsigned char colorA, unsigned char colorB, unsigned char, unsigned char)
+static inline unsigned char screen(unsigned char colorA, unsigned char colorB, unsigned char, unsigned char)
 {
     return (((colorB + colorA) * 255 - colorA * colorB) / 255);
 }
 
-static unsigned char darken(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB)
+static inline unsigned char darken(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB)
 {
     return ((std::min((255 - alphaA) * colorB + colorA * 255, (255 - alphaB) * colorA + colorB * 255)) / 255);
 }
 
-static unsigned char lighten(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB)
+static inline unsigned char lighten(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB)
 {
     return ((std::max((255 - alphaA) * colorB + colorA * 255, (255 - alphaB) * colorA + colorB * 255)) / 255);
 }
@@ -115,9 +110,6 @@
     IntRect effectBDrawingRect = requestedRegionOfInputImageData(in2->absolutePaintRect());
     RefPtr<ByteArray> srcPixelArrayB = in2->asPremultipliedImage(effectBDrawingRect);
 
-    // Keep synchronized with BlendModeType
-    static const BlendType callEffect[] = {unknown, normal, multiply, screen, darken, lighten};
-
     unsigned pixelArrayLength = srcPixelArrayA->length();
     ASSERT(pixelArrayLength == srcPixelArrayB->length());
     for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) {
@@ -126,8 +118,30 @@
         for (unsigned channel = 0; channel < 3; ++channel) {
             unsigned char colorA = srcPixelArrayA->get(pixelOffset + channel);
             unsigned char colorB = srcPixelArrayB->get(pixelOffset + channel);
+            unsigned char result;
 
-            unsigned char result = (*callEffect[m_mode])(colorA, colorB, alphaA, alphaB);
+            switch (m_mode) {
+            case FEBLEND_MODE_NORMAL:
+                result = normal(colorA, colorB, alphaA, alphaB);
+                break;
+            case FEBLEND_MODE_MULTIPLY:
+                result = multiply(colorA, colorB, alphaA, alphaB);
+                break;
+            case FEBLEND_MODE_SCREEN:
+                result = screen(colorA, colorB, alphaA, alphaB);
+                break;
+            case FEBLEND_MODE_DARKEN:
+                result = darken(colorA, colorB, alphaA, alphaB);
+                break;
+            case FEBLEND_MODE_LIGHTEN:
+                result = lighten(colorA, colorB, alphaA, alphaB);
+                break;
+            case FEBLEND_MODE_UNKNOWN:
+            default:
+                result = 0;
+                break;
+            }
+
             dstPixelArray->set(pixelOffset + channel, result);
         }
         unsigned char alphaR = 255 - ((255 - alphaA) * (255 - alphaB)) / 255;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to