Mir

Merge lp:~alan-griffiths/mir/fix-1496849 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 2964
Proposed branch: lp:~alan-griffiths/mir/fix-1496849
Merge into: lp:mir
Diff against target: 119 lines (+38/-20)
3 files modified
src/server/graphics/nested/cursor.cpp (+4/-1)
src/server/graphics/nested/cursor.h (+1/-1)
src/server/graphics/nested/mir_client_host_connection.cpp (+33/-18)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1496849
Reviewer Review Type Date Requested Status
Daniel van Vugt Needs Information
Alexandros Frantzis (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+271949@code.launchpad.net

Commit message

graphics: when supplying the host Mir with a cursor don't discard the buffer stream that supports it

Description of the change

graphics: when supplying the host Mir with a cursor don't discard the buffer stream that supports it

NB This fixes the linked bug, but isn't the last problem in this area. In particular, testing with "animated_cursor" shows that when moving outside the client window the default cursor isn't restored.

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

@testing with "animated_cursor" - the problem is that the displayed cursor is a frame behind the nested server. Will tackle in a follow-up MP.

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

Looks good.

Nit:

+mgn::Cursor::~Cursor()
+{
+}

mgn::Cursor::~Cursor() = default

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

I haven't looked into how the cursor buffer stream stuff works yet, but based on your description alone I'm concerned we might have a bad client API design. The client should be able to set-and-forget a cursor. Don't we support that?

Revision history for this message
Daniel van Vugt (vanvugt) :
review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> I haven't looked into how the cursor buffer stream stuff works yet, but based
> on your description alone I'm concerned we might have a bad client API design.
> The client should be able to set-and-forget a cursor. Don't we support that?

The original code didn't "forget" the buffer stream - it released it.

I'm not trying to defend the design (or implementation) of cursors. (As anyone hearing my recent complaints would realize.) I'm working to get the cursor code under some useful tests[1] as preparation for some rework.

[1] Note that the existing interaction between tests and implementation are "interesting". For example cursor_request_applied_from_buffer_stream configures the cursor before posting any buffers in this scenario BasicSurface::set_cursor_stream() creates an image from the stream before the stream has received a buffer.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/graphics/nested/cursor.cpp'
2--- src/server/graphics/nested/cursor.cpp 2015-05-19 21:34:34 +0000
3+++ src/server/graphics/nested/cursor.cpp 2015-09-22 12:00:32 +0000
4@@ -31,9 +31,12 @@
5 connection->set_cursor_image(*default_image);
6 }
7
8+mgn::Cursor::~Cursor()
9+{
10+}
11+
12 void mgn::Cursor::move_to(geom::Point)
13 {
14- // TODO Should this throw?
15 }
16
17 void mgn::Cursor::show(mg::CursorImage const& cursor_image)
18
19=== modified file 'src/server/graphics/nested/cursor.h'
20--- src/server/graphics/nested/cursor.h 2015-05-19 21:34:34 +0000
21+++ src/server/graphics/nested/cursor.h 2015-09-22 12:00:32 +0000
22@@ -32,7 +32,7 @@
23 {
24 public:
25 Cursor(std::shared_ptr<HostConnection> const& host_connection, std::shared_ptr<CursorImage> const& default_image);
26- ~Cursor() = default;
27+ ~Cursor();
28
29 void show(CursorImage const& image) override;
30 void show() override;
31
32=== modified file 'src/server/graphics/nested/mir_client_host_connection.cpp'
33--- src/server/graphics/nested/mir_client_host_connection.cpp 2015-09-07 15:28:22 +0000
34+++ src/server/graphics/nested/mir_client_host_connection.cpp 2015-09-22 12:00:32 +0000
35@@ -74,6 +74,7 @@
36
37 ~MirClientHostSurface()
38 {
39+ if (cursor) mir_buffer_stream_release_sync(cursor);
40 mir_surface_release_sync(mir_surface);
41 }
42
43@@ -90,36 +91,50 @@
44
45 void set_cursor_image(mg::CursorImage const& image)
46 {
47- auto image_width = image.size().width.as_int();
48- auto image_height = image.size().height.as_int();
49- auto pixels_size = image_width * image_height
50+ auto const image_width = image.size().width.as_int();
51+ auto const image_height = image.size().height.as_int();
52+ auto const pixels_size = image_width * image_height
53 * MIR_BYTES_PER_PIXEL(mir_pixel_format_argb_8888);
54
55- // TODO: Maybe the stream should be preserved.
56- auto bs = mir_connection_create_buffer_stream_sync(mir_connection,
57- image_width,
58- image_height,
59- mir_pixel_format_argb_8888,
60- mir_buffer_usage_software);
61-
62 MirGraphicsRegion g;
63- mir_buffer_stream_get_graphics_region(bs, &g);
64- if ((g.height * g.stride) !=
65- pixels_size)
66- BOOST_THROW_EXCEPTION(std::runtime_error("Cursor BufferStream not compatible with requested cursor image"));
67+
68+ if (cursor)
69+ {
70+ mir_buffer_stream_get_graphics_region(cursor, &g);
71+
72+ if (image_width != g.width || image_height != g.height)
73+ {
74+ mir_buffer_stream_release_sync(cursor);
75+ cursor = nullptr;
76+ }
77+ }
78+
79+ if (!cursor)
80+ {
81+ cursor = mir_connection_create_buffer_stream_sync(
82+ mir_connection,
83+ image_width,
84+ image_height,
85+ mir_pixel_format_argb_8888,
86+ mir_buffer_usage_software);
87+
88+ mir_buffer_stream_get_graphics_region(cursor, &g);
89+ }
90+
91 memcpy(g.vaddr, image.as_argb_8888(), pixels_size);
92- mir_buffer_stream_swap_buffers_sync(bs);
93+ mir_buffer_stream_swap_buffers_sync(cursor);
94
95- auto conf = mir_cursor_configuration_from_buffer_stream(bs,
96+ auto conf = mir_cursor_configuration_from_buffer_stream(cursor,
97 image.hotspot().dx.as_int(), image.hotspot().dy.as_int());
98
99 mir_surface_configure_cursor(mir_surface, conf);
100 mir_cursor_configuration_destroy(conf);
101- mir_buffer_stream_release_sync(bs);
102 }
103
104 void hide_cursor()
105 {
106+ if (cursor) { mir_buffer_stream_release_sync(cursor); cursor = nullptr; }
107+
108 auto conf = mir_cursor_configuration_from_name(mir_disabled_cursor_name);
109 mir_surface_configure_cursor(mir_surface, conf);
110 mir_cursor_configuration_destroy(conf);
111@@ -128,7 +143,7 @@
112 private:
113 MirConnection* const mir_connection;
114 MirSurface* const mir_surface;
115-
116+ MirBufferStream* cursor{nullptr};
117 };
118
119 }

Subscribers

People subscribed via source and target branches