OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 l1_delegate.AddColor(SK_ColorWHITE); | 1184 l1_delegate.AddColor(SK_ColorWHITE); |
1185 l1->set_delegate(&l1_delegate); | 1185 l1->set_delegate(&l1_delegate); |
1186 | 1186 |
1187 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1187 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
1188 GetCompositor()->SetRootLayer(root.get()); | 1188 GetCompositor()->SetRootLayer(root.get()); |
1189 root->Add(l1.get()); | 1189 root->Add(l1.get()); |
1190 WaitForDraw(); | 1190 WaitForDraw(); |
1191 | 1191 |
1192 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1192 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
1193 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1193 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1194 gfx::Size size_in_pixel = root->cc_layer()->bounds(); | 1194 gfx::Size cc_bounds_size = root->cc_layer()->bounds(); |
1195 EXPECT_EQ("200x220", size_in_pixel.ToString()); | 1195 EXPECT_EQ("200x220", cc_bounds_size.ToString()); |
1196 size_in_pixel = l1->cc_layer()->bounds(); | 1196 cc_bounds_size = l1->cc_layer()->bounds(); |
1197 EXPECT_EQ("140x180", size_in_pixel.ToString()); | 1197 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
1198 // No scale change, so no scale notification. | 1198 // No scale change, so no scale notification. |
1199 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); | 1199 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); |
1200 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1200 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
1201 | 1201 |
1202 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); | 1202 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); |
1203 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | 1203 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); |
1204 | 1204 |
1205 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. | 1205 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. |
1206 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | 1206 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); |
1207 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1207 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
1208 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1208 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1209 // Pixel size must have been scaled up. | 1209 // CC layer should still match the UI layer bounds. |
1210 size_in_pixel = root->cc_layer()->bounds(); | 1210 cc_bounds_size = root->cc_layer()->bounds(); |
1211 EXPECT_EQ("400x440", size_in_pixel.ToString()); | 1211 EXPECT_EQ("200x220", cc_bounds_size.ToString()); |
1212 size_in_pixel = l1->cc_layer()->bounds(); | 1212 cc_bounds_size = l1->cc_layer()->bounds(); |
1213 EXPECT_EQ("280x360", size_in_pixel.ToString()); | 1213 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
1214 // New scale factor must have been notified. | 1214 // New scale factor must have been notified. |
1215 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); | 1215 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); |
1216 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); | 1216 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
1217 | 1217 |
1218 // Canvas size must have been scaled down up. | 1218 // Canvas size must have been scaled down up. |
1219 WaitForDraw(); | 1219 WaitForDraw(); |
1220 EXPECT_EQ("400x440", root_delegate.paint_size().ToString()); | 1220 EXPECT_EQ("400x440", root_delegate.paint_size().ToString()); |
1221 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString()); | 1221 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString()); |
1222 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | 1222 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); |
1223 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); | 1223 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); |
1224 | 1224 |
1225 // Scale down back to 1.0f. | 1225 // Scale down back to 1.0f. |
1226 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1226 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
1227 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1227 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
1228 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1228 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1229 // Pixel size must have been scaled down. | 1229 // CC layer should still match the UI layer bounds. |
1230 size_in_pixel = root->cc_layer()->bounds(); | 1230 cc_bounds_size = root->cc_layer()->bounds(); |
1231 EXPECT_EQ("200x220", size_in_pixel.ToString()); | 1231 EXPECT_EQ("200x220", cc_bounds_size.ToString()); |
1232 size_in_pixel = l1->cc_layer()->bounds(); | 1232 cc_bounds_size = l1->cc_layer()->bounds(); |
1233 EXPECT_EQ("140x180", size_in_pixel.ToString()); | 1233 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
1234 // New scale factor must have been notified. | 1234 // New scale factor must have been notified. |
1235 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); | 1235 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); |
1236 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); | 1236 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); |
1237 | 1237 |
1238 // Canvas size must have been scaled down too. | 1238 // Canvas size must have been scaled down too. |
1239 WaitForDraw(); | 1239 WaitForDraw(); |
1240 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); | 1240 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); |
1241 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString()); | 1241 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString()); |
1242 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | 1242 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); |
1243 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); | 1243 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); |
(...skipping 21 matching lines...) Expand all Loading... |
1265 TestLayerDelegate l1_delegate; | 1265 TestLayerDelegate l1_delegate; |
1266 l1_delegate.AddColor(SK_ColorWHITE); | 1266 l1_delegate.AddColor(SK_ColorWHITE); |
1267 l1->set_delegate(&l1_delegate); | 1267 l1->set_delegate(&l1_delegate); |
1268 | 1268 |
1269 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1269 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
1270 GetCompositor()->SetRootLayer(root.get()); | 1270 GetCompositor()->SetRootLayer(root.get()); |
1271 WaitForDraw(); | 1271 WaitForDraw(); |
1272 | 1272 |
1273 root->Add(l1.get()); | 1273 root->Add(l1.get()); |
1274 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1274 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1275 gfx::Size size_in_pixel = l1->cc_layer()->bounds(); | 1275 gfx::Size cc_bounds_size = l1->cc_layer()->bounds(); |
1276 EXPECT_EQ("140x180", size_in_pixel.ToString()); | 1276 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
1277 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1277 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
1278 | 1278 |
1279 WaitForDraw(); | 1279 WaitForDraw(); |
1280 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); | 1280 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); |
1281 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); | 1281 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); |
1282 | 1282 |
1283 // Remove l1 from root and change the scale. | 1283 // Remove l1 from root and change the scale. |
1284 root->Remove(l1.get()); | 1284 root->Remove(l1.get()); |
1285 EXPECT_EQ(NULL, l1->parent()); | 1285 EXPECT_EQ(NULL, l1->parent()); |
1286 EXPECT_EQ(NULL, l1->GetCompositor()); | 1286 EXPECT_EQ(NULL, l1->GetCompositor()); |
1287 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | 1287 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); |
1288 // Sanity check on root and l1. | 1288 // Sanity check on root and l1. |
1289 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); | 1289 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); |
1290 size_in_pixel = l1->cc_layer()->bounds(); | 1290 cc_bounds_size = l1->cc_layer()->bounds(); |
1291 EXPECT_EQ("140x180", size_in_pixel.ToString()); | 1291 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
1292 | |
1293 | 1292 |
1294 root->Add(l1.get()); | 1293 root->Add(l1.get()); |
1295 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1294 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1296 size_in_pixel = l1->cc_layer()->bounds(); | 1295 cc_bounds_size = l1->cc_layer()->bounds(); |
1297 EXPECT_EQ("280x360", size_in_pixel.ToString()); | 1296 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
1298 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); | 1297 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
1299 WaitForDraw(); | 1298 WaitForDraw(); |
1300 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | 1299 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); |
1301 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); | 1300 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); |
1302 } | 1301 } |
1303 | 1302 |
1304 // Tests layer::set_scale_content(false). | |
1305 TEST_F(LayerWithRealCompositorTest, NoScaleCanvas) { | |
1306 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, | |
1307 gfx::Rect(10, 20, 200, 220))); | |
1308 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, | |
1309 gfx::Rect(10, 20, 140, 180))); | |
1310 l1->set_scale_content(false); | |
1311 root->Add(l1.get()); | |
1312 TestLayerDelegate l1_delegate; | |
1313 l1_delegate.AddColor(SK_ColorWHITE); | |
1314 l1->set_delegate(&l1_delegate); | |
1315 | |
1316 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); | |
1317 GetCompositor()->SetRootLayer(root.get()); | |
1318 // Scale factor change is notified regardless of scale_content flag. | |
1319 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); | |
1320 | |
1321 WaitForDraw(); | |
1322 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | |
1323 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); | |
1324 } | |
1325 | |
1326 // Verifies that when changing bounds on a layer that is invisible, and then | 1303 // Verifies that when changing bounds on a layer that is invisible, and then |
1327 // made visible, the right thing happens: | 1304 // made visible, the right thing happens: |
1328 // - if just a move, then no painting should happen. | 1305 // - if just a move, then no painting should happen. |
1329 // - if a resize, the layer should be repainted. | 1306 // - if a resize, the layer should be repainted. |
1330 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { | 1307 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { |
1331 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1308 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); |
1332 | 1309 |
1333 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1310 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); |
1334 child->SetBounds(gfx::Rect(0, 0, 500, 500)); | 1311 child->SetBounds(gfx::Rect(0, 0, 500, 500)); |
1335 DrawTreeLayerDelegate delegate; | 1312 DrawTreeLayerDelegate delegate; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 // Hi-DPI content on low-DPI layer. | 1385 // Hi-DPI content on low-DPI layer. |
1409 frame_provider = new cc::DelegatedFrameProvider( | 1386 frame_provider = new cc::DelegatedFrameProvider( |
1410 resource_collection.get(), MakeFrameData(gfx::Size(20, 20))); | 1387 resource_collection.get(), MakeFrameData(gfx::Size(20, 20))); |
1411 child->SetShowDelegatedContent(frame_provider, gfx::Size(10, 10)); | 1388 child->SetShowDelegatedContent(frame_provider, gfx::Size(10, 10)); |
1412 EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1389 EXPECT_EQ(child->cc_layer()->bounds().ToString(), |
1413 gfx::Size(10, 10).ToString()); | 1390 gfx::Size(10, 10).ToString()); |
1414 | 1391 |
1415 // Hi-DPI content on hi-DPI layer. | 1392 // Hi-DPI content on hi-DPI layer. |
1416 compositor()->SetScaleAndSize(2.f, gfx::Size(1000, 1000)); | 1393 compositor()->SetScaleAndSize(2.f, gfx::Size(1000, 1000)); |
1417 EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1394 EXPECT_EQ(child->cc_layer()->bounds().ToString(), |
1418 gfx::Size(20, 20).ToString()); | 1395 gfx::Size(10, 10).ToString()); |
1419 | 1396 |
1420 // Low-DPI content on hi-DPI layer. | 1397 // Low-DPI content on hi-DPI layer. |
1421 frame_provider = new cc::DelegatedFrameProvider( | 1398 frame_provider = new cc::DelegatedFrameProvider( |
1422 resource_collection.get(), MakeFrameData(gfx::Size(10, 10))); | 1399 resource_collection.get(), MakeFrameData(gfx::Size(10, 10))); |
1423 child->SetShowDelegatedContent(frame_provider, gfx::Size(10, 10)); | 1400 child->SetShowDelegatedContent(frame_provider, gfx::Size(10, 10)); |
1424 EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1401 EXPECT_EQ(child->cc_layer()->bounds().ToString(), |
1425 gfx::Size(20, 20).ToString()); | 1402 gfx::Size(10, 10).ToString()); |
1426 } | 1403 } |
1427 | 1404 |
1428 TEST_F(LayerWithDelegateTest, ExternalContent) { | 1405 TEST_F(LayerWithDelegateTest, ExternalContent) { |
1429 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1406 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); |
1430 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1407 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); |
1431 | 1408 |
1432 child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1409 child->SetBounds(gfx::Rect(0, 0, 10, 10)); |
1433 child->SetVisible(true); | 1410 child->SetVisible(true); |
1434 root->Add(child.get()); | 1411 root->Add(child.get()); |
1435 | 1412 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 l1->SetOpacity(0.5f); | 1497 l1->SetOpacity(0.5f); |
1521 | 1498 |
1522 // Change l1's cc::Layer. | 1499 // Change l1's cc::Layer. |
1523 l1->SwitchCCLayerForTest(); | 1500 l1->SwitchCCLayerForTest(); |
1524 | 1501 |
1525 // Ensure that the opacity animation completed. | 1502 // Ensure that the opacity animation completed. |
1526 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); | 1503 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); |
1527 } | 1504 } |
1528 | 1505 |
1529 } // namespace ui | 1506 } // namespace ui |
OLD | NEW |