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

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

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