Skip to content
Permalink
Browse files
2009-11-23 Dirk Schulze <krit@webkit.org>
        Reviewed by Nikolas Zimmermann.

        This is the implementation of the filterRes attribute. It
        helps the SVG developer to set the quality of a filter by
        giving the width or height of filter.
        This patch also sets the filter resolution to lower values
        if a intermediate ImageBuffer size is bigger than the given
        maximal size.
        The maximal size is set to 5000x5000 by default. This is a
        subjectiv decission. Everthing greater than this values gets
        sensible slower. Values of 10000x10000 crashed on WebKitGtk.
        For mobil devices a maximum size of 100x100 or 200x200 seems
        to be reasonable.
        The important fact on filter resolution is, that the output
        size is still the size given by the <filter> element.

        Tests: svg/filters/big-sized-filter-2.svg
               svg/filters/big-sized-filter.svg
               svg/filters/filterRes.svg

        * platform/graphics/FloatRect.cpp:
        (WebCore::FloatRect::scale): Add the abbility to scale a rect by x and y.
        * platform/graphics/FloatRect.h:
        (WebCore::FloatRect::scale): Add the abbility to scale a rect by x and y.
        * platform/graphics/cairo/GraphicsContextCairo.cpp:
        (WebCore::GraphicsContext::createPlatformShadow): Use scaledSubRegion for
        calculation.
        * platform/graphics/filters/FEBlend.cpp:
        (WebCore::FEBlend::apply): Use scaledSubRegion for effect intern calculations.
        * platform/graphics/filters/FEColorMatrix.cpp:
        (WebCore::FEColorMatrix::apply): Use scaledSubRegion for effect intern calculations.
        * platform/graphics/filters/FEComponentTransfer.cpp:
        (WebCore::FEComponentTransfer::apply): Use scaledSubRegion for effect intern
        calculations.
        * platform/graphics/filters/FEComposite.cpp:
        (WebCore::FEComposite::apply): Use scaledSubRegion for effect intern calculations.
        * platform/graphics/filters/FEGaussianBlur.cpp:
        (WebCore::FEGaussianBlur::apply): Use scaledSubRegion for effect intern calculations.
        * platform/graphics/filters/Filter.h: Add the abbility to change the quality
        of a filter output.
        (WebCore::Filter::filterResolution):
        (WebCore::Filter::setFilterResolution):
        (WebCore::Filter::calculateEffectSubRegion): Calculates the correct subRegion
        as well as the scaledSubRegion. It also searches for the biggest effect size.
        We have to change the filter resolution, if one intermediate ImageBuffer size
        doesn't fit in the maximal image size.
        * platform/graphics/filters/FilterEffect.cpp:
        (WebCore::FilterEffect::calculateDrawingIntRect): Use scaledSubRegion to get
        the right part of a previous effect result.
        (WebCore::FilterEffect::calculateDrawingRect): Use scaledSubRegion to get
        the right part of a previous effect result.
        (WebCore::FilterEffect::getEffectContext): Use scaledSubRegion to create
        a new intermediate ImageBuffer for the result of the current effect.
        * platform/graphics/filters/FilterEffect.h:
        (WebCore::FilterEffect::scaledSubRegion): The scaled subRegion of a the
        filter effect.
        (WebCore::FilterEffect::setScaledSubRegion):
        (WebCore::FilterEffect::effectBoundaries): The original values of the
        EffectElement for a second subRegion calculation.
        (WebCore::FilterEffect::setEffectBoundaries):
        * platform/graphics/filters/ImageBufferFilter.cpp:
        (WebCore::ImageBufferFilter::ImageBufferFilter): Set the scale factor to one.
        * platform/graphics/filters/ImageBufferFilter.h:
        (WebCore::ImageBufferFilter::maxImageSize):
        (WebCore::ImageBufferFilter::calculateEffectSubRegion):
        * platform/graphics/filters/SourceAlpha.cpp:
        (WebCore::SourceAlpha::calculateEffectRect): Use scaledSubRegion for effect
        intern calculations.
        * platform/graphics/filters/SourceGraphic.cpp:
        (WebCore::SourceGraphic::calculateEffectRect): Use scaledSubRegion for effect
        intern calculations.
        * svg/SVGFilterElement.cpp:
        (WebCore::SVGFilterElement::parseMappedAttribute): Parse filterRes attribute.
        (WebCore::SVGFilterElement::buildFilter): Give SVGResourceFilter the current
        filterResolution.
        * svg/SVGFilterPrimitiveStandardAttributes.cpp:
        (WebCore::SVGFilterPrimitiveStandardAttributes::setStandardAttributes): Save
        values to effectBoundaries of the filter effect
        * svg/graphics/SVGResourceFilter.cpp:
        (WebCore::SVGResourceFilter::SVGResourceFilter):
        (WebCore::shouldProcessFilter): Return signal if a neccessary value is zero.
        (WebCore::SVGResourceFilter::fitsInMaximumImageSize): Checks if the given size
        fits into the maximal image size, modifys scale factors if not and return a
        bool: fits.
        (WebCore::SVGResourceFilter::prepareFilter): Scale the SourceImage to
        filterResolution (given by FilterElement or calculated on to big image sizes).
        Set the scale level to SVGFilter.
        (WebCore::SVGResourceFilter::applyFilter): Don't apply filters if shouldProcessFilter
        is wrong.
        * svg/graphics/SVGResourceFilter.h:
        (WebCore::SVGResourceFilter::setFilterResolution): FilterResolution of FilterElement.
        (WebCore::SVGResourceFilter::setHasFilterResolution): Does FilterElement provides
        a FilterResolution?
        (WebCore::SVGResourceFilter::scaleX): Current scale factor for horizontal.
        (WebCore::SVGResourceFilter::scaleY): Current scale factor for vertical.
        * svg/graphics/filters/SVGFEDisplacementMap.cpp:
        (WebCore::FEDisplacementMap::apply): Use scaledSubRegion for effect intern calculations.
        Kernel values are scaled to current filter resolution too.
        * svg/graphics/filters/SVGFEFlood.cpp:
        (WebCore::FEFlood::apply): Use scaledSubRegion for effect intern calculations.
        * svg/graphics/filters/SVGFEMerge.cpp:
        (WebCore::FEMerge::apply): Use scaledSubRegion for effect intern calculations.
        Kernel values are scaled to current filter resolution too.
        * svg/graphics/filters/SVGFEMorphology.cpp:
        (WebCore::FEMorphology::apply): Use scaledSubRegion for effect intern calculations.
        Kernel values are scaled to current filter resolution too.
        * svg/graphics/filters/SVGFEOffset.cpp:
        (WebCore::FEOffset::apply): Use scaledSubRegion for effect intern calculations.
        * svg/graphics/filters/SVGFETile.cpp:
        (WebCore::FETile::apply): Use scaledSubRegion for effect intern calculations.
        * svg/graphics/filters/SVGFilter.cpp:
        (WebCore::SVGFilter::calculateEffectSubRegion): Calculate subRegion for LayoutTests,
        scaledSubRegion according to the current filterResolution and get the maximal image size.
        * svg/graphics/filters/SVGFilter.h:
        (WebCore::SVGFilter::effectBoundingBoxMode): Original values of the FilterElement.
        (WebCore::SVGFilter::filterRegion): Use virtual for clarification.
        (WebCore::SVGFilter::sourceImageRect): Use virtual for clarification.
        (WebCore::SVGFilter::maxImageSize): Get the maximal image size.


Canonical link: https://commits.webkit.org/42739@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@51310 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
dirkschulze committed Nov 23, 2009
1 parent 96aac2e commit f1720092bb8506c57fc378cde8d6b4ac6ee71b99
Showing 28 changed files with 314 additions and 65 deletions.
@@ -1,3 +1,124 @@
2009-11-23 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

This is the implementation of the filterRes attribute. It
helps the SVG developer to set the quality of a filter by
giving the width or height of filter.
This patch also sets the filter resolution to lower values
if a intermediate ImageBuffer size is bigger than the given
maximal size.
The maximal size is set to 5000x5000 by default. This is a
subjectiv decission. Everthing greater than this values gets
sensible slower. Values of 10000x10000 crashed on WebKitGtk.
For mobil devices a maximum size of 100x100 or 200x200 seems
to be reasonable.
The important fact on filter resolution is, that the output
size is still the size given by the <filter> element.

Tests: svg/filters/big-sized-filter-2.svg
svg/filters/big-sized-filter.svg
svg/filters/filterRes.svg

* platform/graphics/FloatRect.cpp:
(WebCore::FloatRect::scale): Add the abbility to scale a rect by x and y.
* platform/graphics/FloatRect.h:
(WebCore::FloatRect::scale): Add the abbility to scale a rect by x and y.
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::createPlatformShadow): Use scaledSubRegion for
calculation.
* platform/graphics/filters/FEBlend.cpp:
(WebCore::FEBlend::apply): Use scaledSubRegion for effect intern calculations.
* platform/graphics/filters/FEColorMatrix.cpp:
(WebCore::FEColorMatrix::apply): Use scaledSubRegion for effect intern calculations.
* platform/graphics/filters/FEComponentTransfer.cpp:
(WebCore::FEComponentTransfer::apply): Use scaledSubRegion for effect intern
calculations.
* platform/graphics/filters/FEComposite.cpp:
(WebCore::FEComposite::apply): Use scaledSubRegion for effect intern calculations.
* platform/graphics/filters/FEGaussianBlur.cpp:
(WebCore::FEGaussianBlur::apply): Use scaledSubRegion for effect intern calculations.
* platform/graphics/filters/Filter.h: Add the abbility to change the quality
of a filter output.
(WebCore::Filter::filterResolution):
(WebCore::Filter::setFilterResolution):
(WebCore::Filter::calculateEffectSubRegion): Calculates the correct subRegion
as well as the scaledSubRegion. It also searches for the biggest effect size.
We have to change the filter resolution, if one intermediate ImageBuffer size
doesn't fit in the maximal image size.
* platform/graphics/filters/FilterEffect.cpp:
(WebCore::FilterEffect::calculateDrawingIntRect): Use scaledSubRegion to get
the right part of a previous effect result.
(WebCore::FilterEffect::calculateDrawingRect): Use scaledSubRegion to get
the right part of a previous effect result.
(WebCore::FilterEffect::getEffectContext): Use scaledSubRegion to create
a new intermediate ImageBuffer for the result of the current effect.
* platform/graphics/filters/FilterEffect.h:
(WebCore::FilterEffect::scaledSubRegion): The scaled subRegion of a the
filter effect.
(WebCore::FilterEffect::setScaledSubRegion):
(WebCore::FilterEffect::effectBoundaries): The original values of the
EffectElement for a second subRegion calculation.
(WebCore::FilterEffect::setEffectBoundaries):
* platform/graphics/filters/ImageBufferFilter.cpp:
(WebCore::ImageBufferFilter::ImageBufferFilter): Set the scale factor to one.
* platform/graphics/filters/ImageBufferFilter.h:
(WebCore::ImageBufferFilter::maxImageSize):
(WebCore::ImageBufferFilter::calculateEffectSubRegion):
* platform/graphics/filters/SourceAlpha.cpp:
(WebCore::SourceAlpha::calculateEffectRect): Use scaledSubRegion for effect
intern calculations.
* platform/graphics/filters/SourceGraphic.cpp:
(WebCore::SourceGraphic::calculateEffectRect): Use scaledSubRegion for effect
intern calculations.
* svg/SVGFilterElement.cpp:
(WebCore::SVGFilterElement::parseMappedAttribute): Parse filterRes attribute.
(WebCore::SVGFilterElement::buildFilter): Give SVGResourceFilter the current
filterResolution.
* svg/SVGFilterPrimitiveStandardAttributes.cpp:
(WebCore::SVGFilterPrimitiveStandardAttributes::setStandardAttributes): Save
values to effectBoundaries of the filter effect
* svg/graphics/SVGResourceFilter.cpp:
(WebCore::SVGResourceFilter::SVGResourceFilter):
(WebCore::shouldProcessFilter): Return signal if a neccessary value is zero.
(WebCore::SVGResourceFilter::fitsInMaximumImageSize): Checks if the given size
fits into the maximal image size, modifys scale factors if not and return a
bool: fits.
(WebCore::SVGResourceFilter::prepareFilter): Scale the SourceImage to
filterResolution (given by FilterElement or calculated on to big image sizes).
Set the scale level to SVGFilter.
(WebCore::SVGResourceFilter::applyFilter): Don't apply filters if shouldProcessFilter
is wrong.
* svg/graphics/SVGResourceFilter.h:
(WebCore::SVGResourceFilter::setFilterResolution): FilterResolution of FilterElement.
(WebCore::SVGResourceFilter::setHasFilterResolution): Does FilterElement provides
a FilterResolution?
(WebCore::SVGResourceFilter::scaleX): Current scale factor for horizontal.
(WebCore::SVGResourceFilter::scaleY): Current scale factor for vertical.
* svg/graphics/filters/SVGFEDisplacementMap.cpp:
(WebCore::FEDisplacementMap::apply): Use scaledSubRegion for effect intern calculations.
Kernel values are scaled to current filter resolution too.
* svg/graphics/filters/SVGFEFlood.cpp:
(WebCore::FEFlood::apply): Use scaledSubRegion for effect intern calculations.
* svg/graphics/filters/SVGFEMerge.cpp:
(WebCore::FEMerge::apply): Use scaledSubRegion for effect intern calculations.
Kernel values are scaled to current filter resolution too.
* svg/graphics/filters/SVGFEMorphology.cpp:
(WebCore::FEMorphology::apply): Use scaledSubRegion for effect intern calculations.
Kernel values are scaled to current filter resolution too.
* svg/graphics/filters/SVGFEOffset.cpp:
(WebCore::FEOffset::apply): Use scaledSubRegion for effect intern calculations.
* svg/graphics/filters/SVGFETile.cpp:
(WebCore::FETile::apply): Use scaledSubRegion for effect intern calculations.
* svg/graphics/filters/SVGFilter.cpp:
(WebCore::SVGFilter::calculateEffectSubRegion): Calculate subRegion for LayoutTests,
scaledSubRegion according to the current filterResolution and get the maximal image size.
* svg/graphics/filters/SVGFilter.h:
(WebCore::SVGFilter::effectBoundingBoxMode): Original values of the FilterElement.
(WebCore::SVGFilter::filterRegion): Use virtual for clarification.
(WebCore::SVGFilter::sourceImageRect): Use virtual for clarification.
(WebCore::SVGFilter::maxImageSize): Get the maximal image size.

2009-11-23 Simon Hausmann <simon.hausmann@nokia.com>

Reviewed by Kenneth Rohde Christiansen.
@@ -102,12 +102,12 @@ void FloatRect::unite(const FloatRect& other)
m_size.setHeight(b - t);
}

void FloatRect::scale(float s)
void FloatRect::scale(float sx, float sy)
{
m_location.setX(x() * s);
m_location.setY(y() * s);
m_size.setWidth(width() * s);
m_size.setHeight(height() * s);
m_location.setX(x() * sx);
m_location.setY(y() * sy);
m_size.setWidth(width() * sx);
m_size.setHeight(height() * sy);
}

IntRect enclosingIntRect(const FloatRect& rect)
@@ -120,7 +120,8 @@ class FloatRect {
m_size.setHeight(m_size.height() + dy + dy);
}
void inflate(float d) { inflateX(d); inflateY(d); }
void scale(float s);
void scale(float s) { scale(s, s); }
void scale(float sx, float sy);

#if PLATFORM(CG)
FloatRect(const CGRect&);
@@ -860,10 +860,10 @@ void GraphicsContext::createPlatformShadow(PassOwnPtr<ImageBuffer> buffer, const
RefPtr<Filter> filter = ImageBufferFilter::create();
filter->setSourceImage(buffer.release());
RefPtr<FilterEffect> source = SourceGraphic::create();
source->setSubRegion(FloatRect(FloatPoint(), shadowRect.size()));
source->setScaledSubRegion(FloatRect(FloatPoint(), shadowRect.size()));
source->setIsAlphaImage(true);
RefPtr<FilterEffect> blur = FEGaussianBlur::create(source.get(), kernelSize, kernelSize);
blur->setSubRegion(FloatRect(FloatPoint(), shadowRect.size()));
blur->setScaledSubRegion(FloatRect(FloatPoint(), shadowRect.size()));
blur->apply(filter.get());

// Mask the filter with the shadow color and draw it to the context.
@@ -111,10 +111,10 @@ void FEBlend::apply(Filter* filter)
if (!getEffectContext())
return;

IntRect effectADrawingRect = calculateDrawingIntRect(m_in->subRegion());
IntRect effectADrawingRect = calculateDrawingIntRect(m_in->scaledSubRegion());
RefPtr<CanvasPixelArray> srcPixelArrayA(m_in->resultImage()->getPremultipliedImageData(effectADrawingRect)->data());

IntRect effectBDrawingRect = calculateDrawingIntRect(m_in2->subRegion());
IntRect effectBDrawingRect = calculateDrawingIntRect(m_in2->scaledSubRegion());
RefPtr<CanvasPixelArray> srcPixelArrayB(m_in2->resultImage()->getPremultipliedImageData(effectBDrawingRect)->data());

IntRect imageRect(IntPoint(), resultImage()->size());
@@ -164,7 +164,7 @@ void FEColorMatrix::apply(Filter* filter)
if (!filterContext)
return;

filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->subRegion()));
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->scaledSubRegion()));

IntRect imageRect(IntPoint(), resultImage()->size());
PassRefPtr<ImageData> imageData(resultImage()->getUnmultipliedImageData(imageRect));
@@ -165,7 +165,7 @@ void FEComponentTransfer::apply(Filter* filter)
for (unsigned channel = 0; channel < 4; channel++)
(*callEffect[transferFunction[channel].type])(tables[channel], transferFunction[channel]);

IntRect drawingRect = calculateDrawingIntRect(m_in->subRegion());
IntRect drawingRect = calculateDrawingIntRect(m_in->scaledSubRegion());
RefPtr<ImageData> imageData(m_in->resultImage()->getUnmultipliedImageData(drawingRect));
CanvasPixelArray* srcPixelArray(imageData->data());

@@ -133,32 +133,32 @@ void FEComposite::apply(Filter* filter)
FloatRect srcRect = FloatRect(0.f, 0.f, -1.f, -1.f);
switch (m_type) {
case FECOMPOSITE_OPERATOR_OVER:
filterContext->drawImage(m_in2->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in2->subRegion()));
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->subRegion()));
filterContext->drawImage(m_in2->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in2->scaledSubRegion()));
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->scaledSubRegion()));
break;
case FECOMPOSITE_OPERATOR_IN:
filterContext->save();
filterContext->clipToImageBuffer(calculateDrawingRect(m_in2->subRegion()), m_in2->resultImage());
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->subRegion()));
filterContext->clipToImageBuffer(calculateDrawingRect(m_in2->scaledSubRegion()), m_in2->resultImage());
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->scaledSubRegion()));
filterContext->restore();
break;
case FECOMPOSITE_OPERATOR_OUT:
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->subRegion()));
filterContext->drawImage(m_in2->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in2->subRegion()), srcRect, CompositeDestinationOut);
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->scaledSubRegion()));
filterContext->drawImage(m_in2->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in2->scaledSubRegion()), srcRect, CompositeDestinationOut);
break;
case FECOMPOSITE_OPERATOR_ATOP:
filterContext->drawImage(m_in2->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in2->subRegion()));
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->subRegion()), srcRect, CompositeSourceAtop);
filterContext->drawImage(m_in2->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in2->scaledSubRegion()));
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->scaledSubRegion()), srcRect, CompositeSourceAtop);
break;
case FECOMPOSITE_OPERATOR_XOR:
filterContext->drawImage(m_in2->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in2->subRegion()));
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->subRegion()), srcRect, CompositeXOR);
filterContext->drawImage(m_in2->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in2->scaledSubRegion()));
filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, calculateDrawingRect(m_in->scaledSubRegion()), srcRect, CompositeXOR);
break;
case FECOMPOSITE_OPERATOR_ARITHMETIC: {
IntRect effectADrawingRect = calculateDrawingIntRect(m_in->subRegion());
IntRect effectADrawingRect = calculateDrawingIntRect(m_in->scaledSubRegion());
RefPtr<CanvasPixelArray> srcPixelArrayA(m_in->resultImage()->getPremultipliedImageData(effectADrawingRect)->data());

IntRect effectBDrawingRect = calculateDrawingIntRect(m_in2->subRegion());
IntRect effectBDrawingRect = calculateDrawingIntRect(m_in2->scaledSubRegion());
RefPtr<ImageData> imageData(m_in2->resultImage()->getPremultipliedImageData(effectBDrawingRect));
CanvasPixelArray* srcPixelArrayB(imageData->data());

@@ -32,6 +32,8 @@
#include <math.h>
#include <wtf/MathExtras.h>

using std::max;

namespace WebCore {

FEGaussianBlur::FEGaussianBlur(FilterEffect* in, const float& x, const float& y)
@@ -111,10 +113,12 @@ void FEGaussianBlur::apply(Filter* filter)
if (m_x == 0 || m_y == 0)
return;

unsigned sdx = static_cast<unsigned>(floor(m_x * 3 * sqrt(2 * piDouble) / 4.f + 0.5f));
unsigned sdy = static_cast<unsigned>(floor(m_y * 3 * sqrt(2 * piDouble) / 4.f + 0.5f));
unsigned sdx = static_cast<unsigned>(floor(m_x * filter->filterResolution().width() * 3 * sqrt(2 * piDouble) / 4.f + 0.5f));
unsigned sdy = static_cast<unsigned>(floor(m_y * filter->filterResolution().height() * 3 * sqrt(2 * piDouble) / 4.f + 0.5f));
sdx = max(sdx, static_cast<unsigned>(1));
sdy = max(sdy, static_cast<unsigned>(1));

IntRect effectDrawingRect = calculateDrawingIntRect(m_in->subRegion());
IntRect effectDrawingRect = calculateDrawingIntRect(m_in->scaledSubRegion());
RefPtr<ImageData> srcImageData(m_in->resultImage()->getPremultipliedImageData(effectDrawingRect));
CanvasPixelArray* srcPixelArray(srcImageData->data());

@@ -22,6 +22,7 @@

#if ENABLE(FILTERS)
#include "FloatRect.h"
#include "FloatSize.h"
#include "ImageBuffer.h"
#include "StringHash.h"

@@ -40,15 +41,21 @@ namespace WebCore {
void setSourceImage(PassOwnPtr<ImageBuffer> sourceImage) { m_sourceImage = sourceImage; }
ImageBuffer* sourceImage() { return m_sourceImage.get(); }

FloatSize filterResolution() const { return m_filterResolution; }
void setFilterResolution(const FloatSize& filterResolution) { m_filterResolution = filterResolution; }

virtual FloatRect sourceImageRect() const = 0;
virtual FloatRect filterRegion() const = 0;

// SVG specific
virtual void calculateEffectSubRegion(FilterEffect*) const = 0;
virtual void calculateEffectSubRegion(FilterEffect*) { }

virtual FloatSize maxImageSize() const = 0;
virtual bool effectBoundingBoxMode() const = 0;

private:
OwnPtr<ImageBuffer> m_sourceImage;
FloatSize m_filterResolution;
};

} // namespace WebCore
@@ -58,21 +58,21 @@ FloatRect FilterEffect::calculateEffectRect(Filter* filter)

IntRect FilterEffect::calculateDrawingIntRect(const FloatRect& effectRect)
{
IntPoint location = roundedIntPoint(FloatPoint(subRegion().x() - effectRect.x(),
subRegion().y() - effectRect.y()));
IntPoint location = roundedIntPoint(FloatPoint(scaledSubRegion().x() - effectRect.x(),
scaledSubRegion().y() - effectRect.y()));
return IntRect(location, resultImage()->size());
}

FloatRect FilterEffect::calculateDrawingRect(const FloatRect& srcRect)
{
FloatPoint startPoint = FloatPoint(srcRect.x() - subRegion().x(), srcRect.y() - subRegion().y());
FloatPoint startPoint = FloatPoint(srcRect.x() - scaledSubRegion().x(), srcRect.y() - scaledSubRegion().y());
FloatRect drawingRect = FloatRect(startPoint, srcRect.size());
return drawingRect;
}

GraphicsContext* FilterEffect::getEffectContext()
{
IntRect bufferRect = enclosingIntRect(subRegion());
IntRect bufferRect = enclosingIntRect(scaledSubRegion());
m_effectBuffer = ImageBuffer::create(bufferRect.size(), LinearRGB);
return m_effectBuffer->context();
}
@@ -44,6 +44,12 @@ namespace WebCore {
FloatRect subRegion() const { return m_subRegion; }
void setSubRegion(const FloatRect& subRegion) { m_subRegion = subRegion; }

FloatRect scaledSubRegion() const { return m_scaledSubRegion; }
void setScaledSubRegion(const FloatRect& scaledSubRegion) { m_scaledSubRegion = scaledSubRegion; }

FloatRect effectBoundaries() const { return m_effectBoundaries; }
void setEffectBoundaries(const FloatRect& effectBoundaries) { m_effectBoundaries = effectBoundaries; }

bool hasX() { return m_hasX; }
void setHasX(bool value) { m_hasX = value; }

@@ -96,7 +102,9 @@ namespace WebCore {

bool m_alphaImage;

FloatRect m_effectBoundaries;
FloatRect m_subRegion;
FloatRect m_scaledSubRegion;
FloatRect m_unionOfChildEffectSubregions;

mutable OwnPtr<ImageBuffer> m_effectBuffer;
@@ -23,11 +23,14 @@
#if ENABLE(FILTERS)
#include "ImageBufferFilter.h"

#include "FloatSize.h"

namespace WebCore {

ImageBufferFilter::ImageBufferFilter()
: Filter()
{
setFilterResolution(FloatSize(1.f, 1.f));
}

PassRefPtr<ImageBufferFilter> ImageBufferFilter::create()
@@ -25,6 +25,7 @@
#include "Filter.h"
#include "FilterEffect.h"
#include "FloatRect.h"
#include "FloatSize.h"

#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
@@ -41,7 +42,9 @@ class ImageBufferFilter : public Filter {

// SVG specific
virtual bool effectBoundingBoxMode() const { return false; }
virtual void calculateEffectSubRegion(FilterEffect*) const { }

virtual FloatSize maxImageSize() const { return FloatSize(); }
virtual void calculateEffectSubRegion(FilterEffect*) { }

private:
ImageBufferFilter();

0 comments on commit f172009

Please sign in to comment.