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 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } | 1107 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } |
1108 | 1108 |
1109 void PaintContents( | 1109 void PaintContents( |
1110 SkCanvas* canvas, | 1110 SkCanvas* canvas, |
1111 const gfx::Rect& clip, | 1111 const gfx::Rect& clip, |
1112 ContentLayerClient::GraphicsContextStatus gc_status) override { | 1112 ContentLayerClient::GraphicsContextStatus gc_status) override { |
1113 // Set layer opacity to 0. | 1113 // Set layer opacity to 0. |
1114 if (test_layer_) | 1114 if (test_layer_) |
1115 test_layer_->SetOpacity(0.f); | 1115 test_layer_->SetOpacity(0.f); |
1116 } | 1116 } |
| 1117 void DidChangeLayerCanUseLCDText() override {} |
1117 bool FillsBoundsCompletely() const override { return false; } | 1118 bool FillsBoundsCompletely() const override { return false; } |
1118 | 1119 |
1119 private: | 1120 private: |
1120 Layer* test_layer_; | 1121 Layer* test_layer_; |
1121 }; | 1122 }; |
1122 | 1123 |
1123 class ContentLayerWithUpdateTracking : public ContentLayer { | 1124 class ContentLayerWithUpdateTracking : public ContentLayer { |
1124 public: | 1125 public: |
1125 static scoped_refptr<ContentLayerWithUpdateTracking> Create( | 1126 static scoped_refptr<ContentLayerWithUpdateTracking> Create( |
1126 ContentLayerClient* client) { | 1127 ContentLayerClient* client) { |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 FakeContentLayerClient client_; | 2301 FakeContentLayerClient client_; |
2301 scoped_refptr<FakeContentLayer> root_layer_; | 2302 scoped_refptr<FakeContentLayer> root_layer_; |
2302 scoped_refptr<FakeContentLayer> child_layer1_; | 2303 scoped_refptr<FakeContentLayer> child_layer1_; |
2303 scoped_refptr<FakeContentLayer> child_layer2_; | 2304 scoped_refptr<FakeContentLayer> child_layer2_; |
2304 int num_commits_; | 2305 int num_commits_; |
2305 }; | 2306 }; |
2306 | 2307 |
2307 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( | 2308 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |
2308 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); | 2309 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); |
2309 | 2310 |
2310 class LayerTreeHostTestLCDChange : public LayerTreeHostTest { | 2311 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { |
2311 public: | 2312 public: |
2312 class PaintClient : public FakeContentLayerClient { | 2313 class NotificationClient : public ContentLayerClient { |
2313 public: | 2314 public: |
2314 PaintClient() : paint_count_(0) {} | 2315 NotificationClient() |
| 2316 : layer_(0), paint_count_(0), lcd_notification_count_(0) {} |
2315 | 2317 |
| 2318 void set_layer(Layer* layer) { layer_ = layer; } |
2316 int paint_count() const { return paint_count_; } | 2319 int paint_count() const { return paint_count_; } |
| 2320 int lcd_notification_count() const { return lcd_notification_count_; } |
2317 | 2321 |
2318 void PaintContents( | 2322 void PaintContents( |
2319 SkCanvas* canvas, | 2323 SkCanvas* canvas, |
2320 const gfx::Rect& clip, | 2324 const gfx::Rect& clip, |
2321 ContentLayerClient::GraphicsContextStatus gc_status) override { | 2325 ContentLayerClient::GraphicsContextStatus gc_status) override { |
2322 FakeContentLayerClient::PaintContents(canvas, clip, gc_status); | |
2323 ++paint_count_; | 2326 ++paint_count_; |
2324 } | 2327 } |
2325 | 2328 void DidChangeLayerCanUseLCDText() override { |
| 2329 ++lcd_notification_count_; |
| 2330 layer_->SetNeedsDisplay(); |
| 2331 } |
2326 bool FillsBoundsCompletely() const override { return false; } | 2332 bool FillsBoundsCompletely() const override { return false; } |
2327 | 2333 |
2328 private: | 2334 private: |
| 2335 Layer* layer_; |
2329 int paint_count_; | 2336 int paint_count_; |
| 2337 int lcd_notification_count_; |
2330 }; | 2338 }; |
2331 | 2339 |
2332 void SetupTree() override { | 2340 void SetupTree() override { |
2333 num_tiles_rastered_ = 0; | |
2334 | |
2335 scoped_refptr<Layer> root_layer; | 2341 scoped_refptr<Layer> root_layer; |
2336 if (layer_tree_host()->settings().impl_side_painting) | 2342 if (layer_tree_host()->settings().impl_side_painting) |
2337 root_layer = PictureLayer::Create(&client_); | 2343 root_layer = PictureLayer::Create(&client_); |
2338 else | 2344 else |
2339 root_layer = ContentLayer::Create(&client_); | 2345 root_layer = ContentLayer::Create(&client_); |
2340 client_.set_fill_with_nonsolid_color(true); | |
2341 root_layer->SetIsDrawable(true); | 2346 root_layer->SetIsDrawable(true); |
2342 root_layer->SetBounds(gfx::Size(10, 10)); | 2347 root_layer->SetBounds(gfx::Size(1, 1)); |
2343 | 2348 |
2344 layer_tree_host()->SetRootLayer(root_layer); | 2349 layer_tree_host()->SetRootLayer(root_layer); |
| 2350 client_.set_layer(root_layer.get()); |
2345 | 2351 |
2346 // The expecations are based on the assumption that the default | 2352 // The expecations are based on the assumption that the default |
2347 // LCD settings are: | 2353 // LCD settings are: |
2348 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); | 2354 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); |
2349 EXPECT_FALSE(root_layer->can_use_lcd_text()); | 2355 EXPECT_FALSE(root_layer->can_use_lcd_text()); |
2350 | 2356 |
2351 LayerTreeHostTest::SetupTree(); | 2357 LayerTreeHostTest::SetupTree(); |
2352 } | 2358 } |
2353 | 2359 |
2354 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 2360 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 2361 void AfterTest() override {} |
2355 | 2362 |
2356 void DidCommitAndDrawFrame() override { | 2363 void DidCommit() override { |
2357 switch (layer_tree_host()->source_frame_number()) { | 2364 switch (layer_tree_host()->source_frame_number()) { |
2358 case 1: | 2365 case 1: |
2359 // The first update consists of a paint of the whole layer. | 2366 // The first update consists of one LCD notification and one paint. |
| 2367 EXPECT_EQ(1, client_.lcd_notification_count()); |
2360 EXPECT_EQ(1, client_.paint_count()); | 2368 EXPECT_EQ(1, client_.paint_count()); |
2361 // LCD text must have been enabled on the layer. | 2369 // LCD text must have been enabled on the layer. |
2362 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2370 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2363 PostSetNeedsCommitToMainThread(); | 2371 PostSetNeedsCommitToMainThread(); |
2364 break; | 2372 break; |
2365 case 2: | 2373 case 2: |
2366 // Since nothing changed on layer, there should be no paint. | 2374 // Since nothing changed on layer, there should be no notification |
| 2375 // or paint on the second update. |
| 2376 EXPECT_EQ(1, client_.lcd_notification_count()); |
2367 EXPECT_EQ(1, client_.paint_count()); | 2377 EXPECT_EQ(1, client_.paint_count()); |
2368 // LCD text must not have changed. | 2378 // LCD text must not have changed. |
2369 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2379 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2370 // Change layer opacity that should trigger lcd change. | 2380 // Change layer opacity that should trigger lcd notification. |
2371 layer_tree_host()->root_layer()->SetOpacity(.5f); | 2381 layer_tree_host()->root_layer()->SetOpacity(.5f); |
| 2382 // No need to request a commit - setting opacity will do it. |
2372 break; | 2383 break; |
2373 case 3: | 2384 default: |
2374 // LCD text doesn't require re-recording, so no painting should occur. | 2385 // Verify that there is no extra commit due to layer invalidation. |
2375 EXPECT_EQ(1, client_.paint_count()); | 2386 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); |
| 2387 // LCD notification count should have incremented due to |
| 2388 // change in layer opacity. |
| 2389 EXPECT_EQ(2, client_.lcd_notification_count()); |
| 2390 // Paint count should be incremented due to invalidation. |
| 2391 EXPECT_EQ(2, client_.paint_count()); |
2376 // LCD text must have been disabled on the layer due to opacity. | 2392 // LCD text must have been disabled on the layer due to opacity. |
2377 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2393 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2378 // Change layer opacity that should not trigger lcd change. | |
2379 layer_tree_host()->root_layer()->SetOpacity(1.f); | |
2380 break; | |
2381 case 4: | |
2382 // LCD text doesn't require re-recording, so no painting should occur. | |
2383 EXPECT_EQ(1, client_.paint_count()); | |
2384 // Even though LCD text could be allowed. | |
2385 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | |
2386 EndTest(); | 2394 EndTest(); |
2387 break; | 2395 break; |
2388 } | 2396 } |
2389 } | 2397 } |
2390 | 2398 |
2391 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, | |
2392 const Tile* tile) override { | |
2393 ++num_tiles_rastered_; | |
2394 } | |
2395 | |
2396 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
2397 switch (host_impl->active_tree()->source_frame_number()) { | |
2398 case 0: | |
2399 // The first draw. | |
2400 EXPECT_EQ(1, num_tiles_rastered_); | |
2401 break; | |
2402 case 1: | |
2403 // Nothing changed on the layer. | |
2404 EXPECT_EQ(1, num_tiles_rastered_); | |
2405 break; | |
2406 case 2: | |
2407 // LCD text was disabled, it should be re-rastered with LCD text off. | |
2408 EXPECT_EQ(2, num_tiles_rastered_); | |
2409 break; | |
2410 case 3: | |
2411 // LCD text was enabled but it's sticky and stays off. | |
2412 EXPECT_EQ(2, num_tiles_rastered_); | |
2413 break; | |
2414 } | |
2415 } | |
2416 | |
2417 void AfterTest() override {} | |
2418 | |
2419 private: | 2399 private: |
2420 PaintClient client_; | 2400 NotificationClient client_; |
2421 int num_tiles_rastered_; | |
2422 }; | 2401 }; |
2423 | 2402 |
2424 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLCDChange); | 2403 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDNotification); |
2425 | 2404 |
2426 // Verify that the BeginFrame notification is used to initiate rendering. | 2405 // Verify that the BeginFrame notification is used to initiate rendering. |
2427 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { | 2406 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { |
2428 public: | 2407 public: |
2429 void InitializeSettings(LayerTreeSettings* settings) override { | 2408 void InitializeSettings(LayerTreeSettings* settings) override { |
2430 settings->use_external_begin_frame_source = true; | 2409 settings->use_external_begin_frame_source = true; |
2431 } | 2410 } |
2432 | 2411 |
2433 void BeginTest() override { | 2412 void BeginTest() override { |
2434 // This will trigger a SetNeedsBeginFrame which will trigger a | 2413 // This will trigger a SetNeedsBeginFrame which will trigger a |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2585 | 2564 |
2586 void set_layer(Layer* layer) { layer_ = layer; } | 2565 void set_layer(Layer* layer) { layer_ = layer; } |
2587 | 2566 |
2588 void PaintContents( | 2567 void PaintContents( |
2589 SkCanvas* canvas, | 2568 SkCanvas* canvas, |
2590 const gfx::Rect& clip, | 2569 const gfx::Rect& clip, |
2591 ContentLayerClient::GraphicsContextStatus gc_status) override { | 2570 ContentLayerClient::GraphicsContextStatus gc_status) override { |
2592 layer_->SetBounds(gfx::Size(2, 2)); | 2571 layer_->SetBounds(gfx::Size(2, 2)); |
2593 } | 2572 } |
2594 | 2573 |
| 2574 void DidChangeLayerCanUseLCDText() override {} |
| 2575 |
2595 bool FillsBoundsCompletely() const override { return false; } | 2576 bool FillsBoundsCompletely() const override { return false; } |
2596 | 2577 |
2597 private: | 2578 private: |
2598 Layer* layer_; | 2579 Layer* layer_; |
2599 }; | 2580 }; |
2600 | 2581 |
2601 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} | 2582 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} |
2602 | 2583 |
2603 void SetupTree() override { | 2584 void SetupTree() override { |
2604 if (layer_tree_host()->settings().impl_side_painting) { | 2585 if (layer_tree_host()->settings().impl_side_painting) { |
(...skipping 3177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5782 FakeContentLayerClient client_; | 5763 FakeContentLayerClient client_; |
5783 int step_; | 5764 int step_; |
5784 int continuous_draws_; | 5765 int continuous_draws_; |
5785 bool expect_draw_; | 5766 bool expect_draw_; |
5786 base::WaitableEvent playback_allowed_event_; | 5767 base::WaitableEvent playback_allowed_event_; |
5787 }; | 5768 }; |
5788 | 5769 |
5789 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles); | 5770 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles); |
5790 | 5771 |
5791 } // namespace cc | 5772 } // namespace cc |
OLD | NEW |