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/debug/test_web_graphics_context_3d.h" | 14 #include "cc/debug/test_web_graphics_context_3d.h" |
14 #include "cc/layers/content_layer.h" | 15 #include "cc/layers/content_layer.h" |
15 #include "cc/layers/content_layer_client.h" | 16 #include "cc/layers/content_layer_client.h" |
16 #include "cc/layers/io_surface_layer.h" | 17 #include "cc/layers/io_surface_layer.h" |
17 #include "cc/layers/layer_impl.h" | 18 #include "cc/layers/layer_impl.h" |
18 #include "cc/layers/painted_scrollbar_layer.h" | 19 #include "cc/layers/painted_scrollbar_layer.h" |
19 #include "cc/layers/picture_layer.h" | 20 #include "cc/layers/picture_layer.h" |
20 #include "cc/layers/solid_color_layer.h" | 21 #include "cc/layers/solid_color_layer.h" |
21 #include "cc/layers/video_layer.h" | 22 #include "cc/layers/video_layer.h" |
(...skipping 5173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5195 size_t first_output_surface_memory_limit_; | 5196 size_t first_output_surface_memory_limit_; |
5196 size_t second_output_surface_memory_limit_; | 5197 size_t second_output_surface_memory_limit_; |
5197 FakeContentLayerClient client_; | 5198 FakeContentLayerClient client_; |
5198 scoped_refptr<FakeContentLayer> root_; | 5199 scoped_refptr<FakeContentLayer> root_; |
5199 }; | 5200 }; |
5200 | 5201 |
5201 // No output to copy for delegated renderers. | 5202 // No output to copy for delegated renderers. |
5202 SINGLE_AND_MULTI_THREAD_TEST_F( | 5203 SINGLE_AND_MULTI_THREAD_TEST_F( |
5203 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); | 5204 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); |
5204 | 5205 |
| 5206 |
| 5207 class LayerTreeHostTestAbortedCommitBreakSwapPromise |
| 5208 : public LayerTreeHostTest { |
| 5209 protected: |
| 5210 LayerTreeHostTestAbortedCommitBreakSwapPromise() |
| 5211 : commit_count_(0), commit_complete_count_(0), finish_promise_count_(0), |
| 5212 break_promise_count_(0) {} |
| 5213 |
| 5214 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 5215 settings->begin_impl_frame_scheduling_enabled = true; |
| 5216 } |
| 5217 |
| 5218 void FinishPromise() { |
| 5219 finish_promise_count_++; |
| 5220 } |
| 5221 |
| 5222 void BreakPromise(const std::string& msg) { |
| 5223 break_promise_count_++; |
| 5224 } |
| 5225 |
| 5226 virtual void WillBeginMainFrame() OVERRIDE { |
| 5227 SwapPromise swap_promise( |
| 5228 base::Bind( |
| 5229 &LayerTreeHostTestAbortedCommitBreakSwapPromise::FinishPromise, |
| 5230 base::Unretained(this)), |
| 5231 base::Bind( |
| 5232 &LayerTreeHostTestAbortedCommitBreakSwapPromise::BreakPromise, |
| 5233 base::Unretained(this))); |
| 5234 layer_tree_host()->QueueSwapPromise(swap_promise); |
| 5235 } |
| 5236 |
| 5237 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 5238 |
| 5239 virtual void DidCommit() OVERRIDE { |
| 5240 commit_count_++; |
| 5241 if (commit_count_ == 2) { |
| 5242 // This commit will finish. |
| 5243 layer_tree_host()->SetNeedsCommit(); |
| 5244 } |
| 5245 } |
| 5246 |
| 5247 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 5248 commit_complete_count_++; |
| 5249 if (commit_complete_count_ == 1) { |
| 5250 // This commit will be aborted. |
| 5251 host_impl->SetNeedsCommit(); |
| 5252 } else { |
| 5253 EndTest(); |
| 5254 } |
| 5255 } |
| 5256 |
| 5257 virtual void AfterTest() OVERRIDE { |
| 5258 // 3 commits are scheduled. 2 completes. 1 is aborted. |
| 5259 // The first completed commit casues swap buffer wihch finishes the promise. |
| 5260 // The last completed commit does not reach swap buffer cause the |
| 5261 // test is already ended. |
| 5262 EXPECT_EQ(commit_count_, 3); |
| 5263 EXPECT_EQ(commit_complete_count_, 2); |
| 5264 EXPECT_EQ(finish_promise_count_, 1); |
| 5265 EXPECT_EQ(break_promise_count_, 1); |
| 5266 } |
| 5267 |
| 5268 int commit_count_; |
| 5269 int commit_complete_count_; |
| 5270 int finish_promise_count_; |
| 5271 int break_promise_count_; |
| 5272 }; |
| 5273 |
| 5274 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortedCommitBreakSwapPromise); |
| 5275 |
| 5276 |
| 5277 class LayerTreeHostTestNoSwapBreakSwapPromise |
| 5278 : public LayerTreeHostTest { |
| 5279 protected: |
| 5280 LayerTreeHostTestNoSwapBreakSwapPromise() |
| 5281 : commit_count_(0), commit_complete_count_(0), finish_promise_count_(0), |
| 5282 break_promise_count_(0) {} |
| 5283 |
| 5284 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 5285 settings->begin_impl_frame_scheduling_enabled = true; |
| 5286 } |
| 5287 |
| 5288 void FinishPromise() { |
| 5289 finish_promise_count_++; |
| 5290 } |
| 5291 |
| 5292 void BreakPromise(const std::string& msg) { |
| 5293 break_promise_count_++; |
| 5294 } |
| 5295 |
| 5296 virtual void WillBeginMainFrame() OVERRIDE { |
| 5297 SwapPromise swap_promise( |
| 5298 base::Bind(&LayerTreeHostTestNoSwapBreakSwapPromise::FinishPromise, |
| 5299 base::Unretained(this)), |
| 5300 base::Bind(&LayerTreeHostTestNoSwapBreakSwapPromise::BreakPromise, |
| 5301 base::Unretained(this))); |
| 5302 layer_tree_host()->QueueSwapPromise(swap_promise); |
| 5303 } |
| 5304 |
| 5305 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 5306 |
| 5307 virtual void DidCommit() OVERRIDE { |
| 5308 commit_count_++; |
| 5309 // Schedule a new commit. |
| 5310 layer_tree_host()->SetNeedsCommit(); |
| 5311 } |
| 5312 |
| 5313 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 5314 commit_complete_count_++; |
| 5315 if (commit_complete_count_ == 3) |
| 5316 EndTest(); |
| 5317 } |
| 5318 |
| 5319 virtual void AfterTest() OVERRIDE { |
| 5320 // 3 commits are scheduled. 3 completes. |
| 5321 // 2 completed commits reach swap buffer. the first swap buffer finishes |
| 5322 // the promise. For the second swap buffer, no damage for the frame, so it |
| 5323 // breaks the swap promise. The third commit does not reach the swap buffer |
| 5324 // cause the test is ended. |
| 5325 EXPECT_EQ(commit_count_, 3); |
| 5326 EXPECT_EQ(commit_complete_count_, 3); |
| 5327 EXPECT_EQ(finish_promise_count_, 1); |
| 5328 EXPECT_EQ(break_promise_count_, 1); |
| 5329 } |
| 5330 |
| 5331 int commit_count_; |
| 5332 int commit_complete_count_; |
| 5333 int finish_promise_count_; |
| 5334 int break_promise_count_; |
| 5335 }; |
| 5336 |
| 5337 MULTI_THREAD_TEST_F(LayerTreeHostTestNoSwapBreakSwapPromise); |
| 5338 |
5205 } // namespace cc | 5339 } // namespace cc |
OLD | NEW |