2 * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com>
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef FilterEffect_h
23 #define FilterEffect_h
26 #include "FloatRect.h"
29 #include <wtf/ByteArray.h>
30 #include <wtf/PassOwnPtr.h>
31 #include <wtf/RefCounted.h>
32 #include <wtf/RefPtr.h>
33 #include <wtf/Vector.h>
35 static const float kMaxFilterSize = 5000.0f;
44 typedef Vector<RefPtr<FilterEffect> > FilterEffectVector;
46 enum FilterEffectType {
47 FilterEffectTypeUnknown,
48 FilterEffectTypeImage,
50 FilterEffectTypeSourceInput
53 class FilterEffect : public RefCounted<FilterEffect> {
55 virtual ~FilterEffect();
57 bool hasResult() const { return m_imageBufferResult || m_unmultipliedImageResult || m_premultipliedImageResult; }
59 ImageBuffer* asImageBuffer();
60 PassRefPtr<ByteArray> asUnmultipliedImage(const IntRect&);
61 PassRefPtr<ByteArray> asPremultipliedImage(const IntRect&);
62 void copyUnmultipliedImage(ByteArray* destination, const IntRect&);
63 void copyPremultipliedImage(ByteArray* destination, const IntRect&);
65 FilterEffectVector& inputEffects() { return m_inputEffects; }
66 FilterEffect* inputEffect(unsigned) const;
67 unsigned numberOfEffectInputs() const { return m_inputEffects.size(); }
69 IntRect drawingRegionOfInputImage(const IntRect&) const;
70 IntRect requestedRegionOfInputImageData(const IntRect&) const;
72 // Solid black image with different alpha values.
73 bool isAlphaImage() const { return m_alphaImage; }
74 void setIsAlphaImage(bool alphaImage) { m_alphaImage = alphaImage; }
76 IntRect absolutePaintRect() const { return m_absolutePaintRect; }
77 void setAbsolutePaintRect(const IntRect& absolutePaintRect) { m_absolutePaintRect = absolutePaintRect; }
79 FloatRect maxEffectRect() const { return m_maxEffectRect; }
80 void setMaxEffectRect(const FloatRect& maxEffectRect) { m_maxEffectRect = maxEffectRect; }
82 virtual void apply() = 0;
83 virtual void dump() = 0;
85 virtual void determineAbsolutePaintRect();
87 virtual FilterEffectType filterEffectType() const { return FilterEffectTypeUnknown; }
89 virtual TextStream& externalRepresentation(TextStream&, int indention = 0) const;
92 // The following functions are SVG specific and will move to RenderSVGResourceFilterPrimitive.
93 // See bug https://bugs.webkit.org/show_bug.cgi?id=45614.
94 bool hasX() const { return m_hasX; }
95 void setHasX(bool value) { m_hasX = value; }
97 bool hasY() const { return m_hasY; }
98 void setHasY(bool value) { m_hasY = value; }
100 bool hasWidth() const { return m_hasWidth; }
101 void setHasWidth(bool value) { m_hasWidth = value; }
103 bool hasHeight() const { return m_hasHeight; }
104 void setHasHeight(bool value) { m_hasHeight = value; }
106 FloatRect filterPrimitiveSubregion() const { return m_filterPrimitiveSubregion; }
107 void setFilterPrimitiveSubregion(const FloatRect& filterPrimitiveSubregion) { m_filterPrimitiveSubregion = filterPrimitiveSubregion; }
109 FloatRect effectBoundaries() const { return m_effectBoundaries; }
110 void setEffectBoundaries(const FloatRect& effectBoundaries) { m_effectBoundaries = effectBoundaries; }
112 Filter* filter() { return m_filter; }
115 FilterEffect(Filter*);
117 ImageBuffer* createImageBufferResult();
118 ByteArray* createUnmultipliedImageResult();
119 ByteArray* createPremultipliedImageResult();
122 OwnPtr<ImageBuffer> m_imageBufferResult;
123 RefPtr<ByteArray> m_unmultipliedImageResult;
124 RefPtr<ByteArray> m_premultipliedImageResult;
125 FilterEffectVector m_inputEffects;
129 IntRect m_absolutePaintRect;
131 // The maximum size of a filter primitive. In SVG this is the primitive subregion in absolute coordinate space.
132 // The absolute paint rect should never be bigger than m_maxEffectRect.
133 FloatRect m_maxEffectRect;
137 inline void copyImageBytes(ByteArray* source, ByteArray* destination, const IntRect&);
139 // The following member variables are SVG specific and will move to RenderSVGResourceFilterPrimitive.
140 // See bug https://bugs.webkit.org/show_bug.cgi?id=45614.
142 // The subregion of a filter primitive according to the SVG Filter specification in local coordinates.
143 // This is SVG specific and needs to move to RenderSVGResourceFilterPrimitive.
144 FloatRect m_filterPrimitiveSubregion;
146 // x, y, width and height of the actual SVGFE*Element. Is needed to determine the subregion of the
147 // filter primitive on a later step.
148 FloatRect m_effectBoundaries;
155 } // namespace WebCore
157 #endif // ENABLE(FILTERS)
159 #endif // FilterEffect_h