tizen beta release
[framework/web/webkit-efl.git] / Source / WebCore / platform / graphics / filters / FilterEffect.h
1 /*
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.
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #ifndef FilterEffect_h
23 #define FilterEffect_h
24
25 #if ENABLE(FILTERS)
26 #include "FloatRect.h"
27 #include "IntRect.h"
28
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>
34
35 static const float kMaxFilterSize = 5000.0f;
36
37 namespace WebCore {
38
39 class Filter;
40 class FilterEffect;
41 class ImageBuffer;
42 class TextStream;
43
44 typedef Vector<RefPtr<FilterEffect> > FilterEffectVector;
45
46 enum FilterEffectType {
47     FilterEffectTypeUnknown,
48     FilterEffectTypeImage,
49     FilterEffectTypeTile,
50     FilterEffectTypeSourceInput
51 };
52
53 class FilterEffect : public RefCounted<FilterEffect> {
54 public:
55     virtual ~FilterEffect();
56
57     void clearResult();
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&);
63
64     FilterEffectVector& inputEffects() { return m_inputEffects; }
65     FilterEffect* inputEffect(unsigned) const;
66     unsigned numberOfEffectInputs() const { return m_inputEffects.size(); }
67     
68     inline bool hasResult() const
69     {
70         // This function needs platform specific checks, if the memory managment is not done by FilterEffect.
71         return m_imageBufferResult || m_unmultipliedImageResult || m_premultipliedImageResult;
72     }
73
74     IntRect drawingRegionOfInputImage(const IntRect&) const;
75     IntRect requestedRegionOfInputImageData(const IntRect&) const;
76
77     // Solid black image with different alpha values.
78     bool isAlphaImage() const { return m_alphaImage; }
79     void setIsAlphaImage(bool alphaImage) { m_alphaImage = alphaImage; }
80
81     IntRect absolutePaintRect() const { return m_absolutePaintRect; }
82     void setAbsolutePaintRect(const IntRect& absolutePaintRect) { m_absolutePaintRect = absolutePaintRect; }
83
84     FloatRect maxEffectRect() const { return m_maxEffectRect; }
85     void setMaxEffectRect(const FloatRect& maxEffectRect) { m_maxEffectRect = maxEffectRect; } 
86
87     void apply();
88     
89     virtual void platformApplySoftware() = 0;
90     virtual void dump() = 0;
91
92     virtual void determineAbsolutePaintRect();
93
94     virtual FilterEffectType filterEffectType() const { return FilterEffectTypeUnknown; }
95
96     virtual TextStream& externalRepresentation(TextStream&, int indention = 0) const;
97
98 public:
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; }
103
104     bool hasY() const { return m_hasY; }
105     void setHasY(bool value) { m_hasY = value; }
106
107     bool hasWidth() const { return m_hasWidth; }
108     void setHasWidth(bool value) { m_hasWidth = value; }
109
110     bool hasHeight() const { return m_hasHeight; }
111     void setHasHeight(bool value) { m_hasHeight = value; }
112
113     FloatRect filterPrimitiveSubregion() const { return m_filterPrimitiveSubregion; }
114     void setFilterPrimitiveSubregion(const FloatRect& filterPrimitiveSubregion) { m_filterPrimitiveSubregion = filterPrimitiveSubregion; }
115
116     FloatRect effectBoundaries() const { return m_effectBoundaries; }
117     void setEffectBoundaries(const FloatRect& effectBoundaries) { m_effectBoundaries = effectBoundaries; }
118
119     Filter* filter() { return m_filter; }
120
121 protected:
122     FilterEffect(Filter*);
123
124     ImageBuffer* createImageBufferResult();
125     ByteArray* createUnmultipliedImageResult();
126     ByteArray* createPremultipliedImageResult();
127
128 private:
129     OwnPtr<ImageBuffer> m_imageBufferResult;
130     RefPtr<ByteArray> m_unmultipliedImageResult;
131     RefPtr<ByteArray> m_premultipliedImageResult;
132     FilterEffectVector m_inputEffects;
133
134     bool m_alphaImage;
135
136     IntRect m_absolutePaintRect;
137     
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;
141     Filter* m_filter;
142
143 private:
144     inline void copyImageBytes(ByteArray* source, ByteArray* destination, const IntRect&);
145
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.
148
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;
152
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;
156     bool m_hasX;
157     bool m_hasY;
158     bool m_hasWidth;
159     bool m_hasHeight;
160 };
161
162 } // namespace WebCore
163
164 #endif // ENABLE(FILTERS)
165
166 #endif // FilterEffect_h