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

Unified Diff: cc/output/gl_renderer.cc

Issue 18432002: Blend TextureLayer background-color at draw time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added TextureLayer unittest 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/gl_renderer.cc
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index 1528703751654f7e2f5a07605c0e74b97320465c..96b4a9f59ffbd621a7f29c012f60b2c9a482e7d3 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -98,6 +98,19 @@ Float4 UVTransform(const TextureDrawQuad* quad) {
return xform;
}
+Float4 PremultipliedColor(SkColor color) {
+ const float factor = 1.0f / 255.0f;
+ const float alpha = SkColorGetA(color) * factor;
+
+ Float4 result = { {
+ SkColorGetR(color) * factor * alpha,
+ SkColorGetG(color) * factor * alpha,
+ SkColorGetB(color) * factor * alpha,
+ alpha
+ } };
+ return result;
+}
+
// Smallest unit that impact anti-aliasing output. We use this to
// determine when anti-aliasing is unnecessary.
const float kAntiAliasingEpsilon = 1.0f / 1024.0f;
@@ -1651,12 +1664,13 @@ struct TextureProgramBinding {
program_id = program->program();
sampler_location = program->fragment_shader().sampler_location();
matrix_location = program->vertex_shader().matrix_location();
- alpha_location = program->fragment_shader().alpha_location();
+ background_color_location =
+ program->fragment_shader().background_color_location();
}
int program_id;
int sampler_location;
int matrix_location;
- int alpha_location;
+ int background_color_location;
};
struct TexTransformTextureProgramBinding : TextureProgramBinding {
@@ -1710,6 +1724,12 @@ void GLRenderer::FlushTextureQuadCache() {
static_cast<int>(draw_cache_.uv_xform_location),
static_cast<int>(draw_cache_.uv_xform_data.size()),
reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front())));
+
+ Float4 background_color = PremultipliedColor(draw_cache_.background_color);
+ GLC(context_,
+ context_->uniform4fv(
+ draw_cache_.background_color_location, 1, background_color.data));
+
GLC(context_,
context_->uniform1fv(
static_cast<int>(draw_cache_.vertex_opacity_location),
@@ -1750,13 +1770,16 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame,
if (draw_cache_.program_id != binding.program_id ||
draw_cache_.resource_id != resource_id ||
draw_cache_.needs_blending != quad->ShouldDrawWithBlending() ||
+ draw_cache_.background_color != quad->background_color ||
draw_cache_.matrix_data.size() >= 8) {
FlushTextureQuadCache();
draw_cache_.program_id = binding.program_id;
draw_cache_.resource_id = resource_id;
draw_cache_.needs_blending = quad->ShouldDrawWithBlending();
+ draw_cache_.background_color = quad->background_color;
draw_cache_.uv_xform_location = binding.tex_transform_location;
+ draw_cache_.background_color_location = binding.background_color_location;
draw_cache_.vertex_opacity_location = binding.vertex_opacity_location;
draw_cache_.matrix_location = binding.matrix_location;
draw_cache_.sampler_location = binding.sampler_location;
@@ -1805,6 +1828,11 @@ void GLRenderer::DrawTextureQuad(const DrawingFrame* frame,
uv_xform.data[2],
uv_xform.data[3]));
+ Float4 background_color = PremultipliedColor(quad->background_color);
+ GLC(Context(),
+ Context()->uniform4fv(
+ binding.background_color_location, 1, background_color.data));
+
GLC(Context(),
Context()->uniform1fv(
binding.vertex_opacity_location, 4, quad->vertex_opacity));

Powered by Google App Engine
This is Rietveld 408576698