| 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 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 91 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 92 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 92 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 93 } | 93 } |
| 94 void SetAutomaticSwapAck(bool automatic_swap_ack) { | 94 void SetAutomaticSwapAck(bool automatic_swap_ack) { |
| 95 automatic_swap_ack_ = automatic_swap_ack; | 95 automatic_swap_ack_ = automatic_swap_ack; |
| 96 } | 96 } |
| 97 | 97 |
| 98 // SchedulerClient implementation. | 98 // SchedulerClient implementation. |
| 99 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { | 99 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { |
| 100 actions_.push_back("SetNeedsBeginFrame"); | 100 actions_.push_back("SetNeedsBeginFrame"); |
| 101 states_.push_back(scheduler_->StateAsValue().release()); | 101 states_.push_back(scheduler_->AsValue().release()); |
| 102 needs_begin_frame_ = enable; | 102 needs_begin_frame_ = enable; |
| 103 } | 103 } |
| 104 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { | 104 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { |
| 105 actions_.push_back("WillBeginImplFrame"); | 105 actions_.push_back("WillBeginImplFrame"); |
| 106 states_.push_back(scheduler_->StateAsValue().release()); | 106 states_.push_back(scheduler_->AsValue().release()); |
| 107 } | 107 } |
| 108 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { | 108 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
| 109 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 109 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
| 110 states_.push_back(scheduler_->StateAsValue().release()); | 110 states_.push_back(scheduler_->AsValue().release()); |
| 111 } | 111 } |
| 112 virtual void ScheduledActionAnimate() OVERRIDE { | 112 virtual void ScheduledActionAnimate() OVERRIDE { |
| 113 actions_.push_back("ScheduledActionAnimate"); | 113 actions_.push_back("ScheduledActionAnimate"); |
| 114 states_.push_back(scheduler_->StateAsValue().release()); | 114 states_.push_back(scheduler_->AsValue().release()); |
| 115 } | 115 } |
| 116 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 116 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
| 117 OVERRIDE { | 117 OVERRIDE { |
| 118 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 118 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
| 119 states_.push_back(scheduler_->StateAsValue().release()); | 119 states_.push_back(scheduler_->AsValue().release()); |
| 120 num_draws_++; | 120 num_draws_++; |
| 121 bool did_readback = false; | 121 bool did_readback = false; |
| 122 DrawSwapReadbackResult::DrawResult result = | 122 DrawSwapReadbackResult::DrawResult result = |
| 123 draw_will_happen_ | 123 draw_will_happen_ |
| 124 ? DrawSwapReadbackResult::DRAW_SUCCESS | 124 ? DrawSwapReadbackResult::DRAW_SUCCESS |
| 125 : DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 125 : DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 126 bool swap_will_happen = | 126 bool swap_will_happen = |
| 127 draw_will_happen_ && swap_will_happen_if_draw_happens_; | 127 draw_will_happen_ && swap_will_happen_if_draw_happens_; |
| 128 if (swap_will_happen) { | 128 if (swap_will_happen) { |
| 129 scheduler_->DidSwapBuffers(); | 129 scheduler_->DidSwapBuffers(); |
| 130 if (automatic_swap_ack_) | 130 if (automatic_swap_ack_) |
| 131 scheduler_->DidSwapBuffersComplete(); | 131 scheduler_->DidSwapBuffersComplete(); |
| 132 } | 132 } |
| 133 return DrawSwapReadbackResult( | 133 return DrawSwapReadbackResult( |
| 134 result, | 134 result, |
| 135 draw_will_happen_ && swap_will_happen_if_draw_happens_, | 135 draw_will_happen_ && swap_will_happen_if_draw_happens_, |
| 136 did_readback); | 136 did_readback); |
| 137 } | 137 } |
| 138 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 138 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
| 139 actions_.push_back("ScheduledActionDrawAndSwapForced"); | 139 actions_.push_back("ScheduledActionDrawAndSwapForced"); |
| 140 states_.push_back(scheduler_->StateAsValue().release()); | 140 states_.push_back(scheduler_->AsValue().release()); |
| 141 bool did_request_swap = swap_will_happen_if_draw_happens_; | 141 bool did_request_swap = swap_will_happen_if_draw_happens_; |
| 142 bool did_readback = false; | 142 bool did_readback = false; |
| 143 return DrawSwapReadbackResult( | 143 return DrawSwapReadbackResult( |
| 144 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | 144 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); |
| 145 } | 145 } |
| 146 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() OVERRIDE { | 146 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() OVERRIDE { |
| 147 actions_.push_back("ScheduledActionDrawAndReadback"); | 147 actions_.push_back("ScheduledActionDrawAndReadback"); |
| 148 states_.push_back(scheduler_->StateAsValue().release()); | 148 states_.push_back(scheduler_->AsValue().release()); |
| 149 bool did_request_swap = false; | 149 bool did_request_swap = false; |
| 150 bool did_readback = true; | 150 bool did_readback = true; |
| 151 return DrawSwapReadbackResult( | 151 return DrawSwapReadbackResult( |
| 152 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | 152 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); |
| 153 } | 153 } |
| 154 virtual void ScheduledActionCommit() OVERRIDE { | 154 virtual void ScheduledActionCommit() OVERRIDE { |
| 155 actions_.push_back("ScheduledActionCommit"); | 155 actions_.push_back("ScheduledActionCommit"); |
| 156 states_.push_back(scheduler_->StateAsValue().release()); | 156 states_.push_back(scheduler_->AsValue().release()); |
| 157 } | 157 } |
| 158 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { | 158 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { |
| 159 actions_.push_back("ScheduledActionUpdateVisibleTiles"); | 159 actions_.push_back("ScheduledActionUpdateVisibleTiles"); |
| 160 states_.push_back(scheduler_->StateAsValue().release()); | 160 states_.push_back(scheduler_->AsValue().release()); |
| 161 } | 161 } |
| 162 virtual void ScheduledActionActivatePendingTree() OVERRIDE { | 162 virtual void ScheduledActionActivatePendingTree() OVERRIDE { |
| 163 actions_.push_back("ScheduledActionActivatePendingTree"); | 163 actions_.push_back("ScheduledActionActivatePendingTree"); |
| 164 states_.push_back(scheduler_->StateAsValue().release()); | 164 states_.push_back(scheduler_->AsValue().release()); |
| 165 } | 165 } |
| 166 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { | 166 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { |
| 167 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); | 167 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); |
| 168 states_.push_back(scheduler_->StateAsValue().release()); | 168 states_.push_back(scheduler_->AsValue().release()); |
| 169 } | 169 } |
| 170 virtual void ScheduledActionManageTiles() OVERRIDE { | 170 virtual void ScheduledActionManageTiles() OVERRIDE { |
| 171 actions_.push_back("ScheduledActionManageTiles"); | 171 actions_.push_back("ScheduledActionManageTiles"); |
| 172 states_.push_back(scheduler_->StateAsValue().release()); | 172 states_.push_back(scheduler_->AsValue().release()); |
| 173 } | 173 } |
| 174 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { | 174 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { |
| 175 if (log_anticipated_draw_time_change_) | 175 if (log_anticipated_draw_time_change_) |
| 176 actions_.push_back("DidAnticipatedDrawTimeChange"); | 176 actions_.push_back("DidAnticipatedDrawTimeChange"); |
| 177 } | 177 } |
| 178 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { | 178 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { |
| 179 return base::TimeDelta(); | 179 return base::TimeDelta(); |
| 180 } | 180 } |
| 181 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { | 181 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { |
| 182 return base::TimeDelta(); | 182 return base::TimeDelta(); |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 scheduler->DidSwapBuffers(); | 1107 scheduler->DidSwapBuffers(); |
| 1108 | 1108 |
| 1109 // Spin the event loop a few times and make sure we get more | 1109 // Spin the event loop a few times and make sure we get more |
| 1110 // DidAnticipateDrawTimeChange calls every time. | 1110 // DidAnticipateDrawTimeChange calls every time. |
| 1111 int actions_so_far = client.num_actions_(); | 1111 int actions_so_far = client.num_actions_(); |
| 1112 | 1112 |
| 1113 // Does three iterations to make sure that the timer is properly repeating. | 1113 // Does three iterations to make sure that the timer is properly repeating. |
| 1114 for (int i = 0; i < 3; ++i) { | 1114 for (int i = 0; i < 3; ++i) { |
| 1115 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1115 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1116 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1116 client.task_runner().NextPendingTaskDelay().InMicroseconds()) |
| 1117 << *scheduler->StateAsValue(); | 1117 << *scheduler->AsValue(); |
| 1118 client.task_runner().RunPendingTasks(); | 1118 client.task_runner().RunPendingTasks(); |
| 1119 EXPECT_GT(client.num_actions_(), actions_so_far); | 1119 EXPECT_GT(client.num_actions_(), actions_so_far); |
| 1120 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1120 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
| 1121 "DidAnticipatedDrawTimeChange"); | 1121 "DidAnticipatedDrawTimeChange"); |
| 1122 actions_so_far = client.num_actions_(); | 1122 actions_so_far = client.num_actions_(); |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 // Do the same thing after BeginMainFrame starts but still before activation. | 1125 // Do the same thing after BeginMainFrame starts but still before activation. |
| 1126 scheduler->NotifyBeginMainFrameStarted(); | 1126 scheduler->NotifyBeginMainFrameStarted(); |
| 1127 for (int i = 0; i < 3; ++i) { | 1127 for (int i = 0; i < 3; ++i) { |
| 1128 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1128 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1129 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1129 client.task_runner().NextPendingTaskDelay().InMicroseconds()) |
| 1130 << *scheduler->StateAsValue(); | 1130 << *scheduler->AsValue(); |
| 1131 client.task_runner().RunPendingTasks(); | 1131 client.task_runner().RunPendingTasks(); |
| 1132 EXPECT_GT(client.num_actions_(), actions_so_far); | 1132 EXPECT_GT(client.num_actions_(), actions_so_far); |
| 1133 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1133 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
| 1134 "DidAnticipatedDrawTimeChange"); | 1134 "DidAnticipatedDrawTimeChange"); |
| 1135 actions_so_far = client.num_actions_(); | 1135 actions_so_far = client.num_actions_(); |
| 1136 } | 1136 } |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 TEST(SchedulerTest, BeginRetroFrame) { | 1139 TEST(SchedulerTest, BeginRetroFrame) { |
| 1140 FakeSchedulerClient client; | 1140 FakeSchedulerClient client; |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 TEST(SchedulerTest, | 1484 TEST(SchedulerTest, |
| 1485 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1485 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
| 1486 bool begin_frame_scheduling_enabled = false; | 1486 bool begin_frame_scheduling_enabled = false; |
| 1487 bool throttle_frame_production = false; | 1487 bool throttle_frame_production = false; |
| 1488 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1488 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
| 1489 throttle_frame_production); | 1489 throttle_frame_production); |
| 1490 } | 1490 } |
| 1491 | 1491 |
| 1492 } // namespace | 1492 } // namespace |
| 1493 } // namespace cc | 1493 } // namespace cc |
| OLD | NEW |