Chromium Code Reviews| Index: cc/output/shader.cc |
| diff --git a/cc/output/shader.cc b/cc/output/shader.cc |
| index 5bc704497ca5b63c24547ac5d9ea15092783b454..21361482edaba57b042089e334a65a055db14116 100644 |
| --- a/cc/output/shader.cc |
| +++ b/cc/output/shader.cc |
| @@ -191,7 +191,9 @@ std::string VertexShaderPosTex::GetShaderString() const { |
| } |
| VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() |
| - : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) { |
| + : matrix_location_(-1), |
| + tex_scale_location_(-1), |
| + tex_offset_location_(-1) { |
| } |
| void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, |
| @@ -217,8 +219,7 @@ std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { |
| // clang-format off |
| return VERTEX_SHADER( |
| // clang-format on |
| - precision mediump float; |
| - attribute vec4 a_position; |
| + precision mediump float; attribute vec4 a_position; |
|
danakj
2015/02/02 18:43:03
?
|
| attribute TexCoordPrecision vec2 a_texCoord; |
| uniform mat4 matrix; |
| varying TexCoordPrecision vec2 v_texCoord; |
| @@ -1741,15 +1742,20 @@ FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
| v_texture_location_(-1), |
| alpha_location_(-1), |
| yuv_matrix_location_(-1), |
| - yuv_adj_location_(-1) { |
| + yuv_adj_location_(-1), |
| + clamp_rect_location_(-1) { |
| } |
| void FragmentShaderYUVVideo::Init(GLES2Interface* context, |
| unsigned program, |
| int* base_uniform_index) { |
| - static const char* uniforms[] = { |
| - "y_texture", "u_texture", "v_texture", "alpha", "yuv_matrix", "yuv_adj", |
| - }; |
| + static const char* uniforms[] = {"y_texture", |
| + "u_texture", |
| + "v_texture", |
| + "alpha", |
| + "yuv_matrix", |
| + "yuv_adj", |
| + "clamp_rect"}; |
| int locations[arraysize(uniforms)]; |
| GetProgramUniformLocations(context, |
| @@ -1764,6 +1770,7 @@ void FragmentShaderYUVVideo::Init(GLES2Interface* context, |
| alpha_location_ = locations[3]; |
| yuv_matrix_location_ = locations[4]; |
| yuv_adj_location_ = locations[5]; |
| + clamp_rect_location_ = locations[6]; |
| } |
| std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
| @@ -1780,10 +1787,12 @@ std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
| uniform float alpha; |
| uniform vec3 yuv_adj; |
| uniform mat3 yuv_matrix; |
| + uniform vec4 clamp_rect; |
| void main() { |
| - float y_raw = TextureLookup(y_texture, v_texCoord).x; |
| - float u_unsigned = TextureLookup(u_texture, v_texCoord).x; |
| - float v_unsigned = TextureLookup(v_texture, v_texCoord).x; |
| + 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
|
| + float y_raw = TextureLookup(y_texture, clamped).x; |
| + float u_unsigned = TextureLookup(u_texture, clamped).x; |
| + float v_unsigned = TextureLookup(v_texture, clamped).x; |
| vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
| vec3 rgb = yuv_matrix * yuv; |
| gl_FragColor = vec4(rgb, 1.0) * alpha; |
| @@ -1814,6 +1823,7 @@ void FragmentShaderYUVAVideo::Init(GLES2Interface* context, |
| "alpha", |
| "cc_matrix", |
| "yuv_adj", |
| + "clamp_rect", |
| }; |
| int locations[arraysize(uniforms)]; |
| @@ -1830,6 +1840,7 @@ void FragmentShaderYUVAVideo::Init(GLES2Interface* context, |
| alpha_location_ = locations[4]; |
| yuv_matrix_location_ = locations[5]; |
| yuv_adj_location_ = locations[6]; |
| + clamp_rect_location_ = locations[7]; |
| } |
| std::string FragmentShaderYUVAVideo::GetShaderString( |
| @@ -1848,11 +1859,13 @@ std::string FragmentShaderYUVAVideo::GetShaderString( |
| uniform float alpha; |
| uniform vec3 yuv_adj; |
| uniform mat3 yuv_matrix; |
| + uniform vec4 clamp_rect; |
| void main() { |
| - float y_raw = TextureLookup(y_texture, v_texCoord).x; |
| - float u_unsigned = TextureLookup(u_texture, v_texCoord).x; |
| - float v_unsigned = TextureLookup(v_texture, v_texCoord).x; |
| - float a_raw = TextureLookup(a_texture, v_texCoord).x; |
| + vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord)); |
| + float y_raw = TextureLookup(y_texture, clamped).x; |
| + float u_unsigned = TextureLookup(u_texture, clamped).x; |
| + float v_unsigned = TextureLookup(v_texture, clamped).x; |
| + float a_raw = TextureLookup(a_texture, clamped).x; |
| vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
| vec3 rgb = yuv_matrix * yuv; |
| gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); |