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