Rename applyHorizontalScale/applyVerticalScale in SVG filters, and related cleanup
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 18:59:09 +0000 (18:59 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 18:59:09 +0000 (18:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181684

Reviewed by Alex Christensen.

Rename the confusing applyHorizontalScale/applyVerticalScale to scaledByFilterResolution(),
and have it take and return a FloatSize. Change callers to do math in terms of FloatSizes.

Add inflate(size) to each of the rect classes.

* platform/graphics/FloatRect.h:
(WebCore::FloatRect::inflate):
* platform/graphics/IntRect.h:
(WebCore::IntRect::inflate):
* platform/graphics/LayoutRect.h:
(WebCore::LayoutRect::inflate):
* 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/Filter.h:
(WebCore::Filter::setSourceImage):
(WebCore::Filter::scaledByFilterResolution const):
(WebCore::Filter::applyHorizontalScale const): Deleted.
(WebCore::Filter::applyVerticalScale const): Deleted.
* platform/graphics/filters/FilterOperations.cpp:
(WebCore::outsetSizeForBlur):
* rendering/FilterEffectRenderer.h:
* svg/graphics/filters/SVGFilter.cpp:
(WebCore::SVGFilter::scaledByFilterResolution const):
(WebCore::SVGFilter::applyHorizontalScale const): Deleted.
(WebCore::SVGFilter::applyVerticalScale const): Deleted.
* svg/graphics/filters/SVGFilter.h:

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FloatRect.h
Source/WebCore/platform/graphics/IntRect.h
Source/WebCore/platform/graphics/LayoutRect.h
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/Filter.h
Source/WebCore/platform/graphics/filters/FilterOperations.cpp
Source/WebCore/rendering/FilterEffectRenderer.h
Source/WebCore/svg/graphics/filters/SVGFilter.cpp
Source/WebCore/svg/graphics/filters/SVGFilter.h

index 309cfbb..83f773d 100644 (file)
@@ -1,3 +1,52 @@
+2018-01-16  Simon Fraser  <simon.fraser@apple.com>
+
+        Rename applyHorizontalScale/applyVerticalScale in SVG filters, and related cleanup
+        https://bugs.webkit.org/show_bug.cgi?id=181684
+
+        Reviewed by Alex Christensen.
+
+        Rename the confusing applyHorizontalScale/applyVerticalScale to scaledByFilterResolution(),
+        and have it take and return a FloatSize. Change callers to do math in terms of FloatSizes.
+
+        Add inflate(size) to each of the rect classes.
+
+        * platform/graphics/FloatRect.h:
+        (WebCore::FloatRect::inflate):
+        * platform/graphics/IntRect.h:
+        (WebCore::IntRect::inflate):
+        * platform/graphics/LayoutRect.h:
+        (WebCore::LayoutRect::inflate):
+        * 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/Filter.h:
+        (WebCore::Filter::setSourceImage):
+        (WebCore::Filter::scaledByFilterResolution const):
+        (WebCore::Filter::applyHorizontalScale const): Deleted.
+        (WebCore::Filter::applyVerticalScale const): Deleted.
+        * platform/graphics/filters/FilterOperations.cpp:
+        (WebCore::outsetSizeForBlur):
+        * rendering/FilterEffectRenderer.h:
+        * svg/graphics/filters/SVGFilter.cpp:
+        (WebCore::SVGFilter::scaledByFilterResolution const):
+        (WebCore::SVGFilter::applyHorizontalScale const): Deleted.
+        (WebCore::SVGFilter::applyVerticalScale const): Deleted.
+        * svg/graphics/filters/SVGFilter.h:
+
 2018-01-16  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [CMake][Mac] Fix the build errors
index e55f17b..4f35766 100644 (file)
@@ -164,6 +164,8 @@ public:
         m_size.setHeight(m_size.height() + dy + dy);
     }
     void inflate(float d) { inflateX(d); inflateY(d); }
+    void inflate(FloatSize size) { inflateX(size.width()); inflateY(size.height()); }
+
     void scale(float s) { scale(s, s); }
     WEBCORE_EXPORT void scale(float sx, float sy);
     void scale(FloatSize size) { scale(size.width(), size.height()); }
index 4f14b21..f5129f0 100644 (file)
@@ -169,6 +169,7 @@ public:
         m_size.setHeight(m_size.height() + dy + dy);
     }
     void inflate(int d) { inflateX(d); inflateY(d); }
+    void inflate(IntSize size) { inflateX(size.width()); inflateY(size.height()); }
     WEBCORE_EXPORT void scale(float s);
 
     IntSize differenceToPoint(const IntPoint&) const;
index 8bbc739..d720b56 100644 (file)
@@ -160,6 +160,7 @@ public:
         m_size.setHeight(m_size.height() + dy + dy);
     }
     void inflate(LayoutUnit d) { inflateX(d); inflateY(d); }
+    void inflate(LayoutSize size) { inflateX(size.width()); inflateY(size.height()); }
     WEBCORE_EXPORT void scale(float);
     void scale(float xScale, float yScale);
 
index 75ad784..db8a319 100644 (file)
@@ -112,12 +112,11 @@ void FEDisplacementMap::platformApplySoftware()
 
     Filter& filter = this->filter();
     IntSize paintSize = absolutePaintRect().size();
-    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;
-    float scaledOffsetY = 0.5 - scaleY * 0.5;
+    FloatSize scale = filter.scaledByFilterResolution({ m_scale, m_scale });
+    float scaleForColorX = scale.width() / 255.0;
+    float scaleForColorY = scale.height() / 255.0;
+    float scaledOffsetX = 0.5 - scale.width() * 0.5;
+    float scaledOffsetY = 0.5 - scale.height() * 0.5;
     
     int displacementChannelX = xChannelIndex();
     int displacementChannelY = yChannelIndex();
index 0b05f17..5d612ff 100644 (file)
@@ -52,10 +52,10 @@ void FEDropShadow::determineAbsolutePaintRect()
 
     FloatRect absolutePaintRect = inputEffect(0)->absolutePaintRect();
     FloatRect absoluteOffsetPaintRect(absolutePaintRect);
-    absoluteOffsetPaintRect.move(filter.applyHorizontalScale(m_dx), filter.applyVerticalScale(m_dy));
+    absoluteOffsetPaintRect.move(filter.scaledByFilterResolution({ m_dx, m_dy }));
     absolutePaintRect.unite(absoluteOffsetPaintRect);
 
-    IntSize kernelSize = FEGaussianBlur::calculateKernelSize(filter, FloatPoint(m_stdX, m_stdY));
+    IntSize kernelSize = FEGaussianBlur::calculateKernelSize(filter, { 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);
@@ -78,9 +78,10 @@ void FEDropShadow::platformApplySoftware()
         return;
 
     Filter& filter = this->filter();
-    FloatSize blurRadius(2 * filter.applyHorizontalScale(m_stdX), 2 * filter.applyVerticalScale(m_stdY));
+    
+    FloatSize blurRadius = 2 * filter.scaledByFilterResolution({ m_stdX, m_stdY });
     blurRadius.scale(filter.filterScale());
-    FloatSize offset(filter.applyHorizontalScale(m_dx), filter.applyVerticalScale(m_dy));
+    FloatSize offset = filter.scaledByFilterResolution({ m_dx, m_dy });
 
     FloatRect drawingRegion = drawingRegionOfInputImage(in->absolutePaintRect());
     FloatRect drawingRegionWithOffset(drawingRegion);
index 0896e66..c04ebb7 100644 (file)
@@ -468,29 +468,28 @@ static int clampedToKernelSize(float value)
     return clampTo<int>(std::min(size, static_cast<unsigned>(gMaxKernelSize)));
 }
     
-IntSize FEGaussianBlur::calculateUnscaledKernelSize(const FloatPoint& stdDeviation)
+IntSize FEGaussianBlur::calculateUnscaledKernelSize(FloatSize stdDeviation)
 {
-    ASSERT(stdDeviation.x() >= 0 && stdDeviation.y() >= 0);
+    ASSERT(stdDeviation.width() >= 0 && stdDeviation.height() >= 0);
     IntSize kernelSize;
 
-    if (stdDeviation.x())
-        kernelSize.setWidth(clampedToKernelSize(stdDeviation.x()));
+    if (stdDeviation.width())
+        kernelSize.setWidth(clampedToKernelSize(stdDeviation.width()));
 
-    if (stdDeviation.y())
-        kernelSize.setHeight(clampedToKernelSize(stdDeviation.y()));
+    if (stdDeviation.height())
+        kernelSize.setHeight(clampedToKernelSize(stdDeviation.height()));
 
     return kernelSize;
 }
 
-IntSize FEGaussianBlur::calculateKernelSize(const Filter& filter, const FloatPoint& stdDeviation)
+IntSize FEGaussianBlur::calculateKernelSize(const Filter& filter, FloatSize stdDeviation)
 {
-    FloatPoint stdFilterScaled(filter.applyHorizontalScale(stdDeviation.x()), filter.applyVerticalScale(stdDeviation.y()));
-    return calculateUnscaledKernelSize(stdFilterScaled);
+    return calculateUnscaledKernelSize(filter.scaledByFilterResolution(stdDeviation));
 }
 
 void FEGaussianBlur::determineAbsolutePaintRect()
 {
-    IntSize kernelSize = calculateKernelSize(filter(), FloatPoint(m_stdX, m_stdY));
+    IntSize kernelSize = calculateKernelSize(filter(), { m_stdX, m_stdY });
 
     FloatRect absolutePaintRect = inputEffect(0)->absolutePaintRect();
     // Edge modes other than 'none' do not inflate the affected paint rect.
@@ -527,7 +526,7 @@ void FEGaussianBlur::platformApplySoftware()
     if (!m_stdX && !m_stdY)
         return;
 
-    IntSize kernelSize = calculateKernelSize(filter(), FloatPoint(m_stdX, m_stdY));
+    IntSize kernelSize = calculateKernelSize(filter(), { m_stdX, m_stdY });
     kernelSize.scale(filter().filterScale());
 
     IntSize paintSize = absolutePaintRect().size();
index f7c7c3b..07efc7a 100644 (file)
@@ -40,8 +40,8 @@ public:
     EdgeModeType edgeMode() const { return m_edgeMode; }
     void setEdgeMode(EdgeModeType);
 
-    static IntSize calculateKernelSize(const Filter&, const FloatPoint& stdDeviation);
-    static IntSize calculateUnscaledKernelSize(const FloatPoint& stdDeviation);
+    static IntSize calculateKernelSize(const Filter&, FloatSize stdDeviation);
+    static IntSize calculateUnscaledKernelSize(FloatSize stdDeviation);
 
 private:
     FEGaussianBlur(Filter&, float, float, EdgeModeType);
index 8d96798..938a786 100644 (file)
@@ -75,8 +75,7 @@ void FEMorphology::determineAbsolutePaintRect()
 {
     FloatRect paintRect = inputEffect(0)->absolutePaintRect();
     Filter& filter = this->filter();
-    paintRect.inflateX(filter.applyHorizontalScale(m_radiusX));
-    paintRect.inflateY(filter.applyVerticalScale(m_radiusY));
+    paintRect.inflate(filter.scaledByFilterResolution({ m_radiusX, m_radiusY }));
     if (clipsToBounds())
         paintRect.intersect(maxEffectRect());
     else
@@ -254,10 +253,9 @@ void FEMorphology::platformApplySoftware()
     if (!srcPixelArray)
         return;
 
-    int radiusX = static_cast<int>(floorf(filter.applyHorizontalScale(m_radiusX)));
-    int radiusY = static_cast<int>(floorf(filter.applyVerticalScale(m_radiusY)));
-    radiusX = std::min(effectDrawingRect.width() - 1, radiusX);
-    radiusY = std::min(effectDrawingRect.height() - 1, radiusY);
+    IntSize radius = flooredIntSize(filter.scaledByFilterResolution({ m_radiusX, m_radiusY }));
+    int radiusX = std::min(effectDrawingRect.width() - 1, radius.width());
+    int radiusY = std::min(effectDrawingRect.height() - 1, radius.height());
 
     if (platformApplyDegenerate(*dstPixelArray, effectDrawingRect, radiusX, radiusY))
         return;
index 0cf15af..04f0686 100644 (file)
@@ -56,7 +56,7 @@ void FEOffset::determineAbsolutePaintRect()
 {
     FloatRect paintRect = inputEffect(0)->absolutePaintRect();
     Filter& filter = this->filter();
-    paintRect.move(filter.applyHorizontalScale(m_dx), filter.applyVerticalScale(m_dy));
+    paintRect.move(filter.scaledByFilterResolution({ m_dx, m_dy }));
     if (clipsToBounds())
         paintRect.intersect(maxEffectRect());
     else
@@ -77,7 +77,7 @@ void FEOffset::platformApplySoftware()
 
     FloatRect drawingRegion = drawingRegionOfInputImage(in->absolutePaintRect());
     Filter& filter = this->filter();
-    drawingRegion.move(filter.applyHorizontalScale(m_dx), filter.applyVerticalScale(m_dy));
+    drawingRegion.move(filter.scaledByFilterResolution({ m_dx, m_dy }));
     resultImage->context().drawImageBuffer(*inBuffer, drawingRegion);
 }
 
index 53d5df0..501afd0 100644 (file)
@@ -33,7 +33,7 @@ public:
     { }
     virtual ~Filter() = default;
 
-    void setSourceImage(std::unique_ptr<ImageBuffer> sourceImage) { m_sourceImage = WTFMove(sourceImage); }
+    void setSourceImage(std::unique_ptr<ImageBuffer>&& sourceImage) { m_sourceImage = WTFMove(sourceImage); }
     ImageBuffer* sourceImage() { return m_sourceImage.get(); }
 
     FloatSize filterResolution() const { return m_filterResolution; }
@@ -49,8 +49,7 @@ public:
 
     virtual bool isSVGFilter() const { return false; }
 
-    virtual float applyHorizontalScale(float value) const { return value * m_filterResolution.width(); }
-    virtual float applyVerticalScale(float value) const { return value * m_filterResolution.height(); }
+    virtual FloatSize scaledByFilterResolution(FloatSize size) const { return size * m_filterResolution; }
     
     virtual FloatRect sourceImageRect() const = 0;
     virtual FloatRect filterRegion() const = 0;
index 9b3baac..d261c7d 100644 (file)
@@ -35,7 +35,7 @@ namespace WebCore {
 
 static inline IntSize outsetSizeForBlur(float stdDeviation)
 {
-    auto kernelSize = FEGaussianBlur::calculateUnscaledKernelSize(FloatPoint(stdDeviation, stdDeviation));
+    auto kernelSize = FEGaussianBlur::calculateUnscaledKernelSize({ stdDeviation, stdDeviation });
 
     // We take the half kernel size and multiply it with three, because we run box blur three times.
     return {
index f8eab8f..4b4492d 100644 (file)
@@ -67,6 +67,7 @@ private:
     bool m_startedFilterEffect { false };
 };
 
+// This is used to render filters for the CSS filter: property, and the filter() image function.
 class FilterEffectRenderer final : public Filter {
     WTF_MAKE_FAST_ALLOCATED;
 public:
index 2d85ae5..9a94a46 100644 (file)
@@ -34,18 +34,12 @@ SVGFilter::SVGFilter(const AffineTransform& absoluteTransform, const FloatRect&
     m_absoluteFilterRegion = absoluteTransform.mapRect(filterRegion);
 }
 
-float SVGFilter::applyHorizontalScale(float value) const
+FloatSize SVGFilter::scaledByFilterResolution(FloatSize size) const
 {
     if (m_effectBBoxMode)
-        value *= m_targetBoundingBox.width();
-    return Filter::applyHorizontalScale(value) * m_absoluteFilterRegion.width() / m_filterRegion.width();
-}
+        size = size * m_targetBoundingBox.size();
 
-float SVGFilter::applyVerticalScale(float value) const
-{
-    if (m_effectBBoxMode)
-        value *= m_targetBoundingBox.height();
-    return Filter::applyVerticalScale(value) * m_absoluteFilterRegion.height() / m_filterRegion.height();
+    return Filter::scaledByFilterResolution(size) * m_absoluteFilterRegion.size() / m_filterRegion.size();
 }
 
 Ref<SVGFilter> SVGFilter::create(const AffineTransform& absoluteTransform, const FloatRect& absoluteSourceDrawingRegion, const FloatRect& targetBoundingBox, const FloatRect& filterRegion, bool effectBBoxMode)
index b40b98d..f780f5e 100644 (file)
@@ -36,8 +36,7 @@ public:
     FloatRect filterRegionInUserSpace() const { return m_filterRegion; }
     FloatRect filterRegion() const final { return m_absoluteFilterRegion; }
 
-    float applyHorizontalScale(float value) const final;
-    float applyVerticalScale(float value) const final;
+    FloatSize scaledByFilterResolution(FloatSize) const final;
 
     FloatRect sourceImageRect() const final { return m_absoluteSourceDrawingRegion; }
     FloatRect targetBoundingBox() const { return m_targetBoundingBox; }