Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: cc/layers/picture_layer_impl_unittest.cc

Issue 260963008: Fixing crash in PictureLayerImpl::MarkVisibleResourcesAsRequired when low-res tiles are disabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding missed file and fixing TileManager unit test Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 11
12 #include "cc/layers/append_quads_data.h" 12 #include "cc/layers/append_quads_data.h"
13 #include "cc/layers/picture_layer.h" 13 #include "cc/layers/picture_layer.h"
14 #include "cc/test/fake_content_layer_client.h" 14 #include "cc/test/fake_content_layer_client.h"
15 #include "cc/test/fake_impl_proxy.h" 15 #include "cc/test/fake_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host_impl.h" 16 #include "cc/test/fake_layer_tree_host_impl.h"
17 #include "cc/test/fake_layer_tree_settings.h"
17 #include "cc/test/fake_output_surface.h" 18 #include "cc/test/fake_output_surface.h"
18 #include "cc/test/fake_picture_layer_impl.h" 19 #include "cc/test/fake_picture_layer_impl.h"
19 #include "cc/test/fake_picture_pile_impl.h" 20 #include "cc/test/fake_picture_pile_impl.h"
20 #include "cc/test/geometry_test_utils.h" 21 #include "cc/test/geometry_test_utils.h"
21 #include "cc/test/impl_side_painting_settings.h" 22 #include "cc/test/impl_side_painting_settings.h"
22 #include "cc/test/layer_test_common.h" 23 #include "cc/test/layer_test_common.h"
23 #include "cc/test/mock_quad_culler.h" 24 #include "cc/test/mock_quad_culler.h"
24 #include "cc/test/test_shared_bitmap_manager.h" 25 #include "cc/test/test_shared_bitmap_manager.h"
25 #include "cc/test/test_web_graphics_context_3d.h" 26 #include "cc/test/test_web_graphics_context_3d.h"
26 #include "cc/trees/layer_tree_impl.h" 27 #include "cc/trees/layer_tree_impl.h"
(...skipping 12 matching lines...) Expand all
39 rects_.push_back(rect); 40 rects_.push_back(rect);
40 } 41 }
41 42
42 std::vector<SkRect> rects_; 43 std::vector<SkRect> rects_;
43 }; 44 };
44 45
45 class PictureLayerImplTest : public testing::Test { 46 class PictureLayerImplTest : public testing::Test {
46 public: 47 public:
47 PictureLayerImplTest() 48 PictureLayerImplTest()
48 : proxy_(base::MessageLoopProxy::current()), 49 : proxy_(base::MessageLoopProxy::current()),
49 host_impl_(ImplSidePaintingSettings(), 50 host_impl_(FakeLayerTreeSettings(),
50 &proxy_, 51 &proxy_,
51 &shared_bitmap_manager_), 52 &shared_bitmap_manager_),
52 id_(7) {} 53 id_(7) {}
53 54
54 explicit PictureLayerImplTest(const LayerTreeSettings& settings) 55 explicit PictureLayerImplTest(const LayerTreeSettings& settings)
55 : proxy_(base::MessageLoopProxy::current()), 56 : proxy_(base::MessageLoopProxy::current()),
56 host_impl_(settings, &proxy_, &shared_bitmap_manager_), 57 host_impl_(settings, &proxy_, &shared_bitmap_manager_),
57 id_(7) {} 58 id_(7) {}
58 59
59 virtual ~PictureLayerImplTest() { 60 virtual ~PictureLayerImplTest() {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 void AssertNoTilesRequired(PictureLayerTiling* tiling) { 191 void AssertNoTilesRequired(PictureLayerTiling* tiling) {
191 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 192 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
192 for (size_t i = 0; i < tiles.size(); ++i) 193 for (size_t i = 0; i < tiles.size(); ++i)
193 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i; 194 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i;
194 EXPECT_GT(tiles.size(), 0u); 195 EXPECT_GT(tiles.size(), 0u);
195 } 196 }
196 197
197 protected: 198 protected:
198 void TestTileGridAlignmentCommon() { 199 void TestTileGridAlignmentCommon() {
199 // Layer to span 4 raster tiles in x and in y 200 // Layer to span 4 raster tiles in x and in y
200 ImplSidePaintingSettings settings; 201 FakeLayerTreeSettings settings;
201 gfx::Size layer_size( 202 gfx::Size layer_size(
202 settings.default_tile_size.width() * 7 / 2, 203 settings.default_tile_size.width() * 7 / 2,
203 settings.default_tile_size.height() * 7 / 2); 204 settings.default_tile_size.height() * 7 / 2);
204 205
205 scoped_refptr<FakePicturePileImpl> pending_pile = 206 scoped_refptr<FakePicturePileImpl> pending_pile =
206 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); 207 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
207 scoped_refptr<FakePicturePileImpl> active_pile = 208 scoped_refptr<FakePicturePileImpl> active_pile =
208 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); 209 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
209 210
210 SetupTrees(pending_pile, active_pile); 211 SetupTrees(pending_pile, active_pile);
(...skipping 2061 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 impl.quad_list(), 2273 impl.quad_list(),
2273 gfx::Rect(layer_bounds), 2274 gfx::Rect(layer_bounds),
2274 occluded, 2275 occluded,
2275 &partially_occluded_count); 2276 &partially_occluded_count);
2276 // The layer outputs one quad, which is partially occluded. 2277 // The layer outputs one quad, which is partially occluded.
2277 EXPECT_EQ(100u - 10u, impl.quad_list().size()); 2278 EXPECT_EQ(100u - 10u, impl.quad_list().size());
2278 EXPECT_EQ(10u + 10u, partially_occluded_count); 2279 EXPECT_EQ(10u + 10u, partially_occluded_count);
2279 } 2280 }
2280 } 2281 }
2281 2282
2283 class NoLowResPictureLayerImplTest : public PictureLayerImplTest {
2284 public:
2285 NoLowResPictureLayerImplTest()
2286 : PictureLayerImplTest(FakeLayerTreeSettings(false))
2287 {}
2288 };
2289
2290 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) {
2291 gfx::Size tile_size(400, 400);
2292 gfx::Size layer_bounds(1300, 1900);
2293
2294 scoped_refptr<FakePicturePileImpl> pending_pile =
2295 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2296 scoped_refptr<FakePicturePileImpl> active_pile =
2297 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2298
2299 float result_scale_x, result_scale_y;
2300 gfx::Size result_bounds;
2301
2302 SetupTrees(pending_pile, active_pile);
2303 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2304
2305 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2306 EXPECT_LT(low_res_factor, 1.f);
2307
2308 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale
2309 1.7f, // device scale
2310 3.2f, // page scale
2311 1.f, // maximum animation scale
2312 false,
2313 &result_scale_x,
2314 &result_scale_y,
2315 &result_bounds);
2316 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
2317 EXPECT_FLOAT_EQ(
2318 1.3f,
2319 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2320
2321 // If we change the layer's CSS scale factor, then we should not get new
2322 // tilings.
2323 pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale
2324 1.7f, // device scale
2325 3.2f, // page scale
2326 1.f, // maximum animation scale
2327 false,
2328 &result_scale_x,
2329 &result_scale_y,
2330 &result_bounds);
2331 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
2332 EXPECT_FLOAT_EQ(
2333 1.3f,
2334 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2335
2336 // If we change the page scale factor, then we should get new tilings.
2337 pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale
2338 1.7f, // device scale
2339 2.2f, // page scale
2340 1.f, // maximum animation scale
2341 false,
2342 &result_scale_x,
2343 &result_scale_y,
2344 &result_bounds);
2345 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
2346 EXPECT_FLOAT_EQ(
2347 1.8f,
2348 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2349
2350 // If we change the device scale factor, then we should get new tilings.
2351 pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale
2352 1.4f, // device scale
2353 2.2f, // page scale
2354 1.f, // maximum animation scale
2355 false,
2356 &result_scale_x,
2357 &result_scale_y,
2358 &result_bounds);
2359 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings());
2360 EXPECT_FLOAT_EQ(
2361 1.9f,
2362 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2363
2364 // If we change the device scale factor, but end up at the same total scale
2365 // factor somehow, then we don't get new tilings.
2366 pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale
2367 2.2f, // device scale
2368 1.4f, // page scale
2369 1.f, // maximum animation scale
2370 false,
2371 &result_scale_x,
2372 &result_scale_y,
2373 &result_bounds);
2374 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings());
2375 EXPECT_FLOAT_EQ(
2376 1.9f,
2377 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2378 }
2379
2380 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) {
2381 gfx::Size tile_size(400, 400);
2382 gfx::Size layer_bounds(1300, 1900);
2383
2384 scoped_refptr<FakePicturePileImpl> pending_pile =
2385 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2386 scoped_refptr<FakePicturePileImpl> active_pile =
2387 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2388
2389 float result_scale_x, result_scale_y;
2390 gfx::Size result_bounds;
2391 std::vector<PictureLayerTiling*> used_tilings;
2392
2393 SetupTrees(pending_pile, active_pile);
2394 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2395
2396 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2397 EXPECT_LT(low_res_factor, 1.f);
2398
2399 float device_scale = 1.7f;
2400 float page_scale = 3.2f;
2401
2402 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
2403 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
2404
2405 // We only have ideal tilings, so they aren't removed.
2406 used_tilings.clear();
2407 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2408 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
2409
2410 // Changing the ideal but not creating new tilings.
2411 SetContentsScaleOnBothLayers(1.5f, device_scale, page_scale, 1.f, false);
2412 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
2413
2414 // The tilings are still our target scale, so they aren't removed.
2415 used_tilings.clear();
2416 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2417 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
2418
2419 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
2420 page_scale = 1.2f;
2421 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false);
2422 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2423 EXPECT_FLOAT_EQ(
2424 1.f,
2425 active_layer_->tilings()->tiling_at(1)->contents_scale());
2426
2427 // Mark the non-ideal tilings as used. They won't be removed.
2428 used_tilings.clear();
2429 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
2430 used_tilings.push_back(active_layer_->tilings()->tiling_at(3));
2431 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2432 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2433
2434 // Now move the ideal scale to 0.5. Our target stays 1.2.
2435 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false);
2436
2437 // The high resolution tiling is between target and ideal, so is not
2438 // removed. The low res tiling for the old ideal=1.0 scale is removed.
2439 used_tilings.clear();
2440 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2441 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2442
2443 // Now move the ideal scale to 1.0. Our target stays 1.2.
2444 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
2445
2446 // All the tilings are between are target and the ideal, so they are not
2447 // removed.
2448 used_tilings.clear();
2449 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2450 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2451
2452 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
2453 active_layer_->CalculateContentsScale(1.1f,
2454 device_scale,
2455 page_scale,
2456 1.f,
2457 false,
2458 &result_scale_x,
2459 &result_scale_y,
2460 &result_bounds);
2461
2462 // Because the pending layer's ideal scale is still 1.0, our tilings fall
2463 // in the range [1.0,1.2] and are kept.
2464 used_tilings.clear();
2465 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2466 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2467
2468 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
2469 // 1.2 still.
2470 pending_layer_->CalculateContentsScale(1.1f,
2471 device_scale,
2472 page_scale,
2473 1.f,
2474 false,
2475 &result_scale_x,
2476 &result_scale_y,
2477 &result_bounds);
2478
2479 // Our 1.0 tiling now falls outside the range between our ideal scale and our
2480 // target raster scale. But it is in our used tilings set, so nothing is
2481 // deleted.
2482 used_tilings.clear();
2483 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
2484 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2485 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2486
2487 // If we remove it from our used tilings set, it is outside the range to keep
2488 // so it is deleted.
2489 used_tilings.clear();
2490 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2491 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
2492 }
2493
2494 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) {
2495 gfx::Size tile_size(400, 400);
2496 gfx::Size layer_bounds(1300, 1900);
2497
2498 scoped_refptr<FakePicturePileImpl> pending_pile =
2499 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2500 scoped_refptr<FakePicturePileImpl> active_pile =
2501 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2502
2503 float result_scale_x, result_scale_y;
2504 gfx::Size result_bounds;
2505
2506 SetupTrees(pending_pile, active_pile);
2507 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2508
2509 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale
2510 2.7f, // device scale
2511 3.2f, // page scale
2512 1.f, // maximum animation scale
2513 false,
2514 &result_scale_x,
2515 &result_scale_y,
2516 &result_bounds);
2517 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2518
2519 // All tilings should be removed when losing output surface.
2520 active_layer_->ReleaseResources();
2521 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2522 pending_layer_->ReleaseResources();
2523 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2524
2525 // This should create new tilings.
2526 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale
2527 2.7f, // device scale
2528 3.2f, // page scale
2529 1.f, // maximum animation scale
2530 false,
2531 &result_scale_x,
2532 &result_scale_y,
2533 &result_bounds);
2534 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2535 }
2536
2282 } // namespace 2537 } // namespace
2283 } // namespace cc 2538 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698