OLD | NEW |
---|---|
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 Loading... | |
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(const TextureDrawQuad* quad, | |
85 const gfx::Size& texture_size, | |
86 SamplerType sampler) { | |
87 gfx::SizeF half_texel(0.5f, 0.5f); | |
88 gfx::RectF uv_clamp_rect(quad->uv_top_left.x(), quad->uv_top_left.y(), | |
89 quad->uv_bottom_right.x() - quad->uv_top_left.x(), | |
90 quad->uv_bottom_right.y() - quad->uv_top_left.y()); | |
91 if (sampler != SAMPLER_TYPE_2D_RECT) { | |
92 half_texel.Scale(1.f / texture_size.width(), 1.f / texture_size.height()); | |
93 } else { | |
94 uv_clamp_rect.Scale(texture_size.width(), texture_size.height()); | |
95 } | |
96 uv_clamp_rect.Inset(half_texel.width(), half_texel.height()); | |
97 return {{uv_clamp_rect.x(), uv_clamp_rect.y(), uv_clamp_rect.right(), | |
98 uv_clamp_rect.bottom()}}; | |
99 } | |
100 | |
84 Float4 PremultipliedColor(SkColor color) { | 101 Float4 PremultipliedColor(SkColor color) { |
85 const float factor = 1.0f / 255.0f; | 102 const float factor = 1.0f / 255.0f; |
86 const float alpha = SkColorGetA(color) * factor; | 103 const float alpha = SkColorGetA(color) * factor; |
87 | 104 |
88 Float4 result = { | 105 Float4 result = { |
89 {SkColorGetR(color) * factor * alpha, SkColorGetG(color) * factor * alpha, | 106 {SkColorGetR(color) * factor * alpha, SkColorGetG(color) * factor * alpha, |
90 SkColorGetB(color) * factor * alpha, alpha}}; | 107 SkColorGetB(color) * factor * alpha, alpha}}; |
91 return result; | 108 return result; |
92 } | 109 } |
93 | 110 |
(...skipping 2384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2478 quad->resource_id()); | 2495 quad->resource_id()); |
2479 | 2496 |
2480 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2497 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
2481 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); | 2498 gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()); |
2482 | 2499 |
2483 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM( | 2500 gl_->UniformMatrix4fvStreamTextureMatrixCHROMIUM( |
2484 program->vertex_shader().tex_matrix_location(), false, gl_matrix); | 2501 program->vertex_shader().tex_matrix_location(), false, gl_matrix); |
2485 | 2502 |
2486 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); | 2503 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); |
2487 | 2504 |
2488 SetShaderOpacity(quad->shared_quad_state->opacity, | 2505 // 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.
| |
2489 program->fragment_shader().alpha_location()); | 2506 { |
2507 gfx::Size texture_size = lock.size(); | |
2508 gfx::SizeF half_texel(0.5f / texture_size.width(), | |
2509 0.5f / texture_size.height()); | |
2510 gfx::Vector2dF uv = quad->matrix.Scale2d(); | |
2511 gfx::RectF tex_clamp_rect(0, 0, uv.x(), uv.y()); | |
2512 tex_clamp_rect.Inset(half_texel.width(), half_texel.height()); | |
2513 gl_->Uniform4f(program->fragment_shader().tex_clamp_rect_location(), | |
2514 tex_clamp_rect.x(), tex_clamp_rect.y(), | |
2515 tex_clamp_rect.right(), tex_clamp_rect.bottom()); | |
2516 } | |
2517 | |
2490 if (!clip_region) { | 2518 if (!clip_region) { |
2491 DrawQuadGeometry(frame->projection_matrix, | 2519 DrawQuadGeometry(frame->projection_matrix, |
2492 quad->shared_quad_state->quad_to_target_transform, | 2520 quad->shared_quad_state->quad_to_target_transform, |
2493 gfx::RectF(quad->rect), | 2521 gfx::RectF(quad->rect), |
2494 program->vertex_shader().matrix_location()); | 2522 program->vertex_shader().matrix_location()); |
2495 } else { | 2523 } else { |
2496 gfx::QuadF region_quad(*clip_region); | 2524 gfx::QuadF region_quad(*clip_region); |
2497 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); | 2525 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); |
2498 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | 2526 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
2499 float uvs[8] = {0}; | 2527 float uvs[8] = {0}; |
(...skipping 22 matching lines...) Expand all Loading... | |
2522 int background_color_location; | 2550 int background_color_location; |
2523 }; | 2551 }; |
2524 | 2552 |
2525 struct TexTransformTextureProgramBinding : TextureProgramBinding { | 2553 struct TexTransformTextureProgramBinding : TextureProgramBinding { |
2526 template <class Program> | 2554 template <class Program> |
2527 void Set(Program* program) { | 2555 void Set(Program* program) { |
2528 TextureProgramBinding::Set(program); | 2556 TextureProgramBinding::Set(program); |
2529 tex_transform_location = program->vertex_shader().tex_transform_location(); | 2557 tex_transform_location = program->vertex_shader().tex_transform_location(); |
2530 vertex_opacity_location = | 2558 vertex_opacity_location = |
2531 program->vertex_shader().vertex_opacity_location(); | 2559 program->vertex_shader().vertex_opacity_location(); |
2560 tex_clamp_rect_location = | |
2561 program->fragment_shader().tex_clamp_rect_location(); | |
2532 } | 2562 } |
2533 int tex_transform_location; | 2563 int tex_transform_location; |
2534 int vertex_opacity_location; | 2564 int vertex_opacity_location; |
2565 int tex_clamp_rect_location; | |
2535 }; | 2566 }; |
2536 | 2567 |
2537 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { | 2568 void GLRenderer::FlushTextureQuadCache(BoundGeometry flush_binding) { |
2538 // Check to see if we have anything to draw. | 2569 // Check to see if we have anything to draw. |
2539 if (draw_cache_.program_id == -1) | 2570 if (draw_cache_.program_id == -1) |
2540 return; | 2571 return; |
2541 | 2572 |
2542 PrepareGeometry(flush_binding); | 2573 PrepareGeometry(flush_binding); |
2543 | 2574 |
2544 // Set the correct blending mode. | 2575 // Set the correct blending mode. |
(...skipping 20 matching lines...) Expand all Loading... | |
2565 | 2596 |
2566 // Upload the tranforms for both points and uvs. | 2597 // Upload the tranforms for both points and uvs. |
2567 gl_->UniformMatrix4fv( | 2598 gl_->UniformMatrix4fv( |
2568 static_cast<int>(draw_cache_.matrix_location), | 2599 static_cast<int>(draw_cache_.matrix_location), |
2569 static_cast<int>(draw_cache_.matrix_data.size()), false, | 2600 static_cast<int>(draw_cache_.matrix_data.size()), false, |
2570 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())); | 2601 reinterpret_cast<float*>(&draw_cache_.matrix_data.front())); |
2571 gl_->Uniform4fv(static_cast<int>(draw_cache_.uv_xform_location), | 2602 gl_->Uniform4fv(static_cast<int>(draw_cache_.uv_xform_location), |
2572 static_cast<int>(draw_cache_.uv_xform_data.size()), | 2603 static_cast<int>(draw_cache_.uv_xform_data.size()), |
2573 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front())); | 2604 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front())); |
2574 | 2605 |
2606 // Prevent texture bleeding issue. | |
2607 gl_->Uniform4fv( | |
2608 draw_cache_.tex_clamp_rect_location, | |
2609 static_cast<int>(draw_cache_.tex_clamp_rect_data.size()), | |
2610 reinterpret_cast<float*>(&draw_cache_.tex_clamp_rect_data.front())); | |
2611 | |
2575 if (draw_cache_.background_color != SK_ColorTRANSPARENT) { | 2612 if (draw_cache_.background_color != SK_ColorTRANSPARENT) { |
2576 Float4 background_color = PremultipliedColor(draw_cache_.background_color); | 2613 Float4 background_color = PremultipliedColor(draw_cache_.background_color); |
2577 gl_->Uniform4fv(draw_cache_.background_color_location, 1, | 2614 gl_->Uniform4fv(draw_cache_.background_color_location, 1, |
2578 background_color.data); | 2615 background_color.data); |
2579 } | 2616 } |
2580 | 2617 |
2581 gl_->Uniform1fv( | 2618 gl_->Uniform1fv( |
2582 static_cast<int>(draw_cache_.vertex_opacity_location), | 2619 static_cast<int>(draw_cache_.vertex_opacity_location), |
2583 static_cast<int>(draw_cache_.vertex_opacity_data.size()), | 2620 static_cast<int>(draw_cache_.vertex_opacity_data.size()), |
2584 static_cast<float*>(&draw_cache_.vertex_opacity_data.front())); | 2621 static_cast<float*>(&draw_cache_.vertex_opacity_data.front())); |
(...skipping 23 matching lines...) Expand all Loading... | |
2608 | 2645 |
2609 gl_->LineWidth(3.0f); | 2646 gl_->LineWidth(3.0f); |
2610 // The indices for the line are stored in the same array as the triangle | 2647 // The indices for the line are stored in the same array as the triangle |
2611 // indices. | 2648 // indices. |
2612 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); | 2649 gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0); |
2613 } | 2650 } |
2614 | 2651 |
2615 // Clear the cache. | 2652 // Clear the cache. |
2616 draw_cache_.program_id = -1; | 2653 draw_cache_.program_id = -1; |
2617 draw_cache_.uv_xform_data.resize(0); | 2654 draw_cache_.uv_xform_data.resize(0); |
2655 draw_cache_.tex_clamp_rect_data.resize(0); | |
2618 draw_cache_.vertex_opacity_data.resize(0); | 2656 draw_cache_.vertex_opacity_data.resize(0); |
2619 draw_cache_.matrix_data.resize(0); | 2657 draw_cache_.matrix_data.resize(0); |
2620 | 2658 |
2621 // If we had a clipped binding, prepare the shared binding for the | 2659 // If we had a clipped binding, prepare the shared binding for the |
2622 // next inserts. | 2660 // next inserts. |
2623 if (flush_binding == CLIPPED_BINDING) { | 2661 if (flush_binding == CLIPPED_BINDING) { |
2624 PrepareGeometry(SHARED_BINDING); | 2662 PrepareGeometry(SHARED_BINDING); |
2625 } | 2663 } |
2626 } | 2664 } |
2627 | 2665 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2672 draw_cache_.background_color != quad->background_color || | 2710 draw_cache_.background_color != quad->background_color || |
2673 draw_cache_.matrix_data.size() >= max_quads) { | 2711 draw_cache_.matrix_data.size() >= max_quads) { |
2674 FlushTextureQuadCache(SHARED_BINDING); | 2712 FlushTextureQuadCache(SHARED_BINDING); |
2675 draw_cache_.program_id = binding.program_id; | 2713 draw_cache_.program_id = binding.program_id; |
2676 draw_cache_.resource_id = resource_id; | 2714 draw_cache_.resource_id = resource_id; |
2677 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); | 2715 draw_cache_.needs_blending = quad->ShouldDrawWithBlending(); |
2678 draw_cache_.nearest_neighbor = quad->nearest_neighbor; | 2716 draw_cache_.nearest_neighbor = quad->nearest_neighbor; |
2679 draw_cache_.background_color = quad->background_color; | 2717 draw_cache_.background_color = quad->background_color; |
2680 | 2718 |
2681 draw_cache_.uv_xform_location = binding.tex_transform_location; | 2719 draw_cache_.uv_xform_location = binding.tex_transform_location; |
2720 draw_cache_.tex_clamp_rect_location = binding.tex_clamp_rect_location; | |
2682 draw_cache_.background_color_location = binding.background_color_location; | 2721 draw_cache_.background_color_location = binding.background_color_location; |
2683 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; | 2722 draw_cache_.vertex_opacity_location = binding.vertex_opacity_location; |
2684 draw_cache_.matrix_location = binding.matrix_location; | 2723 draw_cache_.matrix_location = binding.matrix_location; |
2685 draw_cache_.sampler_location = binding.sampler_location; | 2724 draw_cache_.sampler_location = binding.sampler_location; |
2686 } | 2725 } |
2687 | 2726 |
2688 // Generate the uv-transform | 2727 // Generate the uv-transform |
2689 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; | 2728 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; |
2690 if (!clip_region) | 2729 if (!clip_region) |
2691 uv_transform = UVTransform(quad); | 2730 uv_transform = UVTransform(quad); |
2692 if (sampler == SAMPLER_TYPE_2D_RECT) { | 2731 if (sampler == SAMPLER_TYPE_2D_RECT) { |
2693 // Un-normalize the texture coordiantes for rectangle targets. | 2732 // Un-normalize the texture coordiantes for rectangle targets. |
2694 gfx::Size texture_size = lock.size(); | 2733 gfx::Size texture_size = lock.size(); |
2695 uv_transform.data[0] *= texture_size.width(); | 2734 uv_transform.data[0] *= texture_size.width(); |
2696 uv_transform.data[2] *= texture_size.width(); | 2735 uv_transform.data[2] *= texture_size.width(); |
2697 uv_transform.data[1] *= texture_size.height(); | 2736 uv_transform.data[1] *= texture_size.height(); |
2698 uv_transform.data[3] *= texture_size.height(); | 2737 uv_transform.data[3] *= texture_size.height(); |
2699 } | 2738 } |
2700 draw_cache_.uv_xform_data.push_back(uv_transform); | 2739 draw_cache_.uv_xform_data.push_back(uv_transform); |
2701 | 2740 |
2741 // Prevent texture bleeding issue. | |
2742 if (draw_cache_.tex_clamp_rect_location != -1) { | |
2743 // VideoLayerImpl always set background color to transparent. | |
2744 DCHECK(quad->background_color == SK_ColorTRANSPARENT); | |
2745 gfx::Size texture_size = lock.size(); | |
2746 if (texture_size.IsEmpty()) { | |
2747 // TODO(dshwang): correct all code coming to here. crbug.com/615325 | |
2748 texture_size = quad->rect.size(); | |
2749 } | |
2750 Float4 tex_clamp_rect = UVClampRect(quad, texture_size, sampler); | |
2751 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
| |
2752 } | |
2753 | |
2702 // Generate the vertex opacity | 2754 // Generate the vertex opacity |
2703 const float opacity = quad->shared_quad_state->opacity; | 2755 const float opacity = quad->shared_quad_state->opacity; |
2704 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); | 2756 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); | 2757 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); | 2758 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); | 2759 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity); |
2708 | 2760 |
2709 // Generate the transform matrix | 2761 // Generate the transform matrix |
2710 gfx::Transform quad_rect_matrix; | 2762 gfx::Transform quad_rect_matrix; |
2711 QuadRectTransform(&quad_rect_matrix, | 2763 QuadRectTransform(&quad_rect_matrix, |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4044 | 4096 |
4045 gl_->ScheduleCALayerSharedStateCHROMIUM( | 4097 gl_->ScheduleCALayerSharedStateCHROMIUM( |
4046 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, | 4098 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, |
4047 sorting_context_id, gl_transform); | 4099 sorting_context_id, gl_transform); |
4048 gl_->ScheduleCALayerCHROMIUM( | 4100 gl_->ScheduleCALayerCHROMIUM( |
4049 texture_id, contents_rect, ca_layer_overlay->background_color, | 4101 texture_id, contents_rect, ca_layer_overlay->background_color, |
4050 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); | 4102 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); |
4051 } | 4103 } |
4052 | 4104 |
4053 } // namespace cc | 4105 } // namespace cc |
OLD | NEW |