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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "cc/layers/append_quads_data.h" | 6 #include "cc/layers/append_quads_data.h" |
7 #include "cc/output/gl_renderer.h" | 7 #include "cc/output/gl_renderer.h" |
8 #include "cc/quads/draw_quad.h" | 8 #include "cc/quads/draw_quad.h" |
9 #include "cc/quads/picture_draw_quad.h" | |
10 #include "cc/resources/platform_color.h" | |
9 #include "cc/resources/sync_point_helper.h" | 11 #include "cc/resources/sync_point_helper.h" |
12 #include "cc/test/fake_picture_pile_impl.h" | |
10 #include "cc/test/pixel_test.h" | 13 #include "cc/test/pixel_test.h" |
11 #include "gpu/GLES2/gl2extchromium.h" | 14 #include "gpu/GLES2/gl2extchromium.h" |
12 #include "third_party/skia/include/core/SkImageFilter.h" | 15 #include "third_party/skia/include/core/SkImageFilter.h" |
13 #include "third_party/skia/include/core/SkMatrix.h" | 16 #include "third_party/skia/include/core/SkMatrix.h" |
14 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" | 17 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" |
15 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 18 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |
19 #include "ui/gfx/rect_conversions.h" | |
16 | 20 |
17 namespace cc { | 21 namespace cc { |
18 namespace { | 22 namespace { |
19 | 23 |
20 scoped_ptr<RenderPass> CreateTestRootRenderPass(RenderPass::Id id, | 24 scoped_ptr<RenderPass> CreateTestRootRenderPass(RenderPass::Id id, |
21 gfx::Rect rect) { | 25 gfx::Rect rect) { |
22 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 26 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
23 const gfx::Rect output_rect = rect; | 27 const gfx::Rect output_rect = rect; |
24 const gfx::RectF damage_rect = rect; | 28 const gfx::RectF damage_rect = rect; |
25 const gfx::Transform transform_to_root_target; | 29 const gfx::Transform transform_to_root_target; |
(...skipping 22 matching lines...) Expand all Loading... | |
48 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); | 52 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); |
49 shared_state->SetAll(content_to_target_transform, | 53 shared_state->SetAll(content_to_target_transform, |
50 content_bounds, | 54 content_bounds, |
51 visible_content_rect, | 55 visible_content_rect, |
52 clip_rect, | 56 clip_rect, |
53 is_clipped, | 57 is_clipped, |
54 opacity); | 58 opacity); |
55 return shared_state.Pass(); | 59 return shared_state.Pass(); |
56 } | 60 } |
57 | 61 |
62 scoped_ptr<SharedQuadState> CreateTestSharedQuadStateClipped( | |
63 gfx::Transform content_to_target_transform, | |
64 gfx::Rect rect, | |
65 gfx::Rect clip_rect) { | |
66 const gfx::Size content_bounds = rect.size(); | |
67 const gfx::Rect visible_content_rect = clip_rect; | |
68 const bool is_clipped = true; | |
69 const float opacity = 1.0f; | |
70 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); | |
71 shared_state->SetAll(content_to_target_transform, | |
72 content_bounds, | |
73 visible_content_rect, | |
74 clip_rect, | |
75 is_clipped, | |
76 opacity); | |
77 return shared_state.Pass(); | |
78 } | |
79 | |
58 scoped_ptr<DrawQuad> CreateTestRenderPassDrawQuad( | 80 scoped_ptr<DrawQuad> CreateTestRenderPassDrawQuad( |
59 SharedQuadState* shared_state, gfx::Rect rect, RenderPass::Id pass_id) { | 81 SharedQuadState* shared_state, gfx::Rect rect, RenderPass::Id pass_id) { |
60 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create(); | 82 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create(); |
61 quad->SetNew(shared_state, | 83 quad->SetNew(shared_state, |
62 rect, | 84 rect, |
63 pass_id, | 85 pass_id, |
64 false, // is_replica | 86 false, // is_replica |
65 0, // mask_resource_id | 87 0, // mask_resource_id |
66 rect, // contents_changed_since_last_frame | 88 rect, // contents_changed_since_last_frame |
67 gfx::RectF(), // mask_uv_rect | 89 gfx::RectF(), // mask_uv_rect |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 base::MessageLoop::current()->PostTask( | 667 base::MessageLoop::current()->PostTask( |
646 FROM_HERE, | 668 FROM_HERE, |
647 base::Bind(&OtherCallback, &other_callback_count)); | 669 base::Bind(&OtherCallback, &other_callback_count)); |
648 | 670 |
649 base::MessageLoop::current()->Run(); | 671 base::MessageLoop::current()->Run(); |
650 | 672 |
651 // The sync point should have happened. | 673 // The sync point should have happened. |
652 EXPECT_EQ(1, sync_point_callback_count); | 674 EXPECT_EQ(1, sync_point_callback_count); |
653 EXPECT_EQ(1, other_callback_count); | 675 EXPECT_EQ(1, other_callback_count); |
654 } | 676 } |
655 #endif | 677 |
678 TEST_F(GLRendererPixelTest, PictureDrawQuadIdentityScale) { | |
679 gfx::Size pile_tile_size(1000, 1000); | |
680 gfx::Rect viewport(this->device_viewport_size_); | |
681 // TODO(enne): the renderer should figure this out on its own. | |
682 bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA); | |
683 | |
684 RenderPass::Id id(1, 1); | |
685 gfx::Transform transform_to_root; | |
686 scoped_ptr<RenderPass> pass = | |
687 CreateTestRenderPass(id, viewport, transform_to_root); | |
688 | |
689 // One clipped blue quad in the lower right corner. Outside the clip | |
690 // is red, which should not appear. | |
691 gfx::Rect blue_rect(gfx::Size(100, 100)); | |
692 gfx::Rect blue_clip_rect(gfx::Point(50, 50), gfx::Size(50, 50)); | |
693 scoped_refptr<FakePicturePileImpl> blue_pile = | |
694 FakePicturePileImpl::CreateFilledPile(pile_tile_size, blue_rect.size()); | |
695 SkPaint red_paint; | |
696 red_paint.setColor(SK_ColorRED); | |
697 blue_pile->add_draw_rect_with_paint(blue_rect, red_paint); | |
698 SkPaint blue_paint; | |
699 blue_paint.setColor(SK_ColorBLUE); | |
700 blue_pile->add_draw_rect_with_paint(blue_clip_rect, blue_paint); | |
701 blue_pile->RerecordPile(); | |
702 | |
703 gfx::Transform blue_content_to_target_transform; | |
704 gfx::Vector2d offset(viewport.bottom_right() - blue_rect.bottom_right()); | |
705 blue_content_to_target_transform.Translate(offset.x(), offset.y()); | |
706 gfx::RectF blue_scissor_rect = blue_clip_rect; | |
707 blue_content_to_target_transform.TransformRect(&blue_scissor_rect); | |
708 scoped_ptr<SharedQuadState> blue_shared_state = | |
709 CreateTestSharedQuadStateClipped(blue_content_to_target_transform, | |
710 blue_rect, | |
711 gfx::ToEnclosingRect(blue_scissor_rect)); | |
712 | |
713 scoped_ptr<PictureDrawQuad> blue_quad = PictureDrawQuad::Create(); | |
714 | |
715 blue_quad->SetNew(blue_shared_state.get(), | |
716 viewport, // intentionally bigger than clip | |
danakj
2013/04/29 14:27:02
Intentionally bigger than clip.
| |
717 gfx::Rect(), | |
718 viewport, | |
719 viewport.size(), | |
720 contents_swizzled, | |
721 viewport, | |
722 1.f, | |
723 blue_pile); | |
724 pass->quad_list.push_back(blue_quad.PassAs<DrawQuad>()); | |
725 | |
726 // One viewport-filling green quad. | |
727 scoped_refptr<FakePicturePileImpl> green_pile = | |
728 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size()); | |
729 SkPaint green_paint; | |
730 green_paint.setColor(SK_ColorGREEN); | |
731 green_pile->add_draw_rect_with_paint(viewport, green_paint); | |
732 green_pile->RerecordPile(); | |
733 | |
734 gfx::Transform green_content_to_target_transform; | |
735 scoped_ptr<SharedQuadState> green_shared_state = | |
736 CreateTestSharedQuadState(green_content_to_target_transform, viewport); | |
737 | |
738 scoped_ptr<PictureDrawQuad> green_quad = PictureDrawQuad::Create(); | |
739 green_quad->SetNew(green_shared_state.get(), | |
740 viewport, | |
741 gfx::Rect(), | |
742 gfx::RectF(0.f, 0.f, 1.f, 1.f), | |
743 viewport.size(), | |
744 contents_swizzled, | |
745 viewport, | |
746 1.f, | |
747 green_pile); | |
748 pass->quad_list.push_back(green_quad.PassAs<DrawQuad>()); | |
749 | |
750 RenderPassList pass_list; | |
751 pass_list.push_back(pass.Pass()); | |
752 | |
753 EXPECT_TRUE(this->RunPixelTest( | |
754 &pass_list, | |
755 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")), | |
756 ExactPixelComparator(true))); | |
757 } | |
758 | |
759 TEST_F(GLRendererPixelTest, PictureDrawQuadNonIdentityScale) { | |
760 gfx::Size pile_tile_size(1000, 1000); | |
761 gfx::Rect viewport(gfx::Size(200, 200)); | |
762 // TODO(enne): the renderer should figure this out on its own. | |
763 bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA); | |
764 | |
765 RenderPass::Id id(1, 1); | |
766 gfx::Transform transform_to_root; | |
767 scoped_ptr<RenderPass> pass = | |
768 CreateTestRenderPass(id, viewport, transform_to_root); | |
769 | |
770 // As scaling up the blue checkerboards will cause sampling on the GPU, | |
771 // a few extra "cleanup rects" need to be added to clobber the blending | |
772 // to make the output image more clean. This will also test subrects | |
773 // of the layer. | |
774 gfx::Transform green_content_to_target_transform; | |
775 gfx::Rect green_rect1(gfx::Point(80, 0), gfx::Size(20, 100)); | |
776 gfx::Rect green_rect2(gfx::Point(0, 80), gfx::Size(100, 20)); | |
777 scoped_refptr<FakePicturePileImpl> green_pile = | |
778 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size()); | |
779 SkPaint red_paint; | |
780 red_paint.setColor(SK_ColorRED); | |
781 green_pile->add_draw_rect_with_paint(viewport, red_paint); | |
782 SkPaint green_paint; | |
783 green_paint.setColor(SK_ColorGREEN); | |
784 green_pile->add_draw_rect_with_paint(green_rect1, green_paint); | |
785 green_pile->add_draw_rect_with_paint(green_rect2, green_paint); | |
786 green_pile->RerecordPile(); | |
787 | |
788 scoped_ptr<SharedQuadState> top_right_green_shared_quad_state = | |
789 CreateTestSharedQuadState(green_content_to_target_transform, viewport); | |
790 | |
791 scoped_ptr<PictureDrawQuad> green_quad1 = PictureDrawQuad::Create(); | |
792 green_quad1->SetNew(top_right_green_shared_quad_state.get(), | |
793 green_rect1, | |
794 gfx::Rect(), | |
795 green_rect1, | |
796 green_rect1.size(), | |
797 contents_swizzled, | |
798 green_rect1, | |
799 1.f, | |
800 green_pile); | |
801 pass->quad_list.push_back(green_quad1.PassAs<DrawQuad>()); | |
802 | |
803 scoped_ptr<PictureDrawQuad> green_quad2 = PictureDrawQuad::Create(); | |
804 green_quad2->SetNew(top_right_green_shared_quad_state.get(), | |
805 green_rect2, | |
806 gfx::Rect(), | |
807 green_rect2, | |
808 green_rect2.size(), | |
809 contents_swizzled, | |
810 green_rect2, | |
811 1.f, | |
812 green_pile); | |
813 pass->quad_list.push_back(green_quad2.PassAs<DrawQuad>()); | |
814 | |
815 // Add a green clipped checkerboard in the bottom right to help test | |
816 // interleaving picture quad content and solid color content. | |
817 gfx::Rect bottom_right_rect( | |
818 gfx::Point(viewport.width() / 2, viewport.height() / 2), | |
819 gfx::Size(viewport.width() / 2, viewport.height() / 2)); | |
820 scoped_ptr<SharedQuadState> bottom_right_green_shared_state = | |
821 CreateTestSharedQuadStateClipped( | |
822 green_content_to_target_transform, viewport, bottom_right_rect); | |
823 scoped_ptr<SolidColorDrawQuad> bottom_right_color_quad = | |
824 SolidColorDrawQuad::Create(); | |
825 bottom_right_color_quad->SetNew( | |
826 bottom_right_green_shared_state.get(), viewport, SK_ColorGREEN); | |
827 pass->quad_list.push_back(bottom_right_color_quad.PassAs<DrawQuad>()); | |
828 | |
829 // Add two blue checkerboards taking up the bottom left and top right, | |
830 // but use content scales as content rects to make this happen. | |
831 // The content is at a 4x content scale. | |
832 gfx::Rect layer_rect(gfx::Size(20, 30)); | |
833 float contents_scale = 4.f; | |
834 // Two rects that touch at their corners, arbitrarily placed in the layer. | |
835 gfx::RectF blue_layer_rect1(gfx::PointF(5.5f, 9.0f), gfx::SizeF(2.5f, 2.5f)); | |
836 gfx::RectF blue_layer_rect2(gfx::PointF(8.0f, 6.5f), gfx::SizeF(2.5f, 2.5f)); | |
837 gfx::RectF union_layer_rect = blue_layer_rect1; | |
838 union_layer_rect.Union(blue_layer_rect2); | |
839 | |
840 // Because scaling up will cause sampling outside the rects, add one extra | |
841 // pixel of buffer at the final content scale. | |
842 float inset = -1.f / contents_scale; | |
843 blue_layer_rect1.Inset(inset, inset, inset, inset); | |
844 blue_layer_rect2.Inset(inset, inset, inset, inset); | |
845 | |
846 scoped_refptr<FakePicturePileImpl> pile = | |
847 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_rect.size()); | |
848 pile->add_draw_rect_with_paint(layer_rect, red_paint); | |
849 SkPaint transparent_paint; | |
850 transparent_paint.setXfermodeMode(SkXfermode::kClear_Mode); | |
851 pile->add_draw_rect_with_paint(union_layer_rect, transparent_paint); | |
852 SkPaint blue_paint; | |
853 blue_paint.setColor(SK_ColorBLUE); | |
854 pile->add_draw_rect_with_paint(blue_layer_rect1, blue_paint); | |
855 pile->add_draw_rect_with_paint(blue_layer_rect2, blue_paint); | |
856 pile->RerecordPile(); | |
857 | |
858 gfx::Rect content_rect( | |
859 gfx::ToEnclosingRect(gfx::ScaleRect(layer_rect, contents_scale))); | |
860 gfx::Rect content_union_rect( | |
861 gfx::ToEnclosingRect(gfx::ScaleRect(union_layer_rect, contents_scale))); | |
862 | |
863 // At a scale of 4x the rectangles with a width of 2.5 will take up 10 pixels, | |
864 // so scale an additional 10x to make them 100x100. | |
865 gfx::Transform content_to_target_transform; | |
866 content_to_target_transform.Scale(10.0, 10.0); | |
867 gfx::Rect quad_content_rect(gfx::Size(20, 20)); | |
868 scoped_ptr<SharedQuadState> blue_shared_state = | |
869 CreateTestSharedQuadState(content_to_target_transform, quad_content_rect); | |
870 | |
871 scoped_ptr<PictureDrawQuad> blue_quad = PictureDrawQuad::Create(); | |
872 blue_quad->SetNew(blue_shared_state.get(), | |
873 quad_content_rect, | |
874 gfx::Rect(), | |
875 quad_content_rect, | |
876 content_union_rect.size(), | |
877 contents_swizzled, | |
878 content_union_rect, | |
879 contents_scale, | |
880 pile); | |
881 pass->quad_list.push_back(blue_quad.PassAs<DrawQuad>()); | |
882 | |
883 // Fill left half of viewport with green. | |
884 gfx::Transform half_green_content_to_target_transform; | |
885 gfx::Rect half_green_rect(gfx::Size(viewport.width() / 2, viewport.height())); | |
886 scoped_ptr<SharedQuadState> half_green_shared_state = | |
887 CreateTestSharedQuadState(half_green_content_to_target_transform, | |
888 half_green_rect); | |
889 scoped_ptr<SolidColorDrawQuad> half_color_quad = SolidColorDrawQuad::Create(); | |
890 half_color_quad->SetNew( | |
891 half_green_shared_state.get(), half_green_rect, SK_ColorGREEN); | |
892 pass->quad_list.push_back(half_color_quad.PassAs<DrawQuad>()); | |
893 | |
894 RenderPassList pass_list; | |
895 pass_list.push_back(pass.Pass()); | |
896 | |
897 EXPECT_TRUE(this->RunPixelTest( | |
898 &pass_list, | |
899 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), | |
900 ExactPixelComparator(true))); | |
901 } | |
902 | |
903 #endif // !defined(OS_ANDROID) | |
656 | 904 |
657 } // namespace | 905 } // namespace |
658 } // namespace cc | 906 } // namespace cc |
OLD | NEW |