OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layers/delegated_renderer_layer_impl.h" | 5 #include "cc/layers/delegated_renderer_layer_impl.h" |
6 | 6 |
7 #include "cc/base/scoped_ptr_vector.h" | 7 #include "cc/base/scoped_ptr_vector.h" |
8 #include "cc/debug/test_web_graphics_context_3d.h" | 8 #include "cc/debug/test_web_graphics_context_3d.h" |
9 #include "cc/layers/append_quads_data.h" | 9 #include "cc/layers/append_quads_data.h" |
10 #include "cc/layers/quad_sink.h" | 10 #include "cc/layers/quad_sink.h" |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 460 |
461 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create( | 461 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create( |
462 host_impl_->active_tree(), 1); | 462 host_impl_->active_tree(), 1); |
463 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer = | 463 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer = |
464 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2); | 464 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2); |
465 | 465 |
466 host_impl_->SetViewportSize(gfx::Size(200, 200)); | 466 host_impl_->SetViewportSize(gfx::Size(200, 200)); |
467 root_layer->SetBounds(gfx::Size(100, 100)); | 467 root_layer->SetBounds(gfx::Size(100, 100)); |
468 | 468 |
469 delegated_renderer_layer->SetPosition(gfx::Point(20, 20)); | 469 delegated_renderer_layer->SetPosition(gfx::Point(20, 20)); |
470 delegated_renderer_layer->SetBounds(gfx::Size(30, 30)); | 470 delegated_renderer_layer->SetBounds(gfx::Size(75, 75)); |
471 delegated_renderer_layer->SetContentBounds(gfx::Size(30, 30)); | 471 delegated_renderer_layer->SetContentBounds(gfx::Size(75, 75)); |
472 delegated_renderer_layer->SetDrawsContent(true); | 472 delegated_renderer_layer->SetDrawsContent(true); |
473 gfx::Transform transform; | 473 gfx::Transform transform; |
474 transform.Scale(2.0, 2.0); | 474 transform.Scale(2.0, 2.0); |
475 transform.Translate(8.0, 8.0); | 475 transform.Translate(8.0, 8.0); |
476 delegated_renderer_layer->SetTransform(transform); | 476 delegated_renderer_layer->SetTransform(transform); |
477 | 477 |
478 ScopedPtrVector<RenderPass> delegated_render_passes; | 478 ScopedPtrVector<RenderPass> delegated_render_passes; |
479 | 479 |
480 gfx::Size child_pass_content_bounds(7, 7); | 480 gfx::Size child_pass_content_bounds(7, 7); |
481 gfx::Rect child_pass_rect(20, 20, 7, 7); | 481 gfx::Rect child_pass_rect(20, 20, 7, 7); |
(...skipping 24 matching lines...) Expand all Loading... |
506 scoped_ptr<SolidColorDrawQuad> color_quad; | 506 scoped_ptr<SolidColorDrawQuad> color_quad; |
507 color_quad = SolidColorDrawQuad::Create(); | 507 color_quad = SolidColorDrawQuad::Create(); |
508 color_quad->SetNew(shared_quad_state, gfx::Rect(20, 20, 3, 7), 1u, false); | 508 color_quad->SetNew(shared_quad_state, gfx::Rect(20, 20, 3, 7), 1u, false); |
509 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data); | 509 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data); |
510 | 510 |
511 color_quad = SolidColorDrawQuad::Create(); | 511 color_quad = SolidColorDrawQuad::Create(); |
512 color_quad->SetNew(shared_quad_state, gfx::Rect(23, 20, 4, 7), 1u, false); | 512 color_quad->SetNew(shared_quad_state, gfx::Rect(23, 20, 4, 7), 1u, false); |
513 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data); | 513 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data); |
514 } | 514 } |
515 | 515 |
516 gfx::Size root_pass_content_bounds(50, 50); | 516 gfx::Size root_pass_content_bounds(100, 100); |
517 gfx::Rect root_pass_rect(0, 0, 50, 50); | 517 gfx::Rect root_pass_rect(0, 0, 100, 100); |
518 gfx::Transform root_pass_transform; | 518 gfx::Transform root_pass_transform; |
519 root_pass_transform.Scale(1.5, 1.5); | 519 root_pass_transform.Scale(1.5, 1.5); |
520 root_pass_transform.Translate(7.0, 7.0); | 520 root_pass_transform.Translate(7.0, 7.0); |
521 gfx::Rect root_pass_clip_rect(10, 10, 35, 35); | 521 gfx::Rect root_pass_clip_rect(10, 10, 35, 35); |
522 bool root_pass_clipped = root_delegated_render_pass_is_clipped_; | 522 bool root_pass_clipped = root_delegated_render_pass_is_clipped_; |
523 | 523 |
524 TestRenderPass* pass = AddRenderPass( | 524 TestRenderPass* pass = AddRenderPass( |
525 &delegated_render_passes, | 525 &delegated_render_passes, |
526 RenderPass::Id(9, 6), | 526 RenderPass::Id(9, 6), |
527 root_pass_rect, | 527 root_pass_rect, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 const SharedQuadState* root_delegated_shared_quad_state = NULL; | 641 const SharedQuadState* root_delegated_shared_quad_state = NULL; |
642 const SharedQuadState* contrib_delegated_shared_quad_state = NULL; | 642 const SharedQuadState* contrib_delegated_shared_quad_state = NULL; |
643 VerifyRenderPasses( | 643 VerifyRenderPasses( |
644 frame, | 644 frame, |
645 2, | 645 2, |
646 &root_delegated_shared_quad_state, | 646 &root_delegated_shared_quad_state, |
647 &contrib_delegated_shared_quad_state); | 647 &contrib_delegated_shared_quad_state); |
648 | 648 |
649 // When the quads don't have a clip of their own, the clip rect is set to | 649 // When the quads don't have a clip of their own, the clip rect is set to |
650 // the drawable_content_rect of the delegated renderer layer. | 650 // the drawable_content_rect of the delegated renderer layer. |
651 EXPECT_EQ(gfx::Rect(42, 42, 120, 120).ToString(), | 651 EXPECT_EQ(delegated_renderer_layer_->drawable_content_rect().ToString(), |
652 root_delegated_shared_quad_state->clip_rect.ToString()); | 652 root_delegated_shared_quad_state->clip_rect.ToString()); |
653 | 653 |
654 // Even though the quads in the root pass have no clip of their own, they | 654 // Even though the quads in the root pass have no clip of their own, they |
655 // inherit the clip rect from the delegated renderer layer if it does not | 655 // inherit the clip rect from the delegated renderer layer if it does not |
656 // own a surface. | 656 // own a surface. |
657 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped); | 657 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped); |
658 | 658 |
659 gfx::Transform expected; | 659 gfx::Transform expected; |
660 // Device scale factor is 2. | 660 // Device scale factor is 2. |
661 expected.Scale(2.0, 2.0); | 661 expected.Scale(2.0, 2.0); |
662 // This is the transform from the layer's space to its target. | 662 // This is the transform from the layer's space to its target. |
663 // The position (20) - the width / scale (30 / 2) = 20 - 15 = 5 | 663 // The position (20) - the width / scale (75 / 2) = 20 - 37.5 = -17.5 |
664 expected.Translate(5.0, 5.0); | 664 expected.Translate(-17.5, -17.5); |
665 expected.Scale(2.0, 2.0); | 665 expected.Scale(2.0, 2.0); |
666 expected.Translate(8.0, 8.0); | 666 expected.Translate(8.0, 8.0); |
667 // The frame has size 50x50 but the layer's bounds are 30x30. | 667 // The frame has size 100x100 but the layer's bounds are 75x75. |
668 expected.Scale(30.0 / 50.0, 30.0 / 50.0); | 668 expected.Scale(75.0 / 100.0, 75.0 / 100.0); |
669 // This is the transform within the source frame. | 669 // This is the transform within the source frame. |
670 expected.Scale(1.5, 1.5); | 670 expected.Scale(1.5, 1.5); |
671 expected.Translate(7.0, 7.0); | 671 expected.Translate(7.0, 7.0); |
672 EXPECT_TRANSFORMATION_MATRIX_EQ( | 672 EXPECT_TRANSFORMATION_MATRIX_EQ( |
673 expected, root_delegated_shared_quad_state->content_to_target_transform); | 673 expected, root_delegated_shared_quad_state->content_to_target_transform); |
674 | 674 |
675 // The contributing render pass should not be transformed from its input. | 675 // The contributing render pass should not be transformed from its input. |
676 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(), | 676 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(), |
677 contrib_delegated_shared_quad_state->clip_rect.ToString()); | 677 contrib_delegated_shared_quad_state->clip_rect.ToString()); |
678 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped); | 678 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped); |
(...skipping 19 matching lines...) Expand all Loading... |
698 const SharedQuadState* contrib_delegated_shared_quad_state = NULL; | 698 const SharedQuadState* contrib_delegated_shared_quad_state = NULL; |
699 VerifyRenderPasses( | 699 VerifyRenderPasses( |
700 frame, | 700 frame, |
701 2, | 701 2, |
702 &root_delegated_shared_quad_state, | 702 &root_delegated_shared_quad_state, |
703 &contrib_delegated_shared_quad_state); | 703 &contrib_delegated_shared_quad_state); |
704 | 704 |
705 // Since the quads have a clip_rect it should be modified by delegated | 705 // Since the quads have a clip_rect it should be modified by delegated |
706 // renderer layer's draw_transform. | 706 // renderer layer's draw_transform. |
707 // The position of the resulting clip_rect is: | 707 // The position of the resulting clip_rect is: |
708 // (clip rect position (10) * scale to layer (30/50) + translate (8)) * | 708 // (clip rect position (10) * scale to layer (75/100) + translate (8)) * |
709 // layer scale (2) + layer position (20) = 48 | 709 // layer scale (2) + layer position (20) = 51 |
710 // But the layer is centered, so: 48 - (width / 2) = 48 - 30 / 2 = 33 | 710 // But the layer is centered, so: 51 - (75 / 2) = 51 - 75 / 2 = 13.5 |
711 // The device scale is 2, so everything gets doubled, giving 66. | 711 // The device scale is 2, so everything gets doubled, giving 27. |
712 // | 712 // |
713 // The size is 35x35 scaled to fit inside the layer's bounds at 30x30 from | 713 // The size is 35x35 scaled to fit inside the layer's bounds at 75x75 from |
714 // a frame at 50x50: 35 * 2 (device scale) * 30 / 50 = 42. The device scale | 714 // a frame at 100x100: 35 * 2 (device scale) * 75 / 100 = 52.5. The device |
715 // doubles this to 84. | 715 // scale doubles this to 105. |
716 EXPECT_EQ(gfx::Rect(66, 66, 84, 84).ToString(), | 716 EXPECT_EQ(gfx::Rect(27, 27, 105, 105).ToString(), |
717 root_delegated_shared_quad_state->clip_rect.ToString()); | 717 root_delegated_shared_quad_state->clip_rect.ToString()); |
718 | 718 |
719 // The quads had a clip and it should be preserved. | 719 // The quads had a clip and it should be preserved. |
720 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped); | 720 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped); |
721 | 721 |
722 gfx::Transform expected; | 722 gfx::Transform expected; |
723 // Device scale factor is 2. | 723 // Device scale factor is 2. |
724 expected.Scale(2.0, 2.0); | 724 expected.Scale(2.0, 2.0); |
725 // This is the transform from the layer's space to its target. | 725 // This is the transform from the layer's space to its target. |
726 // The position (20) - the width / scale (30 / 2) = 20 - 15 = 5 | 726 // The position (20) - the width / scale (75 / 2) = 20 - 37.5 = -17.5 |
727 expected.Translate(5.0, 5.0); | 727 expected.Translate(-17.5, -17.5); |
728 expected.Scale(2.0, 2.0); | 728 expected.Scale(2.0, 2.0); |
729 expected.Translate(8.0, 8.0); | 729 expected.Translate(8.0, 8.0); |
730 // The frame has size 50x50 but the layer's bounds are 30x30. | 730 // The frame has size 100x100 but the layer's bounds are 75x75. |
731 expected.Scale(30.0 / 50.0, 30.0 / 50.0); | 731 expected.Scale(75.0 / 100.0, 75.0 / 100.0); |
732 // This is the transform within the source frame. | 732 // This is the transform within the source frame. |
733 expected.Scale(1.5, 1.5); | 733 expected.Scale(1.5, 1.5); |
734 expected.Translate(7.0, 7.0); | 734 expected.Translate(7.0, 7.0); |
735 EXPECT_TRANSFORMATION_MATRIX_EQ( | 735 EXPECT_TRANSFORMATION_MATRIX_EQ( |
736 expected, root_delegated_shared_quad_state->content_to_target_transform); | 736 expected, root_delegated_shared_quad_state->content_to_target_transform); |
737 | 737 |
738 // The contributing render pass should not be transformed from its input. | 738 // The contributing render pass should not be transformed from its input. |
739 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(), | 739 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(), |
740 contrib_delegated_shared_quad_state->clip_rect.ToString()); | 740 contrib_delegated_shared_quad_state->clip_rect.ToString()); |
741 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped); | 741 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped); |
(...skipping 21 matching lines...) Expand all Loading... |
763 const SharedQuadState* contrib_delegated_shared_quad_state = NULL; | 763 const SharedQuadState* contrib_delegated_shared_quad_state = NULL; |
764 VerifyRenderPasses( | 764 VerifyRenderPasses( |
765 frame, | 765 frame, |
766 3, | 766 3, |
767 &root_delegated_shared_quad_state, | 767 &root_delegated_shared_quad_state, |
768 &contrib_delegated_shared_quad_state); | 768 &contrib_delegated_shared_quad_state); |
769 | 769 |
770 // When the layer owns a surface, then its position and translation are not | 770 // When the layer owns a surface, then its position and translation are not |
771 // a part of its draw transform. | 771 // a part of its draw transform. |
772 // The position of the resulting clip_rect is: | 772 // The position of the resulting clip_rect is: |
773 // (clip rect position (10) * scale to layer (30/50)) * device scale (2) = 12 | 773 // (clip rect position (10) * scale to layer (75/100)) * device scale (2) = 15 |
774 // The size is 35x35 scaled to fit inside the layer's bounds at 30x30 from | 774 // The size is 35x35 scaled to fit inside the layer's bounds at 75x75 from |
775 // a frame at 50x50: 35 * 2 (device scale) * 30 / 50 = 42. | 775 // a frame at 100x100: 35 * 2 (device scale) * 75 / 100 = 52.5. |
776 EXPECT_EQ(gfx::Rect(12, 12, 42, 42).ToString(), | 776 EXPECT_EQ(gfx::Rect(15, 15, 53, 53).ToString(), |
777 root_delegated_shared_quad_state->clip_rect.ToString()); | 777 root_delegated_shared_quad_state->clip_rect.ToString()); |
778 | 778 |
779 // Since the layer owns a surface it doesn't need to clip its quads, so | 779 // Since the layer owns a surface it doesn't need to clip its quads, so |
780 // unclipped quads remain unclipped. | 780 // unclipped quads remain unclipped. |
781 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped); | 781 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped); |
782 | 782 |
783 gfx::Transform expected; | 783 gfx::Transform expected; |
784 // Device scale factor is 2. | 784 // Device scale factor is 2. |
785 expected.Scale(2.0, 2.0); | 785 expected.Scale(2.0, 2.0); |
786 // The frame has size 50x50 but the layer's bounds are 30x30. | 786 // The frame has size 100x100 but the layer's bounds are 75x75. |
787 expected.Scale(30.0 / 50.0, 30.0 / 50.0); | 787 expected.Scale(75.0 / 100.0, 75.0 / 100.0); |
788 // This is the transform within the source frame. | 788 // This is the transform within the source frame. |
789 expected.Scale(1.5, 1.5); | 789 expected.Scale(1.5, 1.5); |
790 expected.Translate(7.0, 7.0); | 790 expected.Translate(7.0, 7.0); |
791 EXPECT_TRANSFORMATION_MATRIX_EQ( | 791 EXPECT_TRANSFORMATION_MATRIX_EQ( |
792 expected, root_delegated_shared_quad_state->content_to_target_transform); | 792 expected, root_delegated_shared_quad_state->content_to_target_transform); |
793 | 793 |
794 // The contributing render pass should not be transformed from its input. | 794 // The contributing render pass should not be transformed from its input. |
795 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(), | 795 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(), |
796 contrib_delegated_shared_quad_state->clip_rect.ToString()); | 796 contrib_delegated_shared_quad_state->clip_rect.ToString()); |
797 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped); | 797 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped); |
(...skipping 21 matching lines...) Expand all Loading... |
819 const SharedQuadState* contrib_delegated_shared_quad_state = NULL; | 819 const SharedQuadState* contrib_delegated_shared_quad_state = NULL; |
820 VerifyRenderPasses( | 820 VerifyRenderPasses( |
821 frame, | 821 frame, |
822 3, | 822 3, |
823 &root_delegated_shared_quad_state, | 823 &root_delegated_shared_quad_state, |
824 &contrib_delegated_shared_quad_state); | 824 &contrib_delegated_shared_quad_state); |
825 | 825 |
826 // When the layer owns a surface, then its position and translation are not | 826 // When the layer owns a surface, then its position and translation are not |
827 // a part of its draw transform. | 827 // a part of its draw transform. |
828 // The position of the resulting clip_rect is: | 828 // The position of the resulting clip_rect is: |
829 // (clip rect position (10) * scale to layer (30/50)) * device scale (2) = 12 | 829 // (clip rect position (10) * scale to layer (75/100)) * device scale (2) = 15 |
830 // The size is 35x35 scaled to fit inside the layer's bounds at 30x30 from | 830 // The size is 35x35 scaled to fit inside the layer's bounds at 75x75 from |
831 // a frame at 50x50: 35 * 2 (device scale) * 30 / 50 = 42. | 831 // a frame at 100x100: 35 * 2 (device scale) * 75 / 100 = 52.5. |
832 EXPECT_EQ(gfx::Rect(12, 12, 42, 42).ToString(), | 832 EXPECT_EQ(gfx::Rect(15, 15, 53, 53).ToString(), |
833 root_delegated_shared_quad_state->clip_rect.ToString()); | 833 root_delegated_shared_quad_state->clip_rect.ToString()); |
834 | 834 |
835 // The quads had a clip and it should be preserved. | 835 // The quads had a clip and it should be preserved. |
836 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped); | 836 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped); |
837 | 837 |
838 gfx::Transform expected; | 838 gfx::Transform expected; |
839 // Device scale factor is 2. | 839 // Device scale factor is 2. |
840 expected.Scale(2.0, 2.0); | 840 expected.Scale(2.0, 2.0); |
841 // The frame has size 50x50 but the layer's bounds are 30x30. | 841 // The frame has size 100x100 but the layer's bounds are 75x75. |
842 expected.Scale(30.0 / 50.0, 30.0 / 50.0); | 842 expected.Scale(75.0 / 100.0, 75.0 / 100.0); |
843 // This is the transform within the source frame. | 843 // This is the transform within the source frame. |
844 expected.Scale(1.5, 1.5); | 844 expected.Scale(1.5, 1.5); |
845 expected.Translate(7.0, 7.0); | 845 expected.Translate(7.0, 7.0); |
846 EXPECT_TRANSFORMATION_MATRIX_EQ( | 846 EXPECT_TRANSFORMATION_MATRIX_EQ( |
847 expected, root_delegated_shared_quad_state->content_to_target_transform); | 847 expected, root_delegated_shared_quad_state->content_to_target_transform); |
848 | 848 |
849 // The contributing render pass should not be transformed from its input. | 849 // The contributing render pass should not be transformed from its input. |
850 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(), | 850 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(), |
851 contrib_delegated_shared_quad_state->clip_rect.ToString()); | 851 contrib_delegated_shared_quad_state->clip_rect.ToString()); |
852 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped); | 852 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); | 1293 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
1294 EXPECT_EQ(DrawQuad::SOLID_COLOR, | 1294 EXPECT_EQ(DrawQuad::SOLID_COLOR, |
1295 frame.render_passes[0]->quad_list[0]->material); | 1295 frame.render_passes[0]->quad_list[0]->material); |
1296 | 1296 |
1297 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); | 1297 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); |
1298 host_impl_->DidDrawAllLayers(frame); | 1298 host_impl_->DidDrawAllLayers(frame); |
1299 } | 1299 } |
1300 | 1300 |
1301 } // namespace | 1301 } // namespace |
1302 } // namespace cc | 1302 } // namespace cc |
OLD | NEW |