OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 #include "cc/layers/content_layer.h" | 6 #include "cc/layers/content_layer.h" |
7 #include "cc/layers/solid_color_layer.h" | 7 #include "cc/layers/solid_color_layer.h" |
8 #include "cc/layers/texture_layer.h" | 8 #include "cc/layers/texture_layer.h" |
9 #include "cc/output/copy_output_request.h" | 9 #include "cc/output/copy_output_request.h" |
10 #include "cc/output/copy_output_result.h" | 10 #include "cc/output/copy_output_result.h" |
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 device_scale_factor_ = 2.f; | 1072 device_scale_factor_ = 2.f; |
1073 | 1073 |
1074 this->impl_side_painting_ = false; | 1074 this->impl_side_painting_ = false; |
1075 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, | 1075 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
1076 background, | 1076 background, |
1077 green.get(), | 1077 green.get(), |
1078 base::FilePath(FILE_PATH_LITERAL( | 1078 base::FilePath(FILE_PATH_LITERAL( |
1079 "green_small_with_blue_corner.png"))); | 1079 "green_small_with_blue_corner.png"))); |
1080 } | 1080 } |
1081 | 1081 |
1082 class LayerTreeHostReadbackViaCompositeAndReadbackPixelTest | |
1083 : public LayerTreePixelTest { | |
1084 protected: | |
1085 LayerTreeHostReadbackViaCompositeAndReadbackPixelTest() | |
1086 : device_scale_factor_(1.f), | |
1087 white_client_(SK_ColorWHITE), | |
1088 green_client_(SK_ColorGREEN), | |
1089 blue_client_(SK_ColorBLUE) {} | |
1090 | |
1091 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | |
1092 // Cause the device scale factor to be inherited by contents scales. | |
1093 settings->layer_transforms_should_scale_layer_contents = true; | |
1094 } | |
1095 | |
1096 virtual void SetupTree() OVERRIDE { | |
1097 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); | |
1098 LayerTreePixelTest::SetupTree(); | |
1099 } | |
1100 | |
1101 virtual void BeginTest() OVERRIDE { | |
1102 EXPECT_EQ(device_scale_factor_, layer_tree_host()->device_scale_factor()); | |
1103 if (TestEnded()) | |
1104 return; | |
1105 | |
1106 gfx::Rect device_viewport_copy_rect( | |
1107 layer_tree_host()->device_viewport_size()); | |
1108 if (!device_viewport_copy_subrect_.IsEmpty()) | |
1109 device_viewport_copy_rect.Intersect(device_viewport_copy_subrect_); | |
1110 | |
1111 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | |
1112 bitmap->allocN32Pixels(device_viewport_copy_rect.width(), | |
1113 device_viewport_copy_rect.height()); | |
1114 layer_tree_host()->CompositeAndReadback(bitmap->getPixels(), | |
1115 device_viewport_copy_rect); | |
1116 | |
1117 result_bitmap_ = bitmap.Pass(); | |
1118 EndTest(); | |
1119 } | |
1120 | |
1121 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | |
1122 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | |
1123 | |
1124 LayerImpl* background_impl = root_impl->children()[0]; | |
1125 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x()); | |
1126 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y()); | |
1127 | |
1128 LayerImpl* green_impl = background_impl->children()[0]; | |
1129 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x()); | |
1130 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y()); | |
1131 | |
1132 LayerImpl* blue_impl = green_impl->children()[0]; | |
1133 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x()); | |
1134 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y()); | |
1135 } | |
1136 | |
1137 gfx::Rect device_viewport_copy_subrect_; | |
1138 float device_scale_factor_; | |
1139 SolidColorContentLayerClient white_client_; | |
1140 SolidColorContentLayerClient green_client_; | |
1141 SolidColorContentLayerClient blue_client_; | |
1142 }; | |
1143 | |
1144 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, | |
1145 CompositeAndReadback_Software_1) { | |
1146 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); | |
1147 background->SetAnchorPoint(gfx::PointF()); | |
1148 background->SetBounds(gfx::Size(200, 200)); | |
1149 background->SetIsDrawable(true); | |
1150 | |
1151 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); | |
1152 green->SetAnchorPoint(gfx::PointF()); | |
1153 green->SetBounds(gfx::Size(200, 200)); | |
1154 green->SetIsDrawable(true); | |
1155 background->AddChild(green); | |
1156 | |
1157 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); | |
1158 blue->SetAnchorPoint(gfx::PointF()); | |
1159 blue->SetPosition(gfx::Point(100, 100)); | |
1160 blue->SetBounds(gfx::Size(50, 50)); | |
1161 blue->SetIsDrawable(true); | |
1162 green->AddChild(blue); | |
1163 | |
1164 // Grab the middle of the device viewport. | |
1165 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); | |
1166 device_scale_factor_ = 1.f; | |
1167 | |
1168 this->impl_side_painting_ = false; | |
1169 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, | |
1170 background, | |
1171 green.get(), | |
1172 base::FilePath(FILE_PATH_LITERAL( | |
1173 "green_small_with_blue_corner.png"))); | |
1174 } | |
1175 | |
1176 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, | |
1177 CompositeAndReadback_Software_2) { | |
1178 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); | |
1179 background->SetAnchorPoint(gfx::PointF()); | |
1180 background->SetBounds(gfx::Size(100, 100)); | |
1181 background->SetIsDrawable(true); | |
1182 | |
1183 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); | |
1184 green->SetAnchorPoint(gfx::PointF()); | |
1185 green->SetBounds(gfx::Size(100, 100)); | |
1186 green->SetIsDrawable(true); | |
1187 background->AddChild(green); | |
1188 | |
1189 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); | |
1190 blue->SetAnchorPoint(gfx::PointF()); | |
1191 blue->SetPosition(gfx::Point(50, 50)); | |
1192 blue->SetBounds(gfx::Size(25, 25)); | |
1193 blue->SetIsDrawable(true); | |
1194 green->AddChild(blue); | |
1195 | |
1196 // Grab the middle of the device viewport. | |
1197 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); | |
1198 device_scale_factor_ = 2.f; | |
1199 | |
1200 this->impl_side_painting_ = false; | |
1201 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, | |
1202 background, | |
1203 green.get(), | |
1204 base::FilePath(FILE_PATH_LITERAL( | |
1205 "green_small_with_blue_corner.png"))); | |
1206 } | |
1207 | |
1208 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, | |
1209 CompositeAndReadback_GL_1) { | |
1210 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); | |
1211 background->SetAnchorPoint(gfx::PointF()); | |
1212 background->SetBounds(gfx::Size(200, 200)); | |
1213 background->SetIsDrawable(true); | |
1214 | |
1215 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); | |
1216 green->SetAnchorPoint(gfx::PointF()); | |
1217 green->SetBounds(gfx::Size(200, 200)); | |
1218 green->SetIsDrawable(true); | |
1219 background->AddChild(green); | |
1220 | |
1221 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); | |
1222 blue->SetAnchorPoint(gfx::PointF()); | |
1223 blue->SetPosition(gfx::Point(100, 100)); | |
1224 blue->SetBounds(gfx::Size(50, 50)); | |
1225 blue->SetIsDrawable(true); | |
1226 green->AddChild(blue); | |
1227 | |
1228 // Grab the middle of the device viewport. | |
1229 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); | |
1230 device_scale_factor_ = 1.f; | |
1231 | |
1232 this->impl_side_painting_ = false; | |
1233 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, | |
1234 background, | |
1235 green.get(), | |
1236 base::FilePath(FILE_PATH_LITERAL( | |
1237 "green_small_with_blue_corner.png"))); | |
1238 } | |
1239 | |
1240 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, | |
1241 CompositeAndReadback_GL_2) { | |
1242 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); | |
1243 background->SetAnchorPoint(gfx::PointF()); | |
1244 background->SetBounds(gfx::Size(100, 100)); | |
1245 background->SetIsDrawable(true); | |
1246 | |
1247 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); | |
1248 green->SetAnchorPoint(gfx::PointF()); | |
1249 green->SetBounds(gfx::Size(100, 100)); | |
1250 green->SetIsDrawable(true); | |
1251 background->AddChild(green); | |
1252 | |
1253 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); | |
1254 blue->SetAnchorPoint(gfx::PointF()); | |
1255 blue->SetPosition(gfx::Point(50, 50)); | |
1256 blue->SetBounds(gfx::Size(25, 25)); | |
1257 blue->SetIsDrawable(true); | |
1258 green->AddChild(blue); | |
1259 | |
1260 // Grab the middle of the device viewport. | |
1261 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); | |
1262 device_scale_factor_ = 2.f; | |
1263 | |
1264 this->impl_side_painting_ = false; | |
1265 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, | |
1266 background, | |
1267 green.get(), | |
1268 base::FilePath(FILE_PATH_LITERAL( | |
1269 "green_small_with_blue_corner.png"))); | |
1270 } | |
1271 | |
1272 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerOutsideViewport) { | 1082 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerOutsideViewport) { |
1273 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 1083 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
1274 gfx::Rect(200, 200), SK_ColorWHITE); | 1084 gfx::Rect(200, 200), SK_ColorWHITE); |
1275 | 1085 |
1276 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 1086 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
1277 gfx::Rect(200, 200), SK_ColorGREEN); | 1087 gfx::Rect(200, 200), SK_ColorGREEN); |
1278 // Only the top left quarter of the layer is inside the viewport, so the | 1088 // Only the top left quarter of the layer is inside the viewport, so the |
1279 // blue layer is entirely outside. | 1089 // blue layer is entirely outside. |
1280 green->SetPosition(gfx::Point(100, 100)); | 1090 green->SetPosition(gfx::Point(100, 100)); |
1281 background->AddChild(green); | 1091 background->AddChild(green); |
1282 | 1092 |
1283 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 1093 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
1284 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); | 1094 gfx::Rect(150, 150, 50, 50), SK_ColorBLUE); |
1285 green->AddChild(blue); | 1095 green->AddChild(blue); |
1286 | 1096 |
1287 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, | 1097 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
1288 background, | 1098 background, |
1289 green.get(), | 1099 green.get(), |
1290 base::FilePath(FILE_PATH_LITERAL( | 1100 base::FilePath(FILE_PATH_LITERAL( |
1291 "green_with_blue_corner.png"))); | 1101 "green_with_blue_corner.png"))); |
1292 } | 1102 } |
1293 | 1103 |
1294 } // namespace | 1104 } // namespace |
1295 } // namespace cc | 1105 } // namespace cc |
1296 | 1106 |
1297 #endif // OS_ANDROID | 1107 #endif // OS_ANDROID |
OLD | NEW |