FEGaussianBlur: unify and const-ify calculateKernelSize
authorcavalcantii@gmail.com <cavalcantii@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Mar 2014 04:14:22 +0000 (04:14 +0000)
committercavalcantii@gmail.com <cavalcantii@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Mar 2014 04:14:22 +0000 (04:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=130779

Some methods can benefit of using const refs as also make sense to
unify the interface (i.e. parameters) in calculateKernelSize/Unscaled.

FilterEffect::filter() will now return a reference, which helps since
its descendants were accessing methods into the pointer without testing
for it.

Reviewed by Simon Fraser.

No new tests, no changes on behavior.

* platform/graphics/filters/FEDisplacementMap.cpp:
(WebCore::FEDisplacementMap::platformApplySoftware):
* platform/graphics/filters/FEDropShadow.cpp:
(WebCore::FEDropShadow::determineAbsolutePaintRect):
(WebCore::FEDropShadow::platformApplySoftware):
* platform/graphics/filters/FEGaussianBlur.cpp:
(WebCore::FEGaussianBlur::calculateUnscaledKernelSize):
(WebCore::FEGaussianBlur::calculateKernelSize):
(WebCore::FEGaussianBlur::determineAbsolutePaintRect):
(WebCore::FEGaussianBlur::platformApplySoftware):
* platform/graphics/filters/FEGaussianBlur.h:
* platform/graphics/filters/FEMorphology.cpp:
(WebCore::FEMorphology::determineAbsolutePaintRect):
(WebCore::FEMorphology::platformApplySoftware):
* platform/graphics/filters/FEOffset.cpp:
(WebCore::FEOffset::determineAbsolutePaintRect):
(WebCore::FEOffset::platformApplySoftware):
* platform/graphics/filters/FETile.cpp:
(WebCore::FETile::platformApplySoftware):
* platform/graphics/filters/FETurbulence.cpp:
(WebCore::FETurbulence::fillRegion):
* platform/graphics/filters/Filter.h:
(WebCore::Filter::applyHorizontalScale):
(WebCore::Filter::applyVerticalScale):
* platform/graphics/filters/FilterEffect.h:
(WebCore::FilterEffect::filter):
* platform/graphics/filters/SourceAlpha.cpp:
(WebCore::SourceAlpha::determineAbsolutePaintRect):
(WebCore::SourceAlpha::platformApplySoftware):
* platform/graphics/filters/SourceGraphic.cpp:
(WebCore::SourceGraphic::determineAbsolutePaintRect):
(WebCore::SourceGraphic::platformApplySoftware):
* rendering/svg/RenderSVGResourceFilterPrimitive.cpp:
(WebCore::RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion):
* svg/graphics/filters/SVGFEImage.cpp:
(WebCore::FEImage::determineAbsolutePaintRect):
(WebCore::FEImage::platformApplySoftware):

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp
Source/WebCore/platform/graphics/filters/FEDropShadow.cpp
Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp
Source/WebCore/platform/graphics/filters/FEGaussianBlur.h
Source/WebCore/platform/graphics/filters/FEMorphology.cpp
Source/WebCore/platform/graphics/filters/FEOffset.cpp
Source/WebCore/platform/graphics/filters/FETile.cpp
Source/WebCore/platform/graphics/filters/FETurbulence.cpp
Source/WebCore/platform/graphics/filters/Filter.h
Source/WebCore/platform/graphics/filters/FilterEffect.h
Source/WebCore/platform/graphics/filters/SourceAlpha.cpp
Source/WebCore/platform/graphics/filters/SourceGraphic.cpp
Source/WebCore/rendering/svg/RenderSVGResourceFilterPrimitive.cpp
Source/WebCore/svg/graphics/filters/SVGFEImage.cpp

index 2f97792..b3aff79 100644 (file)
@@ -1,3 +1,57 @@
+2014-03-26  Adenilson Cavalcanti  <cavalcantii@gmail.com>
+
+        FEGaussianBlur: unify and const-ify calculateKernelSize
+        https://bugs.webkit.org/show_bug.cgi?id=130779
+
+        Some methods can benefit of using const refs as also make sense to
+        unify the interface (i.e. parameters) in calculateKernelSize/Unscaled.
+
+        FilterEffect::filter() will now return a reference, which helps since
+        its descendants were accessing methods into the pointer without testing
+        for it.
+
+        Reviewed by Simon Fraser.
+
+        No new tests, no changes on behavior.
+
+        * platform/graphics/filters/FEDisplacementMap.cpp:
+        (WebCore::FEDisplacementMap::platformApplySoftware):
+        * platform/graphics/filters/FEDropShadow.cpp:
+        (WebCore::FEDropShadow::determineAbsolutePaintRect):
+        (WebCore::FEDropShadow::platformApplySoftware):
+        * platform/graphics/filters/FEGaussianBlur.cpp:
+        (WebCore::FEGaussianBlur::calculateUnscaledKernelSize):
+        (WebCore::FEGaussianBlur::calculateKernelSize):
+        (WebCore::FEGaussianBlur::determineAbsolutePaintRect):
+        (WebCore::FEGaussianBlur::platformApplySoftware):
+        * platform/graphics/filters/FEGaussianBlur.h:
+        * platform/graphics/filters/FEMorphology.cpp:
+        (WebCore::FEMorphology::determineAbsolutePaintRect):
+        (WebCore::FEMorphology::platformApplySoftware):
+        * platform/graphics/filters/FEOffset.cpp:
+        (WebCore::FEOffset::determineAbsolutePaintRect):
+        (WebCore::FEOffset::platformApplySoftware):
+        * platform/graphics/filters/FETile.cpp:
+        (WebCore::FETile::platformApplySoftware):
+        * platform/graphics/filters/FETurbulence.cpp:
+        (WebCore::FETurbulence::fillRegion):
+        * platform/graphics/filters/Filter.h:
+        (WebCore::Filter::applyHorizontalScale):
+        (WebCore::Filter::applyVerticalScale):
+        * platform/graphics/filters/FilterEffect.h:
+        (WebCore::FilterEffect::filter):
+        * platform/graphics/filters/SourceAlpha.cpp:
+        (WebCore::SourceAlpha::determineAbsolutePaintRect):
+        (WebCore::SourceAlpha::platformApplySoftware):
+        * platform/graphics/filters/SourceGraphic.cpp:
+        (WebCore::SourceGraphic::determineAbsolutePaintRect):
+        (WebCore::SourceGraphic::platformApplySoftware):
+        * rendering/svg/RenderSVGResourceFilterPrimitive.cpp:
+        (WebCore::RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion):
+        * svg/graphics/filters/SVGFEImage.cpp:
+        (WebCore::FEImage::determineAbsolutePaintRect):
+        (WebCore::FEImage::platformApplySoftware):
+
 2014-03-26  Simon Fraser  <simon.fraser@apple.com>
 
         Make sure childContainmentLayer is parented
index dfb9194..6fce373 100644 (file)
@@ -123,10 +123,10 @@ void FEDisplacementMap::platformApplySoftware()
 
     ASSERT(srcPixelArrayA->length() == srcPixelArrayB->length());
 
-    Filter* filter = this->filter();
+    Filter& filter = this->filter();
     IntSize paintSize = absolutePaintRect().size();
-    float scaleX = filter->applyHorizontalScale(m_scale);
-    float scaleY = filter->applyVerticalScale(m_scale);
+    float scaleX = filter.applyHorizontalScale(m_scale);
+    float scaleY = filter.applyVerticalScale(m_scale);
     float scaleForColorX = scaleX / 255.0;
     float scaleForColorY = scaleY / 255.0;
     float scaledOffsetX = 0.5 - scaleX * 0.5;
index eec7345..10a8996 100644 (file)
@@ -51,15 +51,14 @@ PassRefPtr<FEDropShadow> FEDropShadow::create(Filter* filter, float stdX, float
 
 void FEDropShadow::determineAbsolutePaintRect()
 {
-    Filter* filter = this->filter();
-    ASSERT(filter);
+    Filter& filter = this->filter();
 
     FloatRect absolutePaintRect = inputEffect(0)->absolutePaintRect();
     FloatRect absoluteOffsetPaintRect(absolutePaintRect);
-    absoluteOffsetPaintRect.move(filter->applyHorizontalScale(m_dx), filter->applyVerticalScale(m_dy));
+    absoluteOffsetPaintRect.move(filter.applyHorizontalScale(m_dx), filter.applyVerticalScale(m_dy));
     absolutePaintRect.unite(absoluteOffsetPaintRect);
 
-    IntSize kernelSize = FEGaussianBlur::calculateKernelSize(filter, m_stdX, m_stdY);
+    IntSize kernelSize = FEGaussianBlur::calculateKernelSize(filter, FloatPoint(m_stdX, m_stdY));
 
     // We take the half kernel size and multiply it with three, because we run box blur three times.
     absolutePaintRect.inflateX(3 * kernelSize.width() * 0.5f);
@@ -81,9 +80,9 @@ void FEDropShadow::platformApplySoftware()
     if (!resultImage)
         return;
 
-    Filter* filter = this->filter();
-    FloatSize blurRadius(filter->applyHorizontalScale(m_stdX), filter->applyVerticalScale(m_stdY));
-    FloatSize offset(filter->applyHorizontalScale(m_dx), filter->applyVerticalScale(m_dy));
+    Filter& filter = this->filter();
+    FloatSize blurRadius(filter.applyHorizontalScale(m_stdX), filter.applyVerticalScale(m_stdY));
+    FloatSize offset(filter.applyHorizontalScale(m_dx), filter.applyVerticalScale(m_dy));
 
     FloatRect drawingRegion = drawingRegionOfInputImage(in->absolutePaintRect());
     FloatRect drawingRegionWithOffset(drawingRegion);
index 150a38f..3364c07 100644 (file)
@@ -385,37 +385,35 @@ inline void FEGaussianBlur::platformApply(Uint8ClampedArray* srcPixelArray, Uint
     platformApplyGeneric(srcPixelArray, tmpPixelArray, kernelSizeX, kernelSizeY, paintSize);
 }
 
-IntSize FEGaussianBlur::calculateUnscaledKernelSize(FloatPoint std)
+IntSize FEGaussianBlur::calculateUnscaledKernelSize(const FloatPoint& stdDeviation)
 {
-    ASSERT(std.x() >= 0 && std.y() >= 0);
-    IntSize kernelSize(0, 0);
+    ASSERT(stdDeviation.x() >= 0 && stdDeviation.y() >= 0);
+    IntSize kernelSize;
 
     // Limit the kernel size to 500. A bigger radius won't make a big difference for the result image but
     // inflates the absolute paint rect to much. This is compatible with Firefox' behavior.
-    if (std.x()) {
-        int size = std::max<unsigned>(2, static_cast<unsigned>(floorf(std.x() * gaussianKernelFactor() + 0.5f)));
+    if (stdDeviation.x()) {
+        int size = std::max<unsigned>(2, static_cast<unsigned>(floorf(stdDeviation.x() * gaussianKernelFactor() + 0.5f)));
         kernelSize.setWidth(std::min(size, gMaxKernelSize));
     }
 
-    if (std.y()) {
-        int size = std::max<unsigned>(2, static_cast<unsigned>(floorf(std.y() * gaussianKernelFactor() + 0.5f)));
+    if (stdDeviation.y()) {
+        int size = std::max<unsigned>(2, static_cast<unsigned>(floorf(stdDeviation.y() * gaussianKernelFactor() + 0.5f)));
         kernelSize.setHeight(std::min(size, gMaxKernelSize));
     }
 
     return kernelSize;
 }
 
-IntSize FEGaussianBlur::calculateKernelSize(Filter* filter, float stdX, float stdY)
+IntSize FEGaussianBlur::calculateKernelSize(const Filter& filter, const FloatPoint& stdDeviation)
 {
-    stdX = filter->applyHorizontalScale(stdX);
-    stdY = filter->applyVerticalScale(stdY);
-
-    return calculateUnscaledKernelSize(FloatPoint(stdX, stdY));
+    FloatPoint stdFilterScaled(filter.applyHorizontalScale(stdDeviation.x()), filter.applyVerticalScale(stdDeviation.y()));
+    return calculateUnscaledKernelSize(stdFilterScaled);
 }
 
 void FEGaussianBlur::determineAbsolutePaintRect()
 {
-    IntSize kernelSize = calculateKernelSize(filter(), m_stdX, m_stdY);
+    IntSize kernelSize = calculateKernelSize(filter(), FloatPoint(m_stdX, m_stdY));
 
     FloatRect absolutePaintRect = inputEffect(0)->absolutePaintRect();
     // Edge modes other than 'none' do not inflate the affected paint rect.
@@ -452,7 +450,7 @@ void FEGaussianBlur::platformApplySoftware()
     if (!m_stdX && !m_stdY)
         return;
 
-    IntSize kernelSize = calculateKernelSize(filter(), m_stdX, m_stdY);
+    IntSize kernelSize = calculateKernelSize(filter(), FloatPoint(m_stdX, m_stdY));
 
     IntSize paintSize = absolutePaintRect().size();
     RefPtr<Uint8ClampedArray> tmpImageData = Uint8ClampedArray::createUninitialized(paintSize.width() * paintSize.height() * 4);
index de65d57..f289732 100644 (file)
@@ -46,8 +46,8 @@ public:
     virtual void dump();
 
     virtual void determineAbsolutePaintRect();
-    static IntSize calculateKernelSize(Filter*, float stdX, float stdY);
-    static IntSize calculateUnscaledKernelSize(FloatPoint std);
+    static IntSize calculateKernelSize(const Filter&, const FloatPoint& stdDeviation);
+    static IntSize calculateUnscaledKernelSize(const FloatPoint& stdDeviation);
 
     virtual TextStream& externalRepresentation(TextStream&, int indention) const;
 
index 72fea36..3a30ddb 100644 (file)
@@ -82,9 +82,9 @@ float FEMorphology::radiusY() const
 void FEMorphology::determineAbsolutePaintRect()
 {
     FloatRect paintRect = inputEffect(0)->absolutePaintRect();
-    Filter* filter = this->filter();
-    paintRect.inflateX(filter->applyHorizontalScale(m_radiusX));
-    paintRect.inflateY(filter->applyVerticalScale(m_radiusY));
+    Filter& filter = this->filter();
+    paintRect.inflateX(filter.applyHorizontalScale(m_radiusX));
+    paintRect.inflateY(filter.applyVerticalScale(m_radiusY));
     if (clipsToBounds())
         paintRect.intersect(maxEffectRect());
     else
@@ -206,9 +206,9 @@ void FEMorphology::platformApplySoftware()
         return;
     }
 
-    Filter* filter = this->filter();
-    int radiusX = static_cast<int>(floorf(filter->applyHorizontalScale(m_radiusX)));
-    int radiusY = static_cast<int>(floorf(filter->applyVerticalScale(m_radiusY)));
+    Filter& filter = this->filter();
+    int radiusX = static_cast<int>(floorf(filter.applyHorizontalScale(m_radiusX)));
+    int radiusY = static_cast<int>(floorf(filter.applyVerticalScale(m_radiusY)));
 
     IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
     RefPtr<Uint8ClampedArray> srcPixelArray = in->asPremultipliedImage(effectDrawingRect);
index 45c4cc8..9db2a0e 100644 (file)
@@ -67,8 +67,8 @@ void FEOffset::setDy(float dy)
 void FEOffset::determineAbsolutePaintRect()
 {
     FloatRect paintRect = inputEffect(0)->absolutePaintRect();
-    Filter* filter = this->filter();
-    paintRect.move(filter->applyHorizontalScale(m_dx), filter->applyVerticalScale(m_dy));
+    Filter& filter = this->filter();
+    paintRect.move(filter.applyHorizontalScale(m_dx), filter.applyVerticalScale(m_dy));
     if (clipsToBounds())
         paintRect.intersect(maxEffectRect());
     else
@@ -87,8 +87,8 @@ void FEOffset::platformApplySoftware()
     setIsAlphaImage(in->isAlphaImage());
 
     FloatRect drawingRegion = drawingRegionOfInputImage(in->absolutePaintRect());
-    Filter* filter = this->filter();
-    drawingRegion.move(filter->applyHorizontalScale(m_dx), filter->applyVerticalScale(m_dy));
+    Filter& filter = this->filter();
+    drawingRegion.move(filter.applyHorizontalScale(m_dx), filter.applyVerticalScale(m_dy));
     resultImage->context()->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegion);
 }
 
index a32059c..b53eca9 100644 (file)
@@ -60,13 +60,13 @@ void FETile::platformApplySoftware()
     FloatPoint inMaxEffectLocation = tileRect.location();
     FloatPoint maxEffectLocation = maxEffectRect().location();
     if (in->filterEffectType() == FilterEffectTypeSourceInput) {
-        Filter* filter = this->filter();
-        tileRect = filter->filterRegion();
-        tileRect.scale(filter->filterResolution().width(), filter->filterResolution().height());
+        Filter& filter = this->filter();
+        tileRect = filter.filterRegion();
+        tileRect.scale(filter.filterResolution().width(), filter.filterResolution().height());
     }
 
     std::unique_ptr<ImageBuffer> tileImage;
-    if (!SVGRenderingContext::createImageBufferForPattern(tileRect, tileRect, tileImage, ColorSpaceDeviceRGB, filter()->renderingMode()))
+    if (!SVGRenderingContext::createImageBufferForPattern(tileRect, tileRect, tileImage, ColorSpaceDeviceRGB, filter().renderingMode()))
         return;
 
     GraphicsContext* tileImageContext = tileImage->context();
index a5e8b34..917c96a 100644 (file)
@@ -343,7 +343,7 @@ inline void FETurbulence::fillRegion(Uint8ClampedArray* pixelArray, PaintingData
         for (int x = 0; x < filterRegion.width(); ++x) {
             point.setX(point.x() + 1);
             for (channel = 0; channel < 4; ++channel, ++indexOfPixelChannel)
-                pixelArray->set(indexOfPixelChannel, calculateTurbulenceValueForPoint(channel, paintingData, stitchData, filter()->mapAbsolutePointToLocalPoint(point)));
+                pixelArray->set(indexOfPixelChannel, calculateTurbulenceValueForPoint(channel, paintingData, stitchData, filter().mapAbsolutePointToLocalPoint(point)));
         }
     }
 }
index 074b30c..5643def 100644 (file)
@@ -46,6 +46,7 @@ public:
 
     virtual bool isSVGFilter() const { return false; }
 
+    // TODO: verify descendants that overload this method and turn them to const.
     virtual float applyHorizontalScale(float value) const { return value * m_filterResolution.width(); }
     virtual float applyVerticalScale(float value) const { return value * m_filterResolution.height(); }
     
index f435827..d2095f5 100644 (file)
@@ -149,7 +149,7 @@ public:
     FloatRect effectBoundaries() const { return m_effectBoundaries; }
     void setEffectBoundaries(const FloatRect& effectBoundaries) { m_effectBoundaries = effectBoundaries; }
 
-    Filter* filter() { return m_filter; }
+    Filter& filter() { ASSERT(m_filter); return *m_filter; }
 
     bool clipsToBounds() const { return m_clipsToBounds; }
     void setClipsToBounds(bool value) { m_clipsToBounds = value; }
index 86ec69e..8d349f4 100644 (file)
@@ -44,17 +44,17 @@ const AtomicString& SourceAlpha::effectName()
 
 void SourceAlpha::determineAbsolutePaintRect()
 {
-    Filter* filter = this->filter();
-    FloatRect paintRect = filter->sourceImageRect();
-    paintRect.scale(filter->filterResolution().width(), filter->filterResolution().height());
+    Filter& filter = this->filter();
+    FloatRect paintRect = filter.sourceImageRect();
+    paintRect.scale(filter.filterResolution().width(), filter.filterResolution().height());
     setAbsolutePaintRect(enclosingIntRect(paintRect));
 }
 
 void SourceAlpha::platformApplySoftware()
 {
     ImageBuffer* resultImage = createImageBufferResult();
-    Filter* filter = this->filter();
-    if (!resultImage || !filter->sourceImage())
+    Filter& filter = this->filter();
+    if (!resultImage || !filter.sourceImage())
         return;
 
     setIsAlphaImage(true);
@@ -62,7 +62,7 @@ void SourceAlpha::platformApplySoftware()
     FloatRect imageRect(FloatPoint(), absolutePaintRect().size());
     GraphicsContext* filterContext = resultImage->context();
     filterContext->fillRect(imageRect, Color::black, ColorSpaceDeviceRGB);
-    filterContext->drawImageBuffer(filter->sourceImage(), ColorSpaceDeviceRGB, IntPoint(), CompositeDestinationIn);
+    filterContext->drawImageBuffer(filter.sourceImage(), ColorSpaceDeviceRGB, IntPoint(), CompositeDestinationIn);
 }
 
 void SourceAlpha::dump()
index 72fb5d3..d001969 100644 (file)
@@ -43,20 +43,20 @@ const AtomicString& SourceGraphic::effectName()
 
 void SourceGraphic::determineAbsolutePaintRect()
 {
-    Filter* filter = this->filter();
-    FloatRect paintRect = filter->sourceImageRect();
-    paintRect.scale(filter->filterResolution().width(), filter->filterResolution().height());
+    Filter& filter = this->filter();
+    FloatRect paintRect = filter.sourceImageRect();
+    paintRect.scale(filter.filterResolution().width(), filter.filterResolution().height());
     setAbsolutePaintRect(enclosingIntRect(paintRect));
 }
 
 void SourceGraphic::platformApplySoftware()
 {
     ImageBuffer* resultImage = createImageBufferResult();
-    Filter* filter = this->filter();
-    if (!resultImage || !filter->sourceImage())
+    Filter& filter = this->filter();
+    if (!resultImage || !filter.sourceImage())
         return;
 
-    resultImage->context()->drawImageBuffer(filter->sourceImage(), ColorSpaceDeviceRGB, IntPoint());
+    resultImage->context()->drawImageBuffer(filter.sourceImage(), ColorSpaceDeviceRGB, IntPoint());
 }
 
 void SourceGraphic::dump()
index 033ff91..e11a4cb 100644 (file)
@@ -72,7 +72,7 @@ void RenderSVGResourceFilterPrimitive::styleDidChange(StyleDifference diff, cons
 
 FloatRect RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(FilterEffect* effect)
 {
-    SVGFilter* filter = toSVGFilter(effect->filter());
+    SVGFilter* filter = toSVGFilter(&(effect->filter()));
     ASSERT(filter);
 
     // FETile, FETurbulence, FEFlood don't have input effects, take the filter region as unite rect.
index 149d93b..2d53ef4 100644 (file)
@@ -67,7 +67,7 @@ PassRefPtr<FEImage> FEImage::createWithIRIReference(Filter* filter, Document& do
 
 void FEImage::determineAbsolutePaintRect()
 {
-    SVGFilter* svgFilter = toSVGFilter(filter());
+    SVGFilter* svgFilter = toSVGFilter(&(filter()));
 
     FloatRect paintRect = svgFilter->absoluteTransform().mapRect(filterPrimitiveSubregion());
     FloatRect srcRect;
@@ -104,7 +104,7 @@ void FEImage::platformApplySoftware()
     if (!resultImage)
         return;
 
-    SVGFilter* svgFilter = toSVGFilter(filter());
+    SVGFilter* svgFilter = toSVGFilter(&(filter()));
     FloatRect destRect = svgFilter->absoluteTransform().mapRect(filterPrimitiveSubregion());
 
     FloatRect srcRect;