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

Unified Diff: cc/output/gl_renderer.cc

Issue 2418173002: Fix HTML5 video blurry (Closed)
Patch Set: fix nits Created 4 years, 2 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/gl_renderer.h ('k') | cc/output/gl_renderer_draw_cache.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/gl_renderer.cc
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index fe9c5d8160678b2bfb02fad747fb4d8dbe7c3b21..90b177bd1aedb15478ee3001c2dc5e3fd6d4e913 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -81,6 +81,20 @@ Float4 UVTransform(const TextureDrawQuad* quad) {
return xform;
}
+Float4 UVClampRect(gfx::RectF uv_clamp_rect,
+ const gfx::Size& texture_size,
+ SamplerType sampler) {
+ gfx::SizeF half_texel(0.5f, 0.5f);
+ 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 +2499,15 @@ 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());
+ gfx::Size texture_size = lock.size();
+ gfx::Vector2dF uv = quad->matrix.Scale2d();
+ gfx::RectF uv_clamp_rect(0, 0, uv.x(), uv.y());
+ const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target());
+ Float4 tex_clamp_rect = UVClampRect(uv_clamp_rect, texture_size, sampler);
+ gl_->Uniform4f(program->fragment_shader().tex_clamp_rect_location(),
+ tex_clamp_rect.data[0], tex_clamp_rect.data[1],
+ tex_clamp_rect.data[2], tex_clamp_rect.data[3]);
+
if (!clip_region) {
DrawQuadGeometry(frame->projection_matrix,
quad->shared_quad_state->quad_to_target_transform,
@@ -2529,9 +2550,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 +2596,11 @@ void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) {
static_cast<int>(draw_cache_.uv_xform_data.size()),
reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front()));
+ 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 +2644,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 +2709,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 +2730,23 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame,
}
draw_cache_.uv_xform_data.push_back(uv_transform);
+ 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();
+ }
+ 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());
+ Float4 tex_clamp_rect = UVClampRect(uv_clamp_rect, texture_size, sampler);
+ draw_cache_.tex_clamp_rect_data.push_back(tex_clamp_rect);
+ DCHECK_EQ(draw_cache_.uv_xform_data.size(),
+ draw_cache_.tex_clamp_rect_data.size());
+ }
+
// Generate the vertex opacity
const float opacity = quad->shared_quad_state->opacity;
draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity);
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_draw_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698