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...) Expand 10 before | Expand all | Expand 10 after 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 TestSwapPromiseResult { |
| 5220 TestSwapPromiseResult() : did_swap_called(false), |
| 5221 did_not_swap_called(false), |
| 5222 dtor_called(false), |
| 5223 reason(SwapPromise::DID_NOT_SWAP_UNKNOWN) { |
| 5224 } |
| 5225 |
| 5226 bool did_swap_called; |
| 5227 bool did_not_swap_called; |
| 5228 bool dtor_called; |
| 5229 SwapPromise::DidNotSwapReason reason; |
| 5230 base::Lock lock; |
| 5231 }; |
| 5232 |
| 5233 class TestSwapPromise : public SwapPromise { |
| 5234 public: |
| 5235 explicit TestSwapPromise(TestSwapPromiseResult* result) |
| 5236 : result_(result) { |
| 5237 } |
| 5238 |
| 5239 virtual ~TestSwapPromise() { |
| 5240 base::AutoLock lock(result_->lock); |
| 5241 result_->dtor_called = true; |
| 5242 } |
| 5243 |
| 5244 virtual void DidSwap() OVERRIDE { |
| 5245 base::AutoLock lock(result_->lock); |
| 5246 EXPECT_FALSE(result_->did_swap_called); |
| 5247 EXPECT_FALSE(result_->did_not_swap_called); |
| 5248 result_->did_swap_called = true; |
| 5249 } |
| 5250 |
| 5251 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE { |
| 5252 base::AutoLock lock(result_->lock); |
| 5253 EXPECT_FALSE(result_->did_swap_called); |
| 5254 EXPECT_FALSE(result_->did_not_swap_called); |
| 5255 result_->did_not_swap_called = true; |
| 5256 result_->reason = reason; |
| 5257 } |
| 5258 |
| 5259 private: |
| 5260 // Not owned. |
| 5261 TestSwapPromiseResult* result_; |
| 5262 }; |
| 5263 |
| 5264 class LayerTreeHostTestBreakSwapPromise |
| 5265 : public LayerTreeHostTest { |
| 5266 protected: |
| 5267 LayerTreeHostTestBreakSwapPromise() |
| 5268 : commit_count_(0), commit_complete_count_(0) { |
| 5269 } |
| 5270 |
| 5271 virtual void WillBeginMainFrame() OVERRIDE { |
| 5272 ASSERT_LE(commit_count_, 2); |
| 5273 scoped_ptr<SwapPromise> swap_promise(new TestSwapPromise( |
| 5274 &swap_promise_result_[commit_count_])); |
| 5275 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
| 5276 } |
| 5277 |
| 5278 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 5279 |
| 5280 virtual void DidCommit() OVERRIDE { |
| 5281 commit_count_++; |
| 5282 if (commit_count_ == 2) { |
| 5283 // This commit will finish. |
| 5284 layer_tree_host()->SetNeedsCommit(); |
| 5285 } |
| 5286 } |
| 5287 |
| 5288 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 5289 commit_complete_count_++; |
| 5290 if (commit_complete_count_ == 1) { |
| 5291 // This commit will be aborted because no actual update. |
| 5292 PostSetNeedsUpdateLayersToMainThread(); |
| 5293 } else { |
| 5294 EndTest(); |
| 5295 } |
| 5296 } |
| 5297 |
| 5298 virtual void AfterTest() OVERRIDE { |
| 5299 // 3 commits are scheduled. 2 completes. 1 is aborted. |
| 5300 EXPECT_EQ(commit_count_, 3); |
| 5301 EXPECT_EQ(commit_complete_count_, 2); |
| 5302 |
| 5303 { |
| 5304 // The first commit completes and causes swap buffer which finishes |
| 5305 // the promise. |
| 5306 base::AutoLock lock(swap_promise_result_[0].lock); |
| 5307 EXPECT_TRUE(swap_promise_result_[0].did_swap_called); |
| 5308 EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called); |
| 5309 EXPECT_TRUE(swap_promise_result_[0].dtor_called); |
| 5310 } |
| 5311 |
| 5312 { |
| 5313 // The second commit aborts. |
| 5314 base::AutoLock lock(swap_promise_result_[1].lock); |
| 5315 EXPECT_FALSE(swap_promise_result_[1].did_swap_called); |
| 5316 EXPECT_TRUE(swap_promise_result_[1].did_not_swap_called); |
| 5317 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_[1].reason); |
| 5318 EXPECT_TRUE(swap_promise_result_[1].dtor_called); |
| 5319 } |
| 5320 |
| 5321 { |
| 5322 // The last commit completes but it does not cause swap buffer because |
| 5323 // there is no damage in the frame data. |
| 5324 base::AutoLock lock(swap_promise_result_[2].lock); |
| 5325 EXPECT_FALSE(swap_promise_result_[2].did_swap_called); |
| 5326 EXPECT_TRUE(swap_promise_result_[2].did_not_swap_called); |
| 5327 EXPECT_EQ(SwapPromise::SWAP_FAILS, swap_promise_result_[2].reason); |
| 5328 EXPECT_TRUE(swap_promise_result_[2].dtor_called); |
| 5329 } |
| 5330 } |
| 5331 |
| 5332 int commit_count_; |
| 5333 int commit_complete_count_; |
| 5334 TestSwapPromiseResult swap_promise_result_[3]; |
| 5335 }; |
| 5336 |
| 5337 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); |
| 5338 |
5218 } // namespace cc | 5339 } // namespace cc |
OLD | NEW |