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();
58 ImageBuffer* asImageBuffer();
59 PassRefPtr<ByteArray> asUnmultipliedImage(const IntRect&);
60 PassRefPtr<ByteArray> asPremultipliedImage(const IntRect&);
61 void copyUnmultipliedImage(ByteArray* destination, const IntRect&);
62 void copyPremultipliedImage(ByteArray* destination, const IntRect&);
64 FilterEffectVector& inputEffects() { return m_inputEffects; }
65 FilterEffect* inputEffect(unsigned) const;
66 unsigned numberOfEffectInputs() const { return m_inputEffects.size(); }
68 inline bool hasResult() const
70 // This function needs platform specific checks, if the memory managment is not done by FilterEffect.
71 return m_imageBufferResult || m_unmultipliedImageResult || m_premultipliedImageResult;
74 IntRect drawingRegionOfInputImage(const IntRect&) const;
75 IntRect requestedRegionOfInputImageData(const IntRect&) const;
77 // Solid black image with different alpha values.
78 bool isAlphaImage() const { return m_alphaImage; }
79 void setIsAlphaImage(bool alphaImage) { m_alphaImage = alphaImage; }
81 IntRect absolutePaintRect() const { return m_absolutePaintRect; }
82 void setAbsolutePaintRect(const IntRect& absolutePaintRect) { m_absolutePaintRect = absolutePaintRect; }
84 FloatRect maxEffectRect() const { return m_maxEffectRect; }
85 void setMaxEffectRect(const FloatRect& maxEffectRect) { m_maxEffectRect = maxEffectRect; }
89 virtual void platformApplySoftware() = 0;
90 virtual void dump() = 0;
92 virtual void determineAbsolutePaintRect();
94 virtual FilterEffectType filterEffectType() const { return FilterEffectTypeUnknown; }
96 virtual TextStream& externalRepresentation(TextStream&, int indention = 0) const;
99 // The following functions are SVG specific and will move to RenderSVGResourceFilterPrimitive.
100 // See bug https://bugs.webkit.org/show_bug.cgi?id=45614.
101 bool hasX() const { return m_hasX; }
102 void setHasX(bool value) { m_hasX = value; }
104 bool hasY() const { return m_hasY; }
105 void setHasY(bool value) { m_hasY = value; }
107 bool hasWidth() const { return m_hasWidth; }
108 void setHasWidth(bool value) { m_hasWidth = value; }
110 bool hasHeight() const { return m_hasHeight; }
111 void setHasHeight(bool value) { m_hasHeight = value; }
113 FloatRect filterPrimitiveSubregion() const { return m_filterPrimitiveSubregion; }
114 void setFilterPrimitiveSubregion(const FloatRect& filterPrimitiveSubregion) { m_filterPrimitiveSubregion = filterPrimitiveSubregion; }
116 FloatRect effectBoundaries() const { return m_effectBoundaries; }
117 void setEffectBoundaries(const FloatRect& effectBoundaries) { m_effectBoundaries = effectBoundaries; }
119 Filter* filter() { return m_filter; }
122 FilterEffect(Filter*);
124 ImageBuffer* createImageBufferResult();
125 ByteArray* createUnmultipliedImageResult();
126 ByteArray* createPremultipliedImageResult();
129 OwnPtr<ImageBuffer> m_imageBufferResult;
130 RefPtr<ByteArray> m_unmultipliedImageResult;
131 RefPtr<ByteArray> m_premultipliedImageResult;
132 FilterEffectVector m_inputEffects;
136 IntRect m_absolutePaintRect;
138 // The maximum size of a filter primitive. In SVG this is the primitive subregion in absolute coordinate space.
139 // The absolute paint rect should never be bigger than m_maxEffectRect.
140 FloatRect m_maxEffectRect;
144 inline void copyImageBytes(ByteArray* source, ByteArray* destination, const IntRect&);
146 // The following member variables are SVG specific and will move to RenderSVGResourceFilterPrimitive.
147 // See bug https://bugs.webkit.org/show_bug.cgi?id=45614.
149 // The subregion of a filter primitive according to the SVG Filter specification in local coordinates.
150 // This is SVG specific and needs to move to RenderSVGResourceFilterPrimitive.
151 FloatRect m_filterPrimitiveSubregion;
153 // x, y, width and height of the actual SVGFE*Element. Is needed to determine the subregion of the
154 // filter primitive on a later step.
155 FloatRect m_effectBoundaries;
162 } // namespace WebCore
164 #endif // ENABLE(FILTERS)
166 #endif // FilterEffect_h