| 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/gpu_rasterization_settings.h" |
| 19 #include "cc/test/hybrid_rasterization_settings.h" |
| 18 #include "cc/test/impl_side_painting_settings.h" | 20 #include "cc/test/impl_side_painting_settings.h" |
| 19 #include "cc/test/mock_quad_culler.h" | 21 #include "cc/test/mock_quad_culler.h" |
| 20 #include "cc/test/test_web_graphics_context_3d.h" | 22 #include "cc/test/test_web_graphics_context_3d.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) {} |
| 31 | 33 |
| 32 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { | 34 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { |
| 33 // Capture calls before SkCanvas quickReject() kicks in. | 35 // Capture calls before SkCanvas quickReject() kicks in. |
| 34 rects_.push_back(rect); | 36 rects_.push_back(rect); |
| 35 } | 37 } |
| 36 | 38 |
| 37 std::vector<SkRect> rects_; | 39 std::vector<SkRect> rects_; |
| 38 }; | 40 }; |
| 39 | 41 |
| 40 class PictureLayerImplTest : public testing::Test { | 42 class PictureLayerImplTest : public testing::Test { |
| 41 public: | 43 public: |
| 42 PictureLayerImplTest() | 44 PictureLayerImplTest() |
| 43 : proxy_(base::MessageLoopProxy::current()), | 45 : proxy_(base::MessageLoopProxy::current()), |
| 44 host_impl_(ImplSidePaintingSettings(), &proxy_), | 46 host_impl_(ImplSidePaintingSettings(), &proxy_), |
| 45 id_(7) {} | 47 id_(7) {} |
| 46 | 48 |
| 49 explicit PictureLayerImplTest(const LayerTreeSettings& settings) |
| 50 : proxy_(base::MessageLoopProxy::current()), |
| 51 host_impl_(settings, &proxy_), |
| 52 id_(7) {} |
| 53 |
| 47 virtual ~PictureLayerImplTest() { | 54 virtual ~PictureLayerImplTest() { |
| 48 } | 55 } |
| 49 | 56 |
| 50 virtual void SetUp() OVERRIDE { | 57 virtual void SetUp() OVERRIDE { |
| 51 InitializeRenderer(); | 58 InitializeRenderer(); |
| 52 } | 59 } |
| 53 | 60 |
| 54 virtual void InitializeRenderer() { | 61 virtual void InitializeRenderer() { |
| 55 host_impl_.InitializeRenderer( | 62 host_impl_.InitializeRenderer( |
| 56 FakeOutputSurface::Create3d().PassAs<OutputSurface>()); | 63 FakeOutputSurface::Create3d().PassAs<OutputSurface>()); |
| (...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 // Contrived unit test of a real crash. A layer is transparent during a | 1415 // Contrived unit test of a real crash. A layer is transparent during a |
| 1409 // context loss, and later becomes opaque, causing active layer SyncTiling to | 1416 // context loss, and later becomes opaque, causing active layer SyncTiling to |
| 1410 // be called. | 1417 // be called. |
| 1411 const float tile_scale = 2.f; | 1418 const float tile_scale = 2.f; |
| 1412 active_layer_->ReleaseResources(); | 1419 active_layer_->ReleaseResources(); |
| 1413 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(tile_scale)); | 1420 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(tile_scale)); |
| 1414 pending_layer_->AddTiling(2.f); | 1421 pending_layer_->AddTiling(2.f); |
| 1415 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(tile_scale)); | 1422 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(tile_scale)); |
| 1416 } | 1423 } |
| 1417 | 1424 |
| 1418 TEST_F(PictureLayerImplTest, TilingGpuRasterization) { | 1425 TEST_F(PictureLayerImplTest, TilingWithoutGpuRasterization) { |
| 1419 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | 1426 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
| 1420 gfx::Size layer_bounds(default_tile_size.width() * 4, | 1427 gfx::Size layer_bounds(default_tile_size.width() * 4, |
| 1421 default_tile_size.height() * 4); | 1428 default_tile_size.height() * 4); |
| 1422 float result_scale_x, result_scale_y; | 1429 float result_scale_x, result_scale_y; |
| 1423 gfx::Size result_bounds; | 1430 gfx::Size result_bounds; |
| 1424 | 1431 |
| 1425 // Layers without GPU rasterization (default). | |
| 1426 SetupDefaultTrees(layer_bounds); | 1432 SetupDefaultTrees(layer_bounds); |
| 1433 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); |
| 1427 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1434 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1428 pending_layer_->CalculateContentsScale( | 1435 pending_layer_->CalculateContentsScale( |
| 1429 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | 1436 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1430 // Should have a low-res and a high-res tiling. | 1437 // Should have a low-res and a high-res tiling. |
| 1431 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1438 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
| 1432 | |
| 1433 // Tell the layer to use GPU rasterization. | |
| 1434 pending_layer_->SetShouldUseGpuRasterization(true); | |
| 1435 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
| 1436 pending_layer_->CalculateContentsScale( | |
| 1437 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1438 // Should only have the high-res tiling. | |
| 1439 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1440 } | 1439 } |
| 1441 | 1440 |
| 1442 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { | 1441 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { |
| 1443 // Set up layers with tilings. | 1442 // Set up layers with tilings. |
| 1444 SetupDefaultTrees(gfx::Size(10, 10)); | 1443 SetupDefaultTrees(gfx::Size(10, 10)); |
| 1445 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, false); | 1444 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, false); |
| 1446 pending_layer_->PushPropertiesTo(active_layer_); | 1445 pending_layer_->PushPropertiesTo(active_layer_); |
| 1447 EXPECT_TRUE(pending_layer_->DrawsContent()); | 1446 EXPECT_TRUE(pending_layer_->DrawsContent()); |
| 1448 EXPECT_TRUE(pending_layer_->CanHaveTilings()); | 1447 EXPECT_TRUE(pending_layer_->CanHaveTilings()); |
| 1449 EXPECT_GE(pending_layer_->num_tilings(), 0u); | 1448 EXPECT_GE(pending_layer_->num_tilings(), 0u); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 static_cast<FakeOutputSurface*>(host_impl_.output_surface()); | 1544 static_cast<FakeOutputSurface*>(host_impl_.output_surface()); |
| 1546 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d( | 1545 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d( |
| 1547 TestContextProvider::Create(), NULL)); | 1546 TestContextProvider::Create(), NULL)); |
| 1548 | 1547 |
| 1549 // These will crash PictureLayerImpl if this is not true. | 1548 // These will crash PictureLayerImpl if this is not true. |
| 1550 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); | 1549 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); |
| 1551 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); | 1550 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); |
| 1552 host_impl_.active_tree()->UpdateDrawProperties(); | 1551 host_impl_.active_tree()->UpdateDrawProperties(); |
| 1553 } | 1552 } |
| 1554 | 1553 |
| 1554 class HybridRasterizationPictureLayerImplTest : public PictureLayerImplTest { |
| 1555 public: |
| 1556 HybridRasterizationPictureLayerImplTest() |
| 1557 : PictureLayerImplTest(HybridRasterizationSettings()) {} |
| 1558 }; |
| 1559 |
| 1560 TEST_F(HybridRasterizationPictureLayerImplTest, Tiling) { |
| 1561 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
| 1562 gfx::Size layer_bounds(default_tile_size.width() * 4, |
| 1563 default_tile_size.height() * 4); |
| 1564 float result_scale_x, result_scale_y; |
| 1565 gfx::Size result_bounds; |
| 1566 |
| 1567 SetupDefaultTrees(layer_bounds); |
| 1568 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); |
| 1569 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1570 pending_layer_->CalculateContentsScale( |
| 1571 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1572 // Should have a low-res and a high-res tiling. |
| 1573 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
| 1574 |
| 1575 pending_layer_->SetHasGpuRasterizationHint(true); |
| 1576 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); |
| 1577 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1578 pending_layer_->CalculateContentsScale( |
| 1579 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1580 // Should only have the high-res tiling. |
| 1581 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 1582 } |
| 1583 |
| 1584 class GpuRasterizationPictureLayerImplTest : public PictureLayerImplTest { |
| 1585 public: |
| 1586 GpuRasterizationPictureLayerImplTest() |
| 1587 : PictureLayerImplTest(GpuRasterizationSettings()) {} |
| 1588 }; |
| 1589 |
| 1590 TEST_F(GpuRasterizationPictureLayerImplTest, 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 |
| 1555 } // namespace | 1616 } // namespace |
| 1556 } // namespace cc | 1617 } // namespace cc |
| OLD | NEW |