Mir

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

Proposed by Alan Griffiths
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 2980
Proposed branch: lp:~alan-griffiths/mir/fix-1308133
Merge into: lp:mir
Prerequisite: lp:~alan-griffiths/mir/make-cursors-less-broken
Diff against target: 220 lines (+74/-68)
4 files modified
examples/animated_cursor_demo_client.c (+3/-1)
src/server/graphics/nested/mir_client_host_connection.cpp (+0/-6)
src/server/scene/basic_surface.cpp (+70/-60)
src/server/scene/basic_surface.h (+1/-1)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1308133
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Alexandros Frantzis (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+272819@code.launchpad.net

Commit message

scene: use the cursor stream for a surface correctly by extracting frames for "composition", not "snapshotting" the last composited frame.
(LP: #1308133)

Description of the change

scene: use the cursor stream for a surface correctly by extracting frames for "composition", not "snapshotting" the last composited frame.

To post a comment you must log in.
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.

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

Oh wow. Such a silly mistake.

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

Confirmed; this fixes the missing cursor in Xmir. In fact this fixes it better than the workaround I have in Xmir.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/animated_cursor_demo_client.c'
2--- examples/animated_cursor_demo_client.c 2015-02-25 22:10:35 +0000
3+++ examples/animated_cursor_demo_client.c 2015-09-29 16:26:37 +0000
4@@ -52,7 +52,9 @@
5 {
6 MirBufferStream* stream = mir_connection_create_buffer_stream_sync(connection,
7 24, 24, mir_pixel_format_argb_8888, mir_buffer_usage_software);
8-
9+
10+ animate_cursor(stream);
11+
12 MirCursorConfiguration* conf = mir_cursor_configuration_from_buffer_stream(stream, 0, 0);
13 mir_wait_for(mir_surface_configure_cursor(surface, conf));
14 mir_cursor_configuration_destroy(conf);
15
16=== modified file 'src/server/graphics/nested/mir_client_host_connection.cpp'
17--- src/server/graphics/nested/mir_client_host_connection.cpp 2015-09-25 16:23:50 +0000
18+++ src/server/graphics/nested/mir_client_host_connection.cpp 2015-09-29 16:26:37 +0000
19@@ -130,12 +130,6 @@
20 {
21 cursor_hotspot = image.hotspot();
22
23- // push an extra frame for host to display correctly
24- // TODO remove this workaround for lp:1308133
25- mir_buffer_stream_get_graphics_region(cursor, &g);
26- memcpy(g.vaddr, image.as_argb_8888(), pixels_size);
27- mir_buffer_stream_swap_buffers_sync(cursor);
28-
29 auto conf = mir_cursor_configuration_from_buffer_stream(
30 cursor, cursor_hotspot.dx.as_int(), cursor_hotspot.dy.as_int());
31
32
33=== modified file 'src/server/scene/basic_surface.cpp'
34--- src/server/scene/basic_surface.cpp 2015-07-27 07:24:50 +0000
35+++ src/server/scene/basic_surface.cpp 2015-09-29 16:26:37 +0000
36@@ -124,6 +124,73 @@
37 { observer->renamed(name); });
38 }
39
40+struct ms::CursorStreamImageAdapter
41+{
42+ CursorStreamImageAdapter(ms::BasicSurface &surface)
43+ : surface(surface),
44+ observer{std::make_shared<FramePostObserver>(this)}
45+ {
46+ }
47+
48+ ~CursorStreamImageAdapter()
49+ {
50+ reset();
51+ }
52+
53+ void reset()
54+ {
55+ if (stream)
56+ {
57+ stream->remove_observer(observer);
58+ stream.reset();
59+ }
60+ }
61+
62+ void update(std::shared_ptr<mf::BufferStream> const& new_stream, geom::Displacement const& new_hotspot)
63+ {
64+ if (new_stream == stream && new_hotspot == hotspot)
65+ {
66+ return;
67+ }
68+ else if (new_stream != stream)
69+ {
70+ if (stream) stream->remove_observer(observer);
71+
72+ stream = std::dynamic_pointer_cast<mc::BufferStream>(new_stream);
73+ stream->add_observer(observer);
74+ }
75+
76+ hotspot = new_hotspot;
77+ post_cursor_image_from_current_buffer();
78+ }
79+
80+private:
81+ struct FramePostObserver : public ms::NullSurfaceObserver
82+ {
83+ FramePostObserver(CursorStreamImageAdapter const* self)
84+ : self(self)
85+ {
86+ }
87+
88+ void frame_posted(int /* available */)
89+ {
90+ self->post_cursor_image_from_current_buffer();
91+ }
92+
93+ CursorStreamImageAdapter const* const self;
94+ };
95+
96+ void post_cursor_image_from_current_buffer() const
97+ {
98+ surface.set_cursor_from_buffer(*stream->lock_compositor_buffer(this), hotspot);
99+ }
100+
101+ ms::BasicSurface& surface;
102+ std::shared_ptr<FramePostObserver> const observer;
103+
104+ std::shared_ptr<mc::BufferStream> stream;
105+ geom::Displacement hotspot;
106+};
107
108 ms::BasicSurface::BasicSurface(
109 std::string const& name,
110@@ -149,6 +216,7 @@
111 report(report),
112 parent_(parent),
113 layers({StreamInfo{buffer_stream, {0,0}}}),
114+ cursor_stream_adapter{std::make_unique<ms::CursorStreamImageAdapter>(*this)},
115 input_validator([this](MirEvent const& ev) { this->input_sender->send_event(ev, server_input_channel); })
116 {
117 report->surface_created(this, surface_name);
118@@ -540,7 +608,7 @@
119 {
120 {
121 std::unique_lock<std::mutex> lock(guard);
122- cursor_stream_adapter.reset();
123+ cursor_stream_adapter->reset();
124
125 cursor_image_ = image;
126 }
127@@ -556,20 +624,6 @@
128
129 namespace
130 {
131-struct FramePostObserver : public ms::NullSurfaceObserver
132-{
133- FramePostObserver(std::function<void()> const& exec)
134- : exec(exec)
135- {
136- }
137-
138- void frame_posted(int /* available */)
139- {
140- exec();
141- }
142- std::function<void()> const exec;
143-};
144-
145 struct CursorImageFromBuffer : public mg::CursorImage
146 {
147 CursorImageFromBuffer(mg::Buffer &buffer, geom::Displacement const& hotspot)
148@@ -608,45 +662,6 @@
149 };
150 }
151
152-namespace mir
153-{
154-namespace scene
155-{
156-struct CursorStreamImageAdapter
157-{
158- CursorStreamImageAdapter(ms::BasicSurface &surface, std::shared_ptr<mf::BufferStream> const& stream,
159- geom::Displacement const& hotspot)
160- : surface(surface),
161- stream(stream),
162- observer{std::make_shared<FramePostObserver>(
163- [this](){ post_cursor_image_from_current_buffer(); })},
164- hotspot(hotspot)
165- {
166- stream->add_observer(observer);
167- }
168-
169- ~CursorStreamImageAdapter()
170- {
171- stream->remove_observer(observer);
172- }
173-
174- void post_cursor_image_from_current_buffer()
175- {
176- stream->with_most_recent_buffer_do([&](mg::Buffer &buffer)
177- {
178- surface.set_cursor_from_buffer(buffer, hotspot);
179- });
180- }
181-
182- ms::BasicSurface &surface;
183-
184- std::shared_ptr<mf::BufferStream> const stream;
185- std::shared_ptr<FramePostObserver> observer;
186- geom::Displacement const hotspot;
187-};
188-}
189-}
190-
191 void ms::BasicSurface::set_cursor_from_buffer(mg::Buffer& buffer, geom::Displacement const& hotspot)
192 {
193 auto image = std::make_shared<CursorImageFromBuffer>(buffer, hotspot);
194@@ -667,12 +682,7 @@
195 void ms::BasicSurface::set_cursor_stream(std::shared_ptr<mf::BufferStream> const& stream,
196 geom::Displacement const& hotspot)
197 {
198- std::unique_lock<std::mutex> lock(guard);
199-
200- cursor_stream_adapter = std::make_unique<ms::CursorStreamImageAdapter>(*this, stream, hotspot);
201- stream->with_most_recent_buffer_do([this, &hotspot](mg::Buffer& buffer) {
202- cursor_image_ = std::make_shared<CursorImageFromBuffer>(buffer, hotspot);
203- });
204+ cursor_stream_adapter->update(stream, hotspot);
205 }
206
207 void ms::BasicSurface::request_client_surface_close()
208
209=== modified file 'src/server/scene/basic_surface.h'
210--- src/server/scene/basic_surface.h 2015-07-23 02:39:20 +0000
211+++ src/server/scene/basic_surface.h 2015-09-29 16:26:37 +0000
212@@ -184,7 +184,7 @@
213 MirSurfaceVisibility visibility_ = mir_surface_visibility_exposed;
214 MirOrientationMode pref_orientation_mode = mir_orientation_mode_any;
215
216- std::unique_ptr<CursorStreamImageAdapter> cursor_stream_adapter;
217+ std::unique_ptr<CursorStreamImageAdapter> const cursor_stream_adapter;
218
219 input::Validator input_validator;
220 };

Subscribers

People subscribed via source and target branches