tizen beta release
[framework/web/webkit-efl.git] / Source / WebCore / platform / graphics / filters / FETurbulence.h
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4  * Copyright (C) 2005 Eric Seidel <eric@webkit.org>
5  * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
6  * Copyright (C) 2010 Renata Hodovan <reni@inf.u-szeged.hu>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #ifndef FETurbulence_h
25 #define FETurbulence_h
26
27 #if ENABLE(FILTERS)
28 #include "FilterEffect.h"
29 #include "Filter.h"
30
31 namespace WebCore {
32
33 enum TurbulenceType {
34     FETURBULENCE_TYPE_UNKNOWN = 0,
35     FETURBULENCE_TYPE_FRACTALNOISE = 1,
36     FETURBULENCE_TYPE_TURBULENCE = 2
37 };
38
39 class FETurbulence : public FilterEffect {
40 public:
41     static PassRefPtr<FETurbulence> create(Filter*, TurbulenceType, float, float, int, float, bool);
42
43     TurbulenceType type() const;
44     bool setType(TurbulenceType);
45
46     float baseFrequencyY() const;
47     bool setBaseFrequencyY(float);
48
49     float baseFrequencyX() const;
50     bool setBaseFrequencyX(float);
51
52     float seed() const;
53     bool setSeed(float);
54
55     int numOctaves() const;
56     bool setNumOctaves(int);
57
58     bool stitchTiles() const;
59     bool setStitchTiles(bool);
60
61 #if ENABLE(PARALLEL_JOBS)
62     static void fillRegionWorker(void*);
63 #endif
64
65     virtual void platformApplySoftware();
66     virtual void dump();
67     
68     virtual void determineAbsolutePaintRect() { setAbsolutePaintRect(enclosingIntRect(maxEffectRect())); }
69
70     virtual TextStream& externalRepresentation(TextStream&, int indention) const;
71
72 private:
73     static const int s_blockSize = 256;
74     static const int s_blockMask = s_blockSize - 1;
75 #if ENABLE(PARALLEL_JOBS)
76     static const int s_minimalRectDimension = (100 * 100); // Empirical data limit for parallel jobs
77 #endif
78
79     struct PaintingData {
80         long seed;
81         int latticeSelector[2 * s_blockSize + 2];
82         float gradient[4][2 * s_blockSize + 2][2];
83         int width; // How much to subtract to wrap for stitching.
84         int height;
85         int wrapX; // Minimum value to wrap.
86         int wrapY;
87         IntSize filterSize;
88
89         PaintingData(long paintingSeed, const IntSize& paintingSize);
90         inline long random();
91     };
92
93 #if ENABLE(PARALLEL_JOBS)
94     template<typename Type>
95     friend class ParallelJobs;
96
97     struct FillRegionParameters {
98         FETurbulence* filter;
99         ByteArray* pixelArray;
100         PaintingData* paintingData;
101         int startY;
102         int endY;
103     };
104
105     static void fillRegionWorker(FillRegionParameters*);
106 #endif
107
108     FETurbulence(Filter*, TurbulenceType, float, float, int, float, bool);
109
110     inline void initPaint(PaintingData&);
111     float noise2D(int channel, PaintingData&, const FloatPoint&);
112     unsigned char calculateTurbulenceValueForPoint(int channel, PaintingData&, const FloatPoint&);
113     inline void fillRegion(ByteArray*, PaintingData&, int, int);
114
115     TurbulenceType m_type;
116     float m_baseFrequencyX;
117     float m_baseFrequencyY;
118     int m_numOctaves;
119     float m_seed;
120     bool m_stitchTiles;
121 };
122
123 } // namespace WebCore
124
125 #endif // ENABLE(FILTERS)
126
127 #endif // FETurbulence_h