initial import
[vuplus_webkit] / Source / WebCore / platform / graphics / chromium / ShaderChromium.h
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
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 APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef ShaderChromium_h
27 #define ShaderChromium_h
28
29 #if USE(ACCELERATED_COMPOSITING)
30
31 #include "PlatformString.h"
32
33 #if USE(SKIA)
34 #include "SkColorPriv.h"
35 #endif
36
37 namespace WebCore {
38
39 class GraphicsContext3D;
40
41 class VertexShaderPosTex {
42 public:
43     VertexShaderPosTex();
44
45     void init(GraphicsContext3D*, unsigned program);
46     String getShaderString() const;
47
48     int matrixLocation() const { return m_matrixLocation; }
49
50 private:
51     int m_matrixLocation;
52 };
53
54 class VertexShaderPosTexYUVStretch {
55 public:
56     VertexShaderPosTexYUVStretch();
57
58     void init(GraphicsContext3D*, unsigned program);
59     String getShaderString() const;
60
61     int matrixLocation() const { return m_matrixLocation; }
62     int yWidthScaleFactorLocation() const { return m_yWidthScaleFactorLocation; }
63     int uvWidthScaleFactorLocation() const { return m_uvWidthScaleFactorLocation; }
64
65 private:
66     int m_matrixLocation;
67     int m_yWidthScaleFactorLocation;
68     int m_uvWidthScaleFactorLocation;
69 };
70
71 class VertexShaderPos {
72 public:
73     VertexShaderPos();
74
75     void init(GraphicsContext3D*, unsigned program);
76     String getShaderString() const;
77
78     int matrixLocation() const { return m_matrixLocation; }
79
80 private:
81     int m_matrixLocation;
82 };
83
84 class VertexShaderPosTexTransform {
85 public:
86     VertexShaderPosTexTransform();
87
88     void init(GraphicsContext3D*, unsigned program);
89     String getShaderString() const;
90
91     int matrixLocation() const { return m_matrixLocation; }
92     int texTransformLocation() const { return m_texTransformLocation; }
93
94 private:
95     int m_matrixLocation;
96     int m_texTransformLocation;
97 };
98
99 class VertexShaderQuad {
100 public:
101     VertexShaderQuad();
102
103     void init(GraphicsContext3D*, unsigned program);
104     String getShaderString() const;
105
106     int matrixLocation() const { return m_matrixLocation; }
107     int pointLocation() const { return m_pointLocation; }
108
109 private:
110     int m_matrixLocation;
111     int m_pointLocation;
112 };
113
114 class VertexShaderTile {
115 public:
116     VertexShaderTile();
117
118     void init(GraphicsContext3D*, unsigned program);
119     String getShaderString() const;
120
121     int matrixLocation() const { return m_matrixLocation; }
122     int pointLocation() const { return m_pointLocation; }
123     int vertexTexTransformLocation() const { return m_vertexTexTransformLocation; }
124
125 private:
126     int m_matrixLocation;
127     int m_pointLocation;
128     int m_vertexTexTransformLocation;
129 };
130
131 class FragmentTexAlphaBinding {
132 public:
133     FragmentTexAlphaBinding();
134
135     void init(GraphicsContext3D*, unsigned program);
136     int alphaLocation() const { return m_alphaLocation; }
137     int samplerLocation() const { return m_samplerLocation; }
138
139 private:
140     int m_samplerLocation;
141     int m_alphaLocation;
142 };
143
144 class FragmentShaderRGBATexFlipAlpha : public FragmentTexAlphaBinding {
145 public:
146     String getShaderString() const;
147 };
148
149 class FragmentShaderRGBATexAlpha : public FragmentTexAlphaBinding {
150 public:
151     String getShaderString() const;
152 };
153
154 // Swizzles the red and blue component of sampled texel.
155 class FragmentShaderRGBATexSwizzleAlpha : public FragmentTexAlphaBinding {
156 public:
157     String getShaderString() const;
158 };
159
160 class FragmentShaderRGBATexAlphaAA {
161 public:
162     FragmentShaderRGBATexAlphaAA();
163
164     void init(GraphicsContext3D*, unsigned program);
165     String getShaderString() const;
166
167     int alphaLocation() const { return m_alphaLocation; }
168     int samplerLocation() const { return m_samplerLocation; }
169     int edgeLocation() const { return m_edgeLocation; }
170
171 private:
172     int m_samplerLocation;
173     int m_alphaLocation;
174     int m_edgeLocation;
175 };
176
177 class FragmentTexClampAlphaAABinding {
178 public:
179     FragmentTexClampAlphaAABinding();
180
181     void init(GraphicsContext3D*, unsigned program);
182     int alphaLocation() const { return m_alphaLocation; }
183     int samplerLocation() const { return m_samplerLocation; }
184     int fragmentTexTransformLocation() const { return m_fragmentTexTransformLocation; }
185     int edgeLocation() const { return m_edgeLocation; }
186
187 private:
188     int m_samplerLocation;
189     int m_alphaLocation;
190     int m_fragmentTexTransformLocation;
191     int m_edgeLocation;
192 };
193
194 class FragmentShaderRGBATexClampAlphaAA : public FragmentTexClampAlphaAABinding {
195 public:
196     String getShaderString() const;
197 };
198
199 // Swizzles the red and blue component of sampled texel.
200 class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentTexClampAlphaAABinding {
201 public:
202     String getShaderString() const;
203 };
204
205 class FragmentShaderRGBATexAlphaMask {
206 public:
207     FragmentShaderRGBATexAlphaMask();
208     String getShaderString() const;
209
210     void init(GraphicsContext3D*, unsigned program);
211     int alphaLocation() const { return m_alphaLocation; }
212     int samplerLocation() const { return m_samplerLocation; }
213     int maskSamplerLocation() const { return m_maskSamplerLocation; }
214
215 private:
216     int m_samplerLocation;
217     int m_maskSamplerLocation;
218     int m_alphaLocation;
219 };
220
221 class FragmentShaderRGBATexAlphaMaskAA {
222 public:
223     FragmentShaderRGBATexAlphaMaskAA();
224     String getShaderString() const;
225
226     void init(GraphicsContext3D*, unsigned program);
227     int alphaLocation() const { return m_alphaLocation; }
228     int samplerLocation() const { return m_samplerLocation; }
229     int maskSamplerLocation() const { return m_maskSamplerLocation; }
230     int edgeLocation() const { return m_edgeLocation; }
231
232 private:
233     int m_samplerLocation;
234     int m_maskSamplerLocation;
235     int m_alphaLocation;
236     int m_edgeLocation;
237 };
238
239 class FragmentShaderYUVVideo {
240 public:
241     FragmentShaderYUVVideo();
242     String getShaderString() const;
243
244     void init(GraphicsContext3D*, unsigned program);
245
246     int yTextureLocation() const { return m_yTextureLocation; }
247     int uTextureLocation() const { return m_uTextureLocation; }
248     int vTextureLocation() const { return m_vTextureLocation; }
249     int alphaLocation() const { return m_alphaLocation; }
250     int ccMatrixLocation() const { return m_ccMatrixLocation; }
251     int yuvAdjLocation() const { return m_yuvAdjLocation; }
252
253 private:
254     int m_yTextureLocation;
255     int m_uTextureLocation;
256     int m_vTextureLocation;
257     int m_alphaLocation;
258     int m_ccMatrixLocation;
259     int m_yuvAdjLocation;
260 };
261
262 class FragmentShaderColor {
263 public:
264     FragmentShaderColor();
265     String getShaderString() const;
266
267     void init(GraphicsContext3D*, unsigned program);
268     int colorLocation() const { return m_colorLocation; }
269
270 private:
271     int m_colorLocation;
272 };
273
274 } // namespace WebCore
275
276 #endif // USE(ACCELERATED_COMPOSITING)
277
278 #endif