Chromium Code Reviews| Index: cc/output/gl_renderer.cc |
| diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc |
| index ac68a08c62f622ed275cca567de070aa52845e20..b1f55a539cc34fb7694fd12394442a35b9d9fe66 100644 |
| --- a/cc/output/gl_renderer.cc |
| +++ b/cc/output/gl_renderer.cc |
| @@ -81,6 +81,23 @@ Float4 UVTransform(const TextureDrawQuad* quad) { |
| return xform; |
| } |
| +Float4 UVClampRect(const TextureDrawQuad* quad, |
| + const gfx::Size& texture_size, |
| + SamplerType sampler) { |
| + gfx::SizeF half_texel(0.5f, 0.5f); |
| + gfx::RectF uv_clamp_rect(quad->uv_top_left.x(), quad->uv_top_left.y(), |
| + quad->uv_bottom_right.x() - quad->uv_top_left.x(), |
| + quad->uv_bottom_right.y() - quad->uv_top_left.y()); |
| + if (sampler != SAMPLER_TYPE_2D_RECT) { |
| + half_texel.Scale(1.f / texture_size.width(), 1.f / texture_size.height()); |
| + } else { |
| + uv_clamp_rect.Scale(texture_size.width(), texture_size.height()); |
| + } |
| + uv_clamp_rect.Inset(half_texel.width(), half_texel.height()); |
| + return {{uv_clamp_rect.x(), uv_clamp_rect.y(), uv_clamp_rect.right(), |
| + uv_clamp_rect.bottom()}}; |
| +} |
| + |
| Float4 PremultipliedColor(SkColor color) { |
| const float factor = 1.0f / 255.0f; |
| const float alpha = SkColorGetA(color) * factor; |
| @@ -2485,8 +2502,19 @@ void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
| gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); |
| - SetShaderOpacity(quad->shared_quad_state->opacity, |
| - program->fragment_shader().alpha_location()); |
| + // Prevent texture bleeding issue. |
|
enne (OOO)
2016/10/19 19:04:03
comment nit: I don't think it's helpful to have th
dshwang
2016/10/20 18:57:55
Done.
|
| + { |
| + gfx::Size texture_size = lock.size(); |
| + gfx::SizeF half_texel(0.5f / texture_size.width(), |
| + 0.5f / texture_size.height()); |
| + gfx::Vector2dF uv = quad->matrix.Scale2d(); |
| + gfx::RectF tex_clamp_rect(0, 0, uv.x(), uv.y()); |
| + tex_clamp_rect.Inset(half_texel.width(), half_texel.height()); |
| + gl_->Uniform4f(program->fragment_shader().tex_clamp_rect_location(), |
| + tex_clamp_rect.x(), tex_clamp_rect.y(), |
| + tex_clamp_rect.right(), tex_clamp_rect.bottom()); |
| + } |
| + |
| if (!clip_region) { |
| DrawQuadGeometry(frame->projection_matrix, |
| quad->shared_quad_state->quad_to_target_transform, |
| @@ -2529,9 +2557,12 @@ struct TexTransformTextureProgramBinding : TextureProgramBinding { |
| tex_transform_location = program->vertex_shader().tex_transform_location(); |
| vertex_opacity_location = |
| program->vertex_shader().vertex_opacity_location(); |
| + tex_clamp_rect_location = |
| + program->fragment_shader().tex_clamp_rect_location(); |
| } |
| int tex_transform_location; |
| int vertex_opacity_location; |
| + int tex_clamp_rect_location; |
| }; |
| void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { |
| @@ -2572,6 +2603,12 @@ void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { |
| static_cast<int>(draw_cache_.uv_xform_data.size()), |
| reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front())); |
| + // Prevent texture bleeding issue. |
| + gl_->Uniform4fv( |
| + draw_cache_.tex_clamp_rect_location, |
| + static_cast<int>(draw_cache_.tex_clamp_rect_data.size()), |
| + reinterpret_cast<float*>(&draw_cache_.tex_clamp_rect_data.front())); |
| + |
| if (draw_cache_.background_color != SK_ColorTRANSPARENT) { |
| Float4 background_color = PremultipliedColor(draw_cache_.background_color); |
| gl_->Uniform4fv(draw_cache_.background_color_location, 1, |
| @@ -2615,6 +2652,7 @@ void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { |
| // Clear the cache. |
| draw_cache_.program_id = -1; |
| draw_cache_.uv_xform_data.resize(0); |
| + draw_cache_.tex_clamp_rect_data.resize(0); |
| draw_cache_.vertex_opacity_data.resize(0); |
| draw_cache_.matrix_data.resize(0); |
| @@ -2679,6 +2717,7 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, |
| draw_cache_.background_color = quad->background_color; |
| draw_cache_.uv_xform_location = binding.tex_transform_location; |
| + draw_cache_.tex_clamp_rect_location = binding.tex_clamp_rect_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; |
| @@ -2699,6 +2738,19 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, |
| } |
| draw_cache_.uv_xform_data.push_back(uv_transform); |
| + // Prevent texture bleeding issue. |
| + if (draw_cache_.tex_clamp_rect_location != -1) { |
| + // VideoLayerImpl always set background color to transparent. |
| + DCHECK(quad->background_color == SK_ColorTRANSPARENT); |
| + gfx::Size texture_size = lock.size(); |
| + if (texture_size.IsEmpty()) { |
| + // TODO(dshwang): correct all code coming to here. crbug.com/615325 |
| + texture_size = quad->rect.size(); |
| + } |
| + Float4 tex_clamp_rect = UVClampRect(quad, texture_size, sampler); |
| + draw_cache_.tex_clamp_rect_data.push_back(tex_clamp_rect); |
|
enne (OOO)
2016/10/19 19:04:03
This is a bit odd. I think that draw_cache_'s vec
dshwang
2016/10/20 18:57:55
I don't understand why you think this would get co
|
| + } |
| + |
| // Generate the vertex opacity |
| const float opacity = quad->shared_quad_state->opacity; |
| draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); |