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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 2418173002: Fix HTML5 video blurry (Closed)
Patch Set: fix nits Created 4 years, 1 month 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 gfx::PointF uv0 = quad->uv_top_left; 74 gfx::PointF uv0 = quad->uv_top_left;
75 gfx::PointF uv1 = quad->uv_bottom_right; 75 gfx::PointF uv1 = quad->uv_bottom_right;
76 Float4 xform = {{uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y()}}; 76 Float4 xform = {{uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y()}};
77 if (quad->y_flipped) { 77 if (quad->y_flipped) {
78 xform.data[1] = 1.0f - xform.data[1]; 78 xform.data[1] = 1.0f - xform.data[1];
79 xform.data[3] = -xform.data[3]; 79 xform.data[3] = -xform.data[3];
80 } 80 }
81 return xform; 81 return xform;
82 } 82 }
83 83
84 Float4 UVClampRect(gfx::RectF uv_clamp_rect,
85 const gfx::Size& texture_size,
86 SamplerType sampler) {
87 gfx::SizeF half_texel(0.5f, 0.5f);
88 if (sampler != SAMPLER_TYPE_2D_RECT) {
89 half_texel.Scale(1.f / texture_size.width(), 1.f / texture_size.height());
90 } else {
91 uv_clamp_rect.Scale(texture_size.width(), texture_size.height());
92 }
93 uv_clamp_rect.Inset(half_texel.width(), half_texel.height());
94 return {{uv_clamp_rect.x(), uv_clamp_rect.y(), uv_clamp_rect.right(),
95 uv_clamp_rect.bottom()}};
96 }
97
84 Float4 PremultipliedColor(SkColor color) { 98 Float4 PremultipliedColor(SkColor color) {
85 const float factor = 1.0f / 255.0f; 99 const float factor = 1.0f / 255.0f;
86 const float alpha = SkColorGetA(color) * factor; 100 const float alpha = SkColorGetA(color) * factor;
87 101
88 Float4 result = { 102 Float4 result = {
89 {SkColorGetR(color) * factor * alpha, SkColorGetG(color) * factor * alpha, 103 {SkColorGetR(color) * factor * alpha, SkColorGetG(color) * factor * alpha,
90 SkColorGetB(color) * factor * alpha, alpha}}; 104 SkColorGetB(color) * factor * alpha, alpha}};
91 return result; 105 return result;
92 } 106 }
93 107
(...skipping 2384 matching lines...) Expand 10 before | Expand all | Expand 10 after
2478 quad->resource_id()); 2492 quad->resource_id());
2479 2493
2480 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); 2494 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
2481 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); 2495 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id());
2482 2496
2483 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM( 2497 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM(
2484 program->vertex_shader().tex_matrix_location(), false, gl_matrix); 2498 program->vertex_shader().tex_matrix_location(), false, gl_matrix);
2485 2499
2486 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); 2500 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0);
2487 2501
2488 SetShaderOpacity(quad->shared_quad_state->opacity, 2502 gfx::Size texture_size = lock.size();
2489 program->fragment_shader().alpha_location()); 2503 gfx::Vector2dF uv = quad->matrix.Scale2d();
2504 gfx::RectF uv_clamp_rect(0, 0, uv.x(), uv.y());
2505 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target());
2506 Float4 tex_clamp_rect = UVClampRect(uv_clamp_rect, texture_size, sampler);
2507 gl_->Uniform4f(program->fragment_shader().tex_clamp_rect_location(),
2508 tex_clamp_rect.data[0], tex_clamp_rect.data[1],
2509 tex_clamp_rect.data[2], tex_clamp_rect.data[3]);
2510
2490 if (!clip_region) { 2511 if (!clip_region) {
2491 DrawQuadGeometry(frame->projection_matrix, 2512 DrawQuadGeometry(frame->projection_matrix,
2492 quad->shared_quad_state->quad_to_target_transform, 2513 quad->shared_quad_state->quad_to_target_transform,
2493 gfx::RectF(quad->rect), 2514 gfx::RectF(quad->rect),
2494 program->vertex_shader().matrix_location()); 2515 program->vertex_shader().matrix_location());
2495 } else { 2516 } else {
2496 gfx::QuadF region_quad(*clip_region); 2517 gfx::QuadF region_quad(*clip_region);
2497 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); 2518 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height());
2498 region_quad -= gfx::Vector2dF(0.5f, 0.5f); 2519 region_quad -= gfx::Vector2dF(0.5f, 0.5f);
2499 float uvs[8] = {0}; 2520 float uvs[8] = {0};
(...skipping 22 matching lines...) Expand all
2522 int background_color_location; 2543 int background_color_location;
2523 }; 2544 };
2524 2545
2525 struct TexTransformTextureProgramBinding : TextureProgramBinding { 2546 struct TexTransformTextureProgramBinding : TextureProgramBinding {
2526 template <class Program> 2547 template <class Program>
2527 void Set(Program* program) { 2548 void Set(Program* program) {
2528 TextureProgramBinding::Set(program); 2549 TextureProgramBinding::Set(program);
2529 tex_transform_location = program->vertex_shader().tex_transform_location(); 2550 tex_transform_location = program->vertex_shader().tex_transform_location();
2530 vertex_opacity_location = 2551 vertex_opacity_location =
2531 program->vertex_shader().vertex_opacity_location(); 2552 program->vertex_shader().vertex_opacity_location();
2553 tex_clamp_rect_location =
2554 program->fragment_shader().tex_clamp_rect_location();
2532 } 2555 }
2533 int tex_transform_location; 2556 int tex_transform_location;
2534 int vertex_opacity_location; 2557 int vertex_opacity_location;
2558 int tex_clamp_rect_location;
2535 }; 2559 };
2536 2560
2537 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { 2561 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) {
2538 // Check to see if we have anything to draw. 2562 // Check to see if we have anything to draw.
2539 if (draw_cache_.program_id == -1) 2563 if (draw_cache_.program_id == -1)
2540 return; 2564 return;
2541 2565
2542 PrepareGeometry(flush_binding); 2566 PrepareGeometry(flush_binding);
2543 2567
2544 // Set the correct blending mode. 2568 // Set the correct blending mode.
(...skipping 20 matching lines...) Expand all
2565 2589
2566 // Upload the tranforms for both points and uvs. 2590 // Upload the tranforms for both points and uvs.
2567 gl_->UniformMatrix4fv( 2591 gl_->UniformMatrix4fv(
2568 static_cast<int>(draw_cache_.matrix_location), 2592 static_cast<int>(draw_cache_.matrix_location),
2569 static_cast<int>(draw_cache_.matrix_data.size()), false, 2593 static_cast<int>(draw_cache_.matrix_data.size()), false,
2570 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())); 2594 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()));
2571 gl_->Uniform4fv(static_cast<int>(draw_cache_.uv_xform_location), 2595 gl_->Uniform4fv(static_cast<int>(draw_cache_.uv_xform_location),
2572 static_cast<int>(draw_cache_.uv_xform_data.size()), 2596 static_cast<int>(draw_cache_.uv_xform_data.size()),
2573 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front())); 2597 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front()));
2574 2598
2599 gl_->Uniform4fv(
2600 draw_cache_.tex_clamp_rect_location,
2601 static_cast<int>(draw_cache_.tex_clamp_rect_data.size()),
2602 reinterpret_cast<float*>(&draw_cache_.tex_clamp_rect_data.front()));
2603
2575 if (draw_cache_.background_color != SK_ColorTRANSPARENT) { 2604 if (draw_cache_.background_color != SK_ColorTRANSPARENT) {
2576 Float4 background_color = PremultipliedColor(draw_cache_.background_color); 2605 Float4 background_color = PremultipliedColor(draw_cache_.background_color);
2577 gl_->Uniform4fv(draw_cache_.background_color_location, 1, 2606 gl_->Uniform4fv(draw_cache_.background_color_location, 1,
2578 background_color.data); 2607 background_color.data);
2579 } 2608 }
2580 2609
2581 gl_->Uniform1fv( 2610 gl_->Uniform1fv(
2582 static_cast<int>(draw_cache_.vertex_opacity_location), 2611 static_cast<int>(draw_cache_.vertex_opacity_location),
2583 static_cast<int>(draw_cache_.vertex_opacity_data.size()), 2612 static_cast<int>(draw_cache_.vertex_opacity_data.size()),
2584 static_cast<float*>(&draw_cache_.vertex_opacity_data.front())); 2613 static_cast<float*>(&draw_cache_.vertex_opacity_data.front()));
(...skipping 23 matching lines...) Expand all
2608 2637
2609 gl_->LineWidth(3.0f); 2638 gl_->LineWidth(3.0f);
2610 // The indices for the line are stored in the same array as the triangle 2639 // The indices for the line are stored in the same array as the triangle
2611 // indices. 2640 // indices.
2612 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); 2641 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0);
2613 } 2642 }
2614 2643
2615 // Clear the cache. 2644 // Clear the cache.
2616 draw_cache_.program_id = -1; 2645 draw_cache_.program_id = -1;
2617 draw_cache_.uv_xform_data.resize(0); 2646 draw_cache_.uv_xform_data.resize(0);
2647 draw_cache_.tex_clamp_rect_data.resize(0);
2618 draw_cache_.vertex_opacity_data.resize(0); 2648 draw_cache_.vertex_opacity_data.resize(0);
2619 draw_cache_.matrix_data.resize(0); 2649 draw_cache_.matrix_data.resize(0);
2620 2650
2621 // If we had a clipped binding, prepare the shared binding for the 2651 // If we had a clipped binding, prepare the shared binding for the
2622 // next inserts. 2652 // next inserts.
2623 if (flush_binding == CLIPPED_BINDING) { 2653 if (flush_binding == CLIPPED_BINDING) {
2624 PrepareGeometry(SHARED_BINDING); 2654 PrepareGeometry(SHARED_BINDING);
2625 } 2655 }
2626 } 2656 }
2627 2657
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2672 draw_cache_.background_color != quad->background_color || 2702 draw_cache_.background_color != quad->background_color ||
2673 draw_cache_.matrix_data.size() >= max_quads) { 2703 draw_cache_.matrix_data.size() >= max_quads) {
2674 FlushTextureQuadCache(SHARED_BINDING); 2704 FlushTextureQuadCache(SHARED_BINDING);
2675 draw_cache_.program_id = binding.program_id; 2705 draw_cache_.program_id = binding.program_id;
2676 draw_cache_.resource_id = resource_id; 2706 draw_cache_.resource_id = resource_id;
2677 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); 2707 draw_cache_.needs_blending = quad->ShouldDrawWithBlending();
2678 draw_cache_.nearest_neighbor = quad->nearest_neighbor; 2708 draw_cache_.nearest_neighbor = quad->nearest_neighbor;
2679 draw_cache_.background_color = quad->background_color; 2709 draw_cache_.background_color = quad->background_color;
2680 2710
2681 draw_cache_.uv_xform_location = binding.tex_transform_location; 2711 draw_cache_.uv_xform_location = binding.tex_transform_location;
2712 draw_cache_.tex_clamp_rect_location = binding.tex_clamp_rect_location;
2682 draw_cache_.background_color_location = binding.background_color_location; 2713 draw_cache_.background_color_location = binding.background_color_location;
2683 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; 2714 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location;
2684 draw_cache_.matrix_location = binding.matrix_location; 2715 draw_cache_.matrix_location = binding.matrix_location;
2685 draw_cache_.sampler_location = binding.sampler_location; 2716 draw_cache_.sampler_location = binding.sampler_location;
2686 } 2717 }
2687 2718
2688 // Generate the uv-transform 2719 // Generate the uv-transform
2689 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; 2720 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}};
2690 if (!clip_region) 2721 if (!clip_region)
2691 uv_transform = UVTransform(quad); 2722 uv_transform = UVTransform(quad);
2692 if (sampler == SAMPLER_TYPE_2D_RECT) { 2723 if (sampler == SAMPLER_TYPE_2D_RECT) {
2693 // Un-normalize the texture coordiantes for rectangle targets. 2724 // Un-normalize the texture coordiantes for rectangle targets.
2694 gfx::Size texture_size = lock.size(); 2725 gfx::Size texture_size = lock.size();
2695 uv_transform.data[0] *= texture_size.width(); 2726 uv_transform.data[0] *= texture_size.width();
2696 uv_transform.data[2] *= texture_size.width(); 2727 uv_transform.data[2] *= texture_size.width();
2697 uv_transform.data[1] *= texture_size.height(); 2728 uv_transform.data[1] *= texture_size.height();
2698 uv_transform.data[3] *= texture_size.height(); 2729 uv_transform.data[3] *= texture_size.height();
2699 } 2730 }
2700 draw_cache_.uv_xform_data.push_back(uv_transform); 2731 draw_cache_.uv_xform_data.push_back(uv_transform);
2701 2732
2733 if (draw_cache_.tex_clamp_rect_location != -1) {
2734 // VideoLayerImpl always set background color to transparent.
2735 DCHECK(quad->background_color == SK_ColorTRANSPARENT);
2736 gfx::Size texture_size = lock.size();
2737 if (texture_size.IsEmpty()) {
2738 // TODO(dshwang): correct all code coming to here. crbug.com/615325
2739 texture_size = quad->rect.size();
2740 }
2741 gfx::RectF uv_clamp_rect(quad->uv_top_left.x(), quad->uv_top_left.y(),
2742 quad->uv_bottom_right.x() - quad->uv_top_left.x(),
2743 quad->uv_bottom_right.y() - quad->uv_top_left.y());
2744 Float4 tex_clamp_rect = UVClampRect(uv_clamp_rect, texture_size, sampler);
2745 draw_cache_.tex_clamp_rect_data.push_back(tex_clamp_rect);
2746 DCHECK_EQ(draw_cache_.uv_xform_data.size(),
2747 draw_cache_.tex_clamp_rect_data.size());
2748 }
2749
2702 // Generate the vertex opacity 2750 // Generate the vertex opacity
2703 const float opacity = quad->shared_quad_state->opacity; 2751 const float opacity = quad->shared_quad_state->opacity;
2704 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); 2752 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity);
2705 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity); 2753 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity);
2706 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity); 2754 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity);
2707 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); 2755 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity);
2708 2756
2709 // Generate the transform matrix 2757 // Generate the transform matrix
2710 gfx::Transform quad_rect_matrix; 2758 gfx::Transform quad_rect_matrix;
2711 QuadRectTransform(&quad_rect_matrix, 2759 QuadRectTransform(&quad_rect_matrix,
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after
4044 4092
4045 gl_->ScheduleCALayerSharedStateCHROMIUM( 4093 gl_->ScheduleCALayerSharedStateCHROMIUM(
4046 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, 4094 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect,
4047 sorting_context_id, gl_transform); 4095 sorting_context_id, gl_transform);
4048 gl_->ScheduleCALayerCHROMIUM( 4096 gl_->ScheduleCALayerCHROMIUM(
4049 texture_id, contents_rect, ca_layer_overlay->background_color, 4097 texture_id, contents_rect, ca_layer_overlay->background_color,
4050 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); 4098 ca_layer_overlay->edge_aa_mask, bounds_rect, filter);
4051 } 4099 }
4052 4100
4053 } // namespace cc 4101 } // namespace cc
OLDNEW
« 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