Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1098)

Side by Side Diff: cc/output/shader.cc

Issue 959283004: Background filters are affected by masks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 void main() { 340 void main() {
341 int quad_index = int(a_index * 0.25); // NOLINT 341 int quad_index = int(a_index * 0.25); // NOLINT
342 gl_Position = matrix[quad_index] * a_position; 342 gl_Position = matrix[quad_index] * a_position;
343 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; 343 TexCoordPrecision vec4 texTrans = texTransform[quad_index];
344 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; 344 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy;
345 v_alpha = opacity[int(a_index)]; // NOLINT 345 v_alpha = opacity[int(a_index)]; // NOLINT
346 } 346 }
347 }); 347 });
348 } 348 }
349 349
350 void VertexShaderPosTexTransform::FillLocations(
351 ShaderLocations* locations) const {
352 locations->matrix = matrix_location();
353 locations->tex_transform = tex_transform_location();
354 }
355
350 std::string VertexShaderPosTexIdentity::GetShaderString() const { 356 std::string VertexShaderPosTexIdentity::GetShaderString() const {
351 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); 357 return VERTEX_SHADER(GetShaderHead(), GetShaderBody());
352 } 358 }
353 359
354 std::string VertexShaderPosTexIdentity::GetShaderHead() { 360 std::string VertexShaderPosTexIdentity::GetShaderHead() {
355 return SHADER0([]() { 361 return SHADER0([]() {
356 attribute vec4 a_position; 362 attribute vec4 a_position;
357 varying TexCoordPrecision vec2 v_texCoord; 363 varying TexCoordPrecision vec2 v_texCoord;
358 }); 364 });
359 } 365 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 dot(edge[2], screen_pos), dot(edge[3], screen_pos)) * 559 dot(edge[2], screen_pos), dot(edge[3], screen_pos)) *
554 gl_Position.w; 560 gl_Position.w;
555 edge_dist[1] = vec4(dot(edge[4], screen_pos), dot(edge[5], screen_pos), 561 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)) * 562 dot(edge[6], screen_pos), dot(edge[7], screen_pos)) *
557 gl_Position.w; 563 gl_Position.w;
558 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy; 564 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy;
559 } 565 }
560 }); 566 });
561 } 567 }
562 568
569 void VertexShaderQuadTexTransformAA::FillLocations(
570 ShaderLocations* locations) const {
571 locations->quad = quad_location();
572 locations->edge = edge_location();
573 locations->viewport = viewport_location();
574 locations->matrix = matrix_location();
575 locations->tex_transform = tex_transform_location();
576 }
577
578
563 VertexShaderTile::VertexShaderTile() 579 VertexShaderTile::VertexShaderTile()
564 : matrix_location_(-1), 580 : matrix_location_(-1),
565 quad_location_(-1), 581 quad_location_(-1),
566 vertex_tex_transform_location_(-1) { 582 vertex_tex_transform_location_(-1) {
567 } 583 }
568 584
569 void VertexShaderTile::Init(GLES2Interface* context, 585 void VertexShaderTile::Init(GLES2Interface* context,
570 unsigned program, 586 unsigned program,
571 int* base_uniform_index) { 587 int* base_uniform_index) {
572 static const char* uniforms[] = { 588 static const char* uniforms[] = {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 std::string VertexShaderVideoTransform::GetShaderBody() { 731 std::string VertexShaderVideoTransform::GetShaderBody() {
716 return SHADER0([]() { 732 return SHADER0([]() {
717 void main() { 733 void main() {
718 gl_Position = matrix * a_position; 734 gl_Position = matrix * a_position;
719 v_texCoord = 735 v_texCoord =
720 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); 736 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0));
721 } 737 }
722 }); 738 });
723 } 739 }
724 740
725 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" 741 #define BLEND_MODE_UNIFORMS "s_backdropTexture", \
726 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 2 : 0) 742 "s_originalBackdropTexture", \
743 "backdropRect"
744 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 3 : 0)
727 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ 745 #define BLEND_MODE_SET_LOCATIONS(X, POS) \
728 if (has_blend_mode()) { \ 746 if (has_blend_mode()) { \
729 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ 747 DCHECK_LT(static_cast<size_t>(POS) + 2, arraysize(X)); \
730 backdrop_location_ = locations[POS]; \ 748 backdrop_location_ = locations[POS]; \
731 backdrop_rect_location_ = locations[POS + 1]; \ 749 original_backdrop_location_ = locations[POS + 1]; \
750 backdrop_rect_location_ = locations[POS + 2]; \
732 } 751 }
733 752
734 FragmentTexBlendMode::FragmentTexBlendMode() 753 FragmentTexBlendMode::FragmentTexBlendMode()
735 : backdrop_location_(-1), 754 : backdrop_location_(-1),
755 original_backdrop_location_(-1),
736 backdrop_rect_location_(-1), 756 backdrop_rect_location_(-1),
737 blend_mode_(BLEND_MODE_NONE) { 757 blend_mode_(BLEND_MODE_NONE),
758 mask_for_background_(false) {
738 } 759 }
739 760
740 std::string FragmentTexBlendMode::SetBlendModeFunctions( 761 std::string FragmentTexBlendMode::SetBlendModeFunctions(
741 std::string shader_string) const { 762 std::string shader_string) const {
742 if (shader_string.find("ApplyBlendMode") == std::string::npos) 763 if (shader_string.find("ApplyBlendMode") == std::string::npos)
743 return shader_string; 764 return shader_string;
744 765
745 if (!has_blend_mode()) { 766 if (!has_blend_mode()) {
746 return "#define ApplyBlendMode(X) (X)\n" + shader_string; 767 return "#define ApplyBlendMode(X) (X)\n"
768 "#define ApplyBlendModeWithMask(X, Y) (X)\n" +
769 shader_string;
747 } 770 }
748 771
749 static const std::string kFunctionApplyBlendMode = SHADER0([]() { 772 static const std::string kFunctionApplyBlendMode = SHADER0([]() {
750 uniform sampler2D s_backdropTexture; 773 uniform sampler2D s_backdropTexture;
774 uniform sampler2D s_originalBackdropTexture;
751 uniform TexCoordPrecision vec4 backdropRect; 775 uniform TexCoordPrecision vec4 backdropRect;
752 776
753 vec4 GetBackdropColor() { 777 vec4 GetBackdropColor() {
754 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; 778 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy;
755 bgTexCoord.x /= backdropRect.z; 779 bgTexCoord.x /= backdropRect.z;
756 bgTexCoord.y /= backdropRect.w; 780 bgTexCoord.y /= backdropRect.w;
757 return texture2D(s_backdropTexture, bgTexCoord); 781 return texture2D(s_backdropTexture, bgTexCoord);
758 } 782 }
759 783
760 vec4 ApplyBlendMode(vec4 src) { 784 vec4 ApplyBlendMode(vec4 src) {
761 vec4 dst = GetBackdropColor(); 785 vec4 dst = GetBackdropColor();
762 return Blend(src, dst); 786 return Blend(src, dst);
763 } 787 }
788
789 vec4 GetBackdropColorWithMask(float mask) {
790 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy;
791 bgTexCoord.x /= backdropRect.z;
792 bgTexCoord.y /= backdropRect.w;
793 vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord);
794 vec4 original_backdrop = texture2D(s_originalBackdropTexture, bgTexCoord);
795 return mix(original_backdrop, backdrop, mask);
796 }
797
798 vec4 ApplyBlendModeWithMask(vec4 src, float mask) {
799 vec4 dst = GetBackdropColorWithMask(mask);
800 return Blend(src, dst);
801 }
764 }); 802 });
765 803
766 return "precision mediump float;" + GetHelperFunctions() + 804 return "precision mediump float;" + GetHelperFunctions() +
767 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; 805 GetBlendFunction() + kFunctionApplyBlendMode + shader_string;
768 } 806 }
769 807
770 std::string FragmentTexBlendMode::GetHelperFunctions() const { 808 std::string FragmentTexBlendMode::GetHelperFunctions() const {
771 static const std::string kFunctionHardLight = SHADER0([]() { 809 static const std::string kFunctionHardLight = SHADER0([]() {
772 vec3 hardLight(vec4 src, vec4 dst) { 810 vec3 hardLight(vec4 src, vec4 dst) {
773 vec3 result; 811 vec3 result;
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 1136
1099 std::string FragmentShaderRGBATexAlpha::GetShaderBody() { 1137 std::string FragmentShaderRGBATexAlpha::GetShaderBody() {
1100 return SHADER0([]() { 1138 return SHADER0([]() {
1101 void main() { 1139 void main() {
1102 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1140 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1103 gl_FragColor = ApplyBlendMode(texColor * alpha); 1141 gl_FragColor = ApplyBlendMode(texColor * alpha);
1104 } 1142 }
1105 }); 1143 });
1106 } 1144 }
1107 1145
1146 void FragmentShaderRGBATexAlpha::FillLocations(
1147 ShaderLocations* locations) const {
1148 locations->alpha = alpha_location();
1149 locations->backdrop = backdrop_location();
1150 locations->backdrop_rect = backdrop_rect_location();
1151 }
1152
1108 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( 1153 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString(
1109 TexCoordPrecision precision, 1154 TexCoordPrecision precision,
1110 SamplerType sampler) const { 1155 SamplerType sampler) const {
1111 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1156 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody());
1112 } 1157 }
1113 1158
1114 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderHead() { 1159 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderHead() {
1115 return SHADER0([]() { 1160 return SHADER0([]() {
1116 precision mediump float; 1161 precision mediump float;
1117 varying TexCoordPrecision vec2 v_texCoord; 1162 varying TexCoordPrecision vec2 v_texCoord;
(...skipping 11 matching lines...) Expand all
1129 float nonZeroAlpha = max(texColor.a, 0.00001); 1174 float nonZeroAlpha = max(texColor.a, 0.00001);
1130 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1175 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1131 texColor = colorMatrix * texColor + colorOffset; 1176 texColor = colorMatrix * texColor + colorOffset;
1132 texColor.rgb *= texColor.a; 1177 texColor.rgb *= texColor.a;
1133 texColor = clamp(texColor, 0.0, 1.0); 1178 texColor = clamp(texColor, 0.0, 1.0);
1134 gl_FragColor = ApplyBlendMode(texColor * alpha); 1179 gl_FragColor = ApplyBlendMode(texColor * alpha);
1135 } 1180 }
1136 }); 1181 });
1137 } 1182 }
1138 1183
1184 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations(
1185 ShaderLocations* locations) const {
1186 locations->alpha = alpha_location();
1187 locations->color_matrix = color_matrix_location();
1188 locations->color_offset = color_offset_location();
1189 locations->backdrop = backdrop_location();
1190 locations->backdrop_rect = backdrop_rect_location();
1191 }
1192
1139 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( 1193 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString(
1140 TexCoordPrecision precision, 1194 TexCoordPrecision precision,
1141 SamplerType sampler) const { 1195 SamplerType sampler) const {
1142 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1196 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody());
1143 } 1197 }
1144 1198
1145 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderHead() { 1199 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderHead() {
1146 return SHADER0([]() { 1200 return SHADER0([]() {
1147 precision mediump float; 1201 precision mediump float;
1148 varying TexCoordPrecision vec2 v_texCoord; 1202 varying TexCoordPrecision vec2 v_texCoord;
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 void main() { 1452 void main() {
1399 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1453 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1400 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1454 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1401 vec2 d2 = min(d4.xz, d4.yw); 1455 vec2 d2 = min(d4.xz, d4.yw);
1402 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1456 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1403 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); 1457 gl_FragColor = ApplyBlendMode(texColor * alpha * aa);
1404 } 1458 }
1405 }); 1459 });
1406 } 1460 }
1407 1461
1462 void FragmentShaderRGBATexAlphaAA::FillLocations(
1463 ShaderLocations* locations) const {
1464 locations->alpha = alpha_location();
1465 locations->backdrop = backdrop_location();
1466 locations->backdrop_rect = backdrop_rect_location();
1467 }
1468
1408 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() 1469 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding()
1409 : sampler_location_(-1), 1470 : sampler_location_(-1),
1410 alpha_location_(-1), 1471 alpha_location_(-1),
1411 fragment_tex_transform_location_(-1) { 1472 fragment_tex_transform_location_(-1) {
1412 } 1473 }
1413 1474
1414 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, 1475 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context,
1415 unsigned program, 1476 unsigned program,
1416 int* base_uniform_index) { 1477 int* base_uniform_index) {
1417 static const char* uniforms[] = { 1478 static const char* uniforms[] = {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 mask_sampler_location_ = locations[1]; 1586 mask_sampler_location_ = locations[1];
1526 alpha_location_ = locations[2]; 1587 alpha_location_ = locations[2];
1527 mask_tex_coord_scale_location_ = locations[3]; 1588 mask_tex_coord_scale_location_ = locations[3];
1528 mask_tex_coord_offset_location_ = locations[4]; 1589 mask_tex_coord_offset_location_ = locations[4];
1529 BLEND_MODE_SET_LOCATIONS(locations, 5); 1590 BLEND_MODE_SET_LOCATIONS(locations, 5);
1530 } 1591 }
1531 1592
1532 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( 1593 std::string FragmentShaderRGBATexAlphaMask::GetShaderString(
1533 TexCoordPrecision precision, 1594 TexCoordPrecision precision,
1534 SamplerType sampler) const { 1595 SamplerType sampler) const {
1535 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1596 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody(mask_for_background()));
1536 } 1597 }
1537 1598
1538 std::string FragmentShaderRGBATexAlphaMask::GetShaderHead() { 1599 std::string FragmentShaderRGBATexAlphaMask::GetShaderHead() {
1539 return SHADER0([]() { 1600 return SHADER0([]() {
1540 precision mediump float; 1601 precision mediump float;
1541 varying TexCoordPrecision vec2 v_texCoord; 1602 varying TexCoordPrecision vec2 v_texCoord;
1542 uniform sampler2D s_texture; 1603 uniform sampler2D s_texture;
1543 uniform SamplerType s_mask; 1604 uniform SamplerType s_mask;
1544 uniform TexCoordPrecision vec2 maskTexCoordScale; 1605 uniform TexCoordPrecision vec2 maskTexCoordScale;
1545 uniform TexCoordPrecision vec2 maskTexCoordOffset; 1606 uniform TexCoordPrecision vec2 maskTexCoordOffset;
1546 uniform float alpha; 1607 uniform float alpha;
1547 }); 1608 });
1548 } 1609 }
1549 1610
1550 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { 1611 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody(
1612 bool mask_for_background) {
1551 return SHADER0([]() { 1613 return SHADER0([]() {
1552 void main() { 1614 void main() {
1553 vec4 texColor = texture2D(s_texture, v_texCoord); 1615 vec4 texColor = texture2D(s_texture, v_texCoord);
1554 TexCoordPrecision vec2 maskTexCoord = 1616 TexCoordPrecision vec2 maskTexCoord =
1555 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1617 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1556 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1618 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1557 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1619 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); }) +
1558 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); 1620 (mask_for_background
1559 } 1621 ? SHADER0([]() { gl_FragColor = ApplyBlendModeWithMask(
1560 }); 1622 texColor * alpha * maskColor.w, maskColor.w); })
1623 : SHADER0([]() { gl_FragColor = ApplyBlendMode(
1624 texColor * alpha * maskColor.w); })) +
1625 SHADER0([]() {}});
1626 }
1627
1628 void FragmentShaderRGBATexAlphaMask::FillLocations(
1629 ShaderLocations* locations) const {
1630 locations->mask_sampler = mask_sampler_location();
1631 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1632 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1633 locations->alpha = alpha_location();
1634 locations->backdrop = backdrop_location();
1635 locations->backdrop_rect = backdrop_rect_location();
1636 if (mask_for_background())
1637 locations->original_backdrop = original_backdrop_location();
1561 } 1638 }
1562 1639
1563 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() 1640 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
1564 : sampler_location_(-1), 1641 : sampler_location_(-1),
1565 mask_sampler_location_(-1), 1642 mask_sampler_location_(-1),
1566 alpha_location_(-1), 1643 alpha_location_(-1),
1567 mask_tex_coord_scale_location_(-1), 1644 mask_tex_coord_scale_location_(-1),
1568 mask_tex_coord_offset_location_(-1) { 1645 mask_tex_coord_offset_location_(-1) {
1569 } 1646 }
1570 1647
(...skipping 20 matching lines...) Expand all
1591 mask_sampler_location_ = locations[1]; 1668 mask_sampler_location_ = locations[1];
1592 alpha_location_ = locations[2]; 1669 alpha_location_ = locations[2];
1593 mask_tex_coord_scale_location_ = locations[3]; 1670 mask_tex_coord_scale_location_ = locations[3];
1594 mask_tex_coord_offset_location_ = locations[4]; 1671 mask_tex_coord_offset_location_ = locations[4];
1595 BLEND_MODE_SET_LOCATIONS(locations, 5); 1672 BLEND_MODE_SET_LOCATIONS(locations, 5);
1596 } 1673 }
1597 1674
1598 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( 1675 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString(
1599 TexCoordPrecision precision, 1676 TexCoordPrecision precision,
1600 SamplerType sampler) const { 1677 SamplerType sampler) const {
1601 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1678 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody(mask_for_background()));
1602 } 1679 }
1603 1680
1604 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderHead() { 1681 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderHead() {
1605 return SHADER0([]() { 1682 return SHADER0([]() {
1606 precision mediump float; 1683 precision mediump float;
1607 uniform sampler2D s_texture; 1684 uniform sampler2D s_texture;
1608 uniform SamplerType s_mask; 1685 uniform SamplerType s_mask;
1609 uniform TexCoordPrecision vec2 maskTexCoordScale; 1686 uniform TexCoordPrecision vec2 maskTexCoordScale;
1610 uniform TexCoordPrecision vec2 maskTexCoordOffset; 1687 uniform TexCoordPrecision vec2 maskTexCoordOffset;
1611 uniform float alpha; 1688 uniform float alpha;
1612 varying TexCoordPrecision vec2 v_texCoord; 1689 varying TexCoordPrecision vec2 v_texCoord;
1613 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1690 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1614 }); 1691 });
1615 } 1692 }
1616 1693
1617 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderBody() { 1694 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderBody(
1695 bool mask_for_background) {
1618 return SHADER0([]() { 1696 return SHADER0([]() {
1619 void main() { 1697 void main() {
1620 vec4 texColor = texture2D(s_texture, v_texCoord); 1698 vec4 texColor = texture2D(s_texture, v_texCoord);
1621 TexCoordPrecision vec2 maskTexCoord = 1699 TexCoordPrecision vec2 maskTexCoord =
1622 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1700 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1623 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1701 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1624 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1702 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1625 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1703 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1626 vec2 d2 = min(d4.xz, d4.yw); 1704 vec2 d2 = min(d4.xz, d4.yw);
1627 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1705 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); }) +
1628 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); 1706 (mask_for_background
1629 } 1707 ? SHADER0([]() { gl_FragColor = ApplyBlendModeWithMask(
1630 }); 1708 texColor * alpha * maskColor.w * aa, maskColor.w); })
1709 : SHADER0([]() { gl_FragColor = ApplyBlendMode(
1710 texColor * alpha * maskColor.w * aa); })) +
1711 SHADER0([]() {}});
1712 }
1713
1714 void FragmentShaderRGBATexAlphaMaskAA::FillLocations(
1715 ShaderLocations* locations) const {
1716 locations->mask_sampler = mask_sampler_location();
1717 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1718 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1719 locations->alpha = alpha_location();
1720 locations->backdrop = backdrop_location();
1721 locations->backdrop_rect = backdrop_rect_location();
1722 if (mask_for_background())
1723 locations->original_backdrop = original_backdrop_location();
1631 } 1724 }
1632 1725
1633 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: 1726 FragmentShaderRGBATexAlphaMaskColorMatrixAA::
1634 FragmentShaderRGBATexAlphaMaskColorMatrixAA() 1727 FragmentShaderRGBATexAlphaMaskColorMatrixAA()
1635 : sampler_location_(-1), 1728 : sampler_location_(-1),
1636 mask_sampler_location_(-1), 1729 mask_sampler_location_(-1),
1637 alpha_location_(-1), 1730 alpha_location_(-1),
1638 mask_tex_coord_scale_location_(-1), 1731 mask_tex_coord_scale_location_(-1),
1639 color_matrix_location_(-1), 1732 color_matrix_location_(-1),
1640 color_offset_location_(-1) { 1733 color_offset_location_(-1) {
(...skipping 27 matching lines...) Expand all
1668 mask_tex_coord_scale_location_ = locations[3]; 1761 mask_tex_coord_scale_location_ = locations[3];
1669 mask_tex_coord_offset_location_ = locations[4]; 1762 mask_tex_coord_offset_location_ = locations[4];
1670 color_matrix_location_ = locations[5]; 1763 color_matrix_location_ = locations[5];
1671 color_offset_location_ = locations[6]; 1764 color_offset_location_ = locations[6];
1672 BLEND_MODE_SET_LOCATIONS(locations, 7); 1765 BLEND_MODE_SET_LOCATIONS(locations, 7);
1673 } 1766 }
1674 1767
1675 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( 1768 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString(
1676 TexCoordPrecision precision, 1769 TexCoordPrecision precision,
1677 SamplerType sampler) const { 1770 SamplerType sampler) const {
1678 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1771 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody(mask_for_background()));
1679 } 1772 }
1680 1773
1681 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderHead() { 1774 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderHead() {
1682 return SHADER0([]() { 1775 return SHADER0([]() {
1683 precision mediump float; 1776 precision mediump float;
1684 uniform sampler2D s_texture; 1777 uniform sampler2D s_texture;
1685 uniform SamplerType s_mask; 1778 uniform SamplerType s_mask;
1686 uniform vec2 maskTexCoordScale; 1779 uniform vec2 maskTexCoordScale;
1687 uniform vec2 maskTexCoordOffset; 1780 uniform vec2 maskTexCoordOffset;
1688 uniform mat4 colorMatrix; 1781 uniform mat4 colorMatrix;
1689 uniform vec4 colorOffset; 1782 uniform vec4 colorOffset;
1690 uniform float alpha; 1783 uniform float alpha;
1691 varying TexCoordPrecision vec2 v_texCoord; 1784 varying TexCoordPrecision vec2 v_texCoord;
1692 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1785 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1693 }); 1786 });
1694 } 1787 }
1695 1788
1696 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderBody() { 1789 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderBody(
1790 bool mask_for_background) {
1697 return SHADER0([]() { 1791 return SHADER0([]() {
1698 void main() { 1792 void main() {
1699 vec4 texColor = texture2D(s_texture, v_texCoord); 1793 vec4 texColor = texture2D(s_texture, v_texCoord);
1700 float nonZeroAlpha = max(texColor.a, 0.00001); 1794 float nonZeroAlpha = max(texColor.a, 0.00001);
1701 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1795 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1702 texColor = colorMatrix * texColor + colorOffset; 1796 texColor = colorMatrix * texColor + colorOffset;
1703 texColor.rgb *= texColor.a; 1797 texColor.rgb *= texColor.a;
1704 texColor = clamp(texColor, 0.0, 1.0); 1798 texColor = clamp(texColor, 0.0, 1.0);
1705 TexCoordPrecision vec2 maskTexCoord = 1799 TexCoordPrecision vec2 maskTexCoord =
1706 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1800 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1707 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1801 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1708 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1802 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1709 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1803 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1710 vec2 d2 = min(d4.xz, d4.yw); 1804 vec2 d2 = min(d4.xz, d4.yw);
1711 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1805 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); }) +
1712 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); 1806 (mask_for_background
1713 } 1807 ? SHADER0([]() { gl_FragColor = ApplyBlendModeWithMask(
1714 }); 1808 texColor * alpha * maskColor.w * aa, maskColor.w); })
1809 : SHADER0([]() { gl_FragColor = ApplyBlendMode(
1810 texColor * alpha * maskColor.w * aa); })) +
1811 SHADER0([]() {}});
1812 }
1813
1814 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations(
1815 ShaderLocations* locations) const {
1816 locations->alpha = alpha_location();
1817 locations->mask_sampler = mask_sampler_location();
1818 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1819 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1820 locations->color_matrix = color_matrix_location();
1821 locations->color_offset = color_offset_location();
1822 locations->backdrop = backdrop_location();
1823 locations->backdrop_rect = backdrop_rect_location();
1824 if (mask_for_background())
1825 locations->original_backdrop = original_backdrop_location();
1715 } 1826 }
1716 1827
1717 FragmentShaderRGBATexAlphaColorMatrixAA:: 1828 FragmentShaderRGBATexAlphaColorMatrixAA::
1718 FragmentShaderRGBATexAlphaColorMatrixAA() 1829 FragmentShaderRGBATexAlphaColorMatrixAA()
1719 : sampler_location_(-1), 1830 : sampler_location_(-1),
1720 alpha_location_(-1), 1831 alpha_location_(-1),
1721 color_matrix_location_(-1), 1832 color_matrix_location_(-1),
1722 color_offset_location_(-1) { 1833 color_offset_location_(-1) {
1723 } 1834 }
1724 1835
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 texColor.rgb *= texColor.a; 1882 texColor.rgb *= texColor.a;
1772 texColor = clamp(texColor, 0.0, 1.0); 1883 texColor = clamp(texColor, 0.0, 1.0);
1773 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1884 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1774 vec2 d2 = min(d4.xz, d4.yw); 1885 vec2 d2 = min(d4.xz, d4.yw);
1775 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1886 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1776 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); 1887 gl_FragColor = ApplyBlendMode(texColor * alpha * aa);
1777 } 1888 }
1778 }); 1889 });
1779 } 1890 }
1780 1891
1892 void FragmentShaderRGBATexAlphaColorMatrixAA::FillLocations(
1893 ShaderLocations* locations) const {
1894 locations->alpha = alpha_location();
1895 locations->color_matrix = color_matrix_location();
1896 locations->color_offset = color_offset_location();
1897 locations->backdrop = backdrop_location();
1898 locations->backdrop_rect = backdrop_rect_location();
1899 }
1900
1781 FragmentShaderRGBATexAlphaMaskColorMatrix:: 1901 FragmentShaderRGBATexAlphaMaskColorMatrix::
1782 FragmentShaderRGBATexAlphaMaskColorMatrix() 1902 FragmentShaderRGBATexAlphaMaskColorMatrix()
1783 : sampler_location_(-1), 1903 : sampler_location_(-1),
1784 mask_sampler_location_(-1), 1904 mask_sampler_location_(-1),
1785 alpha_location_(-1), 1905 alpha_location_(-1),
1786 mask_tex_coord_scale_location_(-1) { 1906 mask_tex_coord_scale_location_(-1) {
1787 } 1907 }
1788 1908
1789 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context, 1909 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context,
1790 unsigned program, 1910 unsigned program,
(...skipping 22 matching lines...) Expand all
1813 mask_tex_coord_scale_location_ = locations[3]; 1933 mask_tex_coord_scale_location_ = locations[3];
1814 mask_tex_coord_offset_location_ = locations[4]; 1934 mask_tex_coord_offset_location_ = locations[4];
1815 color_matrix_location_ = locations[5]; 1935 color_matrix_location_ = locations[5];
1816 color_offset_location_ = locations[6]; 1936 color_offset_location_ = locations[6];
1817 BLEND_MODE_SET_LOCATIONS(locations, 7); 1937 BLEND_MODE_SET_LOCATIONS(locations, 7);
1818 } 1938 }
1819 1939
1820 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( 1940 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString(
1821 TexCoordPrecision precision, 1941 TexCoordPrecision precision,
1822 SamplerType sampler) const { 1942 SamplerType sampler) const {
1823 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1943 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody(mask_for_background()));
1824 } 1944 }
1825 1945
1826 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderHead() { 1946 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderHead() {
1827 return SHADER0([]() { 1947 return SHADER0([]() {
1828 precision mediump float; 1948 precision mediump float;
1829 varying TexCoordPrecision vec2 v_texCoord; 1949 varying TexCoordPrecision vec2 v_texCoord;
1830 uniform sampler2D s_texture; 1950 uniform sampler2D s_texture;
1831 uniform SamplerType s_mask; 1951 uniform SamplerType s_mask;
1832 uniform vec2 maskTexCoordScale; 1952 uniform vec2 maskTexCoordScale;
1833 uniform vec2 maskTexCoordOffset; 1953 uniform vec2 maskTexCoordOffset;
1834 uniform mat4 colorMatrix; 1954 uniform mat4 colorMatrix;
1835 uniform vec4 colorOffset; 1955 uniform vec4 colorOffset;
1836 uniform float alpha; 1956 uniform float alpha;
1837 }); 1957 });
1838 } 1958 }
1839 1959
1840 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderBody() { 1960 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderBody(
1961 bool mask_for_background) {
1841 return SHADER0([]() { 1962 return SHADER0([]() {
1842 void main() { 1963 void main() {
1843 vec4 texColor = texture2D(s_texture, v_texCoord); 1964 vec4 texColor = texture2D(s_texture, v_texCoord);
1844 float nonZeroAlpha = max(texColor.a, 0.00001); 1965 float nonZeroAlpha = max(texColor.a, 0.00001);
1845 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1966 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1846 texColor = colorMatrix * texColor + colorOffset; 1967 texColor = colorMatrix * texColor + colorOffset;
1847 texColor.rgb *= texColor.a; 1968 texColor.rgb *= texColor.a;
1848 texColor = clamp(texColor, 0.0, 1.0); 1969 texColor = clamp(texColor, 0.0, 1.0);
1849 TexCoordPrecision vec2 maskTexCoord = 1970 TexCoordPrecision vec2 maskTexCoord =
1850 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1971 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1851 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1972 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1852 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1973 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); }) +
1853 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); 1974 (mask_for_background
1854 } 1975 ? SHADER0([]() { gl_FragColor = ApplyBlendModeWithMask(
1855 }); 1976 texColor * alpha * maskColor.w, maskColor.w); })
1977 : SHADER0([]() { gl_FragColor = ApplyBlendMode(
1978 texColor * alpha * maskColor.w); })) +
1979 SHADER0([]() {}});
1980 }
1981
1982 void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations(
1983 ShaderLocations* locations) const {
1984 locations->mask_sampler = mask_sampler_location();
1985 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1986 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1987 locations->alpha = alpha_location();
1988 locations->color_matrix = color_matrix_location();
1989 locations->color_offset = color_offset_location();
1990 locations->backdrop = backdrop_location();
1991 locations->backdrop_rect = backdrop_rect_location();
1992 if (mask_for_background())
1993 locations->original_backdrop = original_backdrop_location();
1856 } 1994 }
1857 1995
1858 FragmentShaderYUVVideo::FragmentShaderYUVVideo() 1996 FragmentShaderYUVVideo::FragmentShaderYUVVideo()
1859 : y_texture_location_(-1), 1997 : y_texture_location_(-1),
1860 u_texture_location_(-1), 1998 u_texture_location_(-1),
1861 v_texture_location_(-1), 1999 v_texture_location_(-1),
1862 alpha_location_(-1), 2000 alpha_location_(-1),
1863 yuv_matrix_location_(-1), 2001 yuv_matrix_location_(-1),
1864 yuv_adj_location_(-1), 2002 yuv_adj_location_(-1),
1865 clamp_rect_location_(-1) { 2003 clamp_rect_location_(-1) {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 vec2 texCoord = 2278 vec2 texCoord =
2141 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; 2279 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy;
2142 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 2280 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
2143 float picker = abs(coord.x - coord.y); // NOLINT 2281 float picker = abs(coord.x - coord.y); // NOLINT
2144 gl_FragColor = mix(color1, color2, picker) * alpha; 2282 gl_FragColor = mix(color1, color2, picker) * alpha;
2145 } 2283 }
2146 }); 2284 });
2147 } 2285 }
2148 2286
2149 } // namespace cc 2287 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698