| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 return shader_string; | 137 return shader_string; |
| 138 default: | 138 default: |
| 139 NOTREACHED(); | 139 NOTREACHED(); |
| 140 break; | 140 break; |
| 141 } | 141 } |
| 142 return shader_string; | 142 return shader_string; |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace | 145 } // namespace |
| 146 | 146 |
| 147 ShaderLocations::ShaderLocations() { |
| 148 } |
| 149 |
| 147 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, | 150 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, |
| 148 int* highp_threshold_cache, | 151 int* highp_threshold_cache, |
| 149 int highp_threshold_min, | 152 int highp_threshold_min, |
| 150 const gfx::Point& max_coordinate) { | 153 const gfx::Point& max_coordinate) { |
| 151 return TexCoordPrecisionRequired(context, | 154 return TexCoordPrecisionRequired(context, |
| 152 highp_threshold_cache, | 155 highp_threshold_cache, |
| 153 highp_threshold_min, | 156 highp_threshold_min, |
| 154 max_coordinate.x(), | 157 max_coordinate.x(), |
| 155 max_coordinate.y()); | 158 max_coordinate.y()); |
| 156 } | 159 } |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 void main() { | 343 void main() { |
| 341 int quad_index = int(a_index * 0.25); // NOLINT | 344 int quad_index = int(a_index * 0.25); // NOLINT |
| 342 gl_Position = matrix[quad_index] * a_position; | 345 gl_Position = matrix[quad_index] * a_position; |
| 343 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; | 346 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; |
| 344 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 347 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 345 v_alpha = opacity[int(a_index)]; // NOLINT | 348 v_alpha = opacity[int(a_index)]; // NOLINT |
| 346 } | 349 } |
| 347 }); | 350 }); |
| 348 } | 351 } |
| 349 | 352 |
| 353 void VertexShaderPosTexTransform::FillLocations( |
| 354 ShaderLocations* locations) const { |
| 355 locations->matrix = matrix_location(); |
| 356 locations->tex_transform = tex_transform_location(); |
| 357 } |
| 358 |
| 350 std::string VertexShaderPosTexIdentity::GetShaderString() const { | 359 std::string VertexShaderPosTexIdentity::GetShaderString() const { |
| 351 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); | 360 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
| 352 } | 361 } |
| 353 | 362 |
| 354 std::string VertexShaderPosTexIdentity::GetShaderHead() { | 363 std::string VertexShaderPosTexIdentity::GetShaderHead() { |
| 355 return SHADER0([]() { | 364 return SHADER0([]() { |
| 356 attribute vec4 a_position; | 365 attribute vec4 a_position; |
| 357 varying TexCoordPrecision vec2 v_texCoord; | 366 varying TexCoordPrecision vec2 v_texCoord; |
| 358 }); | 367 }); |
| 359 } | 368 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 dot(edge[2], screen_pos), dot(edge[3], screen_pos)) * | 562 dot(edge[2], screen_pos), dot(edge[3], screen_pos)) * |
| 554 gl_Position.w; | 563 gl_Position.w; |
| 555 edge_dist[1] = vec4(dot(edge[4], screen_pos), dot(edge[5], screen_pos), | 564 edge_dist[1] = vec4(dot(edge[4], screen_pos), dot(edge[5], screen_pos), |
| 556 dot(edge[6], screen_pos), dot(edge[7], screen_pos)) * | 565 dot(edge[6], screen_pos), dot(edge[7], screen_pos)) * |
| 557 gl_Position.w; | 566 gl_Position.w; |
| 558 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy; | 567 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy; |
| 559 } | 568 } |
| 560 }); | 569 }); |
| 561 } | 570 } |
| 562 | 571 |
| 572 void VertexShaderQuadTexTransformAA::FillLocations( |
| 573 ShaderLocations* locations) const { |
| 574 locations->quad = quad_location(); |
| 575 locations->edge = edge_location(); |
| 576 locations->viewport = viewport_location(); |
| 577 locations->matrix = matrix_location(); |
| 578 locations->tex_transform = tex_transform_location(); |
| 579 } |
| 580 |
| 581 |
| 563 VertexShaderTile::VertexShaderTile() | 582 VertexShaderTile::VertexShaderTile() |
| 564 : matrix_location_(-1), | 583 : matrix_location_(-1), |
| 565 quad_location_(-1), | 584 quad_location_(-1), |
| 566 vertex_tex_transform_location_(-1) { | 585 vertex_tex_transform_location_(-1) { |
| 567 } | 586 } |
| 568 | 587 |
| 569 void VertexShaderTile::Init(GLES2Interface* context, | 588 void VertexShaderTile::Init(GLES2Interface* context, |
| 570 unsigned program, | 589 unsigned program, |
| 571 int* base_uniform_index) { | 590 int* base_uniform_index) { |
| 572 static const char* uniforms[] = { | 591 static const char* uniforms[] = { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 std::string VertexShaderVideoTransform::GetShaderBody() { | 734 std::string VertexShaderVideoTransform::GetShaderBody() { |
| 716 return SHADER0([]() { | 735 return SHADER0([]() { |
| 717 void main() { | 736 void main() { |
| 718 gl_Position = matrix * a_position; | 737 gl_Position = matrix * a_position; |
| 719 v_texCoord = | 738 v_texCoord = |
| 720 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 739 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
| 721 } | 740 } |
| 722 }); | 741 }); |
| 723 } | 742 } |
| 724 | 743 |
| 725 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" | 744 #define BLEND_MODE_UNIFORMS "s_backdropTexture", \ |
| 726 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 2 : 0) | 745 "s_originalBackdropTexture", \ |
| 746 "backdropRect" |
| 747 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 3 : 0) |
| 727 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ | 748 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ |
| 728 if (has_blend_mode()) { \ | 749 if (has_blend_mode()) { \ |
| 729 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ | 750 DCHECK_LT(static_cast<size_t>(POS) + 2, arraysize(X)); \ |
| 730 backdrop_location_ = locations[POS]; \ | 751 backdrop_location_ = locations[POS]; \ |
| 731 backdrop_rect_location_ = locations[POS + 1]; \ | 752 original_backdrop_location_ = locations[POS + 1]; \ |
| 753 backdrop_rect_location_ = locations[POS + 2]; \ |
| 732 } | 754 } |
| 733 | 755 |
| 734 FragmentTexBlendMode::FragmentTexBlendMode() | 756 FragmentTexBlendMode::FragmentTexBlendMode() |
| 735 : backdrop_location_(-1), | 757 : backdrop_location_(-1), |
| 758 original_backdrop_location_(-1), |
| 736 backdrop_rect_location_(-1), | 759 backdrop_rect_location_(-1), |
| 737 blend_mode_(BLEND_MODE_NONE) { | 760 blend_mode_(BLEND_MODE_NONE), |
| 761 mask_for_background_(false) { |
| 738 } | 762 } |
| 739 | 763 |
| 740 std::string FragmentTexBlendMode::SetBlendModeFunctions( | 764 std::string FragmentTexBlendMode::SetBlendModeFunctions( |
| 741 std::string shader_string) const { | 765 std::string shader_string) const { |
| 742 if (shader_string.find("ApplyBlendMode") == std::string::npos) | 766 if (shader_string.find("ApplyBlendMode") == std::string::npos) |
| 743 return shader_string; | 767 return shader_string; |
| 744 | 768 |
| 745 if (!has_blend_mode()) { | 769 if (!has_blend_mode()) { |
| 746 return "#define ApplyBlendMode(X) (X)\n" + shader_string; | 770 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; |
| 771 } |
| 772 |
| 773 static const std::string kUniforms = SHADER0([]() { |
| 774 uniform sampler2D s_backdropTexture; |
| 775 uniform sampler2D s_originalBackdropTexture; |
| 776 uniform TexCoordPrecision vec4 backdropRect; |
| 777 }); |
| 778 |
| 779 std::string mixFunction; |
| 780 if (mask_for_background()) { |
| 781 mixFunction = SHADER0([]() { |
| 782 vec4 MixBackdrop(TexCoordPrecision vec2 bgTexCoord, float mask) { |
| 783 vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord); |
| 784 vec4 original_backdrop = |
| 785 texture2D(s_originalBackdropTexture, bgTexCoord); |
| 786 return mix(original_backdrop, backdrop, mask); |
| 787 } |
| 788 }); |
| 789 } else { |
| 790 mixFunction = SHADER0([]() { |
| 791 vec4 MixBackdrop(TexCoordPrecision vec2 bgTexCoord, float mask) { |
| 792 return texture2D(s_backdropTexture, bgTexCoord); |
| 793 } |
| 794 }); |
| 747 } | 795 } |
| 748 | 796 |
| 749 static const std::string kFunctionApplyBlendMode = SHADER0([]() { | 797 static const std::string kFunctionApplyBlendMode = SHADER0([]() { |
| 750 uniform sampler2D s_backdropTexture; | 798 vec4 GetBackdropColor(float mask) { |
| 751 uniform TexCoordPrecision vec4 backdropRect; | |
| 752 | |
| 753 vec4 GetBackdropColor() { | |
| 754 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; | 799 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; |
| 755 bgTexCoord.x /= backdropRect.z; | 800 bgTexCoord.x /= backdropRect.z; |
| 756 bgTexCoord.y /= backdropRect.w; | 801 bgTexCoord.y /= backdropRect.w; |
| 757 return texture2D(s_backdropTexture, bgTexCoord); | 802 return MixBackdrop(bgTexCoord, mask); |
| 758 } | 803 } |
| 759 | 804 |
| 760 vec4 ApplyBlendMode(vec4 src) { | 805 vec4 ApplyBlendMode(vec4 src, float mask) { |
| 761 vec4 dst = GetBackdropColor(); | 806 vec4 dst = GetBackdropColor(mask); |
| 762 return Blend(src, dst); | 807 return Blend(src, dst); |
| 763 } | 808 } |
| 764 }); | 809 }); |
| 765 | 810 |
| 766 return "precision mediump float;" + GetHelperFunctions() + | 811 return "precision mediump float;" + GetHelperFunctions() + |
| 767 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; | 812 GetBlendFunction() + kUniforms + mixFunction + |
| 813 kFunctionApplyBlendMode + shader_string; |
| 768 } | 814 } |
| 769 | 815 |
| 770 std::string FragmentTexBlendMode::GetHelperFunctions() const { | 816 std::string FragmentTexBlendMode::GetHelperFunctions() const { |
| 771 static const std::string kFunctionHardLight = SHADER0([]() { | 817 static const std::string kFunctionHardLight = SHADER0([]() { |
| 772 vec3 hardLight(vec4 src, vec4 dst) { | 818 vec3 hardLight(vec4 src, vec4 dst) { |
| 773 vec3 result; | 819 vec3 result; |
| 774 result.r = | 820 result.r = |
| 775 (2.0 * src.r <= src.a) | 821 (2.0 * src.r <= src.a) |
| 776 ? (2.0 * src.r * dst.r) | 822 ? (2.0 * src.r * dst.r) |
| 777 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); | 823 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 varying TexCoordPrecision vec2 v_texCoord; | 1139 varying TexCoordPrecision vec2 v_texCoord; |
| 1094 uniform SamplerType s_texture; | 1140 uniform SamplerType s_texture; |
| 1095 uniform float alpha; | 1141 uniform float alpha; |
| 1096 }); | 1142 }); |
| 1097 } | 1143 } |
| 1098 | 1144 |
| 1099 std::string FragmentShaderRGBATexAlpha::GetShaderBody() { | 1145 std::string FragmentShaderRGBATexAlpha::GetShaderBody() { |
| 1100 return SHADER0([]() { | 1146 return SHADER0([]() { |
| 1101 void main() { | 1147 void main() { |
| 1102 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1148 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1103 gl_FragColor = ApplyBlendMode(texColor * alpha); | 1149 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); |
| 1104 } | 1150 } |
| 1105 }); | 1151 }); |
| 1106 } | 1152 } |
| 1107 | 1153 |
| 1154 void FragmentShaderRGBATexAlpha::FillLocations( |
| 1155 ShaderLocations* locations) const { |
| 1156 locations->sampler = sampler_location(); |
| 1157 locations->alpha = alpha_location(); |
| 1158 locations->backdrop = backdrop_location(); |
| 1159 locations->backdrop_rect = backdrop_rect_location(); |
| 1160 } |
| 1161 |
| 1108 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( | 1162 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( |
| 1109 TexCoordPrecision precision, | 1163 TexCoordPrecision precision, |
| 1110 SamplerType sampler) const { | 1164 SamplerType sampler) const { |
| 1111 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1165 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
| 1112 } | 1166 } |
| 1113 | 1167 |
| 1114 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderHead() { | 1168 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderHead() { |
| 1115 return SHADER0([]() { | 1169 return SHADER0([]() { |
| 1116 precision mediump float; | 1170 precision mediump float; |
| 1117 varying TexCoordPrecision vec2 v_texCoord; | 1171 varying TexCoordPrecision vec2 v_texCoord; |
| 1118 uniform SamplerType s_texture; | 1172 uniform SamplerType s_texture; |
| 1119 uniform float alpha; | 1173 uniform float alpha; |
| 1120 uniform mat4 colorMatrix; | 1174 uniform mat4 colorMatrix; |
| 1121 uniform vec4 colorOffset; | 1175 uniform vec4 colorOffset; |
| 1122 }); | 1176 }); |
| 1123 } | 1177 } |
| 1124 | 1178 |
| 1125 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderBody() { | 1179 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderBody() { |
| 1126 return SHADER0([]() { | 1180 return SHADER0([]() { |
| 1127 void main() { | 1181 void main() { |
| 1128 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1182 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1129 float nonZeroAlpha = max(texColor.a, 0.00001); | 1183 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1130 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1184 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1131 texColor = colorMatrix * texColor + colorOffset; | 1185 texColor = colorMatrix * texColor + colorOffset; |
| 1132 texColor.rgb *= texColor.a; | 1186 texColor.rgb *= texColor.a; |
| 1133 texColor = clamp(texColor, 0.0, 1.0); | 1187 texColor = clamp(texColor, 0.0, 1.0); |
| 1134 gl_FragColor = ApplyBlendMode(texColor * alpha); | 1188 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); |
| 1135 } | 1189 } |
| 1136 }); | 1190 }); |
| 1137 } | 1191 } |
| 1138 | 1192 |
| 1193 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( |
| 1194 ShaderLocations* locations) const { |
| 1195 locations->sampler = sampler_location(); |
| 1196 locations->alpha = alpha_location(); |
| 1197 locations->color_matrix = color_matrix_location(); |
| 1198 locations->color_offset = color_offset_location(); |
| 1199 locations->backdrop = backdrop_location(); |
| 1200 locations->backdrop_rect = backdrop_rect_location(); |
| 1201 } |
| 1202 |
| 1139 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( | 1203 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( |
| 1140 TexCoordPrecision precision, | 1204 TexCoordPrecision precision, |
| 1141 SamplerType sampler) const { | 1205 SamplerType sampler) const { |
| 1142 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1206 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
| 1143 } | 1207 } |
| 1144 | 1208 |
| 1145 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderHead() { | 1209 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderHead() { |
| 1146 return SHADER0([]() { | 1210 return SHADER0([]() { |
| 1147 precision mediump float; | 1211 precision mediump float; |
| 1148 varying TexCoordPrecision vec2 v_texCoord; | 1212 varying TexCoordPrecision vec2 v_texCoord; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 }); | 1457 }); |
| 1394 } | 1458 } |
| 1395 | 1459 |
| 1396 std::string FragmentShaderRGBATexAlphaAA::GetShaderBody() { | 1460 std::string FragmentShaderRGBATexAlphaAA::GetShaderBody() { |
| 1397 return SHADER0([]() { | 1461 return SHADER0([]() { |
| 1398 void main() { | 1462 void main() { |
| 1399 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1463 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1400 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1464 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1401 vec2 d2 = min(d4.xz, d4.yw); | 1465 vec2 d2 = min(d4.xz, d4.yw); |
| 1402 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1466 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1403 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); | 1467 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); |
| 1404 } | 1468 } |
| 1405 }); | 1469 }); |
| 1406 } | 1470 } |
| 1407 | 1471 |
| 1472 void FragmentShaderRGBATexAlphaAA::FillLocations( |
| 1473 ShaderLocations* locations) const { |
| 1474 locations->sampler = sampler_location(); |
| 1475 locations->alpha = alpha_location(); |
| 1476 locations->backdrop = backdrop_location(); |
| 1477 locations->backdrop_rect = backdrop_rect_location(); |
| 1478 } |
| 1479 |
| 1408 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() | 1480 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() |
| 1409 : sampler_location_(-1), | 1481 : sampler_location_(-1), |
| 1410 alpha_location_(-1), | 1482 alpha_location_(-1), |
| 1411 fragment_tex_transform_location_(-1) { | 1483 fragment_tex_transform_location_(-1) { |
| 1412 } | 1484 } |
| 1413 | 1485 |
| 1414 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, | 1486 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, |
| 1415 unsigned program, | 1487 unsigned program, |
| 1416 int* base_uniform_index) { | 1488 int* base_uniform_index) { |
| 1417 static const char* uniforms[] = { | 1489 static const char* uniforms[] = { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 } | 1620 } |
| 1549 | 1621 |
| 1550 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { | 1622 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { |
| 1551 return SHADER0([]() { | 1623 return SHADER0([]() { |
| 1552 void main() { | 1624 void main() { |
| 1553 vec4 texColor = texture2D(s_texture, v_texCoord); | 1625 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1554 TexCoordPrecision vec2 maskTexCoord = | 1626 TexCoordPrecision vec2 maskTexCoord = |
| 1555 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1627 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1556 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1628 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1557 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1629 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1558 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); | 1630 gl_FragColor = ApplyBlendMode( |
| 1631 texColor * alpha * maskColor.w, maskColor.w); |
| 1559 } | 1632 } |
| 1560 }); | 1633 }); |
| 1561 } | 1634 } |
| 1562 | 1635 |
| 1636 void FragmentShaderRGBATexAlphaMask::FillLocations( |
| 1637 ShaderLocations* locations) const { |
| 1638 locations->sampler = sampler_location(); |
| 1639 locations->mask_sampler = mask_sampler_location(); |
| 1640 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
| 1641 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
| 1642 locations->alpha = alpha_location(); |
| 1643 locations->backdrop = backdrop_location(); |
| 1644 locations->backdrop_rect = backdrop_rect_location(); |
| 1645 if (mask_for_background()) |
| 1646 locations->original_backdrop = original_backdrop_location(); |
| 1647 } |
| 1648 |
| 1563 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 1649 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
| 1564 : sampler_location_(-1), | 1650 : sampler_location_(-1), |
| 1565 mask_sampler_location_(-1), | 1651 mask_sampler_location_(-1), |
| 1566 alpha_location_(-1), | 1652 alpha_location_(-1), |
| 1567 mask_tex_coord_scale_location_(-1), | 1653 mask_tex_coord_scale_location_(-1), |
| 1568 mask_tex_coord_offset_location_(-1) { | 1654 mask_tex_coord_offset_location_(-1) { |
| 1569 } | 1655 } |
| 1570 | 1656 |
| 1571 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context, | 1657 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context, |
| 1572 unsigned program, | 1658 unsigned program, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 return SHADER0([]() { | 1704 return SHADER0([]() { |
| 1619 void main() { | 1705 void main() { |
| 1620 vec4 texColor = texture2D(s_texture, v_texCoord); | 1706 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1621 TexCoordPrecision vec2 maskTexCoord = | 1707 TexCoordPrecision vec2 maskTexCoord = |
| 1622 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1708 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1623 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1709 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1624 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1710 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1625 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1711 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1626 vec2 d2 = min(d4.xz, d4.yw); | 1712 vec2 d2 = min(d4.xz, d4.yw); |
| 1627 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1713 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1628 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); | 1714 gl_FragColor = ApplyBlendMode( |
| 1715 texColor * alpha * maskColor.w * aa, maskColor.w); |
| 1629 } | 1716 } |
| 1630 }); | 1717 }); |
| 1631 } | 1718 } |
| 1632 | 1719 |
| 1720 void FragmentShaderRGBATexAlphaMaskAA::FillLocations( |
| 1721 ShaderLocations* locations) const { |
| 1722 locations->sampler = sampler_location(); |
| 1723 locations->mask_sampler = mask_sampler_location(); |
| 1724 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
| 1725 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
| 1726 locations->alpha = alpha_location(); |
| 1727 locations->backdrop = backdrop_location(); |
| 1728 locations->backdrop_rect = backdrop_rect_location(); |
| 1729 if (mask_for_background()) |
| 1730 locations->original_backdrop = original_backdrop_location(); |
| 1731 } |
| 1732 |
| 1633 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: | 1733 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: |
| 1634 FragmentShaderRGBATexAlphaMaskColorMatrixAA() | 1734 FragmentShaderRGBATexAlphaMaskColorMatrixAA() |
| 1635 : sampler_location_(-1), | 1735 : sampler_location_(-1), |
| 1636 mask_sampler_location_(-1), | 1736 mask_sampler_location_(-1), |
| 1637 alpha_location_(-1), | 1737 alpha_location_(-1), |
| 1638 mask_tex_coord_scale_location_(-1), | 1738 mask_tex_coord_scale_location_(-1), |
| 1639 color_matrix_location_(-1), | 1739 color_matrix_location_(-1), |
| 1640 color_offset_location_(-1) { | 1740 color_offset_location_(-1) { |
| 1641 } | 1741 } |
| 1642 | 1742 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 texColor = colorMatrix * texColor + colorOffset; | 1802 texColor = colorMatrix * texColor + colorOffset; |
| 1703 texColor.rgb *= texColor.a; | 1803 texColor.rgb *= texColor.a; |
| 1704 texColor = clamp(texColor, 0.0, 1.0); | 1804 texColor = clamp(texColor, 0.0, 1.0); |
| 1705 TexCoordPrecision vec2 maskTexCoord = | 1805 TexCoordPrecision vec2 maskTexCoord = |
| 1706 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1806 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1707 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1807 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1708 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1808 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1709 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1809 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1710 vec2 d2 = min(d4.xz, d4.yw); | 1810 vec2 d2 = min(d4.xz, d4.yw); |
| 1711 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1811 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1712 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); | 1812 gl_FragColor = ApplyBlendMode( |
| 1813 texColor * alpha * maskColor.w * aa, maskColor.w); |
| 1713 } | 1814 } |
| 1714 }); | 1815 }); |
| 1715 } | 1816 } |
| 1716 | 1817 |
| 1818 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations( |
| 1819 ShaderLocations* locations) const { |
| 1820 locations->sampler = sampler_location(); |
| 1821 locations->alpha = alpha_location(); |
| 1822 locations->mask_sampler = mask_sampler_location(); |
| 1823 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
| 1824 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
| 1825 locations->color_matrix = color_matrix_location(); |
| 1826 locations->color_offset = color_offset_location(); |
| 1827 locations->backdrop = backdrop_location(); |
| 1828 locations->backdrop_rect = backdrop_rect_location(); |
| 1829 if (mask_for_background()) |
| 1830 locations->original_backdrop = original_backdrop_location(); |
| 1831 } |
| 1832 |
| 1717 FragmentShaderRGBATexAlphaColorMatrixAA:: | 1833 FragmentShaderRGBATexAlphaColorMatrixAA:: |
| 1718 FragmentShaderRGBATexAlphaColorMatrixAA() | 1834 FragmentShaderRGBATexAlphaColorMatrixAA() |
| 1719 : sampler_location_(-1), | 1835 : sampler_location_(-1), |
| 1720 alpha_location_(-1), | 1836 alpha_location_(-1), |
| 1721 color_matrix_location_(-1), | 1837 color_matrix_location_(-1), |
| 1722 color_offset_location_(-1) { | 1838 color_offset_location_(-1) { |
| 1723 } | 1839 } |
| 1724 | 1840 |
| 1725 void FragmentShaderRGBATexAlphaColorMatrixAA::Init(GLES2Interface* context, | 1841 void FragmentShaderRGBATexAlphaColorMatrixAA::Init(GLES2Interface* context, |
| 1726 unsigned program, | 1842 unsigned program, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1766 void main() { | 1882 void main() { |
| 1767 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1883 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1768 float nonZeroAlpha = max(texColor.a, 0.00001); | 1884 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1769 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1885 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1770 texColor = colorMatrix * texColor + colorOffset; | 1886 texColor = colorMatrix * texColor + colorOffset; |
| 1771 texColor.rgb *= texColor.a; | 1887 texColor.rgb *= texColor.a; |
| 1772 texColor = clamp(texColor, 0.0, 1.0); | 1888 texColor = clamp(texColor, 0.0, 1.0); |
| 1773 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1889 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1774 vec2 d2 = min(d4.xz, d4.yw); | 1890 vec2 d2 = min(d4.xz, d4.yw); |
| 1775 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1891 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1776 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); | 1892 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); |
| 1777 } | 1893 } |
| 1778 }); | 1894 }); |
| 1779 } | 1895 } |
| 1780 | 1896 |
| 1897 void FragmentShaderRGBATexAlphaColorMatrixAA::FillLocations( |
| 1898 ShaderLocations* locations) const { |
| 1899 locations->sampler = sampler_location(); |
| 1900 locations->alpha = alpha_location(); |
| 1901 locations->color_matrix = color_matrix_location(); |
| 1902 locations->color_offset = color_offset_location(); |
| 1903 locations->backdrop = backdrop_location(); |
| 1904 locations->backdrop_rect = backdrop_rect_location(); |
| 1905 } |
| 1906 |
| 1781 FragmentShaderRGBATexAlphaMaskColorMatrix:: | 1907 FragmentShaderRGBATexAlphaMaskColorMatrix:: |
| 1782 FragmentShaderRGBATexAlphaMaskColorMatrix() | 1908 FragmentShaderRGBATexAlphaMaskColorMatrix() |
| 1783 : sampler_location_(-1), | 1909 : sampler_location_(-1), |
| 1784 mask_sampler_location_(-1), | 1910 mask_sampler_location_(-1), |
| 1785 alpha_location_(-1), | 1911 alpha_location_(-1), |
| 1786 mask_tex_coord_scale_location_(-1) { | 1912 mask_tex_coord_scale_location_(-1) { |
| 1787 } | 1913 } |
| 1788 | 1914 |
| 1789 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context, | 1915 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context, |
| 1790 unsigned program, | 1916 unsigned program, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1843 vec4 texColor = texture2D(s_texture, v_texCoord); | 1969 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1844 float nonZeroAlpha = max(texColor.a, 0.00001); | 1970 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1845 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1971 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1846 texColor = colorMatrix * texColor + colorOffset; | 1972 texColor = colorMatrix * texColor + colorOffset; |
| 1847 texColor.rgb *= texColor.a; | 1973 texColor.rgb *= texColor.a; |
| 1848 texColor = clamp(texColor, 0.0, 1.0); | 1974 texColor = clamp(texColor, 0.0, 1.0); |
| 1849 TexCoordPrecision vec2 maskTexCoord = | 1975 TexCoordPrecision vec2 maskTexCoord = |
| 1850 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1976 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1851 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1977 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1852 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1978 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1853 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); | 1979 gl_FragColor = ApplyBlendMode( |
| 1980 texColor * alpha * maskColor.w, maskColor.w); |
| 1854 } | 1981 } |
| 1855 }); | 1982 }); |
| 1856 } | 1983 } |
| 1857 | 1984 |
| 1985 void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations( |
| 1986 ShaderLocations* locations) const { |
| 1987 locations->sampler = sampler_location(); |
| 1988 locations->mask_sampler = mask_sampler_location(); |
| 1989 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
| 1990 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
| 1991 locations->alpha = alpha_location(); |
| 1992 locations->color_matrix = color_matrix_location(); |
| 1993 locations->color_offset = color_offset_location(); |
| 1994 locations->backdrop = backdrop_location(); |
| 1995 locations->backdrop_rect = backdrop_rect_location(); |
| 1996 if (mask_for_background()) |
| 1997 locations->original_backdrop = original_backdrop_location(); |
| 1998 } |
| 1999 |
| 1858 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 2000 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
| 1859 : y_texture_location_(-1), | 2001 : y_texture_location_(-1), |
| 1860 u_texture_location_(-1), | 2002 u_texture_location_(-1), |
| 1861 v_texture_location_(-1), | 2003 v_texture_location_(-1), |
| 1862 alpha_location_(-1), | 2004 alpha_location_(-1), |
| 1863 yuv_matrix_location_(-1), | 2005 yuv_matrix_location_(-1), |
| 1864 yuv_adj_location_(-1), | 2006 yuv_adj_location_(-1), |
| 1865 clamp_rect_location_(-1) { | 2007 clamp_rect_location_(-1) { |
| 1866 } | 2008 } |
| 1867 | 2009 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2140 vec2 texCoord = | 2282 vec2 texCoord = |
| 2141 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 2283 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
| 2142 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 2284 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 2143 float picker = abs(coord.x - coord.y); // NOLINT | 2285 float picker = abs(coord.x - coord.y); // NOLINT |
| 2144 gl_FragColor = mix(color1, color2, picker) * alpha; | 2286 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 2145 } | 2287 } |
| 2146 }); | 2288 }); |
| 2147 } | 2289 } |
| 2148 | 2290 |
| 2149 } // namespace cc | 2291 } // namespace cc |
| OLD | NEW |