OLD | NEW |
(Empty) | |
| 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 #include "config.h" |
| 27 |
| 28 #if USE(ACCELERATED_COMPOSITING) |
| 29 |
| 30 #include "ShaderChromium.h" |
| 31 |
| 32 #include <public/WebGraphicsContext3D.h> |
| 33 |
| 34 #define SHADER0(Src) #Src |
| 35 #define SHADER(Src) SHADER0(Src) |
| 36 |
| 37 using WebKit::WebGraphicsContext3D; |
| 38 |
| 39 namespace WebCore { |
| 40 |
| 41 VertexShaderPosTex::VertexShaderPosTex() |
| 42 : m_matrixLocation(-1) |
| 43 { |
| 44 } |
| 45 |
| 46 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program) |
| 47 { |
| 48 m_matrixLocation = context->getUniformLocation(program, "matrix"); |
| 49 ASSERT(m_matrixLocation != -1); |
| 50 } |
| 51 |
| 52 String VertexShaderPosTex::getShaderString() const |
| 53 { |
| 54 return SHADER( |
| 55 attribute vec4 a_position; |
| 56 attribute vec2 a_texCoord; |
| 57 uniform mat4 matrix; |
| 58 varying vec2 v_texCoord; |
| 59 void main() |
| 60 { |
| 61 gl_Position = matrix * a_position; |
| 62 v_texCoord = a_texCoord; |
| 63 } |
| 64 ); |
| 65 } |
| 66 |
| 67 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() |
| 68 : m_matrixLocation(-1) |
| 69 , m_yWidthScaleFactorLocation(-1) |
| 70 , m_uvWidthScaleFactorLocation(-1) |
| 71 { |
| 72 } |
| 73 |
| 74 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned
program) |
| 75 { |
| 76 m_matrixLocation = context->getUniformLocation(program, "matrix"); |
| 77 m_yWidthScaleFactorLocation = context->getUniformLocation(program, "y_widthS
caleFactor"); |
| 78 m_uvWidthScaleFactorLocation = context->getUniformLocation(program, "uv_widt
hScaleFactor"); |
| 79 ASSERT(m_matrixLocation != -1 && m_yWidthScaleFactorLocation != -1 && m_uvWi
dthScaleFactorLocation != -1); |
| 80 } |
| 81 |
| 82 String VertexShaderPosTexYUVStretch::getShaderString() const |
| 83 { |
| 84 return SHADER( |
| 85 precision mediump float; |
| 86 attribute vec4 a_position; |
| 87 attribute vec2 a_texCoord; |
| 88 uniform mat4 matrix; |
| 89 varying vec2 y_texCoord; |
| 90 varying vec2 uv_texCoord; |
| 91 uniform float y_widthScaleFactor; |
| 92 uniform float uv_widthScaleFactor; |
| 93 void main() |
| 94 { |
| 95 gl_Position = matrix * a_position; |
| 96 y_texCoord = vec2(y_widthScaleFactor * a_texCoord.x, a_texCoord.y); |
| 97 uv_texCoord = vec2(uv_widthScaleFactor * a_texCoord.x, a_texCoord.y)
; |
| 98 } |
| 99 ); |
| 100 } |
| 101 |
| 102 VertexShaderPos::VertexShaderPos() |
| 103 : m_matrixLocation(-1) |
| 104 { |
| 105 } |
| 106 |
| 107 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program) |
| 108 { |
| 109 m_matrixLocation = context->getUniformLocation(program, "matrix"); |
| 110 ASSERT(m_matrixLocation != -1); |
| 111 } |
| 112 |
| 113 String VertexShaderPos::getShaderString() const |
| 114 { |
| 115 return SHADER( |
| 116 attribute vec4 a_position; |
| 117 uniform mat4 matrix; |
| 118 void main() |
| 119 { |
| 120 gl_Position = matrix * a_position; |
| 121 } |
| 122 ); |
| 123 } |
| 124 |
| 125 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
| 126 : m_matrixLocation(-1) |
| 127 , m_texTransformLocation(-1) |
| 128 { |
| 129 } |
| 130 |
| 131 void VertexShaderPosTexTransform::init(WebGraphicsContext3D* context, unsigned p
rogram) |
| 132 { |
| 133 m_matrixLocation = context->getUniformLocation(program, "matrix"); |
| 134 m_texTransformLocation = context->getUniformLocation(program, "texTransform"
); |
| 135 ASSERT(m_matrixLocation != -1 && m_texTransformLocation != -1); |
| 136 } |
| 137 |
| 138 String VertexShaderPosTexTransform::getShaderString() const |
| 139 { |
| 140 return SHADER( |
| 141 attribute vec4 a_position; |
| 142 attribute vec2 a_texCoord; |
| 143 uniform mat4 matrix; |
| 144 uniform vec4 texTransform; |
| 145 varying vec2 v_texCoord; |
| 146 void main() |
| 147 { |
| 148 gl_Position = matrix * a_position; |
| 149 v_texCoord = a_texCoord * texTransform.zw + texTransform.xy; |
| 150 } |
| 151 ); |
| 152 } |
| 153 |
| 154 VertexShaderQuad::VertexShaderQuad() |
| 155 : m_matrixLocation(-1) |
| 156 , m_pointLocation(-1) |
| 157 { |
| 158 } |
| 159 |
| 160 String VertexShaderPosTexIdentity::getShaderString() const |
| 161 { |
| 162 return SHADER( |
| 163 attribute vec4 a_position; |
| 164 varying vec2 v_texCoord; |
| 165 void main() |
| 166 { |
| 167 gl_Position = a_position; |
| 168 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
| 169 } |
| 170 ); |
| 171 } |
| 172 |
| 173 void VertexShaderQuad::init(WebGraphicsContext3D* context, unsigned program) |
| 174 { |
| 175 m_matrixLocation = context->getUniformLocation(program, "matrix"); |
| 176 m_pointLocation = context->getUniformLocation(program, "point"); |
| 177 ASSERT(m_matrixLocation != -1 && m_pointLocation != -1); |
| 178 } |
| 179 |
| 180 String VertexShaderQuad::getShaderString() const |
| 181 { |
| 182 return SHADER( |
| 183 attribute vec4 a_position; |
| 184 attribute vec2 a_texCoord; |
| 185 uniform mat4 matrix; |
| 186 uniform vec2 point[4]; |
| 187 varying vec2 v_texCoord; |
| 188 void main() |
| 189 { |
| 190 vec2 complement = abs(a_texCoord - 1.0); |
| 191 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 192 pos.xy += (complement.x * complement.y) * point[0]; |
| 193 pos.xy += (a_texCoord.x * complement.y) * point[1]; |
| 194 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; |
| 195 pos.xy += (complement.x * a_texCoord.y) * point[3]; |
| 196 gl_Position = matrix * pos; |
| 197 v_texCoord = pos.xy + vec2(0.5); |
| 198 } |
| 199 ); |
| 200 } |
| 201 |
| 202 VertexShaderTile::VertexShaderTile() |
| 203 : m_matrixLocation(-1) |
| 204 , m_pointLocation(-1) |
| 205 , m_vertexTexTransformLocation(-1) |
| 206 { |
| 207 } |
| 208 |
| 209 void VertexShaderTile::init(WebGraphicsContext3D* context, unsigned program) |
| 210 { |
| 211 m_matrixLocation = context->getUniformLocation(program, "matrix"); |
| 212 m_pointLocation = context->getUniformLocation(program, "point"); |
| 213 m_vertexTexTransformLocation = context->getUniformLocation(program, "vertexT
exTransform"); |
| 214 ASSERT(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo
rmLocation != -1); |
| 215 } |
| 216 |
| 217 String VertexShaderTile::getShaderString() const |
| 218 { |
| 219 return SHADER( |
| 220 attribute vec4 a_position; |
| 221 attribute vec2 a_texCoord; |
| 222 uniform mat4 matrix; |
| 223 uniform vec2 point[4]; |
| 224 uniform vec4 vertexTexTransform; |
| 225 varying vec2 v_texCoord; |
| 226 void main() |
| 227 { |
| 228 vec2 complement = abs(a_texCoord - 1.0); |
| 229 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 230 pos.xy += (complement.x * complement.y) * point[0]; |
| 231 pos.xy += (a_texCoord.x * complement.y) * point[1]; |
| 232 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; |
| 233 pos.xy += (complement.x * a_texCoord.y) * point[3]; |
| 234 gl_Position = matrix * pos; |
| 235 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; |
| 236 } |
| 237 ); |
| 238 } |
| 239 |
| 240 VertexShaderVideoTransform::VertexShaderVideoTransform() |
| 241 : m_matrixLocation(-1) |
| 242 , m_texMatrixLocation(-1) |
| 243 { |
| 244 } |
| 245 |
| 246 bool VertexShaderVideoTransform::init(WebGraphicsContext3D* context, unsigned pr
ogram) |
| 247 { |
| 248 m_matrixLocation = context->getUniformLocation(program, "matrix"); |
| 249 m_texMatrixLocation = context->getUniformLocation(program, "texMatrix"); |
| 250 return m_matrixLocation != -1 && m_texMatrixLocation != -1; |
| 251 } |
| 252 |
| 253 String VertexShaderVideoTransform::getShaderString() const |
| 254 { |
| 255 return SHADER( |
| 256 attribute vec4 a_position; |
| 257 attribute vec2 a_texCoord; |
| 258 uniform mat4 matrix; |
| 259 uniform mat4 texMatrix; |
| 260 varying vec2 v_texCoord; |
| 261 void main() |
| 262 { |
| 263 gl_Position = matrix * a_position; |
| 264 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y,
0.0, 1.0)); |
| 265 } |
| 266 ); |
| 267 } |
| 268 |
| 269 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
| 270 : m_samplerLocation(-1) |
| 271 , m_alphaLocation(-1) |
| 272 { |
| 273 } |
| 274 |
| 275 void FragmentTexAlphaBinding::init(WebGraphicsContext3D* context, unsigned progr
am) |
| 276 { |
| 277 m_samplerLocation = context->getUniformLocation(program, "s_texture"); |
| 278 m_alphaLocation = context->getUniformLocation(program, "alpha"); |
| 279 |
| 280 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1); |
| 281 } |
| 282 |
| 283 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() |
| 284 : m_samplerLocation(-1) |
| 285 { |
| 286 } |
| 287 |
| 288 void FragmentTexOpaqueBinding::init(WebGraphicsContext3D* context, unsigned prog
ram) |
| 289 { |
| 290 m_samplerLocation = context->getUniformLocation(program, "s_texture"); |
| 291 |
| 292 ASSERT(m_samplerLocation != -1); |
| 293 } |
| 294 |
| 295 String FragmentShaderRGBATexFlipAlpha::getShaderString() const |
| 296 { |
| 297 return SHADER( |
| 298 precision mediump float; |
| 299 varying vec2 v_texCoord; |
| 300 uniform sampler2D s_texture; |
| 301 uniform float alpha; |
| 302 void main() |
| 303 { |
| 304 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC
oord.y)); |
| 305 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha; |
| 306 } |
| 307 ); |
| 308 } |
| 309 |
| 310 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
d program) |
| 311 { |
| 312 m_samplerLocation = context->getUniformLocation(program, "s_texture"); |
| 313 |
| 314 return m_samplerLocation != -1; |
| 315 } |
| 316 |
| 317 String FragmentShaderOESImageExternal::getShaderString() const |
| 318 { |
| 319 // Cannot use the SHADER() macro because of the '#' char |
| 320 return "#extension GL_OES_EGL_image_external : require \n" |
| 321 "precision mediump float;\n" |
| 322 "varying vec2 v_texCoord;\n" |
| 323 "uniform samplerExternalOES s_texture;\n" |
| 324 "void main()\n" |
| 325 "{\n" |
| 326 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" |
| 327 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor
.w);\n" |
| 328 "}\n"; |
| 329 } |
| 330 |
| 331 String FragmentShaderRGBATexAlpha::getShaderString() const |
| 332 { |
| 333 return SHADER( |
| 334 precision mediump float; |
| 335 varying vec2 v_texCoord; |
| 336 uniform sampler2D s_texture; |
| 337 uniform float alpha; |
| 338 void main() |
| 339 { |
| 340 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 341 gl_FragColor = texColor * alpha; |
| 342 } |
| 343 ); |
| 344 } |
| 345 |
| 346 String FragmentShaderRGBATexRectFlipAlpha::getShaderString() const |
| 347 { |
| 348 // This must be paired with VertexShaderPosTexTransform to pick up the texTr
ansform uniform. |
| 349 // The necessary #extension preprocessing directive breaks the SHADER and SH
ADER0 macros. |
| 350 return "#extension GL_ARB_texture_rectangle : require\n" |
| 351 "precision mediump float;\n" |
| 352 "varying vec2 v_texCoord;\n" |
| 353 "uniform vec4 texTransform;\n" |
| 354 "uniform sampler2DRect s_texture;\n" |
| 355 "uniform float alpha;\n" |
| 356 "void main()\n" |
| 357 "{\n" |
| 358 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex
Transform.w - v_texCoord.y));\n" |
| 359 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo
r.w) * alpha;\n" |
| 360 "}\n"; |
| 361 } |
| 362 |
| 363 String FragmentShaderRGBATexRectAlpha::getShaderString() const |
| 364 { |
| 365 return "#extension GL_ARB_texture_rectangle : require\n" |
| 366 "precision mediump float;\n" |
| 367 "varying vec2 v_texCoord;\n" |
| 368 "uniform sampler2DRect s_texture;\n" |
| 369 "uniform float alpha;\n" |
| 370 "void main()\n" |
| 371 "{\n" |
| 372 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" |
| 373 " gl_FragColor = texColor * alpha;\n" |
| 374 "}\n"; |
| 375 } |
| 376 |
| 377 String FragmentShaderRGBATexOpaque::getShaderString() const |
| 378 { |
| 379 return SHADER( |
| 380 precision mediump float; |
| 381 varying vec2 v_texCoord; |
| 382 uniform sampler2D s_texture; |
| 383 void main() |
| 384 { |
| 385 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 386 gl_FragColor = vec4(texColor.rgb, 1.0); |
| 387 } |
| 388 ); |
| 389 } |
| 390 |
| 391 String FragmentShaderRGBATex::getShaderString() const |
| 392 { |
| 393 return SHADER( |
| 394 precision mediump float; |
| 395 varying vec2 v_texCoord; |
| 396 uniform sampler2D s_texture; |
| 397 void main() |
| 398 { |
| 399 gl_FragColor = texture2D(s_texture, v_texCoord); |
| 400 } |
| 401 ); |
| 402 } |
| 403 |
| 404 String FragmentShaderRGBATexSwizzleAlpha::getShaderString() const |
| 405 { |
| 406 return SHADER( |
| 407 precision mediump float; |
| 408 varying vec2 v_texCoord; |
| 409 uniform sampler2D s_texture; |
| 410 uniform float alpha; |
| 411 void main() |
| 412 { |
| 413 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 414 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w)
* alpha; |
| 415 } |
| 416 ); |
| 417 } |
| 418 |
| 419 String FragmentShaderRGBATexSwizzleOpaque::getShaderString() const |
| 420 { |
| 421 return SHADER( |
| 422 precision mediump float; |
| 423 varying vec2 v_texCoord; |
| 424 uniform sampler2D s_texture; |
| 425 void main() |
| 426 { |
| 427 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 428 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
| 429 } |
| 430 ); |
| 431 } |
| 432 |
| 433 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
| 434 : m_samplerLocation(-1) |
| 435 , m_alphaLocation(-1) |
| 436 , m_edgeLocation(-1) |
| 437 { |
| 438 } |
| 439 |
| 440 void FragmentShaderRGBATexAlphaAA::init(WebGraphicsContext3D* context, unsigned
program) |
| 441 { |
| 442 m_samplerLocation = context->getUniformLocation(program, "s_texture"); |
| 443 m_alphaLocation = context->getUniformLocation(program, "alpha"); |
| 444 m_edgeLocation = context->getUniformLocation(program, "edge"); |
| 445 |
| 446 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation !=
-1); |
| 447 } |
| 448 |
| 449 String FragmentShaderRGBATexAlphaAA::getShaderString() const |
| 450 { |
| 451 return SHADER( |
| 452 precision mediump float; |
| 453 varying vec2 v_texCoord; |
| 454 uniform sampler2D s_texture; |
| 455 uniform float alpha; |
| 456 uniform vec3 edge[8]; |
| 457 void main() |
| 458 { |
| 459 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 460 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 461 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 462 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 463 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 464 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 465 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 466 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 467 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 468 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| 469 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min
(a4, a6) * min(a5, a7)); |
| 470 } |
| 471 ); |
| 472 } |
| 473 |
| 474 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() |
| 475 : m_samplerLocation(-1) |
| 476 , m_alphaLocation(-1) |
| 477 , m_fragmentTexTransformLocation(-1) |
| 478 , m_edgeLocation(-1) |
| 479 { |
| 480 } |
| 481 |
| 482 void FragmentTexClampAlphaAABinding::init(WebGraphicsContext3D* context, unsigne
d program) |
| 483 { |
| 484 m_samplerLocation = context->getUniformLocation(program, "s_texture"); |
| 485 m_alphaLocation = context->getUniformLocation(program, "alpha"); |
| 486 m_fragmentTexTransformLocation = context->getUniformLocation(program, "fragm
entTexTransform"); |
| 487 m_edgeLocation = context->getUniformLocation(program, "edge"); |
| 488 |
| 489 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran
sformLocation != -1 && m_edgeLocation != -1); |
| 490 } |
| 491 |
| 492 String FragmentShaderRGBATexClampAlphaAA::getShaderString() const |
| 493 { |
| 494 return SHADER( |
| 495 precision mediump float; |
| 496 varying vec2 v_texCoord; |
| 497 uniform sampler2D s_texture; |
| 498 uniform float alpha; |
| 499 uniform vec4 fragmentTexTransform; |
| 500 uniform vec3 edge[8]; |
| 501 void main() |
| 502 { |
| 503 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; |
| 504 vec4 texColor = texture2D(s_texture, texCoord); |
| 505 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 506 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 507 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 508 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 509 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 510 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 511 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 512 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 513 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| 514 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min
(a4, a6) * min(a5, a7)); |
| 515 } |
| 516 ); |
| 517 } |
| 518 |
| 519 String FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const |
| 520 { |
| 521 return SHADER( |
| 522 precision mediump float; |
| 523 varying vec2 v_texCoord; |
| 524 uniform sampler2D s_texture; |
| 525 uniform float alpha; |
| 526 uniform vec4 fragmentTexTransform; |
| 527 uniform vec3 edge[8]; |
| 528 void main() |
| 529 { |
| 530 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; |
| 531 vec4 texColor = texture2D(s_texture, texCoord); |
| 532 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 533 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 534 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 535 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 536 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 537 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 538 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 539 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 540 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| 541 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)); |
| 542 } |
| 543 ); |
| 544 } |
| 545 |
| 546 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() |
| 547 : m_samplerLocation(-1) |
| 548 , m_maskSamplerLocation(-1) |
| 549 , m_alphaLocation(-1) |
| 550 { |
| 551 } |
| 552 |
| 553 void FragmentShaderRGBATexAlphaMask::init(WebGraphicsContext3D* context, unsigne
d program) |
| 554 { |
| 555 m_samplerLocation = context->getUniformLocation(program, "s_texture"); |
| 556 m_maskSamplerLocation = context->getUniformLocation(program, "s_mask"); |
| 557 m_alphaLocation = context->getUniformLocation(program, "alpha"); |
| 558 ASSERT(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1); |
| 559 } |
| 560 |
| 561 String FragmentShaderRGBATexAlphaMask::getShaderString() const |
| 562 { |
| 563 return SHADER( |
| 564 precision mediump float; |
| 565 varying vec2 v_texCoord; |
| 566 uniform sampler2D s_texture; |
| 567 uniform sampler2D s_mask; |
| 568 uniform float alpha; |
| 569 void main() |
| 570 { |
| 571 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 572 vec4 maskColor = texture2D(s_mask, v_texCoord); |
| 573 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha * maskColor.w; |
| 574 } |
| 575 ); |
| 576 } |
| 577 |
| 578 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
| 579 : m_samplerLocation(-1) |
| 580 , m_maskSamplerLocation(-1) |
| 581 , m_alphaLocation(-1) |
| 582 , m_edgeLocation(-1) |
| 583 { |
| 584 } |
| 585 |
| 586 void FragmentShaderRGBATexAlphaMaskAA::init(WebGraphicsContext3D* context, unsig
ned program) |
| 587 { |
| 588 m_samplerLocation = context->getUniformLocation(program, "s_texture"); |
| 589 m_maskSamplerLocation = context->getUniformLocation(program, "s_mask"); |
| 590 m_alphaLocation = context->getUniformLocation(program, "alpha"); |
| 591 m_edgeLocation = context->getUniformLocation(program, "edge"); |
| 592 ASSERT(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1 && m_edgeLocation != -1); |
| 593 } |
| 594 |
| 595 String FragmentShaderRGBATexAlphaMaskAA::getShaderString() const |
| 596 { |
| 597 return SHADER( |
| 598 precision mediump float; |
| 599 varying vec2 v_texCoord; |
| 600 uniform sampler2D s_texture; |
| 601 uniform sampler2D s_mask; |
| 602 uniform float alpha; |
| 603 uniform vec3 edge[8]; |
| 604 void main() |
| 605 { |
| 606 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 607 vec4 maskColor = texture2D(s_mask, v_texCoord); |
| 608 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 609 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 610 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 611 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 612 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 613 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 614 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 615 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 616 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| 617 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)
); |
| 618 } |
| 619 ); |
| 620 } |
| 621 |
| 622 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
| 623 : m_yTextureLocation(-1) |
| 624 , m_uTextureLocation(-1) |
| 625 , m_vTextureLocation(-1) |
| 626 , m_alphaLocation(-1) |
| 627 , m_ccMatrixLocation(-1) |
| 628 , m_yuvAdjLocation(-1) |
| 629 { |
| 630 } |
| 631 |
| 632 void FragmentShaderYUVVideo::init(WebGraphicsContext3D* context, unsigned progra
m) |
| 633 { |
| 634 m_yTextureLocation = context->getUniformLocation(program, "y_texture"); |
| 635 m_uTextureLocation = context->getUniformLocation(program, "u_texture"); |
| 636 m_vTextureLocation = context->getUniformLocation(program, "v_texture"); |
| 637 m_alphaLocation = context->getUniformLocation(program, "alpha"); |
| 638 m_ccMatrixLocation = context->getUniformLocation(program, "cc_matrix"); |
| 639 m_yuvAdjLocation = context->getUniformLocation(program, "yuv_adj"); |
| 640 |
| 641 ASSERT(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc
ation != -1 |
| 642 && m_alphaLocation != -1 && m_ccMatrixLocation != -1 && m_yuvAdjLocat
ion != -1); |
| 643 } |
| 644 |
| 645 String FragmentShaderYUVVideo::getShaderString() const |
| 646 { |
| 647 return SHADER( |
| 648 precision mediump float; |
| 649 precision mediump int; |
| 650 varying vec2 y_texCoord; |
| 651 varying vec2 uv_texCoord; |
| 652 uniform sampler2D y_texture; |
| 653 uniform sampler2D u_texture; |
| 654 uniform sampler2D v_texture; |
| 655 uniform float alpha; |
| 656 uniform vec3 yuv_adj; |
| 657 uniform mat3 cc_matrix; |
| 658 void main() |
| 659 { |
| 660 float y_raw = texture2D(y_texture, y_texCoord).x; |
| 661 float u_unsigned = texture2D(u_texture, uv_texCoord).x; |
| 662 float v_unsigned = texture2D(v_texture, uv_texCoord).x; |
| 663 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
| 664 vec3 rgb = cc_matrix * yuv; |
| 665 gl_FragColor = vec4(rgb, float(1)) * alpha; |
| 666 } |
| 667 ); |
| 668 } |
| 669 |
| 670 FragmentShaderColor::FragmentShaderColor() |
| 671 : m_colorLocation(-1) |
| 672 { |
| 673 } |
| 674 |
| 675 void FragmentShaderColor::init(WebGraphicsContext3D* context, unsigned program) |
| 676 { |
| 677 m_colorLocation = context->getUniformLocation(program, "color"); |
| 678 ASSERT(m_colorLocation != -1); |
| 679 } |
| 680 |
| 681 String FragmentShaderColor::getShaderString() const |
| 682 { |
| 683 return SHADER( |
| 684 precision mediump float; |
| 685 uniform vec4 color; |
| 686 void main() |
| 687 { |
| 688 gl_FragColor = color; |
| 689 } |
| 690 ); |
| 691 } |
| 692 |
| 693 FragmentShaderCheckerboard::FragmentShaderCheckerboard() |
| 694 : m_alphaLocation(-1) |
| 695 , m_texTransformLocation(-1) |
| 696 , m_frequencyLocation(-1) |
| 697 { |
| 698 } |
| 699 |
| 700 void FragmentShaderCheckerboard::init(WebGraphicsContext3D* context, unsigned pr
ogram) |
| 701 { |
| 702 m_alphaLocation = context->getUniformLocation(program, "alpha"); |
| 703 m_texTransformLocation = context->getUniformLocation(program, "texTransform"
); |
| 704 m_frequencyLocation = context->getUniformLocation(program, "frequency"); |
| 705 ASSERT(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL
ocation != -1); |
| 706 } |
| 707 |
| 708 String FragmentShaderCheckerboard::getShaderString() const |
| 709 { |
| 710 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
| 711 // by Munshi, Ginsburg, Shreiner. |
| 712 return SHADER( |
| 713 precision mediump float; |
| 714 precision mediump int; |
| 715 varying vec2 v_texCoord; |
| 716 uniform float alpha; |
| 717 uniform float frequency; |
| 718 uniform vec4 texTransform; |
| 719 void main() |
| 720 { |
| 721 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
| 722 vec4 color2 = vec4(0.945, 0.945, 0.945, 1.0); |
| 723 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; |
| 724 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 725 float picker = abs(coord.x - coord.y); |
| 726 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 727 } |
| 728 ); |
| 729 } |
| 730 |
| 731 } // namespace WebCore |
| 732 |
| 733 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |