FETurbulence const and inline cleanup
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Nov 2017 19:39:58 +0000 (19:39 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Nov 2017 19:39:58 +0000 (19:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179832

Reviewed by Dean Jackson.

Pass the PaintingData& around as const, and remove some 'inline', letting the compiler
decide. Also declare a few variables closer to first use.

Speeds up FETurbulence by about 1%.

* platform/graphics/filters/FETurbulence.cpp:
(WebCore::FETurbulence::initPaint):
(WebCore::FETurbulence::noise2D):
(WebCore::FETurbulence::calculateTurbulenceValueForPoint):
(WebCore::FETurbulence::fillRegion):
* platform/graphics/filters/FETurbulence.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224977 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/filters/FETurbulence.cpp
Source/WebCore/platform/graphics/filters/FETurbulence.h

index 6bfa626..4eaa0ce 100644 (file)
@@ -1,3 +1,22 @@
+2017-11-17  Simon Fraser  <simon.fraser@apple.com>
+
+        FETurbulence const and inline cleanup
+        https://bugs.webkit.org/show_bug.cgi?id=179832
+
+        Reviewed by Dean Jackson.
+
+        Pass the PaintingData& around as const, and remove some 'inline', letting the compiler
+        decide. Also declare a few variables closer to first use.
+        
+        Speeds up FETurbulence by about 1%.
+
+        * platform/graphics/filters/FETurbulence.cpp:
+        (WebCore::FETurbulence::initPaint):
+        (WebCore::FETurbulence::noise2D):
+        (WebCore::FETurbulence::calculateTurbulenceValueForPoint):
+        (WebCore::FETurbulence::fillRegion):
+        * platform/graphics/filters/FETurbulence.h:
+
 2017-11-17  Antti Koivisto  <antti@apple.com>
 
         Move destroyLeftoverChildren call to RenderObject::destroy
index 9892f49..e9e39b6 100644 (file)
@@ -165,7 +165,7 @@ inline float linearInterpolation(float t, float a, float b)
     return a + t * (b - a);
 }
 
-inline void FETurbulence::initPaint(PaintingData& paintingData)
+void FETurbulence::initPaint(PaintingData& paintingData)
 {
     float normalizationFactor;
 
@@ -189,6 +189,7 @@ inline void FETurbulence::initPaint(PaintingData& paintingData)
             gradient[1] /= normalizationFactor;
         }
     }
+
     for (int i = s_blockSize - 1; i > 0; --i) {
         int k = paintingData.latticeSelector[i];
         int j = paintingData.random() % s_blockSize;
@@ -197,6 +198,7 @@ inline void FETurbulence::initPaint(PaintingData& paintingData)
         paintingData.latticeSelector[i] = paintingData.latticeSelector[j];
         paintingData.latticeSelector[j] = k;
     }
+
     for (int i = 0; i < s_blockSize + 2; ++i) {
         paintingData.latticeSelector[s_blockSize + i] = paintingData.latticeSelector[i];
         for (int channel = 0; channel < 4; ++channel) {
@@ -214,7 +216,7 @@ inline void checkNoise(int& noiseValue, int limitValue, int newValue)
         noiseValue -= newValue - 1;
 }
 
-float FETurbulence::noise2D(int channel, PaintingData& paintingData, StitchData& stitchData, const FloatPoint& noiseVector)
+float FETurbulence::noise2D(int channel, const PaintingData& paintingData, StitchData& stitchData, const FloatPoint& noiseVector)
 {
     struct Noise {
         int noisePositionIntegerValue;
@@ -230,8 +232,6 @@ float FETurbulence::noise2D(int channel, PaintingData& paintingData, StitchData&
 
     Noise noiseX(noiseVector.x());
     Noise noiseY(noiseVector.y());
-    float* q;
-    float sx, sy, a, b, u, v;
 
     // If stitching, adjust lattice points accordingly.
     if (m_stitchTiles) {
@@ -244,12 +244,13 @@ float FETurbulence::noise2D(int channel, PaintingData& paintingData, StitchData&
     int latticeIndex = paintingData.latticeSelector[noiseX.noisePositionIntegerValue];
     int nextLatticeIndex = paintingData.latticeSelector[(noiseX.noisePositionIntegerValue + 1) & s_blockMask];
 
-    sx = smoothCurve(noiseX.noisePositionFractionValue);
-    sy = smoothCurve(noiseY.noisePositionFractionValue);
+    float sx = smoothCurve(noiseX.noisePositionFractionValue);
+    float sy = smoothCurve(noiseY.noisePositionFractionValue);
+    float a, b, u, v;
 
     // This is taken 1:1 from SVG spec: http://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement.
     int temp = paintingData.latticeSelector[latticeIndex + noiseY.noisePositionIntegerValue];
-    q = paintingData.gradient[channel][temp];
+    const float* q = paintingData.gradient[channel][temp];
     u = noiseX.noisePositionFractionValue * q[0] + noiseY.noisePositionFractionValue * q[1];
     temp = paintingData.latticeSelector[nextLatticeIndex + noiseY.noisePositionIntegerValue];
     q = paintingData.gradient[channel][temp];
@@ -265,7 +266,7 @@ float FETurbulence::noise2D(int channel, PaintingData& paintingData, StitchData&
     return linearInterpolation(sy, a, b);
 }
 
-unsigned char FETurbulence::calculateTurbulenceValueForPoint(int channel, PaintingData& paintingData, StitchData& stitchData, const FloatPoint& point)
+unsigned char FETurbulence::calculateTurbulenceValueForPoint(int channel, const PaintingData& paintingData, StitchData& stitchData, const FloatPoint& point)
 {
     float tileWidth = paintingData.filterSize.width();
     float tileHeight = paintingData.filterSize.height();
@@ -299,6 +300,7 @@ unsigned char FETurbulence::calculateTurbulenceValueForPoint(int channel, Painti
         stitchData.height = roundf(tileHeight * baseFrequencyY);
         stitchData.wrapY = s_perlinNoise + stitchData.height;
     }
+
     float turbulenceFunctionResult = 0;
     FloatPoint noiseVector(point.x() * baseFrequencyX, point.y() * baseFrequencyY);
     float ratio = 1;
@@ -329,7 +331,7 @@ unsigned char FETurbulence::calculateTurbulenceValueForPoint(int channel, Painti
     return static_cast<unsigned char>(turbulenceFunctionResult * 255);
 }
 
-inline void FETurbulence::fillRegion(Uint8ClampedArray* pixelArray, PaintingData& paintingData, int startY, int endY)
+void FETurbulence::fillRegion(Uint8ClampedArray* pixelArray, const PaintingData& paintingData, int startY, int endY)
 {
     IntRect filterRegion = absolutePaintRect();
     IntPoint point(0, filterRegion.y() + startY);
index d91bdd9..fc1d79d 100644 (file)
@@ -117,10 +117,10 @@ private:
 
     FETurbulence(Filter&, TurbulenceType, float, float, int, float, bool);
 
-    inline void initPaint(PaintingData&);
-    float noise2D(int channel, PaintingData&, StitchData&, const FloatPoint&);
-    unsigned char calculateTurbulenceValueForPoint(int channel, PaintingData&, StitchData&, const FloatPoint&);
-    inline void fillRegion(Uint8ClampedArray*, PaintingData&, int, int);
+    void initPaint(PaintingData&);
+    float noise2D(int channel, const PaintingData&, StitchData&, const FloatPoint&);
+    unsigned char calculateTurbulenceValueForPoint(int channel, const PaintingData&, StitchData&, const FloatPoint&);
+    void fillRegion(Uint8ClampedArray*, const PaintingData&, int, int);
 
     TurbulenceType m_type;
     float m_baseFrequencyX;