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

Unified Diff: cc/output/shader.cc

Issue 959283004: Background filters are affected by masks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes and more tests Created 5 years, 10 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 287ffcc9b4662cc0d18366f1c7ecfbe6c9254d3c..d51d3f1c8b899e0a5a8e0bd55220bf2c705630ec 100644
--- a/cc/output/shader.cc
+++ b/cc/output/shader.cc
@@ -741,19 +741,24 @@ std::string VertexShaderVideoTransform::GetShaderBody() {
});
}
-#define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect"
-#define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 2 : 0)
+#define BLEND_MODE_UNIFORMS "s_backdropTexture", \
+ "s_originalBackdropTexture", \
+ "backdropRect"
+#define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 3 : 0)
#define BLEND_MODE_SET_LOCATIONS(X, POS) \
if (has_blend_mode()) { \
- DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \
+ DCHECK_LT(static_cast<size_t>(POS) + 2, arraysize(X)); \
backdrop_location_ = locations[POS]; \
- backdrop_rect_location_ = locations[POS + 1]; \
+ original_backdrop_location_ = locations[POS + 1]; \
+ backdrop_rect_location_ = locations[POS + 2]; \
}
FragmentTexBlendMode::FragmentTexBlendMode()
: backdrop_location_(-1),
+ original_backdrop_location_(-1),
backdrop_rect_location_(-1),
- blend_mode_(BLEND_MODE_NONE) {
+ blend_mode_(BLEND_MODE_NONE),
+ mask_for_background_(false) {
}
std::string FragmentTexBlendMode::SetBlendModeFunctions(
@@ -762,22 +767,28 @@ std::string FragmentTexBlendMode::SetBlendModeFunctions(
return shader_string;
if (!has_blend_mode()) {
- return "#define ApplyBlendMode(X) (X)\n" + shader_string;
+ return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string;
}
static const std::string kFunctionApplyBlendMode = SHADER0([]() {
uniform sampler2D s_backdropTexture;
+ uniform sampler2D s_originalBackdropTexture;
uniform TexCoordPrecision vec4 backdropRect;
- vec4 GetBackdropColor() {
+ vec4 GetBackdropColor(float mask) {
TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy;
bgTexCoord.x /= backdropRect.z;
- bgTexCoord.y /= backdropRect.w;
- return texture2D(s_backdropTexture, bgTexCoord);
- }
-
- vec4 ApplyBlendMode(vec4 src) {
- vec4 dst = GetBackdropColor();
+ bgTexCoord.y /= backdropRect.w; }) +
+ (mask_for_background()
+ ? SHADER0([]() {
enne (OOO) 2015/03/04 19:58:44 This is super hard to read. Can you put the two b
+ vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord);
+ vec4 original_backdrop = texture2D(s_originalBackdropTexture, bgTexCoord);
+ return mix(original_backdrop, backdrop, mask); } })
+ : SHADER0([]() {
+ return texture2D(s_backdropTexture, bgTexCoord); } }) ) +
+ SHADER0([]() {
+ vec4 ApplyBlendMode(vec4 src, float mask) {
+ vec4 dst = GetBackdropColor(mask);
return Blend(src, dst);
}
});
@@ -1119,7 +1130,7 @@ std::string FragmentShaderRGBATexAlpha::GetShaderBody() {
return SHADER0([]() {
void main() {
vec4 texColor = TextureLookup(s_texture, v_texCoord);
- gl_FragColor = ApplyBlendMode(texColor * alpha);
+ gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0);
}
});
}
@@ -1158,7 +1169,7 @@ std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderBody() {
texColor = colorMatrix * texColor + colorOffset;
texColor.rgb *= texColor.a;
texColor = clamp(texColor, 0.0, 1.0);
- gl_FragColor = ApplyBlendMode(texColor * alpha);
+ gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0);
}
});
}
@@ -1437,7 +1448,7 @@ std::string FragmentShaderRGBATexAlphaAA::GetShaderBody() {
vec4 d4 = min(edge_dist[0], edge_dist[1]);
vec2 d2 = min(d4.xz, d4.yw);
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
- gl_FragColor = ApplyBlendMode(texColor * alpha * aa);
+ gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0);
}
});
}
@@ -1600,7 +1611,8 @@ std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() {
vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
- gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w);
+ gl_FragColor = ApplyBlendMode(
+ texColor * alpha * maskColor.w, maskColor.w);
}
});
}
@@ -1614,6 +1626,8 @@ void FragmentShaderRGBATexAlphaMask::FillLocations(
locations->alpha = alpha_location();
locations->backdrop = backdrop_location();
locations->backdrop_rect = backdrop_rect_location();
+ if (mask_for_background())
+ locations->original_backdrop = original_backdrop_location();
}
FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
@@ -1681,7 +1695,8 @@ std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderBody() {
vec4 d4 = min(edge_dist[0], edge_dist[1]);
vec2 d2 = min(d4.xz, d4.yw);
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
- gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa);
+ gl_FragColor = ApplyBlendMode(
+ texColor * alpha * maskColor.w * aa, maskColor.w);
}
});
}
@@ -1695,6 +1710,8 @@ void FragmentShaderRGBATexAlphaMaskAA::FillLocations(
locations->alpha = alpha_location();
locations->backdrop = backdrop_location();
locations->backdrop_rect = backdrop_rect_location();
+ if (mask_for_background())
+ locations->original_backdrop = original_backdrop_location();
}
FragmentShaderRGBATexAlphaMaskColorMatrixAA::
@@ -1776,7 +1793,8 @@ std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderBody() {
vec4 d4 = min(edge_dist[0], edge_dist[1]);
vec2 d2 = min(d4.xz, d4.yw);
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
- gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa);
+ gl_FragColor = ApplyBlendMode(
+ texColor * alpha * maskColor.w * aa, maskColor.w);
}
});
}
@@ -1792,6 +1810,8 @@ void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations(
locations->color_offset = color_offset_location();
locations->backdrop = backdrop_location();
locations->backdrop_rect = backdrop_rect_location();
+ if (mask_for_background())
+ locations->original_backdrop = original_backdrop_location();
}
FragmentShaderRGBATexAlphaColorMatrixAA::
@@ -1853,7 +1873,7 @@ std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderBody() {
vec4 d4 = min(edge_dist[0], edge_dist[1]);
vec2 d2 = min(d4.xz, d4.yw);
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
- gl_FragColor = ApplyBlendMode(texColor * alpha * aa);
+ gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0);
}
});
}
@@ -1940,7 +1960,8 @@ std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderBody() {
vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
- gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w);
+ gl_FragColor = ApplyBlendMode(
+ texColor * alpha * maskColor.w, maskColor.w);
}
});
}
@@ -1956,6 +1977,8 @@ void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations(
locations->color_offset = color_offset_location();
locations->backdrop = backdrop_location();
locations->backdrop_rect = backdrop_rect_location();
+ if (mask_for_background())
+ locations->original_backdrop = original_backdrop_location();
}
FragmentShaderYUVVideo::FragmentShaderYUVVideo()

Powered by Google App Engine
This is Rietveld 408576698