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