Chromium Code Reviews| Index: cc/layers/texture_layer_unittest.cc |
| diff --git a/cc/layers/texture_layer_unittest.cc b/cc/layers/texture_layer_unittest.cc |
| index 7d10bf7ee4ae7739693a0d58c5afe75ac8d6d3fe..483581dbd8b6f2fa95452aba85e19f3308e1c40d 100644 |
| --- a/cc/layers/texture_layer_unittest.cc |
| +++ b/cc/layers/texture_layer_unittest.cc |
| @@ -643,15 +643,64 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
| bool synchronous_composite = |
| !HasImplThread() && |
| !layer_tree_host()->GetSettings().single_thread_proxy_scheduler; |
| - // Allow relaim resources for this test so that mailboxes in the display |
| - // will be returned inside the commit that replaces them. |
| - bool force_disable_reclaim_resources = false; |
| return base::MakeUnique<TestCompositorFrameSink>( |
| compositor_context_provider, std::move(worker_context_provider), |
| shared_bitmap_manager(), gpu_memory_buffer_manager(), |
| layer_tree_host()->GetSettings().renderer_settings, |
| - ImplThreadTaskRunner(), synchronous_composite, |
| - force_disable_reclaim_resources); |
| + ImplThreadTaskRunner(), synchronous_composite); |
| + } |
| + |
| + void AdvancePhase() { |
| + ++test_phase_; |
| + switch (test_phase_) { |
| + case 1: |
| + // Case #2: change mailbox after the commit (and draw), where the |
|
danakj
2017/01/18 20:35:03
Uh, it looks like Case #1 didn't make it, maybe u
ericrk
2017/01/18 23:18:23
Case 1 was in BeginTest - Moved it here so they're
|
| + // layer draws. The old mailbox should be released during the next |
| + // commit. |
| + SetMailbox('3'); |
| + EXPECT_EQ(1, callback_count_); |
| + |
| + // Phases 2-4 rely on a callback to advance. |
| + pending_callback_ = true; |
| + break; |
| + case 2: |
| + EXPECT_EQ(2, callback_count_); |
| + // Case #3: change mailbox when the layer doesn't draw. The old |
| + // mailbox should be released during the next commit. |
| + layer_->SetBounds(gfx::Size()); |
| + SetMailbox('4'); |
| + break; |
| + case 3: |
| + EXPECT_EQ(3, callback_count_); |
| + // Case #4: release mailbox that was committed but never drawn. The |
| + // old mailbox should be released during the next commit. |
| + layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
| + break; |
| + case 4: |
| + EXPECT_EQ(4, callback_count_); |
| + // Restore a mailbox for the next step. |
| + SetMailbox('5'); |
| + |
| + // Phases 5 and 6 do not rely on callbacks to advance. |
| + pending_callback_ = false; |
| + break; |
| + case 5: |
| + // Case #5: remove layer from tree. Callback should *not* be called, the |
| + // mailbox is returned to the main thread. |
| + EXPECT_EQ(4, callback_count_); |
| + layer_->RemoveFromParent(); |
| + break; |
| + case 6: |
| + EXPECT_EQ(4, callback_count_); |
| + // Resetting the mailbox will call the callback now. |
| + layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
| + EXPECT_EQ(5, callback_count_); |
| + EndTest(); |
| + break; |
| + default: |
| + NOTREACHED(); |
| + break; |
| + } |
| } |
| // Make sure callback is received on main and doesn't block the impl thread. |
| @@ -661,6 +710,10 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
| EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| EXPECT_FALSE(lost_resource); |
| ++callback_count_; |
| + |
| + // If we are waiting on a callback, advance now. |
| + if (pending_callback_) |
| + AdvancePhase(); |
| } |
| void SetMailbox(char mailbox_char) { |
| @@ -704,50 +757,9 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
| } |
| void DidCommit() override { |
| - ++commit_count_; |
| - switch (commit_count_) { |
| - case 1: |
| - // Case #2: change mailbox after the commit (and draw), where the |
| - // layer draws. The old mailbox should be released during the next |
| - // commit. |
| - SetMailbox('3'); |
| - EXPECT_EQ(1, callback_count_); |
| - break; |
| - case 2: |
| - EXPECT_EQ(2, callback_count_); |
| - // Case #3: change mailbox when the layer doesn't draw. The old |
| - // mailbox should be released during the next commit. |
| - layer_->SetBounds(gfx::Size()); |
| - SetMailbox('4'); |
| - break; |
| - case 3: |
| - EXPECT_EQ(3, callback_count_); |
| - // Case #4: release mailbox that was committed but never drawn. The |
| - // old mailbox should be released during the next commit. |
| - layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
| - break; |
| - case 4: |
| - EXPECT_EQ(4, callback_count_); |
| - // Restore a mailbox for the next step. |
| - SetMailbox('5'); |
| - break; |
| - case 5: |
| - // Case #5: remove layer from tree. Callback should *not* be called, the |
| - // mailbox is returned to the main thread. |
| - EXPECT_EQ(4, callback_count_); |
| - layer_->RemoveFromParent(); |
| - break; |
| - case 6: |
| - EXPECT_EQ(4, callback_count_); |
| - // Resetting the mailbox will call the callback now. |
| - layer_->SetTextureMailbox(TextureMailbox(), nullptr); |
| - EXPECT_EQ(5, callback_count_); |
| - EndTest(); |
| - break; |
| - default: |
| - NOTREACHED(); |
| - break; |
| - } |
| + // If we are not waiting on a callback, advance now. |
| + if (!pending_callback_) |
| + AdvancePhase(); |
| } |
| void AfterTest() override {} |
| @@ -755,7 +767,9 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
| private: |
| base::ThreadChecker main_thread_; |
| int callback_count_ = 0; |
| - int commit_count_ = 0; |
| + int test_phase_ = 0; |
| + // Whether we are waiting on a callback to advance the test phase. |
| + bool pending_callback_ = false; |
| scoped_refptr<Layer> root_; |
| scoped_refptr<TextureLayer> layer_; |
| }; |