| 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 <AVFoundation/AVFoundation.h> |
| 5 #include <memory> | 6 #include <memory> |
| 6 | 7 |
| 7 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
| 8 #include "gpu/GLES2/gl2extchromium.h" | 9 #include "gpu/GLES2/gl2extchromium.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 11 #include "ui/accelerated_widget_mac/ca_renderer_layer_tree.h" | 12 #include "ui/accelerated_widget_mac/ca_renderer_layer_tree.h" |
| 12 #include "ui/gfx/geometry/dip_util.h" | 13 #include "ui/gfx/geometry/dip_util.h" |
| 13 #include "ui/gfx/mac/io_surface.h" | 14 #include "ui/gfx/mac/io_surface.h" |
| 14 | 15 |
| 15 namespace gpu { | 16 namespace gpu { |
| 16 | 17 |
| 17 class CALayerTreeTest : public testing::Test { | 18 class CALayerTreeTest : public testing::Test { |
| 18 protected: | 19 protected: |
| 19 void SetUp() override { | 20 void SetUp() override { |
| 20 superlayer_.reset([[CALayer alloc] init]); | 21 superlayer_.reset([[CALayer alloc] init]); |
| 22 fullscreen_low_power_layer_.reset( |
| 23 [[AVSampleBufferDisplayLayer alloc] init]); |
| 21 } | 24 } |
| 22 | 25 |
| 23 base::scoped_nsobject<CALayer> superlayer_; | 26 base::scoped_nsobject<CALayer> superlayer_; |
| 27 base::scoped_nsobject<AVSampleBufferDisplayLayer> fullscreen_low_power_layer_; |
| 24 }; | 28 }; |
| 25 | 29 |
| 26 // Test updating each layer's properties. | 30 // Test updating each layer's properties. |
| 27 TEST_F(CALayerTreeTest, PropertyUpdates) { | 31 TEST_F(CALayerTreeTest, PropertyUpdates) { |
| 28 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(gfx::CreateIOSurface( | 32 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(gfx::CreateIOSurface( |
| 29 gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888)); | 33 gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888)); |
| 30 bool is_clipped = true; | 34 bool is_clipped = true; |
| 31 gfx::Rect clip_rect(2, 4, 8, 16); | 35 gfx::Rect clip_rect(2, 4, 8, 16); |
| 32 int sorting_context_id = 0; | 36 int sorting_context_id = 0; |
| 33 gfx::Transform transform; | 37 gfx::Transform transform; |
| (...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 952 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 949 content_layer3 = [[transform_layer sublayers] objectAtIndex:0]; | 953 content_layer3 = [[transform_layer sublayers] objectAtIndex:0]; |
| 950 | 954 |
| 951 // Validate the content layer. | 955 // Validate the content layer. |
| 952 EXPECT_FALSE([content_layer3 | 956 EXPECT_FALSE([content_layer3 |
| 953 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 957 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 954 EXPECT_NE(content_layer3, content_layer2); | 958 EXPECT_NE(content_layer3, content_layer2); |
| 955 } | 959 } |
| 956 } | 960 } |
| 957 | 961 |
| 962 // Test fullscreen low power detection. |
| 963 TEST_F(CALayerTreeTest, FullscreenLowPower) { |
| 964 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(gfx::CreateIOSurface( |
| 965 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR)); |
| 966 |
| 967 bool is_clipped = false; |
| 968 gfx::Rect clip_rect(0, 0, 1, 1); |
| 969 int sorting_context_id = 0; |
| 970 gfx::Transform transform; |
| 971 transform.Translate(10, 20); |
| 972 transform.Scale(0.5, 2.0); |
| 973 gfx::RectF contents_rect(0.0f, 0.0f, 1.0f, 1.0f); |
| 974 gfx::Rect rect(16, 32, 64, 128); |
| 975 unsigned background_color = SkColorSetARGB(0, 0, 0, 0); |
| 976 unsigned edge_aa_mask = 0; |
| 977 float opacity = 1.0f; |
| 978 float scale_factor = 1.0f; |
| 979 bool result = false; |
| 980 |
| 981 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree; |
| 982 |
| 983 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; |
| 984 CVPixelBufferCreateWithIOSurface(nullptr, io_surface, nullptr, |
| 985 cv_pixel_buffer.InitializeInto()); |
| 986 |
| 987 // Test a configuration with no background. |
| 988 { |
| 989 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
| 990 new ui::CARendererLayerTree); |
| 991 result = new_ca_layer_tree->ScheduleCALayer( |
| 992 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 993 cv_pixel_buffer, contents_rect, rect, background_color, edge_aa_mask, |
| 994 opacity); |
| 995 EXPECT_TRUE(result); |
| 996 new_ca_layer_tree->CommitScheduledCALayers( |
| 997 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 998 bool fullscreen_low_power_valid = |
| 999 new_ca_layer_tree->CommitFullscreenLowPowerLayer( |
| 1000 fullscreen_low_power_layer_); |
| 1001 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 1002 |
| 1003 // Validate the tree structure. |
| 1004 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 1005 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 1006 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 1007 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 1008 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 1009 CALayer* transform_layer = |
| 1010 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 1011 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 1012 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; |
| 1013 |
| 1014 // Validate the content layer and fullscreen low power mode. |
| 1015 EXPECT_TRUE([content_layer |
| 1016 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 1017 EXPECT_TRUE(fullscreen_low_power_valid); |
| 1018 } |
| 1019 |
| 1020 // Test a configuration with a black background. |
| 1021 { |
| 1022 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
| 1023 new ui::CARendererLayerTree); |
| 1024 result = new_ca_layer_tree->ScheduleCALayer( |
| 1025 is_clipped, clip_rect, sorting_context_id, transform, nullptr, nullptr, |
| 1026 contents_rect, rect, SK_ColorBLACK, edge_aa_mask, opacity); |
| 1027 result = new_ca_layer_tree->ScheduleCALayer( |
| 1028 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 1029 cv_pixel_buffer, contents_rect, rect, background_color, edge_aa_mask, |
| 1030 opacity); |
| 1031 EXPECT_TRUE(result); |
| 1032 new_ca_layer_tree->CommitScheduledCALayers( |
| 1033 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 1034 bool fullscreen_low_power_valid = |
| 1035 new_ca_layer_tree->CommitFullscreenLowPowerLayer( |
| 1036 fullscreen_low_power_layer_); |
| 1037 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 1038 |
| 1039 // Validate the tree structure. |
| 1040 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 1041 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 1042 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 1043 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 1044 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 1045 CALayer* transform_layer = |
| 1046 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 1047 EXPECT_EQ(2u, [[transform_layer sublayers] count]); |
| 1048 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:1]; |
| 1049 |
| 1050 // Validate the content layer and fullscreen low power mode. |
| 1051 EXPECT_TRUE([content_layer |
| 1052 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 1053 EXPECT_TRUE(fullscreen_low_power_valid); |
| 1054 } |
| 1055 |
| 1056 // Test a configuration with a white background. It will fail. |
| 1057 { |
| 1058 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
| 1059 new ui::CARendererLayerTree); |
| 1060 result = new_ca_layer_tree->ScheduleCALayer( |
| 1061 is_clipped, clip_rect, sorting_context_id, transform, nullptr, nullptr, |
| 1062 contents_rect, rect, SK_ColorWHITE, edge_aa_mask, opacity); |
| 1063 result = new_ca_layer_tree->ScheduleCALayer( |
| 1064 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 1065 cv_pixel_buffer, contents_rect, rect, background_color, edge_aa_mask, |
| 1066 opacity); |
| 1067 EXPECT_TRUE(result); |
| 1068 new_ca_layer_tree->CommitScheduledCALayers( |
| 1069 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 1070 bool fullscreen_low_power_valid = |
| 1071 new_ca_layer_tree->CommitFullscreenLowPowerLayer( |
| 1072 fullscreen_low_power_layer_); |
| 1073 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 1074 |
| 1075 // Validate the tree structure. |
| 1076 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 1077 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 1078 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 1079 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 1080 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 1081 CALayer* transform_layer = |
| 1082 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 1083 EXPECT_EQ(2u, [[transform_layer sublayers] count]); |
| 1084 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:1]; |
| 1085 |
| 1086 // Validate the content layer and fullscreen low power mode. |
| 1087 EXPECT_TRUE([content_layer |
| 1088 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 1089 EXPECT_FALSE(fullscreen_low_power_valid); |
| 1090 } |
| 1091 |
| 1092 // Test a configuration with a black foreground. It too will fail. |
| 1093 { |
| 1094 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
| 1095 new ui::CARendererLayerTree); |
| 1096 result = new_ca_layer_tree->ScheduleCALayer( |
| 1097 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 1098 cv_pixel_buffer, contents_rect, rect, background_color, edge_aa_mask, |
| 1099 opacity); |
| 1100 result = new_ca_layer_tree->ScheduleCALayer( |
| 1101 is_clipped, clip_rect, sorting_context_id, transform, nullptr, nullptr, |
| 1102 contents_rect, rect, SK_ColorBLACK, edge_aa_mask, opacity); |
| 1103 EXPECT_TRUE(result); |
| 1104 new_ca_layer_tree->CommitScheduledCALayers( |
| 1105 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 1106 bool fullscreen_low_power_valid = |
| 1107 new_ca_layer_tree->CommitFullscreenLowPowerLayer( |
| 1108 fullscreen_low_power_layer_); |
| 1109 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 1110 |
| 1111 // Validate the tree structure. |
| 1112 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 1113 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 1114 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 1115 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 1116 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 1117 CALayer* transform_layer = |
| 1118 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 1119 EXPECT_EQ(2u, [[transform_layer sublayers] count]); |
| 1120 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; |
| 1121 |
| 1122 // Validate the content layer and fullscreen low power mode. |
| 1123 EXPECT_TRUE([content_layer |
| 1124 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 1125 EXPECT_FALSE(fullscreen_low_power_valid); |
| 1126 } |
| 1127 } |
| 1128 |
| 958 } // namespace gpu | 1129 } // namespace gpu |
| OLD | NEW |