| 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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 std::string VertexShaderVideoTransform::GetShaderBody() { | 734 std::string VertexShaderVideoTransform::GetShaderBody() { |
| 735 return SHADER0([]() { | 735 return SHADER0([]() { |
| 736 void main() { | 736 void main() { |
| 737 gl_Position = matrix * a_position; | 737 gl_Position = matrix * a_position; |
| 738 v_texCoord = | 738 v_texCoord = |
| 739 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)); |
| 740 } | 740 } |
| 741 }); | 741 }); |
| 742 } | 742 } |
| 743 | 743 |
| 744 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" | 744 #define BLEND_MODE_UNIFORMS "s_backdropTexture", \ |
| 745 #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) |
| 746 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ | 748 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ |
| 747 if (has_blend_mode()) { \ | 749 if (has_blend_mode()) { \ |
| 748 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ | 750 DCHECK_LT(static_cast<size_t>(POS) + 2, arraysize(X)); \ |
| 749 backdrop_location_ = locations[POS]; \ | 751 backdrop_location_ = locations[POS]; \ |
| 750 backdrop_rect_location_ = locations[POS + 1]; \ | 752 original_backdrop_location_ = locations[POS + 1]; \ |
| 753 backdrop_rect_location_ = locations[POS + 2]; \ |
| 751 } | 754 } |
| 752 | 755 |
| 753 FragmentTexBlendMode::FragmentTexBlendMode() | 756 FragmentTexBlendMode::FragmentTexBlendMode() |
| 754 : backdrop_location_(-1), | 757 : backdrop_location_(-1), |
| 758 original_backdrop_location_(-1), |
| 755 backdrop_rect_location_(-1), | 759 backdrop_rect_location_(-1), |
| 756 blend_mode_(BLEND_MODE_NONE) { | 760 blend_mode_(BLEND_MODE_NONE), |
| 761 mask_for_background_(false) { |
| 757 } | 762 } |
| 758 | 763 |
| 759 std::string FragmentTexBlendMode::SetBlendModeFunctions( | 764 std::string FragmentTexBlendMode::SetBlendModeFunctions( |
| 760 std::string shader_string) const { | 765 std::string shader_string) const { |
| 761 if (shader_string.find("ApplyBlendMode") == std::string::npos) | 766 if (shader_string.find("ApplyBlendMode") == std::string::npos) |
| 762 return shader_string; | 767 return shader_string; |
| 763 | 768 |
| 764 if (!has_blend_mode()) { | 769 if (!has_blend_mode()) { |
| 765 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 }); |
| 766 } | 795 } |
| 767 | 796 |
| 768 static const std::string kFunctionApplyBlendMode = SHADER0([]() { | 797 static const std::string kFunctionApplyBlendMode = SHADER0([]() { |
| 769 uniform sampler2D s_backdropTexture; | 798 vec4 GetBackdropColor(float mask) { |
| 770 uniform TexCoordPrecision vec4 backdropRect; | |
| 771 | |
| 772 vec4 GetBackdropColor() { | |
| 773 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; | 799 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; |
| 774 bgTexCoord.x /= backdropRect.z; | 800 bgTexCoord.x /= backdropRect.z; |
| 775 bgTexCoord.y /= backdropRect.w; | 801 bgTexCoord.y /= backdropRect.w; |
| 776 return texture2D(s_backdropTexture, bgTexCoord); | 802 return MixBackdrop(bgTexCoord, mask); |
| 777 } | 803 } |
| 778 | 804 |
| 779 vec4 ApplyBlendMode(vec4 src) { | 805 vec4 ApplyBlendMode(vec4 src, float mask) { |
| 780 vec4 dst = GetBackdropColor(); | 806 vec4 dst = GetBackdropColor(mask); |
| 781 return Blend(src, dst); | 807 return Blend(src, dst); |
| 782 } | 808 } |
| 783 }); | 809 }); |
| 784 | 810 |
| 785 return "precision mediump float;" + GetHelperFunctions() + | 811 return "precision mediump float;" + GetHelperFunctions() + |
| 786 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; | 812 GetBlendFunction() + kUniforms + mixFunction + |
| 813 kFunctionApplyBlendMode + shader_string; |
| 787 } | 814 } |
| 788 | 815 |
| 789 std::string FragmentTexBlendMode::GetHelperFunctions() const { | 816 std::string FragmentTexBlendMode::GetHelperFunctions() const { |
| 790 static const std::string kFunctionHardLight = SHADER0([]() { | 817 static const std::string kFunctionHardLight = SHADER0([]() { |
| 791 vec3 hardLight(vec4 src, vec4 dst) { | 818 vec3 hardLight(vec4 src, vec4 dst) { |
| 792 vec3 result; | 819 vec3 result; |
| 793 result.r = | 820 result.r = |
| 794 (2.0 * src.r <= src.a) | 821 (2.0 * src.r <= src.a) |
| 795 ? (2.0 * src.r * dst.r) | 822 ? (2.0 * src.r * dst.r) |
| 796 : (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... |
| 1112 varying TexCoordPrecision vec2 v_texCoord; | 1139 varying TexCoordPrecision vec2 v_texCoord; |
| 1113 uniform SamplerType s_texture; | 1140 uniform SamplerType s_texture; |
| 1114 uniform float alpha; | 1141 uniform float alpha; |
| 1115 }); | 1142 }); |
| 1116 } | 1143 } |
| 1117 | 1144 |
| 1118 std::string FragmentShaderRGBATexAlpha::GetShaderBody() { | 1145 std::string FragmentShaderRGBATexAlpha::GetShaderBody() { |
| 1119 return SHADER0([]() { | 1146 return SHADER0([]() { |
| 1120 void main() { | 1147 void main() { |
| 1121 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1148 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1122 gl_FragColor = ApplyBlendMode(texColor * alpha); | 1149 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); |
| 1123 } | 1150 } |
| 1124 }); | 1151 }); |
| 1125 } | 1152 } |
| 1126 | 1153 |
| 1127 void FragmentShaderRGBATexAlpha::FillLocations( | 1154 void FragmentShaderRGBATexAlpha::FillLocations( |
| 1128 ShaderLocations* locations) const { | 1155 ShaderLocations* locations) const { |
| 1129 locations->sampler = sampler_location(); | 1156 locations->sampler = sampler_location(); |
| 1130 locations->alpha = alpha_location(); | 1157 locations->alpha = alpha_location(); |
| 1131 locations->backdrop = backdrop_location(); | 1158 locations->backdrop = backdrop_location(); |
| 1132 locations->backdrop_rect = backdrop_rect_location(); | 1159 locations->backdrop_rect = backdrop_rect_location(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1151 | 1178 |
| 1152 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderBody() { | 1179 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderBody() { |
| 1153 return SHADER0([]() { | 1180 return SHADER0([]() { |
| 1154 void main() { | 1181 void main() { |
| 1155 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1182 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1156 float nonZeroAlpha = max(texColor.a, 0.00001); | 1183 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1157 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1184 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1158 texColor = colorMatrix * texColor + colorOffset; | 1185 texColor = colorMatrix * texColor + colorOffset; |
| 1159 texColor.rgb *= texColor.a; | 1186 texColor.rgb *= texColor.a; |
| 1160 texColor = clamp(texColor, 0.0, 1.0); | 1187 texColor = clamp(texColor, 0.0, 1.0); |
| 1161 gl_FragColor = ApplyBlendMode(texColor * alpha); | 1188 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); |
| 1162 } | 1189 } |
| 1163 }); | 1190 }); |
| 1164 } | 1191 } |
| 1165 | 1192 |
| 1166 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( | 1193 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( |
| 1167 ShaderLocations* locations) const { | 1194 ShaderLocations* locations) const { |
| 1168 locations->sampler = sampler_location(); | 1195 locations->sampler = sampler_location(); |
| 1169 locations->alpha = alpha_location(); | 1196 locations->alpha = alpha_location(); |
| 1170 locations->color_matrix = color_matrix_location(); | 1197 locations->color_matrix = color_matrix_location(); |
| 1171 locations->color_offset = color_offset_location(); | 1198 locations->color_offset = color_offset_location(); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 }); | 1457 }); |
| 1431 } | 1458 } |
| 1432 | 1459 |
| 1433 std::string FragmentShaderRGBATexAlphaAA::GetShaderBody() { | 1460 std::string FragmentShaderRGBATexAlphaAA::GetShaderBody() { |
| 1434 return SHADER0([]() { | 1461 return SHADER0([]() { |
| 1435 void main() { | 1462 void main() { |
| 1436 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1463 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1437 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1464 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1438 vec2 d2 = min(d4.xz, d4.yw); | 1465 vec2 d2 = min(d4.xz, d4.yw); |
| 1439 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); |
| 1440 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); | 1467 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); |
| 1441 } | 1468 } |
| 1442 }); | 1469 }); |
| 1443 } | 1470 } |
| 1444 | 1471 |
| 1445 void FragmentShaderRGBATexAlphaAA::FillLocations( | 1472 void FragmentShaderRGBATexAlphaAA::FillLocations( |
| 1446 ShaderLocations* locations) const { | 1473 ShaderLocations* locations) const { |
| 1447 locations->sampler = sampler_location(); | 1474 locations->sampler = sampler_location(); |
| 1448 locations->alpha = alpha_location(); | 1475 locations->alpha = alpha_location(); |
| 1449 locations->backdrop = backdrop_location(); | 1476 locations->backdrop = backdrop_location(); |
| 1450 locations->backdrop_rect = backdrop_rect_location(); | 1477 locations->backdrop_rect = backdrop_rect_location(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1593 } | 1620 } |
| 1594 | 1621 |
| 1595 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { | 1622 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { |
| 1596 return SHADER0([]() { | 1623 return SHADER0([]() { |
| 1597 void main() { | 1624 void main() { |
| 1598 vec4 texColor = texture2D(s_texture, v_texCoord); | 1625 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1599 TexCoordPrecision vec2 maskTexCoord = | 1626 TexCoordPrecision vec2 maskTexCoord = |
| 1600 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1627 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1601 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1628 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1602 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1629 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1603 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); | 1630 gl_FragColor = ApplyBlendMode( |
| 1631 texColor * alpha * maskColor.w, maskColor.w); |
| 1604 } | 1632 } |
| 1605 }); | 1633 }); |
| 1606 } | 1634 } |
| 1607 | 1635 |
| 1608 void FragmentShaderRGBATexAlphaMask::FillLocations( | 1636 void FragmentShaderRGBATexAlphaMask::FillLocations( |
| 1609 ShaderLocations* locations) const { | 1637 ShaderLocations* locations) const { |
| 1610 locations->sampler = sampler_location(); | 1638 locations->sampler = sampler_location(); |
| 1611 locations->mask_sampler = mask_sampler_location(); | 1639 locations->mask_sampler = mask_sampler_location(); |
| 1612 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); | 1640 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
| 1613 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); | 1641 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
| 1614 locations->alpha = alpha_location(); | 1642 locations->alpha = alpha_location(); |
| 1615 locations->backdrop = backdrop_location(); | 1643 locations->backdrop = backdrop_location(); |
| 1616 locations->backdrop_rect = backdrop_rect_location(); | 1644 locations->backdrop_rect = backdrop_rect_location(); |
| 1645 if (mask_for_background()) |
| 1646 locations->original_backdrop = original_backdrop_location(); |
| 1617 } | 1647 } |
| 1618 | 1648 |
| 1619 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 1649 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
| 1620 : sampler_location_(-1), | 1650 : sampler_location_(-1), |
| 1621 mask_sampler_location_(-1), | 1651 mask_sampler_location_(-1), |
| 1622 alpha_location_(-1), | 1652 alpha_location_(-1), |
| 1623 mask_tex_coord_scale_location_(-1), | 1653 mask_tex_coord_scale_location_(-1), |
| 1624 mask_tex_coord_offset_location_(-1) { | 1654 mask_tex_coord_offset_location_(-1) { |
| 1625 } | 1655 } |
| 1626 | 1656 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1674 return SHADER0([]() { | 1704 return SHADER0([]() { |
| 1675 void main() { | 1705 void main() { |
| 1676 vec4 texColor = texture2D(s_texture, v_texCoord); | 1706 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1677 TexCoordPrecision vec2 maskTexCoord = | 1707 TexCoordPrecision vec2 maskTexCoord = |
| 1678 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1708 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1679 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1709 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1680 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1710 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1681 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1711 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1682 vec2 d2 = min(d4.xz, d4.yw); | 1712 vec2 d2 = min(d4.xz, d4.yw); |
| 1683 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); |
| 1684 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); | 1714 gl_FragColor = ApplyBlendMode( |
| 1715 texColor * alpha * maskColor.w * aa, maskColor.w); |
| 1685 } | 1716 } |
| 1686 }); | 1717 }); |
| 1687 } | 1718 } |
| 1688 | 1719 |
| 1689 void FragmentShaderRGBATexAlphaMaskAA::FillLocations( | 1720 void FragmentShaderRGBATexAlphaMaskAA::FillLocations( |
| 1690 ShaderLocations* locations) const { | 1721 ShaderLocations* locations) const { |
| 1691 locations->sampler = sampler_location(); | 1722 locations->sampler = sampler_location(); |
| 1692 locations->mask_sampler = mask_sampler_location(); | 1723 locations->mask_sampler = mask_sampler_location(); |
| 1693 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); | 1724 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
| 1694 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); | 1725 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
| 1695 locations->alpha = alpha_location(); | 1726 locations->alpha = alpha_location(); |
| 1696 locations->backdrop = backdrop_location(); | 1727 locations->backdrop = backdrop_location(); |
| 1697 locations->backdrop_rect = backdrop_rect_location(); | 1728 locations->backdrop_rect = backdrop_rect_location(); |
| 1729 if (mask_for_background()) |
| 1730 locations->original_backdrop = original_backdrop_location(); |
| 1698 } | 1731 } |
| 1699 | 1732 |
| 1700 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: | 1733 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: |
| 1701 FragmentShaderRGBATexAlphaMaskColorMatrixAA() | 1734 FragmentShaderRGBATexAlphaMaskColorMatrixAA() |
| 1702 : sampler_location_(-1), | 1735 : sampler_location_(-1), |
| 1703 mask_sampler_location_(-1), | 1736 mask_sampler_location_(-1), |
| 1704 alpha_location_(-1), | 1737 alpha_location_(-1), |
| 1705 mask_tex_coord_scale_location_(-1), | 1738 mask_tex_coord_scale_location_(-1), |
| 1706 color_matrix_location_(-1), | 1739 color_matrix_location_(-1), |
| 1707 color_offset_location_(-1) { | 1740 color_offset_location_(-1) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1769 texColor = colorMatrix * texColor + colorOffset; | 1802 texColor = colorMatrix * texColor + colorOffset; |
| 1770 texColor.rgb *= texColor.a; | 1803 texColor.rgb *= texColor.a; |
| 1771 texColor = clamp(texColor, 0.0, 1.0); | 1804 texColor = clamp(texColor, 0.0, 1.0); |
| 1772 TexCoordPrecision vec2 maskTexCoord = | 1805 TexCoordPrecision vec2 maskTexCoord = |
| 1773 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1806 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1774 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1807 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1775 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1808 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1776 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1809 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1777 vec2 d2 = min(d4.xz, d4.yw); | 1810 vec2 d2 = min(d4.xz, d4.yw); |
| 1778 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); |
| 1779 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); | 1812 gl_FragColor = ApplyBlendMode( |
| 1813 texColor * alpha * maskColor.w * aa, maskColor.w); |
| 1780 } | 1814 } |
| 1781 }); | 1815 }); |
| 1782 } | 1816 } |
| 1783 | 1817 |
| 1784 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations( | 1818 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations( |
| 1785 ShaderLocations* locations) const { | 1819 ShaderLocations* locations) const { |
| 1786 locations->sampler = sampler_location(); | 1820 locations->sampler = sampler_location(); |
| 1787 locations->alpha = alpha_location(); | 1821 locations->alpha = alpha_location(); |
| 1788 locations->mask_sampler = mask_sampler_location(); | 1822 locations->mask_sampler = mask_sampler_location(); |
| 1789 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); | 1823 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
| 1790 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); | 1824 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
| 1791 locations->color_matrix = color_matrix_location(); | 1825 locations->color_matrix = color_matrix_location(); |
| 1792 locations->color_offset = color_offset_location(); | 1826 locations->color_offset = color_offset_location(); |
| 1793 locations->backdrop = backdrop_location(); | 1827 locations->backdrop = backdrop_location(); |
| 1794 locations->backdrop_rect = backdrop_rect_location(); | 1828 locations->backdrop_rect = backdrop_rect_location(); |
| 1829 if (mask_for_background()) |
| 1830 locations->original_backdrop = original_backdrop_location(); |
| 1795 } | 1831 } |
| 1796 | 1832 |
| 1797 FragmentShaderRGBATexAlphaColorMatrixAA:: | 1833 FragmentShaderRGBATexAlphaColorMatrixAA:: |
| 1798 FragmentShaderRGBATexAlphaColorMatrixAA() | 1834 FragmentShaderRGBATexAlphaColorMatrixAA() |
| 1799 : sampler_location_(-1), | 1835 : sampler_location_(-1), |
| 1800 alpha_location_(-1), | 1836 alpha_location_(-1), |
| 1801 color_matrix_location_(-1), | 1837 color_matrix_location_(-1), |
| 1802 color_offset_location_(-1) { | 1838 color_offset_location_(-1) { |
| 1803 } | 1839 } |
| 1804 | 1840 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 void main() { | 1882 void main() { |
| 1847 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1883 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1848 float nonZeroAlpha = max(texColor.a, 0.00001); | 1884 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1849 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1885 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1850 texColor = colorMatrix * texColor + colorOffset; | 1886 texColor = colorMatrix * texColor + colorOffset; |
| 1851 texColor.rgb *= texColor.a; | 1887 texColor.rgb *= texColor.a; |
| 1852 texColor = clamp(texColor, 0.0, 1.0); | 1888 texColor = clamp(texColor, 0.0, 1.0); |
| 1853 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1889 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1854 vec2 d2 = min(d4.xz, d4.yw); | 1890 vec2 d2 = min(d4.xz, d4.yw); |
| 1855 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); |
| 1856 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); | 1892 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); |
| 1857 } | 1893 } |
| 1858 }); | 1894 }); |
| 1859 } | 1895 } |
| 1860 | 1896 |
| 1861 void FragmentShaderRGBATexAlphaColorMatrixAA::FillLocations( | 1897 void FragmentShaderRGBATexAlphaColorMatrixAA::FillLocations( |
| 1862 ShaderLocations* locations) const { | 1898 ShaderLocations* locations) const { |
| 1863 locations->sampler = sampler_location(); | 1899 locations->sampler = sampler_location(); |
| 1864 locations->alpha = alpha_location(); | 1900 locations->alpha = alpha_location(); |
| 1865 locations->color_matrix = color_matrix_location(); | 1901 locations->color_matrix = color_matrix_location(); |
| 1866 locations->color_offset = color_offset_location(); | 1902 locations->color_offset = color_offset_location(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1933 vec4 texColor = texture2D(s_texture, v_texCoord); | 1969 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1934 float nonZeroAlpha = max(texColor.a, 0.00001); | 1970 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1935 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1971 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1936 texColor = colorMatrix * texColor + colorOffset; | 1972 texColor = colorMatrix * texColor + colorOffset; |
| 1937 texColor.rgb *= texColor.a; | 1973 texColor.rgb *= texColor.a; |
| 1938 texColor = clamp(texColor, 0.0, 1.0); | 1974 texColor = clamp(texColor, 0.0, 1.0); |
| 1939 TexCoordPrecision vec2 maskTexCoord = | 1975 TexCoordPrecision vec2 maskTexCoord = |
| 1940 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1976 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1941 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1977 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1942 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1978 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1943 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); | 1979 gl_FragColor = ApplyBlendMode( |
| 1980 texColor * alpha * maskColor.w, maskColor.w); |
| 1944 } | 1981 } |
| 1945 }); | 1982 }); |
| 1946 } | 1983 } |
| 1947 | 1984 |
| 1948 void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations( | 1985 void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations( |
| 1949 ShaderLocations* locations) const { | 1986 ShaderLocations* locations) const { |
| 1950 locations->sampler = sampler_location(); | 1987 locations->sampler = sampler_location(); |
| 1951 locations->mask_sampler = mask_sampler_location(); | 1988 locations->mask_sampler = mask_sampler_location(); |
| 1952 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); | 1989 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
| 1953 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); | 1990 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
| 1954 locations->alpha = alpha_location(); | 1991 locations->alpha = alpha_location(); |
| 1955 locations->color_matrix = color_matrix_location(); | 1992 locations->color_matrix = color_matrix_location(); |
| 1956 locations->color_offset = color_offset_location(); | 1993 locations->color_offset = color_offset_location(); |
| 1957 locations->backdrop = backdrop_location(); | 1994 locations->backdrop = backdrop_location(); |
| 1958 locations->backdrop_rect = backdrop_rect_location(); | 1995 locations->backdrop_rect = backdrop_rect_location(); |
| 1996 if (mask_for_background()) |
| 1997 locations->original_backdrop = original_backdrop_location(); |
| 1959 } | 1998 } |
| 1960 | 1999 |
| 1961 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 2000 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
| 1962 : y_texture_location_(-1), | 2001 : y_texture_location_(-1), |
| 1963 u_texture_location_(-1), | 2002 u_texture_location_(-1), |
| 1964 v_texture_location_(-1), | 2003 v_texture_location_(-1), |
| 1965 alpha_location_(-1), | 2004 alpha_location_(-1), |
| 1966 yuv_matrix_location_(-1), | 2005 yuv_matrix_location_(-1), |
| 1967 yuv_adj_location_(-1), | 2006 yuv_adj_location_(-1), |
| 1968 clamp_rect_location_(-1) { | 2007 clamp_rect_location_(-1) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2243 vec2 texCoord = | 2282 vec2 texCoord = |
| 2244 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 2283 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
| 2245 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 2284 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 2246 float picker = abs(coord.x - coord.y); // NOLINT | 2285 float picker = abs(coord.x - coord.y); // NOLINT |
| 2247 gl_FragColor = mix(color1, color2, picker) * alpha; | 2286 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 2248 } | 2287 } |
| 2249 }); | 2288 }); |
| 2250 } | 2289 } |
| 2251 | 2290 |
| 2252 } // namespace cc | 2291 } // namespace cc |
| OLD | NEW |