1 /* 2 Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 2004, 2005 Rob Buis <buis@kde.org> 4 2005 Eric Seidel <eric@webkit.org> 5 2009 Dirk Schulze <krit@webkit.org> 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Library General Public 9 License as published by the Free Software Foundation; either 10 version 2 of the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Library General Public License for more details. 16 17 You should have received a copy of the GNU Library General Public License 18 aint with this library; see the file COPYING.LIB. If not, write to 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 Boston, MA 02110-1301, USA. 21 */ 22 23 #ifndef SVGResourceFilter_h 24 #define SVGResourceFilter_h 25 26 #if ENABLE(SVG) && ENABLE(FILTERS) 27 #include "SVGResource.h" 28 29 #include "Image.h" 30 #include "ImageBuffer.h" 31 #include "FloatRect.h" 32 #include "RenderObject.h" 33 #include "SVGFilterPrimitiveStandardAttributes.h" 34 35 #include <wtf/OwnPtr.h> 36 #include <wtf/PassOwnPtr.h> 37 #include <wtf/PassRefPtr.h> 38 #include <wtf/RefPtr.h> 39 40 namespace WebCore { 41 42 class Filter; 43 class FilterEffect; 44 class GraphicsContext; 45 class SVGFilterBuilder; 46 class SVGFilterElement; 47 class SVGFilterPrimitiveStandardAttributes; 48 49 class SVGResourceFilter : public SVGResource { 50 public: create(const SVGFilterElement * ownerElement)51 static PassRefPtr<SVGResourceFilter> create(const SVGFilterElement* ownerElement) { return adoptRef(new SVGResourceFilter(ownerElement)); } 52 virtual ~SVGResourceFilter(); 53 resourceType()54 virtual SVGResourceType resourceType() const { return FilterResourceType; } 55 setFilterResolution(const FloatSize & filterResSize)56 void setFilterResolution(const FloatSize& filterResSize) { m_filterResSize = filterResSize; } setHasFilterResolution(bool filterRes)57 void setHasFilterResolution(bool filterRes) { m_filterRes = filterRes; } 58 filterBoundingBoxMode()59 bool filterBoundingBoxMode() const { return m_filterBBoxMode; } setFilterBoundingBoxMode(bool bboxMode)60 void setFilterBoundingBoxMode(bool bboxMode) { m_filterBBoxMode = bboxMode; } 61 effectBoundingBoxMode()62 bool effectBoundingBoxMode() const { return m_effectBBoxMode; } setEffectBoundingBoxMode(bool bboxMode)63 void setEffectBoundingBoxMode(bool bboxMode) { m_effectBBoxMode = bboxMode; } 64 filterRect()65 FloatRect filterRect() const { return m_filterRect; } setFilterRect(const FloatRect & rect)66 void setFilterRect(const FloatRect& rect) { m_filterRect = rect; } 67 scaleX()68 float scaleX() const { return m_scaleX; } scaleY()69 float scaleY() const { return m_scaleY; } 70 71 FloatRect filterBoundingBox(const FloatRect& obb) const; setFilterBoundingBox(const FloatRect & rect)72 void setFilterBoundingBox(const FloatRect& rect) { m_filterBBox = rect; } 73 74 bool prepareFilter(GraphicsContext*&, const RenderObject*); 75 void applyFilter(GraphicsContext*&, const RenderObject*); 76 77 bool fitsInMaximumImageSize(const FloatSize&); 78 79 void addFilterEffect(SVGFilterPrimitiveStandardAttributes*, PassRefPtr<FilterEffect>); 80 builder()81 SVGFilterBuilder* builder() { return m_filterBuilder.get(); } 82 83 virtual TextStream& externalRepresentation(TextStream&) const; 84 85 private: 86 SVGResourceFilter(const SVGFilterElement*); 87 88 const SVGFilterElement* m_ownerElement; 89 90 bool m_filterBBoxMode : 1; 91 bool m_effectBBoxMode : 1; 92 bool m_filterRes : 1; 93 float m_scaleX; 94 float m_scaleY; 95 96 FloatRect m_filterRect; 97 FloatRect m_filterBBox; 98 FloatSize m_filterResSize; 99 100 OwnPtr<SVGFilterBuilder> m_filterBuilder; 101 GraphicsContext* m_savedContext; 102 OwnPtr<ImageBuffer> m_sourceGraphicBuffer; 103 RefPtr<Filter> m_filter; 104 }; 105 106 SVGResourceFilter* getFilterById(Document*, const AtomicString&, const RenderObject*); 107 108 } // namespace WebCore 109 110 #endif // ENABLE(SVG) 111 112 #endif // SVGResourceFilter_h 113