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 2265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2276 SetupDefaultTrees(gfx::Size(10, 10)); | 2276 SetupDefaultTrees(gfx::Size(10, 10)); |
2277 host_impl_.active_tree()->UpdateDrawProperties(); | 2277 host_impl_.active_tree()->UpdateDrawProperties(); |
2278 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); | 2278 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); |
2279 | 2279 |
2280 // Contrived unit test of a real crash. A layer is transparent during a | 2280 // Contrived unit test of a real crash. A layer is transparent during a |
2281 // context loss, and later becomes opaque, causing active layer SyncTiling to | 2281 // context loss, and later becomes opaque, causing active layer SyncTiling to |
2282 // be called. | 2282 // be called. |
2283 float new_scale = 1.f; | 2283 float new_scale = 1.f; |
2284 active_layer_->ReleaseResources(); | 2284 active_layer_->ReleaseResources(); |
2285 pending_layer_->ReleaseResources(); | 2285 pending_layer_->ReleaseResources(); |
2286 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(new_scale)); | 2286 EXPECT_FALSE(active_layer_->tilings()->FindTilingWithScale(new_scale)); |
2287 pending_layer_->AddTiling(new_scale); | 2287 pending_layer_->AddTiling(new_scale); |
2288 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(new_scale)); | 2288 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(new_scale)); |
2289 | 2289 |
2290 // UpdateDrawProperties early-outs if the tree doesn't need it. It is also | 2290 // UpdateDrawProperties early-outs if the tree doesn't need it. It is also |
2291 // responsible for calling ManageTilings. These checks verify that | 2291 // responsible for calling ManageTilings. These checks verify that |
2292 // ReleaseResources has set needs update draw properties so that the | 2292 // ReleaseResources has set needs update draw properties so that the |
2293 // new tiling gets the appropriate resolution set in ManageTilings. | 2293 // new tiling gets the appropriate resolution set in ManageTilings. |
2294 EXPECT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); | 2294 EXPECT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); |
2295 host_impl_.active_tree()->UpdateDrawProperties(); | 2295 host_impl_.active_tree()->UpdateDrawProperties(); |
2296 PictureLayerTiling* high_res = | 2296 PictureLayerTiling* high_res = |
2297 active_layer_->tilings()->TilingAtScale(new_scale); | 2297 active_layer_->tilings()->FindTilingWithScale(new_scale); |
2298 ASSERT_TRUE(!!high_res); | 2298 ASSERT_TRUE(!!high_res); |
2299 EXPECT_EQ(HIGH_RESOLUTION, high_res->resolution()); | 2299 EXPECT_EQ(HIGH_RESOLUTION, high_res->resolution()); |
2300 } | 2300 } |
2301 | 2301 |
2302 TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) { | 2302 TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) { |
2303 SetupDefaultTrees(gfx::Size(10, 10)); | 2303 SetupDefaultTrees(gfx::Size(10, 10)); |
2304 | 2304 |
2305 const float kScale = 1.f; | 2305 const float kScale = 1.f; |
2306 pending_layer_->AddTiling(kScale); | 2306 pending_layer_->AddTiling(kScale); |
2307 EXPECT_TRUE(pending_layer_->tilings()->TilingAtScale(kScale)); | 2307 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(kScale)); |
2308 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(kScale)); | 2308 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(kScale)); |
2309 | 2309 |
2310 // Gpu rasterization is disabled by default. | 2310 // Gpu rasterization is disabled by default. |
2311 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); | 2311 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); |
2312 // Toggling the gpu rasterization clears all tilings on both trees. | 2312 // Toggling the gpu rasterization clears all tilings on both trees. |
2313 host_impl_.SetUseGpuRasterization(true); | 2313 host_impl_.SetUseGpuRasterization(true); |
2314 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 2314 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
2315 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 2315 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
2316 | 2316 |
2317 // Make sure that we can still add tiling to the pending layer, | 2317 // Make sure that we can still add tiling to the pending layer, |
2318 // that gets synced to the active layer. | 2318 // that gets synced to the active layer. |
2319 pending_layer_->AddTiling(kScale); | 2319 pending_layer_->AddTiling(kScale); |
2320 EXPECT_TRUE(pending_layer_->tilings()->TilingAtScale(kScale)); | 2320 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(kScale)); |
2321 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(kScale)); | 2321 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(kScale)); |
2322 | 2322 |
2323 // Toggling the gpu rasterization clears all tilings on both trees. | 2323 // Toggling the gpu rasterization clears all tilings on both trees. |
2324 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); | 2324 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); |
2325 host_impl_.SetUseGpuRasterization(false); | 2325 host_impl_.SetUseGpuRasterization(false); |
2326 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 2326 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
2327 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 2327 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
2328 } | 2328 } |
2329 | 2329 |
2330 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { | 2330 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { |
2331 gfx::Size tile_size(100, 100); | 2331 gfx::Size tile_size(100, 100); |
2332 | 2332 |
2333 scoped_refptr<FakePicturePileImpl> active_pile = | 2333 scoped_refptr<FakePicturePileImpl> active_pile = |
2334 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(10, 10)); | 2334 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(10, 10)); |
2335 SetupPendingTree(active_pile); | 2335 SetupPendingTree(active_pile); |
2336 ActivateTree(); | 2336 ActivateTree(); |
2337 host_impl_.active_tree()->UpdateDrawProperties(); | 2337 host_impl_.active_tree()->UpdateDrawProperties(); |
2338 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); | 2338 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); |
2339 | 2339 |
2340 SetupDrawPropertiesAndUpdateTiles( | 2340 SetupDrawPropertiesAndUpdateTiles( |
2341 active_layer_, 0.5f, 0.5f, 0.5f, 0.5f, false); | 2341 active_layer_, 0.5f, 0.5f, 0.5f, 0.5f, false); |
2342 active_layer_->tilings()->RemoveAllTilings(); | 2342 active_layer_->tilings()->RemoveAllTilings(); |
2343 PictureLayerTiling* tiling = active_layer_->AddTiling(0.5f); | 2343 PictureLayerTiling* tiling = active_layer_->AddTiling(0.5f); |
2344 active_layer_->AddTiling(1.5f); | 2344 active_layer_->AddTiling(1.5f); |
2345 active_layer_->AddTiling(0.25f); | 2345 active_layer_->AddTiling(0.25f); |
2346 tiling->set_resolution(HIGH_RESOLUTION); | 2346 tiling->set_resolution(HIGH_RESOLUTION); |
2347 | 2347 |
2348 // Sanity checks. | 2348 // Sanity checks. |
2349 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); | 2349 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); |
2350 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f)); | 2350 ASSERT_EQ(tiling, active_layer_->tilings()->FindTilingWithScale(0.5f)); |
2351 | 2351 |
2352 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes | 2352 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes |
2353 // 1.0f). Note that we should also ensure that the pending layer needs post | 2353 // 1.0f). Note that we should also ensure that the pending layer needs post |
2354 // commit initialization, since this is what would happen during commit. In | 2354 // commit initialization, since this is what would happen during commit. In |
2355 // other words we want the pending layer to sync from the active layer. | 2355 // other words we want the pending layer to sync from the active layer. |
2356 scoped_refptr<FakePicturePileImpl> pending_pile = | 2356 scoped_refptr<FakePicturePileImpl> pending_pile = |
2357 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1, 1)); | 2357 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1, 1)); |
2358 SetupPendingTree(pending_pile); | 2358 SetupPendingTree(pending_pile); |
2359 | 2359 |
2360 // Update the draw properties: sync from active tree should happen here. | 2360 // Update the draw properties: sync from active tree should happen here. |
2361 host_impl_.pending_tree()->UpdateDrawProperties(); | 2361 host_impl_.pending_tree()->UpdateDrawProperties(); |
2362 EXPECT_FALSE(pending_layer_->needs_post_commit_initialization()); | 2362 EXPECT_FALSE(pending_layer_->needs_post_commit_initialization()); |
2363 | 2363 |
2364 // Another sanity check. | 2364 // Another sanity check. |
2365 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale()); | 2365 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale()); |
2366 | 2366 |
2367 // Now we should've synced 1.5f tiling, since that's the only one that doesn't | 2367 // Now we should've synced 1.5f tiling, since that's the only one that doesn't |
2368 // violate minimum contents scale. At the same time, we should've created a | 2368 // violate minimum contents scale. At the same time, we should've created a |
2369 // new high res tiling at scale 1.0f. | 2369 // new high res tiling at scale 1.0f. |
2370 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 2370 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
2371 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f)); | 2371 ASSERT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.0f)); |
2372 EXPECT_EQ(HIGH_RESOLUTION, | 2372 EXPECT_EQ(HIGH_RESOLUTION, |
2373 pending_layer_->tilings()->TilingAtScale(1.0f)->resolution()); | 2373 pending_layer_->tilings()->FindTilingWithScale(1.0f)->resolution()); |
2374 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.5f)); | 2374 ASSERT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.5f)); |
2375 EXPECT_EQ(NON_IDEAL_RESOLUTION, | 2375 EXPECT_EQ(NON_IDEAL_RESOLUTION, |
2376 pending_layer_->tilings()->TilingAtScale(1.5f)->resolution()); | 2376 pending_layer_->tilings()->FindTilingWithScale(1.5f)->resolution()); |
2377 } | 2377 } |
2378 | 2378 |
2379 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { | 2379 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { |
2380 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | 2380 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
2381 gfx::Size layer_bounds(default_tile_size.width() * 4, | 2381 gfx::Size layer_bounds(default_tile_size.width() * 4, |
2382 default_tile_size.height() * 4); | 2382 default_tile_size.height() * 4); |
2383 | 2383 |
2384 SetupDefaultTrees(layer_bounds); | 2384 SetupDefaultTrees(layer_bounds); |
2385 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); | 2385 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); |
2386 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 2386 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
(...skipping 2110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4497 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); | 4497 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); |
4498 | 4498 |
4499 host_impl_.SetViewportSize(layer_bounds); | 4499 host_impl_.SetViewportSize(layer_bounds); |
4500 | 4500 |
4501 int frame_number = 0; | 4501 int frame_number = 0; |
4502 | 4502 |
4503 client.set_fill_with_nonsolid_color(!test_for_solid); | 4503 client.set_fill_with_nonsolid_color(!test_for_solid); |
4504 | 4504 |
4505 Region invalidation(layer_rect); | 4505 Region invalidation(layer_rect); |
4506 recording_source->UpdateAndExpandInvalidation( | 4506 recording_source->UpdateAndExpandInvalidation( |
4507 &client, &invalidation, layer_bounds, layer_rect, frame_number++, | 4507 &client, &invalidation, false, layer_bounds, layer_rect, frame_number++, |
4508 Picture::RECORD_NORMALLY); | 4508 Picture::RECORD_NORMALLY); |
4509 | 4509 |
4510 scoped_refptr<RasterSource> pending_raster_source = | 4510 scoped_refptr<RasterSource> pending_raster_source = |
4511 recording_source->CreateRasterSource(); | 4511 recording_source->CreateRasterSource(); |
4512 | 4512 |
4513 SetupPendingTree(pending_raster_source); | 4513 SetupPendingTree(pending_raster_source); |
4514 ActivateTree(); | 4514 ActivateTree(); |
4515 | 4515 |
4516 active_layer_->set_fixed_tile_size(tile_size); | 4516 active_layer_->set_fixed_tile_size(tile_size); |
4517 host_impl_.active_tree()->UpdateDrawProperties(); | 4517 host_impl_.active_tree()->UpdateDrawProperties(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4564 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); | 4564 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); |
4565 | 4565 |
4566 host_impl_.SetViewportSize(layer_bounds); | 4566 host_impl_.SetViewportSize(layer_bounds); |
4567 | 4567 |
4568 int frame_number = 0; | 4568 int frame_number = 0; |
4569 | 4569 |
4570 client.set_fill_with_nonsolid_color(true); | 4570 client.set_fill_with_nonsolid_color(true); |
4571 | 4571 |
4572 Region invalidation1(layer_rect); | 4572 Region invalidation1(layer_rect); |
4573 recording_source->UpdateAndExpandInvalidation( | 4573 recording_source->UpdateAndExpandInvalidation( |
4574 &client, &invalidation1, layer_bounds, layer_rect, frame_number++, | 4574 &client, &invalidation1, false, layer_bounds, layer_rect, frame_number++, |
4575 Picture::RECORD_NORMALLY); | 4575 Picture::RECORD_NORMALLY); |
4576 | 4576 |
4577 scoped_refptr<RasterSource> raster_source1 = | 4577 scoped_refptr<RasterSource> raster_source1 = |
4578 recording_source->CreateRasterSource(); | 4578 recording_source->CreateRasterSource(); |
4579 | 4579 |
4580 SetupPendingTree(raster_source1); | 4580 SetupPendingTree(raster_source1); |
4581 ActivateTree(); | 4581 ActivateTree(); |
4582 host_impl_.active_tree()->UpdateDrawProperties(); | 4582 host_impl_.active_tree()->UpdateDrawProperties(); |
4583 | 4583 |
4584 // We've started with a solid layer that contains some tilings. | 4584 // We've started with a solid layer that contains some tilings. |
4585 ASSERT_TRUE(active_layer_->tilings()); | 4585 ASSERT_TRUE(active_layer_->tilings()); |
4586 EXPECT_NE(0u, active_layer_->tilings()->num_tilings()); | 4586 EXPECT_NE(0u, active_layer_->tilings()->num_tilings()); |
4587 | 4587 |
4588 client.set_fill_with_nonsolid_color(false); | 4588 client.set_fill_with_nonsolid_color(false); |
4589 | 4589 |
4590 Region invalidation2(layer_rect); | 4590 Region invalidation2(layer_rect); |
4591 recording_source->UpdateAndExpandInvalidation( | 4591 recording_source->UpdateAndExpandInvalidation( |
4592 &client, &invalidation2, layer_bounds, layer_rect, frame_number++, | 4592 &client, &invalidation2, false, layer_bounds, layer_rect, frame_number++, |
4593 Picture::RECORD_NORMALLY); | 4593 Picture::RECORD_NORMALLY); |
4594 | 4594 |
4595 scoped_refptr<RasterSource> raster_source2 = | 4595 scoped_refptr<RasterSource> raster_source2 = |
4596 recording_source->CreateRasterSource(); | 4596 recording_source->CreateRasterSource(); |
4597 | 4597 |
4598 SetupPendingTree(raster_source2); | 4598 SetupPendingTree(raster_source2); |
4599 ActivateTree(); | 4599 ActivateTree(); |
4600 | 4600 |
4601 // We've switched to a solid color, so we should end up with no tilings. | 4601 // We've switched to a solid color, so we should end up with no tilings. |
4602 ASSERT_TRUE(active_layer_->tilings()); | 4602 ASSERT_TRUE(active_layer_->tilings()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4722 result = layer->CalculateTileSize(gfx::Size(447, 400)); | 4722 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
4723 EXPECT_EQ(result.width(), 448); | 4723 EXPECT_EQ(result.width(), 448); |
4724 EXPECT_EQ(result.height(), 448); | 4724 EXPECT_EQ(result.height(), 448); |
4725 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 4725 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
4726 EXPECT_EQ(result.width(), 512); | 4726 EXPECT_EQ(result.width(), 512); |
4727 EXPECT_EQ(result.height(), 500 + 2); | 4727 EXPECT_EQ(result.height(), 500 + 2); |
4728 } | 4728 } |
4729 | 4729 |
4730 } // namespace | 4730 } // namespace |
4731 } // namespace cc | 4731 } // namespace cc |
OLD | NEW |