Mir

Merge lp:~alan-griffiths/mir/workaround-1464690 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alberto Aguirre
Approved revision: no longer in the source branch.
Merged at revision: 2662
Proposed branch: lp:~alan-griffiths/mir/workaround-1464690
Merge into: lp:mir
Diff against target: 140 lines (+39/-45)
2 files modified
examples/server_example_canonical_window_manager.cpp (+23/-44)
examples/server_example_canonical_window_manager.h (+16/-1)
To merge this branch: bzr merge lp:~alan-griffiths/mir/workaround-1464690
Reviewer Review Type Date Requested Status
Kevin DuBois (community) Approve
Alberto Aguirre (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+261966@code.launchpad.net

Commit message

examples: don't block the window manager to paint titlebars

Description of the change

examples: don't block the window manager to paint titlebars

This avoids the deadlock noted in lp:1464690.

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
Alberto Aguirre (albaguirre) wrote :

LGTM

review: Approve
Revision history for this message
Kevin DuBois (kdub) wrote :

There's still a bit of a structural problem (lp: #1395421 ), that oftentimes the compositor will drive the ipc, and now, it will sometimes paint on behalf of the window manager. I suppose this is better than a deadlock though, so lgtm too

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/server_example_canonical_window_manager.cpp'
--- examples/server_example_canonical_window_manager.cpp 2015-06-08 14:41:13 +0000
+++ examples/server_example_canonical_window_manager.cpp 2015-06-15 13:53:13 +0000
@@ -72,7 +72,8 @@
72 width_inc{params.width_inc},72 width_inc{params.width_inc},
73 height_inc{params.height_inc},73 height_inc{params.height_inc},
74 min_aspect{params.min_aspect},74 min_aspect{params.min_aspect},
75 max_aspect{params.max_aspect}75 max_aspect{params.max_aspect},
76 buffer_stream(surface->primary_buffer_stream())
76{77{
77}78}
7879
@@ -253,49 +254,27 @@
253254
254//TODO: provide an easier way for the server to write to a surface!255//TODO: provide an easier way for the server to write to a surface!
255//TODO: this is painful to use mg::Buffer::write()256//TODO: this is painful to use mg::Buffer::write()
256namespace257void mir::examples::CanonicalSurfaceInfoCopy::paint_titlebar(int intensity)
257{258{
258void swap_buffers(259 if (auto const buf = this->buffer.load())
259 std::shared_ptr<ms::Surface> const& surface,260 {
260 mir::graphics::Buffer*& surface_buffer)261 auto const format = buffer_stream->pixel_format();
261{262 auto const sz = buf->size().height.as_int() *
262 std::mutex mut;263 buf->size().width.as_int() * MIR_BYTES_PER_PIXEL(format);
263 std::condition_variable cv;264
264265 std::vector<unsigned char> pixels(sz, intensity);
265 auto const callback = [&](mir::graphics::Buffer* buffer)266 buf->write(pixels.data(), sz);
267 }
268
269 auto const callback = [this, intensity](mir::graphics::Buffer* new_buffer)
266 {270 {
267 std::unique_lock<decltype(mut)> lk(mut);271 bool const first_time = !buffer;
268 surface_buffer = buffer;272 buffer.store(new_buffer);
269 cv.notify_one();273 if (first_time)
274 paint_titlebar(intensity);
270 };275 };
271276
272 auto const old_buffer = surface_buffer;277 buffer_stream->swap_buffers(buffer, callback);
273
274 surface->primary_buffer_stream()->swap_buffers(surface_buffer, callback);
275
276 std::unique_lock<decltype(mut)> lk(mut);
277 cv.wait(lk, [&]{return old_buffer != surface_buffer;});
278}
279
280void paint_titlebar(
281 std::shared_ptr<ms::Surface> const& titlebar,
282 mir::examples::CanonicalSurfaceInfoCopy& titlebar_info,
283 int intensity)
284{
285 auto stream = titlebar->primary_buffer_stream();
286 auto const format = stream->pixel_format();
287
288 if (!titlebar_info.buffer)
289 swap_buffers(titlebar, titlebar_info.buffer);
290
291 auto const sz = titlebar_info.buffer->size().height.as_int() *
292 titlebar_info.buffer->size().width.as_int() * MIR_BYTES_PER_PIXEL(format);
293
294 std::vector<unsigned char> pixels(sz, intensity);
295 titlebar_info.buffer->write(pixels.data(), sz);
296
297 swap_buffers(titlebar, titlebar_info.buffer);
298}
299}278}
300279
301void me::CanonicalWindowManagerPolicyCopy::generate_decorations_for(280void me::CanonicalWindowManagerPolicyCopy::generate_decorations_for(
@@ -708,7 +687,7 @@
708 {687 {
709 if (auto const titlebar = tools->info_for(active_surface).titlebar)688 if (auto const titlebar = tools->info_for(active_surface).titlebar)
710 {689 {
711 paint_titlebar(titlebar, tools->info_for(titlebar), 0x3F);690 tools->info_for(titlebar).paint_titlebar(0x3F);
712 }691 }
713 }692 }
714693
@@ -734,12 +713,12 @@
734 {713 {
735 if (auto const titlebar = tools->info_for(active_surface).titlebar)714 if (auto const titlebar = tools->info_for(active_surface).titlebar)
736 {715 {
737 paint_titlebar(titlebar, tools->info_for(titlebar), 0x3F);716 tools->info_for(titlebar).paint_titlebar(0x3F);
738 }717 }
739 }718 }
740 if (auto const titlebar = tools->info_for(surface).titlebar)719 if (auto const titlebar = tools->info_for(surface).titlebar)
741 {720 {
742 paint_titlebar(titlebar, tools->info_for(titlebar), 0xFF);721 tools->info_for(titlebar).paint_titlebar(0xFF);
743 }722 }
744 tools->set_focus_to(info_for.session.lock(), surface);723 tools->set_focus_to(info_for.session.lock(), surface);
745 raise_tree(surface);724 raise_tree(surface);
746725
=== modified file 'examples/server_example_canonical_window_manager.h'
--- examples/server_example_canonical_window_manager.h 2015-05-27 11:37:38 +0000
+++ examples/server_example_canonical_window_manager.h 2015-06-15 13:53:13 +0000
@@ -23,6 +23,8 @@
2323
24#include "mir/geometry/displacement.h"24#include "mir/geometry/displacement.h"
2525
26#include <atomic>
27
26///\example server_example_canonical_window_manager.h28///\example server_example_canonical_window_manager.h
27// Based on "Mir and Unity: Surfaces, input, and displays (v0.3)"29// Based on "Mir and Unity: Surfaces, input, and displays (v0.3)"
2830
@@ -59,7 +61,20 @@
59 mir::optional_value<shell::SurfaceAspectRatio> min_aspect;61 mir::optional_value<shell::SurfaceAspectRatio> min_aspect;
60 mir::optional_value<shell::SurfaceAspectRatio> max_aspect;62 mir::optional_value<shell::SurfaceAspectRatio> max_aspect;
6163
62 graphics::Buffer* buffer{nullptr};64 void paint_titlebar(int intensity);
65
66private:
67 std::shared_ptr<frontend::BufferStream> const buffer_stream;
68
69 // Add copy-ctor to std::atomic
70 struct AtomicBufferPtr : std::atomic<graphics::Buffer*>
71 {
72 using std::atomic<graphics::Buffer*>::atomic;
73
74 AtomicBufferPtr(AtomicBufferPtr const& that) :
75 std::atomic<graphics::Buffer*>{that.load()} {}
76 };
77 AtomicBufferPtr buffer{nullptr};
63};78};
6479
65// standard window management algorithm:80// standard window management algorithm:

Subscribers

People subscribed via source and target branches