| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "cc/layers/heads_up_display_layer.h" | 9 #include "cc/layers/heads_up_display_layer.h" |
| 10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds); | 358 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds); |
| 359 | 359 |
| 360 class LayerTreeHostClientNotVisibleDoesNotCreateOutputSurface | 360 class LayerTreeHostClientNotVisibleDoesNotCreateOutputSurface |
| 361 : public LayerTreeHostContextTest { | 361 : public LayerTreeHostContextTest { |
| 362 public: | 362 public: |
| 363 LayerTreeHostClientNotVisibleDoesNotCreateOutputSurface() | 363 LayerTreeHostClientNotVisibleDoesNotCreateOutputSurface() |
| 364 : LayerTreeHostContextTest() {} | 364 : LayerTreeHostContextTest() {} |
| 365 | 365 |
| 366 void WillBeginTest() override { | 366 void WillBeginTest() override { |
| 367 // Override to not become visible. | 367 // Override to not become visible. |
| 368 DCHECK(!layer_tree_host()->visible()); | 368 DCHECK(!layer_tree_host()->IsVisible()); |
| 369 } | 369 } |
| 370 | 370 |
| 371 void BeginTest() override { | 371 void BeginTest() override { |
| 372 PostSetNeedsCommitToMainThread(); | 372 PostSetNeedsCommitToMainThread(); |
| 373 EndTest(); | 373 EndTest(); |
| 374 } | 374 } |
| 375 | 375 |
| 376 void RequestNewOutputSurface() override { | 376 void RequestNewOutputSurface() override { |
| 377 ADD_FAILURE() << "RequestNewOutputSurface() should not be called"; | 377 ADD_FAILURE() << "RequestNewOutputSurface() should not be called"; |
| 378 } | 378 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 394 // Create and init new OutputSurface | 394 // Create and init new OutputSurface |
| 395 class LayerTreeHostClientTakeAwayOutputSurface | 395 class LayerTreeHostClientTakeAwayOutputSurface |
| 396 : public LayerTreeHostContextTest { | 396 : public LayerTreeHostContextTest { |
| 397 public: | 397 public: |
| 398 LayerTreeHostClientTakeAwayOutputSurface() | 398 LayerTreeHostClientTakeAwayOutputSurface() |
| 399 : LayerTreeHostContextTest(), setos_counter_(0) {} | 399 : LayerTreeHostContextTest(), setos_counter_(0) {} |
| 400 | 400 |
| 401 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 401 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 402 | 402 |
| 403 void RequestNewOutputSurface() override { | 403 void RequestNewOutputSurface() override { |
| 404 if (layer_tree_host()->visible()) { | 404 if (layer_tree_host()->IsVisible()) { |
| 405 setos_counter_++; | 405 setos_counter_++; |
| 406 LayerTreeHostContextTest::RequestNewOutputSurface(); | 406 LayerTreeHostContextTest::RequestNewOutputSurface(); |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 | 409 |
| 410 void HideAndReleaseOutputSurface() { | 410 void HideAndReleaseOutputSurface() { |
| 411 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 411 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
| 412 layer_tree_host()->SetVisible(false); | 412 layer_tree_host()->SetVisible(false); |
| 413 std::unique_ptr<OutputSurface> surface = | 413 std::unique_ptr<OutputSurface> surface = |
| 414 layer_tree_host()->ReleaseOutputSurface(); | 414 layer_tree_host()->ReleaseOutputSurface(); |
| 415 CHECK(surface); | 415 CHECK(surface); |
| 416 MainThreadTaskRunner()->PostTask( | 416 MainThreadTaskRunner()->PostTask( |
| 417 FROM_HERE, | 417 FROM_HERE, |
| 418 base::Bind(&LayerTreeHostClientTakeAwayOutputSurface::MakeVisible, | 418 base::Bind(&LayerTreeHostClientTakeAwayOutputSurface::MakeVisible, |
| 419 base::Unretained(this))); | 419 base::Unretained(this))); |
| 420 } | 420 } |
| 421 | 421 |
| 422 void DidInitializeOutputSurface() override { | 422 void DidInitializeOutputSurface() override { |
| 423 EXPECT_TRUE(layer_tree_host()->visible()); | 423 EXPECT_TRUE(layer_tree_host()->IsVisible()); |
| 424 if (setos_counter_ == 1) { | 424 if (setos_counter_ == 1) { |
| 425 MainThreadTaskRunner()->PostTask( | 425 MainThreadTaskRunner()->PostTask( |
| 426 FROM_HERE, base::Bind(&LayerTreeHostClientTakeAwayOutputSurface:: | 426 FROM_HERE, base::Bind(&LayerTreeHostClientTakeAwayOutputSurface:: |
| 427 HideAndReleaseOutputSurface, | 427 HideAndReleaseOutputSurface, |
| 428 base::Unretained(this))); | 428 base::Unretained(this))); |
| 429 } else { | 429 } else { |
| 430 EndTest(); | 430 EndTest(); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 void MakeVisible() { | 434 void MakeVisible() { |
| 435 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 435 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
| 436 layer_tree_host()->SetVisible(true); | 436 layer_tree_host()->SetVisible(true); |
| 437 } | 437 } |
| 438 | 438 |
| 439 void AfterTest() override {} | 439 void AfterTest() override {} |
| 440 | 440 |
| 441 int setos_counter_; | 441 int setos_counter_; |
| 442 }; | 442 }; |
| 443 | 443 |
| 444 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostClientTakeAwayOutputSurface); | 444 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostClientTakeAwayOutputSurface); |
| 445 | 445 |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 // Lose the context during draw on the second commit. This will cause | 1038 // Lose the context during draw on the second commit. This will cause |
| 1039 // a third commit to recover. | 1039 // a third commit to recover. |
| 1040 context3d_->set_times_bind_texture_succeeds(0); | 1040 context3d_->set_times_bind_texture_succeeds(0); |
| 1041 } | 1041 } |
| 1042 return draw_result; | 1042 return draw_result; |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 void RequestNewOutputSurface() override { | 1045 void RequestNewOutputSurface() override { |
| 1046 // This will get called twice: | 1046 // This will get called twice: |
| 1047 // First when we create the initial output surface... | 1047 // First when we create the initial output surface... |
| 1048 if (layer_tree_host()->source_frame_number() > 0) { | 1048 if (layer_tree_host()->SourceFrameNumber() > 0) { |
| 1049 // ... and then again after we forced the context to be lost. | 1049 // ... and then again after we forced the context to be lost. |
| 1050 lost_context_ = true; | 1050 lost_context_ = true; |
| 1051 } | 1051 } |
| 1052 LayerTreeHostContextTest::RequestNewOutputSurface(); | 1052 LayerTreeHostContextTest::RequestNewOutputSurface(); |
| 1053 } | 1053 } |
| 1054 | 1054 |
| 1055 void DidCommitAndDrawFrame() override { | 1055 void DidCommitAndDrawFrame() override { |
| 1056 ASSERT_TRUE(layer_tree()->hud_layer()); | 1056 ASSERT_TRUE(layer_tree()->hud_layer()); |
| 1057 // End the test once we know the 3nd frame drew. | 1057 // End the test once we know the 3nd frame drew. |
| 1058 if (layer_tree_host()->source_frame_number() < 5) { | 1058 if (layer_tree_host()->SourceFrameNumber() < 5) { |
| 1059 layer_tree()->root_layer()->SetNeedsDisplay(); | 1059 layer_tree()->root_layer()->SetNeedsDisplay(); |
| 1060 layer_tree_host()->SetNeedsCommit(); | 1060 layer_tree_host()->SetNeedsCommit(); |
| 1061 } else { | 1061 } else { |
| 1062 EndTest(); | 1062 EndTest(); |
| 1063 } | 1063 } |
| 1064 } | 1064 } |
| 1065 | 1065 |
| 1066 void AfterTest() override { EXPECT_TRUE(lost_context_); } | 1066 void AfterTest() override { EXPECT_TRUE(lost_context_); } |
| 1067 | 1067 |
| 1068 private: | 1068 private: |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 // the call to StepCompleteOnMainThread will not occur until after | 1185 // the call to StepCompleteOnMainThread will not occur until after |
| 1186 // the commit completes, because the main thread is blocked. | 1186 // the commit completes, because the main thread is blocked. |
| 1187 void PostStepCompleteToMainThread() { | 1187 void PostStepCompleteToMainThread() { |
| 1188 task_runner_provider()->MainThreadTaskRunner()->PostTask( | 1188 task_runner_provider()->MainThreadTaskRunner()->PostTask( |
| 1189 FROM_HERE, | 1189 FROM_HERE, |
| 1190 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, | 1190 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, |
| 1191 base::Unretained(this), time_step_)); | 1191 base::Unretained(this), time_step_)); |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 void PostLoseContextToImplThread() { | 1194 void PostLoseContextToImplThread() { |
| 1195 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 1195 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
| 1196 ImplThreadTaskRunner()->PostTask( | 1196 ImplThreadTaskRunner()->PostTask( |
| 1197 FROM_HERE, | 1197 FROM_HERE, |
| 1198 base::Bind(&LayerTreeHostContextTest::LoseContext, | 1198 base::Bind(&LayerTreeHostContextTest::LoseContext, |
| 1199 base::Unretained(this))); | 1199 base::Unretained(this))); |
| 1200 } | 1200 } |
| 1201 | 1201 |
| 1202 protected: | 1202 protected: |
| 1203 int time_step_; | 1203 int time_step_; |
| 1204 std::unique_ptr<FakeScopedUIResource> ui_resource_; | 1204 std::unique_ptr<FakeScopedUIResource> ui_resource_; |
| 1205 | 1205 |
| 1206 private: | 1206 private: |
| 1207 void StepCompleteOnMainThreadInternal(int step) { | 1207 void StepCompleteOnMainThreadInternal(int step) { |
| 1208 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 1208 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
| 1209 StepCompleteOnMainThread(step); | 1209 StepCompleteOnMainThread(step); |
| 1210 } | 1210 } |
| 1211 }; | 1211 }; |
| 1212 | 1212 |
| 1213 class UIResourceLostTestSimple : public UIResourceLostTest { | 1213 class UIResourceLostTestSimple : public UIResourceLostTest { |
| 1214 public: | 1214 public: |
| 1215 // This is called when the new layer tree has been activated. | 1215 // This is called when the new layer tree has been activated. |
| 1216 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) = 0; | 1216 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) = 0; |
| 1217 | 1217 |
| 1218 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1218 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 1219 StepCompleteOnImplThread(impl); | 1219 StepCompleteOnImplThread(impl); |
| 1220 PostStepCompleteToMainThread(); | 1220 PostStepCompleteToMainThread(); |
| 1221 ++time_step_; | 1221 ++time_step_; |
| 1222 } | 1222 } |
| 1223 }; | 1223 }; |
| 1224 | 1224 |
| 1225 // Losing context after an UI resource has been created. | 1225 // Losing context after an UI resource has been created. |
| 1226 class UIResourceLostAfterCommit : public UIResourceLostTestSimple { | 1226 class UIResourceLostAfterCommit : public UIResourceLostTestSimple { |
| 1227 public: | 1227 public: |
| 1228 void StepCompleteOnMainThread(int step) override { | 1228 void StepCompleteOnMainThread(int step) override { |
| 1229 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 1229 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
| 1230 switch (step) { | 1230 switch (step) { |
| 1231 case 0: | 1231 case 0: |
| 1232 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1232 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1233 // Expects a valid UIResourceId. | 1233 // Expects a valid UIResourceId. |
| 1234 EXPECT_NE(0, ui_resource_->id()); | 1234 EXPECT_NE(0, ui_resource_->id()); |
| 1235 PostSetNeedsCommitToMainThread(); | 1235 PostSetNeedsCommitToMainThread(); |
| 1236 break; | 1236 break; |
| 1237 case 4: | 1237 case 4: |
| 1238 // Release resource before ending the test. | 1238 // Release resource before ending the test. |
| 1239 ui_resource_ = nullptr; | 1239 ui_resource_ = nullptr; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 UIResourceId test_id0_; | 1374 UIResourceId test_id0_; |
| 1375 UIResourceId test_id1_; | 1375 UIResourceId test_id1_; |
| 1376 }; | 1376 }; |
| 1377 | 1377 |
| 1378 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); | 1378 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); |
| 1379 | 1379 |
| 1380 // Losing UI resource before the pending trees is activated but after the | 1380 // Losing UI resource before the pending trees is activated but after the |
| 1381 // commit. Impl-side-painting only. | 1381 // commit. Impl-side-painting only. |
| 1382 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { | 1382 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { |
| 1383 void StepCompleteOnMainThread(int step) override { | 1383 void StepCompleteOnMainThread(int step) override { |
| 1384 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 1384 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
| 1385 switch (step) { | 1385 switch (step) { |
| 1386 case 0: | 1386 case 0: |
| 1387 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1387 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1388 PostSetNeedsCommitToMainThread(); | 1388 PostSetNeedsCommitToMainThread(); |
| 1389 break; | 1389 break; |
| 1390 case 3: | 1390 case 3: |
| 1391 test_id_ = ui_resource_->id(); | 1391 test_id_ = ui_resource_->id(); |
| 1392 ui_resource_ = nullptr; | 1392 ui_resource_ = nullptr; |
| 1393 PostSetNeedsCommitToMainThread(); | 1393 PostSetNeedsCommitToMainThread(); |
| 1394 break; | 1394 break; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 private: | 1457 private: |
| 1458 UIResourceId test_id_; | 1458 UIResourceId test_id_; |
| 1459 }; | 1459 }; |
| 1460 | 1460 |
| 1461 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeActivateTree); | 1461 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeActivateTree); |
| 1462 | 1462 |
| 1463 // Resources evicted explicitly and by visibility changes. | 1463 // Resources evicted explicitly and by visibility changes. |
| 1464 class UIResourceLostEviction : public UIResourceLostTestSimple { | 1464 class UIResourceLostEviction : public UIResourceLostTestSimple { |
| 1465 public: | 1465 public: |
| 1466 void StepCompleteOnMainThread(int step) override { | 1466 void StepCompleteOnMainThread(int step) override { |
| 1467 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 1467 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
| 1468 switch (step) { | 1468 switch (step) { |
| 1469 case 0: | 1469 case 0: |
| 1470 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1470 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1471 ui_resource2_ = FakeScopedUIResource::Create(layer_tree_host()); | 1471 ui_resource2_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1472 EXPECT_NE(0, ui_resource_->id()); | 1472 EXPECT_NE(0, ui_resource_->id()); |
| 1473 EXPECT_NE(0, ui_resource2_->id()); | 1473 EXPECT_NE(0, ui_resource2_->id()); |
| 1474 PostSetNeedsCommitToMainThread(); | 1474 PostSetNeedsCommitToMainThread(); |
| 1475 break; | 1475 break; |
| 1476 case 2: | 1476 case 2: |
| 1477 // Make the tree not visible. | 1477 // Make the tree not visible. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 | 1617 |
| 1618 bool deferred_ = false; | 1618 bool deferred_ = false; |
| 1619 bool lost_ = true; | 1619 bool lost_ = true; |
| 1620 }; | 1620 }; |
| 1621 | 1621 |
| 1622 SINGLE_AND_MULTI_THREAD_TEST_F( | 1622 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1623 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1623 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
| 1624 | 1624 |
| 1625 } // namespace | 1625 } // namespace |
| 1626 } // namespace cc | 1626 } // namespace cc |
| OLD | NEW |