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

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

Issue 130483010: cc: Limit ManageTiles calls to once per-frame on average (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add tests Created 6 years, 11 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/trees/layer_tree_host_impl.cc » ('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/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1087 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
1088 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); 1088 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
1089 client.Reset(); 1089 client.Reset();
1090 scheduler->OnBeginImplFrameDeadline(); 1090 scheduler->OnBeginImplFrameDeadline();
1091 EXPECT_EQ(0, client.num_draws()); 1091 EXPECT_EQ(0, client.num_draws());
1092 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1092 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1093 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 1093 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
1094 } 1094 }
1095 1095
1096 // Test that ManageTiles only happens once per frame. If an external caller 1096 // Test that ManageTiles only happens once per frame. If an external caller
1097 // initiates it, then the state machine should not on that frame. 1097 // initiates it, then the state machine should not ManageTiles on that frame.
1098 TEST(SchedulerTest, ManageTilesOncePerFrame) { 1098 TEST(SchedulerTest, ManageTilesOncePerFrame) {
1099 FakeSchedulerClient client; 1099 FakeSchedulerClient client;
1100 SchedulerSettings default_scheduler_settings; 1100 SchedulerSettings default_scheduler_settings;
1101 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 1101 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
1102 scheduler->SetCanStart(); 1102 scheduler->SetCanStart();
1103 scheduler->SetVisible(true); 1103 scheduler->SetVisible(true);
1104 scheduler->SetCanDraw(true); 1104 scheduler->SetCanDraw(true);
1105 InitializeOutputSurfaceAndFirstCommit(scheduler); 1105 InitializeOutputSurfaceAndFirstCommit(scheduler);
1106 1106
1107 // If DidManageTiles during a frame, then ManageTiles should not occur again. 1107 // If DidManageTiles during a frame, then ManageTiles should not occur again.
1108 scheduler->SetNeedsManageTiles(); 1108 scheduler->SetNeedsManageTiles();
1109 scheduler->SetNeedsRedraw(); 1109 scheduler->SetNeedsRedraw();
1110 client.Reset(); 1110 client.Reset();
1111 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1111 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
1112 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); 1112 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
1113 1113
1114 EXPECT_TRUE(scheduler->ManageTilesPending()); 1114 EXPECT_TRUE(scheduler->ManageTilesPending());
1115 scheduler->DidManageTiles(); 1115 scheduler->DidManageTiles(); // An explicit ManageTiles.
1116 EXPECT_FALSE(scheduler->ManageTilesPending()); 1116 EXPECT_FALSE(scheduler->ManageTilesPending());
1117 1117
1118 client.Reset(); 1118 client.Reset();
1119 scheduler->OnBeginImplFrameDeadline(); 1119 scheduler->OnBeginImplFrameDeadline();
1120 EXPECT_EQ(1, client.num_draws()); 1120 EXPECT_EQ(1, client.num_draws());
1121 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1121 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1122 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 1122 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
1123 EXPECT_FALSE(scheduler->RedrawPending()); 1123 EXPECT_FALSE(scheduler->RedrawPending());
1124 EXPECT_FALSE(scheduler->ManageTilesPending()); 1124 EXPECT_FALSE(scheduler->ManageTilesPending());
1125 1125
1126 // Next frame without DidManageTiles should ManageTiles with draw. 1126 // Next frame without DidManageTiles should ManageTiles with draw.
1127 scheduler->SetNeedsManageTiles(); 1127 scheduler->SetNeedsManageTiles();
1128 scheduler->SetNeedsRedraw(); 1128 scheduler->SetNeedsRedraw();
1129 client.Reset(); 1129 client.Reset();
1130 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1130 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
1131 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); 1131 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
1132 1132
1133 client.Reset(); 1133 client.Reset();
1134 scheduler->OnBeginImplFrameDeadline(); 1134 scheduler->OnBeginImplFrameDeadline();
1135 EXPECT_EQ(1, client.num_draws()); 1135 EXPECT_EQ(1, client.num_draws());
1136 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1136 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1137 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 1137 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
1138 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 1138 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
1139 client.ActionIndex("ScheduledActionManageTiles")); 1139 client.ActionIndex("ScheduledActionManageTiles"));
1140 EXPECT_FALSE(scheduler->RedrawPending()); 1140 EXPECT_FALSE(scheduler->RedrawPending());
1141 EXPECT_FALSE(scheduler->ManageTilesPending()); 1141 EXPECT_FALSE(scheduler->ManageTilesPending());
1142 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles
1143
1144 // If we get another DidManageTiles within the same frame, we should
1145 // not ManageTiles on the next frame.
1146 scheduler->DidManageTiles(); // An explicit ManageTiles.
1147 scheduler->SetNeedsManageTiles();
1148 scheduler->SetNeedsRedraw();
1149 client.Reset();
1150 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
1151 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
1152
1153 EXPECT_TRUE(scheduler->ManageTilesPending());
1154
1155 client.Reset();
1156 scheduler->OnBeginImplFrameDeadline();
1157 EXPECT_EQ(1, client.num_draws());
1158 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1159 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
1160 EXPECT_FALSE(scheduler->RedrawPending());
1161
1162 // If we get another DidManageTiles, we should not ManageTiles on the next
1163 // frame. This verifies we don't alternate calling ManageTiles once and twice.
1164 EXPECT_TRUE(scheduler->ManageTilesPending());
1165 scheduler->DidManageTiles(); // An explicit ManageTiles.
1166 EXPECT_FALSE(scheduler->ManageTilesPending());
1167 scheduler->SetNeedsManageTiles();
1168 scheduler->SetNeedsRedraw();
1169 client.Reset();
1170 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
1171 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
1172
1173 EXPECT_TRUE(scheduler->ManageTilesPending());
1174
1175 client.Reset();
1176 scheduler->OnBeginImplFrameDeadline();
1177 EXPECT_EQ(1, client.num_draws());
1178 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1179 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
1180 EXPECT_FALSE(scheduler->RedrawPending());
1181
1182 // Next frame without DidManageTiles should ManageTiles with draw.
1183 scheduler->SetNeedsManageTiles();
1184 scheduler->SetNeedsRedraw();
1185 client.Reset();
1186 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
1187 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
1188
1189 client.Reset();
1190 scheduler->OnBeginImplFrameDeadline();
1191 EXPECT_EQ(1, client.num_draws());
1192 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1193 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
1194 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
1195 client.ActionIndex("ScheduledActionManageTiles"));
1196 EXPECT_FALSE(scheduler->RedrawPending());
1197 EXPECT_FALSE(scheduler->ManageTilesPending());
1198 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles
1142 } 1199 }
1143 1200
1144 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { 1201 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient {
1145 public: 1202 public:
1146 SchedulerClientWithFixedEstimates( 1203 SchedulerClientWithFixedEstimates(
1147 base::TimeDelta draw_duration, 1204 base::TimeDelta draw_duration,
1148 base::TimeDelta begin_main_frame_to_commit_duration, 1205 base::TimeDelta begin_main_frame_to_commit_duration,
1149 base::TimeDelta commit_to_activate_duration) 1206 base::TimeDelta commit_to_activate_duration)
1150 : draw_duration_(draw_duration), 1207 : draw_duration_(draw_duration),
1151 begin_main_frame_to_commit_duration_( 1208 begin_main_frame_to_commit_duration_(
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 SpinForMillis(interval * 2); 1334 SpinForMillis(interval * 2);
1278 EXPECT_GT(client.num_actions_(), actions_so_far); 1335 EXPECT_GT(client.num_actions_(), actions_so_far);
1279 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1336 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1280 "DidAnticipatedDrawTimeChange"); 1337 "DidAnticipatedDrawTimeChange");
1281 actions_so_far = client.num_actions_(); 1338 actions_so_far = client.num_actions_();
1282 } 1339 }
1283 } 1340 }
1284 1341
1285 } // namespace 1342 } // namespace
1286 } // namespace cc 1343 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698