~mir-team/mir/development-branch

« back to all changes in this revision

Viewing changes to tests/unit-tests/client/input/test_android_input_receiver.cpp

  • Committer: Tarmac
  • Author(s): Daniel van Vugt
  • Date: 2015-10-19 15:54:48 UTC
  • mfrom: (3025.1.3 fix-1506331)
  • Revision ID: tarmac-20151019155448-zx4d57xrfrg4c4we
Revert optimization r2782. Although it gave us a nice 5ms reduction in
touch latency, it also reduced Android-input's ability to smooth the curve
of the resulting event stream. And that reduction in smoothness is going
to be visible in some touch scrolling scenarios, just as it is visible in
mir_demo_client_fingerpaint / mir_demo_client_target. (LP: #1506331). Fixes: https://bugs.launchpad.net/bugs/1506331.

Approved by Alan Griffiths, PS Jenkins bot, Alexandros Frantzis.

Show diffs side-by-side

added added

removed removed

Lines of Context:
222
222
    EXPECT_FALSE(mt::fd_is_readable(receiver.watch_fd()));
223
223
}
224
224
 
225
 
TEST_F(AndroidInputReceiverSetup, no_artificial_latency_in_resampling)
226
 
{
227
 
    using namespace testing;
228
 
    using namespace std::chrono;
229
 
    using namespace std::literals::chrono_literals;
230
 
 
231
 
    auto t = 0ns;
232
 
    MirEvent ev;
233
 
    bool handler_called{false};
234
 
 
235
 
    mircva::InputReceiver receiver{
236
 
        client_fd,
237
 
        std::make_shared<mircv::XKBMapper>(),
238
 
        [&ev, &handler_called](MirEvent* event)
239
 
        {
240
 
            ev = *event;
241
 
            handler_called = true;
242
 
        },
243
 
        std::make_shared<mircv::NullInputReceiverReport>(),
244
 
        [&t](int)
245
 
        {
246
 
            return t;
247
 
        }
248
 
    };
249
 
    TestingInputProducer producer(server_fd);
250
 
 
251
 
    producer.produce_a_pointer_event(123, 456, t);
252
 
    flush_channels();
253
 
 
254
 
    while (!mt::fd_becomes_readable(receiver.watch_fd(), 1ms) && t < 100ms)
255
 
        t += 1ms;
256
 
 
257
 
    receiver.dispatch(md::FdEvent::readable);
258
 
    EXPECT_TRUE(handler_called);
259
 
    ASSERT_EQ(mir_event_type_motion, ev.type);
260
 
 
261
 
    auto const resample_latency_ms =
262
 
        duration_cast<std::chrono::milliseconds>(t);
263
 
 
264
 
    // Check that we're not using the Android-default RESAMPLE_LATENCY of 5ms
265
 
    // which is too high...
266
 
    // Use plain integers so any failures are readable:
267
 
    EXPECT_THAT(resample_latency_ms.count(), Lt(1));
268
 
}
269
 
 
270
225
TEST_F(AndroidInputReceiverSetup, slow_raw_input_doesnt_cause_frameskipping)
271
226
{  // Regression test for LP: #1372300
272
227
    using namespace testing;
304
259
    EXPECT_TRUE(handler_called);
305
260
    ASSERT_EQ(mir_event_type_key, ev.type);
306
261
 
 
262
    // The motion is still too new. Won't be reported yet, but is batched.
307
263
    auto start = high_resolution_clock::now();
308
264
 
309
265
    EXPECT_TRUE(mt::fd_becomes_readable(receiver.watch_fd(), 1ms));
310
266
    handler_called = false;
311
267
    receiver.dispatch(md::FdEvent::readable);
 
268
    // We've processed the data, but no new event has been generated.
 
269
    EXPECT_FALSE(handler_called);
312
270
 
313
271
    auto end = high_resolution_clock::now();
314
272
    auto duration = end - start;
322
280
 
323
281
    // But later in a frame or so, the motion will be reported:
324
282
    t += 2 * one_frame;  // Account for the slower 59Hz event rate
325
 
    EXPECT_TRUE(handler_called || mt::fd_becomes_readable(receiver.watch_fd(), next_event_timeout));
 
283
    EXPECT_TRUE(mt::fd_becomes_readable(receiver.watch_fd(), next_event_timeout));
326
284
    receiver.dispatch(md::FdEvent::readable);
327
285
 
328
286
    EXPECT_TRUE(handler_called);