@@ -40,6 +40,26 @@ void AwaitVsyncChecked(FlatlandConnection& flatland_connection,
4040 });
4141}
4242
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+
4363} // namespace
4464
4565class FlatlandConnectionTest : public ::testing::Test {
@@ -61,10 +81,12 @@ class FlatlandConnectionTest : public ::testing::Test {
6181 }
6282
6383 // Syntactic sugar for OnNextFrameBegin
64- void OnNextFrameBegin (int num_present_credits) {
84+ void OnNextFrameBegin (int num_present_credits, int presentation_time = 345 ) {
6585 fuchsia::ui::composition::OnNextFrameBeginValues on_next_frame_begin_values;
6686 on_next_frame_begin_values.set_additional_present_credits (
6787 num_present_credits);
88+ on_next_frame_begin_values.set_future_presentation_infos (
89+ CreateFuturePresentationInfos (presentation_time));
6890 fake_flatland ().FireOnNextFrameBeginEvent (
6991 std::move (on_next_frame_begin_values));
7092 }
@@ -171,10 +193,14 @@ TEST_F(FlatlandConnectionTest, BasicPresent) {
171193 EXPECT_FALSE (await_vsync_fired);
172194
173195 // Fire the `OnNextFrameBegin` event. AwaitVsync should be fired.
196+ const int kPresentationTime = 123 ;
174197 AwaitVsyncChecked (flatland_connection, await_vsync_fired,
175- kDefaultFlatlandPresentationInterval );
198+ fml::TimePoint::FromEpochDelta (
199+ fml::TimeDelta::FromNanoseconds (kPresentationTime )));
176200 fuchsia::ui::composition::OnNextFrameBeginValues on_next_frame_begin_values;
177201 on_next_frame_begin_values.set_additional_present_credits (3 );
202+ on_next_frame_begin_values.set_future_presentation_infos (
203+ CreateFuturePresentationInfos (kPresentationTime ));
178204 fake_flatland ().FireOnNextFrameBeginEvent (
179205 std::move (on_next_frame_begin_values));
180206 loop ().RunUntilIdle ();
@@ -275,24 +301,29 @@ TEST_F(FlatlandConnectionTest, OutOfOrderAwait) {
275301
276302 // Set the callback with AwaitVsync, callback should not be fired
277303 await_vsync_callback_fired = false ;
304+ const int kPresentationTime1 = 567 ;
278305 AwaitVsyncChecked (flatland_connection, await_vsync_callback_fired,
279- kDefaultFlatlandPresentationInterval );
306+ fml::TimePoint::FromEpochDelta (
307+ fml::TimeDelta::FromNanoseconds (kPresentationTime1 )));
280308 EXPECT_FALSE (await_vsync_callback_fired);
281309
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.
283312 await_vsync_callback_fired = false ;
284- OnNextFrameBegin (1 );
313+ OnNextFrameBegin (1 , kPresentationTime1 );
285314 loop ().RunUntilIdle ();
286315 EXPECT_TRUE (await_vsync_callback_fired);
287316
288317 // Second consecutive ONFB should not call the fire callback and should
289318 // instead set it to be pending to fire on next AwaitVsync
290319 await_vsync_callback_fired = false ;
291- OnNextFrameBegin (1 );
320+ const int kPresentationTime2 = 678 ;
321+ OnNextFrameBegin (1 , kPresentationTime2 );
292322 loop ().RunUntilIdle ();
293323 EXPECT_FALSE (await_vsync_callback_fired);
294324
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.
296327 await_vsync_callback_fired = false ;
297328 AwaitVsyncChecked (flatland_connection, await_vsync_callback_fired,
298329 kDefaultFlatlandPresentationInterval );
@@ -301,13 +332,15 @@ TEST_F(FlatlandConnectionTest, OutOfOrderAwait) {
301332 // With the pending callback fired, The new callback should be set for the
302333 // next OnNextFrameBegin to call
303334 await_vsync_callback_fired = false ;
335+ const int kPresentationTime3 = 789 ;
304336 AwaitVsyncChecked (flatland_connection, await_vsync_callback_fired,
305- kDefaultFlatlandPresentationInterval );
337+ fml::TimePoint::FromEpochDelta (
338+ fml::TimeDelta::FromNanoseconds (kPresentationTime3 )));
306339 EXPECT_FALSE (await_vsync_callback_fired);
307340
308341 // Now OnNextFrameBegin should fire the callback
309342 await_vsync_callback_fired = false ;
310- OnNextFrameBegin (1 );
343+ OnNextFrameBegin (1 , kPresentationTime3 );
311344 loop ().RunUntilIdle ();
312345 EXPECT_TRUE (await_vsync_callback_fired);
313346}
0 commit comments