#ifndef Filter_h
#define Filter_h
#include "platform/PlatformExport.h"
#include "platform/geometry/FloatRect.h"
#include "platform/geometry/FloatSize.h"
#include "platform/graphics/ImageBuffer.h"
#include "wtf/RefCounted.h"
namespace WebCore {
class FilterEffect;
class PLATFORM_EXPORT Filter : public RefCounted<Filter> {
public:
Filter(const AffineTransform& absoluteTransform)
: m_absoluteTransform(absoluteTransform)
, m_inverseTransform(absoluteTransform.inverse())
{
ASSERT(!absoluteTransform.b() && !absoluteTransform.c());
}
virtual ~Filter() { }
void setSourceImage(PassOwnPtr<ImageBuffer> sourceImage) { m_sourceImage = sourceImage; }
ImageBuffer* sourceImage() { return m_sourceImage.get(); }
const AffineTransform& absoluteTransform() const { return m_absoluteTransform; }
void setAbsoluteTransform(const AffineTransform& absoluteTransform)
{
ASSERT(!absoluteTransform.b() && !absoluteTransform.c());
m_absoluteTransform = absoluteTransform;
m_inverseTransform = absoluteTransform.inverse();
m_absoluteFilterRegion = m_absoluteTransform.mapRect(m_filterRegion);
}
FloatPoint mapAbsolutePointToLocalPoint(const FloatPoint& point) const { return m_inverseTransform.mapPoint(point); }
FloatRect mapLocalRectToAbsoluteRect(const FloatRect& rect) const { return m_absoluteTransform.mapRect(rect); }
FloatRect mapAbsoluteRectToLocalRect(const FloatRect& rect) const { return m_inverseTransform.mapRect(rect); }
virtual float applyHorizontalScale(float value) const
{
return value * m_absoluteTransform.a();
}
virtual float applyVerticalScale(float value) const
{
return value * m_absoluteTransform.d();
}
virtual IntRect sourceImageRect() const = 0;
FloatRect absoluteFilterRegion() const { return m_absoluteFilterRegion; }
FloatRect filterRegion() const { return m_filterRegion; }
void setFilterRegion(const FloatRect& rect)
{
m_filterRegion = rect;
m_absoluteFilterRegion = m_absoluteTransform.mapRect(m_filterRegion);
}
private:
OwnPtr<ImageBuffer> m_sourceImage;
AffineTransform m_absoluteTransform;
AffineTransform m_inverseTransform;
FloatRect m_absoluteFilterRegion;
FloatRect m_filterRegion;
};
}
#endif