Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 MAIN_DID_BEGIN_FRAME, | 123 MAIN_DID_BEGIN_FRAME, |
| 124 MAIN_END, | 124 MAIN_END, |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 enum ImplOrder : int { | 127 enum ImplOrder : int { |
| 128 IMPL_START = 1, | 128 IMPL_START = 1, |
| 129 IMPL_COMMIT, | 129 IMPL_COMMIT, |
| 130 IMPL_COMMIT_COMPLETE, | 130 IMPL_COMMIT_COMPLETE, |
| 131 IMPL_ACTIVATE, | 131 IMPL_ACTIVATE, |
| 132 IMPL_DRAW, | 132 IMPL_DRAW, |
| 133 IMPL_SWAP, | |
| 134 IMPL_END, | 133 IMPL_END, |
| 135 }; | 134 }; |
| 136 | 135 |
| 137 template <typename T> | 136 template <typename T> |
| 138 bool CheckStep(T next, T* var) { | 137 bool CheckStep(T next, T* var) { |
| 139 int expected = next - 1; | 138 int expected = next - 1; |
| 140 EXPECT_EQ(expected, *var); | 139 EXPECT_EQ(expected, *var); |
| 141 bool correct = expected == *var; | 140 bool correct = expected == *var; |
| 142 *var = next; | 141 *var = next; |
| 143 return correct; | 142 return correct; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 164 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 163 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| 165 EXPECT_TRUE(CheckStep(IMPL_COMMIT_COMPLETE, &impl_)); | 164 EXPECT_TRUE(CheckStep(IMPL_COMMIT_COMPLETE, &impl_)); |
| 166 } | 165 } |
| 167 | 166 |
| 168 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 167 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 169 EXPECT_TRUE(CheckStep(IMPL_ACTIVATE, &impl_)); | 168 EXPECT_TRUE(CheckStep(IMPL_ACTIVATE, &impl_)); |
| 170 } | 169 } |
| 171 | 170 |
| 172 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 171 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 173 EXPECT_TRUE(CheckStep(IMPL_DRAW, &impl_)); | 172 EXPECT_TRUE(CheckStep(IMPL_DRAW, &impl_)); |
| 174 } | |
| 175 | |
| 176 void SwapBuffersCompleteOnThread(LayerTreeHostImpl* impl) override { | |
| 177 EXPECT_TRUE(CheckStep(IMPL_SWAP, &impl_)); | |
| 178 | |
| 179 EndTest(); | 173 EndTest(); |
| 180 } | 174 } |
| 181 | 175 |
| 182 void AfterTest() override { | 176 void AfterTest() override { |
| 183 EXPECT_TRUE(CheckStep(MAIN_END, &main_)); | 177 EXPECT_TRUE(CheckStep(MAIN_END, &main_)); |
| 184 EXPECT_TRUE(CheckStep(IMPL_END, &impl_)); | 178 EXPECT_TRUE(CheckStep(IMPL_END, &impl_)); |
| 185 } | 179 } |
| 186 | 180 |
| 187 MainOrder main_ = MAIN_START; | 181 MainOrder main_ = MAIN_START; |
| 188 ImplOrder impl_ = IMPL_START; | 182 ImplOrder impl_ = IMPL_START; |
| (...skipping 2606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2795 EXPECT_EQ(2u, frame_data->render_passes.size()); | 2789 EXPECT_EQ(2u, frame_data->render_passes.size()); |
| 2796 | 2790 |
| 2797 // At least root layer quad in root render pass. | 2791 // At least root layer quad in root render pass. |
| 2798 EXPECT_GE(frame_data->render_passes[0]->quad_list.size(), 1u); | 2792 EXPECT_GE(frame_data->render_passes[0]->quad_list.size(), 1u); |
| 2799 // At least parent and child layer quads in parent render pass. | 2793 // At least parent and child layer quads in parent render pass. |
| 2800 EXPECT_GE(frame_data->render_passes[1]->quad_list.size(), 2u); | 2794 EXPECT_GE(frame_data->render_passes[1]->quad_list.size(), 2u); |
| 2801 } | 2795 } |
| 2802 return draw_result; | 2796 return draw_result; |
| 2803 } | 2797 } |
| 2804 | 2798 |
| 2805 void SwapBuffersCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 2799 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 2806 swap_count_++; | 2800 swap_count_++; |
| 2807 switch (swap_count_) { | 2801 switch (swap_count_) { |
| 2808 case 1: | 2802 case 1: |
| 2809 host_impl->SetNeedsRedraw(); | 2803 host_impl->SetNeedsRedraw(); |
| 2810 break; | 2804 break; |
| 2811 case 2: | 2805 case 2: |
| 2812 EndTest(); | 2806 EndTest(); |
| 2813 break; | 2807 break; |
| 2814 default: | 2808 default: |
| 2815 NOTREACHED(); | 2809 NOTREACHED(); |
| (...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4279 // Lost context sometimes takes two frames to recreate. The third frame | 4273 // Lost context sometimes takes two frames to recreate. The third frame |
| 4280 // is sometimes aborted, so wait until the fourth frame to verify that | 4274 // is sometimes aborted, so wait until the fourth frame to verify that |
| 4281 // the memory has been set, and the fifth frame to end the test. | 4275 // the memory has been set, and the fifth frame to end the test. |
| 4282 if (layer_tree_host()->source_frame_number() < 5) { | 4276 if (layer_tree_host()->source_frame_number() < 5) { |
| 4283 layer_tree_host()->SetNeedsCommit(); | 4277 layer_tree_host()->SetNeedsCommit(); |
| 4284 } else if (layer_tree_host()->source_frame_number() == 5) { | 4278 } else if (layer_tree_host()->source_frame_number() == 5) { |
| 4285 EndTest(); | 4279 EndTest(); |
| 4286 } | 4280 } |
| 4287 } | 4281 } |
| 4288 | 4282 |
| 4289 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override { | 4283 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 4290 switch (impl->active_tree()->source_frame_number()) { | 4284 switch (impl->active_tree()->source_frame_number()) { |
| 4291 case 1: | 4285 case 1: |
| 4292 EXPECT_EQ(first_output_surface_memory_limit_, | 4286 EXPECT_EQ(first_output_surface_memory_limit_, |
| 4293 impl->memory_allocation_limit_bytes()); | 4287 impl->memory_allocation_limit_bytes()); |
| 4294 // Lose the output surface. | 4288 // Lose the output surface. |
| 4295 first_context_provider_->TestContext3d()->loseContextCHROMIUM( | 4289 first_context_provider_->TestContext3d()->loseContextCHROMIUM( |
| 4296 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 4290 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 4297 break; | 4291 break; |
| 4298 case 4: | 4292 case 4: |
| 4299 EXPECT_EQ(second_output_surface_memory_limit_, | 4293 EXPECT_EQ(second_output_surface_memory_limit_, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4384 if (frame == -1) { | 4378 if (frame == -1) { |
| 4385 host_impl->active_tree()->QueuePinnedSwapPromise(base::WrapUnique( | 4379 host_impl->active_tree()->QueuePinnedSwapPromise(base::WrapUnique( |
| 4386 new TestSwapPromise(&pinned_active_swap_promise_result_))); | 4380 new TestSwapPromise(&pinned_active_swap_promise_result_))); |
| 4387 host_impl->pending_tree()->QueueSwapPromise( | 4381 host_impl->pending_tree()->QueueSwapPromise( |
| 4388 base::WrapUnique(new TestSwapPromise(&pending_swap_promise_result_))); | 4382 base::WrapUnique(new TestSwapPromise(&pending_swap_promise_result_))); |
| 4389 host_impl->active_tree()->QueueSwapPromise( | 4383 host_impl->active_tree()->QueueSwapPromise( |
| 4390 base::WrapUnique(new TestSwapPromise(&active_swap_promise_result_))); | 4384 base::WrapUnique(new TestSwapPromise(&active_swap_promise_result_))); |
| 4391 } | 4385 } |
| 4392 } | 4386 } |
| 4393 | 4387 |
| 4394 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 4388 void SwapBuffersCompleteOnThread() override { EndTest(); } |
| 4395 EndTest(); | |
| 4396 } | |
| 4397 | 4389 |
| 4398 void AfterTest() override { | 4390 void AfterTest() override { |
| 4399 // The pending swap promise should activate and swap. | 4391 // The pending swap promise should activate and swap. |
| 4400 EXPECT_TRUE(pending_swap_promise_result_.did_activate_called); | 4392 EXPECT_TRUE(pending_swap_promise_result_.did_activate_called); |
| 4401 EXPECT_TRUE(pending_swap_promise_result_.did_swap_called); | 4393 EXPECT_TRUE(pending_swap_promise_result_.did_swap_called); |
| 4402 | 4394 |
| 4403 // The active swap promise should fail to swap (it is cancelled by | 4395 // The active swap promise should fail to swap (it is cancelled by |
| 4404 // the activation of a new frame). | 4396 // the activation of a new frame). |
| 4405 EXPECT_FALSE(active_swap_promise_result_.did_activate_called); | 4397 EXPECT_FALSE(active_swap_promise_result_.did_activate_called); |
| 4406 EXPECT_FALSE(active_swap_promise_result_.did_swap_called); | 4398 EXPECT_FALSE(active_swap_promise_result_.did_swap_called); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4458 } | 4450 } |
| 4459 | 4451 |
| 4460 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 4452 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 4461 commit_complete_count_++; | 4453 commit_complete_count_++; |
| 4462 if (commit_complete_count_ == 1) { | 4454 if (commit_complete_count_ == 1) { |
| 4463 // This commit will be aborted because no actual update. | 4455 // This commit will be aborted because no actual update. |
| 4464 PostSetNeedsUpdateLayersToMainThread(); | 4456 PostSetNeedsUpdateLayersToMainThread(); |
| 4465 } | 4457 } |
| 4466 } | 4458 } |
| 4467 | 4459 |
| 4468 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 4460 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 4469 int frame = host_impl->active_tree()->source_frame_number(); | 4461 int frame = host_impl->active_tree()->source_frame_number(); |
| 4470 if (frame == 2) { | 4462 if (frame == 2) { |
| 4471 EndTest(); | 4463 EndTest(); |
| 4472 } | 4464 } |
| 4473 } | 4465 } |
| 4474 | 4466 |
| 4475 void AfterTest() override { | 4467 void AfterTest() override { |
| 4476 // 3 commits are scheduled. 2 completes. 1 is aborted. | 4468 // 3 commits are scheduled. 2 completes. 1 is aborted. |
| 4477 EXPECT_EQ(commit_count_, 3); | 4469 EXPECT_EQ(commit_count_, 3); |
| 4478 EXPECT_EQ(commit_complete_count_, 2); | 4470 EXPECT_EQ(commit_complete_count_, 2); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4578 } | 4570 } |
| 4579 | 4571 |
| 4580 void SetCallback(bool enable) { | 4572 void SetCallback(bool enable) { |
| 4581 output_surface()->SetTreeActivationCallback( | 4573 output_surface()->SetTreeActivationCallback( |
| 4582 enable | 4574 enable |
| 4583 ? base::Bind(&LayerTreeHostTestKeepSwapPromise::ActivationCallback, | 4575 ? base::Bind(&LayerTreeHostTestKeepSwapPromise::ActivationCallback, |
| 4584 base::Unretained(this)) | 4576 base::Unretained(this)) |
| 4585 : base::Closure()); | 4577 : base::Closure()); |
| 4586 } | 4578 } |
| 4587 | 4579 |
| 4588 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 4580 void SwapBuffersCompleteOnThread() override { |
| 4589 EXPECT_TRUE(result); | 4581 if (num_swaps_++ >= 1) { |
| 4590 if (host_impl->active_tree()->source_frame_number() >= 1) { | |
| 4591 // The commit changes layers so it should cause a swap. | 4582 // The commit changes layers so it should cause a swap. |
| 4592 base::AutoLock lock(swap_promise_result_.lock); | 4583 base::AutoLock lock(swap_promise_result_.lock); |
| 4593 EXPECT_TRUE(swap_promise_result_.did_swap_called); | 4584 EXPECT_TRUE(swap_promise_result_.did_swap_called); |
| 4594 EXPECT_FALSE(swap_promise_result_.did_not_swap_called); | 4585 EXPECT_FALSE(swap_promise_result_.did_not_swap_called); |
| 4595 EXPECT_TRUE(swap_promise_result_.dtor_called); | 4586 EXPECT_TRUE(swap_promise_result_.dtor_called); |
| 4596 EndTest(); | 4587 EndTest(); |
| 4597 } | 4588 } |
| 4598 } | 4589 } |
| 4599 | 4590 |
| 4600 void AfterTest() override {} | 4591 void AfterTest() override {} |
| 4601 | 4592 |
| 4602 private: | 4593 private: |
| 4594 int num_swaps_ = 0; | |
| 4603 scoped_refptr<Layer> layer_; | 4595 scoped_refptr<Layer> layer_; |
| 4604 TestSwapPromiseResult swap_promise_result_; | 4596 TestSwapPromiseResult swap_promise_result_; |
| 4605 }; | 4597 }; |
| 4606 | 4598 |
| 4607 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise); | 4599 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F( |
| 4600 LayerTreeHostTestKeepSwapPromise); | |
| 4608 | 4601 |
| 4609 class LayerTreeHostTestBreakSwapPromiseForVisibility | 4602 class LayerTreeHostTestBreakSwapPromiseForVisibility |
| 4610 : public LayerTreeHostTest { | 4603 : public LayerTreeHostTest { |
| 4611 protected: | 4604 protected: |
| 4612 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 4605 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 4613 | 4606 |
| 4614 void SetVisibleFalseAndQueueSwapPromise() { | 4607 void SetVisibleFalseAndQueueSwapPromise() { |
| 4615 layer_tree_host()->SetVisible(false); | 4608 layer_tree_host()->SetVisible(false); |
| 4616 std::unique_ptr<SwapPromise> swap_promise( | 4609 std::unique_ptr<SwapPromise> swap_promise( |
| 4617 new TestSwapPromise(&swap_promise_result_)); | 4610 new TestSwapPromise(&swap_promise_result_)); |
| (...skipping 2060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6678 // Makes sure that painted_device_scale_factor is propagated to the | 6671 // Makes sure that painted_device_scale_factor is propagated to the |
| 6679 // frame's metadata. | 6672 // frame's metadata. |
| 6680 class LayerTreeHostTestPaintedDeviceScaleFactor : public LayerTreeHostTest { | 6673 class LayerTreeHostTestPaintedDeviceScaleFactor : public LayerTreeHostTest { |
| 6681 protected: | 6674 protected: |
| 6682 void BeginTest() override { | 6675 void BeginTest() override { |
| 6683 layer_tree_host()->SetPaintedDeviceScaleFactor(2.0f); | 6676 layer_tree_host()->SetPaintedDeviceScaleFactor(2.0f); |
| 6684 EXPECT_EQ(1.0f, layer_tree_host()->device_scale_factor()); | 6677 EXPECT_EQ(1.0f, layer_tree_host()->device_scale_factor()); |
| 6685 PostSetNeedsCommitToMainThread(); | 6678 PostSetNeedsCommitToMainThread(); |
| 6686 } | 6679 } |
| 6687 | 6680 |
| 6688 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 6681 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 6682 EXPECT_EQ(2.0f, host_impl->active_tree()->painted_device_scale_factor()); | |
|
danakj
2016/07/13 21:50:18
Check the tree state when we draw. Check the swapp
| |
| 6683 EXPECT_EQ(1.0f, host_impl->active_tree()->device_scale_factor()); | |
| 6684 } | |
| 6685 | |
| 6686 void SwapBuffersCompleteOnThread() override { | |
| 6689 EXPECT_EQ( | 6687 EXPECT_EQ( |
| 6690 2.0f, | 6688 2.0f, |
| 6691 output_surface()->last_sent_frame()->metadata.device_scale_factor); | 6689 output_surface()->last_sent_frame()->metadata.device_scale_factor); |
| 6692 EXPECT_EQ(2.0f, host_impl->active_tree()->painted_device_scale_factor()); | |
| 6693 EXPECT_EQ(1.0f, host_impl->active_tree()->device_scale_factor()); | |
| 6694 EndTest(); | 6690 EndTest(); |
| 6695 } | 6691 } |
| 6696 | 6692 |
| 6697 void AfterTest() override {} | 6693 void AfterTest() override {} |
| 6698 }; | 6694 }; |
| 6699 | 6695 |
| 6700 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPaintedDeviceScaleFactor); | 6696 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPaintedDeviceScaleFactor); |
| 6701 | 6697 |
| 6702 } // namespace | 6698 } // namespace |
| 6703 } // namespace cc | 6699 } // namespace cc |
| OLD | NEW |