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

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

Issue 881963002: Clamp YUV videos to their visible size in the shader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: danakj review, build fix Created 5 years, 10 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
« no previous file with comments | « cc/output/shader.h ('k') | cc/quads/draw_quad_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 ); // NOLINT(whitespace/parens) 1734 ); // NOLINT(whitespace/parens)
1735 // clang-format on 1735 // clang-format on
1736 } 1736 }
1737 1737
1738 FragmentShaderYUVVideo::FragmentShaderYUVVideo() 1738 FragmentShaderYUVVideo::FragmentShaderYUVVideo()
1739 : y_texture_location_(-1), 1739 : y_texture_location_(-1),
1740 u_texture_location_(-1), 1740 u_texture_location_(-1),
1741 v_texture_location_(-1), 1741 v_texture_location_(-1),
1742 alpha_location_(-1), 1742 alpha_location_(-1),
1743 yuv_matrix_location_(-1), 1743 yuv_matrix_location_(-1),
1744 yuv_adj_location_(-1) { 1744 yuv_adj_location_(-1),
1745 clamp_rect_location_(-1) {
1745 } 1746 }
1746 1747
1747 void FragmentShaderYUVVideo::Init(GLES2Interface* context, 1748 void FragmentShaderYUVVideo::Init(GLES2Interface* context,
1748 unsigned program, 1749 unsigned program,
1749 int* base_uniform_index) { 1750 int* base_uniform_index) {
1750 static const char* uniforms[] = { 1751 static const char* uniforms[] = {"y_texture",
1751 "y_texture", "u_texture", "v_texture", "alpha", "yuv_matrix", "yuv_adj", 1752 "u_texture",
1752 }; 1753 "v_texture",
1754 "alpha",
1755 "yuv_matrix",
1756 "yuv_adj",
1757 "clamp_rect"};
1753 int locations[arraysize(uniforms)]; 1758 int locations[arraysize(uniforms)];
1754 1759
1755 GetProgramUniformLocations(context, 1760 GetProgramUniformLocations(context,
1756 program, 1761 program,
1757 arraysize(uniforms), 1762 arraysize(uniforms),
1758 uniforms, 1763 uniforms,
1759 locations, 1764 locations,
1760 base_uniform_index); 1765 base_uniform_index);
1761 y_texture_location_ = locations[0]; 1766 y_texture_location_ = locations[0];
1762 u_texture_location_ = locations[1]; 1767 u_texture_location_ = locations[1];
1763 v_texture_location_ = locations[2]; 1768 v_texture_location_ = locations[2];
1764 alpha_location_ = locations[3]; 1769 alpha_location_ = locations[3];
1765 yuv_matrix_location_ = locations[4]; 1770 yuv_matrix_location_ = locations[4];
1766 yuv_adj_location_ = locations[5]; 1771 yuv_adj_location_ = locations[5];
1772 clamp_rect_location_ = locations[6];
1767 } 1773 }
1768 1774
1769 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, 1775 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision,
1770 SamplerType sampler) const { 1776 SamplerType sampler) const {
1771 // clang-format off 1777 // clang-format off
1772 return FRAGMENT_SHADER( 1778 return FRAGMENT_SHADER(
1773 // clang-format on 1779 // clang-format on
1774 precision mediump float; 1780 precision mediump float;
1775 precision mediump int; 1781 precision mediump int;
1776 varying TexCoordPrecision vec2 v_texCoord; 1782 varying TexCoordPrecision vec2 v_texCoord;
1777 uniform SamplerType y_texture; 1783 uniform SamplerType y_texture;
1778 uniform SamplerType u_texture; 1784 uniform SamplerType u_texture;
1779 uniform SamplerType v_texture; 1785 uniform SamplerType v_texture;
1780 uniform float alpha; 1786 uniform float alpha;
1781 uniform vec3 yuv_adj; 1787 uniform vec3 yuv_adj;
1782 uniform mat3 yuv_matrix; 1788 uniform mat3 yuv_matrix;
1789 uniform vec4 clamp_rect;
1783 void main() { 1790 void main() {
1784 float y_raw = TextureLookup(y_texture, v_texCoord).x; 1791 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord));
1785 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; 1792 float y_raw = TextureLookup(y_texture, clamped).x;
1786 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; 1793 float u_unsigned = TextureLookup(u_texture, clamped).x;
1794 float v_unsigned = TextureLookup(v_texture, clamped).x;
1787 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; 1795 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj;
1788 vec3 rgb = yuv_matrix * yuv; 1796 vec3 rgb = yuv_matrix * yuv;
1789 gl_FragColor = vec4(rgb, 1.0) * alpha; 1797 gl_FragColor = vec4(rgb, 1.0) * alpha;
1790 } 1798 }
1791 // clang-format off 1799 // clang-format off
1792 ); // NOLINT(whitespace/parens) 1800 ); // NOLINT(whitespace/parens)
1793 // clang-format on 1801 // clang-format on
1794 } 1802 }
1795 1803
1796 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() 1804 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo()
(...skipping 10 matching lines...) Expand all
1807 unsigned program, 1815 unsigned program,
1808 int* base_uniform_index) { 1816 int* base_uniform_index) {
1809 static const char* uniforms[] = { 1817 static const char* uniforms[] = {
1810 "y_texture", 1818 "y_texture",
1811 "u_texture", 1819 "u_texture",
1812 "v_texture", 1820 "v_texture",
1813 "a_texture", 1821 "a_texture",
1814 "alpha", 1822 "alpha",
1815 "cc_matrix", 1823 "cc_matrix",
1816 "yuv_adj", 1824 "yuv_adj",
1825 "clamp_rect",
1817 }; 1826 };
1818 int locations[arraysize(uniforms)]; 1827 int locations[arraysize(uniforms)];
1819 1828
1820 GetProgramUniformLocations(context, 1829 GetProgramUniformLocations(context,
1821 program, 1830 program,
1822 arraysize(uniforms), 1831 arraysize(uniforms),
1823 uniforms, 1832 uniforms,
1824 locations, 1833 locations,
1825 base_uniform_index); 1834 base_uniform_index);
1826 y_texture_location_ = locations[0]; 1835 y_texture_location_ = locations[0];
1827 u_texture_location_ = locations[1]; 1836 u_texture_location_ = locations[1];
1828 v_texture_location_ = locations[2]; 1837 v_texture_location_ = locations[2];
1829 a_texture_location_ = locations[3]; 1838 a_texture_location_ = locations[3];
1830 alpha_location_ = locations[4]; 1839 alpha_location_ = locations[4];
1831 yuv_matrix_location_ = locations[5]; 1840 yuv_matrix_location_ = locations[5];
1832 yuv_adj_location_ = locations[6]; 1841 yuv_adj_location_ = locations[6];
1842 clamp_rect_location_ = locations[7];
1833 } 1843 }
1834 1844
1835 std::string FragmentShaderYUVAVideo::GetShaderString( 1845 std::string FragmentShaderYUVAVideo::GetShaderString(
1836 TexCoordPrecision precision, 1846 TexCoordPrecision precision,
1837 SamplerType sampler) const { 1847 SamplerType sampler) const {
1838 // clang-format off 1848 // clang-format off
1839 return FRAGMENT_SHADER( 1849 return FRAGMENT_SHADER(
1840 // clang-format on 1850 // clang-format on
1841 precision mediump float; 1851 precision mediump float;
1842 precision mediump int; 1852 precision mediump int;
1843 varying TexCoordPrecision vec2 v_texCoord; 1853 varying TexCoordPrecision vec2 v_texCoord;
1844 uniform SamplerType y_texture; 1854 uniform SamplerType y_texture;
1845 uniform SamplerType u_texture; 1855 uniform SamplerType u_texture;
1846 uniform SamplerType v_texture; 1856 uniform SamplerType v_texture;
1847 uniform SamplerType a_texture; 1857 uniform SamplerType a_texture;
1848 uniform float alpha; 1858 uniform float alpha;
1849 uniform vec3 yuv_adj; 1859 uniform vec3 yuv_adj;
1850 uniform mat3 yuv_matrix; 1860 uniform mat3 yuv_matrix;
1861 uniform vec4 clamp_rect;
1851 void main() { 1862 void main() {
1852 float y_raw = TextureLookup(y_texture, v_texCoord).x; 1863 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord));
1853 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; 1864 float y_raw = TextureLookup(y_texture, clamped).x;
1854 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; 1865 float u_unsigned = TextureLookup(u_texture, clamped).x;
1855 float a_raw = TextureLookup(a_texture, v_texCoord).x; 1866 float v_unsigned = TextureLookup(v_texture, clamped).x;
1867 float a_raw = TextureLookup(a_texture, clamped).x;
1856 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; 1868 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj;
1857 vec3 rgb = yuv_matrix * yuv; 1869 vec3 rgb = yuv_matrix * yuv;
1858 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); 1870 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw);
1859 } 1871 }
1860 // clang-format off 1872 // clang-format off
1861 ); // NOLINT(whitespace/parens) 1873 ); // NOLINT(whitespace/parens)
1862 // clang-format on 1874 // clang-format on
1863 } 1875 }
1864 1876
1865 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { 1877 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 1996 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
1985 float picker = abs(coord.x - coord.y); // NOLINT 1997 float picker = abs(coord.x - coord.y); // NOLINT
1986 gl_FragColor = mix(color1, color2, picker) * alpha; 1998 gl_FragColor = mix(color1, color2, picker) * alpha;
1987 } 1999 }
1988 // clang-format off 2000 // clang-format off
1989 ); // NOLINT(whitespace/parens) 2001 ); // NOLINT(whitespace/parens)
1990 // clang-format on 2002 // clang-format on
1991 } 2003 }
1992 2004
1993 } // namespace cc 2005 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/shader.h ('k') | cc/quads/draw_quad_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698