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

Unified Diff: cc/output/shader.cc

Issue 988693005: Chromium roll (https://codereview.chromium.org/976353002) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fixed bad android build patch Created 5 years, 9 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
« no previous file with comments | « cc/output/shader.h ('k') | cc/output/software_renderer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/shader.cc
diff --git a/cc/output/shader.cc b/cc/output/shader.cc
index 189154637d6ab9bffbecf1244b516762e1f9114e..883b68353996e3857f0d463fd9d20f07fc6665b3 100644
--- a/cc/output/shader.cc
+++ b/cc/output/shader.cc
@@ -144,6 +144,9 @@ static std::string SetFragmentSamplerType(SamplerType requested_type,
} // namespace
+ShaderLocations::ShaderLocations() {
+}
+
TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context,
int* highp_threshold_cache,
int highp_threshold_min,
@@ -347,6 +350,12 @@ std::string VertexShaderPosTexTransform::GetShaderBody() {
});
}
+void VertexShaderPosTexTransform::FillLocations(
+ ShaderLocations* locations) const {
+ locations->matrix = matrix_location();
+ locations->tex_transform = tex_transform_location();
+}
+
std::string VertexShaderPosTexIdentity::GetShaderString() const {
return VERTEX_SHADER(GetShaderHead(), GetShaderBody());
}
@@ -560,6 +569,16 @@ std::string VertexShaderQuadTexTransformAA::GetShaderBody() {
});
}
+void VertexShaderQuadTexTransformAA::FillLocations(
+ ShaderLocations* locations) const {
+ locations->quad = quad_location();
+ locations->edge = edge_location();
+ locations->viewport = viewport_location();
+ locations->matrix = matrix_location();
+ locations->tex_transform = tex_transform_location();
+}
+
+
VertexShaderTile::VertexShaderTile()
: matrix_location_(-1),
quad_location_(-1),
@@ -722,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(
@@ -743,28 +767,50 @@ 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([]() {
+ static const std::string kUniforms = SHADER0([]() {
uniform sampler2D s_backdropTexture;
+ uniform sampler2D s_originalBackdropTexture;
uniform TexCoordPrecision vec4 backdropRect;
+ });
- vec4 GetBackdropColor() {
+ std::string mixFunction;
+ if (mask_for_background()) {
+ mixFunction = SHADER0([]() {
+ vec4 MixBackdrop(TexCoordPrecision vec2 bgTexCoord, float mask) {
+ vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord);
+ vec4 original_backdrop =
+ texture2D(s_originalBackdropTexture, bgTexCoord);
+ return mix(original_backdrop, backdrop, mask);
+ }
+ });
+ } else {
+ mixFunction = SHADER0([]() {
+ vec4 MixBackdrop(TexCoordPrecision vec2 bgTexCoord, float mask) {
+ return texture2D(s_backdropTexture, bgTexCoord);
+ }
+ });
+ }
+
+ static const std::string kFunctionApplyBlendMode = SHADER0([]() {
+ 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);
+ return MixBackdrop(bgTexCoord, mask);
}
- vec4 ApplyBlendMode(vec4 src) {
- vec4 dst = GetBackdropColor();
+ vec4 ApplyBlendMode(vec4 src, float mask) {
+ vec4 dst = GetBackdropColor(mask);
return Blend(src, dst);
}
});
return "precision mediump float;" + GetHelperFunctions() +
- GetBlendFunction() + kFunctionApplyBlendMode + shader_string;
+ GetBlendFunction() + kUniforms + mixFunction +
+ kFunctionApplyBlendMode + shader_string;
}
std::string FragmentTexBlendMode::GetHelperFunctions() const {
@@ -1100,11 +1146,19 @@ 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);
}
});
}
+void FragmentShaderRGBATexAlpha::FillLocations(
+ ShaderLocations* locations) const {
+ locations->sampler = sampler_location();
+ locations->alpha = alpha_location();
+ locations->backdrop = backdrop_location();
+ locations->backdrop_rect = backdrop_rect_location();
+}
+
std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString(
TexCoordPrecision precision,
SamplerType sampler) const {
@@ -1131,11 +1185,21 @@ 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);
}
});
}
+void FragmentShaderRGBATexColorMatrixAlpha::FillLocations(
+ ShaderLocations* locations) const {
+ locations->sampler = sampler_location();
+ locations->alpha = alpha_location();
+ locations->color_matrix = color_matrix_location();
+ locations->color_offset = color_offset_location();
+ locations->backdrop = backdrop_location();
+ locations->backdrop_rect = backdrop_rect_location();
+}
+
std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString(
TexCoordPrecision precision,
SamplerType sampler) const {
@@ -1400,11 +1464,19 @@ 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);
}
});
}
+void FragmentShaderRGBATexAlphaAA::FillLocations(
+ ShaderLocations* locations) const {
+ locations->sampler = sampler_location();
+ locations->alpha = alpha_location();
+ locations->backdrop = backdrop_location();
+ locations->backdrop_rect = backdrop_rect_location();
+}
+
FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding()
: sampler_location_(-1),
alpha_location_(-1),
@@ -1555,11 +1627,25 @@ 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);
}
});
}
+void FragmentShaderRGBATexAlphaMask::FillLocations(
+ ShaderLocations* locations) const {
+ locations->sampler = sampler_location();
+ locations->mask_sampler = mask_sampler_location();
+ locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
+ locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
+ 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()
: sampler_location_(-1),
mask_sampler_location_(-1),
@@ -1625,11 +1711,25 @@ 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);
}
});
}
+void FragmentShaderRGBATexAlphaMaskAA::FillLocations(
+ ShaderLocations* locations) const {
+ locations->sampler = sampler_location();
+ locations->mask_sampler = mask_sampler_location();
+ locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
+ locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
+ 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::
FragmentShaderRGBATexAlphaMaskColorMatrixAA()
: sampler_location_(-1),
@@ -1709,11 +1809,27 @@ 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);
}
});
}
+void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations(
+ ShaderLocations* locations) const {
+ locations->sampler = sampler_location();
+ locations->alpha = alpha_location();
+ locations->mask_sampler = mask_sampler_location();
+ locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
+ locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
+ locations->color_matrix = color_matrix_location();
+ 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::
FragmentShaderRGBATexAlphaColorMatrixAA()
: sampler_location_(-1),
@@ -1773,11 +1889,21 @@ 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);
}
});
}
+void FragmentShaderRGBATexAlphaColorMatrixAA::FillLocations(
+ ShaderLocations* locations) const {
+ locations->sampler = sampler_location();
+ locations->alpha = alpha_location();
+ locations->color_matrix = color_matrix_location();
+ locations->color_offset = color_offset_location();
+ locations->backdrop = backdrop_location();
+ locations->backdrop_rect = backdrop_rect_location();
+}
+
FragmentShaderRGBATexAlphaMaskColorMatrix::
FragmentShaderRGBATexAlphaMaskColorMatrix()
: sampler_location_(-1),
@@ -1850,11 +1976,27 @@ 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);
}
});
}
+void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations(
+ ShaderLocations* locations) const {
+ locations->sampler = sampler_location();
+ locations->mask_sampler = mask_sampler_location();
+ locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
+ locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
+ locations->alpha = alpha_location();
+ locations->color_matrix = color_matrix_location();
+ 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()
: y_texture_location_(-1),
u_texture_location_(-1),
« 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