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

Side by Side Diff: cc/surfaces/display_scheduler_unittest.cc

Issue 1996783002: Make cc::SurfaceId unguessable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Ben's comment Created 4 years, 7 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/surfaces/display_scheduler.cc ('k') | cc/surfaces/surface.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/surfaces/display_scheduler.h" 5 #include "cc/surfaces/display_scheduler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/test/null_task_runner.h" 8 #include "base/test/null_task_runner.h"
9 #include "base/test/simple_test_tick_clock.h" 9 #include "base/test/simple_test_tick_clock.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 FakeBeginFrameSource fake_begin_frame_source_; 102 FakeBeginFrameSource fake_begin_frame_source_;
103 103
104 std::unique_ptr<base::SimpleTestTickClock> now_src_; 104 std::unique_ptr<base::SimpleTestTickClock> now_src_;
105 scoped_refptr<base::NullTaskRunner> task_runner_; 105 scoped_refptr<base::NullTaskRunner> task_runner_;
106 std::unique_ptr<FakeDisplaySchedulerClient> client_; 106 std::unique_ptr<FakeDisplaySchedulerClient> client_;
107 std::unique_ptr<TestDisplayScheduler> scheduler_; 107 std::unique_ptr<TestDisplayScheduler> scheduler_;
108 }; 108 };
109 109
110 TEST_F(DisplaySchedulerTest, ResizeHasLateDeadlineUntilNewRootSurface) { 110 TEST_F(DisplaySchedulerTest, ResizeHasLateDeadlineUntilNewRootSurface) {
111 SurfaceId root_surface_id1(1); 111 SurfaceId root_surface_id1(0, 1, 0);
112 SurfaceId root_surface_id2(2); 112 SurfaceId root_surface_id2(0, 2, 0);
113 SurfaceId sid1(3); 113 SurfaceId sid1(0, 3, 0);
114 base::TimeTicks late_deadline; 114 base::TimeTicks late_deadline;
115 115
116 // Go trough an initial BeginFrame cycle with the root surface. 116 // Go trough an initial BeginFrame cycle with the root surface.
117 BeginFrameForTest(); 117 BeginFrameForTest();
118 scheduler_->SetNewRootSurface(root_surface_id1); 118 scheduler_->SetNewRootSurface(root_surface_id1);
119 scheduler_->BeginFrameDeadlineForTest(); 119 scheduler_->BeginFrameDeadlineForTest();
120 120
121 // Resize on the next begin frame cycle should cause the deadline to wait 121 // Resize on the next begin frame cycle should cause the deadline to wait
122 // for a new root surface. 122 // for a new root surface.
123 late_deadline = now_src().NowTicks() + BeginFrameArgs::DefaultInterval(); 123 late_deadline = now_src().NowTicks() + BeginFrameArgs::DefaultInterval();
(...skipping 12 matching lines...) Expand all
136 BeginFrameForTest(); 136 BeginFrameForTest();
137 scheduler_->SurfaceDamaged(sid1); 137 scheduler_->SurfaceDamaged(sid1);
138 EXPECT_GT(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 138 EXPECT_GT(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest());
139 scheduler_->SurfaceDamaged(root_surface_id2); 139 scheduler_->SurfaceDamaged(root_surface_id2);
140 EXPECT_GE(now_src().NowTicks(), 140 EXPECT_GE(now_src().NowTicks(),
141 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 141 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
142 scheduler_->BeginFrameDeadlineForTest(); 142 scheduler_->BeginFrameDeadlineForTest();
143 } 143 }
144 144
145 TEST_F(DisplaySchedulerTest, ResizeHasLateDeadlineUntilDamagedSurface) { 145 TEST_F(DisplaySchedulerTest, ResizeHasLateDeadlineUntilDamagedSurface) {
146 SurfaceId root_surface_id(1); 146 SurfaceId root_surface_id(0, 1, 0);
147 SurfaceId sid1(2); 147 SurfaceId sid1(0, 2, 0);
148 base::TimeTicks late_deadline; 148 base::TimeTicks late_deadline;
149 149
150 // Go trough an initial BeginFrame cycle with the root surface. 150 // Go trough an initial BeginFrame cycle with the root surface.
151 BeginFrameForTest(); 151 BeginFrameForTest();
152 scheduler_->SetNewRootSurface(root_surface_id); 152 scheduler_->SetNewRootSurface(root_surface_id);
153 scheduler_->BeginFrameDeadlineForTest(); 153 scheduler_->BeginFrameDeadlineForTest();
154 154
155 // Resize on the next begin frame cycle should cause the deadline to wait 155 // Resize on the next begin frame cycle should cause the deadline to wait
156 // for a new root surface. 156 // for a new root surface.
157 late_deadline = now_src().NowTicks() + BeginFrameArgs::DefaultInterval(); 157 late_deadline = now_src().NowTicks() + BeginFrameArgs::DefaultInterval();
(...skipping 12 matching lines...) Expand all
170 BeginFrameForTest(); 170 BeginFrameForTest();
171 scheduler_->SurfaceDamaged(sid1); 171 scheduler_->SurfaceDamaged(sid1);
172 EXPECT_GT(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 172 EXPECT_GT(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest());
173 scheduler_->SurfaceDamaged(root_surface_id); 173 scheduler_->SurfaceDamaged(root_surface_id);
174 EXPECT_GE(now_src().NowTicks(), 174 EXPECT_GE(now_src().NowTicks(),
175 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 175 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
176 scheduler_->BeginFrameDeadlineForTest(); 176 scheduler_->BeginFrameDeadlineForTest();
177 } 177 }
178 178
179 TEST_F(DisplaySchedulerTest, SurfaceDamaged) { 179 TEST_F(DisplaySchedulerTest, SurfaceDamaged) {
180 SurfaceId root_surface_id(0); 180 SurfaceId root_surface_id(0, 0, 0);
181 SurfaceId sid1(1); 181 SurfaceId sid1(0, 1, 0);
182 SurfaceId sid2(2); 182 SurfaceId sid2(0, 2, 0);
183 183
184 // Set the root surface 184 // Set the root surface
185 scheduler_->SetNewRootSurface(root_surface_id); 185 scheduler_->SetNewRootSurface(root_surface_id);
186 186
187 // Get scheduler to detect surface 1 as active by drawing 187 // Get scheduler to detect surface 1 as active by drawing
188 // two frames in a row with damage from surface 1. 188 // two frames in a row with damage from surface 1.
189 BeginFrameForTest(); 189 BeginFrameForTest();
190 scheduler_->SurfaceDamaged(sid1); 190 scheduler_->SurfaceDamaged(sid1);
191 scheduler_->BeginFrameDeadlineForTest(); 191 scheduler_->BeginFrameDeadlineForTest();
192 BeginFrameForTest(); 192 BeginFrameForTest();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 BeginFrameForTest(); 234 BeginFrameForTest();
235 EXPECT_LT(now_src().NowTicks(), 235 EXPECT_LT(now_src().NowTicks(),
236 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 236 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
237 scheduler_->SurfaceDamaged(root_surface_id); 237 scheduler_->SurfaceDamaged(root_surface_id);
238 EXPECT_GE(now_src().NowTicks(), 238 EXPECT_GE(now_src().NowTicks(),
239 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 239 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
240 scheduler_->BeginFrameDeadlineForTest(); 240 scheduler_->BeginFrameDeadlineForTest();
241 } 241 }
242 242
243 TEST_F(DisplaySchedulerTest, OutputSurfaceLost) { 243 TEST_F(DisplaySchedulerTest, OutputSurfaceLost) {
244 SurfaceId root_surface_id(0); 244 SurfaceId root_surface_id(0, 0, 0);
245 SurfaceId sid1(1); 245 SurfaceId sid1(0, 1, 0);
246 246
247 // Set the root surface 247 // Set the root surface
248 scheduler_->SetNewRootSurface(root_surface_id); 248 scheduler_->SetNewRootSurface(root_surface_id);
249 249
250 // DrawAndSwap normally. 250 // DrawAndSwap normally.
251 BeginFrameForTest(); 251 BeginFrameForTest();
252 EXPECT_LT(now_src().NowTicks(), 252 EXPECT_LT(now_src().NowTicks(),
253 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 253 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
254 EXPECT_EQ(0, client_->draw_and_swap_count()); 254 EXPECT_EQ(0, client_->draw_and_swap_count());
255 scheduler_->SurfaceDamaged(sid1); 255 scheduler_->SurfaceDamaged(sid1);
256 scheduler_->BeginFrameDeadlineForTest(); 256 scheduler_->BeginFrameDeadlineForTest();
257 EXPECT_EQ(1, client_->draw_and_swap_count()); 257 EXPECT_EQ(1, client_->draw_and_swap_count());
258 258
259 // Deadline triggers immediately on OutputSurfaceLost. 259 // Deadline triggers immediately on OutputSurfaceLost.
260 BeginFrameForTest(); 260 BeginFrameForTest();
261 EXPECT_LT(now_src().NowTicks(), 261 EXPECT_LT(now_src().NowTicks(),
262 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 262 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
263 scheduler_->OutputSurfaceLost(); 263 scheduler_->OutputSurfaceLost();
264 EXPECT_GE(now_src().NowTicks(), 264 EXPECT_GE(now_src().NowTicks(),
265 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 265 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
266 266
267 // Deadline does not DrawAndSwap after OutputSurfaceLost. 267 // Deadline does not DrawAndSwap after OutputSurfaceLost.
268 EXPECT_EQ(1, client_->draw_and_swap_count()); 268 EXPECT_EQ(1, client_->draw_and_swap_count());
269 scheduler_->SurfaceDamaged(sid1); 269 scheduler_->SurfaceDamaged(sid1);
270 scheduler_->BeginFrameDeadlineForTest(); 270 scheduler_->BeginFrameDeadlineForTest();
271 EXPECT_EQ(1, client_->draw_and_swap_count()); 271 EXPECT_EQ(1, client_->draw_and_swap_count());
272 } 272 }
273 273
274 TEST_F(DisplaySchedulerTest, ResizeCausesSwap) { 274 TEST_F(DisplaySchedulerTest, ResizeCausesSwap) {
275 SurfaceId root_surface_id(0); 275 SurfaceId root_surface_id(0, 0, 0);
276 SurfaceId sid1(1); 276 SurfaceId sid1(0, 1, 0);
277 277
278 // Set the root surface 278 // Set the root surface
279 scheduler_->SetNewRootSurface(root_surface_id); 279 scheduler_->SetNewRootSurface(root_surface_id);
280 280
281 // DrawAndSwap normally. 281 // DrawAndSwap normally.
282 BeginFrameForTest(); 282 BeginFrameForTest();
283 EXPECT_LT(now_src().NowTicks(), 283 EXPECT_LT(now_src().NowTicks(),
284 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 284 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
285 EXPECT_EQ(0, client_->draw_and_swap_count()); 285 EXPECT_EQ(0, client_->draw_and_swap_count());
286 scheduler_->SurfaceDamaged(sid1); 286 scheduler_->SurfaceDamaged(sid1);
287 scheduler_->BeginFrameDeadlineForTest(); 287 scheduler_->BeginFrameDeadlineForTest();
288 EXPECT_EQ(1, client_->draw_and_swap_count()); 288 EXPECT_EQ(1, client_->draw_and_swap_count());
289 289
290 scheduler_->DisplayResized(); 290 scheduler_->DisplayResized();
291 BeginFrameForTest(); 291 BeginFrameForTest();
292 // DisplayResized should trigger a swap to happen. 292 // DisplayResized should trigger a swap to happen.
293 scheduler_->BeginFrameDeadlineForTest(); 293 scheduler_->BeginFrameDeadlineForTest();
294 EXPECT_EQ(2, client_->draw_and_swap_count()); 294 EXPECT_EQ(2, client_->draw_and_swap_count());
295 } 295 }
296 296
297 TEST_F(DisplaySchedulerTest, RootSurfaceResourcesLocked) { 297 TEST_F(DisplaySchedulerTest, RootSurfaceResourcesLocked) {
298 SurfaceId root_surface_id(0); 298 SurfaceId root_surface_id(0, 0, 0);
299 SurfaceId sid1(1); 299 SurfaceId sid1(0, 1, 0);
300 base::TimeTicks late_deadline; 300 base::TimeTicks late_deadline;
301 301
302 // Set the root surface 302 // Set the root surface
303 scheduler_->SetNewRootSurface(root_surface_id); 303 scheduler_->SetNewRootSurface(root_surface_id);
304 304
305 // DrawAndSwap normally. 305 // DrawAndSwap normally.
306 BeginFrameForTest(); 306 BeginFrameForTest();
307 EXPECT_LT(now_src().NowTicks(), 307 EXPECT_LT(now_src().NowTicks(),
308 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 308 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
309 EXPECT_EQ(0, client_->draw_and_swap_count()); 309 EXPECT_EQ(0, client_->draw_and_swap_count());
(...skipping 24 matching lines...) Expand all
334 scheduler_->SurfaceDamaged(root_surface_id); 334 scheduler_->SurfaceDamaged(root_surface_id);
335 EXPECT_EQ(base::TimeTicks(), 335 EXPECT_EQ(base::TimeTicks(),
336 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 336 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
337 337
338 EXPECT_EQ(1, client_->draw_and_swap_count()); 338 EXPECT_EQ(1, client_->draw_and_swap_count());
339 scheduler_->BeginFrameDeadlineForTest(); 339 scheduler_->BeginFrameDeadlineForTest();
340 EXPECT_EQ(2, client_->draw_and_swap_count()); 340 EXPECT_EQ(2, client_->draw_and_swap_count());
341 } 341 }
342 342
343 TEST_F(DisplaySchedulerTest, DidSwapBuffers) { 343 TEST_F(DisplaySchedulerTest, DidSwapBuffers) {
344 SurfaceId root_surface_id(0); 344 SurfaceId root_surface_id(0, 0, 0);
345 SurfaceId sid1(1); 345 SurfaceId sid1(0, 1, 0);
346 SurfaceId sid2(2); 346 SurfaceId sid2(0, 2, 0);
347 347
348 // Set the root surface 348 // Set the root surface
349 scheduler_->SetNewRootSurface(root_surface_id); 349 scheduler_->SetNewRootSurface(root_surface_id);
350 350
351 // Get scheduler to detect surface 1 and 2 as active. 351 // Get scheduler to detect surface 1 and 2 as active.
352 BeginFrameForTest(); 352 BeginFrameForTest();
353 scheduler_->SurfaceDamaged(sid1); 353 scheduler_->SurfaceDamaged(sid1);
354 scheduler_->SurfaceDamaged(sid2); 354 scheduler_->SurfaceDamaged(sid2);
355 scheduler_->BeginFrameDeadlineForTest(); 355 scheduler_->BeginFrameDeadlineForTest();
356 BeginFrameForTest(); 356 BeginFrameForTest();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 base::TimeTicks()); 399 base::TimeTicks());
400 // Draw and swap now that we aren't throttled. 400 // Draw and swap now that we aren't throttled.
401 EXPECT_EQ(3, client_->draw_and_swap_count()); 401 EXPECT_EQ(3, client_->draw_and_swap_count());
402 scheduler_->BeginFrameDeadlineForTest(); 402 scheduler_->BeginFrameDeadlineForTest();
403 EXPECT_EQ(4, client_->draw_and_swap_count()); 403 EXPECT_EQ(4, client_->draw_and_swap_count());
404 } 404 }
405 405
406 // This test verfies that we try to reschedule the deadline 406 // This test verfies that we try to reschedule the deadline
407 // after any event that may change what deadline we want. 407 // after any event that may change what deadline we want.
408 TEST_F(DisplaySchedulerTest, ScheduleBeginFrameDeadline) { 408 TEST_F(DisplaySchedulerTest, ScheduleBeginFrameDeadline) {
409 SurfaceId root_surface_id(1); 409 SurfaceId root_surface_id(0, 1, 0);
410 SurfaceId sid1(2); 410 SurfaceId sid1(0, 2, 0);
411 int count = 1; 411 int count = 1;
412 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count()); 412 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count());
413 413
414 // Set the root surface 414 // Set the root surface
415 scheduler_->SetNewRootSurface(root_surface_id); 415 scheduler_->SetNewRootSurface(root_surface_id);
416 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count()); 416 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count());
417 417
418 BeginFrameForTest(); 418 BeginFrameForTest();
419 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count()); 419 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count());
420 420
(...skipping 16 matching lines...) Expand all
437 437
438 scheduler_->SetRootSurfaceResourcesLocked(true); 438 scheduler_->SetRootSurfaceResourcesLocked(true);
439 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count()); 439 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count());
440 440
441 scheduler_->OutputSurfaceLost(); 441 scheduler_->OutputSurfaceLost();
442 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count()); 442 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count());
443 } 443 }
444 444
445 } // namespace 445 } // namespace
446 } // namespace cc 446 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/display_scheduler.cc ('k') | cc/surfaces/surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698