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 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1088 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } | 1088 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } |
1089 | 1089 |
1090 void PaintContents( | 1090 void PaintContents( |
1091 SkCanvas* canvas, | 1091 SkCanvas* canvas, |
1092 const gfx::Rect& clip, | 1092 const gfx::Rect& clip, |
1093 ContentLayerClient::GraphicsContextStatus gc_status) override { | 1093 ContentLayerClient::GraphicsContextStatus gc_status) override { |
1094 // Set layer opacity to 0. | 1094 // Set layer opacity to 0. |
1095 if (test_layer_) | 1095 if (test_layer_) |
1096 test_layer_->SetOpacity(0.f); | 1096 test_layer_->SetOpacity(0.f); |
1097 } | 1097 } |
1098 void DidChangeLayerCanUseLCDText() override {} | |
1099 bool FillsBoundsCompletely() const override { return false; } | 1098 bool FillsBoundsCompletely() const override { return false; } |
1100 | 1099 |
1101 private: | 1100 private: |
1102 Layer* test_layer_; | 1101 Layer* test_layer_; |
1103 }; | 1102 }; |
1104 | 1103 |
1105 class ContentLayerWithUpdateTracking : public ContentLayer { | 1104 class ContentLayerWithUpdateTracking : public ContentLayer { |
1106 public: | 1105 public: |
1107 static scoped_refptr<ContentLayerWithUpdateTracking> Create( | 1106 static scoped_refptr<ContentLayerWithUpdateTracking> Create( |
1108 ContentLayerClient* client) { | 1107 ContentLayerClient* client) { |
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2273 FakeContentLayerClient client_; | 2272 FakeContentLayerClient client_; |
2274 scoped_refptr<FakeContentLayer> root_layer_; | 2273 scoped_refptr<FakeContentLayer> root_layer_; |
2275 scoped_refptr<FakeContentLayer> child_layer1_; | 2274 scoped_refptr<FakeContentLayer> child_layer1_; |
2276 scoped_refptr<FakeContentLayer> child_layer2_; | 2275 scoped_refptr<FakeContentLayer> child_layer2_; |
2277 int num_commits_; | 2276 int num_commits_; |
2278 }; | 2277 }; |
2279 | 2278 |
2280 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( | 2279 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |
2281 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); | 2280 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); |
2282 | 2281 |
2283 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { | 2282 class LayerTreeHostTestLcdChange : public LayerTreeHostTest { |
2284 public: | 2283 public: |
2285 class NotificationClient : public ContentLayerClient { | 2284 class PaintClient : public FakeContentLayerClient { |
2286 public: | 2285 public: |
2287 NotificationClient() | 2286 PaintClient() : paint_count_(0) {} |
2288 : layer_(0), paint_count_(0), lcd_notification_count_(0) {} | |
2289 | 2287 |
2290 void set_layer(Layer* layer) { layer_ = layer; } | |
2291 int paint_count() const { return paint_count_; } | 2288 int paint_count() const { return paint_count_; } |
2292 int lcd_notification_count() const { return lcd_notification_count_; } | |
2293 | 2289 |
2294 void PaintContents( | 2290 void PaintContents( |
2295 SkCanvas* canvas, | 2291 SkCanvas* canvas, |
2296 const gfx::Rect& clip, | 2292 const gfx::Rect& clip, |
2297 ContentLayerClient::GraphicsContextStatus gc_status) override { | 2293 ContentLayerClient::GraphicsContextStatus gc_status) override { |
2294 FakeContentLayerClient::PaintContents(canvas, clip, gc_status); | |
2298 ++paint_count_; | 2295 ++paint_count_; |
2299 } | 2296 } |
2300 void DidChangeLayerCanUseLCDText() override { | 2297 |
2301 ++lcd_notification_count_; | |
2302 layer_->SetNeedsDisplay(); | |
2303 } | |
2304 bool FillsBoundsCompletely() const override { return false; } | 2298 bool FillsBoundsCompletely() const override { return false; } |
2305 | 2299 |
2306 private: | 2300 private: |
2307 Layer* layer_; | |
2308 int paint_count_; | 2301 int paint_count_; |
2309 int lcd_notification_count_; | |
2310 }; | 2302 }; |
2311 | 2303 |
2312 void SetupTree() override { | 2304 void SetupTree() override { |
2305 num_tiles_rastered_ = 0; | |
2306 | |
2313 scoped_refptr<Layer> root_layer; | 2307 scoped_refptr<Layer> root_layer; |
2314 if (layer_tree_host()->settings().impl_side_painting) | 2308 if (layer_tree_host()->settings().impl_side_painting) |
2315 root_layer = PictureLayer::Create(&client_); | 2309 root_layer = PictureLayer::Create(&client_); |
2316 else | 2310 else |
2317 root_layer = ContentLayer::Create(&client_); | 2311 root_layer = ContentLayer::Create(&client_); |
2312 client_.set_fill_with_nonsolid_color(true); | |
2318 root_layer->SetIsDrawable(true); | 2313 root_layer->SetIsDrawable(true); |
2319 root_layer->SetBounds(gfx::Size(1, 1)); | 2314 root_layer->SetBounds(gfx::Size(10, 10)); |
2320 | 2315 |
2321 layer_tree_host()->SetRootLayer(root_layer); | 2316 layer_tree_host()->SetRootLayer(root_layer); |
2322 client_.set_layer(root_layer.get()); | |
2323 | 2317 |
2324 // The expecations are based on the assumption that the default | 2318 // The expecations are based on the assumption that the default |
2325 // LCD settings are: | 2319 // LCD settings are: |
2326 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); | 2320 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); |
2327 EXPECT_FALSE(root_layer->can_use_lcd_text()); | 2321 EXPECT_FALSE(root_layer->can_use_lcd_text()); |
2328 | 2322 |
2329 LayerTreeHostTest::SetupTree(); | 2323 LayerTreeHostTest::SetupTree(); |
2330 } | 2324 } |
2331 | 2325 |
2332 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 2326 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
2333 void AfterTest() override {} | |
2334 | 2327 |
2335 void DidCommit() override { | 2328 void DidCommitAndDrawFrame() override { |
2336 switch (layer_tree_host()->source_frame_number()) { | 2329 switch (layer_tree_host()->source_frame_number()) { |
2337 case 1: | 2330 case 1: |
2338 // The first update consists of one LCD notification and one paint. | 2331 // The first update consists of a paint of the whole layer. |
2339 EXPECT_EQ(1, client_.lcd_notification_count()); | |
2340 EXPECT_EQ(1, client_.paint_count()); | 2332 EXPECT_EQ(1, client_.paint_count()); |
2341 // LCD text must have been enabled on the layer. | 2333 // LCD text must have been enabled on the layer. |
2342 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2334 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2343 PostSetNeedsCommitToMainThread(); | 2335 PostSetNeedsCommitToMainThread(); |
2344 break; | 2336 break; |
2345 case 2: | 2337 case 2: |
2346 // Since nothing changed on layer, there should be no notification | 2338 // Since nothing changed on layer, there should be no paint. |
2347 // or paint on the second update. | |
2348 EXPECT_EQ(1, client_.lcd_notification_count()); | |
2349 EXPECT_EQ(1, client_.paint_count()); | 2339 EXPECT_EQ(1, client_.paint_count()); |
2350 // LCD text must not have changed. | 2340 // LCD text must not have changed. |
2351 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2341 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2352 // Change layer opacity that should trigger lcd notification. | 2342 // Change layer opacity that should trigger lcd change. |
2353 layer_tree_host()->root_layer()->SetOpacity(.5f); | 2343 layer_tree_host()->root_layer()->SetOpacity(.5f); |
2354 // No need to request a commit - setting opacity will do it. | |
2355 break; | 2344 break; |
2356 default: | 2345 case 3: |
2357 // Verify that there is no extra commit due to layer invalidation. | 2346 // LCD text doesn't require re-recording, so no painting should occur. |
2358 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); | 2347 EXPECT_EQ(1, client_.paint_count()); |
2359 // LCD notification count should have incremented due to | |
2360 // change in layer opacity. | |
2361 EXPECT_EQ(2, client_.lcd_notification_count()); | |
2362 // Paint count should be incremented due to invalidation. | |
2363 EXPECT_EQ(2, client_.paint_count()); | |
2364 // LCD text must have been disabled on the layer due to opacity. | 2348 // LCD text must have been disabled on the layer due to opacity. |
2365 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2349 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2350 // Change layer opacity that should not trigger lcd change. | |
2351 layer_tree_host()->root_layer()->SetOpacity(1.f); | |
2352 break; | |
2353 case 4: | |
2354 // LCD text doesn't require re-recording, so no painting should occur. | |
2355 EXPECT_EQ(1, client_.paint_count()); | |
2356 // Even though LCD text could be allowed. | |
2357 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | |
2366 EndTest(); | 2358 EndTest(); |
2367 break; | 2359 break; |
2368 } | 2360 } |
2369 } | 2361 } |
2370 | 2362 |
2363 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, | |
2364 const Tile* tile) override { | |
2365 ++num_tiles_rastered_; | |
2366 } | |
2367 | |
2368 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
2369 switch (host_impl->active_tree()->source_frame_number()) { | |
2370 case 0: | |
2371 // The first draw. | |
2372 EXPECT_EQ(1, num_tiles_rastered_); | |
2373 break; | |
2374 case 1: | |
2375 // Nothing changed on the layer. | |
2376 EXPECT_EQ(1, num_tiles_rastered_); | |
2377 break; | |
2378 case 2: | |
2379 // LCD text was disabled, it should be re-rastered with LCD text off. | |
2380 EXPECT_EQ(2, num_tiles_rastered_); | |
2381 break; | |
2382 case 3: | |
2383 // LCD text was enabled but it's sticky and stays off. | |
2384 EXPECT_EQ(2, num_tiles_rastered_); | |
2385 break; | |
2386 } | |
2387 } | |
2388 | |
2389 void AfterTest() override {} | |
2390 | |
2371 private: | 2391 private: |
2372 NotificationClient client_; | 2392 PaintClient client_; |
2393 int num_tiles_rastered_; | |
2373 }; | 2394 }; |
2374 | 2395 |
2375 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDNotification); | 2396 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLcdChange); |
enne (OOO)
2014/11/14 00:05:45
Nice try, but Lcd => LCD
$ git grep Lcd cc | wc -
| |
2376 | 2397 |
2377 // Verify that the BeginFrame notification is used to initiate rendering. | 2398 // Verify that the BeginFrame notification is used to initiate rendering. |
2378 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { | 2399 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { |
2379 public: | 2400 public: |
2380 void InitializeSettings(LayerTreeSettings* settings) override { | 2401 void InitializeSettings(LayerTreeSettings* settings) override { |
2381 settings->use_external_begin_frame_source = true; | 2402 settings->use_external_begin_frame_source = true; |
2382 } | 2403 } |
2383 | 2404 |
2384 void BeginTest() override { | 2405 void BeginTest() override { |
2385 // This will trigger a SetNeedsBeginFrame which will trigger a | 2406 // This will trigger a SetNeedsBeginFrame which will trigger a |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2536 | 2557 |
2537 void set_layer(Layer* layer) { layer_ = layer; } | 2558 void set_layer(Layer* layer) { layer_ = layer; } |
2538 | 2559 |
2539 void PaintContents( | 2560 void PaintContents( |
2540 SkCanvas* canvas, | 2561 SkCanvas* canvas, |
2541 const gfx::Rect& clip, | 2562 const gfx::Rect& clip, |
2542 ContentLayerClient::GraphicsContextStatus gc_status) override { | 2563 ContentLayerClient::GraphicsContextStatus gc_status) override { |
2543 layer_->SetBounds(gfx::Size(2, 2)); | 2564 layer_->SetBounds(gfx::Size(2, 2)); |
2544 } | 2565 } |
2545 | 2566 |
2546 void DidChangeLayerCanUseLCDText() override {} | |
2547 | |
2548 bool FillsBoundsCompletely() const override { return false; } | 2567 bool FillsBoundsCompletely() const override { return false; } |
2549 | 2568 |
2550 private: | 2569 private: |
2551 Layer* layer_; | 2570 Layer* layer_; |
2552 }; | 2571 }; |
2553 | 2572 |
2554 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} | 2573 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} |
2555 | 2574 |
2556 void SetupTree() override { | 2575 void SetupTree() override { |
2557 if (layer_tree_host()->settings().impl_side_painting) { | 2576 if (layer_tree_host()->settings().impl_side_painting) { |
(...skipping 3143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5701 | 5720 |
5702 FakeContentLayerClient client_; | 5721 FakeContentLayerClient client_; |
5703 int step_; | 5722 int step_; |
5704 int continuous_draws_; | 5723 int continuous_draws_; |
5705 base::WaitableEvent playback_allowed_event_; | 5724 base::WaitableEvent playback_allowed_event_; |
5706 }; | 5725 }; |
5707 | 5726 |
5708 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles); | 5727 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles); |
5709 | 5728 |
5710 } // namespace cc | 5729 } // namespace cc |
OLD | NEW |