Chromium Code Reviews| Index: third_party/WebKit/Source/platform/graphics/filters/FEGaussianBlur.cpp |
| diff --git a/third_party/WebKit/Source/platform/graphics/filters/FEGaussianBlur.cpp b/third_party/WebKit/Source/platform/graphics/filters/FEGaussianBlur.cpp |
| index 1527161d5a95be30a359dca05bd8921534a50ecf..0646df1a5242d925a0fe6f5a21111d7b7d53d340 100644 |
| --- a/third_party/WebKit/Source/platform/graphics/filters/FEGaussianBlur.cpp |
| +++ b/third_party/WebKit/Source/platform/graphics/filters/FEGaussianBlur.cpp |
| @@ -31,54 +31,44 @@ |
| #include "SkBlurImageFilter.h" |
| -static inline float gaussianKernelFactor() { |
| - return 3 / 4.f * sqrtf(twoPiFloat); |
| -} |
| - |
| namespace blink { |
| -FEGaussianBlur::FEGaussianBlur(Filter* filter, float x, float y) |
| - : FilterEffect(filter), m_stdX(x), m_stdY(y) {} |
| +namespace { |
| -FEGaussianBlur* FEGaussianBlur::create(Filter* filter, float x, float y) { |
| - return new FEGaussianBlur(filter, x, y); |
| +inline unsigned approximateBoxWidth(float s) { |
| + return static_cast<unsigned>( |
| + floorf(s * (3 / 4.f * sqrtf(twoPiFloat)) + 0.5f)); |
| } |
| -IntSize FEGaussianBlur::calculateUnscaledKernelSize(const FloatPoint& std) { |
| - ASSERT(std.x() >= 0 && std.y() >= 0); |
| - |
| +IntSize calculateKernelSize(const FloatSize& std) { |
| + DCHECK(std.width() >= 0 && std.height() >= 0); |
| IntSize kernelSize; |
| // Limit the kernel size to 1000. A bigger radius won't make a big difference |
| // for the result image but inflates the absolute paint rect too much. This is |
| // compatible with Firefox' behavior. |
|
Stephen Chennney
2016/10/10 19:43:25
Where do we do this limiting? It would be nice of
fs
2016/10/10 20:40:03
It looks like this comment has outstayed its welco
fs
2016/10/10 20:43:53
Dropped.
|
| - if (std.x()) { |
| - int size = std::max<unsigned>( |
| - 2, |
| - static_cast<unsigned>(floorf(std.x() * gaussianKernelFactor() + 0.5f))); |
| + if (std.width()) { |
| + int size = std::max<unsigned>(2, approximateBoxWidth(std.width())); |
| kernelSize.setWidth(size); |
| } |
| - |
| - if (std.y()) { |
| - int size = std::max<unsigned>( |
| - 2, |
| - static_cast<unsigned>(floorf(std.y() * gaussianKernelFactor() + 0.5f))); |
| + if (std.height()) { |
| + int size = std::max<unsigned>(2, approximateBoxWidth(std.height())); |
| kernelSize.setHeight(size); |
| } |
| - |
| return kernelSize; |
| } |
| -IntSize FEGaussianBlur::calculateKernelSize(const Filter* filter, |
| - const FloatPoint& std) { |
| - FloatPoint stdError(filter->applyHorizontalScale(std.x()), |
| - filter->applyVerticalScale(std.y())); |
| - return calculateUnscaledKernelSize(stdError); |
| } |
| -FloatRect FEGaussianBlur::mapEffect(const FloatRect& rect) const { |
| - IntSize kernelSize = |
| - calculateKernelSize(getFilter(), FloatPoint(m_stdX, m_stdY)); |
| +FEGaussianBlur::FEGaussianBlur(Filter* filter, float x, float y) |
| + : FilterEffect(filter), m_stdX(x), m_stdY(y) {} |
| +FEGaussianBlur* FEGaussianBlur::create(Filter* filter, float x, float y) { |
| + return new FEGaussianBlur(filter, x, y); |
| +} |
| + |
| +FloatRect FEGaussianBlur::mapEffect(const FloatSize& stdDeviation, |
| + const FloatRect& rect) { |
| + IntSize kernelSize = calculateKernelSize(stdDeviation); |
| // We take the half kernel size and multiply it by three, because we run box |
| // blur three times. |
| FloatRect result = rect; |
| @@ -87,6 +77,12 @@ FloatRect FEGaussianBlur::mapEffect(const FloatRect& rect) const { |
| return result; |
| } |
| +FloatRect FEGaussianBlur::mapEffect(const FloatRect& rect) const { |
| + FloatSize stdError(getFilter()->applyHorizontalScale(m_stdX), |
| + getFilter()->applyVerticalScale(m_stdY)); |
| + return mapEffect(stdError, rect); |
| +} |
| + |
| sk_sp<SkImageFilter> FEGaussianBlur::createImageFilter() { |
| sk_sp<SkImageFilter> input( |
| SkiaImageFilterBuilder::build(inputEffect(0), operatingColorSpace())); |