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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 id_(7) {} | 69 id_(7) {} |
70 | 70 |
71 virtual ~PictureLayerImplTest() { | 71 virtual ~PictureLayerImplTest() { |
72 } | 72 } |
73 | 73 |
74 virtual void SetUp() OVERRIDE { | 74 virtual void SetUp() OVERRIDE { |
75 InitializeRenderer(); | 75 InitializeRenderer(); |
76 } | 76 } |
77 | 77 |
78 virtual void InitializeRenderer() { | 78 virtual void InitializeRenderer() { |
79 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); | 79 host_impl_.InitializeRenderer( |
| 80 FakeOutputSurface::Create3d().PassAs<OutputSurface>()); |
80 } | 81 } |
81 | 82 |
82 void SetupDefaultTrees(const gfx::Size& layer_bounds) { | 83 void SetupDefaultTrees(const gfx::Size& layer_bounds) { |
83 gfx::Size tile_size(100, 100); | 84 gfx::Size tile_size(100, 100); |
84 | 85 |
85 scoped_refptr<FakePicturePileImpl> pending_pile = | 86 scoped_refptr<FakePicturePileImpl> pending_pile = |
86 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 87 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
87 scoped_refptr<FakePicturePileImpl> active_pile = | 88 scoped_refptr<FakePicturePileImpl> active_pile = |
88 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 89 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
89 | 90 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) { | 138 void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) { |
138 host_impl_.CreatePendingTree(); | 139 host_impl_.CreatePendingTree(); |
139 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f); | 140 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f); |
140 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | 141 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
141 // Clear recycled tree. | 142 // Clear recycled tree. |
142 pending_tree->DetachLayerTree(); | 143 pending_tree->DetachLayerTree(); |
143 | 144 |
144 scoped_ptr<FakePictureLayerImpl> pending_layer = | 145 scoped_ptr<FakePictureLayerImpl> pending_layer = |
145 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile); | 146 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile); |
146 pending_layer->SetDrawsContent(true); | 147 pending_layer->SetDrawsContent(true); |
147 pending_tree->SetRootLayer(pending_layer.Pass()); | 148 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>()); |
148 | 149 |
149 pending_layer_ = static_cast<FakePictureLayerImpl*>( | 150 pending_layer_ = static_cast<FakePictureLayerImpl*>( |
150 host_impl_.pending_tree()->LayerById(id_)); | 151 host_impl_.pending_tree()->LayerById(id_)); |
151 pending_layer_->DoPostCommitInitializationIfNeeded(); | 152 pending_layer_->DoPostCommitInitializationIfNeeded(); |
152 } | 153 } |
153 | 154 |
154 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer, | 155 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer, |
155 float ideal_contents_scale, | 156 float ideal_contents_scale, |
156 float device_scale_factor, | 157 float device_scale_factor, |
157 float page_scale_factor, | 158 float page_scale_factor, |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 EXPECT_EQ(gfx::Size(256, 256).ToString(), | 1287 EXPECT_EQ(gfx::Size(256, 256).ToString(), |
1287 tile->content_rect().size().ToString()); | 1288 tile->content_rect().size().ToString()); |
1288 | 1289 |
1289 pending_layer_->ReleaseResources(); | 1290 pending_layer_->ReleaseResources(); |
1290 | 1291 |
1291 // Change the max texture size on the output surface context. | 1292 // Change the max texture size on the output surface context. |
1292 scoped_ptr<TestWebGraphicsContext3D> context = | 1293 scoped_ptr<TestWebGraphicsContext3D> context = |
1293 TestWebGraphicsContext3D::Create(); | 1294 TestWebGraphicsContext3D::Create(); |
1294 context->set_max_texture_size(140); | 1295 context->set_max_texture_size(140); |
1295 host_impl_.DidLoseOutputSurface(); | 1296 host_impl_.DidLoseOutputSurface(); |
1296 host_impl_.InitializeRenderer( | 1297 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( |
1297 FakeOutputSurface::Create3d(context.Pass()).Pass()); | 1298 context.Pass()).PassAs<OutputSurface>()); |
1298 | 1299 |
1299 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false); | 1300 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
1300 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1301 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
1301 | 1302 |
1302 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 1303 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
1303 | 1304 |
1304 // Verify the tiles are not larger than the context's max texture size. | 1305 // Verify the tiles are not larger than the context's max texture size. |
1305 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; | 1306 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; |
1306 EXPECT_GE(140, tile->content_rect().width()); | 1307 EXPECT_GE(140, tile->content_rect().width()); |
1307 EXPECT_GE(140, tile->content_rect().height()); | 1308 EXPECT_GE(140, tile->content_rect().height()); |
(...skipping 25 matching lines...) Expand all Loading... |
1333 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0); | 1334 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0); |
1334 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size()); | 1335 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size()); |
1335 | 1336 |
1336 pending_layer_->ReleaseResources(); | 1337 pending_layer_->ReleaseResources(); |
1337 | 1338 |
1338 // Change the max texture size on the output surface context. | 1339 // Change the max texture size on the output surface context. |
1339 scoped_ptr<TestWebGraphicsContext3D> context = | 1340 scoped_ptr<TestWebGraphicsContext3D> context = |
1340 TestWebGraphicsContext3D::Create(); | 1341 TestWebGraphicsContext3D::Create(); |
1341 context->set_max_texture_size(140); | 1342 context->set_max_texture_size(140); |
1342 host_impl_.DidLoseOutputSurface(); | 1343 host_impl_.DidLoseOutputSurface(); |
1343 host_impl_.InitializeRenderer( | 1344 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( |
1344 FakeOutputSurface::Create3d(context.Pass()).Pass()); | 1345 context.Pass()).PassAs<OutputSurface>()); |
1345 | 1346 |
1346 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false); | 1347 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
1347 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); | 1348 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); |
1348 | 1349 |
1349 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 1350 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
1350 | 1351 |
1351 // There should be more than one tile since the max texture size won't cover | 1352 // There should be more than one tile since the max texture size won't cover |
1352 // the layer. | 1353 // the layer. |
1353 high_res_tiling = pending_layer_->tilings()->tiling_at(0); | 1354 high_res_tiling = pending_layer_->tilings()->tiling_at(0); |
1354 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size()); | 1355 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size()); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 gfx::Size layer_bounds(400, 400); | 1853 gfx::Size layer_bounds(400, 400); |
1853 scoped_refptr<FakePicturePileImpl> pending_pile = | 1854 scoped_refptr<FakePicturePileImpl> pending_pile = |
1854 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1855 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1855 | 1856 |
1856 host_impl_.CreatePendingTree(); | 1857 host_impl_.CreatePendingTree(); |
1857 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | 1858 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
1858 | 1859 |
1859 scoped_ptr<FakePictureLayerImpl> pending_layer = | 1860 scoped_ptr<FakePictureLayerImpl> pending_layer = |
1860 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pending_pile); | 1861 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pending_pile); |
1861 pending_layer->SetDrawsContent(true); | 1862 pending_layer->SetDrawsContent(true); |
1862 pending_tree->SetRootLayer(pending_layer.Pass()); | 1863 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>()); |
1863 | 1864 |
1864 pending_layer_ = static_cast<FakePictureLayerImpl*>( | 1865 pending_layer_ = static_cast<FakePictureLayerImpl*>( |
1865 host_impl_.pending_tree()->LayerById(id_)); | 1866 host_impl_.pending_tree()->LayerById(id_)); |
1866 | 1867 |
1867 // Set some state on the pending layer, make sure it is not clobbered | 1868 // Set some state on the pending layer, make sure it is not clobbered |
1868 // by a sync from the active layer. This could happen because if the | 1869 // by a sync from the active layer. This could happen because if the |
1869 // pending layer has not been post-commit initialized it will attempt | 1870 // pending layer has not been post-commit initialized it will attempt |
1870 // to sync from the active layer. | 1871 // to sync from the active layer. |
1871 float raster_page_scale = 10.f * pending_layer_->raster_page_scale(); | 1872 float raster_page_scale = 10.f * pending_layer_->raster_page_scale(); |
1872 pending_layer_->set_raster_page_scale(raster_page_scale); | 1873 pending_layer_->set_raster_page_scale(raster_page_scale); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2207 SetContentsScaleOnBothLayers(contents_scale, 1.f, page_scale, 1.f, false); | 2208 SetContentsScaleOnBothLayers(contents_scale, 1.f, page_scale, 1.f, false); |
2208 ASSERT_GE(pending_layer_->num_tilings(), 0u); | 2209 ASSERT_GE(pending_layer_->num_tilings(), 0u); |
2209 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(), | 2210 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(), |
2210 pending_layer_->HighResTiling()->contents_scale()); | 2211 pending_layer_->HighResTiling()->contents_scale()); |
2211 } | 2212 } |
2212 | 2213 |
2213 class DeferredInitPictureLayerImplTest : public PictureLayerImplTest { | 2214 class DeferredInitPictureLayerImplTest : public PictureLayerImplTest { |
2214 public: | 2215 public: |
2215 virtual void InitializeRenderer() OVERRIDE { | 2216 virtual void InitializeRenderer() OVERRIDE { |
2216 bool delegated_rendering = false; | 2217 bool delegated_rendering = false; |
2217 host_impl_.InitializeRenderer(FakeOutputSurface::CreateDeferredGL( | 2218 host_impl_.InitializeRenderer( |
2218 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice), | 2219 FakeOutputSurface::CreateDeferredGL( |
2219 delegated_rendering)); | 2220 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice), |
| 2221 delegated_rendering).PassAs<OutputSurface>()); |
2220 } | 2222 } |
2221 | 2223 |
2222 virtual void SetUp() OVERRIDE { | 2224 virtual void SetUp() OVERRIDE { |
2223 PictureLayerImplTest::SetUp(); | 2225 PictureLayerImplTest::SetUp(); |
2224 | 2226 |
2225 // Create some default active and pending trees. | 2227 // Create some default active and pending trees. |
2226 gfx::Size tile_size(100, 100); | 2228 gfx::Size tile_size(100, 100); |
2227 gfx::Size layer_bounds(400, 400); | 2229 gfx::Size layer_bounds(400, 400); |
2228 | 2230 |
2229 scoped_refptr<FakePicturePileImpl> pending_pile = | 2231 scoped_refptr<FakePicturePileImpl> pending_pile = |
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3493 FakePicturePileImpl::CreateFilledPile(tile_size, bounds); | 3495 FakePicturePileImpl::CreateFilledPile(tile_size, bounds); |
3494 pending_pile->set_is_mask(true); | 3496 pending_pile->set_is_mask(true); |
3495 scoped_ptr<FakePictureLayerImpl> mask = FakePictureLayerImpl::CreateWithPile( | 3497 scoped_ptr<FakePictureLayerImpl> mask = FakePictureLayerImpl::CreateWithPile( |
3496 host_impl_.pending_tree(), 3, pending_pile); | 3498 host_impl_.pending_tree(), 3, pending_pile); |
3497 | 3499 |
3498 mask->SetBounds(bounds); | 3500 mask->SetBounds(bounds); |
3499 mask->SetContentBounds(bounds); | 3501 mask->SetContentBounds(bounds); |
3500 mask->SetDrawsContent(true); | 3502 mask->SetDrawsContent(true); |
3501 | 3503 |
3502 FakePictureLayerImpl* pending_mask_content = mask.get(); | 3504 FakePictureLayerImpl* pending_mask_content = mask.get(); |
3503 layer_with_mask->SetMaskLayer(mask.Pass()); | 3505 layer_with_mask->SetMaskLayer(mask.PassAs<LayerImpl>()); |
3504 | 3506 |
3505 scoped_ptr<FakePictureLayerImpl> child_of_layer_with_mask = | 3507 scoped_ptr<FakePictureLayerImpl> child_of_layer_with_mask = |
3506 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 4); | 3508 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 4); |
3507 | 3509 |
3508 child_of_layer_with_mask->SetBounds(bounds); | 3510 child_of_layer_with_mask->SetBounds(bounds); |
3509 child_of_layer_with_mask->SetContentBounds(bounds); | 3511 child_of_layer_with_mask->SetContentBounds(bounds); |
3510 child_of_layer_with_mask->SetDrawsContent(true); | 3512 child_of_layer_with_mask->SetDrawsContent(true); |
3511 | 3513 |
3512 layer_with_mask->AddChild(child_of_layer_with_mask.Pass()); | 3514 layer_with_mask->AddChild(child_of_layer_with_mask.PassAs<LayerImpl>()); |
3513 | 3515 |
3514 root->AddChild(layer_with_mask.Pass()); | 3516 root->AddChild(layer_with_mask.PassAs<LayerImpl>()); |
3515 | 3517 |
3516 host_impl_.pending_tree()->SetRootLayer(root.Pass()); | 3518 host_impl_.pending_tree()->SetRootLayer(root.Pass()); |
3517 | 3519 |
3518 EXPECT_FALSE(pending_mask_content->tilings()); | 3520 EXPECT_FALSE(pending_mask_content->tilings()); |
3519 host_impl_.pending_tree()->UpdateDrawProperties(); | 3521 host_impl_.pending_tree()->UpdateDrawProperties(); |
3520 EXPECT_NE(0u, pending_mask_content->num_tilings()); | 3522 EXPECT_NE(0u, pending_mask_content->num_tilings()); |
3521 } | 3523 } |
3522 | 3524 |
3523 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest { | 3525 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest { |
3524 public: | 3526 public: |
3525 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {} | 3527 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {} |
3526 | 3528 |
3527 virtual void InitializeRenderer() OVERRIDE { | 3529 virtual void InitializeRenderer() OVERRIDE { |
3528 host_impl_.InitializeRenderer(FakeOutputSurface::CreateDelegating3d()); | 3530 host_impl_.InitializeRenderer( |
| 3531 FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>()); |
3529 } | 3532 } |
3530 }; | 3533 }; |
3531 | 3534 |
3532 TEST_F(PictureLayerImplTestWithDelegatingRenderer, | 3535 TEST_F(PictureLayerImplTestWithDelegatingRenderer, |
3533 DelegatingRendererWithTileOOM) { | 3536 DelegatingRendererWithTileOOM) { |
3534 // This test is added for crbug.com/402321, where quad should be produced when | 3537 // This test is added for crbug.com/402321, where quad should be produced when |
3535 // raster on demand is not allowed and tile is OOM. | 3538 // raster on demand is not allowed and tile is OOM. |
3536 gfx::Size tile_size = host_impl_.settings().default_tile_size; | 3539 gfx::Size tile_size = host_impl_.settings().default_tile_size; |
3537 gfx::Size layer_bounds(1000, 1000); | 3540 gfx::Size layer_bounds(1000, 1000); |
3538 | 3541 |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4362 SetupPendingTree(pending_pile2); | 4365 SetupPendingTree(pending_pile2); |
4363 ActivateTree(); | 4366 ActivateTree(); |
4364 | 4367 |
4365 // We've switched to a solid color, so we should end up with no tilings. | 4368 // We've switched to a solid color, so we should end up with no tilings. |
4366 ASSERT_TRUE(active_layer_->tilings()); | 4369 ASSERT_TRUE(active_layer_->tilings()); |
4367 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 4370 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
4368 } | 4371 } |
4369 | 4372 |
4370 } // namespace | 4373 } // namespace |
4371 } // namespace cc | 4374 } // namespace cc |
OLD | NEW |