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