OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 2307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2318 scoped_refptr<FakeContentLayer> child_layer1_; | 2318 scoped_refptr<FakeContentLayer> child_layer1_; |
2319 scoped_refptr<FakeContentLayer> child_layer2_; | 2319 scoped_refptr<FakeContentLayer> child_layer2_; |
2320 int num_commits_; | 2320 int num_commits_; |
2321 }; | 2321 }; |
2322 | 2322 |
2323 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( | 2323 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |
2324 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); | 2324 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); |
2325 | 2325 |
2326 class LayerTreeHostTestLCDChange : public LayerTreeHostTest { | 2326 class LayerTreeHostTestLCDChange : public LayerTreeHostTest { |
2327 public: | 2327 public: |
2328 class PaintClient : public FakeContentLayerClient { | |
2329 public: | |
2330 PaintClient() : paint_count_(0) {} | |
2331 | |
2332 int paint_count() const { return paint_count_; } | |
2333 | |
2334 void PaintContents(SkCanvas* canvas, | |
2335 const gfx::Rect& clip, | |
2336 PaintingControlSetting picture_control) override { | |
2337 FakeContentLayerClient::PaintContents(canvas, clip, picture_control); | |
2338 ++paint_count_; | |
2339 } | |
2340 | |
2341 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | |
2342 const gfx::Rect& clip, | |
2343 PaintingControlSetting picture_control) override { | |
2344 NOTIMPLEMENTED(); | |
2345 return DisplayItemList::Create(); | |
2346 } | |
2347 | |
2348 bool FillsBoundsCompletely() const override { return false; } | |
2349 | |
2350 private: | |
2351 int paint_count_; | |
2352 }; | |
2353 | |
2354 void SetupTree() override { | 2328 void SetupTree() override { |
2355 num_tiles_rastered_ = 0; | 2329 num_tiles_rastered_ = 0; |
2356 | 2330 |
2357 scoped_refptr<Layer> root_layer; | 2331 scoped_refptr<Layer> root_layer = PictureLayer::Create(&client_); |
2358 if (layer_tree_host()->settings().impl_side_painting) | |
2359 root_layer = PictureLayer::Create(&client_); | |
2360 else | |
2361 root_layer = ContentLayer::Create(&client_); | |
2362 client_.set_fill_with_nonsolid_color(true); | 2332 client_.set_fill_with_nonsolid_color(true); |
2363 root_layer->SetIsDrawable(true); | 2333 root_layer->SetIsDrawable(true); |
2364 root_layer->SetBounds(gfx::Size(10, 10)); | 2334 root_layer->SetBounds(gfx::Size(10, 10)); |
2365 root_layer->SetContentsOpaque(true); | 2335 root_layer->SetContentsOpaque(true); |
2366 | 2336 |
2367 layer_tree_host()->SetRootLayer(root_layer); | 2337 layer_tree_host()->SetRootLayer(root_layer); |
2368 | 2338 |
2369 // The expecations are based on the assumption that the default | 2339 // The expectations are based on the assumption that the default |
2370 // LCD settings are: | 2340 // LCD settings are: |
2371 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); | 2341 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); |
2372 EXPECT_FALSE(root_layer->can_use_lcd_text()); | |
2373 | 2342 |
2374 LayerTreeHostTest::SetupTree(); | 2343 LayerTreeHostTest::SetupTree(); |
2375 } | 2344 } |
2376 | 2345 |
2377 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 2346 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
2378 | 2347 |
2379 void DidCommitAndDrawFrame() override { | 2348 void DidCommitAndDrawFrame() override { |
2380 switch (layer_tree_host()->source_frame_number()) { | 2349 switch (layer_tree_host()->source_frame_number()) { |
2381 case 1: | 2350 case 1: |
2382 // The first update consists of a paint of the whole layer. | |
2383 EXPECT_EQ(1, client_.paint_count()); | |
2384 // LCD text must have been enabled on the layer. | |
2385 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | |
2386 PostSetNeedsCommitToMainThread(); | 2351 PostSetNeedsCommitToMainThread(); |
2387 break; | 2352 break; |
2388 case 2: | 2353 case 2: |
2389 // Since nothing changed on layer, there should be no paint. | |
2390 EXPECT_EQ(1, client_.paint_count()); | |
2391 // LCD text must not have changed. | |
2392 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | |
2393 // Change layer opacity that should trigger lcd change. | 2354 // Change layer opacity that should trigger lcd change. |
2394 layer_tree_host()->root_layer()->SetOpacity(.5f); | 2355 layer_tree_host()->root_layer()->SetOpacity(.5f); |
2395 break; | 2356 break; |
2396 case 3: | 2357 case 3: |
2397 // LCD text doesn't require re-recording, so no painting should occur. | |
2398 EXPECT_EQ(1, client_.paint_count()); | |
2399 // LCD text must have been disabled on the layer due to opacity. | |
2400 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); | |
2401 // Change layer opacity that should not trigger lcd change. | 2358 // Change layer opacity that should not trigger lcd change. |
2402 layer_tree_host()->root_layer()->SetOpacity(1.f); | 2359 layer_tree_host()->root_layer()->SetOpacity(1.f); |
2403 break; | 2360 break; |
2404 case 4: | 2361 case 4: |
2405 // LCD text doesn't require re-recording, so no painting should occur. | |
2406 EXPECT_EQ(1, client_.paint_count()); | |
2407 // Even though LCD text could be allowed. | |
2408 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | |
2409 EndTest(); | 2362 EndTest(); |
2410 break; | 2363 break; |
2411 } | 2364 } |
2412 } | 2365 } |
2413 | 2366 |
2414 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, | 2367 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, |
2415 const Tile* tile) override { | 2368 const Tile* tile) override { |
2416 ++num_tiles_rastered_; | 2369 ++num_tiles_rastered_; |
2417 } | 2370 } |
2418 | 2371 |
2419 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 2372 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 2373 PictureLayerImpl* root_layer = |
| 2374 static_cast<PictureLayerImpl*>(host_impl->active_tree()->root_layer()); |
| 2375 bool can_use_lcd_text = |
| 2376 host_impl->active_tree()->root_layer()->can_use_lcd_text(); |
2420 switch (host_impl->active_tree()->source_frame_number()) { | 2377 switch (host_impl->active_tree()->source_frame_number()) { |
2421 case 0: | 2378 case 0: |
2422 // The first draw. | 2379 // The first draw. |
2423 EXPECT_EQ(1, num_tiles_rastered_); | 2380 EXPECT_EQ(1, num_tiles_rastered_); |
| 2381 EXPECT_TRUE(can_use_lcd_text); |
| 2382 EXPECT_TRUE(root_layer->RasterSourceUsesLCDText()); |
2424 break; | 2383 break; |
2425 case 1: | 2384 case 1: |
2426 // Nothing changed on the layer. | 2385 // Nothing changed on the layer. |
2427 EXPECT_EQ(1, num_tiles_rastered_); | 2386 EXPECT_EQ(1, num_tiles_rastered_); |
| 2387 EXPECT_TRUE(can_use_lcd_text); |
| 2388 EXPECT_TRUE(root_layer->RasterSourceUsesLCDText()); |
2428 break; | 2389 break; |
2429 case 2: | 2390 case 2: |
2430 // LCD text was disabled, it should be re-rastered with LCD text off. | 2391 // LCD text was disabled; it should be re-rastered with LCD text off. |
2431 EXPECT_EQ(2, num_tiles_rastered_); | 2392 EXPECT_EQ(2, num_tiles_rastered_); |
| 2393 EXPECT_FALSE(can_use_lcd_text); |
| 2394 EXPECT_FALSE(root_layer->RasterSourceUsesLCDText()); |
2432 break; | 2395 break; |
2433 case 3: | 2396 case 3: |
2434 // LCD text was enabled but it's sticky and stays off. | 2397 // LCD text was enabled, but it's sticky and stays off. |
2435 EXPECT_EQ(2, num_tiles_rastered_); | 2398 EXPECT_EQ(2, num_tiles_rastered_); |
| 2399 EXPECT_TRUE(can_use_lcd_text); |
| 2400 EXPECT_FALSE(root_layer->RasterSourceUsesLCDText()); |
2436 break; | 2401 break; |
2437 } | 2402 } |
2438 } | 2403 } |
2439 | 2404 |
2440 void AfterTest() override {} | 2405 void AfterTest() override {} |
2441 | 2406 |
2442 private: | 2407 private: |
2443 PaintClient client_; | 2408 FakeContentLayerClient client_; |
2444 int num_tiles_rastered_; | 2409 int num_tiles_rastered_; |
2445 }; | 2410 }; |
2446 | 2411 |
2447 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLCDChange); | 2412 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLCDChange); |
2448 | 2413 |
2449 // Verify that the BeginFrame notification is used to initiate rendering. | 2414 // Verify that the BeginFrame notification is used to initiate rendering. |
2450 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { | 2415 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { |
2451 public: | 2416 public: |
2452 void InitializeSettings(LayerTreeSettings* settings) override { | 2417 void InitializeSettings(LayerTreeSettings* settings) override { |
2453 settings->use_external_begin_frame_source = true; | 2418 settings->use_external_begin_frame_source = true; |
(...skipping 3860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6314 | 6279 |
6315 void AfterTest() override { EXPECT_TRUE(did_commit_); } | 6280 void AfterTest() override { EXPECT_TRUE(did_commit_); } |
6316 | 6281 |
6317 private: | 6282 private: |
6318 bool did_commit_; | 6283 bool did_commit_; |
6319 }; | 6284 }; |
6320 | 6285 |
6321 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); | 6286 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); |
6322 | 6287 |
6323 } // namespace cc | 6288 } // namespace cc |
OLD | NEW |