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
=== modified file 'examples/animated_cursor_demo_client.c'
--- examples/animated_cursor_demo_client.c 2015-02-25 22:10:35 +0000
+++ examples/animated_cursor_demo_client.c 2015-09-29 16:26:37 +0000
@@ -52,7 +52,9 @@
52{52{
53 MirBufferStream* stream = mir_connection_create_buffer_stream_sync(connection,53 MirBufferStream* stream = mir_connection_create_buffer_stream_sync(connection,
54 24, 24, mir_pixel_format_argb_8888, mir_buffer_usage_software);54 24, 24, mir_pixel_format_argb_8888, mir_buffer_usage_software);
55 55
56 animate_cursor(stream);
57
56 MirCursorConfiguration* conf = mir_cursor_configuration_from_buffer_stream(stream, 0, 0);58 MirCursorConfiguration* conf = mir_cursor_configuration_from_buffer_stream(stream, 0, 0);
57 mir_wait_for(mir_surface_configure_cursor(surface, conf));59 mir_wait_for(mir_surface_configure_cursor(surface, conf));
58 mir_cursor_configuration_destroy(conf);60 mir_cursor_configuration_destroy(conf);
5961
=== modified file 'src/server/graphics/nested/mir_client_host_connection.cpp'
--- src/server/graphics/nested/mir_client_host_connection.cpp 2015-09-25 16:23:50 +0000
+++ src/server/graphics/nested/mir_client_host_connection.cpp 2015-09-29 16:26:37 +0000
@@ -130,12 +130,6 @@
130 {130 {
131 cursor_hotspot = image.hotspot();131 cursor_hotspot = image.hotspot();
132132
133 // push an extra frame for host to display correctly
134 // TODO remove this workaround for lp:1308133
135 mir_buffer_stream_get_graphics_region(cursor, &g);
136 memcpy(g.vaddr, image.as_argb_8888(), pixels_size);
137 mir_buffer_stream_swap_buffers_sync(cursor);
138
139 auto conf = mir_cursor_configuration_from_buffer_stream(133 auto conf = mir_cursor_configuration_from_buffer_stream(
140 cursor, cursor_hotspot.dx.as_int(), cursor_hotspot.dy.as_int());134 cursor, cursor_hotspot.dx.as_int(), cursor_hotspot.dy.as_int());
141135
142136
=== modified file 'src/server/scene/basic_surface.cpp'
--- src/server/scene/basic_surface.cpp 2015-07-27 07:24:50 +0000
+++ src/server/scene/basic_surface.cpp 2015-09-29 16:26:37 +0000
@@ -124,6 +124,73 @@
124 { observer->renamed(name); });124 { observer->renamed(name); });
125}125}
126126
127struct ms::CursorStreamImageAdapter
128{
129 CursorStreamImageAdapter(ms::BasicSurface &surface)
130 : surface(surface),
131 observer{std::make_shared<FramePostObserver>(this)}
132 {
133 }
134
135 ~CursorStreamImageAdapter()
136 {
137 reset();
138 }
139
140 void reset()
141 {
142 if (stream)
143 {
144 stream->remove_observer(observer);
145 stream.reset();
146 }
147 }
148
149 void update(std::shared_ptr<mf::BufferStream> const& new_stream, geom::Displacement const& new_hotspot)
150 {
151 if (new_stream == stream && new_hotspot == hotspot)
152 {
153 return;
154 }
155 else if (new_stream != stream)
156 {
157 if (stream) stream->remove_observer(observer);
158
159 stream = std::dynamic_pointer_cast<mc::BufferStream>(new_stream);
160 stream->add_observer(observer);
161 }
162
163 hotspot = new_hotspot;
164 post_cursor_image_from_current_buffer();
165 }
166
167private:
168 struct FramePostObserver : public ms::NullSurfaceObserver
169 {
170 FramePostObserver(CursorStreamImageAdapter const* self)
171 : self(self)
172 {
173 }
174
175 void frame_posted(int /* available */)
176 {
177 self->post_cursor_image_from_current_buffer();
178 }
179
180 CursorStreamImageAdapter const* const self;
181 };
182
183 void post_cursor_image_from_current_buffer() const
184 {
185 surface.set_cursor_from_buffer(*stream->lock_compositor_buffer(this), hotspot);
186 }
187
188 ms::BasicSurface& surface;
189 std::shared_ptr<FramePostObserver> const observer;
190
191 std::shared_ptr<mc::BufferStream> stream;
192 geom::Displacement hotspot;
193};
127194
128ms::BasicSurface::BasicSurface(195ms::BasicSurface::BasicSurface(
129 std::string const& name,196 std::string const& name,
@@ -149,6 +216,7 @@
149 report(report),216 report(report),
150 parent_(parent),217 parent_(parent),
151 layers({StreamInfo{buffer_stream, {0,0}}}),218 layers({StreamInfo{buffer_stream, {0,0}}}),
219 cursor_stream_adapter{std::make_unique<ms::CursorStreamImageAdapter>(*this)},
152 input_validator([this](MirEvent const& ev) { this->input_sender->send_event(ev, server_input_channel); })220 input_validator([this](MirEvent const& ev) { this->input_sender->send_event(ev, server_input_channel); })
153{221{
154 report->surface_created(this, surface_name);222 report->surface_created(this, surface_name);
@@ -540,7 +608,7 @@
540{608{
541 {609 {
542 std::unique_lock<std::mutex> lock(guard);610 std::unique_lock<std::mutex> lock(guard);
543 cursor_stream_adapter.reset();611 cursor_stream_adapter->reset();
544 612
545 cursor_image_ = image;613 cursor_image_ = image;
546 }614 }
@@ -556,20 +624,6 @@
556624
557namespace625namespace
558{626{
559struct FramePostObserver : public ms::NullSurfaceObserver
560{
561 FramePostObserver(std::function<void()> const& exec)
562 : exec(exec)
563 {
564 }
565
566 void frame_posted(int /* available */)
567 {
568 exec();
569 }
570 std::function<void()> const exec;
571};
572
573struct CursorImageFromBuffer : public mg::CursorImage627struct CursorImageFromBuffer : public mg::CursorImage
574{628{
575 CursorImageFromBuffer(mg::Buffer &buffer, geom::Displacement const& hotspot)629 CursorImageFromBuffer(mg::Buffer &buffer, geom::Displacement const& hotspot)
@@ -608,45 +662,6 @@
608};662};
609}663}
610664
611namespace mir
612{
613namespace scene
614{
615struct CursorStreamImageAdapter
616{
617 CursorStreamImageAdapter(ms::BasicSurface &surface, std::shared_ptr<mf::BufferStream> const& stream,
618 geom::Displacement const& hotspot)
619 : surface(surface),
620 stream(stream),
621 observer{std::make_shared<FramePostObserver>(
622 [this](){ post_cursor_image_from_current_buffer(); })},
623 hotspot(hotspot)
624 {
625 stream->add_observer(observer);
626 }
627
628 ~CursorStreamImageAdapter()
629 {
630 stream->remove_observer(observer);
631 }
632
633 void post_cursor_image_from_current_buffer()
634 {
635 stream->with_most_recent_buffer_do([&](mg::Buffer &buffer)
636 {
637 surface.set_cursor_from_buffer(buffer, hotspot);
638 });
639 }
640
641 ms::BasicSurface &surface;
642
643 std::shared_ptr<mf::BufferStream> const stream;
644 std::shared_ptr<FramePostObserver> observer;
645 geom::Displacement const hotspot;
646};
647}
648}
649
650void ms::BasicSurface::set_cursor_from_buffer(mg::Buffer& buffer, geom::Displacement const& hotspot)665void ms::BasicSurface::set_cursor_from_buffer(mg::Buffer& buffer, geom::Displacement const& hotspot)
651{666{
652 auto image = std::make_shared<CursorImageFromBuffer>(buffer, hotspot);667 auto image = std::make_shared<CursorImageFromBuffer>(buffer, hotspot);
@@ -667,12 +682,7 @@
667void ms::BasicSurface::set_cursor_stream(std::shared_ptr<mf::BufferStream> const& stream,682void ms::BasicSurface::set_cursor_stream(std::shared_ptr<mf::BufferStream> const& stream,
668 geom::Displacement const& hotspot)683 geom::Displacement const& hotspot)
669{684{
670 std::unique_lock<std::mutex> lock(guard);685 cursor_stream_adapter->update(stream, hotspot);
671
672 cursor_stream_adapter = std::make_unique<ms::CursorStreamImageAdapter>(*this, stream, hotspot);
673 stream->with_most_recent_buffer_do([this, &hotspot](mg::Buffer& buffer) {
674 cursor_image_ = std::make_shared<CursorImageFromBuffer>(buffer, hotspot);
675 });
676}686}
677687
678void ms::BasicSurface::request_client_surface_close()688void ms::BasicSurface::request_client_surface_close()
679689
=== modified file 'src/server/scene/basic_surface.h'
--- src/server/scene/basic_surface.h 2015-07-23 02:39:20 +0000
+++ src/server/scene/basic_surface.h 2015-09-29 16:26:37 +0000
@@ -184,7 +184,7 @@
184 MirSurfaceVisibility visibility_ = mir_surface_visibility_exposed;184 MirSurfaceVisibility visibility_ = mir_surface_visibility_exposed;
185 MirOrientationMode pref_orientation_mode = mir_orientation_mode_any;185 MirOrientationMode pref_orientation_mode = mir_orientation_mode_any;
186186
187 std::unique_ptr<CursorStreamImageAdapter> cursor_stream_adapter;187 std::unique_ptr<CursorStreamImageAdapter> const cursor_stream_adapter;
188188
189 input::Validator input_validator;189 input::Validator input_validator;
190};190};

Subscribers

People subscribed via source and target branches