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#if ENABLE(FILTERS) 28#include "ImageBuffer.h" 29#include "RenderSVGResourceContainer.h" 30#include "SVGFilter.h" 31#include "SVGFilterBuilder.h" 32#include "SVGFilterElement.h" 33#include "SVGUnitTypes.h" 34 35#include <wtf/RefPtr.h> 36 37namespace WebCore { 38 39struct FilterData { 40 WTF_MAKE_FAST_ALLOCATED; 41 WTF_MAKE_NONCOPYABLE(FilterData); 42public: 43 enum FilterDataState { PaintingSource, Applying, Built, CycleDetected, MarkedForRemoval }; 44 45 FilterData() 46 : savedContext(0) 47 , state(PaintingSource) 48 { 49 } 50 51 RefPtr<SVGFilter> filter; 52 std::unique_ptr<SVGFilterBuilder> builder; 53 std::unique_ptr<ImageBuffer> sourceGraphicBuffer; 54 GraphicsContext* savedContext; 55 AffineTransform shearFreeAbsoluteTransform; 56 FloatRect boundaries; 57 FloatRect drawingRegion; 58 FloatSize scale; 59 FilterDataState state; 60}; 61 62class GraphicsContext; 63 64class RenderSVGResourceFilter final : public RenderSVGResourceContainer { 65public: 66 RenderSVGResourceFilter(SVGFilterElement&, PassRef<RenderStyle>); 67 virtual ~RenderSVGResourceFilter(); 68 69 SVGFilterElement& filterElement() const { return toSVGFilterElement(RenderSVGResourceContainer::element()); } 70 71 virtual void removeAllClientsFromCache(bool markForInvalidation = true) override; 72 virtual void removeClientFromCache(RenderElement&, bool markForInvalidation = true) override; 73 74 virtual bool applyResource(RenderElement&, const RenderStyle&, GraphicsContext*&, unsigned short resourceMode) override; 75 virtual void postApplyResource(RenderElement&, GraphicsContext*&, unsigned short resourceMode, const Path*, const RenderSVGShape*) override; 76 77 virtual FloatRect resourceBoundingBox(const RenderObject&) override; 78 79 std::unique_ptr<SVGFilterBuilder> buildPrimitives(SVGFilter*) const; 80 81 SVGUnitTypes::SVGUnitType filterUnits() const { return filterElement().filterUnits(); } 82 SVGUnitTypes::SVGUnitType primitiveUnits() const { return filterElement().primitiveUnits(); } 83 84 void primitiveAttributeChanged(RenderObject*, const QualifiedName&); 85 86 virtual RenderSVGResourceType resourceType() const { return s_resourceType; } 87 static RenderSVGResourceType s_resourceType; 88 89 FloatRect drawingRegion(RenderObject*) const; 90private: 91 void element() const = delete; 92 93 virtual const char* renderName() const override { return "RenderSVGResourceFilter"; } 94 virtual bool isSVGResourceFilter() const override { return true; } 95 96 bool fitsInMaximumImageSize(const FloatSize&, FloatSize&); 97 98 HashMap<RenderObject*, std::unique_ptr<FilterData>> m_filter; 99}; 100 101RENDER_OBJECT_TYPE_CASTS(RenderSVGResourceFilter, isSVGResourceFilter()) 102 103} 104 105#endif 106#endif 107