OLD | NEW |
| (Empty) |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 | |
7 #if USE(ACCELERATED_COMPOSITING) | |
8 | |
9 #include "ShaderChromium.h" | |
10 | |
11 #include <public/WebGraphicsContext3D.h> | |
12 #include <wtf/StdLibExtras.h> | |
13 | |
14 #define SHADER0(Src) #Src | |
15 #define SHADER(Src) SHADER0(Src) | |
16 | |
17 using WebKit::WebGraphicsContext3D; | |
18 | |
19 namespace cc { | |
20 | |
21 namespace { | |
22 | |
23 static void getProgramUniformLocations(WebGraphicsContext3D* context, unsigned p
rogram, const char** shaderUniforms, size_t count, size_t maxLocations, int* loc
ations, bool usingBindUniform, int* baseUniformIndex) | |
24 { | |
25 for (size_t uniformIndex = 0; uniformIndex < count; uniformIndex ++) { | |
26 ASSERT(uniformIndex < maxLocations); | |
27 | |
28 if (usingBindUniform) { | |
29 locations[uniformIndex] = (*baseUniformIndex)++; | |
30 context->bindUniformLocationCHROMIUM(program, locations[uniformIndex
], shaderUniforms[uniformIndex]); | |
31 } else | |
32 locations[uniformIndex] = context->getUniformLocation(program, shade
rUniforms[uniformIndex]); | |
33 } | |
34 } | |
35 | |
36 } | |
37 | |
38 VertexShaderPosTex::VertexShaderPosTex() | |
39 : m_matrixLocation(-1) | |
40 { | |
41 } | |
42 | |
43 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b
ool usingBindUniform, int* baseUniformIndex) | |
44 { | |
45 static const char* shaderUniforms[] = { | |
46 "matrix", | |
47 }; | |
48 int locations[1]; | |
49 | |
50 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
51 | |
52 m_matrixLocation = locations[0]; | |
53 ASSERT(m_matrixLocation != -1); | |
54 } | |
55 | |
56 std::string VertexShaderPosTex::getShaderString() const | |
57 { | |
58 return SHADER( | |
59 attribute vec4 a_position; | |
60 attribute vec2 a_texCoord; | |
61 uniform mat4 matrix; | |
62 varying vec2 v_texCoord; | |
63 void main() | |
64 { | |
65 gl_Position = matrix * a_position; | |
66 v_texCoord = a_texCoord; | |
67 } | |
68 ); | |
69 } | |
70 | |
71 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() | |
72 : m_matrixLocation(-1) | |
73 , m_yWidthScaleFactorLocation(-1) | |
74 , m_uvWidthScaleFactorLocation(-1) | |
75 { | |
76 } | |
77 | |
78 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned
program, bool usingBindUniform, int* baseUniformIndex) | |
79 { | |
80 static const char* shaderUniforms[] = { | |
81 "matrix", | |
82 "y_widthScaleFactor", | |
83 "uv_widthScaleFactor", | |
84 }; | |
85 int locations[3]; | |
86 | |
87 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
88 | |
89 m_matrixLocation = locations[0]; | |
90 m_yWidthScaleFactorLocation = locations[1]; | |
91 m_uvWidthScaleFactorLocation = locations[2]; | |
92 ASSERT(m_matrixLocation != -1 && m_yWidthScaleFactorLocation != -1 && m_uvWi
dthScaleFactorLocation != -1); | |
93 } | |
94 | |
95 std::string VertexShaderPosTexYUVStretch::getShaderString() const | |
96 { | |
97 return SHADER( | |
98 precision mediump float; | |
99 attribute vec4 a_position; | |
100 attribute vec2 a_texCoord; | |
101 uniform mat4 matrix; | |
102 varying vec2 y_texCoord; | |
103 varying vec2 uv_texCoord; | |
104 uniform float y_widthScaleFactor; | |
105 uniform float uv_widthScaleFactor; | |
106 void main() | |
107 { | |
108 gl_Position = matrix * a_position; | |
109 y_texCoord = vec2(y_widthScaleFactor * a_texCoord.x, a_texCoord.y); | |
110 uv_texCoord = vec2(uv_widthScaleFactor * a_texCoord.x, a_texCoord.y)
; | |
111 } | |
112 ); | |
113 } | |
114 | |
115 VertexShaderPos::VertexShaderPos() | |
116 : m_matrixLocation(-1) | |
117 { | |
118 } | |
119 | |
120 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool
usingBindUniform, int* baseUniformIndex) | |
121 { | |
122 static const char* shaderUniforms[] = { | |
123 "matrix", | |
124 }; | |
125 int locations[1]; | |
126 | |
127 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
128 | |
129 m_matrixLocation = locations[0]; | |
130 ASSERT(m_matrixLocation != -1); | |
131 } | |
132 | |
133 std::string VertexShaderPos::getShaderString() const | |
134 { | |
135 return SHADER( | |
136 attribute vec4 a_position; | |
137 uniform mat4 matrix; | |
138 void main() | |
139 { | |
140 gl_Position = matrix * a_position; | |
141 } | |
142 ); | |
143 } | |
144 | |
145 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | |
146 : m_matrixLocation(-1) | |
147 , m_texTransformLocation(-1) | |
148 { | |
149 } | |
150 | |
151 void VertexShaderPosTexTransform::init(WebGraphicsContext3D* context, unsigned p
rogram, bool usingBindUniform, int* baseUniformIndex) | |
152 { | |
153 static const char* shaderUniforms[] = { | |
154 "matrix", | |
155 "texTransform", | |
156 }; | |
157 int locations[2]; | |
158 | |
159 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
160 | |
161 m_matrixLocation = locations[0]; | |
162 m_texTransformLocation = locations[1]; | |
163 ASSERT(m_matrixLocation != -1 && m_texTransformLocation != -1); | |
164 } | |
165 | |
166 std::string VertexShaderPosTexTransform::getShaderString() const | |
167 { | |
168 return SHADER( | |
169 attribute vec4 a_position; | |
170 attribute vec2 a_texCoord; | |
171 uniform mat4 matrix; | |
172 uniform vec4 texTransform; | |
173 varying vec2 v_texCoord; | |
174 void main() | |
175 { | |
176 gl_Position = matrix * a_position; | |
177 v_texCoord = a_texCoord * texTransform.zw + texTransform.xy; | |
178 } | |
179 ); | |
180 } | |
181 | |
182 VertexShaderQuad::VertexShaderQuad() | |
183 : m_matrixLocation(-1) | |
184 , m_pointLocation(-1) | |
185 { | |
186 } | |
187 | |
188 std::string VertexShaderPosTexIdentity::getShaderString() const | |
189 { | |
190 return SHADER( | |
191 attribute vec4 a_position; | |
192 varying vec2 v_texCoord; | |
193 void main() | |
194 { | |
195 gl_Position = a_position; | |
196 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | |
197 } | |
198 ); | |
199 } | |
200 | |
201 void VertexShaderQuad::init(WebGraphicsContext3D* context, unsigned program, boo
l usingBindUniform, int* baseUniformIndex) | |
202 { | |
203 static const char* shaderUniforms[] = { | |
204 "matrix", | |
205 "point", | |
206 }; | |
207 int locations[2]; | |
208 | |
209 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
210 | |
211 m_matrixLocation = locations[0]; | |
212 m_pointLocation = locations[1]; | |
213 ASSERT(m_matrixLocation != -1 && m_pointLocation != -1); | |
214 } | |
215 | |
216 std::string VertexShaderQuad::getShaderString() const | |
217 { | |
218 return SHADER( | |
219 attribute vec4 a_position; | |
220 attribute vec2 a_texCoord; | |
221 uniform mat4 matrix; | |
222 uniform vec2 point[4]; | |
223 varying vec2 v_texCoord; | |
224 void main() | |
225 { | |
226 vec2 complement = abs(a_texCoord - 1.0); | |
227 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | |
228 pos.xy += (complement.x * complement.y) * point[0]; | |
229 pos.xy += (a_texCoord.x * complement.y) * point[1]; | |
230 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | |
231 pos.xy += (complement.x * a_texCoord.y) * point[3]; | |
232 gl_Position = matrix * pos; | |
233 v_texCoord = pos.xy + vec2(0.5); | |
234 } | |
235 ); | |
236 } | |
237 | |
238 VertexShaderTile::VertexShaderTile() | |
239 : m_matrixLocation(-1) | |
240 , m_pointLocation(-1) | |
241 , m_vertexTexTransformLocation(-1) | |
242 { | |
243 } | |
244 | |
245 void VertexShaderTile::init(WebGraphicsContext3D* context, unsigned program, boo
l usingBindUniform, int* baseUniformIndex) | |
246 { | |
247 static const char* shaderUniforms[] = { | |
248 "matrix", | |
249 "point", | |
250 "vertexTexTransform", | |
251 }; | |
252 int locations[3]; | |
253 | |
254 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
255 | |
256 m_matrixLocation = locations[0]; | |
257 m_pointLocation = locations[1]; | |
258 m_vertexTexTransformLocation = locations[2]; | |
259 ASSERT(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo
rmLocation != -1); | |
260 } | |
261 | |
262 std::string VertexShaderTile::getShaderString() const | |
263 { | |
264 return SHADER( | |
265 attribute vec4 a_position; | |
266 attribute vec2 a_texCoord; | |
267 uniform mat4 matrix; | |
268 uniform vec2 point[4]; | |
269 uniform vec4 vertexTexTransform; | |
270 varying vec2 v_texCoord; | |
271 void main() | |
272 { | |
273 vec2 complement = abs(a_texCoord - 1.0); | |
274 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | |
275 pos.xy += (complement.x * complement.y) * point[0]; | |
276 pos.xy += (a_texCoord.x * complement.y) * point[1]; | |
277 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | |
278 pos.xy += (complement.x * a_texCoord.y) * point[3]; | |
279 gl_Position = matrix * pos; | |
280 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | |
281 } | |
282 ); | |
283 } | |
284 | |
285 VertexShaderVideoTransform::VertexShaderVideoTransform() | |
286 : m_matrixLocation(-1) | |
287 , m_texMatrixLocation(-1) | |
288 { | |
289 } | |
290 | |
291 bool VertexShaderVideoTransform::init(WebGraphicsContext3D* context, unsigned pr
ogram, bool usingBindUniform, int* baseUniformIndex) | |
292 { | |
293 static const char* shaderUniforms[] = { | |
294 "matrix", | |
295 "texMatrix", | |
296 }; | |
297 int locations[2]; | |
298 | |
299 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
300 | |
301 m_matrixLocation = locations[0]; | |
302 m_texMatrixLocation = locations[1]; | |
303 return m_matrixLocation != -1 && m_texMatrixLocation != -1; | |
304 } | |
305 | |
306 std::string VertexShaderVideoTransform::getShaderString() const | |
307 { | |
308 return SHADER( | |
309 attribute vec4 a_position; | |
310 attribute vec2 a_texCoord; | |
311 uniform mat4 matrix; | |
312 uniform mat4 texMatrix; | |
313 varying vec2 v_texCoord; | |
314 void main() | |
315 { | |
316 gl_Position = matrix * a_position; | |
317 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y,
0.0, 1.0)); | |
318 } | |
319 ); | |
320 } | |
321 | |
322 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | |
323 : m_samplerLocation(-1) | |
324 , m_alphaLocation(-1) | |
325 { | |
326 } | |
327 | |
328 void FragmentTexAlphaBinding::init(WebGraphicsContext3D* context, unsigned progr
am, bool usingBindUniform, int* baseUniformIndex) | |
329 { | |
330 static const char* shaderUniforms[] = { | |
331 "s_texture", | |
332 "alpha", | |
333 }; | |
334 int locations[2]; | |
335 | |
336 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
337 | |
338 m_samplerLocation = locations[0]; | |
339 m_alphaLocation = locations[1]; | |
340 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1); | |
341 } | |
342 | |
343 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() | |
344 : m_samplerLocation(-1) | |
345 { | |
346 } | |
347 | |
348 void FragmentTexOpaqueBinding::init(WebGraphicsContext3D* context, unsigned prog
ram, bool usingBindUniform, int* baseUniformIndex) | |
349 { | |
350 static const char* shaderUniforms[] = { | |
351 "s_texture", | |
352 }; | |
353 int locations[1]; | |
354 | |
355 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
356 | |
357 m_samplerLocation = locations[0]; | |
358 ASSERT(m_samplerLocation != -1); | |
359 } | |
360 | |
361 std::string FragmentShaderRGBATexFlipAlpha::getShaderString() const | |
362 { | |
363 return SHADER( | |
364 precision mediump float; | |
365 varying vec2 v_texCoord; | |
366 uniform sampler2D s_texture; | |
367 uniform float alpha; | |
368 void main() | |
369 { | |
370 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC
oord.y)); | |
371 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha; | |
372 } | |
373 ); | |
374 } | |
375 | |
376 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) | |
377 { | |
378 static const char* shaderUniforms[] = { | |
379 "s_texture", | |
380 }; | |
381 int locations[1]; | |
382 | |
383 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
384 | |
385 m_samplerLocation = locations[0]; | |
386 return m_samplerLocation != -1; | |
387 } | |
388 | |
389 std::string FragmentShaderOESImageExternal::getShaderString() const | |
390 { | |
391 // Cannot use the SHADER() macro because of the '#' char | |
392 return "#extension GL_OES_EGL_image_external : require \n" | |
393 "precision mediump float;\n" | |
394 "varying vec2 v_texCoord;\n" | |
395 "uniform samplerExternalOES s_texture;\n" | |
396 "void main()\n" | |
397 "{\n" | |
398 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" | |
399 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor
.w);\n" | |
400 "}\n"; | |
401 } | |
402 | |
403 std::string FragmentShaderRGBATexAlpha::getShaderString() const | |
404 { | |
405 return SHADER( | |
406 precision mediump float; | |
407 varying vec2 v_texCoord; | |
408 uniform sampler2D s_texture; | |
409 uniform float alpha; | |
410 void main() | |
411 { | |
412 vec4 texColor = texture2D(s_texture, v_texCoord); | |
413 gl_FragColor = texColor * alpha; | |
414 } | |
415 ); | |
416 } | |
417 | |
418 std::string FragmentShaderRGBATexRectFlipAlpha::getShaderString() const | |
419 { | |
420 // This must be paired with VertexShaderPosTexTransform to pick up the texTr
ansform uniform. | |
421 // The necessary #extension preprocessing directive breaks the SHADER and SH
ADER0 macros. | |
422 return "#extension GL_ARB_texture_rectangle : require\n" | |
423 "precision mediump float;\n" | |
424 "varying vec2 v_texCoord;\n" | |
425 "uniform vec4 texTransform;\n" | |
426 "uniform sampler2DRect s_texture;\n" | |
427 "uniform float alpha;\n" | |
428 "void main()\n" | |
429 "{\n" | |
430 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex
Transform.w - v_texCoord.y));\n" | |
431 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo
r.w) * alpha;\n" | |
432 "}\n"; | |
433 } | |
434 | |
435 std::string FragmentShaderRGBATexRectAlpha::getShaderString() const | |
436 { | |
437 return "#extension GL_ARB_texture_rectangle : require\n" | |
438 "precision mediump float;\n" | |
439 "varying vec2 v_texCoord;\n" | |
440 "uniform sampler2DRect s_texture;\n" | |
441 "uniform float alpha;\n" | |
442 "void main()\n" | |
443 "{\n" | |
444 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | |
445 " gl_FragColor = texColor * alpha;\n" | |
446 "}\n"; | |
447 } | |
448 | |
449 std::string FragmentShaderRGBATexOpaque::getShaderString() const | |
450 { | |
451 return SHADER( | |
452 precision mediump float; | |
453 varying vec2 v_texCoord; | |
454 uniform sampler2D s_texture; | |
455 void main() | |
456 { | |
457 vec4 texColor = texture2D(s_texture, v_texCoord); | |
458 gl_FragColor = vec4(texColor.rgb, 1.0); | |
459 } | |
460 ); | |
461 } | |
462 | |
463 std::string FragmentShaderRGBATex::getShaderString() const | |
464 { | |
465 return SHADER( | |
466 precision mediump float; | |
467 varying vec2 v_texCoord; | |
468 uniform sampler2D s_texture; | |
469 void main() | |
470 { | |
471 gl_FragColor = texture2D(s_texture, v_texCoord); | |
472 } | |
473 ); | |
474 } | |
475 | |
476 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const | |
477 { | |
478 return SHADER( | |
479 precision mediump float; | |
480 varying vec2 v_texCoord; | |
481 uniform sampler2D s_texture; | |
482 uniform float alpha; | |
483 void main() | |
484 { | |
485 vec4 texColor = texture2D(s_texture, v_texCoord); | |
486 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w)
* alpha; | |
487 } | |
488 ); | |
489 } | |
490 | |
491 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const | |
492 { | |
493 return SHADER( | |
494 precision mediump float; | |
495 varying vec2 v_texCoord; | |
496 uniform sampler2D s_texture; | |
497 void main() | |
498 { | |
499 vec4 texColor = texture2D(s_texture, v_texCoord); | |
500 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | |
501 } | |
502 ); | |
503 } | |
504 | |
505 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | |
506 : m_samplerLocation(-1) | |
507 , m_alphaLocation(-1) | |
508 , m_edgeLocation(-1) | |
509 { | |
510 } | |
511 | |
512 void FragmentShaderRGBATexAlphaAA::init(WebGraphicsContext3D* context, unsigned
program, bool usingBindUniform, int* baseUniformIndex) | |
513 { | |
514 static const char* shaderUniforms[] = { | |
515 "s_texture", | |
516 "alpha", | |
517 "edge", | |
518 }; | |
519 int locations[3]; | |
520 | |
521 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
522 | |
523 m_samplerLocation = locations[0]; | |
524 m_alphaLocation = locations[1]; | |
525 m_edgeLocation = locations[2]; | |
526 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation !=
-1); | |
527 } | |
528 | |
529 std::string FragmentShaderRGBATexAlphaAA::getShaderString() const | |
530 { | |
531 return SHADER( | |
532 precision mediump float; | |
533 varying vec2 v_texCoord; | |
534 uniform sampler2D s_texture; | |
535 uniform float alpha; | |
536 uniform vec3 edge[8]; | |
537 void main() | |
538 { | |
539 vec4 texColor = texture2D(s_texture, v_texCoord); | |
540 vec3 pos = vec3(gl_FragCoord.xy, 1); | |
541 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | |
542 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | |
543 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
544 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
545 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
546 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
547 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
548 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
549 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min
(a4, a6) * min(a5, a7)); | |
550 } | |
551 ); | |
552 } | |
553 | |
554 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() | |
555 : m_samplerLocation(-1) | |
556 , m_alphaLocation(-1) | |
557 , m_fragmentTexTransformLocation(-1) | |
558 , m_edgeLocation(-1) | |
559 { | |
560 } | |
561 | |
562 void FragmentTexClampAlphaAABinding::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) | |
563 { | |
564 static const char* shaderUniforms[] = { | |
565 "s_texture", | |
566 "alpha", | |
567 "fragmentTexTransform", | |
568 "edge", | |
569 }; | |
570 int locations[4]; | |
571 | |
572 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
573 | |
574 m_samplerLocation = locations[0]; | |
575 m_alphaLocation = locations[1]; | |
576 m_fragmentTexTransformLocation = locations[2]; | |
577 m_edgeLocation = locations[3]; | |
578 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran
sformLocation != -1 && m_edgeLocation != -1); | |
579 } | |
580 | |
581 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString() const | |
582 { | |
583 return SHADER( | |
584 precision mediump float; | |
585 varying vec2 v_texCoord; | |
586 uniform sampler2D s_texture; | |
587 uniform float alpha; | |
588 uniform vec4 fragmentTexTransform; | |
589 uniform vec3 edge[8]; | |
590 void main() | |
591 { | |
592 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; | |
593 vec4 texColor = texture2D(s_texture, texCoord); | |
594 vec3 pos = vec3(gl_FragCoord.xy, 1); | |
595 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | |
596 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | |
597 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
598 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
599 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
600 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
601 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
602 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
603 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min
(a4, a6) * min(a5, a7)); | |
604 } | |
605 ); | |
606 } | |
607 | |
608 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const | |
609 { | |
610 return SHADER( | |
611 precision mediump float; | |
612 varying vec2 v_texCoord; | |
613 uniform sampler2D s_texture; | |
614 uniform float alpha; | |
615 uniform vec4 fragmentTexTransform; | |
616 uniform vec3 edge[8]; | |
617 void main() | |
618 { | |
619 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; | |
620 vec4 texColor = texture2D(s_texture, texCoord); | |
621 vec3 pos = vec3(gl_FragCoord.xy, 1); | |
622 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | |
623 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | |
624 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
625 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
626 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
627 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
628 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
629 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
630 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w)
* alpha * min(min(a0, a2) * min(a1, a3), min(a4, a6) * min(a5, a7)); | |
631 } | |
632 ); | |
633 } | |
634 | |
635 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() | |
636 : m_samplerLocation(-1) | |
637 , m_maskSamplerLocation(-1) | |
638 , m_alphaLocation(-1) | |
639 , m_maskTexCoordScaleLocation(-1) | |
640 { | |
641 } | |
642 | |
643 void FragmentShaderRGBATexAlphaMask::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) | |
644 { | |
645 static const char* shaderUniforms[] = { | |
646 "s_texture", | |
647 "s_mask", | |
648 "alpha", | |
649 "maskTexCoordScale", | |
650 "maskTexCoordOffset", | |
651 }; | |
652 int locations[5]; | |
653 | |
654 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
655 | |
656 m_samplerLocation = locations[0]; | |
657 m_maskSamplerLocation = locations[1]; | |
658 m_alphaLocation = locations[2]; | |
659 m_maskTexCoordScaleLocation = locations[3]; | |
660 m_maskTexCoordOffsetLocation = locations[4]; | |
661 ASSERT(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1); | |
662 } | |
663 | |
664 std::string FragmentShaderRGBATexAlphaMask::getShaderString() const | |
665 { | |
666 return SHADER( | |
667 precision mediump float; | |
668 varying vec2 v_texCoord; | |
669 uniform sampler2D s_texture; | |
670 uniform sampler2D s_mask; | |
671 uniform vec2 maskTexCoordScale; | |
672 uniform vec2 maskTexCoordOffset; | |
673 uniform float alpha; | |
674 void main() | |
675 { | |
676 vec4 texColor = texture2D(s_texture, v_texCoord); | |
677 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT
exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | |
678 vec4 maskColor = texture2D(s_mask, maskTexCoord); | |
679 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha * maskColor.w; | |
680 } | |
681 ); | |
682 } | |
683 | |
684 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | |
685 : m_samplerLocation(-1) | |
686 , m_maskSamplerLocation(-1) | |
687 , m_alphaLocation(-1) | |
688 , m_edgeLocation(-1) | |
689 , m_maskTexCoordScaleLocation(-1) | |
690 { | |
691 } | |
692 | |
693 void FragmentShaderRGBATexAlphaMaskAA::init(WebGraphicsContext3D* context, unsig
ned program, bool usingBindUniform, int* baseUniformIndex) | |
694 { | |
695 static const char* shaderUniforms[] = { | |
696 "s_texture", | |
697 "s_mask", | |
698 "alpha", | |
699 "edge", | |
700 "maskTexCoordScale", | |
701 "maskTexCoordOffset", | |
702 }; | |
703 int locations[6]; | |
704 | |
705 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
706 | |
707 m_samplerLocation = locations[0]; | |
708 m_maskSamplerLocation = locations[1]; | |
709 m_alphaLocation = locations[2]; | |
710 m_edgeLocation = locations[3]; | |
711 m_maskTexCoordScaleLocation = locations[4]; | |
712 m_maskTexCoordOffsetLocation = locations[5]; | |
713 ASSERT(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1 && m_edgeLocation != -1); | |
714 } | |
715 | |
716 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString() const | |
717 { | |
718 return SHADER( | |
719 precision mediump float; | |
720 varying vec2 v_texCoord; | |
721 uniform sampler2D s_texture; | |
722 uniform sampler2D s_mask; | |
723 uniform vec2 maskTexCoordScale; | |
724 uniform vec2 maskTexCoordOffset; | |
725 uniform float alpha; | |
726 uniform vec3 edge[8]; | |
727 void main() | |
728 { | |
729 vec4 texColor = texture2D(s_texture, v_texCoord); | |
730 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT
exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | |
731 vec4 maskColor = texture2D(s_mask, maskTexCoord); | |
732 vec3 pos = vec3(gl_FragCoord.xy, 1); | |
733 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | |
734 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | |
735 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
736 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
737 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
738 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
739 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
740 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
741 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha * maskColor.w * min(min(a0, a2) * min(a1, a3), min(a4, a6) * min(a5, a7)
); | |
742 } | |
743 ); | |
744 } | |
745 | |
746 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | |
747 : m_yTextureLocation(-1) | |
748 , m_uTextureLocation(-1) | |
749 , m_vTextureLocation(-1) | |
750 , m_alphaLocation(-1) | |
751 , m_ccMatrixLocation(-1) | |
752 , m_yuvAdjLocation(-1) | |
753 { | |
754 } | |
755 | |
756 void FragmentShaderYUVVideo::init(WebGraphicsContext3D* context, unsigned progra
m, bool usingBindUniform, int* baseUniformIndex) | |
757 { | |
758 static const char* shaderUniforms[] = { | |
759 "y_texture", | |
760 "u_texture", | |
761 "v_texture", | |
762 "alpha", | |
763 "cc_matrix", | |
764 "yuv_adj", | |
765 }; | |
766 int locations[6]; | |
767 | |
768 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
769 | |
770 m_yTextureLocation = locations[0]; | |
771 m_uTextureLocation = locations[1]; | |
772 m_vTextureLocation = locations[2]; | |
773 m_alphaLocation = locations[3]; | |
774 m_ccMatrixLocation = locations[4]; | |
775 m_yuvAdjLocation = locations[5]; | |
776 | |
777 ASSERT(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc
ation != -1 | |
778 && m_alphaLocation != -1 && m_ccMatrixLocation != -1 && m_yuvAdjLocat
ion != -1); | |
779 } | |
780 | |
781 std::string FragmentShaderYUVVideo::getShaderString() const | |
782 { | |
783 return SHADER( | |
784 precision mediump float; | |
785 precision mediump int; | |
786 varying vec2 y_texCoord; | |
787 varying vec2 uv_texCoord; | |
788 uniform sampler2D y_texture; | |
789 uniform sampler2D u_texture; | |
790 uniform sampler2D v_texture; | |
791 uniform float alpha; | |
792 uniform vec3 yuv_adj; | |
793 uniform mat3 cc_matrix; | |
794 void main() | |
795 { | |
796 float y_raw = texture2D(y_texture, y_texCoord).x; | |
797 float u_unsigned = texture2D(u_texture, uv_texCoord).x; | |
798 float v_unsigned = texture2D(v_texture, uv_texCoord).x; | |
799 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | |
800 vec3 rgb = cc_matrix * yuv; | |
801 gl_FragColor = vec4(rgb, float(1)) * alpha; | |
802 } | |
803 ); | |
804 } | |
805 | |
806 FragmentShaderColor::FragmentShaderColor() | |
807 : m_colorLocation(-1) | |
808 { | |
809 } | |
810 | |
811 void FragmentShaderColor::init(WebGraphicsContext3D* context, unsigned program,
bool usingBindUniform, int* baseUniformIndex) | |
812 { | |
813 static const char* shaderUniforms[] = { | |
814 "color", | |
815 }; | |
816 int locations[1]; | |
817 | |
818 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
819 | |
820 m_colorLocation = locations[0]; | |
821 ASSERT(m_colorLocation != -1); | |
822 } | |
823 | |
824 std::string FragmentShaderColor::getShaderString() const | |
825 { | |
826 return SHADER( | |
827 precision mediump float; | |
828 uniform vec4 color; | |
829 void main() | |
830 { | |
831 gl_FragColor = color; | |
832 } | |
833 ); | |
834 } | |
835 | |
836 FragmentShaderCheckerboard::FragmentShaderCheckerboard() | |
837 : m_alphaLocation(-1) | |
838 , m_texTransformLocation(-1) | |
839 , m_frequencyLocation(-1) | |
840 { | |
841 } | |
842 | |
843 void FragmentShaderCheckerboard::init(WebGraphicsContext3D* context, unsigned pr
ogram, bool usingBindUniform, int* baseUniformIndex) | |
844 { | |
845 static const char* shaderUniforms[] = { | |
846 "alpha", | |
847 "texTransform", | |
848 "frequency", | |
849 "color", | |
850 }; | |
851 int locations[4]; | |
852 | |
853 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | |
854 | |
855 m_alphaLocation = locations[0]; | |
856 m_texTransformLocation = locations[1]; | |
857 m_frequencyLocation = locations[2]; | |
858 m_colorLocation = locations[3]; | |
859 ASSERT(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL
ocation != -1 && m_colorLocation != -1); | |
860 } | |
861 | |
862 std::string FragmentShaderCheckerboard::getShaderString() const | |
863 { | |
864 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | |
865 // by Munshi, Ginsburg, Shreiner. | |
866 return SHADER( | |
867 precision mediump float; | |
868 precision mediump int; | |
869 varying vec2 v_texCoord; | |
870 uniform float alpha; | |
871 uniform float frequency; | |
872 uniform vec4 texTransform; | |
873 uniform vec4 color; | |
874 void main() | |
875 { | |
876 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | |
877 vec4 color2 = color; | |
878 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; | |
879 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | |
880 float picker = abs(coord.x - coord.y); | |
881 gl_FragColor = mix(color1, color2, picker) * alpha; | |
882 } | |
883 ); | |
884 } | |
885 | |
886 } // namespace cc | |
887 | |
888 #endif // USE(ACCELERATED_COMPOSITING) | |
OLD | NEW |