| Index: third_party/WebKit/Source/platform/graphics/filters/FEConvolveMatrix.cpp
|
| diff --git a/third_party/WebKit/Source/platform/graphics/filters/FEConvolveMatrix.cpp b/third_party/WebKit/Source/platform/graphics/filters/FEConvolveMatrix.cpp
|
| index ba5df1f46f830224b97dd2eb5b32e9838338ed94..bb715e08461556b02e879c9d1f57f98e84d16af5 100644
|
| --- a/third_party/WebKit/Source/platform/graphics/filters/FEConvolveMatrix.cpp
|
| +++ b/third_party/WebKit/Source/platform/graphics/filters/FEConvolveMatrix.cpp
|
| @@ -44,8 +44,6 @@ FEConvolveMatrix::FEConvolveMatrix(Filter* filter, const IntSize& kernelSize,
|
| , m_preserveAlpha(preserveAlpha)
|
| , m_kernelMatrix(kernelMatrix)
|
| {
|
| - ASSERT(m_kernelSize.width() > 0);
|
| - ASSERT(m_kernelSize.height() > 0);
|
| }
|
|
|
| PassRefPtrWillBeRawPtr<FEConvolveMatrix> FEConvolveMatrix::create(Filter* filter, const IntSize& kernelSize,
|
| @@ -59,53 +57,21 @@ PassRefPtrWillBeRawPtr<FEConvolveMatrix> FEConvolveMatrix::create(Filter* filter
|
| FloatRect FEConvolveMatrix::mapPaintRect(const FloatRect& rect, bool forward)
|
| {
|
| FloatRect result = rect;
|
| -
|
| - result.moveBy(forward ? -m_targetOffset : m_targetOffset - m_kernelSize);
|
| - result.expand(m_kernelSize);
|
| + if (parametersValid()) {
|
| + result.moveBy(forward ? -m_targetOffset : m_targetOffset - m_kernelSize);
|
| + result.expand(m_kernelSize);
|
| + }
|
| return result;
|
| }
|
|
|
| -IntSize FEConvolveMatrix::kernelSize() const
|
| -{
|
| - return m_kernelSize;
|
| -}
|
| -
|
| -void FEConvolveMatrix::setKernelSize(const IntSize& kernelSize)
|
| -{
|
| - ASSERT(kernelSize.width() > 0);
|
| - ASSERT(kernelSize.height() > 0);
|
| - m_kernelSize = kernelSize;
|
| -}
|
| -
|
| -const Vector<float>& FEConvolveMatrix::kernel() const
|
| -{
|
| - return m_kernelMatrix;
|
| -}
|
| -
|
| -void FEConvolveMatrix::setKernel(const Vector<float>& kernel)
|
| -{
|
| - m_kernelMatrix = kernel;
|
| -}
|
| -
|
| -float FEConvolveMatrix::divisor() const
|
| -{
|
| - return m_divisor;
|
| -}
|
| -
|
| bool FEConvolveMatrix::setDivisor(float divisor)
|
| {
|
| - ASSERT(divisor);
|
| if (m_divisor == divisor)
|
| return false;
|
| m_divisor = divisor;
|
| return true;
|
| }
|
|
|
| -float FEConvolveMatrix::bias() const
|
| -{
|
| - return m_bias;
|
| -}
|
| -
|
| bool FEConvolveMatrix::setBias(float bias)
|
| {
|
| if (m_bias == bias)
|
| @@ -114,11 +80,6 @@ bool FEConvolveMatrix::setBias(float bias)
|
| return true;
|
| }
|
|
|
| -IntPoint FEConvolveMatrix::targetOffset() const
|
| -{
|
| - return m_targetOffset;
|
| -}
|
| -
|
| bool FEConvolveMatrix::setTargetOffset(const IntPoint& targetOffset)
|
| {
|
| if (m_targetOffset == targetOffset)
|
| @@ -127,11 +88,6 @@ bool FEConvolveMatrix::setTargetOffset(const IntPoint& targetOffset)
|
| return true;
|
| }
|
|
|
| -EdgeModeType FEConvolveMatrix::edgeMode() const
|
| -{
|
| - return m_edgeMode;
|
| -}
|
| -
|
| bool FEConvolveMatrix::setEdgeMode(EdgeModeType edgeMode)
|
| {
|
| if (m_edgeMode == edgeMode)
|
| @@ -140,11 +96,6 @@ bool FEConvolveMatrix::setEdgeMode(EdgeModeType edgeMode)
|
| return true;
|
| }
|
|
|
| -bool FEConvolveMatrix::preserveAlpha() const
|
| -{
|
| - return m_preserveAlpha;
|
| -}
|
| -
|
| bool FEConvolveMatrix::setPreserveAlpha(bool preserveAlpha)
|
| {
|
| if (m_preserveAlpha == preserveAlpha)
|
| @@ -167,12 +118,34 @@ SkMatrixConvolutionImageFilter::TileMode toSkiaTileMode(EdgeModeType edgeMode)
|
| }
|
| }
|
|
|
| +bool FEConvolveMatrix::parametersValid() const
|
| +{
|
| + if (m_kernelSize.isEmpty())
|
| + return false;
|
| + uint64_t kernelArea = m_kernelSize.area();
|
| + if (!WTF::isInBounds<int>(kernelArea))
|
| + return false;
|
| + if (safeCast<size_t>(kernelArea) != m_kernelMatrix.size())
|
| + return false;
|
| + if (m_targetOffset.x() < 0 || m_targetOffset.x() >= m_kernelSize.width())
|
| + return false;
|
| + if (m_targetOffset.y() < 0 || m_targetOffset.y() >= m_kernelSize.height())
|
| + return false;
|
| + if (!m_divisor)
|
| + return false;
|
| + return true;
|
| +}
|
| +
|
| PassRefPtr<SkImageFilter> FEConvolveMatrix::createImageFilter(SkiaImageFilterBuilder* builder)
|
| {
|
| + if (!parametersValid())
|
| + return createTransparentBlack();
|
| +
|
| RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpace()));
|
|
|
| SkISize kernelSize(SkISize::Make(m_kernelSize.width(), m_kernelSize.height()));
|
| - int numElements = kernelSize.width() * kernelSize.height();
|
| + // parametersValid() above checks that the kernel area fits in int.
|
| + int numElements = safeCast<int>(m_kernelSize.area());
|
| SkScalar gain = SkFloatToScalar(1.0f / m_divisor);
|
| SkScalar bias = SkFloatToScalar(m_bias * 255);
|
| SkIPoint target = SkIPoint::Make(m_targetOffset.x(), m_targetOffset.y());
|
|
|