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

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

Issue 18432002: Blend TextureLayer background-color at draw time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: separate shaders for textures with background Created 7 years, 5 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 | Annotate | Revision Log
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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 varying float v_alpha; 690 varying float v_alpha;
691 uniform sampler2D s_texture; 691 uniform sampler2D s_texture;
692 void main() { 692 void main() {
693 vec4 texColor = texture2D(s_texture, v_texCoord); 693 vec4 texColor = texture2D(s_texture, v_texCoord);
694 texColor.rgb *= texColor.a; 694 texColor.rgb *= texColor.a;
695 gl_FragColor = texColor * v_alpha; 695 gl_FragColor = texColor * v_alpha;
696 } 696 }
697 ); // NOLINT(whitespace/parens) 697 ); // NOLINT(whitespace/parens)
698 } 698 }
699 699
700 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding()
701 : background_color_location_(-1),
702 sampler_location_(-1) {
703 }
704
705 void FragmentTexBackgroundBinding::Init(WebGraphicsContext3D* context,
706 unsigned program,
707 bool using_bind_uniform,
708 int* base_uniform_index) {
709 static const char* shader_uniforms[] = {
710 "s_texture",
711 "background_color",
712 };
713 int locations[2];
714
715 GetProgramUniformLocations(context,
716 program,
717 shader_uniforms,
718 arraysize(shader_uniforms),
719 arraysize(locations),
720 locations,
721 using_bind_uniform,
722 base_uniform_index);
723
724 sampler_location_ = locations[0];
725 DCHECK_NE(sampler_location_, -1);
726
727 background_color_location_ = locations[1];
728 DCHECK_NE(background_color_location_, -1);
729 }
730
731 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString(
732 TexCoordPrecision precision) const {
733 return FRAGMENT_SHADER(
734 precision mediump float;
735 varying TexCoordPrecision vec2 v_texCoord;
736 varying float v_alpha;
737 uniform vec4 background_color;
738 uniform sampler2D s_texture;
739 void main() {
740 vec4 texColor = texture2D(s_texture, v_texCoord);
741 texColor += background_color * (1.0 - texColor.a);
742 gl_FragColor = texColor * v_alpha;
743 }
744 ); // NOLINT(whitespace/parens)
745 }
746
747 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString(
748 TexCoordPrecision precision) const {
749 return FRAGMENT_SHADER(
750 precision mediump float;
751 varying TexCoordPrecision vec2 v_texCoord;
752 varying float v_alpha;
753 uniform sampler2D s_texture;
754 void main() {
755 vec4 texColor = texture2D(s_texture, v_texCoord);
756 texColor.rgb *= texColor.a;
757 texColor += background_color * (1.0 - texColor.a);
758 gl_FragColor = texColor * v_alpha;
759 }
760 ); // NOLINT(whitespace/parens)
761 }
762
700 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString( 763 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString(
701 TexCoordPrecision precision) const { 764 TexCoordPrecision precision) const {
702 return "#extension GL_ARB_texture_rectangle : require\n" + 765 return "#extension GL_ARB_texture_rectangle : require\n" +
703 FRAGMENT_SHADER( 766 FRAGMENT_SHADER(
704 precision mediump float; 767 precision mediump float;
705 varying TexCoordPrecision vec2 v_texCoord; 768 varying TexCoordPrecision vec2 v_texCoord;
706 varying float v_alpha; 769 varying float v_alpha;
707 uniform sampler2DRect s_texture; 770 uniform sampler2DRect s_texture;
708 void main() { 771 void main() {
709 vec4 texColor = texture2DRect(s_texture, v_texCoord); 772 vec4 texColor = texture2DRect(s_texture, v_texCoord);
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 vec2 texCoord = 1623 vec2 texCoord =
1561 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; 1624 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy;
1562 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 1625 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
1563 float picker = abs(coord.x - coord.y); 1626 float picker = abs(coord.x - coord.y);
1564 gl_FragColor = mix(color1, color2, picker) * alpha; 1627 gl_FragColor = mix(color1, color2, picker) * alpha;
1565 } 1628 }
1566 ); // NOLINT(whitespace/parens) 1629 ); // NOLINT(whitespace/parens)
1567 } 1630 }
1568 1631
1569 } // namespace cc 1632 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698