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/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "cc/debug/rendering_stats_instrumentation.h" | |
| 17 #include "cc/test/begin_frame_args_test.h" | 18 #include "cc/test/begin_frame_args_test.h" |
| 18 #include "cc/test/ordered_simple_task_runner.h" | 19 #include "cc/test/ordered_simple_task_runner.h" |
| 19 #include "cc/test/scheduler_test_common.h" | 20 #include "cc/test/scheduler_test_common.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 23 |
| 23 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ | 24 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ |
| 24 do { \ | 25 do { \ |
| 25 EXPECT_EQ(expected_num_actions, client->num_actions_()); \ | 26 EXPECT_EQ(expected_num_actions, client->num_actions_()); \ |
| 26 if (action_index >= 0) { \ | 27 if (action_index >= 0) { \ |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 127 |
| 127 if (automatic_swap_ack_) | 128 if (automatic_swap_ack_) |
| 128 scheduler_->DidSwapBuffersComplete(); | 129 scheduler_->DidSwapBuffersComplete(); |
| 129 } | 130 } |
| 130 return result; | 131 return result; |
| 131 } | 132 } |
| 132 DrawResult ScheduledActionDrawAndSwapForced() override { | 133 DrawResult ScheduledActionDrawAndSwapForced() override { |
| 133 PushAction("ScheduledActionDrawAndSwapForced"); | 134 PushAction("ScheduledActionDrawAndSwapForced"); |
| 134 return DRAW_SUCCESS; | 135 return DRAW_SUCCESS; |
| 135 } | 136 } |
| 136 void ScheduledActionCommit() override { PushAction("ScheduledActionCommit"); } | 137 void ScheduledActionCommit() override { |
| 138 PushAction("ScheduledActionCommit"); | |
| 139 scheduler_->DidCommit(); | |
| 140 } | |
| 137 void ScheduledActionActivateSyncTree() override { | 141 void ScheduledActionActivateSyncTree() override { |
| 138 PushAction("ScheduledActionActivateSyncTree"); | 142 PushAction("ScheduledActionActivateSyncTree"); |
| 139 } | 143 } |
| 140 void ScheduledActionBeginOutputSurfaceCreation() override { | 144 void ScheduledActionBeginOutputSurfaceCreation() override { |
| 141 PushAction("ScheduledActionBeginOutputSurfaceCreation"); | 145 PushAction("ScheduledActionBeginOutputSurfaceCreation"); |
| 142 } | 146 } |
| 143 void ScheduledActionPrepareTiles() override { | 147 void ScheduledActionPrepareTiles() override { |
| 144 PushAction("ScheduledActionPrepareTiles"); | 148 PushAction("ScheduledActionPrepareTiles"); |
| 149 scheduler_->WillPrepareTiles(); | |
| 150 scheduler_->DidPrepareTiles(); | |
|
picksi
2015/06/19 13:04:28
You seem to be measuring nothing here?
brianderson
2015/06/19 17:24:27
Every WillPrepareTiles must be followed by a DidPr
| |
| 145 } | 151 } |
| 146 void ScheduledActionInvalidateOutputSurface() override { | 152 void ScheduledActionInvalidateOutputSurface() override { |
| 147 actions_.push_back("ScheduledActionInvalidateOutputSurface"); | 153 actions_.push_back("ScheduledActionInvalidateOutputSurface"); |
| 148 states_.push_back(scheduler_->AsValue()); | 154 states_.push_back(scheduler_->AsValue()); |
| 149 } | 155 } |
| 150 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { | 156 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { |
| 151 if (log_anticipated_draw_time_change_) | 157 if (log_anticipated_draw_time_change_) |
| 152 PushAction("DidAnticipatedDrawTimeChange"); | 158 PushAction("DidAnticipatedDrawTimeChange"); |
| 153 } | 159 } |
| 154 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } | |
| 155 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | |
| 156 return base::TimeDelta(); | |
| 157 } | |
| 158 base::TimeDelta CommitToActivateDurationEstimate() override { | |
| 159 return base::TimeDelta(); | |
| 160 } | |
| 161 | 160 |
| 162 void SendBeginFramesToChildren(const BeginFrameArgs& args) override { | 161 void SendBeginFramesToChildren(const BeginFrameArgs& args) override { |
| 163 begin_frame_args_sent_to_children_ = args; | 162 begin_frame_args_sent_to_children_ = args; |
| 164 } | 163 } |
| 165 | 164 |
| 166 void SendBeginMainFrameNotExpectedSoon() override { | 165 void SendBeginMainFrameNotExpectedSoon() override { |
| 167 PushAction("SendBeginMainFrameNotExpectedSoon"); | 166 PushAction("SendBeginMainFrameNotExpectedSoon"); |
| 168 } | 167 } |
| 169 | 168 |
| 170 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { | 169 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 197 int num_draws_; | 196 int num_draws_; |
| 198 bool log_anticipated_draw_time_change_; | 197 bool log_anticipated_draw_time_change_; |
| 199 BeginFrameArgs begin_frame_args_sent_to_children_; | 198 BeginFrameArgs begin_frame_args_sent_to_children_; |
| 200 base::TimeTicks posted_begin_impl_frame_deadline_; | 199 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 201 std::vector<const char*> actions_; | 200 std::vector<const char*> actions_; |
| 202 std::vector<scoped_refptr<base::trace_event::ConvertableToTraceFormat>> | 201 std::vector<scoped_refptr<base::trace_event::ConvertableToTraceFormat>> |
| 203 states_; | 202 states_; |
| 204 TestScheduler* scheduler_; | 203 TestScheduler* scheduler_; |
| 205 }; | 204 }; |
| 206 | 205 |
| 207 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | |
| 208 public: | |
| 209 SchedulerClientWithFixedEstimates( | |
| 210 base::TimeDelta draw_duration, | |
| 211 base::TimeDelta begin_main_frame_to_commit_duration, | |
| 212 base::TimeDelta commit_to_activate_duration) | |
| 213 : draw_duration_(draw_duration), | |
| 214 begin_main_frame_to_commit_duration_( | |
| 215 begin_main_frame_to_commit_duration), | |
| 216 commit_to_activate_duration_(commit_to_activate_duration) {} | |
| 217 | |
| 218 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } | |
| 219 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | |
| 220 return begin_main_frame_to_commit_duration_; | |
| 221 } | |
| 222 base::TimeDelta CommitToActivateDurationEstimate() override { | |
| 223 return commit_to_activate_duration_; | |
| 224 } | |
| 225 | |
| 226 private: | |
| 227 base::TimeDelta draw_duration_; | |
| 228 base::TimeDelta begin_main_frame_to_commit_duration_; | |
| 229 base::TimeDelta commit_to_activate_duration_; | |
| 230 }; | |
| 231 | |
| 232 class FakeExternalBeginFrameSource : public BeginFrameSourceBase { | 206 class FakeExternalBeginFrameSource : public BeginFrameSourceBase { |
| 233 public: | 207 public: |
| 234 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) | 208 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) |
| 235 : client_(client) {} | 209 : client_(client) {} |
| 236 ~FakeExternalBeginFrameSource() override {} | 210 ~FakeExternalBeginFrameSource() override {} |
| 237 | 211 |
| 238 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | 212 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
| 239 if (needs_begin_frames) { | 213 if (needs_begin_frames) { |
| 240 client_->PushAction("SetNeedsBeginFrames(true)"); | 214 client_->PushAction("SetNeedsBeginFrames(true)"); |
| 241 } else { | 215 } else { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 269 | 243 |
| 270 protected: | 244 protected: |
| 271 TestScheduler* CreateScheduler() { | 245 TestScheduler* CreateScheduler() { |
| 272 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; | 246 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; |
| 273 if (scheduler_settings_.use_external_begin_frame_source) { | 247 if (scheduler_settings_.use_external_begin_frame_source) { |
| 274 fake_external_begin_frame_source.reset( | 248 fake_external_begin_frame_source.reset( |
| 275 new FakeExternalBeginFrameSource(client_.get())); | 249 new FakeExternalBeginFrameSource(client_.get())); |
| 276 fake_external_begin_frame_source_ = | 250 fake_external_begin_frame_source_ = |
| 277 fake_external_begin_frame_source.get(); | 251 fake_external_begin_frame_source.get(); |
| 278 } | 252 } |
| 253 rendering_stats_instrumentation_ = RenderingStatsInstrumentation::Create(); | |
| 279 scheduler_ = TestScheduler::Create(now_src_.get(), client_.get(), | 254 scheduler_ = TestScheduler::Create(now_src_.get(), client_.get(), |
| 280 scheduler_settings_, 0, task_runner_, | 255 scheduler_settings_, 0, task_runner_, |
| 281 fake_external_begin_frame_source.Pass()); | 256 fake_external_begin_frame_source.Pass(), |
| 257 rendering_stats_instrumentation_.get()); | |
| 282 DCHECK(scheduler_); | 258 DCHECK(scheduler_); |
| 283 client_->set_scheduler(scheduler_.get()); | 259 client_->set_scheduler(scheduler_.get()); |
| 284 return scheduler_.get(); | 260 return scheduler_.get(); |
| 285 } | 261 } |
| 286 | 262 |
| 287 void CreateSchedulerAndInitSurface() { | 263 void CreateSchedulerAndInitSurface() { |
| 288 CreateScheduler(); | 264 CreateScheduler(); |
| 289 EXPECT_SCOPED(InitializeOutputSurfaceAndFirstCommit()); | 265 EXPECT_SCOPED(InitializeOutputSurfaceAndFirstCommit()); |
| 290 } | 266 } |
| 291 | 267 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 scheduler_->SetNeedsCommit(); | 308 scheduler_->SetNeedsCommit(); |
| 333 EXPECT_TRUE(client_->needs_begin_frames()); | 309 EXPECT_TRUE(client_->needs_begin_frames()); |
| 334 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 310 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 335 client_->Reset(); | 311 client_->Reset(); |
| 336 | 312 |
| 337 { | 313 { |
| 338 SCOPED_TRACE("Do first frame to commit after initialize."); | 314 SCOPED_TRACE("Do first frame to commit after initialize."); |
| 339 AdvanceFrame(); | 315 AdvanceFrame(); |
| 340 | 316 |
| 341 scheduler_->NotifyBeginMainFrameStarted(); | 317 scheduler_->NotifyBeginMainFrameStarted(); |
| 342 scheduler_->NotifyReadyToCommitThenActivateIfNeeded(); | 318 scheduler_->NotifyReadyToCommit(); |
| 319 scheduler_->NotifyReadyToActivate(); | |
| 343 | 320 |
| 344 EXPECT_FALSE(scheduler_->CommitPending()); | 321 EXPECT_FALSE(scheduler_->CommitPending()); |
| 345 | 322 |
| 346 if (scheduler_settings_.using_synchronous_renderer_compositor) { | 323 if (scheduler_settings_.using_synchronous_renderer_compositor) { |
| 347 scheduler_->SetNeedsRedraw(); | 324 scheduler_->SetNeedsRedraw(); |
| 348 scheduler_->OnDrawForOutputSurface(); | 325 scheduler_->OnDrawForOutputSurface(); |
| 349 } else { | 326 } else { |
| 350 // Run the posted deadline task. | 327 // Run the posted deadline task. |
| 351 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 328 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 352 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 329 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 428 void BeginFramesNotFromClient_SwapThrottled( | 405 void BeginFramesNotFromClient_SwapThrottled( |
| 429 bool use_external_begin_frame_source, | 406 bool use_external_begin_frame_source, |
| 430 bool throttle_frame_production); | 407 bool throttle_frame_production); |
| 431 | 408 |
| 432 scoped_ptr<base::SimpleTestTickClock> now_src_; | 409 scoped_ptr<base::SimpleTestTickClock> now_src_; |
| 433 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 410 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
| 434 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; | 411 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; |
| 435 SchedulerSettings scheduler_settings_; | 412 SchedulerSettings scheduler_settings_; |
| 436 scoped_ptr<FakeSchedulerClient> client_; | 413 scoped_ptr<FakeSchedulerClient> client_; |
| 437 scoped_ptr<TestScheduler> scheduler_; | 414 scoped_ptr<TestScheduler> scheduler_; |
| 415 scoped_ptr<RenderingStatsInstrumentation> rendering_stats_instrumentation_; | |
| 438 }; | 416 }; |
| 439 | 417 |
| 440 TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 418 TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
| 441 scheduler_settings_.use_external_begin_frame_source = true; | 419 scheduler_settings_.use_external_begin_frame_source = true; |
| 442 SetUpScheduler(false); | 420 SetUpScheduler(false); |
| 443 scheduler_->SetCanStart(); | 421 scheduler_->SetCanStart(); |
| 444 scheduler_->SetVisible(true); | 422 scheduler_->SetVisible(true); |
| 445 scheduler_->SetCanDraw(true); | 423 scheduler_->SetCanDraw(true); |
| 446 | 424 |
| 447 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | 425 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 457 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 480 EXPECT_TRUE(client_->needs_begin_frames()); | 458 EXPECT_TRUE(client_->needs_begin_frames()); |
| 481 | 459 |
| 482 client_->Reset(); | 460 client_->Reset(); |
| 483 EXPECT_SCOPED(AdvanceFrame()); | 461 EXPECT_SCOPED(AdvanceFrame()); |
| 484 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | 462 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); |
| 485 } | 463 } |
| 486 | 464 |
| 487 TEST_F(SchedulerTest, SendBeginFramesToChildrenDeadlineNotAdjusted) { | 465 TEST_F(SchedulerTest, SendBeginFramesToChildrenDeadlineNotAdjusted) { |
| 488 // Set up client with specified estimates. | 466 // Set up client with specified estimates. |
| 489 SchedulerClientWithFixedEstimates* client = | |
| 490 new SchedulerClientWithFixedEstimates( | |
| 491 base::TimeDelta::FromMilliseconds(1), | |
| 492 base::TimeDelta::FromMilliseconds(2), | |
| 493 base::TimeDelta::FromMilliseconds(4)); | |
| 494 scheduler_settings_.use_external_begin_frame_source = true; | 467 scheduler_settings_.use_external_begin_frame_source = true; |
| 495 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 468 SetUpScheduler(true); |
| 469 scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); | |
| 470 scheduler_->SetBeginMainFrameToCommitDurationEstimate( | |
| 471 base::TimeDelta::FromMilliseconds(2)); | |
| 472 scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( | |
| 473 base::TimeDelta::FromMilliseconds(4)); | |
| 496 | 474 |
| 497 EXPECT_FALSE(client_->needs_begin_frames()); | 475 EXPECT_FALSE(client_->needs_begin_frames()); |
| 498 scheduler_->SetChildrenNeedBeginFrames(true); | 476 scheduler_->SetChildrenNeedBeginFrames(true); |
| 499 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 477 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 500 EXPECT_TRUE(client_->needs_begin_frames()); | 478 EXPECT_TRUE(client_->needs_begin_frames()); |
| 501 | 479 |
| 502 client_->Reset(); | 480 client_->Reset(); |
| 503 | 481 |
| 504 BeginFrameArgs frame_args = | 482 BeginFrameArgs frame_args = |
| 505 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 483 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 task_runner().RunPendingTasks(); // Run posted deadline. | 718 task_runner().RunPendingTasks(); // Run posted deadline. |
| 741 EXPECT_FALSE(client_->needs_begin_frames()); | 719 EXPECT_FALSE(client_->needs_begin_frames()); |
| 742 client_->Reset(); | 720 client_->Reset(); |
| 743 } | 721 } |
| 744 | 722 |
| 745 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 723 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 746 public: | 724 public: |
| 747 SchedulerClientThatsetNeedsDrawInsideDraw() | 725 SchedulerClientThatsetNeedsDrawInsideDraw() |
| 748 : FakeSchedulerClient(), request_redraws_(false) {} | 726 : FakeSchedulerClient(), request_redraws_(false) {} |
| 749 | 727 |
| 750 void ScheduledActionSendBeginMainFrame() override {} | |
| 751 | |
| 752 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } | 728 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } |
| 753 | 729 |
| 754 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 730 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 755 // Only SetNeedsRedraw the first time this is called | 731 // Only SetNeedsRedraw the first time this is called |
| 756 if (request_redraws_) { | 732 if (request_redraws_) { |
| 757 scheduler_->SetNeedsRedraw(); | 733 scheduler_->SetNeedsRedraw(); |
| 758 } | 734 } |
| 759 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 735 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 760 } | 736 } |
| 761 | 737 |
| 762 DrawResult ScheduledActionDrawAndSwapForced() override { | 738 DrawResult ScheduledActionDrawAndSwapForced() override { |
| 763 NOTREACHED(); | 739 NOTREACHED(); |
| 764 return DRAW_SUCCESS; | 740 return DRAW_SUCCESS; |
| 765 } | 741 } |
| 766 | 742 |
| 767 void ScheduledActionCommit() override {} | |
| 768 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | |
| 769 | |
| 770 private: | 743 private: |
| 771 bool request_redraws_; | 744 bool request_redraws_; |
| 772 }; | 745 }; |
| 773 | 746 |
| 774 // Tests for two different situations: | 747 // Tests for two different situations: |
| 775 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 748 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
| 776 // a ScheduledActionDrawAndSwap | 749 // a ScheduledActionDrawAndSwap |
| 777 // 2. the scheduler drawing twice inside a single tick | 750 // 2. the scheduler drawing twice inside a single tick |
| 778 TEST_F(SchedulerTest, RequestRedrawInsideDraw) { | 751 TEST_F(SchedulerTest, RequestRedrawInsideDraw) { |
| 779 SchedulerClientThatsetNeedsDrawInsideDraw* client = | 752 SchedulerClientThatsetNeedsDrawInsideDraw* client = |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 EXPECT_TRUE(scheduler_->CommitPending()); | 827 EXPECT_TRUE(scheduler_->CommitPending()); |
| 855 EXPECT_FALSE(scheduler_->RedrawPending()); | 828 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 856 EXPECT_TRUE(client->needs_begin_frames()); | 829 EXPECT_TRUE(client->needs_begin_frames()); |
| 857 } | 830 } |
| 858 | 831 |
| 859 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 832 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 860 public: | 833 public: |
| 861 SchedulerClientThatSetNeedsCommitInsideDraw() | 834 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 862 : set_needs_commit_on_next_draw_(false) {} | 835 : set_needs_commit_on_next_draw_(false) {} |
| 863 | 836 |
| 864 void ScheduledActionSendBeginMainFrame() override {} | |
| 865 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 837 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 866 // Only SetNeedsCommit the first time this is called | 838 // Only SetNeedsCommit the first time this is called |
| 867 if (set_needs_commit_on_next_draw_) { | 839 if (set_needs_commit_on_next_draw_) { |
| 868 scheduler_->SetNeedsCommit(); | 840 scheduler_->SetNeedsCommit(); |
| 869 set_needs_commit_on_next_draw_ = false; | 841 set_needs_commit_on_next_draw_ = false; |
| 870 } | 842 } |
| 871 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 843 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 872 } | 844 } |
| 873 | 845 |
| 874 DrawResult ScheduledActionDrawAndSwapForced() override { | 846 DrawResult ScheduledActionDrawAndSwapForced() override { |
| 875 NOTREACHED(); | 847 NOTREACHED(); |
| 876 return DRAW_SUCCESS; | 848 return DRAW_SUCCESS; |
| 877 } | 849 } |
| 878 | 850 |
| 879 void ScheduledActionCommit() override {} | |
| 880 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | |
| 881 | |
| 882 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 851 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
| 883 | 852 |
| 884 private: | 853 private: |
| 885 bool set_needs_commit_on_next_draw_; | 854 bool set_needs_commit_on_next_draw_; |
| 886 }; | 855 }; |
| 887 | 856 |
| 888 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that | 857 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that |
| 889 // happen inside a ScheduledActionDrawAndSwap | 858 // happen inside a ScheduledActionDrawAndSwap |
| 890 TEST_F(SchedulerTest, RequestCommitInsideDraw) { | 859 TEST_F(SchedulerTest, RequestCommitInsideDraw) { |
| 891 SchedulerClientThatSetNeedsCommitInsideDraw* client = | 860 SchedulerClientThatSetNeedsCommitInsideDraw* client = |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1123 // again. | 1092 // again. |
| 1124 scheduler_->SetNeedsPrepareTiles(); | 1093 scheduler_->SetNeedsPrepareTiles(); |
| 1125 scheduler_->SetNeedsRedraw(); | 1094 scheduler_->SetNeedsRedraw(); |
| 1126 client_->Reset(); | 1095 client_->Reset(); |
| 1127 EXPECT_SCOPED(AdvanceFrame()); | 1096 EXPECT_SCOPED(AdvanceFrame()); |
| 1128 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1097 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1129 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1098 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1130 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1099 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1131 | 1100 |
| 1132 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1101 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1102 scheduler_->WillPrepareTiles(); | |
| 1133 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1103 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1134 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1104 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1135 | 1105 |
| 1136 client_->Reset(); | 1106 client_->Reset(); |
| 1137 task_runner().RunPendingTasks(); // Run posted deadline. | 1107 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1138 EXPECT_EQ(1, client_->num_draws()); | 1108 EXPECT_EQ(1, client_->num_draws()); |
| 1139 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1109 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1140 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1110 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1141 EXPECT_FALSE(scheduler_->RedrawPending()); | 1111 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1142 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1112 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1154 client_->Reset(); | 1124 client_->Reset(); |
| 1155 task_runner().RunPendingTasks(); // Run posted deadline. | 1125 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1156 EXPECT_EQ(1, client_->num_draws()); | 1126 EXPECT_EQ(1, client_->num_draws()); |
| 1157 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1127 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1158 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1128 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1159 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1129 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 1160 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1130 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1161 EXPECT_FALSE(scheduler_->RedrawPending()); | 1131 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1162 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1132 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1163 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1133 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1164 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | |
| 1165 | 1134 |
| 1166 // If we get another DidPrepareTiles within the same frame, we should | 1135 // If we get another DidPrepareTiles within the same frame, we should |
| 1167 // not PrepareTiles on the next frame. | 1136 // not PrepareTiles on the next frame. |
| 1137 scheduler_->WillPrepareTiles(); | |
| 1168 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1138 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1169 scheduler_->SetNeedsPrepareTiles(); | 1139 scheduler_->SetNeedsPrepareTiles(); |
| 1170 scheduler_->SetNeedsRedraw(); | 1140 scheduler_->SetNeedsRedraw(); |
| 1171 client_->Reset(); | 1141 client_->Reset(); |
| 1172 EXPECT_SCOPED(AdvanceFrame()); | 1142 EXPECT_SCOPED(AdvanceFrame()); |
| 1173 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1143 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1174 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1144 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1175 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1145 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1176 | 1146 |
| 1177 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1147 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1178 | 1148 |
| 1179 client_->Reset(); | 1149 client_->Reset(); |
| 1180 task_runner().RunPendingTasks(); // Run posted deadline. | 1150 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1181 EXPECT_EQ(1, client_->num_draws()); | 1151 EXPECT_EQ(1, client_->num_draws()); |
| 1182 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1152 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1183 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1153 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1184 EXPECT_FALSE(scheduler_->RedrawPending()); | 1154 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1185 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1155 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1186 | 1156 |
| 1187 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 1157 // If we get another DidPrepareTiles, we should not PrepareTiles on the next |
| 1188 // frame. This verifies we don't alternate calling PrepareTiles once and | 1158 // frame. This verifies we don't alternate calling PrepareTiles once and |
| 1189 // twice. | 1159 // twice. |
| 1190 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1160 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1161 scheduler_->WillPrepareTiles(); | |
| 1191 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1162 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1192 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1163 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1193 scheduler_->SetNeedsPrepareTiles(); | 1164 scheduler_->SetNeedsPrepareTiles(); |
| 1194 scheduler_->SetNeedsRedraw(); | 1165 scheduler_->SetNeedsRedraw(); |
| 1195 client_->Reset(); | 1166 client_->Reset(); |
| 1196 EXPECT_SCOPED(AdvanceFrame()); | 1167 EXPECT_SCOPED(AdvanceFrame()); |
| 1197 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1168 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1198 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1169 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1199 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1170 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1200 | 1171 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1220 client_->Reset(); | 1191 client_->Reset(); |
| 1221 task_runner().RunPendingTasks(); // Run posted deadline. | 1192 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1222 EXPECT_EQ(1, client_->num_draws()); | 1193 EXPECT_EQ(1, client_->num_draws()); |
| 1223 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1194 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1224 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1195 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1225 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1196 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 1226 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1197 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1227 EXPECT_FALSE(scheduler_->RedrawPending()); | 1198 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1228 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1199 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1229 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1200 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1230 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | |
| 1231 } | 1201 } |
| 1232 | 1202 |
| 1233 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1203 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 1234 SchedulerClientNeedsPrepareTilesInDraw* client = | 1204 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 1235 new SchedulerClientNeedsPrepareTilesInDraw; | 1205 new SchedulerClientNeedsPrepareTilesInDraw; |
| 1236 scheduler_settings_.use_external_begin_frame_source = true; | 1206 scheduler_settings_.use_external_begin_frame_source = true; |
| 1237 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 1207 SetUpScheduler(make_scoped_ptr(client).Pass(), true); |
| 1238 | 1208 |
| 1239 scheduler_->SetNeedsRedraw(); | 1209 scheduler_->SetNeedsRedraw(); |
| 1240 EXPECT_SCOPED(AdvanceFrame()); | 1210 EXPECT_SCOPED(AdvanceFrame()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1326 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 1296 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); |
| 1327 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 1297 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); |
| 1328 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 1298 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 1329 } | 1299 } |
| 1330 | 1300 |
| 1331 void SchedulerTest::MainFrameInHighLatencyMode( | 1301 void SchedulerTest::MainFrameInHighLatencyMode( |
| 1332 int64 begin_main_frame_to_commit_estimate_in_ms, | 1302 int64 begin_main_frame_to_commit_estimate_in_ms, |
| 1333 int64 commit_to_activate_estimate_in_ms, | 1303 int64 commit_to_activate_estimate_in_ms, |
| 1334 bool impl_latency_takes_priority, | 1304 bool impl_latency_takes_priority, |
| 1335 bool should_send_begin_main_frame) { | 1305 bool should_send_begin_main_frame) { |
| 1336 // Set up client with specified estimates (draw duration is set to 1). | 1306 scheduler_settings_.use_external_begin_frame_source = true; |
| 1337 SchedulerClientWithFixedEstimates* client = | 1307 SetUpScheduler(true); |
|
picksi
2015/06/19 13:04:28
I see it is a common pattern, but SetUpScheduler(t
brianderson
2015/06/19 17:24:27
Good idea. I can clean that up in a separate patch
| |
| 1338 new SchedulerClientWithFixedEstimates( | |
| 1339 base::TimeDelta::FromMilliseconds(1), | |
| 1340 base::TimeDelta::FromMilliseconds( | |
| 1341 begin_main_frame_to_commit_estimate_in_ms), | |
| 1342 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | |
| 1343 | 1308 |
| 1344 scheduler_settings_.use_external_begin_frame_source = true; | 1309 scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); |
| 1345 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 1310 scheduler_->SetBeginMainFrameToCommitDurationEstimate( |
| 1311 base::TimeDelta::FromMilliseconds( | |
| 1312 begin_main_frame_to_commit_estimate_in_ms)); | |
| 1313 scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( | |
| 1314 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | |
| 1346 | 1315 |
| 1347 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority); | 1316 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority); |
| 1348 | 1317 |
| 1349 // Impl thread hits deadline before commit finishes. | 1318 // Impl thread hits deadline before commit finishes. |
| 1350 scheduler_->SetNeedsCommit(); | 1319 scheduler_->SetNeedsCommit(); |
| 1351 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | 1320 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1352 EXPECT_SCOPED(AdvanceFrame()); | 1321 EXPECT_SCOPED(AdvanceFrame()); |
| 1353 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | 1322 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1354 task_runner().RunPendingTasks(); // Run posted deadline. | 1323 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1355 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 1324 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1356 scheduler_->NotifyBeginMainFrameStarted(); | 1325 scheduler_->NotifyBeginMainFrameStarted(); |
| 1357 scheduler_->NotifyReadyToCommit(); | 1326 scheduler_->NotifyReadyToCommit(); |
| 1358 scheduler_->NotifyReadyToActivate(); | 1327 scheduler_->NotifyReadyToActivate(); |
| 1359 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 1328 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1360 EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame")); | 1329 EXPECT_TRUE(client_->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1361 | 1330 |
| 1362 client->Reset(); | 1331 client_->Reset(); |
| 1363 scheduler_->SetNeedsCommit(); | 1332 scheduler_->SetNeedsCommit(); |
| 1364 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 1333 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1365 EXPECT_SCOPED(AdvanceFrame()); | 1334 EXPECT_SCOPED(AdvanceFrame()); |
| 1366 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 1335 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1367 task_runner().RunPendingTasks(); // Run posted deadline. | 1336 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1368 EXPECT_EQ(scheduler_->MainThreadIsInHighLatencyMode(), | 1337 EXPECT_EQ(scheduler_->MainThreadIsInHighLatencyMode(), |
| 1369 should_send_begin_main_frame); | 1338 should_send_begin_main_frame); |
| 1370 EXPECT_EQ(client->HasAction("ScheduledActionSendBeginMainFrame"), | 1339 EXPECT_EQ(client_->HasAction("ScheduledActionSendBeginMainFrame"), |
| 1371 should_send_begin_main_frame); | 1340 should_send_begin_main_frame); |
| 1372 } | 1341 } |
| 1373 | 1342 |
| 1374 TEST_F(SchedulerTest, | 1343 TEST_F(SchedulerTest, |
| 1375 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1344 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
| 1376 // Set up client so that estimates indicate that we can commit and activate | 1345 // Set up client so that estimates indicate that we can commit and activate |
| 1377 // before the deadline (~8ms by default). | 1346 // before the deadline (~8ms by default). |
| 1378 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 1, false, false)); | 1347 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 1, false, false)); |
| 1379 } | 1348 } |
| 1380 | 1349 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1400 TEST_F(SchedulerTest, | 1369 TEST_F(SchedulerTest, |
| 1401 Deadlock_NotifyReadyToCommitMakesProgressWhileSwapTrottled) { | 1370 Deadlock_NotifyReadyToCommitMakesProgressWhileSwapTrottled) { |
| 1402 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main | 1371 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main |
| 1403 // thread. This prevents the scheduler from receiving any pending swap acks. | 1372 // thread. This prevents the scheduler from receiving any pending swap acks. |
| 1404 // This test makes sure that we keep updating the TextureUploader with | 1373 // This test makes sure that we keep updating the TextureUploader with |
| 1405 // DidAnticipatedDrawTimeChange's so that it can make forward progress and | 1374 // DidAnticipatedDrawTimeChange's so that it can make forward progress and |
| 1406 // upload all the textures needed for the commit to complete. | 1375 // upload all the textures needed for the commit to complete. |
| 1407 | 1376 |
| 1408 // Since we are simulating a long commit, set up a client with draw duration | 1377 // Since we are simulating a long commit, set up a client with draw duration |
| 1409 // estimates that prevent skipping main frames to get to low latency mode. | 1378 // estimates that prevent skipping main frames to get to low latency mode. |
| 1410 SchedulerClientWithFixedEstimates* client = | |
| 1411 new SchedulerClientWithFixedEstimates( | |
| 1412 base::TimeDelta::FromMilliseconds(1), | |
| 1413 base::TimeDelta::FromMilliseconds(32), | |
| 1414 base::TimeDelta::FromMilliseconds(32)); | |
| 1415 scheduler_settings_.use_external_begin_frame_source = true; | 1379 scheduler_settings_.use_external_begin_frame_source = true; |
| 1416 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 1380 SetUpScheduler(true); |
| 1417 | 1381 |
| 1418 client->set_log_anticipated_draw_time_change(true); | 1382 scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); |
| 1383 scheduler_->SetBeginMainFrameToCommitDurationEstimate( | |
| 1384 base::TimeDelta::FromMilliseconds(32)); | |
| 1385 scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( | |
| 1386 base::TimeDelta::FromMilliseconds(32)); | |
| 1387 | |
| 1388 client_->set_log_anticipated_draw_time_change(true); | |
| 1419 | 1389 |
| 1420 BeginFrameArgs frame_args = | 1390 BeginFrameArgs frame_args = |
| 1421 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 1391 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 1422 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1392 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
| 1423 | 1393 |
| 1424 // At this point, we've drawn a frame. Start another commit, but hold off on | 1394 // At this point, we've drawn a frame. Start another commit, but hold off on |
| 1425 // the NotifyReadyToCommit for now. | 1395 // the NotifyReadyToCommit for now. |
| 1426 EXPECT_FALSE(scheduler_->CommitPending()); | 1396 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1427 scheduler_->SetNeedsCommit(); | 1397 scheduler_->SetNeedsCommit(); |
| 1428 fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); | 1398 fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); |
| 1429 EXPECT_TRUE(scheduler_->CommitPending()); | 1399 EXPECT_TRUE(scheduler_->CommitPending()); |
| 1430 | 1400 |
| 1431 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1401 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
| 1432 // blocking on the renderer. | 1402 // blocking on the renderer. |
| 1433 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1403 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1434 task_runner().RunPendingTasks(); // Run posted deadline. | 1404 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1435 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1405 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1436 scheduler_->DidSwapBuffers(); | 1406 scheduler_->DidSwapBuffers(); |
| 1437 | 1407 |
| 1438 // Spin the event loop a few times and make sure we get more | 1408 // Spin the event loop a few times and make sure we get more |
| 1439 // DidAnticipateDrawTimeChange calls every time. | 1409 // DidAnticipateDrawTimeChange calls every time. |
| 1440 int actions_so_far = client->num_actions_(); | 1410 int actions_so_far = client_->num_actions_(); |
| 1441 | 1411 |
| 1442 // Does three iterations to make sure that the timer is properly repeating. | 1412 // Does three iterations to make sure that the timer is properly repeating. |
| 1443 for (int i = 0; i < 3; ++i) { | 1413 for (int i = 0; i < 3; ++i) { |
| 1444 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1414 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1445 task_runner().DelayToNextTaskTime().InMicroseconds()) | 1415 task_runner().DelayToNextTaskTime().InMicroseconds()) |
| 1446 << scheduler_->AsValue()->ToString(); | 1416 << scheduler_->AsValue()->ToString(); |
| 1447 task_runner().RunPendingTasks(); | 1417 task_runner().RunPendingTasks(); |
| 1448 EXPECT_GT(client->num_actions_(), actions_so_far); | 1418 EXPECT_GT(client_->num_actions_(), actions_so_far); |
| 1449 EXPECT_STREQ(client->Action(client->num_actions_() - 1), | 1419 EXPECT_STREQ(client_->Action(client_->num_actions_() - 1), |
| 1450 "DidAnticipatedDrawTimeChange"); | 1420 "DidAnticipatedDrawTimeChange"); |
| 1451 actions_so_far = client->num_actions_(); | 1421 actions_so_far = client_->num_actions_(); |
| 1452 } | 1422 } |
| 1453 | 1423 |
| 1454 // Do the same thing after BeginMainFrame starts but still before activation. | 1424 // Do the same thing after BeginMainFrame starts but still before activation. |
| 1455 scheduler_->NotifyBeginMainFrameStarted(); | 1425 scheduler_->NotifyBeginMainFrameStarted(); |
| 1456 for (int i = 0; i < 3; ++i) { | 1426 for (int i = 0; i < 3; ++i) { |
| 1457 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1427 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1458 task_runner().DelayToNextTaskTime().InMicroseconds()) | 1428 task_runner().DelayToNextTaskTime().InMicroseconds()) |
| 1459 << scheduler_->AsValue()->ToString(); | 1429 << scheduler_->AsValue()->ToString(); |
| 1460 task_runner().RunPendingTasks(); | 1430 task_runner().RunPendingTasks(); |
| 1461 EXPECT_GT(client->num_actions_(), actions_so_far); | 1431 EXPECT_GT(client_->num_actions_(), actions_so_far); |
| 1462 EXPECT_STREQ(client->Action(client->num_actions_() - 1), | 1432 EXPECT_STREQ(client_->Action(client_->num_actions_() - 1), |
| 1463 "DidAnticipatedDrawTimeChange"); | 1433 "DidAnticipatedDrawTimeChange"); |
| 1464 actions_so_far = client->num_actions_(); | 1434 actions_so_far = client_->num_actions_(); |
| 1465 } | 1435 } |
| 1466 } | 1436 } |
| 1467 | 1437 |
| 1468 TEST_F( | 1438 TEST_F( |
| 1469 SchedulerTest, | 1439 SchedulerTest, |
| 1470 Deadlock_CommitMakesProgressWhileSwapTrottledAndActiveTreeNeedsFirstDraw) { | 1440 Deadlock_CommitMakesProgressWhileSwapTrottledAndActiveTreeNeedsFirstDraw) { |
| 1471 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main | 1441 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main |
| 1472 // thread. This prevents the scheduler from receiving any pending swap acks. | 1442 // thread. This prevents the scheduler from receiving any pending swap acks. |
| 1473 | 1443 |
| 1474 // Since we are simulating a long commit, set up a client with draw duration | 1444 // Since we are simulating a long commit, set up a client with draw duration |
| 1475 // estimates that prevent skipping main frames to get to low latency mode. | 1445 // estimates that prevent skipping main frames to get to low latency mode. |
| 1476 SchedulerClientWithFixedEstimates* client = | |
| 1477 new SchedulerClientWithFixedEstimates( | |
| 1478 base::TimeDelta::FromMilliseconds(1), | |
| 1479 base::TimeDelta::FromMilliseconds(32), | |
| 1480 base::TimeDelta::FromMilliseconds(32)); | |
| 1481 scheduler_settings_.use_external_begin_frame_source = true; | 1446 scheduler_settings_.use_external_begin_frame_source = true; |
| 1482 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 1447 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; |
| 1483 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 1448 SetUpScheduler(true); |
| 1449 | |
| 1450 scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); | |
| 1451 scheduler_->SetBeginMainFrameToCommitDurationEstimate( | |
| 1452 base::TimeDelta::FromMilliseconds(32)); | |
| 1453 scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( | |
| 1454 base::TimeDelta::FromMilliseconds(32)); | |
| 1484 | 1455 |
| 1485 // Disables automatic swap acks so this test can force swap ack throttling | 1456 // Disables automatic swap acks so this test can force swap ack throttling |
| 1486 // to simulate a blocked Browser ui thread. | 1457 // to simulate a blocked Browser ui thread. |
| 1487 scheduler_->SetMaxSwapsPending(1); | 1458 scheduler_->SetMaxSwapsPending(1); |
| 1488 client_->SetAutomaticSwapAck(false); | 1459 client_->SetAutomaticSwapAck(false); |
| 1489 | 1460 |
| 1490 // Get a new active tree in main-thread high latency mode and put us | 1461 // Get a new active tree in main-thread high latency mode and put us |
| 1491 // in a swap throttled state. | 1462 // in a swap throttled state. |
| 1492 client_->Reset(); | 1463 client_->Reset(); |
| 1493 EXPECT_FALSE(scheduler_->CommitPending()); | 1464 EXPECT_FALSE(scheduler_->CommitPending()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1543 Deadlock_NoBeginMainFrameWhileSwapTrottledAndPipelineFull) { | 1514 Deadlock_NoBeginMainFrameWhileSwapTrottledAndPipelineFull) { |
| 1544 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main | 1515 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main |
| 1545 // thread. This prevents the scheduler from receiving any pending swap acks. | 1516 // thread. This prevents the scheduler from receiving any pending swap acks. |
| 1546 | 1517 |
| 1547 // This particular test makes sure we do not send a BeginMainFrame while | 1518 // This particular test makes sure we do not send a BeginMainFrame while |
| 1548 // swap trottled and we have a pending tree and active tree that | 1519 // swap trottled and we have a pending tree and active tree that |
| 1549 // still needs to be drawn for the first time. | 1520 // still needs to be drawn for the first time. |
| 1550 | 1521 |
| 1551 // Since we are simulating a long commit, set up a client with draw duration | 1522 // Since we are simulating a long commit, set up a client with draw duration |
| 1552 // estimates that prevent skipping main frames to get to low latency mode. | 1523 // estimates that prevent skipping main frames to get to low latency mode. |
| 1553 SchedulerClientWithFixedEstimates* client = | |
| 1554 new SchedulerClientWithFixedEstimates( | |
| 1555 base::TimeDelta::FromMilliseconds(1), | |
| 1556 base::TimeDelta::FromMilliseconds(32), | |
| 1557 base::TimeDelta::FromMilliseconds(32)); | |
| 1558 scheduler_settings_.use_external_begin_frame_source = true; | 1524 scheduler_settings_.use_external_begin_frame_source = true; |
| 1559 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 1525 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; |
| 1560 scheduler_settings_.main_frame_before_activation_enabled = true; | 1526 scheduler_settings_.main_frame_before_activation_enabled = true; |
| 1561 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 1527 SetUpScheduler(true); |
| 1528 | |
| 1529 scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); | |
| 1530 scheduler_->SetBeginMainFrameToCommitDurationEstimate( | |
| 1531 base::TimeDelta::FromMilliseconds(32)); | |
| 1532 scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( | |
| 1533 base::TimeDelta::FromMilliseconds(32)); | |
| 1562 | 1534 |
| 1563 // Disables automatic swap acks so this test can force swap ack throttling | 1535 // Disables automatic swap acks so this test can force swap ack throttling |
| 1564 // to simulate a blocked Browser ui thread. | 1536 // to simulate a blocked Browser ui thread. |
| 1565 scheduler_->SetMaxSwapsPending(1); | 1537 scheduler_->SetMaxSwapsPending(1); |
| 1566 client_->SetAutomaticSwapAck(false); | 1538 client_->SetAutomaticSwapAck(false); |
| 1567 | 1539 |
| 1568 // Start a new commit in main-thread high latency mode and hold off on | 1540 // Start a new commit in main-thread high latency mode and hold off on |
| 1569 // activation. | 1541 // activation. |
| 1570 client_->Reset(); | 1542 client_->Reset(); |
| 1571 EXPECT_FALSE(scheduler_->CommitPending()); | 1543 EXPECT_FALSE(scheduler_->CommitPending()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1629 } | 1601 } |
| 1630 | 1602 |
| 1631 TEST_F( | 1603 TEST_F( |
| 1632 SchedulerTest, | 1604 SchedulerTest, |
| 1633 CommitMakesProgressWhenIdleAndHasPendingTreeAndActiveTreeNeedsFirstDraw) { | 1605 CommitMakesProgressWhenIdleAndHasPendingTreeAndActiveTreeNeedsFirstDraw) { |
| 1634 // This verifies we don't block commits longer than we need to | 1606 // This verifies we don't block commits longer than we need to |
| 1635 // for performance reasons - not deadlock reasons. | 1607 // for performance reasons - not deadlock reasons. |
| 1636 | 1608 |
| 1637 // Since we are simulating a long commit, set up a client with draw duration | 1609 // Since we are simulating a long commit, set up a client with draw duration |
| 1638 // estimates that prevent skipping main frames to get to low latency mode. | 1610 // estimates that prevent skipping main frames to get to low latency mode. |
| 1639 SchedulerClientWithFixedEstimates* client = | |
| 1640 new SchedulerClientWithFixedEstimates( | |
| 1641 base::TimeDelta::FromMilliseconds(1), | |
| 1642 base::TimeDelta::FromMilliseconds(32), | |
| 1643 base::TimeDelta::FromMilliseconds(32)); | |
| 1644 scheduler_settings_.use_external_begin_frame_source = true; | 1611 scheduler_settings_.use_external_begin_frame_source = true; |
| 1645 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 1612 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; |
| 1646 scheduler_settings_.main_frame_before_activation_enabled = true; | 1613 scheduler_settings_.main_frame_before_activation_enabled = true; |
| 1647 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 1614 SetUpScheduler(true); |
| 1615 | |
| 1616 scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); | |
| 1617 scheduler_->SetBeginMainFrameToCommitDurationEstimate( | |
| 1618 base::TimeDelta::FromMilliseconds(32)); | |
| 1619 scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( | |
| 1620 base::TimeDelta::FromMilliseconds(32)); | |
| 1648 | 1621 |
| 1649 // Disables automatic swap acks so this test can force swap ack throttling | 1622 // Disables automatic swap acks so this test can force swap ack throttling |
| 1650 // to simulate a blocked Browser ui thread. | 1623 // to simulate a blocked Browser ui thread. |
| 1651 scheduler_->SetMaxSwapsPending(1); | 1624 scheduler_->SetMaxSwapsPending(1); |
| 1652 client_->SetAutomaticSwapAck(false); | 1625 client_->SetAutomaticSwapAck(false); |
| 1653 | 1626 |
| 1654 // Start a new commit in main-thread high latency mode and hold off on | 1627 // Start a new commit in main-thread high latency mode and hold off on |
| 1655 // activation. | 1628 // activation. |
| 1656 client_->Reset(); | 1629 client_->Reset(); |
| 1657 EXPECT_FALSE(scheduler_->CommitPending()); | 1630 EXPECT_FALSE(scheduler_->CommitPending()); |
| (...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2946 | 2919 |
| 2947 class SchedulerClientSetNeedsPrepareTilesOnDraw : public FakeSchedulerClient { | 2920 class SchedulerClientSetNeedsPrepareTilesOnDraw : public FakeSchedulerClient { |
| 2948 public: | 2921 public: |
| 2949 SchedulerClientSetNeedsPrepareTilesOnDraw() : FakeSchedulerClient() {} | 2922 SchedulerClientSetNeedsPrepareTilesOnDraw() : FakeSchedulerClient() {} |
| 2950 | 2923 |
| 2951 protected: | 2924 protected: |
| 2952 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 2925 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 2953 scheduler_->SetNeedsPrepareTiles(); | 2926 scheduler_->SetNeedsPrepareTiles(); |
| 2954 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 2927 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 2955 } | 2928 } |
| 2956 | |
| 2957 void ScheduledActionPrepareTiles() override { | |
| 2958 FakeSchedulerClient::ScheduledActionPrepareTiles(); | |
| 2959 scheduler_->DidPrepareTiles(); | |
| 2960 } | |
| 2961 }; | 2929 }; |
| 2962 | 2930 |
| 2963 TEST_F(SchedulerTest, SynchronousCompositorPrepareTilesOnDraw) { | 2931 TEST_F(SchedulerTest, SynchronousCompositorPrepareTilesOnDraw) { |
| 2964 scheduler_settings_.using_synchronous_renderer_compositor = true; | 2932 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 2965 scheduler_settings_.use_external_begin_frame_source = true; | 2933 scheduler_settings_.use_external_begin_frame_source = true; |
| 2966 | 2934 |
| 2967 scoped_ptr<FakeSchedulerClient> client = | 2935 scoped_ptr<FakeSchedulerClient> client = |
| 2968 make_scoped_ptr(new SchedulerClientSetNeedsPrepareTilesOnDraw); | 2936 make_scoped_ptr(new SchedulerClientSetNeedsPrepareTilesOnDraw); |
| 2969 SetUpScheduler(client.Pass(), true); | 2937 SetUpScheduler(client.Pass(), true); |
| 2970 | 2938 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3061 scheduler_->SetImplLatencyTakesPriority(true); | 3029 scheduler_->SetImplLatencyTakesPriority(true); |
| 3062 scheduler_->SetChildrenNeedBeginFrames(true); | 3030 scheduler_->SetChildrenNeedBeginFrames(true); |
| 3063 | 3031 |
| 3064 EXPECT_SCOPED(AdvanceFrame()); | 3032 EXPECT_SCOPED(AdvanceFrame()); |
| 3065 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | 3033 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); |
| 3066 EXPECT_FALSE(client_->begin_frame_args_sent_to_children().on_critical_path); | 3034 EXPECT_FALSE(client_->begin_frame_args_sent_to_children().on_critical_path); |
| 3067 } | 3035 } |
| 3068 | 3036 |
| 3069 } // namespace | 3037 } // namespace |
| 3070 } // namespace cc | 3038 } // namespace cc |
| OLD | NEW |