| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #if USE(ACCELERATED_COMPOSITING) | 7 #if USE(ACCELERATED_COMPOSITING) |
| 8 | 8 |
| 9 #include "ShaderChromium.h" | 9 #include "ShaderChromium.h" |
| 10 | 10 |
| 11 #include <public/WebGraphicsContext3D.h> | 11 #include <public/WebGraphicsContext3D.h> |
| 12 #include <wtf/StdLibExtras.h> |
| 12 | 13 |
| 13 #define SHADER0(Src) #Src | 14 #define SHADER0(Src) #Src |
| 14 #define SHADER(Src) SHADER0(Src) | 15 #define SHADER(Src) SHADER0(Src) |
| 15 | 16 |
| 16 using WebKit::WebGraphicsContext3D; | 17 using WebKit::WebGraphicsContext3D; |
| 17 | 18 |
| 18 namespace WebCore { | 19 namespace WebCore { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 45 "matrix", | 46 "matrix", |
| 46 }; | 47 }; |
| 47 int locations[1]; | 48 int locations[1]; |
| 48 | 49 |
| 49 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 50 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 50 | 51 |
| 51 m_matrixLocation = locations[0]; | 52 m_matrixLocation = locations[0]; |
| 52 ASSERT(m_matrixLocation != -1); | 53 ASSERT(m_matrixLocation != -1); |
| 53 } | 54 } |
| 54 | 55 |
| 55 String VertexShaderPosTex::getShaderString() const | 56 std::string VertexShaderPosTex::getShaderString() const |
| 56 { | 57 { |
| 57 return SHADER( | 58 return SHADER( |
| 58 attribute vec4 a_position; | 59 attribute vec4 a_position; |
| 59 attribute vec2 a_texCoord; | 60 attribute vec2 a_texCoord; |
| 60 uniform mat4 matrix; | 61 uniform mat4 matrix; |
| 61 varying vec2 v_texCoord; | 62 varying vec2 v_texCoord; |
| 62 void main() | 63 void main() |
| 63 { | 64 { |
| 64 gl_Position = matrix * a_position; | 65 gl_Position = matrix * a_position; |
| 65 v_texCoord = a_texCoord; | 66 v_texCoord = a_texCoord; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 84 int locations[3]; | 85 int locations[3]; |
| 85 | 86 |
| 86 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 87 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 87 | 88 |
| 88 m_matrixLocation = locations[0]; | 89 m_matrixLocation = locations[0]; |
| 89 m_yWidthScaleFactorLocation = locations[1]; | 90 m_yWidthScaleFactorLocation = locations[1]; |
| 90 m_uvWidthScaleFactorLocation = locations[2]; | 91 m_uvWidthScaleFactorLocation = locations[2]; |
| 91 ASSERT(m_matrixLocation != -1 && m_yWidthScaleFactorLocation != -1 && m_uvWi
dthScaleFactorLocation != -1); | 92 ASSERT(m_matrixLocation != -1 && m_yWidthScaleFactorLocation != -1 && m_uvWi
dthScaleFactorLocation != -1); |
| 92 } | 93 } |
| 93 | 94 |
| 94 String VertexShaderPosTexYUVStretch::getShaderString() const | 95 std::string VertexShaderPosTexYUVStretch::getShaderString() const |
| 95 { | 96 { |
| 96 return SHADER( | 97 return SHADER( |
| 97 precision mediump float; | 98 precision mediump float; |
| 98 attribute vec4 a_position; | 99 attribute vec4 a_position; |
| 99 attribute vec2 a_texCoord; | 100 attribute vec2 a_texCoord; |
| 100 uniform mat4 matrix; | 101 uniform mat4 matrix; |
| 101 varying vec2 y_texCoord; | 102 varying vec2 y_texCoord; |
| 102 varying vec2 uv_texCoord; | 103 varying vec2 uv_texCoord; |
| 103 uniform float y_widthScaleFactor; | 104 uniform float y_widthScaleFactor; |
| 104 uniform float uv_widthScaleFactor; | 105 uniform float uv_widthScaleFactor; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 122 "matrix", | 123 "matrix", |
| 123 }; | 124 }; |
| 124 int locations[1]; | 125 int locations[1]; |
| 125 | 126 |
| 126 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 127 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 127 | 128 |
| 128 m_matrixLocation = locations[0]; | 129 m_matrixLocation = locations[0]; |
| 129 ASSERT(m_matrixLocation != -1); | 130 ASSERT(m_matrixLocation != -1); |
| 130 } | 131 } |
| 131 | 132 |
| 132 String VertexShaderPos::getShaderString() const | 133 std::string VertexShaderPos::getShaderString() const |
| 133 { | 134 { |
| 134 return SHADER( | 135 return SHADER( |
| 135 attribute vec4 a_position; | 136 attribute vec4 a_position; |
| 136 uniform mat4 matrix; | 137 uniform mat4 matrix; |
| 137 void main() | 138 void main() |
| 138 { | 139 { |
| 139 gl_Position = matrix * a_position; | 140 gl_Position = matrix * a_position; |
| 140 } | 141 } |
| 141 ); | 142 ); |
| 142 } | 143 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 155 }; | 156 }; |
| 156 int locations[2]; | 157 int locations[2]; |
| 157 | 158 |
| 158 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 159 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 159 | 160 |
| 160 m_matrixLocation = locations[0]; | 161 m_matrixLocation = locations[0]; |
| 161 m_texTransformLocation = locations[1]; | 162 m_texTransformLocation = locations[1]; |
| 162 ASSERT(m_matrixLocation != -1 && m_texTransformLocation != -1); | 163 ASSERT(m_matrixLocation != -1 && m_texTransformLocation != -1); |
| 163 } | 164 } |
| 164 | 165 |
| 165 String VertexShaderPosTexTransform::getShaderString() const | 166 std::string VertexShaderPosTexTransform::getShaderString() const |
| 166 { | 167 { |
| 167 return SHADER( | 168 return SHADER( |
| 168 attribute vec4 a_position; | 169 attribute vec4 a_position; |
| 169 attribute vec2 a_texCoord; | 170 attribute vec2 a_texCoord; |
| 170 uniform mat4 matrix; | 171 uniform mat4 matrix; |
| 171 uniform vec4 texTransform; | 172 uniform vec4 texTransform; |
| 172 varying vec2 v_texCoord; | 173 varying vec2 v_texCoord; |
| 173 void main() | 174 void main() |
| 174 { | 175 { |
| 175 gl_Position = matrix * a_position; | 176 gl_Position = matrix * a_position; |
| 176 v_texCoord = a_texCoord * texTransform.zw + texTransform.xy; | 177 v_texCoord = a_texCoord * texTransform.zw + texTransform.xy; |
| 177 } | 178 } |
| 178 ); | 179 ); |
| 179 } | 180 } |
| 180 | 181 |
| 181 VertexShaderQuad::VertexShaderQuad() | 182 VertexShaderQuad::VertexShaderQuad() |
| 182 : m_matrixLocation(-1) | 183 : m_matrixLocation(-1) |
| 183 , m_pointLocation(-1) | 184 , m_pointLocation(-1) |
| 184 { | 185 { |
| 185 } | 186 } |
| 186 | 187 |
| 187 String VertexShaderPosTexIdentity::getShaderString() const | 188 std::string VertexShaderPosTexIdentity::getShaderString() const |
| 188 { | 189 { |
| 189 return SHADER( | 190 return SHADER( |
| 190 attribute vec4 a_position; | 191 attribute vec4 a_position; |
| 191 varying vec2 v_texCoord; | 192 varying vec2 v_texCoord; |
| 192 void main() | 193 void main() |
| 193 { | 194 { |
| 194 gl_Position = a_position; | 195 gl_Position = a_position; |
| 195 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 196 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
| 196 } | 197 } |
| 197 ); | 198 ); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void VertexShaderQuad::init(WebGraphicsContext3D* context, unsigned program, boo
l usingBindUniform, int* baseUniformIndex) | 201 void VertexShaderQuad::init(WebGraphicsContext3D* context, unsigned program, boo
l usingBindUniform, int* baseUniformIndex) |
| 201 { | 202 { |
| 202 static const char* shaderUniforms[] = { | 203 static const char* shaderUniforms[] = { |
| 203 "matrix", | 204 "matrix", |
| 204 "point", | 205 "point", |
| 205 }; | 206 }; |
| 206 int locations[2]; | 207 int locations[2]; |
| 207 | 208 |
| 208 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 209 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 209 | 210 |
| 210 m_matrixLocation = locations[0]; | 211 m_matrixLocation = locations[0]; |
| 211 m_pointLocation = locations[1]; | 212 m_pointLocation = locations[1]; |
| 212 ASSERT(m_matrixLocation != -1 && m_pointLocation != -1); | 213 ASSERT(m_matrixLocation != -1 && m_pointLocation != -1); |
| 213 } | 214 } |
| 214 | 215 |
| 215 String VertexShaderQuad::getShaderString() const | 216 std::string VertexShaderQuad::getShaderString() const |
| 216 { | 217 { |
| 217 return SHADER( | 218 return SHADER( |
| 218 attribute vec4 a_position; | 219 attribute vec4 a_position; |
| 219 attribute vec2 a_texCoord; | 220 attribute vec2 a_texCoord; |
| 220 uniform mat4 matrix; | 221 uniform mat4 matrix; |
| 221 uniform vec2 point[4]; | 222 uniform vec2 point[4]; |
| 222 varying vec2 v_texCoord; | 223 varying vec2 v_texCoord; |
| 223 void main() | 224 void main() |
| 224 { | 225 { |
| 225 vec2 complement = abs(a_texCoord - 1.0); | 226 vec2 complement = abs(a_texCoord - 1.0); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 251 int locations[3]; | 252 int locations[3]; |
| 252 | 253 |
| 253 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 254 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 254 | 255 |
| 255 m_matrixLocation = locations[0]; | 256 m_matrixLocation = locations[0]; |
| 256 m_pointLocation = locations[1]; | 257 m_pointLocation = locations[1]; |
| 257 m_vertexTexTransformLocation = locations[2]; | 258 m_vertexTexTransformLocation = locations[2]; |
| 258 ASSERT(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo
rmLocation != -1); | 259 ASSERT(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo
rmLocation != -1); |
| 259 } | 260 } |
| 260 | 261 |
| 261 String VertexShaderTile::getShaderString() const | 262 std::string VertexShaderTile::getShaderString() const |
| 262 { | 263 { |
| 263 return SHADER( | 264 return SHADER( |
| 264 attribute vec4 a_position; | 265 attribute vec4 a_position; |
| 265 attribute vec2 a_texCoord; | 266 attribute vec2 a_texCoord; |
| 266 uniform mat4 matrix; | 267 uniform mat4 matrix; |
| 267 uniform vec2 point[4]; | 268 uniform vec2 point[4]; |
| 268 uniform vec4 vertexTexTransform; | 269 uniform vec4 vertexTexTransform; |
| 269 varying vec2 v_texCoord; | 270 varying vec2 v_texCoord; |
| 270 void main() | 271 void main() |
| 271 { | 272 { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 295 }; | 296 }; |
| 296 int locations[2]; | 297 int locations[2]; |
| 297 | 298 |
| 298 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 299 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 299 | 300 |
| 300 m_matrixLocation = locations[0]; | 301 m_matrixLocation = locations[0]; |
| 301 m_texMatrixLocation = locations[1]; | 302 m_texMatrixLocation = locations[1]; |
| 302 return m_matrixLocation != -1 && m_texMatrixLocation != -1; | 303 return m_matrixLocation != -1 && m_texMatrixLocation != -1; |
| 303 } | 304 } |
| 304 | 305 |
| 305 String VertexShaderVideoTransform::getShaderString() const | 306 std::string VertexShaderVideoTransform::getShaderString() const |
| 306 { | 307 { |
| 307 return SHADER( | 308 return SHADER( |
| 308 attribute vec4 a_position; | 309 attribute vec4 a_position; |
| 309 attribute vec2 a_texCoord; | 310 attribute vec2 a_texCoord; |
| 310 uniform mat4 matrix; | 311 uniform mat4 matrix; |
| 311 uniform mat4 texMatrix; | 312 uniform mat4 texMatrix; |
| 312 varying vec2 v_texCoord; | 313 varying vec2 v_texCoord; |
| 313 void main() | 314 void main() |
| 314 { | 315 { |
| 315 gl_Position = matrix * a_position; | 316 gl_Position = matrix * a_position; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 "s_texture", | 351 "s_texture", |
| 351 }; | 352 }; |
| 352 int locations[1]; | 353 int locations[1]; |
| 353 | 354 |
| 354 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 355 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 355 | 356 |
| 356 m_samplerLocation = locations[0]; | 357 m_samplerLocation = locations[0]; |
| 357 ASSERT(m_samplerLocation != -1); | 358 ASSERT(m_samplerLocation != -1); |
| 358 } | 359 } |
| 359 | 360 |
| 360 String FragmentShaderRGBATexFlipAlpha::getShaderString() const | 361 std::string FragmentShaderRGBATexFlipAlpha::getShaderString() const |
| 361 { | 362 { |
| 362 return SHADER( | 363 return SHADER( |
| 363 precision mediump float; | 364 precision mediump float; |
| 364 varying vec2 v_texCoord; | 365 varying vec2 v_texCoord; |
| 365 uniform sampler2D s_texture; | 366 uniform sampler2D s_texture; |
| 366 uniform float alpha; | 367 uniform float alpha; |
| 367 void main() | 368 void main() |
| 368 { | 369 { |
| 369 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC
oord.y)); | 370 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC
oord.y)); |
| 370 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha; | 371 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha; |
| 371 } | 372 } |
| 372 ); | 373 ); |
| 373 } | 374 } |
| 374 | 375 |
| 375 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) | 376 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) |
| 376 { | 377 { |
| 377 static const char* shaderUniforms[] = { | 378 static const char* shaderUniforms[] = { |
| 378 "s_texture", | 379 "s_texture", |
| 379 }; | 380 }; |
| 380 int locations[1]; | 381 int locations[1]; |
| 381 | 382 |
| 382 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 383 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 383 | 384 |
| 384 m_samplerLocation = locations[0]; | 385 m_samplerLocation = locations[0]; |
| 385 return m_samplerLocation != -1; | 386 return m_samplerLocation != -1; |
| 386 } | 387 } |
| 387 | 388 |
| 388 String FragmentShaderOESImageExternal::getShaderString() const | 389 std::string FragmentShaderOESImageExternal::getShaderString() const |
| 389 { | 390 { |
| 390 // Cannot use the SHADER() macro because of the '#' char | 391 // Cannot use the SHADER() macro because of the '#' char |
| 391 return "#extension GL_OES_EGL_image_external : require \n" | 392 return "#extension GL_OES_EGL_image_external : require \n" |
| 392 "precision mediump float;\n" | 393 "precision mediump float;\n" |
| 393 "varying vec2 v_texCoord;\n" | 394 "varying vec2 v_texCoord;\n" |
| 394 "uniform samplerExternalOES s_texture;\n" | 395 "uniform samplerExternalOES s_texture;\n" |
| 395 "void main()\n" | 396 "void main()\n" |
| 396 "{\n" | 397 "{\n" |
| 397 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" | 398 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" |
| 398 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor
.w);\n" | 399 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor
.w);\n" |
| 399 "}\n"; | 400 "}\n"; |
| 400 } | 401 } |
| 401 | 402 |
| 402 String FragmentShaderRGBATexAlpha::getShaderString() const | 403 std::string FragmentShaderRGBATexAlpha::getShaderString() const |
| 403 { | 404 { |
| 404 return SHADER( | 405 return SHADER( |
| 405 precision mediump float; | 406 precision mediump float; |
| 406 varying vec2 v_texCoord; | 407 varying vec2 v_texCoord; |
| 407 uniform sampler2D s_texture; | 408 uniform sampler2D s_texture; |
| 408 uniform float alpha; | 409 uniform float alpha; |
| 409 void main() | 410 void main() |
| 410 { | 411 { |
| 411 vec4 texColor = texture2D(s_texture, v_texCoord); | 412 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 412 gl_FragColor = texColor * alpha; | 413 gl_FragColor = texColor * alpha; |
| 413 } | 414 } |
| 414 ); | 415 ); |
| 415 } | 416 } |
| 416 | 417 |
| 417 String FragmentShaderRGBATexRectFlipAlpha::getShaderString() const | 418 std::string FragmentShaderRGBATexRectFlipAlpha::getShaderString() const |
| 418 { | 419 { |
| 419 // This must be paired with VertexShaderPosTexTransform to pick up the texTr
ansform uniform. | 420 // This must be paired with VertexShaderPosTexTransform to pick up the texTr
ansform uniform. |
| 420 // The necessary #extension preprocessing directive breaks the SHADER and SH
ADER0 macros. | 421 // The necessary #extension preprocessing directive breaks the SHADER and SH
ADER0 macros. |
| 421 return "#extension GL_ARB_texture_rectangle : require\n" | 422 return "#extension GL_ARB_texture_rectangle : require\n" |
| 422 "precision mediump float;\n" | 423 "precision mediump float;\n" |
| 423 "varying vec2 v_texCoord;\n" | 424 "varying vec2 v_texCoord;\n" |
| 424 "uniform vec4 texTransform;\n" | 425 "uniform vec4 texTransform;\n" |
| 425 "uniform sampler2DRect s_texture;\n" | 426 "uniform sampler2DRect s_texture;\n" |
| 426 "uniform float alpha;\n" | 427 "uniform float alpha;\n" |
| 427 "void main()\n" | 428 "void main()\n" |
| 428 "{\n" | 429 "{\n" |
| 429 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex
Transform.w - v_texCoord.y));\n" | 430 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex
Transform.w - v_texCoord.y));\n" |
| 430 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo
r.w) * alpha;\n" | 431 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo
r.w) * alpha;\n" |
| 431 "}\n"; | 432 "}\n"; |
| 432 } | 433 } |
| 433 | 434 |
| 434 String FragmentShaderRGBATexRectAlpha::getShaderString() const | 435 std::string FragmentShaderRGBATexRectAlpha::getShaderString() const |
| 435 { | 436 { |
| 436 return "#extension GL_ARB_texture_rectangle : require\n" | 437 return "#extension GL_ARB_texture_rectangle : require\n" |
| 437 "precision mediump float;\n" | 438 "precision mediump float;\n" |
| 438 "varying vec2 v_texCoord;\n" | 439 "varying vec2 v_texCoord;\n" |
| 439 "uniform sampler2DRect s_texture;\n" | 440 "uniform sampler2DRect s_texture;\n" |
| 440 "uniform float alpha;\n" | 441 "uniform float alpha;\n" |
| 441 "void main()\n" | 442 "void main()\n" |
| 442 "{\n" | 443 "{\n" |
| 443 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | 444 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" |
| 444 " gl_FragColor = texColor * alpha;\n" | 445 " gl_FragColor = texColor * alpha;\n" |
| 445 "}\n"; | 446 "}\n"; |
| 446 } | 447 } |
| 447 | 448 |
| 448 String FragmentShaderRGBATexOpaque::getShaderString() const | 449 std::string FragmentShaderRGBATexOpaque::getShaderString() const |
| 449 { | 450 { |
| 450 return SHADER( | 451 return SHADER( |
| 451 precision mediump float; | 452 precision mediump float; |
| 452 varying vec2 v_texCoord; | 453 varying vec2 v_texCoord; |
| 453 uniform sampler2D s_texture; | 454 uniform sampler2D s_texture; |
| 454 void main() | 455 void main() |
| 455 { | 456 { |
| 456 vec4 texColor = texture2D(s_texture, v_texCoord); | 457 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 457 gl_FragColor = vec4(texColor.rgb, 1.0); | 458 gl_FragColor = vec4(texColor.rgb, 1.0); |
| 458 } | 459 } |
| 459 ); | 460 ); |
| 460 } | 461 } |
| 461 | 462 |
| 462 String FragmentShaderRGBATex::getShaderString() const | 463 std::string FragmentShaderRGBATex::getShaderString() const |
| 463 { | 464 { |
| 464 return SHADER( | 465 return SHADER( |
| 465 precision mediump float; | 466 precision mediump float; |
| 466 varying vec2 v_texCoord; | 467 varying vec2 v_texCoord; |
| 467 uniform sampler2D s_texture; | 468 uniform sampler2D s_texture; |
| 468 void main() | 469 void main() |
| 469 { | 470 { |
| 470 gl_FragColor = texture2D(s_texture, v_texCoord); | 471 gl_FragColor = texture2D(s_texture, v_texCoord); |
| 471 } | 472 } |
| 472 ); | 473 ); |
| 473 } | 474 } |
| 474 | 475 |
| 475 String FragmentShaderRGBATexSwizzleAlpha::getShaderString() const | 476 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const |
| 476 { | 477 { |
| 477 return SHADER( | 478 return SHADER( |
| 478 precision mediump float; | 479 precision mediump float; |
| 479 varying vec2 v_texCoord; | 480 varying vec2 v_texCoord; |
| 480 uniform sampler2D s_texture; | 481 uniform sampler2D s_texture; |
| 481 uniform float alpha; | 482 uniform float alpha; |
| 482 void main() | 483 void main() |
| 483 { | 484 { |
| 484 vec4 texColor = texture2D(s_texture, v_texCoord); | 485 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 485 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w)
* alpha; | 486 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w)
* alpha; |
| 486 } | 487 } |
| 487 ); | 488 ); |
| 488 } | 489 } |
| 489 | 490 |
| 490 String FragmentShaderRGBATexSwizzleOpaque::getShaderString() const | 491 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const |
| 491 { | 492 { |
| 492 return SHADER( | 493 return SHADER( |
| 493 precision mediump float; | 494 precision mediump float; |
| 494 varying vec2 v_texCoord; | 495 varying vec2 v_texCoord; |
| 495 uniform sampler2D s_texture; | 496 uniform sampler2D s_texture; |
| 496 void main() | 497 void main() |
| 497 { | 498 { |
| 498 vec4 texColor = texture2D(s_texture, v_texCoord); | 499 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 499 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 500 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
| 500 } | 501 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 518 int locations[3]; | 519 int locations[3]; |
| 519 | 520 |
| 520 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 521 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 521 | 522 |
| 522 m_samplerLocation = locations[0]; | 523 m_samplerLocation = locations[0]; |
| 523 m_alphaLocation = locations[1]; | 524 m_alphaLocation = locations[1]; |
| 524 m_edgeLocation = locations[2]; | 525 m_edgeLocation = locations[2]; |
| 525 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation !=
-1); | 526 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation !=
-1); |
| 526 } | 527 } |
| 527 | 528 |
| 528 String FragmentShaderRGBATexAlphaAA::getShaderString() const | 529 std::string FragmentShaderRGBATexAlphaAA::getShaderString() const |
| 529 { | 530 { |
| 530 return SHADER( | 531 return SHADER( |
| 531 precision mediump float; | 532 precision mediump float; |
| 532 varying vec2 v_texCoord; | 533 varying vec2 v_texCoord; |
| 533 uniform sampler2D s_texture; | 534 uniform sampler2D s_texture; |
| 534 uniform float alpha; | 535 uniform float alpha; |
| 535 uniform vec3 edge[8]; | 536 uniform vec3 edge[8]; |
| 536 void main() | 537 void main() |
| 537 { | 538 { |
| 538 vec4 texColor = texture2D(s_texture, v_texCoord); | 539 vec4 texColor = texture2D(s_texture, v_texCoord); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 | 571 |
| 571 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 572 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 572 | 573 |
| 573 m_samplerLocation = locations[0]; | 574 m_samplerLocation = locations[0]; |
| 574 m_alphaLocation = locations[1]; | 575 m_alphaLocation = locations[1]; |
| 575 m_fragmentTexTransformLocation = locations[2]; | 576 m_fragmentTexTransformLocation = locations[2]; |
| 576 m_edgeLocation = locations[3]; | 577 m_edgeLocation = locations[3]; |
| 577 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran
sformLocation != -1 && m_edgeLocation != -1); | 578 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran
sformLocation != -1 && m_edgeLocation != -1); |
| 578 } | 579 } |
| 579 | 580 |
| 580 String FragmentShaderRGBATexClampAlphaAA::getShaderString() const | 581 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString() const |
| 581 { | 582 { |
| 582 return SHADER( | 583 return SHADER( |
| 583 precision mediump float; | 584 precision mediump float; |
| 584 varying vec2 v_texCoord; | 585 varying vec2 v_texCoord; |
| 585 uniform sampler2D s_texture; | 586 uniform sampler2D s_texture; |
| 586 uniform float alpha; | 587 uniform float alpha; |
| 587 uniform vec4 fragmentTexTransform; | 588 uniform vec4 fragmentTexTransform; |
| 588 uniform vec3 edge[8]; | 589 uniform vec3 edge[8]; |
| 589 void main() | 590 void main() |
| 590 { | 591 { |
| 591 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; | 592 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; |
| 592 vec4 texColor = texture2D(s_texture, texCoord); | 593 vec4 texColor = texture2D(s_texture, texCoord); |
| 593 vec3 pos = vec3(gl_FragCoord.xy, 1); | 594 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 594 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 595 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 595 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 596 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 596 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 597 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 597 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 598 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 598 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 599 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 599 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 600 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 600 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 601 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 601 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 602 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| 602 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min
(a4, a6) * min(a5, a7)); | 603 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min
(a4, a6) * min(a5, a7)); |
| 603 } | 604 } |
| 604 ); | 605 ); |
| 605 } | 606 } |
| 606 | 607 |
| 607 String FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const | 608 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const |
| 608 { | 609 { |
| 609 return SHADER( | 610 return SHADER( |
| 610 precision mediump float; | 611 precision mediump float; |
| 611 varying vec2 v_texCoord; | 612 varying vec2 v_texCoord; |
| 612 uniform sampler2D s_texture; | 613 uniform sampler2D s_texture; |
| 613 uniform float alpha; | 614 uniform float alpha; |
| 614 uniform vec4 fragmentTexTransform; | 615 uniform vec4 fragmentTexTransform; |
| 615 uniform vec3 edge[8]; | 616 uniform vec3 edge[8]; |
| 616 void main() | 617 void main() |
| 617 { | 618 { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 654 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 654 | 655 |
| 655 m_samplerLocation = locations[0]; | 656 m_samplerLocation = locations[0]; |
| 656 m_maskSamplerLocation = locations[1]; | 657 m_maskSamplerLocation = locations[1]; |
| 657 m_alphaLocation = locations[2]; | 658 m_alphaLocation = locations[2]; |
| 658 m_maskTexCoordScaleLocation = locations[3]; | 659 m_maskTexCoordScaleLocation = locations[3]; |
| 659 m_maskTexCoordOffsetLocation = locations[4]; | 660 m_maskTexCoordOffsetLocation = locations[4]; |
| 660 ASSERT(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1); | 661 ASSERT(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1); |
| 661 } | 662 } |
| 662 | 663 |
| 663 String FragmentShaderRGBATexAlphaMask::getShaderString() const | 664 std::string FragmentShaderRGBATexAlphaMask::getShaderString() const |
| 664 { | 665 { |
| 665 return SHADER( | 666 return SHADER( |
| 666 precision mediump float; | 667 precision mediump float; |
| 667 varying vec2 v_texCoord; | 668 varying vec2 v_texCoord; |
| 668 uniform sampler2D s_texture; | 669 uniform sampler2D s_texture; |
| 669 uniform sampler2D s_mask; | 670 uniform sampler2D s_mask; |
| 670 uniform vec2 maskTexCoordScale; | 671 uniform vec2 maskTexCoordScale; |
| 671 uniform vec2 maskTexCoordOffset; | 672 uniform vec2 maskTexCoordOffset; |
| 672 uniform float alpha; | 673 uniform float alpha; |
| 673 void main() | 674 void main() |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 | 706 |
| 706 m_samplerLocation = locations[0]; | 707 m_samplerLocation = locations[0]; |
| 707 m_maskSamplerLocation = locations[1]; | 708 m_maskSamplerLocation = locations[1]; |
| 708 m_alphaLocation = locations[2]; | 709 m_alphaLocation = locations[2]; |
| 709 m_edgeLocation = locations[3]; | 710 m_edgeLocation = locations[3]; |
| 710 m_maskTexCoordScaleLocation = locations[4]; | 711 m_maskTexCoordScaleLocation = locations[4]; |
| 711 m_maskTexCoordOffsetLocation = locations[5]; | 712 m_maskTexCoordOffsetLocation = locations[5]; |
| 712 ASSERT(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1 && m_edgeLocation != -1); | 713 ASSERT(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1 && m_edgeLocation != -1); |
| 713 } | 714 } |
| 714 | 715 |
| 715 String FragmentShaderRGBATexAlphaMaskAA::getShaderString() const | 716 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString() const |
| 716 { | 717 { |
| 717 return SHADER( | 718 return SHADER( |
| 718 precision mediump float; | 719 precision mediump float; |
| 719 varying vec2 v_texCoord; | 720 varying vec2 v_texCoord; |
| 720 uniform sampler2D s_texture; | 721 uniform sampler2D s_texture; |
| 721 uniform sampler2D s_mask; | 722 uniform sampler2D s_mask; |
| 722 uniform vec2 maskTexCoordScale; | 723 uniform vec2 maskTexCoordScale; |
| 723 uniform vec2 maskTexCoordOffset; | 724 uniform vec2 maskTexCoordOffset; |
| 724 uniform float alpha; | 725 uniform float alpha; |
| 725 uniform vec3 edge[8]; | 726 uniform vec3 edge[8]; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 m_uTextureLocation = locations[1]; | 771 m_uTextureLocation = locations[1]; |
| 771 m_vTextureLocation = locations[2]; | 772 m_vTextureLocation = locations[2]; |
| 772 m_alphaLocation = locations[3]; | 773 m_alphaLocation = locations[3]; |
| 773 m_ccMatrixLocation = locations[4]; | 774 m_ccMatrixLocation = locations[4]; |
| 774 m_yuvAdjLocation = locations[5]; | 775 m_yuvAdjLocation = locations[5]; |
| 775 | 776 |
| 776 ASSERT(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc
ation != -1 | 777 ASSERT(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc
ation != -1 |
| 777 && m_alphaLocation != -1 && m_ccMatrixLocation != -1 && m_yuvAdjLocat
ion != -1); | 778 && m_alphaLocation != -1 && m_ccMatrixLocation != -1 && m_yuvAdjLocat
ion != -1); |
| 778 } | 779 } |
| 779 | 780 |
| 780 String FragmentShaderYUVVideo::getShaderString() const | 781 std::string FragmentShaderYUVVideo::getShaderString() const |
| 781 { | 782 { |
| 782 return SHADER( | 783 return SHADER( |
| 783 precision mediump float; | 784 precision mediump float; |
| 784 precision mediump int; | 785 precision mediump int; |
| 785 varying vec2 y_texCoord; | 786 varying vec2 y_texCoord; |
| 786 varying vec2 uv_texCoord; | 787 varying vec2 uv_texCoord; |
| 787 uniform sampler2D y_texture; | 788 uniform sampler2D y_texture; |
| 788 uniform sampler2D u_texture; | 789 uniform sampler2D u_texture; |
| 789 uniform sampler2D v_texture; | 790 uniform sampler2D v_texture; |
| 790 uniform float alpha; | 791 uniform float alpha; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 813 "color", | 814 "color", |
| 814 }; | 815 }; |
| 815 int locations[1]; | 816 int locations[1]; |
| 816 | 817 |
| 817 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 818 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 818 | 819 |
| 819 m_colorLocation = locations[0]; | 820 m_colorLocation = locations[0]; |
| 820 ASSERT(m_colorLocation != -1); | 821 ASSERT(m_colorLocation != -1); |
| 821 } | 822 } |
| 822 | 823 |
| 823 String FragmentShaderColor::getShaderString() const | 824 std::string FragmentShaderColor::getShaderString() const |
| 824 { | 825 { |
| 825 return SHADER( | 826 return SHADER( |
| 826 precision mediump float; | 827 precision mediump float; |
| 827 uniform vec4 color; | 828 uniform vec4 color; |
| 828 void main() | 829 void main() |
| 829 { | 830 { |
| 830 gl_FragColor = color; | 831 gl_FragColor = color; |
| 831 } | 832 } |
| 832 ); | 833 ); |
| 833 } | 834 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 849 int locations[3]; | 850 int locations[3]; |
| 850 | 851 |
| 851 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); | 852 getProgramUniformLocations(context, program, shaderUniforms, WTF_ARRAY_LENGT
H(shaderUniforms), WTF_ARRAY_LENGTH(locations), locations, usingBindUniform, bas
eUniformIndex); |
| 852 | 853 |
| 853 m_alphaLocation = locations[0]; | 854 m_alphaLocation = locations[0]; |
| 854 m_texTransformLocation = locations[1]; | 855 m_texTransformLocation = locations[1]; |
| 855 m_frequencyLocation = locations[2]; | 856 m_frequencyLocation = locations[2]; |
| 856 ASSERT(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL
ocation != -1); | 857 ASSERT(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL
ocation != -1); |
| 857 } | 858 } |
| 858 | 859 |
| 859 String FragmentShaderCheckerboard::getShaderString() const | 860 std::string FragmentShaderCheckerboard::getShaderString() const |
| 860 { | 861 { |
| 861 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | 862 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
| 862 // by Munshi, Ginsburg, Shreiner. | 863 // by Munshi, Ginsburg, Shreiner. |
| 863 return SHADER( | 864 return SHADER( |
| 864 precision mediump float; | 865 precision mediump float; |
| 865 precision mediump int; | 866 precision mediump int; |
| 866 varying vec2 v_texCoord; | 867 varying vec2 v_texCoord; |
| 867 uniform float alpha; | 868 uniform float alpha; |
| 868 uniform float frequency; | 869 uniform float frequency; |
| 869 uniform vec4 texTransform; | 870 uniform vec4 texTransform; |
| 870 void main() | 871 void main() |
| 871 { | 872 { |
| 872 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | 873 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
| 873 vec4 color2 = vec4(0.945, 0.945, 0.945, 1.0); | 874 vec4 color2 = vec4(0.945, 0.945, 0.945, 1.0); |
| 874 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; | 875 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; |
| 875 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 876 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 876 float picker = abs(coord.x - coord.y); | 877 float picker = abs(coord.x - coord.y); |
| 877 gl_FragColor = mix(color1, color2, picker) * alpha; | 878 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 878 } | 879 } |
| 879 ); | 880 ); |
| 880 } | 881 } |
| 881 | 882 |
| 882 } // namespace WebCore | 883 } // namespace WebCore |
| 883 | 884 |
| 884 #endif // USE(ACCELERATED_COMPOSITING) | 885 #endif // USE(ACCELERATED_COMPOSITING) |
| OLD | NEW |