tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / filters / FELighting.h
1 /*
2  * Copyright (C) 2010 University of Szeged
3  * Copyright (C) 2010 Zoltan Herczeg
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
25  */
26
27 #ifndef FELighting_h
28 #define FELighting_h
29
30 #if ENABLE(FILTERS)
31 #include "Color.h"
32 #include "Filter.h"
33 #include "FilterEffect.h"
34 #include "LightSource.h"
35 #include "PointLightSource.h"
36 #include "SpotLightSource.h"
37 #include <wtf/ByteArray.h>
38 #include <wtf/Platform.h>
39
40 // Common base class for FEDiffuseLighting and FESpecularLighting
41
42 namespace WebCore {
43
44 struct FELightingPaintingDataForNeon;
45
46 class FELighting : public FilterEffect {
47 public:
48     virtual void platformApplySoftware();
49
50     virtual void determineAbsolutePaintRect() { setAbsolutePaintRect(enclosingIntRect(maxEffectRect())); }
51
52 protected:
53 #if ENABLE(PARALLEL_JOBS)
54     static const int s_minimalRectDimension = 100 * 100; // Empirical data limit for parallel jobs
55 #endif
56
57     enum LightingType {
58         DiffuseLighting,
59         SpecularLighting
60     };
61
62     struct LightingData {
63         // This structure contains only read-only (SMP safe) data
64         ByteArray* pixels;
65         float surfaceScale;
66         int widthMultipliedByPixelSize;
67         int widthDecreasedByOne;
68         int heightDecreasedByOne;
69
70         inline void topLeft(int offset, IntPoint& normalVector);
71         inline void topRow(int offset, IntPoint& normalVector);
72         inline void topRight(int offset, IntPoint& normalVector);
73         inline void leftColumn(int offset, IntPoint& normalVector);
74         inline void interior(int offset, IntPoint& normalVector);
75         inline void rightColumn(int offset, IntPoint& normalVector);
76         inline void bottomLeft(int offset, IntPoint& normalVector);
77         inline void bottomRow(int offset, IntPoint& normalVector);
78         inline void bottomRight(int offset, IntPoint& normalVector);
79     };
80
81 #if ENABLE(PARALLEL_JOBS)
82     template<typename Type>
83     friend class ParallelJobs;
84
85     struct PlatformApplyGenericParameters {
86         FELighting* filter;
87         LightingData data;
88         LightSource::PaintingData paintingData;
89         int yStart;
90         int yEnd;
91     };
92
93     static void platformApplyGenericWorker(PlatformApplyGenericParameters*);
94     static void platformApplyNeonWorker(FELightingPaintingDataForNeon*);
95 #endif
96
97     FELighting(Filter*, LightingType, const Color&, float, float, float, float, float, float, PassRefPtr<LightSource>);
98
99     bool drawLighting(ByteArray*, int, int);
100     inline void inlineSetPixel(int offset, LightingData&, LightSource::PaintingData&,
101                                int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector);
102
103     // Not worth to inline every occurence of setPixel.
104     void setPixel(int offset, LightingData&, LightSource::PaintingData&,
105                   int lightX, int lightY, float factorX, float factorY, IntPoint& normalVector);
106
107     inline void platformApply(LightingData&, LightSource::PaintingData&);
108
109     inline void platformApplyGenericPaint(LightingData&, LightSource::PaintingData&, int startX, int startY);
110     inline void platformApplyGeneric(LightingData&, LightSource::PaintingData&);
111
112     static int getPowerCoefficients(float exponent);
113     inline void platformApplyNeon(LightingData&, LightSource::PaintingData&);
114
115     LightingType m_lightingType;
116     RefPtr<LightSource> m_lightSource;
117
118     Color m_lightingColor;
119     float m_surfaceScale;
120     float m_diffuseConstant;
121     float m_specularConstant;
122     float m_specularExponent;
123     float m_kernelUnitLengthX;
124     float m_kernelUnitLengthY;
125 };
126
127 } // namespace WebCore
128
129 #endif // ENABLE(FILTERS)
130
131 #endif // FELighting_h