OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "cc/layers/delegated_frame_provider.h" | 8 #include "cc/layers/delegated_frame_provider.h" |
9 #include "cc/layers/delegated_frame_resource_collection.h" | 9 #include "cc/layers/delegated_frame_resource_collection.h" |
10 #include "cc/layers/heads_up_display_layer.h" | 10 #include "cc/layers/heads_up_display_layer.h" |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 405 |
406 void CreateAndSetOutputSurface() { | 406 void CreateAndSetOutputSurface() { |
407 scoped_ptr<OutputSurface> surface = | 407 scoped_ptr<OutputSurface> surface = |
408 LayerTreeHostContextTest::CreateOutputSurface(); | 408 LayerTreeHostContextTest::CreateOutputSurface(); |
409 CHECK(surface); | 409 CHECK(surface); |
410 setos_counter_++; | 410 setos_counter_++; |
411 layer_tree_host()->SetOutputSurface(surface.Pass()); | 411 layer_tree_host()->SetOutputSurface(surface.Pass()); |
412 } | 412 } |
413 | 413 |
414 void HideAndReleaseOutputSurface() { | 414 void HideAndReleaseOutputSurface() { |
415 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 415 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
416 layer_tree_host()->SetVisible(false); | 416 layer_tree_host()->SetVisible(false); |
417 scoped_ptr<OutputSurface> surface = | 417 scoped_ptr<OutputSurface> surface = |
418 layer_tree_host()->ReleaseOutputSurface(); | 418 layer_tree_host()->ReleaseOutputSurface(); |
419 CHECK(surface); | 419 CHECK(surface); |
420 MainThreadTaskRunner()->PostTask( | 420 MainThreadTaskRunner()->PostTask( |
421 FROM_HERE, | 421 FROM_HERE, |
422 base::Bind(&LayerTreeHostClientTakeAwayOutputSurface::MakeVisible, | 422 base::Bind(&LayerTreeHostClientTakeAwayOutputSurface::MakeVisible, |
423 base::Unretained(this))); | 423 base::Unretained(this))); |
424 } | 424 } |
425 | 425 |
426 void DidInitializeOutputSurface() override { | 426 void DidInitializeOutputSurface() override { |
427 EXPECT_TRUE(layer_tree_host()->visible()); | 427 EXPECT_TRUE(layer_tree_host()->visible()); |
428 if (setos_counter_ == 1) { | 428 if (setos_counter_ == 1) { |
429 MainThreadTaskRunner()->PostTask( | 429 MainThreadTaskRunner()->PostTask( |
430 FROM_HERE, base::Bind(&LayerTreeHostClientTakeAwayOutputSurface:: | 430 FROM_HERE, base::Bind(&LayerTreeHostClientTakeAwayOutputSurface:: |
431 HideAndReleaseOutputSurface, | 431 HideAndReleaseOutputSurface, |
432 base::Unretained(this))); | 432 base::Unretained(this))); |
433 } else { | 433 } else { |
434 EndTest(); | 434 EndTest(); |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 void MakeVisible() { | 438 void MakeVisible() { |
439 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 439 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
440 layer_tree_host()->SetVisible(true); | 440 layer_tree_host()->SetVisible(true); |
441 } | 441 } |
442 | 442 |
443 void AfterTest() override {} | 443 void AfterTest() override {} |
444 | 444 |
445 int setos_counter_; | 445 int setos_counter_; |
446 }; | 446 }; |
447 | 447 |
448 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostClientTakeAwayOutputSurface); | 448 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostClientTakeAwayOutputSurface); |
449 | 449 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 717 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
718 | 718 |
719 void PostEvictTextures() { | 719 void PostEvictTextures() { |
720 if (HasImplThread()) { | 720 if (HasImplThread()) { |
721 ImplThreadTaskRunner()->PostTask( | 721 ImplThreadTaskRunner()->PostTask( |
722 FROM_HERE, | 722 FROM_HERE, |
723 base::Bind(&LayerTreeHostContextTestLostContextAndEvictTextures:: | 723 base::Bind(&LayerTreeHostContextTestLostContextAndEvictTextures:: |
724 EvictTexturesOnImplThread, | 724 EvictTexturesOnImplThread, |
725 base::Unretained(this))); | 725 base::Unretained(this))); |
726 } else { | 726 } else { |
727 DebugScopedSetImplThread impl(proxy()); | 727 DebugScopedSetImplThread impl(task_runner_provider()); |
728 EvictTexturesOnImplThread(); | 728 EvictTexturesOnImplThread(); |
729 } | 729 } |
730 } | 730 } |
731 | 731 |
732 void EvictTexturesOnImplThread() { | 732 void EvictTexturesOnImplThread() { |
733 impl_host_->EvictTexturesForTesting(); | 733 impl_host_->EvictTexturesForTesting(); |
734 | 734 |
735 if (lose_after_evict_) { | 735 if (lose_after_evict_) { |
736 LoseContext(); | 736 LoseContext(); |
737 lost_context_ = true; | 737 lost_context_ = true; |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 // work on the main thread in DidCommit but that is unsuitable because | 1217 // work on the main thread in DidCommit but that is unsuitable because |
1218 // the main thread work for these tests must happen after | 1218 // the main thread work for these tests must happen after |
1219 // DidActivateTreeOnThread, which happens after DidCommit with impl-side | 1219 // DidActivateTreeOnThread, which happens after DidCommit with impl-side |
1220 // painting. | 1220 // painting. |
1221 virtual void StepCompleteOnMainThread(int time_step) = 0; | 1221 virtual void StepCompleteOnMainThread(int time_step) = 0; |
1222 | 1222 |
1223 // Called after DidActivateTreeOnThread. If this is done during the commit, | 1223 // Called after DidActivateTreeOnThread. If this is done during the commit, |
1224 // the call to StepCompleteOnMainThread will not occur until after | 1224 // the call to StepCompleteOnMainThread will not occur until after |
1225 // the commit completes, because the main thread is blocked. | 1225 // the commit completes, because the main thread is blocked. |
1226 void PostStepCompleteToMainThread() { | 1226 void PostStepCompleteToMainThread() { |
1227 proxy()->MainThreadTaskRunner()->PostTask( | 1227 task_runner_provider()->MainThreadTaskRunner()->PostTask( |
1228 FROM_HERE, | 1228 FROM_HERE, |
1229 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, | 1229 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, |
1230 base::Unretained(this), | 1230 base::Unretained(this), time_step_)); |
1231 time_step_)); | |
1232 } | 1231 } |
1233 | 1232 |
1234 void PostLoseContextToImplThread() { | 1233 void PostLoseContextToImplThread() { |
1235 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 1234 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
1236 ImplThreadTaskRunner()->PostTask( | 1235 ImplThreadTaskRunner()->PostTask( |
1237 FROM_HERE, | 1236 FROM_HERE, |
1238 base::Bind(&LayerTreeHostContextTest::LoseContext, | 1237 base::Bind(&LayerTreeHostContextTest::LoseContext, |
1239 base::Unretained(this))); | 1238 base::Unretained(this))); |
1240 } | 1239 } |
1241 | 1240 |
1242 protected: | 1241 protected: |
1243 int time_step_; | 1242 int time_step_; |
1244 scoped_ptr<FakeScopedUIResource> ui_resource_; | 1243 scoped_ptr<FakeScopedUIResource> ui_resource_; |
1245 | 1244 |
1246 private: | 1245 private: |
1247 void StepCompleteOnMainThreadInternal(int step) { | 1246 void StepCompleteOnMainThreadInternal(int step) { |
1248 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 1247 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
1249 StepCompleteOnMainThread(step); | 1248 StepCompleteOnMainThread(step); |
1250 } | 1249 } |
1251 }; | 1250 }; |
1252 | 1251 |
1253 class UIResourceLostTestSimple : public UIResourceLostTest { | 1252 class UIResourceLostTestSimple : public UIResourceLostTest { |
1254 public: | 1253 public: |
1255 // This is called when the new layer tree has been activated. | 1254 // This is called when the new layer tree has been activated. |
1256 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) = 0; | 1255 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) = 0; |
1257 | 1256 |
1258 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1257 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
1259 StepCompleteOnImplThread(impl); | 1258 StepCompleteOnImplThread(impl); |
1260 PostStepCompleteToMainThread(); | 1259 PostStepCompleteToMainThread(); |
1261 ++time_step_; | 1260 ++time_step_; |
1262 } | 1261 } |
1263 }; | 1262 }; |
1264 | 1263 |
1265 // Losing context after an UI resource has been created. | 1264 // Losing context after an UI resource has been created. |
1266 class UIResourceLostAfterCommit : public UIResourceLostTestSimple { | 1265 class UIResourceLostAfterCommit : public UIResourceLostTestSimple { |
1267 public: | 1266 public: |
1268 void StepCompleteOnMainThread(int step) override { | 1267 void StepCompleteOnMainThread(int step) override { |
1269 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 1268 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
1270 switch (step) { | 1269 switch (step) { |
1271 case 0: | 1270 case 0: |
1272 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1271 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
1273 // Expects a valid UIResourceId. | 1272 // Expects a valid UIResourceId. |
1274 EXPECT_NE(0, ui_resource_->id()); | 1273 EXPECT_NE(0, ui_resource_->id()); |
1275 PostSetNeedsCommitToMainThread(); | 1274 PostSetNeedsCommitToMainThread(); |
1276 break; | 1275 break; |
1277 case 4: | 1276 case 4: |
1278 // Release resource before ending the test. | 1277 // Release resource before ending the test. |
1279 ui_resource_ = nullptr; | 1278 ui_resource_ = nullptr; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 UIResourceId test_id0_; | 1413 UIResourceId test_id0_; |
1415 UIResourceId test_id1_; | 1414 UIResourceId test_id1_; |
1416 }; | 1415 }; |
1417 | 1416 |
1418 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); | 1417 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); |
1419 | 1418 |
1420 // Losing UI resource before the pending trees is activated but after the | 1419 // Losing UI resource before the pending trees is activated but after the |
1421 // commit. Impl-side-painting only. | 1420 // commit. Impl-side-painting only. |
1422 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { | 1421 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { |
1423 void StepCompleteOnMainThread(int step) override { | 1422 void StepCompleteOnMainThread(int step) override { |
1424 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 1423 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
1425 switch (step) { | 1424 switch (step) { |
1426 case 0: | 1425 case 0: |
1427 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1426 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
1428 PostSetNeedsCommitToMainThread(); | 1427 PostSetNeedsCommitToMainThread(); |
1429 break; | 1428 break; |
1430 case 3: | 1429 case 3: |
1431 test_id_ = ui_resource_->id(); | 1430 test_id_ = ui_resource_->id(); |
1432 ui_resource_ = nullptr; | 1431 ui_resource_ = nullptr; |
1433 PostSetNeedsCommitToMainThread(); | 1432 PostSetNeedsCommitToMainThread(); |
1434 break; | 1433 break; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 private: | 1496 private: |
1498 UIResourceId test_id_; | 1497 UIResourceId test_id_; |
1499 }; | 1498 }; |
1500 | 1499 |
1501 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeActivateTree); | 1500 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeActivateTree); |
1502 | 1501 |
1503 // Resources evicted explicitly and by visibility changes. | 1502 // Resources evicted explicitly and by visibility changes. |
1504 class UIResourceLostEviction : public UIResourceLostTestSimple { | 1503 class UIResourceLostEviction : public UIResourceLostTestSimple { |
1505 public: | 1504 public: |
1506 void StepCompleteOnMainThread(int step) override { | 1505 void StepCompleteOnMainThread(int step) override { |
1507 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 1506 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
1508 switch (step) { | 1507 switch (step) { |
1509 case 0: | 1508 case 0: |
1510 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1509 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
1511 EXPECT_NE(0, ui_resource_->id()); | 1510 EXPECT_NE(0, ui_resource_->id()); |
1512 PostSetNeedsCommitToMainThread(); | 1511 PostSetNeedsCommitToMainThread(); |
1513 break; | 1512 break; |
1514 case 2: | 1513 case 2: |
1515 // Make the tree not visible. | 1514 // Make the tree not visible. |
1516 PostSetVisibleToMainThread(false); | 1515 PostSetVisibleToMainThread(false); |
1517 break; | 1516 break; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 void AfterTest() override {} | 1622 void AfterTest() override {} |
1624 | 1623 |
1625 bool deferred_; | 1624 bool deferred_; |
1626 }; | 1625 }; |
1627 | 1626 |
1628 SINGLE_AND_MULTI_THREAD_TEST_F( | 1627 SINGLE_AND_MULTI_THREAD_TEST_F( |
1629 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1628 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1630 | 1629 |
1631 } // namespace | 1630 } // namespace |
1632 } // namespace cc | 1631 } // namespace cc |
OLD | NEW |