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

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

Issue 2547683003: Reland "Fix HTML5 video blurry" (Closed)
Patch Set: rebase to ToT Created 4 years 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
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 2382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2476 quad->resource_id()); 2490 quad->resource_id());
2477 2491
2478 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); 2492 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
2479 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); 2493 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id());
2480 2494
2481 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM( 2495 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM(
2482 program->vertex_shader().tex_matrix_location(), false, gl_matrix); 2496 program->vertex_shader().tex_matrix_location(), false, gl_matrix);
2483 2497
2484 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); 2498 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0);
2485 2499
2486 SetShaderOpacity(quad->shared_quad_state->opacity, 2500 gfx::Size texture_size = lock.size();
2487 program->fragment_shader().alpha_location()); 2501 gfx::Vector2dF uv = quad->matrix.Scale2d();
2502 gfx::RectF uv_clamp_rect(0, 0, uv.x(), uv.y());
2503 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target());
2504 Float4 tex_clamp_rect = UVClampRect(uv_clamp_rect, texture_size, sampler);
2505 gl_->Uniform4f(program->fragment_shader().tex_clamp_rect_location(),
2506 tex_clamp_rect.data[0], tex_clamp_rect.data[1],
2507 tex_clamp_rect.data[2], tex_clamp_rect.data[3]);
2508
2488 if (!clip_region) { 2509 if (!clip_region) {
2489 DrawQuadGeometry(frame->projection_matrix, 2510 DrawQuadGeometry(frame->projection_matrix,
2490 quad->shared_quad_state->quad_to_target_transform, 2511 quad->shared_quad_state->quad_to_target_transform,
2491 gfx::RectF(quad->rect), 2512 gfx::RectF(quad->rect),
2492 program->vertex_shader().matrix_location()); 2513 program->vertex_shader().matrix_location());
2493 } else { 2514 } else {
2494 gfx::QuadF region_quad(*clip_region); 2515 gfx::QuadF region_quad(*clip_region);
2495 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); 2516 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height());
2496 region_quad -= gfx::Vector2dF(0.5f, 0.5f); 2517 region_quad -= gfx::Vector2dF(0.5f, 0.5f);
2497 float uvs[8] = {0}; 2518 float uvs[8] = {0};
(...skipping 22 matching lines...) Expand all
2520 int background_color_location; 2541 int background_color_location;
2521 }; 2542 };
2522 2543
2523 struct TexTransformTextureProgramBinding : TextureProgramBinding { 2544 struct TexTransformTextureProgramBinding : TextureProgramBinding {
2524 template <class Program> 2545 template <class Program>
2525 void Set(Program* program) { 2546 void Set(Program* program) {
2526 TextureProgramBinding::Set(program); 2547 TextureProgramBinding::Set(program);
2527 tex_transform_location = program->vertex_shader().tex_transform_location(); 2548 tex_transform_location = program->vertex_shader().tex_transform_location();
2528 vertex_opacity_location = 2549 vertex_opacity_location =
2529 program->vertex_shader().vertex_opacity_location(); 2550 program->vertex_shader().vertex_opacity_location();
2551 tex_clamp_rect_location =
2552 program->fragment_shader().tex_clamp_rect_location();
2530 } 2553 }
2531 int tex_transform_location; 2554 int tex_transform_location;
2532 int vertex_opacity_location; 2555 int vertex_opacity_location;
2556 int tex_clamp_rect_location;
2533 }; 2557 };
2534 2558
2535 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { 2559 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) {
2536 // Check to see if we have anything to draw. 2560 // Check to see if we have anything to draw.
2537 if (draw_cache_.program_id == -1) 2561 if (draw_cache_.program_id == -1)
2538 return; 2562 return;
2539 2563
2540 PrepareGeometry(flush_binding); 2564 PrepareGeometry(flush_binding);
2541 2565
2542 // Set the correct blending mode. 2566 // Set the correct blending mode.
(...skipping 20 matching lines...) Expand all
2563 2587
2564 // Upload the tranforms for both points and uvs. 2588 // Upload the tranforms for both points and uvs.
2565 gl_->UniformMatrix4fv( 2589 gl_->UniformMatrix4fv(
2566 static_cast<int>(draw_cache_.matrix_location), 2590 static_cast<int>(draw_cache_.matrix_location),
2567 static_cast<int>(draw_cache_.matrix_data.size()), false, 2591 static_cast<int>(draw_cache_.matrix_data.size()), false,
2568 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())); 2592 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()));
2569 gl_->Uniform4fv(static_cast<int>(draw_cache_.uv_xform_location), 2593 gl_->Uniform4fv(static_cast<int>(draw_cache_.uv_xform_location),
2570 static_cast<int>(draw_cache_.uv_xform_data.size()), 2594 static_cast<int>(draw_cache_.uv_xform_data.size()),
2571 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front())); 2595 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front()));
2572 2596
2597 if (draw_cache_.tex_clamp_rect_location != -1) {
2598 gl_->Uniform4fv(
2599 draw_cache_.tex_clamp_rect_location,
2600 static_cast<int>(draw_cache_.tex_clamp_rect_data.size()),
2601 reinterpret_cast<float*>(&draw_cache_.tex_clamp_rect_data.front()));
2602 }
2603
2573 if (draw_cache_.background_color != SK_ColorTRANSPARENT) { 2604 if (draw_cache_.background_color != SK_ColorTRANSPARENT) {
2574 Float4 background_color = PremultipliedColor(draw_cache_.background_color); 2605 Float4 background_color = PremultipliedColor(draw_cache_.background_color);
2575 gl_->Uniform4fv(draw_cache_.background_color_location, 1, 2606 gl_->Uniform4fv(draw_cache_.background_color_location, 1,
2576 background_color.data); 2607 background_color.data);
2577 } 2608 }
2578 2609
2579 gl_->Uniform1fv( 2610 gl_->Uniform1fv(
2580 static_cast<int>(draw_cache_.vertex_opacity_location), 2611 static_cast<int>(draw_cache_.vertex_opacity_location),
2581 static_cast<int>(draw_cache_.vertex_opacity_data.size()), 2612 static_cast<int>(draw_cache_.vertex_opacity_data.size()),
2582 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
2606 2637
2607 gl_->LineWidth(3.0f); 2638 gl_->LineWidth(3.0f);
2608 // 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
2609 // indices. 2640 // indices.
2610 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); 2641 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0);
2611 } 2642 }
2612 2643
2613 // Clear the cache. 2644 // Clear the cache.
2614 draw_cache_.program_id = -1; 2645 draw_cache_.program_id = -1;
2615 draw_cache_.uv_xform_data.resize(0); 2646 draw_cache_.uv_xform_data.resize(0);
2647 draw_cache_.tex_clamp_rect_data.resize(0);
2616 draw_cache_.vertex_opacity_data.resize(0); 2648 draw_cache_.vertex_opacity_data.resize(0);
2617 draw_cache_.matrix_data.resize(0); 2649 draw_cache_.matrix_data.resize(0);
2618 2650
2619 // 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
2620 // next inserts. 2652 // next inserts.
2621 if (flush_binding == CLIPPED_BINDING) { 2653 if (flush_binding == CLIPPED_BINDING) {
2622 PrepareGeometry(SHARED_BINDING); 2654 PrepareGeometry(SHARED_BINDING);
2623 } 2655 }
2624 } 2656 }
2625 2657
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 draw_cache_.background_color != quad->background_color || 2702 draw_cache_.background_color != quad->background_color ||
2671 draw_cache_.matrix_data.size() >= max_quads) { 2703 draw_cache_.matrix_data.size() >= max_quads) {
2672 FlushTextureQuadCache(SHARED_BINDING); 2704 FlushTextureQuadCache(SHARED_BINDING);
2673 draw_cache_.program_id = binding.program_id; 2705 draw_cache_.program_id = binding.program_id;
2674 draw_cache_.resource_id = resource_id; 2706 draw_cache_.resource_id = resource_id;
2675 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); 2707 draw_cache_.needs_blending = quad->ShouldDrawWithBlending();
2676 draw_cache_.nearest_neighbor = quad->nearest_neighbor; 2708 draw_cache_.nearest_neighbor = quad->nearest_neighbor;
2677 draw_cache_.background_color = quad->background_color; 2709 draw_cache_.background_color = quad->background_color;
2678 2710
2679 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;
2680 draw_cache_.background_color_location = binding.background_color_location; 2713 draw_cache_.background_color_location = binding.background_color_location;
2681 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; 2714 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location;
2682 draw_cache_.matrix_location = binding.matrix_location; 2715 draw_cache_.matrix_location = binding.matrix_location;
2683 draw_cache_.sampler_location = binding.sampler_location; 2716 draw_cache_.sampler_location = binding.sampler_location;
2684 } 2717 }
2685 2718
2686 // Generate the uv-transform 2719 // Generate the uv-transform
2687 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; 2720 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}};
2688 if (!clip_region) 2721 if (!clip_region)
2689 uv_transform = UVTransform(quad); 2722 uv_transform = UVTransform(quad);
2690 if (sampler == SAMPLER_TYPE_2D_RECT) { 2723 if (sampler == SAMPLER_TYPE_2D_RECT) {
2691 // Un-normalize the texture coordiantes for rectangle targets. 2724 // Un-normalize the texture coordiantes for rectangle targets.
2692 gfx::Size texture_size = lock.size(); 2725 gfx::Size texture_size = lock.size();
2693 uv_transform.data[0] *= texture_size.width(); 2726 uv_transform.data[0] *= texture_size.width();
2694 uv_transform.data[2] *= texture_size.width(); 2727 uv_transform.data[2] *= texture_size.width();
2695 uv_transform.data[1] *= texture_size.height(); 2728 uv_transform.data[1] *= texture_size.height();
2696 uv_transform.data[3] *= texture_size.height(); 2729 uv_transform.data[3] *= texture_size.height();
2697 } 2730 }
2698 draw_cache_.uv_xform_data.push_back(uv_transform); 2731 draw_cache_.uv_xform_data.push_back(uv_transform);
2699 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
2700 // Generate the vertex opacity 2750 // Generate the vertex opacity
2701 const float opacity = quad->shared_quad_state->opacity; 2751 const float opacity = quad->shared_quad_state->opacity;
2702 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);
2703 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);
2704 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);
2705 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);
2706 2756
2707 // Generate the transform matrix 2757 // Generate the transform matrix
2708 gfx::Transform quad_rect_matrix; 2758 gfx::Transform quad_rect_matrix;
2709 QuadRectTransform(&quad_rect_matrix, 2759 QuadRectTransform(&quad_rect_matrix,
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after
4041 // The alpha has already been applied when copying the RPDQ to an IOSurface. 4091 // The alpha has already been applied when copying the RPDQ to an IOSurface.
4042 GLfloat alpha = 1; 4092 GLfloat alpha = 1;
4043 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect, 4093 gl_->ScheduleCALayerSharedStateCHROMIUM(alpha, is_clipped, clip_rect,
4044 sorting_context_id, gl_transform); 4094 sorting_context_id, gl_transform);
4045 gl_->ScheduleCALayerCHROMIUM( 4095 gl_->ScheduleCALayerCHROMIUM(
4046 texture_id, contents_rect, ca_layer_overlay->background_color, 4096 texture_id, contents_rect, ca_layer_overlay->background_color,
4047 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); 4097 ca_layer_overlay->edge_aa_mask, bounds_rect, filter);
4048 } 4098 }
4049 4099
4050 } // namespace cc 4100 } // namespace cc
OLDNEW
« 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