2 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
3 * Copyright (C) 2013 Google Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include "FloatRect.h"
26 #include "FloatSize.h"
27 #include "ImageBuffer.h"
28 #include <wtf/RefCounted.h>
34 class Filter : public RefCounted<Filter> {
36 Filter(const AffineTransform& absoluteTransform)
37 : m_absoluteTransform(absoluteTransform)
38 , m_renderingMode(Unaccelerated)
42 void setSourceImage(std::unique_ptr<ImageBuffer> sourceImage) { m_sourceImage = std::move(sourceImage); }
43 ImageBuffer* sourceImage() { return m_sourceImage.get(); }
45 FloatSize filterResolution() const { return m_filterResolution; }
46 void setFilterResolution(const FloatSize& filterResolution) { m_filterResolution = filterResolution; }
48 const AffineTransform& absoluteTransform() const { return m_absoluteTransform; }
49 FloatPoint mapAbsolutePointToLocalPoint(const FloatPoint& point) const { return m_absoluteTransform.inverse().mapPoint(point); }
51 RenderingMode renderingMode() const { return m_renderingMode; }
52 void setRenderingMode(RenderingMode renderingMode) { m_renderingMode = renderingMode; }
54 virtual bool isSVGFilter() const { return false; }
56 virtual float applyHorizontalScale(float value) const { return value * m_filterResolution.width(); }
57 virtual float applyVerticalScale(float value) const { return value * m_filterResolution.height(); }
59 virtual FloatRect sourceImageRect() const = 0;
60 virtual FloatRect filterRegion() const = 0;
63 std::unique_ptr<ImageBuffer> m_sourceImage;
64 FloatSize m_filterResolution;
65 AffineTransform m_absoluteTransform;
66 RenderingMode m_renderingMode;
69 #define FILTER_TYPE_CASTS(ToValueTypeName, predicate) \
70 TYPE_CASTS_BASE(ToValueTypeName, Filter, filter, filter->predicate, filter.predicate)
72 } // namespace WebCore
74 #endif // ENABLE(FILTERS)