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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 void main() { | 184 void main() { |
185 gl_Position = matrix * a_position; | 185 gl_Position = matrix * a_position; |
186 v_texCoord = a_texCoord; | 186 v_texCoord = a_texCoord; |
187 } | 187 } |
188 // clang-format off | 188 // clang-format off |
189 ); // NOLINT(whitespace/parens) | 189 ); // NOLINT(whitespace/parens) |
190 // clang-format on | 190 // clang-format on |
191 } | 191 } |
192 | 192 |
193 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() | 193 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() |
194 : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) { | 194 : matrix_location_(-1), |
195 tex_scale_location_(-1), | |
196 tex_offset_location_(-1) { | |
195 } | 197 } |
196 | 198 |
197 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, | 199 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, |
198 unsigned program, | 200 unsigned program, |
199 int* base_uniform_index) { | 201 int* base_uniform_index) { |
200 static const char* uniforms[] = { | 202 static const char* uniforms[] = { |
201 "matrix", "texScale", "texOffset", | 203 "matrix", "texScale", "texOffset", |
202 }; | 204 }; |
203 int locations[arraysize(uniforms)]; | 205 int locations[arraysize(uniforms)]; |
204 | 206 |
205 GetProgramUniformLocations(context, | 207 GetProgramUniformLocations(context, |
206 program, | 208 program, |
207 arraysize(uniforms), | 209 arraysize(uniforms), |
208 uniforms, | 210 uniforms, |
209 locations, | 211 locations, |
210 base_uniform_index); | 212 base_uniform_index); |
211 matrix_location_ = locations[0]; | 213 matrix_location_ = locations[0]; |
212 tex_scale_location_ = locations[1]; | 214 tex_scale_location_ = locations[1]; |
213 tex_offset_location_ = locations[2]; | 215 tex_offset_location_ = locations[2]; |
214 } | 216 } |
215 | 217 |
216 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { | 218 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { |
217 // clang-format off | 219 // clang-format off |
218 return VERTEX_SHADER( | 220 return VERTEX_SHADER( |
219 // clang-format on | 221 // clang-format on |
220 precision mediump float; | 222 precision mediump float; attribute vec4 a_position; |
danakj
2015/02/02 18:43:03
?
| |
221 attribute vec4 a_position; | |
222 attribute TexCoordPrecision vec2 a_texCoord; | 223 attribute TexCoordPrecision vec2 a_texCoord; |
223 uniform mat4 matrix; | 224 uniform mat4 matrix; |
224 varying TexCoordPrecision vec2 v_texCoord; | 225 varying TexCoordPrecision vec2 v_texCoord; |
225 uniform TexCoordPrecision vec2 texScale; | 226 uniform TexCoordPrecision vec2 texScale; |
226 uniform TexCoordPrecision vec2 texOffset; | 227 uniform TexCoordPrecision vec2 texOffset; |
227 void main() { | 228 void main() { |
228 gl_Position = matrix * a_position; | 229 gl_Position = matrix * a_position; |
229 v_texCoord = a_texCoord * texScale + texOffset; | 230 v_texCoord = a_texCoord * texScale + texOffset; |
230 } | 231 } |
231 // clang-format off | 232 // clang-format off |
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1734 ); // NOLINT(whitespace/parens) | 1735 ); // NOLINT(whitespace/parens) |
1735 // clang-format on | 1736 // clang-format on |
1736 } | 1737 } |
1737 | 1738 |
1738 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 1739 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
1739 : y_texture_location_(-1), | 1740 : y_texture_location_(-1), |
1740 u_texture_location_(-1), | 1741 u_texture_location_(-1), |
1741 v_texture_location_(-1), | 1742 v_texture_location_(-1), |
1742 alpha_location_(-1), | 1743 alpha_location_(-1), |
1743 yuv_matrix_location_(-1), | 1744 yuv_matrix_location_(-1), |
1744 yuv_adj_location_(-1) { | 1745 yuv_adj_location_(-1), |
1746 clamp_rect_location_(-1) { | |
1745 } | 1747 } |
1746 | 1748 |
1747 void FragmentShaderYUVVideo::Init(GLES2Interface* context, | 1749 void FragmentShaderYUVVideo::Init(GLES2Interface* context, |
1748 unsigned program, | 1750 unsigned program, |
1749 int* base_uniform_index) { | 1751 int* base_uniform_index) { |
1750 static const char* uniforms[] = { | 1752 static const char* uniforms[] = {"y_texture", |
1751 "y_texture", "u_texture", "v_texture", "alpha", "yuv_matrix", "yuv_adj", | 1753 "u_texture", |
1752 }; | 1754 "v_texture", |
1755 "alpha", | |
1756 "yuv_matrix", | |
1757 "yuv_adj", | |
1758 "clamp_rect"}; | |
1753 int locations[arraysize(uniforms)]; | 1759 int locations[arraysize(uniforms)]; |
1754 | 1760 |
1755 GetProgramUniformLocations(context, | 1761 GetProgramUniformLocations(context, |
1756 program, | 1762 program, |
1757 arraysize(uniforms), | 1763 arraysize(uniforms), |
1758 uniforms, | 1764 uniforms, |
1759 locations, | 1765 locations, |
1760 base_uniform_index); | 1766 base_uniform_index); |
1761 y_texture_location_ = locations[0]; | 1767 y_texture_location_ = locations[0]; |
1762 u_texture_location_ = locations[1]; | 1768 u_texture_location_ = locations[1]; |
1763 v_texture_location_ = locations[2]; | 1769 v_texture_location_ = locations[2]; |
1764 alpha_location_ = locations[3]; | 1770 alpha_location_ = locations[3]; |
1765 yuv_matrix_location_ = locations[4]; | 1771 yuv_matrix_location_ = locations[4]; |
1766 yuv_adj_location_ = locations[5]; | 1772 yuv_adj_location_ = locations[5]; |
1773 clamp_rect_location_ = locations[6]; | |
1767 } | 1774 } |
1768 | 1775 |
1769 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, | 1776 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
1770 SamplerType sampler) const { | 1777 SamplerType sampler) const { |
1771 // clang-format off | 1778 // clang-format off |
1772 return FRAGMENT_SHADER( | 1779 return FRAGMENT_SHADER( |
1773 // clang-format on | 1780 // clang-format on |
1774 precision mediump float; | 1781 precision mediump float; |
1775 precision mediump int; | 1782 precision mediump int; |
1776 varying TexCoordPrecision vec2 v_texCoord; | 1783 varying TexCoordPrecision vec2 v_texCoord; |
1777 uniform SamplerType y_texture; | 1784 uniform SamplerType y_texture; |
1778 uniform SamplerType u_texture; | 1785 uniform SamplerType u_texture; |
1779 uniform SamplerType v_texture; | 1786 uniform SamplerType v_texture; |
1780 uniform float alpha; | 1787 uniform float alpha; |
1781 uniform vec3 yuv_adj; | 1788 uniform vec3 yuv_adj; |
1782 uniform mat3 yuv_matrix; | 1789 uniform mat3 yuv_matrix; |
1790 uniform vec4 clamp_rect; | |
1783 void main() { | 1791 void main() { |
1784 float y_raw = TextureLookup(y_texture, v_texCoord).x; | 1792 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord)); |
enne (OOO)
2015/01/31 01:32:14
I moved the clamping from the vertex to the fragme
| |
1785 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; | 1793 float y_raw = TextureLookup(y_texture, clamped).x; |
1786 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; | 1794 float u_unsigned = TextureLookup(u_texture, clamped).x; |
1795 float v_unsigned = TextureLookup(v_texture, clamped).x; | |
1787 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 1796 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
1788 vec3 rgb = yuv_matrix * yuv; | 1797 vec3 rgb = yuv_matrix * yuv; |
1789 gl_FragColor = vec4(rgb, 1.0) * alpha; | 1798 gl_FragColor = vec4(rgb, 1.0) * alpha; |
1790 } | 1799 } |
1791 // clang-format off | 1800 // clang-format off |
1792 ); // NOLINT(whitespace/parens) | 1801 ); // NOLINT(whitespace/parens) |
1793 // clang-format on | 1802 // clang-format on |
1794 } | 1803 } |
1795 | 1804 |
1796 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() | 1805 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() |
(...skipping 10 matching lines...) Expand all Loading... | |
1807 unsigned program, | 1816 unsigned program, |
1808 int* base_uniform_index) { | 1817 int* base_uniform_index) { |
1809 static const char* uniforms[] = { | 1818 static const char* uniforms[] = { |
1810 "y_texture", | 1819 "y_texture", |
1811 "u_texture", | 1820 "u_texture", |
1812 "v_texture", | 1821 "v_texture", |
1813 "a_texture", | 1822 "a_texture", |
1814 "alpha", | 1823 "alpha", |
1815 "cc_matrix", | 1824 "cc_matrix", |
1816 "yuv_adj", | 1825 "yuv_adj", |
1826 "clamp_rect", | |
1817 }; | 1827 }; |
1818 int locations[arraysize(uniforms)]; | 1828 int locations[arraysize(uniforms)]; |
1819 | 1829 |
1820 GetProgramUniformLocations(context, | 1830 GetProgramUniformLocations(context, |
1821 program, | 1831 program, |
1822 arraysize(uniforms), | 1832 arraysize(uniforms), |
1823 uniforms, | 1833 uniforms, |
1824 locations, | 1834 locations, |
1825 base_uniform_index); | 1835 base_uniform_index); |
1826 y_texture_location_ = locations[0]; | 1836 y_texture_location_ = locations[0]; |
1827 u_texture_location_ = locations[1]; | 1837 u_texture_location_ = locations[1]; |
1828 v_texture_location_ = locations[2]; | 1838 v_texture_location_ = locations[2]; |
1829 a_texture_location_ = locations[3]; | 1839 a_texture_location_ = locations[3]; |
1830 alpha_location_ = locations[4]; | 1840 alpha_location_ = locations[4]; |
1831 yuv_matrix_location_ = locations[5]; | 1841 yuv_matrix_location_ = locations[5]; |
1832 yuv_adj_location_ = locations[6]; | 1842 yuv_adj_location_ = locations[6]; |
1843 clamp_rect_location_ = locations[7]; | |
1833 } | 1844 } |
1834 | 1845 |
1835 std::string FragmentShaderYUVAVideo::GetShaderString( | 1846 std::string FragmentShaderYUVAVideo::GetShaderString( |
1836 TexCoordPrecision precision, | 1847 TexCoordPrecision precision, |
1837 SamplerType sampler) const { | 1848 SamplerType sampler) const { |
1838 // clang-format off | 1849 // clang-format off |
1839 return FRAGMENT_SHADER( | 1850 return FRAGMENT_SHADER( |
1840 // clang-format on | 1851 // clang-format on |
1841 precision mediump float; | 1852 precision mediump float; |
1842 precision mediump int; | 1853 precision mediump int; |
1843 varying TexCoordPrecision vec2 v_texCoord; | 1854 varying TexCoordPrecision vec2 v_texCoord; |
1844 uniform SamplerType y_texture; | 1855 uniform SamplerType y_texture; |
1845 uniform SamplerType u_texture; | 1856 uniform SamplerType u_texture; |
1846 uniform SamplerType v_texture; | 1857 uniform SamplerType v_texture; |
1847 uniform SamplerType a_texture; | 1858 uniform SamplerType a_texture; |
1848 uniform float alpha; | 1859 uniform float alpha; |
1849 uniform vec3 yuv_adj; | 1860 uniform vec3 yuv_adj; |
1850 uniform mat3 yuv_matrix; | 1861 uniform mat3 yuv_matrix; |
1862 uniform vec4 clamp_rect; | |
1851 void main() { | 1863 void main() { |
1852 float y_raw = TextureLookup(y_texture, v_texCoord).x; | 1864 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord)); |
1853 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; | 1865 float y_raw = TextureLookup(y_texture, clamped).x; |
1854 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; | 1866 float u_unsigned = TextureLookup(u_texture, clamped).x; |
1855 float a_raw = TextureLookup(a_texture, v_texCoord).x; | 1867 float v_unsigned = TextureLookup(v_texture, clamped).x; |
1868 float a_raw = TextureLookup(a_texture, clamped).x; | |
1856 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 1869 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
1857 vec3 rgb = yuv_matrix * yuv; | 1870 vec3 rgb = yuv_matrix * yuv; |
1858 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); | 1871 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); |
1859 } | 1872 } |
1860 // clang-format off | 1873 // clang-format off |
1861 ); // NOLINT(whitespace/parens) | 1874 ); // NOLINT(whitespace/parens) |
1862 // clang-format on | 1875 // clang-format on |
1863 } | 1876 } |
1864 | 1877 |
1865 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { | 1878 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1984 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1997 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1985 float picker = abs(coord.x - coord.y); // NOLINT | 1998 float picker = abs(coord.x - coord.y); // NOLINT |
1986 gl_FragColor = mix(color1, color2, picker) * alpha; | 1999 gl_FragColor = mix(color1, color2, picker) * alpha; |
1987 } | 2000 } |
1988 // clang-format off | 2001 // clang-format off |
1989 ); // NOLINT(whitespace/parens) | 2002 ); // NOLINT(whitespace/parens) |
1990 // clang-format on | 2003 // clang-format on |
1991 } | 2004 } |
1992 | 2005 |
1993 } // namespace cc | 2006 } // namespace cc |
OLD | NEW |