~vanvugt/mir/set-subpixel

« back to all changes in this revision

Viewing changes to tests/unit-tests/platforms/mesa/kms/test_cursor.cpp

Simplify hardware cursor construction (no parameter required).

Previously hardware cursor implementations were expected to show
on construction with a given image. We now instead hide on construction but show an image immediately after as part of the default configuration policy.

Aside from providing a simpler interface, this is required as a
prerequisite for runtime fallback to the software cursor when the
hardware cursor won't be used (both cursors exist but never more than
one of them shown). This is also a prerequisite to fixing bug 1662760.

Assuming that a hardware cursor might only fail during construction was
a poor design. Going forward we will need to deal with a hardware cursor
that might become unusable or undesirable at any point in its life. Fixes: https://bugs.launchpad.net/bugs/1639226.

Approved by mir-ci-bot, Daniel van Vugt, Chris Halse Rogers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
            auto& out = *entry.second;
67
67
            ON_CALL(out, has_cursor())
68
68
                .WillByDefault(Return(true));
 
69
            ON_CALL(out, set_cursor(_))
 
70
                .WillByDefault(Return(true));
 
71
            ON_CALL(out, clear_cursor())
 
72
                .WillByDefault(Return(true));
69
73
        }
70
74
    }
71
75
 
281
285
    size_t const cursor_side{64};
282
286
    MesaCursorTest()
283
287
        : cursor{mock_gbm.fake_gbm.device, output_container,
284
 
            mt::fake_shared(current_configuration),
285
 
            mt::fake_shared(stub_image)}
 
288
            mt::fake_shared(current_configuration)}
286
289
    {
287
290
        using namespace ::testing;
288
291
        ON_CALL(mock_drm, drmGetCap(_, DRM_CAP_CURSOR_WIDTH, _))
333
336
                                        GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE));
334
337
 
335
338
    mgm::Cursor cursor_tmp{mock_gbm.fake_gbm.device, output_container,
336
 
        std::make_shared<StubCurrentConfiguration>(),
337
 
        std::make_shared<StubCursorImage>()};
 
339
        std::make_shared<StubCurrentConfiguration>()};
338
340
}
339
341
 
340
342
TEST_F(MesaCursorTest, queries_received_cursor_size)
345
347
    EXPECT_CALL(mock_gbm, gbm_bo_get_height(_));
346
348
 
347
349
    mgm::Cursor cursor_tmp{mock_gbm.fake_gbm.device, output_container,
348
 
        std::make_shared<StubCurrentConfiguration>(),
349
 
        std::make_shared<StubCursorImage>()};
 
350
        std::make_shared<StubCurrentConfiguration>()};
350
351
}
351
352
 
352
353
TEST_F(MesaCursorTest, respects_drm_cap_cursor)
361
362
    EXPECT_CALL(mock_gbm, gbm_bo_create(_, drm_buffer_size, drm_buffer_size, _, _));
362
363
 
363
364
    mgm::Cursor cursor_tmp{mock_gbm.fake_gbm.device, output_container,
364
 
                           std::make_shared<StubCurrentConfiguration>(),
365
 
                           std::make_shared<StubCursorImage>()};
 
365
                           std::make_shared<StubCurrentConfiguration>()};
366
366
}
367
367
 
368
368
TEST_F(MesaCursorTest, can_force_64x64_cursor)
379
379
    EXPECT_CALL(mock_gbm, gbm_bo_create(_, 64, 64, _, _));
380
380
 
381
381
    mgm::Cursor cursor_tmp{mock_gbm.fake_gbm.device, output_container,
382
 
                           std::make_shared<StubCurrentConfiguration>(),
383
 
                           std::make_shared<StubCursorImage>()};
 
382
                           std::make_shared<StubCurrentConfiguration>()};
384
383
}
385
384
 
386
385
TEST_F(MesaCursorTest, show_cursor_writes_to_bo)
444
443
    EXPECT_CALL(mock_gbm, gbm_bo_write(mock_gbm.fake_gbm.bo, ContainsASingleWhitePixel(width*height), buffer_size_bytes));
445
444
 
446
445
    mgm::Cursor cursor_tmp{mock_gbm.fake_gbm.device, output_container,
447
 
        std::make_shared<StubCurrentConfiguration>(),
448
 
        std::make_shared<SinglePixelCursorImage>()};
 
446
        std::make_shared<StubCurrentConfiguration>()};
 
447
    cursor_tmp.show(SinglePixelCursorImage());
449
448
}
450
449
 
451
450
TEST_F(MesaCursorTest, throws_when_images_are_too_large)
467
466
    }, std::logic_error);
468
467
}
469
468
 
470
 
TEST_F(MesaCursorTest, forces_cursor_state_on_construction)
 
469
TEST_F(MesaCursorTest, clears_cursor_state_on_construction)
471
470
{
472
471
    using namespace testing;
473
472
 
474
 
    EXPECT_CALL(*output_container.outputs[10], move_cursor(geom::Point{0,0}));
475
 
    EXPECT_CALL(*output_container.outputs[10], set_cursor(_));
 
473
    EXPECT_CALL(*output_container.outputs[10], clear_cursor());
476
474
    EXPECT_CALL(*output_container.outputs[11], clear_cursor());
477
475
    EXPECT_CALL(*output_container.outputs[12], clear_cursor());
478
476
 
479
477
    /* No checking of existing cursor state */
480
 
    EXPECT_CALL(*output_container.outputs[10], has_cursor()).Times(1);
 
478
    EXPECT_CALL(*output_container.outputs[10], has_cursor()).Times(0);
481
479
    EXPECT_CALL(*output_container.outputs[11], has_cursor()).Times(0);
482
480
    EXPECT_CALL(*output_container.outputs[12], has_cursor()).Times(0);
483
481
 
484
482
    mgm::Cursor cursor_tmp{mock_gbm.fake_gbm.device, output_container,
485
 
       std::make_shared<StubCurrentConfiguration>(),
486
 
       std::make_shared<StubCursorImage>()};
 
483
       std::make_shared<StubCurrentConfiguration>()};
487
484
 
488
485
    output_container.verify_and_clear_expectations();
489
486
}
492
489
{
493
490
    using namespace testing;
494
491
 
495
 
    EXPECT_CALL(*output_container.outputs[10], has_cursor())
496
 
        .WillOnce(Return(false));
 
492
    ON_CALL(*output_container.outputs[10], clear_cursor())
 
493
        .WillByDefault(Return(false));
 
494
    ON_CALL(*output_container.outputs[10], set_cursor(_))
 
495
        .WillByDefault(Return(false));
 
496
    ON_CALL(*output_container.outputs[10], has_cursor())
 
497
        .WillByDefault(Return(false));
497
498
 
498
499
    EXPECT_THROW(
499
500
        mgm::Cursor cursor_tmp(mock_gbm.fake_gbm.device, output_container,
500
 
           std::make_shared<StubCurrentConfiguration>(),
501
 
           std::make_shared<StubCursorImage>())
 
501
           std::make_shared<StubCurrentConfiguration>());
502
502
    , std::runtime_error);
503
503
}
504
504
 
506
506
{
507
507
    using namespace testing;
508
508
 
 
509
    cursor.show(stub_image);
 
510
 
509
511
    EXPECT_CALL(*output_container.outputs[10], has_cursor())
510
512
        .WillOnce(Return(false))
511
513
        .WillOnce(Return(true));
524
526
{
525
527
    using namespace testing;
526
528
 
 
529
    cursor.show(stub_image);
 
530
 
527
531
    EXPECT_CALL(*output_container.outputs[10], has_cursor())
528
532
        .WillOnce(Return(true));
529
533
    EXPECT_CALL(*output_container.outputs[10], set_cursor(_))
543
547
{
544
548
    using namespace testing;
545
549
 
 
550
    cursor.show(stub_image);
 
551
 
546
552
    EXPECT_CALL(*output_container.outputs[10], move_cursor(geom::Point{10,10}));
547
553
    EXPECT_CALL(*output_container.outputs[11], move_cursor(_))
548
554
        .Times(0);
580
586
{
581
587
    using namespace testing;
582
588
 
 
589
    cursor.show(stub_image);
 
590
 
583
591
    current_configuration.conf.set_orentation_of_output(mg::DisplayConfigurationOutputId{12}, mir_orientation_left);
584
592
 
585
593
    EXPECT_CALL(*output_container.outputs[12], move_cursor(geom::Point{112,100}));
596
604
{
597
605
    using namespace testing;
598
606
 
 
607
    cursor.show(stub_image);
 
608
 
599
609
    current_configuration.conf.set_orentation_of_output(mg::DisplayConfigurationOutputId{12}, mir_orientation_right);
600
610
 
601
611
 
612
622
{
613
623
    using namespace testing;
614
624
 
 
625
    cursor.show(stub_image);
 
626
 
615
627
    current_configuration.conf.set_orentation_of_output(mg::DisplayConfigurationOutputId{12}, mir_orientation_inverted);
616
628
 
617
629
    EXPECT_CALL(*output_container.outputs[12], move_cursor(geom::Point{700,88}));
666
678
{
667
679
    using namespace testing;
668
680
 
 
681
    cursor.show(stub_image);
 
682
 
669
683
    EXPECT_CALL(*output_container.outputs[10], move_cursor(geom::Point{150,75}));
670
684
    EXPECT_CALL(*output_container.outputs[11], move_cursor(geom::Point{50,25}));
671
685
    EXPECT_CALL(*output_container.outputs[10], clear_cursor());
736
750
{
737
751
    using namespace testing;
738
752
 
 
753
    cursor.show(stub_image); // ensures initial_cursor_location
 
754
 
739
755
    static geom::Displacement hotspot_displacement{10, 10};
740
756
    
741
757
    static geom::Point const