1/*
2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB.  If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24#ifndef RenderSVGResourceFilter_h
25#define RenderSVGResourceFilter_h
26
27#include "core/rendering/svg/RenderSVGResourceContainer.h"
28#include "core/svg/SVGFilterElement.h"
29#include "core/svg/graphics/filters/SVGFilter.h"
30#include "core/svg/graphics/filters/SVGFilterBuilder.h"
31
32namespace WebCore {
33
34struct FilterData {
35    WTF_MAKE_FAST_ALLOCATED;
36public:
37    enum FilterDataState { PaintingSource, Applying, Built, CycleDetected, MarkedForRemoval };
38
39    FilterData()
40        : savedContext(0)
41        , state(PaintingSource)
42    {
43    }
44
45    RefPtr<SVGFilter> filter;
46    RefPtr<SVGFilterBuilder> builder;
47    OwnPtr<ImageBuffer> sourceGraphicBuffer;
48    GraphicsContext* savedContext;
49    AffineTransform shearFreeAbsoluteTransform;
50    FloatRect boundaries;
51    FloatRect drawingRegion;
52    FloatSize scale;
53    FilterDataState state;
54};
55
56class GraphicsContext;
57
58class RenderSVGResourceFilter FINAL : public RenderSVGResourceContainer {
59public:
60    explicit RenderSVGResourceFilter(SVGFilterElement*);
61    virtual ~RenderSVGResourceFilter();
62
63    virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE;
64
65    virtual const char* renderName() const OVERRIDE { return "RenderSVGResourceFilter"; }
66    virtual bool isSVGResourceFilter() const OVERRIDE { return true; }
67
68    virtual void removeAllClientsFromCache(bool markForInvalidation = true) OVERRIDE;
69    virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true) OVERRIDE;
70
71    virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode) OVERRIDE;
72    virtual void postApplyResource(RenderObject*, GraphicsContext*&, unsigned short resourceMode, const Path*, const RenderSVGShape*) OVERRIDE;
73
74    FloatRect resourceBoundingBox(const RenderObject*);
75
76    PassRefPtr<SVGFilterBuilder> buildPrimitives(SVGFilter*);
77
78    SVGUnitTypes::SVGUnitType filterUnits() const { return toSVGFilterElement(element())->filterUnits()->currentValue()->enumValue(); }
79    SVGUnitTypes::SVGUnitType primitiveUnits() const { return toSVGFilterElement(element())->primitiveUnits()->currentValue()->enumValue(); }
80
81    void primitiveAttributeChanged(RenderObject*, const QualifiedName&);
82
83    virtual RenderSVGResourceType resourceType() const OVERRIDE { return s_resourceType; }
84    static const RenderSVGResourceType s_resourceType;
85
86    FloatRect drawingRegion(RenderObject*) const;
87private:
88    void adjustScaleForMaximumImageSize(const FloatSize&, FloatSize&);
89
90    typedef HashMap<RenderObject*, OwnPtr<FilterData> > FilterMap;
91    FilterMap m_filter;
92};
93
94DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderSVGResourceFilter, isSVGResourceFilter());
95
96}
97
98#endif
99