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
1=== modified file 'examples/server_example_canonical_window_manager.cpp'
2--- examples/server_example_canonical_window_manager.cpp 2015-06-08 14:41:13 +0000
3+++ examples/server_example_canonical_window_manager.cpp 2015-06-15 13:53:13 +0000
4@@ -72,7 +72,8 @@
5 width_inc{params.width_inc},
6 height_inc{params.height_inc},
7 min_aspect{params.min_aspect},
8- max_aspect{params.max_aspect}
9+ max_aspect{params.max_aspect},
10+ buffer_stream(surface->primary_buffer_stream())
11 {
12 }
13
14@@ -253,49 +254,27 @@
15
16 //TODO: provide an easier way for the server to write to a surface!
17 //TODO: this is painful to use mg::Buffer::write()
18-namespace
19-{
20-void swap_buffers(
21- std::shared_ptr<ms::Surface> const& surface,
22- mir::graphics::Buffer*& surface_buffer)
23-{
24- std::mutex mut;
25- std::condition_variable cv;
26-
27- auto const callback = [&](mir::graphics::Buffer* buffer)
28+void mir::examples::CanonicalSurfaceInfoCopy::paint_titlebar(int intensity)
29+{
30+ if (auto const buf = this->buffer.load())
31+ {
32+ auto const format = buffer_stream->pixel_format();
33+ auto const sz = buf->size().height.as_int() *
34+ buf->size().width.as_int() * MIR_BYTES_PER_PIXEL(format);
35+
36+ std::vector<unsigned char> pixels(sz, intensity);
37+ buf->write(pixels.data(), sz);
38+ }
39+
40+ auto const callback = [this, intensity](mir::graphics::Buffer* new_buffer)
41 {
42- std::unique_lock<decltype(mut)> lk(mut);
43- surface_buffer = buffer;
44- cv.notify_one();
45+ bool const first_time = !buffer;
46+ buffer.store(new_buffer);
47+ if (first_time)
48+ paint_titlebar(intensity);
49 };
50
51- auto const old_buffer = surface_buffer;
52-
53- surface->primary_buffer_stream()->swap_buffers(surface_buffer, callback);
54-
55- std::unique_lock<decltype(mut)> lk(mut);
56- cv.wait(lk, [&]{return old_buffer != surface_buffer;});
57-}
58-
59-void paint_titlebar(
60- std::shared_ptr<ms::Surface> const& titlebar,
61- mir::examples::CanonicalSurfaceInfoCopy& titlebar_info,
62- int intensity)
63-{
64- auto stream = titlebar->primary_buffer_stream();
65- auto const format = stream->pixel_format();
66-
67- if (!titlebar_info.buffer)
68- swap_buffers(titlebar, titlebar_info.buffer);
69-
70- auto const sz = titlebar_info.buffer->size().height.as_int() *
71- titlebar_info.buffer->size().width.as_int() * MIR_BYTES_PER_PIXEL(format);
72-
73- std::vector<unsigned char> pixels(sz, intensity);
74- titlebar_info.buffer->write(pixels.data(), sz);
75-
76- swap_buffers(titlebar, titlebar_info.buffer);
77-}
78+ buffer_stream->swap_buffers(buffer, callback);
79 }
80
81 void me::CanonicalWindowManagerPolicyCopy::generate_decorations_for(
82@@ -708,7 +687,7 @@
83 {
84 if (auto const titlebar = tools->info_for(active_surface).titlebar)
85 {
86- paint_titlebar(titlebar, tools->info_for(titlebar), 0x3F);
87+ tools->info_for(titlebar).paint_titlebar(0x3F);
88 }
89 }
90
91@@ -734,12 +713,12 @@
92 {
93 if (auto const titlebar = tools->info_for(active_surface).titlebar)
94 {
95- paint_titlebar(titlebar, tools->info_for(titlebar), 0x3F);
96+ tools->info_for(titlebar).paint_titlebar(0x3F);
97 }
98 }
99 if (auto const titlebar = tools->info_for(surface).titlebar)
100 {
101- paint_titlebar(titlebar, tools->info_for(titlebar), 0xFF);
102+ tools->info_for(titlebar).paint_titlebar(0xFF);
103 }
104 tools->set_focus_to(info_for.session.lock(), surface);
105 raise_tree(surface);
106
107=== modified file 'examples/server_example_canonical_window_manager.h'
108--- examples/server_example_canonical_window_manager.h 2015-05-27 11:37:38 +0000
109+++ examples/server_example_canonical_window_manager.h 2015-06-15 13:53:13 +0000
110@@ -23,6 +23,8 @@
111
112 #include "mir/geometry/displacement.h"
113
114+#include <atomic>
115+
116 ///\example server_example_canonical_window_manager.h
117 // Based on "Mir and Unity: Surfaces, input, and displays (v0.3)"
118
119@@ -59,7 +61,20 @@
120 mir::optional_value<shell::SurfaceAspectRatio> min_aspect;
121 mir::optional_value<shell::SurfaceAspectRatio> max_aspect;
122
123- graphics::Buffer* buffer{nullptr};
124+ void paint_titlebar(int intensity);
125+
126+private:
127+ std::shared_ptr<frontend::BufferStream> const buffer_stream;
128+
129+ // Add copy-ctor to std::atomic
130+ struct AtomicBufferPtr : std::atomic<graphics::Buffer*>
131+ {
132+ using std::atomic<graphics::Buffer*>::atomic;
133+
134+ AtomicBufferPtr(AtomicBufferPtr const& that) :
135+ std::atomic<graphics::Buffer*>{that.load()} {}
136+ };
137+ AtomicBufferPtr buffer{nullptr};
138 };
139
140 // standard window management algorithm:

Subscribers

People subscribed via source and target branches