@@ -40,6 +40,26 @@ void AwaitVsyncChecked(FlatlandConnection& flatland_connection,
40
40
});
41
41
}
42
42
43
+ void AwaitVsyncChecked (FlatlandConnection& flatland_connection,
44
+ bool & condition_variable,
45
+ fml::TimePoint expected_frame_end) {
46
+ flatland_connection.AwaitVsync (
47
+ [&condition_variable, expected_frame_end = std::move (expected_frame_end)](
48
+ fml::TimePoint frame_start, fml::TimePoint frame_end) {
49
+ EXPECT_EQ (frame_end, expected_frame_end);
50
+ condition_variable = true ;
51
+ });
52
+ }
53
+
54
+ std::vector<fuchsia::scenic::scheduling::PresentationInfo>
55
+ CreateFuturePresentationInfos (int presentation_time) {
56
+ fuchsia::scenic::scheduling::PresentationInfo info_1;
57
+ info_1.set_presentation_time (presentation_time);
58
+ std::vector<fuchsia::scenic::scheduling::PresentationInfo> infos;
59
+ infos.push_back (std::move (info_1));
60
+ return infos;
61
+ }
62
+
43
63
} // namespace
44
64
45
65
class FlatlandConnectionTest : public ::testing::Test {
@@ -61,10 +81,12 @@ class FlatlandConnectionTest : public ::testing::Test {
61
81
}
62
82
63
83
// Syntactic sugar for OnNextFrameBegin
64
- void OnNextFrameBegin (int num_present_credits) {
84
+ void OnNextFrameBegin (int num_present_credits, int presentation_time = 345 ) {
65
85
fuchsia::ui::composition::OnNextFrameBeginValues on_next_frame_begin_values;
66
86
on_next_frame_begin_values.set_additional_present_credits (
67
87
num_present_credits);
88
+ on_next_frame_begin_values.set_future_presentation_infos (
89
+ CreateFuturePresentationInfos (presentation_time));
68
90
fake_flatland ().FireOnNextFrameBeginEvent (
69
91
std::move (on_next_frame_begin_values));
70
92
}
@@ -171,10 +193,14 @@ TEST_F(FlatlandConnectionTest, BasicPresent) {
171
193
EXPECT_FALSE (await_vsync_fired);
172
194
173
195
// Fire the `OnNextFrameBegin` event. AwaitVsync should be fired.
196
+ const int kPresentationTime = 123 ;
174
197
AwaitVsyncChecked (flatland_connection, await_vsync_fired,
175
- kDefaultFlatlandPresentationInterval );
198
+ fml::TimePoint::FromEpochDelta (
199
+ fml::TimeDelta::FromNanoseconds (kPresentationTime )));
176
200
fuchsia::ui::composition::OnNextFrameBeginValues on_next_frame_begin_values;
177
201
on_next_frame_begin_values.set_additional_present_credits (3 );
202
+ on_next_frame_begin_values.set_future_presentation_infos (
203
+ CreateFuturePresentationInfos (kPresentationTime ));
178
204
fake_flatland ().FireOnNextFrameBeginEvent (
179
205
std::move (on_next_frame_begin_values));
180
206
loop ().RunUntilIdle ();
@@ -275,24 +301,29 @@ TEST_F(FlatlandConnectionTest, OutOfOrderAwait) {
275
301
276
302
// Set the callback with AwaitVsync, callback should not be fired
277
303
await_vsync_callback_fired = false ;
304
+ const int kPresentationTime1 = 567 ;
278
305
AwaitVsyncChecked (flatland_connection, await_vsync_callback_fired,
279
- kDefaultFlatlandPresentationInterval );
306
+ fml::TimePoint::FromEpochDelta (
307
+ fml::TimeDelta::FromNanoseconds (kPresentationTime1 )));
280
308
EXPECT_FALSE (await_vsync_callback_fired);
281
309
282
- // Fire the `OnNextFrameBegin` event. AwaitVsync callback should be fired.
310
+ // Fire the `OnNextFrameBegin` event. AwaitVsync callback should be fired with
311
+ // the given presentation time.
283
312
await_vsync_callback_fired = false ;
284
- OnNextFrameBegin (1 );
313
+ OnNextFrameBegin (1 , kPresentationTime1 );
285
314
loop ().RunUntilIdle ();
286
315
EXPECT_TRUE (await_vsync_callback_fired);
287
316
288
317
// Second consecutive ONFB should not call the fire callback and should
289
318
// instead set it to be pending to fire on next AwaitVsync
290
319
await_vsync_callback_fired = false ;
291
- OnNextFrameBegin (1 );
320
+ const int kPresentationTime2 = 678 ;
321
+ OnNextFrameBegin (1 , kPresentationTime2 );
292
322
loop ().RunUntilIdle ();
293
323
EXPECT_FALSE (await_vsync_callback_fired);
294
324
295
- // Now an AwaitVsync should immediately fire the pending callback
325
+ // Now an AwaitVsync should immediately fire the pending callback with the
326
+ // default presentation interval.
296
327
await_vsync_callback_fired = false ;
297
328
AwaitVsyncChecked (flatland_connection, await_vsync_callback_fired,
298
329
kDefaultFlatlandPresentationInterval );
@@ -301,13 +332,15 @@ TEST_F(FlatlandConnectionTest, OutOfOrderAwait) {
301
332
// With the pending callback fired, The new callback should be set for the
302
333
// next OnNextFrameBegin to call
303
334
await_vsync_callback_fired = false ;
335
+ const int kPresentationTime3 = 789 ;
304
336
AwaitVsyncChecked (flatland_connection, await_vsync_callback_fired,
305
- kDefaultFlatlandPresentationInterval );
337
+ fml::TimePoint::FromEpochDelta (
338
+ fml::TimeDelta::FromNanoseconds (kPresentationTime3 )));
306
339
EXPECT_FALSE (await_vsync_callback_fired);
307
340
308
341
// Now OnNextFrameBegin should fire the callback
309
342
await_vsync_callback_fired = false ;
310
- OnNextFrameBegin (1 );
343
+ OnNextFrameBegin (1 , kPresentationTime3 );
311
344
loop ().RunUntilIdle ();
312
345
EXPECT_TRUE (await_vsync_callback_fired);
313
346
}
0 commit comments