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" |
11 #include "cc/animation/timing_function.h" | 11 #include "cc/animation/timing_function.h" |
12 #include "cc/base/swap_promise.h" | |
12 #include "cc/debug/frame_rate_counter.h" | 13 #include "cc/debug/frame_rate_counter.h" |
13 #include "cc/layers/content_layer.h" | 14 #include "cc/layers/content_layer.h" |
14 #include "cc/layers/content_layer_client.h" | 15 #include "cc/layers/content_layer_client.h" |
15 #include "cc/layers/io_surface_layer.h" | 16 #include "cc/layers/io_surface_layer.h" |
16 #include "cc/layers/layer_impl.h" | 17 #include "cc/layers/layer_impl.h" |
17 #include "cc/layers/painted_scrollbar_layer.h" | 18 #include "cc/layers/painted_scrollbar_layer.h" |
18 #include "cc/layers/picture_layer.h" | 19 #include "cc/layers/picture_layer.h" |
19 #include "cc/layers/solid_color_layer.h" | 20 #include "cc/layers/solid_color_layer.h" |
20 #include "cc/layers/video_layer.h" | 21 #include "cc/layers/video_layer.h" |
21 #include "cc/output/begin_frame_args.h" | 22 #include "cc/output/begin_frame_args.h" |
(...skipping 5186 matching lines...) Loading... | |
5208 size_t first_output_surface_memory_limit_; | 5209 size_t first_output_surface_memory_limit_; |
5209 size_t second_output_surface_memory_limit_; | 5210 size_t second_output_surface_memory_limit_; |
5210 FakeContentLayerClient client_; | 5211 FakeContentLayerClient client_; |
5211 scoped_refptr<FakeContentLayer> root_; | 5212 scoped_refptr<FakeContentLayer> root_; |
5212 }; | 5213 }; |
5213 | 5214 |
5214 // No output to copy for delegated renderers. | 5215 // No output to copy for delegated renderers. |
5215 SINGLE_AND_MULTI_THREAD_TEST_F( | 5216 SINGLE_AND_MULTI_THREAD_TEST_F( |
5216 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); | 5217 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); |
5217 | 5218 |
5219 struct SwapPromiseResult { | |
5220 bool did_swap_called; | |
5221 bool did_not_swap_called; | |
5222 bool dtor_called; | |
5223 SwapPromise::DidNotSwapReason reason; | |
5224 }; | |
5225 | |
5226 class TestSwapPromise : public SwapPromise { | |
5227 public: | |
5228 explicit TestSwapPromise(SwapPromiseResult* result) | |
5229 : SwapPromise(SWAP_PROMISE_UNKNOWN), | |
5230 result_(result) { | |
5231 } | |
5232 | |
5233 virtual ~TestSwapPromise() { | |
5234 result_->dtor_called = true; | |
5235 } | |
5236 | |
5237 virtual void DidSwap() OVERRIDE { | |
5238 EXPECT_FALSE(result_->did_swap_called); | |
5239 EXPECT_FALSE(result_->did_not_swap_called); | |
5240 result_->did_swap_called = true; | |
5241 } | |
5242 | |
5243 virtual void DidNotSwap(DidNotSwapReason reason) { | |
5244 EXPECT_FALSE(result_->did_swap_called); | |
5245 EXPECT_FALSE(result_->did_not_swap_called); | |
5246 result_->did_not_swap_called = true; | |
5247 result_->reason = reason; | |
5248 } | |
5249 | |
5250 private: | |
5251 // Not owned. | |
5252 SwapPromiseResult* result_; | |
5253 }; | |
5254 | |
5255 class LayerTreeHostTestBreakSwapPromise | |
5256 : public LayerTreeHostTest { | |
5257 protected: | |
5258 LayerTreeHostTestBreakSwapPromise() | |
5259 : commit_count_(0), commit_complete_count_(0) { | |
5260 memset(&swap_promise_result_, 0, sizeof(swap_promise_result_)); | |
danakj
2013/11/13 23:22:09
Make a constructor on SwapPromiseResult instead of
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
Done.
| |
5261 } | |
5262 | |
5263 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | |
5264 settings->begin_impl_frame_scheduling_enabled = true; | |
danakj
2013/11/13 23:22:09
Why is this needed?
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
removed.
| |
5265 } | |
5266 | |
5267 virtual void WillBeginMainFrame() OVERRIDE { | |
5268 layer_tree_host()->QueueSwapPromise( | |
5269 new TestSwapPromise(&swap_promise_result_[commit_count_])); | |
5270 } | |
5271 | |
5272 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | |
5273 | |
5274 virtual void DidCommit() OVERRIDE { | |
5275 commit_count_++; | |
danakj
2013/11/13 23:22:09
You can use layer_tree_host()->source_frame_number
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
I think here what we want is that after we have tr
| |
5276 if (commit_count_ == 2) { | |
5277 // This commit will finish. | |
5278 layer_tree_host()->SetNeedsCommit(); | |
5279 } | |
5280 } | |
5281 | |
5282 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | |
5283 commit_complete_count_++; | |
5284 if (commit_complete_count_ == 1) { | |
5285 // This commit will be aborted. | |
danakj
2013/11/13 23:22:09
I think that a better way to make an aborted commi
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
Done.
| |
5286 host_impl->SetNeedsCommit(); | |
5287 } else { | |
5288 EndTest(); | |
5289 } | |
5290 } | |
5291 | |
5292 virtual void AfterTest() OVERRIDE { | |
5293 // 3 commits are scheduled. 2 completes. 1 is aborted. | |
5294 EXPECT_EQ(commit_count_, 3); | |
5295 EXPECT_EQ(commit_complete_count_, 2); | |
5296 | |
5297 // The first commit completes and causes swap buffer wihch finishes | |
danakj
2013/11/13 23:22:09
which
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
Done.
| |
5298 // the promise. | |
5299 EXPECT_TRUE(swap_promise_result_[0].did_swap_called); | |
5300 EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called); | |
5301 EXPECT_TRUE(swap_promise_result_[0].dtor_called); | |
5302 | |
5303 // The second commit aborts. | |
5304 EXPECT_FALSE(swap_promise_result_[1].did_swap_called); | |
5305 EXPECT_TRUE(swap_promise_result_[1].did_not_swap_called); | |
5306 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_[1].reason); | |
5307 EXPECT_TRUE(swap_promise_result_[1].dtor_called); | |
5308 | |
5309 // The last commit completes but it does not cause swap buffer because | |
5310 // there is no damage in the frame data. | |
5311 EXPECT_FALSE(swap_promise_result_[2].did_swap_called); | |
5312 EXPECT_TRUE(swap_promise_result_[2].did_not_swap_called); | |
5313 EXPECT_EQ(SwapPromise::SWAP_FAILS, swap_promise_result_[2].reason); | |
5314 EXPECT_TRUE(swap_promise_result_[2].dtor_called); | |
5315 } | |
5316 | |
5317 int commit_count_; | |
5318 int commit_complete_count_; | |
5319 SwapPromiseResult swap_promise_result_[3]; | |
5320 }; | |
5321 | |
5322 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); | |
5323 | |
5218 } // namespace cc | 5324 } // namespace cc |
OLD | NEW |