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

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: rebase 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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) (X)\n"
771 "#define ApplyBlendModeWithMask(X, Y) (X)\n" +
772 shader_string;
766 } 773 }
767 774
768 static const std::string kFunctionApplyBlendMode = SHADER0([]() { 775 static const std::string kFunctionApplyBlendMode = SHADER0([]() {
769 uniform sampler2D s_backdropTexture; 776 uniform sampler2D s_backdropTexture;
777 uniform sampler2D s_originalBackdropTexture;
770 uniform TexCoordPrecision vec4 backdropRect; 778 uniform TexCoordPrecision vec4 backdropRect;
771 779
772 vec4 GetBackdropColor() { 780 vec4 GetBackdropColor() {
773 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; 781 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy;
774 bgTexCoord.x /= backdropRect.z; 782 bgTexCoord.x /= backdropRect.z;
775 bgTexCoord.y /= backdropRect.w; 783 bgTexCoord.y /= backdropRect.w;
776 return texture2D(s_backdropTexture, bgTexCoord); 784 return texture2D(s_backdropTexture, bgTexCoord);
777 } 785 }
778 786
779 vec4 ApplyBlendMode(vec4 src) { 787 vec4 ApplyBlendMode(vec4 src) {
780 vec4 dst = GetBackdropColor(); 788 vec4 dst = GetBackdropColor();
781 return Blend(src, dst); 789 return Blend(src, dst);
782 } 790 }
791
792 vec4 GetBackdropColorWithMask(float mask) {
793 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy;
794 bgTexCoord.x /= backdropRect.z;
795 bgTexCoord.y /= backdropRect.w;
796 vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord);
797 vec4 original_backdrop = texture2D(s_originalBackdropTexture, bgTexCoord);
enne (OOO) 2015/03/03 23:27:47 Would it be more precise to call this unfiltered,
798 return mix(original_backdrop, backdrop, mask);
799 }
800
801 vec4 ApplyBlendModeWithMask(vec4 src, float mask) {
802 vec4 dst = GetBackdropColorWithMask(mask);
803 return Blend(src, dst);
804 }
783 }); 805 });
784 806
785 return "precision mediump float;" + GetHelperFunctions() + 807 return "precision mediump float;" + GetHelperFunctions() +
786 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; 808 GetBlendFunction() + kFunctionApplyBlendMode + shader_string;
787 } 809 }
788 810
789 std::string FragmentTexBlendMode::GetHelperFunctions() const { 811 std::string FragmentTexBlendMode::GetHelperFunctions() const {
790 static const std::string kFunctionHardLight = SHADER0([]() { 812 static const std::string kFunctionHardLight = SHADER0([]() {
791 vec3 hardLight(vec4 src, vec4 dst) { 813 vec3 hardLight(vec4 src, vec4 dst) {
792 vec3 result; 814 vec3 result;
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 mask_sampler_location_ = locations[1]; 1592 mask_sampler_location_ = locations[1];
1571 alpha_location_ = locations[2]; 1593 alpha_location_ = locations[2];
1572 mask_tex_coord_scale_location_ = locations[3]; 1594 mask_tex_coord_scale_location_ = locations[3];
1573 mask_tex_coord_offset_location_ = locations[4]; 1595 mask_tex_coord_offset_location_ = locations[4];
1574 BLEND_MODE_SET_LOCATIONS(locations, 5); 1596 BLEND_MODE_SET_LOCATIONS(locations, 5);
1575 } 1597 }
1576 1598
1577 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( 1599 std::string FragmentShaderRGBATexAlphaMask::GetShaderString(
1578 TexCoordPrecision precision, 1600 TexCoordPrecision precision,
1579 SamplerType sampler) const { 1601 SamplerType sampler) const {
1580 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1602 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody(mask_for_background()));
1581 } 1603 }
1582 1604
1583 std::string FragmentShaderRGBATexAlphaMask::GetShaderHead() { 1605 std::string FragmentShaderRGBATexAlphaMask::GetShaderHead() {
1584 return SHADER0([]() { 1606 return SHADER0([]() {
1585 precision mediump float; 1607 precision mediump float;
1586 varying TexCoordPrecision vec2 v_texCoord; 1608 varying TexCoordPrecision vec2 v_texCoord;
1587 uniform sampler2D s_texture; 1609 uniform sampler2D s_texture;
1588 uniform SamplerType s_mask; 1610 uniform SamplerType s_mask;
1589 uniform TexCoordPrecision vec2 maskTexCoordScale; 1611 uniform TexCoordPrecision vec2 maskTexCoordScale;
1590 uniform TexCoordPrecision vec2 maskTexCoordOffset; 1612 uniform TexCoordPrecision vec2 maskTexCoordOffset;
1591 uniform float alpha; 1613 uniform float alpha;
1592 }); 1614 });
1593 } 1615 }
1594 1616
1595 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { 1617 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody(
1618 bool mask_for_background) {
1596 return SHADER0([]() { 1619 return SHADER0([]() {
1597 void main() { 1620 void main() {
1598 vec4 texColor = texture2D(s_texture, v_texCoord); 1621 vec4 texColor = texture2D(s_texture, v_texCoord);
1599 TexCoordPrecision vec2 maskTexCoord = 1622 TexCoordPrecision vec2 maskTexCoord =
1600 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1623 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1601 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1624 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1602 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1625 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); }) +
1603 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); 1626 (mask_for_background
1604 } 1627 ? SHADER0([]() { gl_FragColor = ApplyBlendModeWithMask(
1605 }); 1628 texColor * alpha * maskColor.w, maskColor.w); })
1629 : SHADER0([]() { gl_FragColor = ApplyBlendMode(
1630 texColor * alpha * maskColor.w); })) +
1631 SHADER0([]() {}});
1606 } 1632 }
1607 1633
1608 void FragmentShaderRGBATexAlphaMask::FillLocations( 1634 void FragmentShaderRGBATexAlphaMask::FillLocations(
1609 ShaderLocations* locations) const { 1635 ShaderLocations* locations) const {
1610 locations->sampler = sampler_location(); 1636 locations->sampler = sampler_location();
1611 locations->mask_sampler = mask_sampler_location(); 1637 locations->mask_sampler = mask_sampler_location();
1612 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); 1638 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1613 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); 1639 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1614 locations->alpha = alpha_location(); 1640 locations->alpha = alpha_location();
1615 locations->backdrop = backdrop_location(); 1641 locations->backdrop = backdrop_location();
1616 locations->backdrop_rect = backdrop_rect_location(); 1642 locations->backdrop_rect = backdrop_rect_location();
1643 if (mask_for_background())
1644 locations->original_backdrop = original_backdrop_location();
1617 } 1645 }
1618 1646
1619 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() 1647 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
1620 : sampler_location_(-1), 1648 : sampler_location_(-1),
1621 mask_sampler_location_(-1), 1649 mask_sampler_location_(-1),
1622 alpha_location_(-1), 1650 alpha_location_(-1),
1623 mask_tex_coord_scale_location_(-1), 1651 mask_tex_coord_scale_location_(-1),
1624 mask_tex_coord_offset_location_(-1) { 1652 mask_tex_coord_offset_location_(-1) {
1625 } 1653 }
1626 1654
(...skipping 20 matching lines...) Expand all
1647 mask_sampler_location_ = locations[1]; 1675 mask_sampler_location_ = locations[1];
1648 alpha_location_ = locations[2]; 1676 alpha_location_ = locations[2];
1649 mask_tex_coord_scale_location_ = locations[3]; 1677 mask_tex_coord_scale_location_ = locations[3];
1650 mask_tex_coord_offset_location_ = locations[4]; 1678 mask_tex_coord_offset_location_ = locations[4];
1651 BLEND_MODE_SET_LOCATIONS(locations, 5); 1679 BLEND_MODE_SET_LOCATIONS(locations, 5);
1652 } 1680 }
1653 1681
1654 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( 1682 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString(
1655 TexCoordPrecision precision, 1683 TexCoordPrecision precision,
1656 SamplerType sampler) const { 1684 SamplerType sampler) const {
1657 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1685 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody(mask_for_background()));
1658 } 1686 }
1659 1687
1660 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderHead() { 1688 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderHead() {
1661 return SHADER0([]() { 1689 return SHADER0([]() {
1662 precision mediump float; 1690 precision mediump float;
1663 uniform sampler2D s_texture; 1691 uniform sampler2D s_texture;
1664 uniform SamplerType s_mask; 1692 uniform SamplerType s_mask;
1665 uniform TexCoordPrecision vec2 maskTexCoordScale; 1693 uniform TexCoordPrecision vec2 maskTexCoordScale;
1666 uniform TexCoordPrecision vec2 maskTexCoordOffset; 1694 uniform TexCoordPrecision vec2 maskTexCoordOffset;
1667 uniform float alpha; 1695 uniform float alpha;
1668 varying TexCoordPrecision vec2 v_texCoord; 1696 varying TexCoordPrecision vec2 v_texCoord;
1669 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1697 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1670 }); 1698 });
1671 } 1699 }
1672 1700
1673 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderBody() { 1701 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderBody(
1702 bool mask_for_background) {
1674 return SHADER0([]() { 1703 return SHADER0([]() {
1675 void main() { 1704 void main() {
1676 vec4 texColor = texture2D(s_texture, v_texCoord); 1705 vec4 texColor = texture2D(s_texture, v_texCoord);
1677 TexCoordPrecision vec2 maskTexCoord = 1706 TexCoordPrecision vec2 maskTexCoord =
1678 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1707 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1679 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1708 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1680 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1709 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1681 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1710 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1682 vec2 d2 = min(d4.xz, d4.yw); 1711 vec2 d2 = min(d4.xz, d4.yw);
1683 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1712 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); }) +
1684 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); 1713 (mask_for_background
1685 } 1714 ? SHADER0([]() { gl_FragColor = ApplyBlendModeWithMask(
1686 }); 1715 texColor * alpha * maskColor.w * aa, maskColor.w); })
1716 : SHADER0([]() { gl_FragColor = ApplyBlendMode(
1717 texColor * alpha * maskColor.w * aa); })) +
1718 SHADER0([]() {}});
1687 } 1719 }
1688 1720
1689 void FragmentShaderRGBATexAlphaMaskAA::FillLocations( 1721 void FragmentShaderRGBATexAlphaMaskAA::FillLocations(
1690 ShaderLocations* locations) const { 1722 ShaderLocations* locations) const {
1691 locations->sampler = sampler_location(); 1723 locations->sampler = sampler_location();
1692 locations->mask_sampler = mask_sampler_location(); 1724 locations->mask_sampler = mask_sampler_location();
1693 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); 1725 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1694 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); 1726 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1695 locations->alpha = alpha_location(); 1727 locations->alpha = alpha_location();
1696 locations->backdrop = backdrop_location(); 1728 locations->backdrop = backdrop_location();
1697 locations->backdrop_rect = backdrop_rect_location(); 1729 locations->backdrop_rect = backdrop_rect_location();
1730 if (mask_for_background())
1731 locations->original_backdrop = original_backdrop_location();
1698 } 1732 }
1699 1733
1700 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: 1734 FragmentShaderRGBATexAlphaMaskColorMatrixAA::
1701 FragmentShaderRGBATexAlphaMaskColorMatrixAA() 1735 FragmentShaderRGBATexAlphaMaskColorMatrixAA()
1702 : sampler_location_(-1), 1736 : sampler_location_(-1),
1703 mask_sampler_location_(-1), 1737 mask_sampler_location_(-1),
1704 alpha_location_(-1), 1738 alpha_location_(-1),
1705 mask_tex_coord_scale_location_(-1), 1739 mask_tex_coord_scale_location_(-1),
1706 color_matrix_location_(-1), 1740 color_matrix_location_(-1),
1707 color_offset_location_(-1) { 1741 color_offset_location_(-1) {
(...skipping 27 matching lines...) Expand all
1735 mask_tex_coord_scale_location_ = locations[3]; 1769 mask_tex_coord_scale_location_ = locations[3];
1736 mask_tex_coord_offset_location_ = locations[4]; 1770 mask_tex_coord_offset_location_ = locations[4];
1737 color_matrix_location_ = locations[5]; 1771 color_matrix_location_ = locations[5];
1738 color_offset_location_ = locations[6]; 1772 color_offset_location_ = locations[6];
1739 BLEND_MODE_SET_LOCATIONS(locations, 7); 1773 BLEND_MODE_SET_LOCATIONS(locations, 7);
1740 } 1774 }
1741 1775
1742 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( 1776 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString(
1743 TexCoordPrecision precision, 1777 TexCoordPrecision precision,
1744 SamplerType sampler) const { 1778 SamplerType sampler) const {
1745 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1779 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody(mask_for_background()));
1746 } 1780 }
1747 1781
1748 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderHead() { 1782 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderHead() {
1749 return SHADER0([]() { 1783 return SHADER0([]() {
1750 precision mediump float; 1784 precision mediump float;
1751 uniform sampler2D s_texture; 1785 uniform sampler2D s_texture;
1752 uniform SamplerType s_mask; 1786 uniform SamplerType s_mask;
1753 uniform vec2 maskTexCoordScale; 1787 uniform vec2 maskTexCoordScale;
1754 uniform vec2 maskTexCoordOffset; 1788 uniform vec2 maskTexCoordOffset;
1755 uniform mat4 colorMatrix; 1789 uniform mat4 colorMatrix;
1756 uniform vec4 colorOffset; 1790 uniform vec4 colorOffset;
1757 uniform float alpha; 1791 uniform float alpha;
1758 varying TexCoordPrecision vec2 v_texCoord; 1792 varying TexCoordPrecision vec2 v_texCoord;
1759 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1793 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1760 }); 1794 });
1761 } 1795 }
1762 1796
1763 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderBody() { 1797 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderBody(
1798 bool mask_for_background) {
1764 return SHADER0([]() { 1799 return SHADER0([]() {
1765 void main() { 1800 void main() {
1766 vec4 texColor = texture2D(s_texture, v_texCoord); 1801 vec4 texColor = texture2D(s_texture, v_texCoord);
1767 float nonZeroAlpha = max(texColor.a, 0.00001); 1802 float nonZeroAlpha = max(texColor.a, 0.00001);
1768 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1803 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1769 texColor = colorMatrix * texColor + colorOffset; 1804 texColor = colorMatrix * texColor + colorOffset;
1770 texColor.rgb *= texColor.a; 1805 texColor.rgb *= texColor.a;
1771 texColor = clamp(texColor, 0.0, 1.0); 1806 texColor = clamp(texColor, 0.0, 1.0);
1772 TexCoordPrecision vec2 maskTexCoord = 1807 TexCoordPrecision vec2 maskTexCoord =
1773 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1808 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1774 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1809 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1775 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1810 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1776 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1811 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1777 vec2 d2 = min(d4.xz, d4.yw); 1812 vec2 d2 = min(d4.xz, d4.yw);
1778 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1813 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); }) +
1779 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); 1814 (mask_for_background
1780 } 1815 ? SHADER0([]() { gl_FragColor = ApplyBlendModeWithMask(
enne (OOO) 2015/03/03 23:27:47 Can you make this easier to read and reduce the co
1781 }); 1816 texColor * alpha * maskColor.w * aa, maskColor.w); })
1817 : SHADER0([]() { gl_FragColor = ApplyBlendMode(
1818 texColor * alpha * maskColor.w * aa); })) +
1819 SHADER0([]() {}});
1782 } 1820 }
1783 1821
1784 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations( 1822 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations(
1785 ShaderLocations* locations) const { 1823 ShaderLocations* locations) const {
1786 locations->sampler = sampler_location(); 1824 locations->sampler = sampler_location();
1787 locations->alpha = alpha_location(); 1825 locations->alpha = alpha_location();
1788 locations->mask_sampler = mask_sampler_location(); 1826 locations->mask_sampler = mask_sampler_location();
1789 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); 1827 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1790 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); 1828 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1791 locations->color_matrix = color_matrix_location(); 1829 locations->color_matrix = color_matrix_location();
1792 locations->color_offset = color_offset_location(); 1830 locations->color_offset = color_offset_location();
1793 locations->backdrop = backdrop_location(); 1831 locations->backdrop = backdrop_location();
1794 locations->backdrop_rect = backdrop_rect_location(); 1832 locations->backdrop_rect = backdrop_rect_location();
1833 if (mask_for_background())
1834 locations->original_backdrop = original_backdrop_location();
1795 } 1835 }
1796 1836
1797 FragmentShaderRGBATexAlphaColorMatrixAA:: 1837 FragmentShaderRGBATexAlphaColorMatrixAA::
1798 FragmentShaderRGBATexAlphaColorMatrixAA() 1838 FragmentShaderRGBATexAlphaColorMatrixAA()
1799 : sampler_location_(-1), 1839 : sampler_location_(-1),
1800 alpha_location_(-1), 1840 alpha_location_(-1),
1801 color_matrix_location_(-1), 1841 color_matrix_location_(-1),
1802 color_offset_location_(-1) { 1842 color_offset_location_(-1) {
1803 } 1843 }
1804 1844
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 mask_tex_coord_scale_location_ = locations[3]; 1943 mask_tex_coord_scale_location_ = locations[3];
1904 mask_tex_coord_offset_location_ = locations[4]; 1944 mask_tex_coord_offset_location_ = locations[4];
1905 color_matrix_location_ = locations[5]; 1945 color_matrix_location_ = locations[5];
1906 color_offset_location_ = locations[6]; 1946 color_offset_location_ = locations[6];
1907 BLEND_MODE_SET_LOCATIONS(locations, 7); 1947 BLEND_MODE_SET_LOCATIONS(locations, 7);
1908 } 1948 }
1909 1949
1910 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( 1950 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString(
1911 TexCoordPrecision precision, 1951 TexCoordPrecision precision,
1912 SamplerType sampler) const { 1952 SamplerType sampler) const {
1913 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); 1953 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody(mask_for_background()));
1914 } 1954 }
1915 1955
1916 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderHead() { 1956 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderHead() {
1917 return SHADER0([]() { 1957 return SHADER0([]() {
1918 precision mediump float; 1958 precision mediump float;
1919 varying TexCoordPrecision vec2 v_texCoord; 1959 varying TexCoordPrecision vec2 v_texCoord;
1920 uniform sampler2D s_texture; 1960 uniform sampler2D s_texture;
1921 uniform SamplerType s_mask; 1961 uniform SamplerType s_mask;
1922 uniform vec2 maskTexCoordScale; 1962 uniform vec2 maskTexCoordScale;
1923 uniform vec2 maskTexCoordOffset; 1963 uniform vec2 maskTexCoordOffset;
1924 uniform mat4 colorMatrix; 1964 uniform mat4 colorMatrix;
1925 uniform vec4 colorOffset; 1965 uniform vec4 colorOffset;
1926 uniform float alpha; 1966 uniform float alpha;
1927 }); 1967 });
1928 } 1968 }
1929 1969
1930 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderBody() { 1970 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderBody(
1971 bool mask_for_background) {
1931 return SHADER0([]() { 1972 return SHADER0([]() {
1932 void main() { 1973 void main() {
1933 vec4 texColor = texture2D(s_texture, v_texCoord); 1974 vec4 texColor = texture2D(s_texture, v_texCoord);
1934 float nonZeroAlpha = max(texColor.a, 0.00001); 1975 float nonZeroAlpha = max(texColor.a, 0.00001);
1935 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1976 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1936 texColor = colorMatrix * texColor + colorOffset; 1977 texColor = colorMatrix * texColor + colorOffset;
1937 texColor.rgb *= texColor.a; 1978 texColor.rgb *= texColor.a;
1938 texColor = clamp(texColor, 0.0, 1.0); 1979 texColor = clamp(texColor, 0.0, 1.0);
1939 TexCoordPrecision vec2 maskTexCoord = 1980 TexCoordPrecision vec2 maskTexCoord =
1940 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1981 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1941 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1982 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1942 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1983 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); }) +
1943 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); 1984 (mask_for_background
1944 } 1985 ? SHADER0([]() { gl_FragColor = ApplyBlendModeWithMask(
1945 }); 1986 texColor * alpha * maskColor.w, maskColor.w); })
1987 : SHADER0([]() { gl_FragColor = ApplyBlendMode(
1988 texColor * alpha * maskColor.w); })) +
1989 SHADER0([]() {}});
1946 } 1990 }
1947 1991
1948 void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations( 1992 void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations(
1949 ShaderLocations* locations) const { 1993 ShaderLocations* locations) const {
1950 locations->sampler = sampler_location(); 1994 locations->sampler = sampler_location();
1951 locations->mask_sampler = mask_sampler_location(); 1995 locations->mask_sampler = mask_sampler_location();
1952 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); 1996 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1953 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); 1997 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1954 locations->alpha = alpha_location(); 1998 locations->alpha = alpha_location();
1955 locations->color_matrix = color_matrix_location(); 1999 locations->color_matrix = color_matrix_location();
1956 locations->color_offset = color_offset_location(); 2000 locations->color_offset = color_offset_location();
1957 locations->backdrop = backdrop_location(); 2001 locations->backdrop = backdrop_location();
1958 locations->backdrop_rect = backdrop_rect_location(); 2002 locations->backdrop_rect = backdrop_rect_location();
2003 if (mask_for_background())
2004 locations->original_backdrop = original_backdrop_location();
1959 } 2005 }
1960 2006
1961 FragmentShaderYUVVideo::FragmentShaderYUVVideo() 2007 FragmentShaderYUVVideo::FragmentShaderYUVVideo()
1962 : y_texture_location_(-1), 2008 : y_texture_location_(-1),
1963 u_texture_location_(-1), 2009 u_texture_location_(-1),
1964 v_texture_location_(-1), 2010 v_texture_location_(-1),
1965 alpha_location_(-1), 2011 alpha_location_(-1),
1966 yuv_matrix_location_(-1), 2012 yuv_matrix_location_(-1),
1967 yuv_adj_location_(-1), 2013 yuv_adj_location_(-1),
1968 clamp_rect_location_(-1) { 2014 clamp_rect_location_(-1) {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 vec2 texCoord = 2289 vec2 texCoord =
2244 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; 2290 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy;
2245 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 2291 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
2246 float picker = abs(coord.x - coord.y); // NOLINT 2292 float picker = abs(coord.x - coord.y); // NOLINT
2247 gl_FragColor = mix(color1, color2, picker) * alpha; 2293 gl_FragColor = mix(color1, color2, picker) * alpha;
2248 } 2294 }
2249 }); 2295 });
2250 } 2296 }
2251 2297
2252 } // namespace cc 2298 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698