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 "cc/output/shader.h" | 5 #include "cc/output/shader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 float y_raw = texture2D(y_texture, v_texCoord).x; | 1348 float y_raw = texture2D(y_texture, v_texCoord).x; |
1349 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 1349 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
1350 float v_unsigned = texture2D(v_texture, v_texCoord).x; | 1350 float v_unsigned = texture2D(v_texture, v_texCoord).x; |
1351 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 1351 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
1352 vec3 rgb = yuv_matrix * yuv; | 1352 vec3 rgb = yuv_matrix * yuv; |
1353 gl_FragColor = vec4(rgb, float(1)) * alpha; // NOLINT | 1353 gl_FragColor = vec4(rgb, float(1)) * alpha; // NOLINT |
1354 } | 1354 } |
1355 ); // NOLINT(whitespace/parens) | 1355 ); // NOLINT(whitespace/parens) |
1356 } | 1356 } |
1357 | 1357 |
| 1358 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() |
| 1359 : y_texture_location_(-1), |
| 1360 u_texture_location_(-1), |
| 1361 v_texture_location_(-1), |
| 1362 a_texture_location_(-1), |
| 1363 alpha_location_(-1), |
| 1364 yuv_matrix_location_(-1), |
| 1365 yuv_adj_location_(-1) { |
| 1366 } |
| 1367 |
| 1368 void FragmentShaderYUVAVideo::Init(WebGraphicsContext3D* context, |
| 1369 unsigned program, |
| 1370 bool using_bind_uniform, |
| 1371 int* base_uniform_index) { |
| 1372 static const char* shader_uniforms[] = { |
| 1373 "y_texture", |
| 1374 "u_texture", |
| 1375 "v_texture", |
| 1376 "a_texture", |
| 1377 "alpha", |
| 1378 "cc_matrix", |
| 1379 "yuv_adj", |
| 1380 }; |
| 1381 int locations[7]; |
| 1382 |
| 1383 GetProgramUniformLocations(context, |
| 1384 program, |
| 1385 shader_uniforms, |
| 1386 arraysize(shader_uniforms), |
| 1387 arraysize(locations), |
| 1388 locations, |
| 1389 using_bind_uniform, |
| 1390 base_uniform_index); |
| 1391 |
| 1392 y_texture_location_ = locations[0]; |
| 1393 u_texture_location_ = locations[1]; |
| 1394 v_texture_location_ = locations[2]; |
| 1395 a_texture_location_ = locations[3]; |
| 1396 alpha_location_ = locations[4]; |
| 1397 yuv_matrix_location_ = locations[5]; |
| 1398 yuv_adj_location_ = locations[6]; |
| 1399 |
| 1400 DCHECK(y_texture_location_ != -1 && u_texture_location_ != -1 && |
| 1401 v_texture_location_ != -1 && a_texture_location_ != -1 && |
| 1402 alpha_location_ != -1 && yuv_matrix_location_ != -1 && |
| 1403 yuv_adj_location_ != -1); |
| 1404 } |
| 1405 |
| 1406 std::string FragmentShaderYUVAVideo::GetShaderString( |
| 1407 TexCoordPrecision precision) const { |
| 1408 return FRAGMENT_SHADER( |
| 1409 precision mediump float; |
| 1410 precision mediump int; |
| 1411 varying TexCoordPrecision vec2 v_texCoord; |
| 1412 uniform sampler2D y_texture; |
| 1413 uniform sampler2D u_texture; |
| 1414 uniform sampler2D v_texture; |
| 1415 uniform sampler2D a_texture; |
| 1416 uniform float alpha; |
| 1417 uniform vec3 yuv_adj; |
| 1418 uniform mat3 yuv_matrix; |
| 1419 void main() { |
| 1420 float y_raw = texture2D(y_texture, v_texCoord).x; |
| 1421 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
| 1422 float v_unsigned = texture2D(v_texture, v_texCoord).x; |
| 1423 float a_raw = texture2D(a_texture, v_texCoord).x; |
| 1424 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
| 1425 vec3 rgb = yuv_matrix * yuv; |
| 1426 gl_FragColor = vec4(rgb, a_raw) * alpha; |
| 1427 } |
| 1428 ); // NOLINT(whitespace/parens) |
| 1429 } |
| 1430 |
1358 FragmentShaderColor::FragmentShaderColor() | 1431 FragmentShaderColor::FragmentShaderColor() |
1359 : color_location_(-1) {} | 1432 : color_location_(-1) {} |
1360 | 1433 |
1361 void FragmentShaderColor::Init(WebGraphicsContext3D* context, | 1434 void FragmentShaderColor::Init(WebGraphicsContext3D* context, |
1362 unsigned program, | 1435 unsigned program, |
1363 bool using_bind_uniform, | 1436 bool using_bind_uniform, |
1364 int* base_uniform_index) { | 1437 int* base_uniform_index) { |
1365 static const char* shader_uniforms[] = { | 1438 static const char* shader_uniforms[] = { |
1366 "color", | 1439 "color", |
1367 }; | 1440 }; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 vec2 texCoord = | 1566 vec2 texCoord = |
1494 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 1567 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
1495 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1568 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1496 float picker = abs(coord.x - coord.y); | 1569 float picker = abs(coord.x - coord.y); |
1497 gl_FragColor = mix(color1, color2, picker) * alpha; | 1570 gl_FragColor = mix(color1, color2, picker) * alpha; |
1498 } | 1571 } |
1499 ); // NOLINT(whitespace/parens) | 1572 ); // NOLINT(whitespace/parens) |
1500 } | 1573 } |
1501 | 1574 |
1502 } // namespace cc | 1575 } // namespace cc |
OLD | NEW |