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