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

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: resolved conflicts with TOT 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
« no previous file with comments | « cc/output/shader.h ('k') | cc/output/software_renderer.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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 varying float v_alpha; 781 varying float v_alpha;
782 uniform sampler2D s_texture; 782 uniform sampler2D s_texture;
783 void main() { 783 void main() {
784 vec4 texColor = texture2D(s_texture, v_texCoord); 784 vec4 texColor = texture2D(s_texture, v_texCoord);
785 texColor.rgb *= texColor.a; 785 texColor.rgb *= texColor.a;
786 gl_FragColor = texColor * v_alpha; 786 gl_FragColor = texColor * v_alpha;
787 } 787 }
788 ); // NOLINT(whitespace/parens) 788 ); // NOLINT(whitespace/parens)
789 } 789 }
790 790
791 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding()
792 : background_color_location_(-1),
793 sampler_location_(-1) {
794 }
795
796 void FragmentTexBackgroundBinding::Init(WebGraphicsContext3D* context,
797 unsigned program,
798 bool using_bind_uniform,
799 int* base_uniform_index) {
800 static const char* uniforms[] = {
801 "s_texture",
802 "background_color",
803 };
804 int locations[arraysize(uniforms)];
805
806 GetProgramUniformLocations(context,
807 program,
808 arraysize(uniforms),
809 uniforms,
810 locations,
811 using_bind_uniform,
812 base_uniform_index);
813
814 sampler_location_ = locations[0];
815 DCHECK_NE(sampler_location_, -1);
816
817 background_color_location_ = locations[1];
818 DCHECK_NE(background_color_location_, -1);
819 }
820
821 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString(
822 TexCoordPrecision precision) const {
823 return FRAGMENT_SHADER(
824 precision mediump float;
825 varying TexCoordPrecision vec2 v_texCoord;
826 varying float v_alpha;
827 uniform vec4 background_color;
828 uniform sampler2D s_texture;
829 void main() {
830 vec4 texColor = texture2D(s_texture, v_texCoord);
831 texColor += background_color * (1.0 - texColor.a);
832 gl_FragColor = texColor * v_alpha;
833 }
834 ); // NOLINT(whitespace/parens)
835 }
836
837 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString(
838 TexCoordPrecision precision) const {
839 return FRAGMENT_SHADER(
840 precision mediump float;
841 varying TexCoordPrecision vec2 v_texCoord;
842 varying float v_alpha;
843 uniform sampler2D s_texture;
844 void main() {
845 vec4 texColor = texture2D(s_texture, v_texCoord);
846 texColor.rgb *= texColor.a;
847 texColor += background_color * (1.0 - texColor.a);
848 gl_FragColor = texColor * v_alpha;
849 }
850 ); // NOLINT(whitespace/parens)
851 }
852
791 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString( 853 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString(
792 TexCoordPrecision precision) const { 854 TexCoordPrecision precision) const {
793 return "#extension GL_ARB_texture_rectangle : require\n" + 855 return "#extension GL_ARB_texture_rectangle : require\n" +
794 FRAGMENT_SHADER( 856 FRAGMENT_SHADER(
795 precision mediump float; 857 precision mediump float;
796 varying TexCoordPrecision vec2 v_texCoord; 858 varying TexCoordPrecision vec2 v_texCoord;
797 varying float v_alpha; 859 varying float v_alpha;
798 uniform sampler2DRect s_texture; 860 uniform sampler2DRect s_texture;
799 void main() { 861 void main() {
800 vec4 texColor = texture2DRect(s_texture, v_texCoord); 862 vec4 texColor = texture2DRect(s_texture, v_texCoord);
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 vec2 texCoord = 1596 vec2 texCoord =
1535 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; 1597 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy;
1536 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 1598 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
1537 float picker = abs(coord.x - coord.y); 1599 float picker = abs(coord.x - coord.y);
1538 gl_FragColor = mix(color1, color2, picker) * alpha; 1600 gl_FragColor = mix(color1, color2, picker) * alpha;
1539 } 1601 }
1540 ); // NOLINT(whitespace/parens) 1602 ); // NOLINT(whitespace/parens)
1541 } 1603 }
1542 1604
1543 } // namespace cc 1605 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/shader.h ('k') | cc/output/software_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698