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

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: Created 5 years, 11 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
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),
197 clamp_size_location_(-1) {
195 } 198 }
196 199
197 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, 200 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context,
198 unsigned program, 201 unsigned program,
199 int* base_uniform_index) { 202 int* base_uniform_index) {
200 static const char* uniforms[] = { 203 static const char* uniforms[] = {
201 "matrix", "texScale", "texOffset", 204 "matrix", "texScale", "texOffset", "clampSize",
202 }; 205 };
203 int locations[arraysize(uniforms)]; 206 int locations[arraysize(uniforms)];
204 207
205 GetProgramUniformLocations(context, 208 GetProgramUniformLocations(context,
206 program, 209 program,
207 arraysize(uniforms), 210 arraysize(uniforms),
208 uniforms, 211 uniforms,
209 locations, 212 locations,
210 base_uniform_index); 213 base_uniform_index);
211 matrix_location_ = locations[0]; 214 matrix_location_ = locations[0];
212 tex_scale_location_ = locations[1]; 215 tex_scale_location_ = locations[1];
213 tex_offset_location_ = locations[2]; 216 tex_offset_location_ = locations[2];
217 clamp_size_location_ = locations[3];
214 } 218 }
215 219
216 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { 220 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const {
217 // clang-format off 221 // clang-format off
218 return VERTEX_SHADER( 222 return VERTEX_SHADER(
219 // clang-format on 223 // clang-format on
220 precision mediump float; 224 precision mediump float; attribute vec4 a_position;
221 attribute vec4 a_position; 225 attribute TexCoordPrecision vec2 a_texCoord; uniform mat4 matrix;
222 attribute TexCoordPrecision vec2 a_texCoord;
223 uniform mat4 matrix;
224 varying TexCoordPrecision vec2 v_texCoord; 226 varying TexCoordPrecision vec2 v_texCoord;
225 uniform TexCoordPrecision vec2 texScale; 227 uniform TexCoordPrecision vec2 texScale;
226 uniform TexCoordPrecision vec2 texOffset; 228 uniform TexCoordPrecision vec2 texOffset;
227 void main() { 229 uniform TexCoordPrecision vec2 clampSize; void main() {
danakj 2015/01/28 01:02:00 formatting..
enne (OOO) 2015/01/31 01:32:13 git cl format T_T
228 gl_Position = matrix * a_position; 230 gl_Position = matrix * a_position;
229 v_texCoord = a_texCoord * texScale + texOffset; 231 v_texCoord = min(clampSize, a_texCoord * texScale + texOffset);
danakj 2015/01/28 01:02:00 do we not have to clamp on the left/top too?
enne (OOO) 2015/01/31 01:32:13 Turns out we do. Thanks. I changed clampSize to
230 } 232 }
231 // clang-format off 233 // clang-format off
232 ); // NOLINT(whitespace/parens) 234 ); // NOLINT(whitespace/parens)
233 // clang-format on 235 // clang-format on
234 } 236 }
235 237
236 VertexShaderPos::VertexShaderPos() : matrix_location_(-1) { 238 VertexShaderPos::VertexShaderPos() : matrix_location_(-1) {
237 } 239 }
238 240
239 void VertexShaderPos::Init(GLES2Interface* context, 241 void VertexShaderPos::Init(GLES2Interface* context,
(...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 1986 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
1985 float picker = abs(coord.x - coord.y); // NOLINT 1987 float picker = abs(coord.x - coord.y); // NOLINT
1986 gl_FragColor = mix(color1, color2, picker) * alpha; 1988 gl_FragColor = mix(color1, color2, picker) * alpha;
1987 } 1989 }
1988 // clang-format off 1990 // clang-format off
1989 ); // NOLINT(whitespace/parens) 1991 ); // NOLINT(whitespace/parens)
1990 // clang-format on 1992 // clang-format on
1991 } 1993 }
1992 1994
1993 } // namespace cc 1995 } // 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