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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 HDR("varying TexCoordPrecision vec2 dummy_varying;"); | 388 HDR("varying TexCoordPrecision vec2 dummy_varying;"); |
389 SRC("dummy_varying = dummy_uniform;"); | 389 SRC("dummy_varying = dummy_uniform;"); |
390 } | 390 } |
391 | 391 |
392 source += "}\n"; | 392 source += "}\n"; |
393 return header + source; | 393 return header + source; |
394 } | 394 } |
395 | 395 |
396 FragmentShaderBase::FragmentShaderBase() {} | 396 FragmentShaderBase::FragmentShaderBase() {} |
397 | 397 |
398 std::string FragmentShaderBase::GetShaderString(TexCoordPrecision precision, | 398 std::string FragmentShaderBase::GetShaderString() const { |
399 SamplerType sampler) const { | |
400 // The AA shader values will use TexCoordPrecision. | 399 // The AA shader values will use TexCoordPrecision. |
| 400 TexCoordPrecision precision = tex_coord_precision_; |
401 if (has_aa_ && precision == TEX_COORD_PRECISION_NA) | 401 if (has_aa_ && precision == TEX_COORD_PRECISION_NA) |
402 precision = TEX_COORD_PRECISION_MEDIUM; | 402 precision = TEX_COORD_PRECISION_MEDIUM; |
403 return SetFragmentTexCoordPrecision( | 403 return SetFragmentTexCoordPrecision( |
404 precision, SetFragmentSamplerType( | 404 precision, SetFragmentSamplerType( |
405 sampler, SetBlendModeFunctions(GetShaderSource()))); | 405 sampler_type_, SetBlendModeFunctions(GetShaderSource()))); |
406 } | 406 } |
407 | 407 |
408 void FragmentShaderBase::Init(GLES2Interface* context, | 408 void FragmentShaderBase::Init(GLES2Interface* context, |
409 unsigned program, | 409 unsigned program, |
410 int* base_uniform_index) { | 410 int* base_uniform_index) { |
411 std::vector<const char*> uniforms; | 411 std::vector<const char*> uniforms; |
412 std::vector<int> locations; | 412 std::vector<int> locations; |
413 if (has_blend_mode()) { | 413 if (has_blend_mode()) { |
414 uniforms.push_back("s_backdropTexture"); | 414 uniforms.push_back("s_backdropTexture"); |
415 uniforms.push_back("s_originalBackdropTexture"); | 415 uniforms.push_back("s_originalBackdropTexture"); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 break; | 474 break; |
475 } | 475 } |
476 DCHECK_EQ(index, locations.size()); | 476 DCHECK_EQ(index, locations.size()); |
477 } | 477 } |
478 | 478 |
479 void FragmentShaderBase::FillLocations(ShaderLocations* locations) const { | 479 void FragmentShaderBase::FillLocations(ShaderLocations* locations) const { |
480 if (has_blend_mode()) { | 480 if (has_blend_mode()) { |
481 locations->backdrop = backdrop_location_; | 481 locations->backdrop = backdrop_location_; |
482 locations->backdrop_rect = backdrop_rect_location_; | 482 locations->backdrop_rect = backdrop_rect_location_; |
483 } | 483 } |
484 if (mask_for_background()) | 484 if (mask_for_background_) |
485 locations->original_backdrop = original_backdrop_location_; | 485 locations->original_backdrop = original_backdrop_location_; |
486 if (has_mask_sampler_) { | 486 if (has_mask_sampler_) { |
487 locations->mask_sampler = mask_sampler_location_; | 487 locations->mask_sampler = mask_sampler_location_; |
488 locations->mask_tex_coord_scale = mask_tex_coord_scale_location_; | 488 locations->mask_tex_coord_scale = mask_tex_coord_scale_location_; |
489 locations->mask_tex_coord_offset = mask_tex_coord_offset_location_; | 489 locations->mask_tex_coord_offset = mask_tex_coord_offset_location_; |
490 } | 490 } |
491 if (has_color_matrix_) { | 491 if (has_color_matrix_) { |
492 locations->color_matrix = color_matrix_location_; | 492 locations->color_matrix = color_matrix_location_; |
493 locations->color_offset = color_offset_location_; | 493 locations->color_offset = color_offset_location_; |
494 } | 494 } |
(...skipping 17 matching lines...) Expand all Loading... |
512 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; | 512 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; |
513 } | 513 } |
514 | 514 |
515 static const std::string kUniforms = SHADER0([]() { | 515 static const std::string kUniforms = SHADER0([]() { |
516 uniform sampler2D s_backdropTexture; | 516 uniform sampler2D s_backdropTexture; |
517 uniform sampler2D s_originalBackdropTexture; | 517 uniform sampler2D s_originalBackdropTexture; |
518 uniform TexCoordPrecision vec4 backdropRect; | 518 uniform TexCoordPrecision vec4 backdropRect; |
519 }); | 519 }); |
520 | 520 |
521 std::string mixFunction; | 521 std::string mixFunction; |
522 if (mask_for_background()) { | 522 if (mask_for_background_) { |
523 mixFunction = SHADER0([]() { | 523 mixFunction = SHADER0([]() { |
524 vec4 MixBackdrop(TexCoordPrecision vec2 bgTexCoord, float mask) { | 524 vec4 MixBackdrop(TexCoordPrecision vec2 bgTexCoord, float mask) { |
525 vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord); | 525 vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord); |
526 vec4 original_backdrop = | 526 vec4 original_backdrop = |
527 texture2D(s_originalBackdropTexture, bgTexCoord); | 527 texture2D(s_originalBackdropTexture, bgTexCoord); |
528 return mix(original_backdrop, backdrop, mask); | 528 return mix(original_backdrop, backdrop, mask); |
529 } | 529 } |
530 }); | 530 }); |
531 } else { | 531 } else { |
532 mixFunction = SHADER0([]() { | 532 mixFunction = SHADER0([]() { |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); | 1077 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); |
1078 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); | 1078 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); |
1079 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); | 1079 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); |
1080 } | 1080 } |
1081 }); | 1081 }); |
1082 | 1082 |
1083 return head + functions; | 1083 return head + functions; |
1084 } | 1084 } |
1085 | 1085 |
1086 } // namespace cc | 1086 } // namespace cc |
OLD | NEW |