| 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 "cc/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "cc/layers/append_quads_data.h" | 9 #include "cc/layers/append_quads_data.h" |
| 10 #include "cc/layers/picture_layer.h" | 10 #include "cc/layers/picture_layer.h" |
| 11 #include "cc/test/fake_content_layer_client.h" | 11 #include "cc/test/fake_content_layer_client.h" |
| 12 #include "cc/test/fake_impl_proxy.h" | 12 #include "cc/test/fake_impl_proxy.h" |
| 13 #include "cc/test/fake_layer_tree_host_impl.h" | 13 #include "cc/test/fake_layer_tree_host_impl.h" |
| 14 #include "cc/test/fake_output_surface.h" | 14 #include "cc/test/fake_output_surface.h" |
| 15 #include "cc/test/fake_picture_layer_impl.h" | 15 #include "cc/test/fake_picture_layer_impl.h" |
| 16 #include "cc/test/fake_picture_pile_impl.h" | 16 #include "cc/test/fake_picture_pile_impl.h" |
| 17 #include "cc/test/geometry_test_utils.h" | 17 #include "cc/test/geometry_test_utils.h" |
| 18 #include "cc/test/hybrid_gpu_rasterization_settings.h" |
| 18 #include "cc/test/impl_side_painting_settings.h" | 19 #include "cc/test/impl_side_painting_settings.h" |
| 19 #include "cc/test/mock_quad_culler.h" | 20 #include "cc/test/mock_quad_culler.h" |
| 20 #include "cc/test/test_web_graphics_context_3d.h" | 21 #include "cc/test/test_web_graphics_context_3d.h" |
| 22 #include "cc/test/universal_gpu_rasterization_settings.h" |
| 21 #include "cc/trees/layer_tree_impl.h" | 23 #include "cc/trees/layer_tree_impl.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "ui/gfx/rect_conversions.h" | 25 #include "ui/gfx/rect_conversions.h" |
| 24 | 26 |
| 25 namespace cc { | 27 namespace cc { |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 class MockCanvas : public SkCanvas { | 30 class MockCanvas : public SkCanvas { |
| 29 public: | 31 public: |
| 30 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} | 32 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 // Contrived unit test of a real crash. A layer is transparent during a | 1411 // Contrived unit test of a real crash. A layer is transparent during a |
| 1410 // context loss, and later becomes opaque, causing active layer SyncTiling to | 1412 // context loss, and later becomes opaque, causing active layer SyncTiling to |
| 1411 // be called. | 1413 // be called. |
| 1412 const float tile_scale = 2.f; | 1414 const float tile_scale = 2.f; |
| 1413 active_layer_->ReleaseResources(); | 1415 active_layer_->ReleaseResources(); |
| 1414 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(tile_scale)); | 1416 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(tile_scale)); |
| 1415 pending_layer_->AddTiling(2.f); | 1417 pending_layer_->AddTiling(2.f); |
| 1416 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(tile_scale)); | 1418 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(tile_scale)); |
| 1417 } | 1419 } |
| 1418 | 1420 |
| 1419 TEST_F(PictureLayerImplTest, TilingGpuRasterization) { | 1421 TEST_F(PictureLayerImplTest, TilingWithoutGpuRasterization) { |
| 1420 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | 1422 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
| 1421 gfx::Size layer_bounds(default_tile_size.width() * 4, | 1423 gfx::Size layer_bounds(default_tile_size.width() * 4, |
| 1422 default_tile_size.height() * 4); | 1424 default_tile_size.height() * 4); |
| 1423 float result_scale_x, result_scale_y; | 1425 float result_scale_x, result_scale_y; |
| 1424 gfx::Size result_bounds; | 1426 gfx::Size result_bounds; |
| 1425 | 1427 |
| 1426 // Layers without GPU rasterization (default). | |
| 1427 SetupDefaultTrees(layer_bounds); | 1428 SetupDefaultTrees(layer_bounds); |
| 1429 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); |
| 1428 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1430 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1429 pending_layer_->CalculateContentsScale( | 1431 pending_layer_->CalculateContentsScale( |
| 1430 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | 1432 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1431 // Should have a low-res and a high-res tiling. | 1433 // Should have a low-res and a high-res tiling. |
| 1432 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1434 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
| 1433 | |
| 1434 // Tell the layer to use GPU rasterization. | |
| 1435 pending_layer_->SetShouldUseGpuRasterization(true); | |
| 1436 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
| 1437 pending_layer_->CalculateContentsScale( | |
| 1438 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1439 // Should only have the high-res tiling. | |
| 1440 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1441 } | 1435 } |
| 1442 | 1436 |
| 1443 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { | 1437 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { |
| 1444 // Set up layers with tilings. | 1438 // Set up layers with tilings. |
| 1445 SetupDefaultTrees(gfx::Size(10, 10)); | 1439 SetupDefaultTrees(gfx::Size(10, 10)); |
| 1446 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, false); | 1440 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, false); |
| 1447 pending_layer_->PushPropertiesTo(active_layer_); | 1441 pending_layer_->PushPropertiesTo(active_layer_); |
| 1448 EXPECT_TRUE(pending_layer_->DrawsContent()); | 1442 EXPECT_TRUE(pending_layer_->DrawsContent()); |
| 1449 EXPECT_TRUE(pending_layer_->CanHaveTilings()); | 1443 EXPECT_TRUE(pending_layer_->CanHaveTilings()); |
| 1450 EXPECT_GE(pending_layer_->num_tilings(), 0u); | 1444 EXPECT_GE(pending_layer_->num_tilings(), 0u); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 static_cast<FakeOutputSurface*>(host_impl_.output_surface()); | 1543 static_cast<FakeOutputSurface*>(host_impl_.output_surface()); |
| 1550 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d( | 1544 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d( |
| 1551 TestContextProvider::Create(), NULL)); | 1545 TestContextProvider::Create(), NULL)); |
| 1552 | 1546 |
| 1553 // These will crash PictureLayerImpl if this is not true. | 1547 // These will crash PictureLayerImpl if this is not true. |
| 1554 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); | 1548 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); |
| 1555 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); | 1549 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); |
| 1556 host_impl_.active_tree()->UpdateDrawProperties(); | 1550 host_impl_.active_tree()->UpdateDrawProperties(); |
| 1557 } | 1551 } |
| 1558 | 1552 |
| 1553 class HybridGpuRasterizationPictureLayerImplTest : public PictureLayerImplTest { |
| 1554 public: |
| 1555 HybridGpuRasterizationPictureLayerImplTest() |
| 1556 : PictureLayerImplTest(HybridGpuRasterizationSettings()) {} |
| 1557 }; |
| 1558 |
| 1559 TEST_F(HybridGpuRasterizationPictureLayerImplTest, Tiling) { |
| 1560 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
| 1561 gfx::Size layer_bounds(default_tile_size.width() * 4, |
| 1562 default_tile_size.height() * 4); |
| 1563 float result_scale_x, result_scale_y; |
| 1564 gfx::Size result_bounds; |
| 1565 |
| 1566 SetupDefaultTrees(layer_bounds); |
| 1567 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); |
| 1568 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1569 pending_layer_->CalculateContentsScale( |
| 1570 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1571 // Should have a low-res and a high-res tiling. |
| 1572 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
| 1573 |
| 1574 pending_layer_->SetHasGpuRasterizationHint(true); |
| 1575 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); |
| 1576 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1577 pending_layer_->CalculateContentsScale( |
| 1578 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1579 // Should only have the high-res tiling. |
| 1580 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 1581 } |
| 1582 |
| 1583 class UniversalGpuRasterizationPictureLayerImplTest |
| 1584 : public PictureLayerImplTest { |
| 1585 public: |
| 1586 UniversalGpuRasterizationPictureLayerImplTest() |
| 1587 : PictureLayerImplTest(UniversalGpuRasterizationSettings()) {} |
| 1588 }; |
| 1589 |
| 1590 TEST_F(UniversalGpuRasterizationPictureLayerImplTest, Tiling) { |
| 1591 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
| 1592 gfx::Size layer_bounds(default_tile_size.width() * 4, |
| 1593 default_tile_size.height() * 4); |
| 1594 float result_scale_x, result_scale_y; |
| 1595 gfx::Size result_bounds; |
| 1596 |
| 1597 SetupDefaultTrees(layer_bounds); |
| 1598 pending_layer_->SetHasGpuRasterizationHint(true); |
| 1599 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); |
| 1600 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1601 pending_layer_->CalculateContentsScale( |
| 1602 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1603 // Should only have the high-res tiling. |
| 1604 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 1605 |
| 1606 pending_layer_->SetHasGpuRasterizationHint(false); |
| 1607 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); |
| 1608 // Should still have the high-res tiling. |
| 1609 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 1610 pending_layer_->CalculateContentsScale( |
| 1611 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1612 // Should still only have the high-res tiling. |
| 1613 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 1614 } |
| 1615 |
| 1559 } // namespace | 1616 } // namespace |
| 1560 } // namespace cc | 1617 } // namespace cc |
| OLD | NEW |