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

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: 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..b2b58177a737f0d43ed2ed0626a8fd395b22d283 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 {
@@ -1711,6 +1725,12 @@ void GLRenderer::FlushTextureQuadCache() {
static_cast<int>(draw_cache_.uv_xform_data.size()),
reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front())));
GLC(context_,
+ context_->uniform4fv(
+ static_cast<int>(draw_cache_.background_color_location),
+ static_cast<int>(draw_cache_.background_color_data.size()),
+ reinterpret_cast<float*>(
+ &draw_cache_.background_color_data.front())));
+ GLC(context_,
context_->uniform1fv(
static_cast<int>(draw_cache_.vertex_opacity_location),
static_cast<int>(draw_cache_.vertex_opacity_data.size()),
@@ -1726,6 +1746,7 @@ void GLRenderer::FlushTextureQuadCache() {
// Clear the cache.
draw_cache_.program_id = 0;
draw_cache_.uv_xform_data.resize(0);
+ draw_cache_.background_color_data.resize(0);
draw_cache_.vertex_opacity_data.resize(0);
draw_cache_.matrix_data.resize(0);
}
@@ -1757,6 +1778,7 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame,
draw_cache_.needs_blending = quad->ShouldDrawWithBlending();
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;
@@ -1765,6 +1787,9 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame,
// Generate the uv-transform
draw_cache_.uv_xform_data.push_back(UVTransform(quad));
+ draw_cache_.background_color_data.push_back(
enne (OOO) 2013/07/02 01:27:22 I don't think the draw cache should support per-qu
alokp 2013/07/02 22:03:54 Done.
+ PremultipliedColor(quad->background_color));
+
// Generate the vertex opacity
const float opacity = quad->opacity();
draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity);
@@ -1805,6 +1830,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, 4, background_color.data));
+
GLC(Context(),
Context()->uniform1fv(
binding.vertex_opacity_location, 4, quad->vertex_opacity));
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_draw_cache.h » ('j') | cc/output/shader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698