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

Unified 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: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: cc/output/shader.cc
diff --git a/cc/output/shader.cc b/cc/output/shader.cc
index 6e1f6c5a915f341354100f7ea92021ef81bfde48..ef88ff586d190106e1eced76492d843827119bcc 100644
--- a/cc/output/shader.cc
+++ b/cc/output/shader.cc
@@ -668,30 +668,65 @@ std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString(
); // NOLINT(whitespace/parens)
}
-std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString(
+FragmentTexBackgroundBinding::FragmentTexBackgroundBinding()
+ : background_color_location_(-1),
+ sampler_location_(-1) {
+}
+
+void FragmentTexBackgroundBinding::Init(WebGraphicsContext3D* context,
+ unsigned program,
+ bool using_bind_uniform,
+ int* base_uniform_index) {
+ static const char* shader_uniforms[] = {
+ "s_texture",
+ "background_color",
+ };
+ int locations[2];
+
+ GetProgramUniformLocations(context,
+ program,
+ shader_uniforms,
+ arraysize(shader_uniforms),
+ arraysize(locations),
+ locations,
+ using_bind_uniform,
+ base_uniform_index);
+
+ sampler_location_ = locations[0];
+ DCHECK_NE(sampler_location_, -1);
+
+ background_color_location_ = locations[1];
+ DCHECK_NE(background_color_location_, -1);
+}
+
+std::string FragmentShaderTexture::GetShaderString(
TexCoordPrecision precision) const {
return FRAGMENT_SHADER(
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
varying float v_alpha;
uniform sampler2D s_texture;
+ uniform vec4 background_color;
void main() {
vec4 texColor = texture2D(s_texture, v_texCoord);
+ texColor += background_color * (1.0 - texColor.a);
piman 2013/07/02 01:26:30 drive-by: so, this extra cost is done on every pix
alokp 2013/07/02 22:03:54 I was hoping to not have to keep the existing shad
gl_FragColor = texColor * v_alpha;
enne (OOO) 2013/07/02 01:27:22 How does v_alpha interact with texColor.a? If the
alokp 2013/07/02 22:03:54 This order is correct for this specific use case.
enne (OOO) 2013/07/02 23:08:29 I think it's still correct. I guess if I think ab
}
); // NOLINT(whitespace/parens)
}
-std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString(
+std::string FragmentShaderNonPremulTexture::GetShaderString(
TexCoordPrecision precision) const {
return FRAGMENT_SHADER(
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
varying float v_alpha;
uniform sampler2D s_texture;
+ uniform vec4 background_color;
void main() {
vec4 texColor = texture2D(s_texture, v_texCoord);
texColor.rgb *= texColor.a;
+ texColor += background_color * (1.0 - texColor.a);
gl_FragColor = texColor * v_alpha;
}
); // NOLINT(whitespace/parens)

Powered by Google App Engine
This is Rietveld 408576698