1 /* 2 Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com> 3 2009 Dirk Schulze <krit@webkit.org> 4 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. 9 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. 14 15 You should have received a copy of the GNU Library General Public License 16 aint 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. 19 */ 20 21 #ifndef FilterEffect_h 22 #define FilterEffect_h 23 24 #if ENABLE(FILTERS) 25 #include "Filter.h" 26 #include "FloatRect.h" 27 #include "GraphicsContext.h" 28 #include "ImageBuffer.h" 29 #include "TextStream.h" 30 31 #include <wtf/PassOwnPtr.h> 32 #include <wtf/RefCounted.h> 33 #include <wtf/RefPtr.h> 34 35 namespace WebCore { 36 37 class FilterEffect : public RefCounted<FilterEffect> { 38 public: 39 virtual ~FilterEffect(); 40 setUnionOfChildEffectSubregions(const FloatRect & uniteRect)41 void setUnionOfChildEffectSubregions(const FloatRect& uniteRect) { m_unionOfChildEffectSubregions = uniteRect; } unionOfChildEffectSubregions()42 FloatRect unionOfChildEffectSubregions() const { return m_unionOfChildEffectSubregions; } 43 subRegion()44 FloatRect subRegion() const { return m_subRegion; } setSubRegion(const FloatRect & subRegion)45 void setSubRegion(const FloatRect& subRegion) { m_subRegion = subRegion; } 46 scaledSubRegion()47 FloatRect scaledSubRegion() const { return m_scaledSubRegion; } setScaledSubRegion(const FloatRect & scaledSubRegion)48 void setScaledSubRegion(const FloatRect& scaledSubRegion) { m_scaledSubRegion = scaledSubRegion; } 49 effectBoundaries()50 FloatRect effectBoundaries() const { return m_effectBoundaries; } setEffectBoundaries(const FloatRect & effectBoundaries)51 void setEffectBoundaries(const FloatRect& effectBoundaries) { m_effectBoundaries = effectBoundaries; } 52 hasX()53 bool hasX() { return m_hasX; } setHasX(bool value)54 void setHasX(bool value) { m_hasX = value; } 55 hasY()56 bool hasY() { return m_hasY; } setHasY(bool value)57 void setHasY(bool value) { m_hasY = value; } 58 hasWidth()59 bool hasWidth() { return m_hasWidth; } setHasWidth(bool value)60 void setHasWidth(bool value) { m_hasWidth = value; } 61 hasHeight()62 bool hasHeight() { return m_hasHeight; } setHasHeight(bool value)63 void setHasHeight(bool value) { m_hasHeight = value; } 64 65 // The result is bounded by the size of the filter primitive to save resources resultImage()66 ImageBuffer* resultImage() { return m_effectBuffer.get(); } setEffectBuffer(PassOwnPtr<ImageBuffer> effectBuffer)67 void setEffectBuffer(PassOwnPtr<ImageBuffer> effectBuffer) { m_effectBuffer = effectBuffer; } 68 69 FloatRect calculateUnionOfChildEffectSubregions(Filter*, FilterEffect*, FilterEffect*); 70 FloatRect calculateUnionOfChildEffectSubregions(Filter*, FilterEffect*); 71 72 GraphicsContext* getEffectContext(); 73 FloatRect calculateDrawingRect(const FloatRect&); 74 IntRect calculateDrawingIntRect(const FloatRect&); 75 76 // black image with different alpha values isAlphaImage()77 bool isAlphaImage() { return m_alphaImage; } setIsAlphaImage(bool alphaImage)78 void setIsAlphaImage(bool alphaImage) { m_alphaImage = alphaImage; } 79 uniteChildEffectSubregions(Filter * filter)80 virtual FloatRect uniteChildEffectSubregions(Filter* filter) { return filter->filterRegion(); } 81 virtual FloatRect calculateEffectRect(Filter*); 82 virtual void apply(Filter*) = 0; 83 virtual void dump() = 0; 84 isSourceInput()85 virtual bool isSourceInput() { return false; } 86 87 virtual TextStream& externalRepresentation(TextStream&) const; 88 protected: 89 FilterEffect(); 90 91 private: 92 93 bool m_xBBoxMode : 1; 94 bool m_yBBoxMode : 1; 95 bool m_widthBBoxMode : 1; 96 bool m_heightBBoxMode : 1; 97 98 bool m_hasX : 1; 99 bool m_hasY : 1; 100 bool m_hasWidth : 1; 101 bool m_hasHeight : 1; 102 103 bool m_alphaImage; 104 105 FloatRect m_effectBoundaries; 106 FloatRect m_subRegion; 107 FloatRect m_scaledSubRegion; 108 FloatRect m_unionOfChildEffectSubregions; 109 110 mutable OwnPtr<ImageBuffer> m_effectBuffer; 111 }; 112 113 } // namespace WebCore 114 115 #endif // ENABLE(FILTERS) 116 117 #endif // FilterEffect_h 118