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