Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: cc/scheduler/scheduler_unittest.cc

Issue 421183003: Revert of Add builders for tracing event's structural arguments (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/scheduler/scheduler_state_machine_unittest.cc ('k') | cc/test/fake_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/debug/trace_event.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
12 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 12 #include "base/run_loop.h"
14 #include "base/time/time.h" 13 #include "base/time/time.h"
15 #include "cc/test/begin_frame_args_test.h" 14 #include "cc/test/begin_frame_args_test.h"
16 #include "cc/test/ordered_simple_task_runner.h" 15 #include "cc/test/ordered_simple_task_runner.h"
17 #include "cc/test/scheduler_test_common.h" 16 #include "cc/test/scheduler_test_common.h"
18 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 103
105 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it 104 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it
106 // for tests that do. 105 // for tests that do.
107 void set_log_anticipated_draw_time_change(bool log) { 106 void set_log_anticipated_draw_time_change(bool log) {
108 log_anticipated_draw_time_change_ = log; 107 log_anticipated_draw_time_change_ = log;
109 } 108 }
110 bool needs_begin_frame() { return needs_begin_frame_; } 109 bool needs_begin_frame() { return needs_begin_frame_; }
111 int num_draws() const { return num_draws_; } 110 int num_draws() const { return num_draws_; }
112 int num_actions_() const { return static_cast<int>(actions_.size()); } 111 int num_actions_() const { return static_cast<int>(actions_.size()); }
113 const char* Action(int i) const { return actions_[i]; } 112 const char* Action(int i) const { return actions_[i]; }
114 std::string StateForAction(int i) const { return states_[i]->ToString(); } 113 base::Value& StateForAction(int i) const { return *states_[i]; }
115 base::TimeTicks posted_begin_impl_frame_deadline() const { 114 base::TimeTicks posted_begin_impl_frame_deadline() const {
116 return posted_begin_impl_frame_deadline_; 115 return posted_begin_impl_frame_deadline_;
117 } 116 }
118 117
119 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } 118 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; }
120 119
121 int ActionIndex(const char* action) const { 120 int ActionIndex(const char* action) const {
122 for (size_t i = 0; i < actions_.size(); i++) 121 for (size_t i = 0; i < actions_.size(); i++)
123 if (!strcmp(actions_[i], action)) 122 if (!strcmp(actions_[i], action))
124 return i; 123 return i;
(...skipping 16 matching lines...) Expand all
141 } 140 }
142 void SetAutomaticSwapAck(bool automatic_swap_ack) { 141 void SetAutomaticSwapAck(bool automatic_swap_ack) {
143 automatic_swap_ack_ = automatic_swap_ack; 142 automatic_swap_ack_ = automatic_swap_ack;
144 } 143 }
145 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) { 144 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) {
146 redraw_will_happen_if_update_visible_tiles_happens_ = redraw; 145 redraw_will_happen_if_update_visible_tiles_happens_ = redraw;
147 } 146 }
148 // SchedulerClient implementation. 147 // SchedulerClient implementation.
149 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { 148 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE {
150 actions_.push_back("SetNeedsBeginFrame"); 149 actions_.push_back("SetNeedsBeginFrame");
151 states_.push_back(scheduler_->AsValue()); 150 states_.push_back(scheduler_->AsValue().release());
152 needs_begin_frame_ = enable; 151 needs_begin_frame_ = enable;
153 } 152 }
154 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { 153 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE {
155 actions_.push_back("WillBeginImplFrame"); 154 actions_.push_back("WillBeginImplFrame");
156 states_.push_back(scheduler_->AsValue()); 155 states_.push_back(scheduler_->AsValue().release());
157 } 156 }
158 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { 157 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {
159 actions_.push_back("ScheduledActionSendBeginMainFrame"); 158 actions_.push_back("ScheduledActionSendBeginMainFrame");
160 states_.push_back(scheduler_->AsValue()); 159 states_.push_back(scheduler_->AsValue().release());
161 } 160 }
162 virtual void ScheduledActionAnimate() OVERRIDE { 161 virtual void ScheduledActionAnimate() OVERRIDE {
163 actions_.push_back("ScheduledActionAnimate"); 162 actions_.push_back("ScheduledActionAnimate");
164 states_.push_back(scheduler_->AsValue()); 163 states_.push_back(scheduler_->AsValue().release());
165 } 164 }
166 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() OVERRIDE { 165 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() OVERRIDE {
167 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); 166 actions_.push_back("ScheduledActionDrawAndSwapIfPossible");
168 states_.push_back(scheduler_->AsValue()); 167 states_.push_back(scheduler_->AsValue().release());
169 num_draws_++; 168 num_draws_++;
170 DrawResult result = 169 DrawResult result =
171 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; 170 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS;
172 bool swap_will_happen = 171 bool swap_will_happen =
173 draw_will_happen_ && swap_will_happen_if_draw_happens_; 172 draw_will_happen_ && swap_will_happen_if_draw_happens_;
174 if (swap_will_happen) { 173 if (swap_will_happen) {
175 scheduler_->DidSwapBuffers(); 174 scheduler_->DidSwapBuffers();
176 if (swap_contains_incomplete_tile_) { 175 if (swap_contains_incomplete_tile_) {
177 scheduler_->SetSwapUsedIncompleteTile(true); 176 scheduler_->SetSwapUsedIncompleteTile(true);
178 swap_contains_incomplete_tile_ = false; 177 swap_contains_incomplete_tile_ = false;
179 } else { 178 } else {
180 scheduler_->SetSwapUsedIncompleteTile(false); 179 scheduler_->SetSwapUsedIncompleteTile(false);
181 } 180 }
182 181
183 if (automatic_swap_ack_) 182 if (automatic_swap_ack_)
184 scheduler_->DidSwapBuffersComplete(); 183 scheduler_->DidSwapBuffersComplete();
185 } 184 }
186 return result; 185 return result;
187 } 186 }
188 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE { 187 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE {
189 actions_.push_back("ScheduledActionDrawAndSwapForced"); 188 actions_.push_back("ScheduledActionDrawAndSwapForced");
190 states_.push_back(scheduler_->AsValue()); 189 states_.push_back(scheduler_->AsValue().release());
191 return DRAW_SUCCESS; 190 return DRAW_SUCCESS;
192 } 191 }
193 virtual void ScheduledActionCommit() OVERRIDE { 192 virtual void ScheduledActionCommit() OVERRIDE {
194 actions_.push_back("ScheduledActionCommit"); 193 actions_.push_back("ScheduledActionCommit");
195 states_.push_back(scheduler_->AsValue()); 194 states_.push_back(scheduler_->AsValue().release());
196 } 195 }
197 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { 196 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE {
198 actions_.push_back("ScheduledActionUpdateVisibleTiles"); 197 actions_.push_back("ScheduledActionUpdateVisibleTiles");
199 states_.push_back(scheduler_->AsValue()); 198 states_.push_back(scheduler_->AsValue().release());
200 if (redraw_will_happen_if_update_visible_tiles_happens_) 199 if (redraw_will_happen_if_update_visible_tiles_happens_)
201 scheduler_->SetNeedsRedraw(); 200 scheduler_->SetNeedsRedraw();
202 } 201 }
203 virtual void ScheduledActionActivateSyncTree() OVERRIDE { 202 virtual void ScheduledActionActivateSyncTree() OVERRIDE {
204 actions_.push_back("ScheduledActionActivateSyncTree"); 203 actions_.push_back("ScheduledActionActivateSyncTree");
205 states_.push_back(scheduler_->AsValue()); 204 states_.push_back(scheduler_->AsValue().release());
206 } 205 }
207 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { 206 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {
208 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); 207 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation");
209 states_.push_back(scheduler_->AsValue()); 208 states_.push_back(scheduler_->AsValue().release());
210 } 209 }
211 virtual void ScheduledActionManageTiles() OVERRIDE { 210 virtual void ScheduledActionManageTiles() OVERRIDE {
212 actions_.push_back("ScheduledActionManageTiles"); 211 actions_.push_back("ScheduledActionManageTiles");
213 states_.push_back(scheduler_->AsValue()); 212 states_.push_back(scheduler_->AsValue().release());
214 } 213 }
215 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { 214 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {
216 if (log_anticipated_draw_time_change_) 215 if (log_anticipated_draw_time_change_)
217 actions_.push_back("DidAnticipatedDrawTimeChange"); 216 actions_.push_back("DidAnticipatedDrawTimeChange");
218 } 217 }
219 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { 218 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE {
220 return base::TimeDelta(); 219 return base::TimeDelta();
221 } 220 }
222 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { 221 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE {
223 return base::TimeDelta(); 222 return base::TimeDelta();
224 } 223 }
225 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { 224 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE {
226 return base::TimeDelta(); 225 return base::TimeDelta();
227 } 226 }
228 227
229 virtual void DidBeginImplFrameDeadline() OVERRIDE {} 228 virtual void DidBeginImplFrameDeadline() OVERRIDE {}
230 229
231 protected: 230 protected:
232 bool needs_begin_frame_; 231 bool needs_begin_frame_;
233 bool draw_will_happen_; 232 bool draw_will_happen_;
234 bool swap_will_happen_if_draw_happens_; 233 bool swap_will_happen_if_draw_happens_;
235 bool automatic_swap_ack_; 234 bool automatic_swap_ack_;
236 int num_draws_; 235 int num_draws_;
237 bool log_anticipated_draw_time_change_; 236 bool log_anticipated_draw_time_change_;
238 bool swap_contains_incomplete_tile_; 237 bool swap_contains_incomplete_tile_;
239 bool redraw_will_happen_if_update_visible_tiles_happens_; 238 bool redraw_will_happen_if_update_visible_tiles_happens_;
240 base::TimeTicks posted_begin_impl_frame_deadline_; 239 base::TimeTicks posted_begin_impl_frame_deadline_;
241 std::vector<const char*> actions_; 240 std::vector<const char*> actions_;
242 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; 241 ScopedVector<base::Value> states_;
243 scoped_ptr<TestScheduler> scheduler_; 242 scoped_ptr<TestScheduler> scheduler_;
244 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; 243 scoped_refptr<OrderedSimpleTaskRunner> task_runner_;
245 }; 244 };
246 245
247 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, 246 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler,
248 FakeSchedulerClient* client) { 247 FakeSchedulerClient* client) {
249 bool client_initiates_begin_frame = 248 bool client_initiates_begin_frame =
250 scheduler->settings().begin_frame_scheduling_enabled && 249 scheduler->settings().begin_frame_scheduling_enabled &&
251 scheduler->settings().throttle_frame_production; 250 scheduler->settings().throttle_frame_production;
252 251
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 scheduler->DidSwapBuffers(); 1160 scheduler->DidSwapBuffers();
1162 1161
1163 // Spin the event loop a few times and make sure we get more 1162 // Spin the event loop a few times and make sure we get more
1164 // DidAnticipateDrawTimeChange calls every time. 1163 // DidAnticipateDrawTimeChange calls every time.
1165 int actions_so_far = client.num_actions_(); 1164 int actions_so_far = client.num_actions_();
1166 1165
1167 // Does three iterations to make sure that the timer is properly repeating. 1166 // Does three iterations to make sure that the timer is properly repeating.
1168 for (int i = 0; i < 3; ++i) { 1167 for (int i = 0; i < 3; ++i) {
1169 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), 1168 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
1170 client.task_runner().NextPendingTaskDelay().InMicroseconds()) 1169 client.task_runner().NextPendingTaskDelay().InMicroseconds())
1171 << scheduler->AsValue()->ToString(); 1170 << *scheduler->AsValue();
1172 client.task_runner().RunPendingTasks(); 1171 client.task_runner().RunPendingTasks();
1173 EXPECT_GT(client.num_actions_(), actions_so_far); 1172 EXPECT_GT(client.num_actions_(), actions_so_far);
1174 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1173 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1175 "DidAnticipatedDrawTimeChange"); 1174 "DidAnticipatedDrawTimeChange");
1176 actions_so_far = client.num_actions_(); 1175 actions_so_far = client.num_actions_();
1177 } 1176 }
1178 1177
1179 // Do the same thing after BeginMainFrame starts but still before activation. 1178 // Do the same thing after BeginMainFrame starts but still before activation.
1180 scheduler->NotifyBeginMainFrameStarted(); 1179 scheduler->NotifyBeginMainFrameStarted();
1181 for (int i = 0; i < 3; ++i) { 1180 for (int i = 0; i < 3; ++i) {
1182 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), 1181 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
1183 client.task_runner().NextPendingTaskDelay().InMicroseconds()) 1182 client.task_runner().NextPendingTaskDelay().InMicroseconds())
1184 << scheduler->AsValue()->ToString(); 1183 << *scheduler->AsValue();
1185 client.task_runner().RunPendingTasks(); 1184 client.task_runner().RunPendingTasks();
1186 EXPECT_GT(client.num_actions_(), actions_so_far); 1185 EXPECT_GT(client.num_actions_(), actions_so_far);
1187 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1186 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1188 "DidAnticipatedDrawTimeChange"); 1187 "DidAnticipatedDrawTimeChange");
1189 actions_so_far = client.num_actions_(); 1188 actions_so_far = client.num_actions_();
1190 } 1189 }
1191 } 1190 }
1192 1191
1193 TEST(SchedulerTest, BeginRetroFrame) { 1192 TEST(SchedulerTest, BeginRetroFrame) {
1194 FakeSchedulerClient client; 1193 FakeSchedulerClient client;
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); 1911 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive());
1913 1912
1914 client.Reset(); 1913 client.Reset();
1915 client.task_runner().RunPendingTasks(); // Run posted deadline. 1914 client.task_runner().RunPendingTasks(); // Run posted deadline.
1916 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1915 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1917 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); 1916 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive());
1918 } 1917 }
1919 1918
1920 } // namespace 1919 } // namespace
1921 } // namespace cc 1920 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine_unittest.cc ('k') | cc/test/fake_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698