Mir

Merge lp:~afrantzis/mir/fix-1462088-update-cursor-on-first-frame-posted into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 2723
Proposed branch: lp:~afrantzis/mir/fix-1462088-update-cursor-on-first-frame-posted
Merge into: lp:mir
Diff against target: 85 lines (+52/-1)
2 files modified
src/server/input/cursor_controller.cpp (+9/-1)
tests/unit-tests/input/test_cursor_controller.cpp (+43/-0)
To merge this branch: bzr merge lp:~afrantzis/mir/fix-1462088-update-cursor-on-first-frame-posted
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Kevin DuBois (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+263883@code.launchpad.net

Commit message

input: Update cursor when the first frame of a surface is posted

This MP fixes lp:1462088, which occurs when the request for disabling the cursor happens to reach the host server before the first buffer of the nested framebuffer surface. In such a case, when the nested framebuffer surface is first rendered by the host, the cursor is not applied and the test fails.

Description of the change

input: Update cursor when the first frame of a surface is posted

This MP fixes lp:1462088, which occurs when the request for disabling the cursor happens to reach the host server before the first buffer of the nested framebuffer surface. In such a case, when the nested framebuffer surface is first rendered by the host, the cursor is not applied and the test fails.

To post a comment you must log in.
Revision history for this message
Kevin DuBois (kdub) wrote :

could use a test, or at least some comments about which bug will pop up if the non-obvious logic is altered.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> could use a test, or at least some comments about which bug will pop up if the non-obvious logic is altered.

Done

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

lgtm

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/input/cursor_controller.cpp'
2--- src/server/input/cursor_controller.cpp 2015-06-17 05:20:42 +0000
3+++ src/server/input/cursor_controller.cpp 2015-07-06 13:52:28 +0000
4@@ -64,7 +64,14 @@
5 }
6 void frame_posted(int) override
7 {
8- // Frame posting wont trigger a cursor update
9+ // The first frame posted will trigger a cursor update, since it
10+ // changes the visibility status of the surface, and can thus affect
11+ // the cursor.
12+ if (!first_frame_posted)
13+ {
14+ first_frame_posted = true;
15+ cursor_controller->update_cursor_image();
16+ }
17 }
18 void alpha_set_to(float) override
19 {
20@@ -92,6 +99,7 @@
21 }
22
23 mi::CursorController* const cursor_controller;
24+ bool first_frame_posted = false;
25 };
26
27 struct UpdateCursorOnSceneChanges : ms::Observer
28
29=== modified file 'tests/unit-tests/input/test_cursor_controller.cpp'
30--- tests/unit-tests/input/test_cursor_controller.cpp 2015-06-25 03:00:08 +0000
31+++ tests/unit-tests/input/test_cursor_controller.cpp 2015-07-06 13:52:28 +0000
32@@ -163,6 +163,19 @@
33 observers.erase(it);
34 }
35
36+ void post_frame()
37+ {
38+ for (auto observer : observers)
39+ {
40+ observer->frame_posted(1);
41+ }
42+ }
43+
44+ void set_cursor_image_without_notifications(std::shared_ptr<mg::CursorImage> const& image)
45+ {
46+ cursor_image_ = image;
47+ }
48+
49 geom::Rectangle const bounds;
50 std::shared_ptr<mg::CursorImage> cursor_image_;
51
52@@ -387,3 +400,33 @@
53 targets.add_surface(mt::fake_shared(surface1));
54 targets.add_surface(mt::fake_shared(surface2));
55 }
56+
57+TEST_F(TestCursorController, updates_cursor_image_when_surface_posts_first_frame)
58+{
59+ using namespace ::testing;
60+
61+ StubInputSurface surface{rect_0_0_1_1,
62+ std::make_shared<NamedCursorImage>(cursor_name_1)};
63+ StubScene targets({mt::fake_shared(surface)});
64+
65+ // Cursor is set when we first create the controller
66+ // because of the existing surface
67+ EXPECT_CALL(cursor, show(CursorNamed(cursor_name_1))).Times(1);
68+
69+ mi::CursorController controller(mt::fake_shared(targets),
70+ mt::fake_shared(cursor), default_cursor_image);
71+
72+ Mock::VerifyAndClearExpectations(&cursor);
73+
74+ surface.set_cursor_image_without_notifications(
75+ std::make_shared<NamedCursorImage>(cursor_name_2));
76+
77+ // First post should lead to cursor update
78+ EXPECT_CALL(cursor, show(CursorNamed(cursor_name_2))).Times(1);
79+ surface.post_frame();
80+ Mock::VerifyAndClearExpectations(&cursor);
81+
82+ // Second post should have no effect
83+ EXPECT_CALL(cursor, show(_)).Times(0);
84+ surface.post_frame();
85+}

Subscribers

People subscribed via source and target branches