| 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/file_util.h" | 8 #include "base/file_util.h" | 
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" | 
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" | 
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" | 
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" | 
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" | 
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" | 
|  | 15 #include "cc/layers/delegated_frame_provider.h" | 
|  | 16 #include "cc/layers/delegated_frame_resource_collection.h" | 
| 15 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" | 
| 16 #include "cc/output/delegated_frame_data.h" | 18 #include "cc/output/delegated_frame_data.h" | 
| 17 #include "cc/test/pixel_test_utils.h" | 19 #include "cc/test/pixel_test_utils.h" | 
| 18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" | 
| 19 #include "ui/compositor/compositor_observer.h" | 21 #include "ui/compositor/compositor_observer.h" | 
| 20 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" | 
| 21 #include "ui/compositor/layer_animation_sequence.h" | 23 #include "ui/compositor/layer_animation_sequence.h" | 
| 22 #include "ui/compositor/layer_animator.h" | 24 #include "ui/compositor/layer_animator.h" | 
| 23 #include "ui/compositor/test/test_compositor_host.h" | 25 #include "ui/compositor/test/test_compositor_host.h" | 
| 24 #include "ui/compositor/test/test_layers.h" | 26 #include "ui/compositor/test/test_layers.h" | 
| (...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1305 TEST_F(LayerWithDelegateTest, DelegatedLayer) { | 1307 TEST_F(LayerWithDelegateTest, DelegatedLayer) { | 
| 1306   scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1308   scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 
| 1307 | 1309 | 
| 1308   scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1310   scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 
| 1309 | 1311 | 
| 1310   child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1312   child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 
| 1311   child->SetVisible(true); | 1313   child->SetVisible(true); | 
| 1312   root->Add(child.get()); | 1314   root->Add(child.get()); | 
| 1313   DrawTree(root.get()); | 1315   DrawTree(root.get()); | 
| 1314 | 1316 | 
|  | 1317   scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection = | 
|  | 1318       new cc::DelegatedFrameResourceCollection; | 
|  | 1319   scoped_refptr<cc::DelegatedFrameProvider> frame_provider; | 
|  | 1320 | 
| 1315   // Content matches layer size. | 1321   // Content matches layer size. | 
| 1316   child->SetDelegatedFrame(MakeFrameData(gfx::Size(10, 10)), gfx::Size(10, 10)); | 1322   frame_provider = new cc::DelegatedFrameProvider( | 
|  | 1323       resource_collection.get(), MakeFrameData(gfx::Size(10, 10))); | 
|  | 1324   child->SetShowDelegatedContent(frame_provider, gfx::Size(10, 10)); | 
| 1317   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1325   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 
| 1318             gfx::Size(10, 10).ToString()); | 1326             gfx::Size(10, 10).ToString()); | 
| 1319 | 1327 | 
| 1320   // Content larger than layer. | 1328   // Content larger than layer. | 
| 1321   child->SetBounds(gfx::Rect(0, 0, 5, 5)); | 1329   child->SetBounds(gfx::Rect(0, 0, 5, 5)); | 
| 1322   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1330   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 
| 1323             gfx::Size(5, 5).ToString()); | 1331             gfx::Size(5, 5).ToString()); | 
| 1324 | 1332 | 
| 1325   // Content smaller than layer. | 1333   // Content smaller than layer. | 
| 1326   child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1334   child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 
| 1327   child->SetDelegatedFrame(MakeFrameData(gfx::Size(5, 5)), gfx::Size(5, 5)); | 1335   frame_provider = new cc::DelegatedFrameProvider( | 
| 1328   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1336       resource_collection.get(), MakeFrameData(gfx::Size(5, 5))); | 
| 1329             gfx::Size(5, 5).ToString()); | 1337   child->SetShowDelegatedContent(frame_provider, gfx::Size(5, 5)); | 
|  | 1338   EXPECT_EQ(child->cc_layer()->bounds().ToString(), gfx::Size(5, 5).ToString()); | 
| 1330 | 1339 | 
| 1331   // Hi-DPI content on low-DPI layer. | 1340   // Hi-DPI content on low-DPI layer. | 
| 1332   child->SetDelegatedFrame(MakeFrameData(gfx::Size(20, 20)), gfx::Size(10, 10)); | 1341   frame_provider = new cc::DelegatedFrameProvider( | 
|  | 1342       resource_collection.get(), MakeFrameData(gfx::Size(20, 20))); | 
|  | 1343   child->SetShowDelegatedContent(frame_provider, gfx::Size(10, 10)); | 
| 1333   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1344   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 
| 1334             gfx::Size(10, 10).ToString()); | 1345             gfx::Size(10, 10).ToString()); | 
| 1335 | 1346 | 
| 1336   // Hi-DPI content on hi-DPI layer. | 1347   // Hi-DPI content on hi-DPI layer. | 
| 1337   compositor()->SetScaleAndSize(2.f, gfx::Size(1000, 1000)); | 1348   compositor()->SetScaleAndSize(2.f, gfx::Size(1000, 1000)); | 
| 1338   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1349   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 
| 1339             gfx::Size(20, 20).ToString()); | 1350             gfx::Size(20, 20).ToString()); | 
| 1340 | 1351 | 
| 1341   // Low-DPI content on hi-DPI layer. | 1352   // Low-DPI content on hi-DPI layer. | 
| 1342   child->SetDelegatedFrame(MakeFrameData(gfx::Size(10, 10)), gfx::Size(10, 10)); | 1353   frame_provider = new cc::DelegatedFrameProvider( | 
|  | 1354       resource_collection.get(), MakeFrameData(gfx::Size(10, 10))); | 
|  | 1355   child->SetShowDelegatedContent(frame_provider, gfx::Size(10, 10)); | 
| 1343   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1356   EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 
| 1344             gfx::Size(20, 20).ToString()); | 1357             gfx::Size(20, 20).ToString()); | 
| 1345 } | 1358 } | 
| 1346 | 1359 | 
| 1347 TEST_F(LayerWithDelegateTest, ExternalContent) { | 1360 TEST_F(LayerWithDelegateTest, ExternalContent) { | 
| 1348   scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1361   scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 
| 1349   scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1362   scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 
| 1350 | 1363 | 
| 1351   child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1364   child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 
| 1352   child->SetVisible(true); | 1365   child->SetVisible(true); | 
| 1353   root->Add(child.get()); | 1366   root->Add(child.get()); | 
| 1354 | 1367 | 
| 1355   // The layer is already showing painted content, so the cc layer won't change. | 1368   // The layer is already showing painted content, so the cc layer won't change. | 
| 1356   scoped_refptr<cc::Layer> before = child->cc_layer(); | 1369   scoped_refptr<cc::Layer> before = child->cc_layer(); | 
| 1357   child->SetShowPaintedContent(); | 1370   child->SetShowPaintedContent(); | 
| 1358   EXPECT_TRUE(child->cc_layer()); | 1371   EXPECT_TRUE(child->cc_layer()); | 
| 1359   EXPECT_EQ(before, child->cc_layer()); | 1372   EXPECT_EQ(before, child->cc_layer()); | 
| 1360 | 1373 | 
|  | 1374   scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection = | 
|  | 1375       new cc::DelegatedFrameResourceCollection; | 
|  | 1376   scoped_refptr<cc::DelegatedFrameProvider> frame_provider = | 
|  | 1377       new cc::DelegatedFrameProvider(resource_collection.get(), | 
|  | 1378                                      MakeFrameData(gfx::Size(10, 10))); | 
|  | 1379 | 
| 1361   // Showing delegated content changes the underlying cc layer. | 1380   // Showing delegated content changes the underlying cc layer. | 
| 1362   before = child->cc_layer(); | 1381   before = child->cc_layer(); | 
| 1363   child->SetDelegatedFrame(MakeFrameData(gfx::Size(10, 10)), gfx::Size(10, 10)); | 1382   child->SetShowDelegatedContent(frame_provider, gfx::Size(10, 10)); | 
| 1364   EXPECT_TRUE(child->cc_layer()); | 1383   EXPECT_TRUE(child->cc_layer()); | 
| 1365   EXPECT_NE(before, child->cc_layer()); | 1384   EXPECT_NE(before, child->cc_layer()); | 
| 1366 | 1385 | 
| 1367   // Changing to painted content should change the underlying cc layer. | 1386   // Changing to painted content should change the underlying cc layer. | 
| 1368   before = child->cc_layer(); | 1387   before = child->cc_layer(); | 
| 1369   child->SetShowPaintedContent(); | 1388   child->SetShowPaintedContent(); | 
| 1370   EXPECT_TRUE(child->cc_layer()); | 1389   EXPECT_TRUE(child->cc_layer()); | 
| 1371   EXPECT_NE(before, child->cc_layer()); | 1390   EXPECT_NE(before, child->cc_layer()); | 
| 1372 } | 1391 } | 
| 1373 | 1392 | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1433   l1->SetOpacity(0.5f); | 1452   l1->SetOpacity(0.5f); | 
| 1434 | 1453 | 
| 1435   // Change l1's cc::Layer. | 1454   // Change l1's cc::Layer. | 
| 1436   l1->SwitchCCLayerForTest(); | 1455   l1->SwitchCCLayerForTest(); | 
| 1437 | 1456 | 
| 1438   // Ensure that the opacity animation completed. | 1457   // Ensure that the opacity animation completed. | 
| 1439   EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); | 1458   EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); | 
| 1440 } | 1459 } | 
| 1441 | 1460 | 
| 1442 }  // namespace ui | 1461 }  // namespace ui | 
| OLD | NEW | 
|---|