| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mac/sdk_forward_declarations.h" | 5 #include "base/mac/sdk_forward_declarations.h" |
| 6 #include "content/common/gpu/ca_layer_tree_mac.h" | 6 #include "content/common/gpu/ca_layer_tree_mac.h" |
| 7 #include "gpu/GLES2/gl2extchromium.h" | 7 #include "gpu/GLES2/gl2extchromium.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "ui/gfx/geometry/dip_util.h" | 10 #include "ui/gfx/geometry/dip_util.h" |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 io_surface, | 730 io_surface, |
| 731 contents_rect, | 731 contents_rect, |
| 732 rect, | 732 rect, |
| 733 background_color, | 733 background_color, |
| 734 edge_aa_mask, | 734 edge_aa_mask, |
| 735 opacity); | 735 opacity); |
| 736 EXPECT_TRUE(result); | 736 EXPECT_TRUE(result); |
| 737 } | 737 } |
| 738 } | 738 } |
| 739 | 739 |
| 740 // Test updating each layer's properties. |
| 741 TEST_F(CALayerTreeTest, AVLayer) { |
| 742 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(gfx::CreateIOSurface( |
| 743 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR)); |
| 744 bool is_clipped = true; |
| 745 gfx::Rect clip_rect(2, 4, 8, 16); |
| 746 int sorting_context_id = 0; |
| 747 gfx::Transform transform; |
| 748 gfx::RectF contents_rect(0.0f, 0.0f, 1.0f, 1.0f); |
| 749 gfx::Rect rect(16, 32, 64, 128); |
| 750 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0, 0); |
| 751 unsigned edge_aa_mask = GL_CA_LAYER_EDGE_LEFT_CHROMIUM; |
| 752 float opacity = 0.5f; |
| 753 float scale_factor = 1.0f; |
| 754 bool result = false; |
| 755 |
| 756 scoped_ptr<CALayerTree> ca_layer_tree; |
| 757 CALayer* root_layer = nil; |
| 758 CALayer* clip_and_sorting_layer = nil; |
| 759 CALayer* transform_layer = nil; |
| 760 CALayer* content_layer1 = nil; |
| 761 CALayer* content_layer2 = nil; |
| 762 CALayer* content_layer3 = nil; |
| 763 |
| 764 // Validate the initial values. |
| 765 { |
| 766 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 767 result = new_ca_layer_tree->ScheduleCALayer( |
| 768 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 769 contents_rect, rect, background_color, edge_aa_mask, opacity); |
| 770 EXPECT_TRUE(result); |
| 771 new_ca_layer_tree->CommitScheduledCALayers( |
| 772 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 773 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 774 |
| 775 // Validate the tree structure. |
| 776 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 777 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 778 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 779 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 780 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 781 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 782 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 783 content_layer1 = [[transform_layer sublayers] objectAtIndex:0]; |
| 784 |
| 785 // Validate the content layer. |
| 786 EXPECT_TRUE([content_layer1 |
| 787 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 788 } |
| 789 |
| 790 io_surface.reset(gfx::CreateIOSurface(gfx::Size(256, 256), |
| 791 gfx::BufferFormat::YUV_420_BIPLANAR)); |
| 792 |
| 793 // Pass another frame. |
| 794 { |
| 795 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 796 result = new_ca_layer_tree->ScheduleCALayer( |
| 797 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 798 contents_rect, rect, background_color, edge_aa_mask, opacity); |
| 799 EXPECT_TRUE(result); |
| 800 new_ca_layer_tree->CommitScheduledCALayers( |
| 801 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 802 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 803 |
| 804 // Validate the tree structure. |
| 805 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 806 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 807 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 808 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 809 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 810 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 811 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 812 content_layer2 = [[transform_layer sublayers] objectAtIndex:0]; |
| 813 |
| 814 // Validate the content layer. |
| 815 EXPECT_TRUE([content_layer2 |
| 816 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 817 EXPECT_EQ(content_layer2, content_layer1); |
| 818 } |
| 819 |
| 820 io_surface.reset(gfx::CreateIOSurface(gfx::Size(256, 256), |
| 821 gfx::BufferFormat::YUV_420_BIPLANAR)); |
| 822 |
| 823 // Pass a frame that is clipped. |
| 824 contents_rect = gfx::RectF(0, 0, 1, 0.9); |
| 825 { |
| 826 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 827 result = new_ca_layer_tree->ScheduleCALayer( |
| 828 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 829 contents_rect, rect, background_color, edge_aa_mask, opacity); |
| 830 EXPECT_TRUE(result); |
| 831 new_ca_layer_tree->CommitScheduledCALayers( |
| 832 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 833 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 834 |
| 835 // Validate the tree structure. |
| 836 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 837 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 838 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 839 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 840 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 841 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 842 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 843 content_layer3 = [[transform_layer sublayers] objectAtIndex:0]; |
| 844 |
| 845 // Validate the content layer. |
| 846 EXPECT_FALSE([content_layer3 |
| 847 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 848 EXPECT_NE(content_layer3, content_layer2); |
| 849 } |
| 850 } |
| 851 |
| 740 } // namespace content | 852 } // namespace content |
| OLD | NEW |