Merge lp:~mir-team/mir/multiple-change-callbacks into lp:mir
- multiple-change-callbacks
- Merge into development-branch
Status: | Work in progress |
---|---|
Proposed branch: | lp:~mir-team/mir/multiple-change-callbacks |
Merge into: | lp:mir |
Diff against target: |
411 lines (+172/-20) 11 files modified
include/server/mir/compositor/scene.h (+8/-2) include/server/mir/scene/observer_id.h (+34/-0) include/test/mir_test_doubles/mock_scene.h (+4/-1) src/server/compositor/multi_threaded_compositor.cpp (+2/-2) src/server/compositor/multi_threaded_compositor.h (+3/-0) src/server/scene/surface_stack.cpp (+20/-4) src/server/scene/surface_stack.h (+7/-3) tests/integration-tests/test_surface_first_frame_sync.cpp (+4/-2) tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp (+10/-2) tests/unit-tests/compositor/test_multi_threaded_compositor.cpp (+17/-4) tests/unit-tests/scene/test_surface_stack.cpp (+63/-0) |
To merge this branch: | bzr merge lp:~mir-team/mir/multiple-change-callbacks |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alan Griffiths | Abstain | ||
Daniel van Vugt | Abstain | ||
Alberto Aguirre (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+214131@code.launchpad.net |
Commit message
Rework Scene::
Description of the change
As part of the cursor spike support registering multiple change callbacks to the surface stack/scene. In the cursor spike these methods are added to mi::InputTargets so that the cursor controller can update the image when surfaces dissapear, etc...
Also told AlbertA needs this for some screencast stuff?
- 1530. By Alan Griffiths
-
frontend, shell: frontend doesn't need send_display_
config( ) in the Session interface. Approved by Alberto Aguirre, Kevin DuBois, PS Jenkins bot.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1527
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1531. By Alan Griffiths
-
scene: Remove spurious BasicSurface:
:frame_ posted( ) function and rework tests that used it. Approved by PS Jenkins bot, Daniel van Vugt, Alexandros Frantzis, Kevin DuBois.
- 1532. By Kevin DuBois
-
compositor: transition bypass detection to operating on RenderableList instead of using operator/filter on mc::Scene.
Approved by Alberto Aguirre, Alan Griffiths, PS Jenkins bot.
- 1533. By Daniel van Vugt
-
Add a simple typedef Renderable::ID to make distinguishing renderables
slightly more explicit.
.Approved by PS Jenkins bot, Alberto Aguirre, Kevin DuBois.
Alan Griffiths (alan-griffiths) wrote : | # |
8 +set (OLD_CMAKE_
9 +# Don't treat warnings as errors in 3rd_party/{gmock}
10 +string (REPLACE " -Werror " " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
11 +
12 +
13 +# Restore -Werror for non-3rd-party code
14 +set (CMAKE_CXX_FLAGS ${OLD_CMAKE_
15 +
Spurious
~~~~
114 - miroptions
115 mirplatform
116 mirsharedandroid
117 - mirsharedenv
118
119 - ${Boost_
120 ${LIBHARDWARE_
121 ${EGL_LDFLAGS} ${EGL_LIBRARIES}
122 ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES}
123
124 === modified file 'src/platform/
125 --- src/platform/
126 +++ src/platform/
127 @@ -47,7 +47,6 @@
128 mirplatformgrap
129 mirplatform
130
131 - ${Boost_
Puzzling
~~~~
87 +typedef IntWrapper<
I'm not convinced we need an Observer ID but other ids capitalize the "D"
- 1534. By Alberto Aguirre
-
Fill the mode refresh rate field for android platform display configurations.
Approved by Alan Griffiths, Alexandros Frantzis, PS Jenkins bot, Kevin DuBois.
- 1535. By Alan Griffiths
-
shell: Eliminate shell::
SurfaceFactory and shell::Surface and use scene:: SurfaceCoordina tor and scene::Surface instead. Approved by Andreas Pokorny, Gerry Boland, Alexandros Frantzis, PS Jenkins bot.
- 1536. By Kevin DuBois
-
Remove the RenderingOperator and VisibilityFilter classes in favor of rendering on the generated list of renderables from the scene.
Approved by Alan Griffiths, Alexandros Frantzis, PS Jenkins bot, Alberto Aguirre.
- 1537. By Alberto Aguirre
-
make current before deleting gl resources in GLPixelBuffer (LP: #1256360). Fixes: https:/
/bugs.launchpad .net/bugs/ 1256360. Approved by Alexandros Frantzis, PS Jenkins bot, Kevin DuBois.
Daniel van Vugt (vanvugt) wrote : | # |
(1) As Alan said, the CMakeLists.txt changes are spurious reverts of changes we want to keep.
(2) Needs Information: We potentially don't need to use ObserverId. The std::function is already unique and has operator== so could be used as the identifier itself...
48 + virtual scene::ObserverId add_change_
49 + virtual void remove_
Then notify_change_by_id could become a std::set with a custom Compare template parameter. Or more simply a std::list with std::find.
(3) observer_id.h: Wrong copyright but then (2) suggests the whole file isn't required.
59 + * Copyright © 2013 Canonical Ltd.
(4) "notify_
- 1538. By Robert Carr
-
Rework Scene::
set_change_ callback to add/remove change callback to support multiple subscribers - 1539. By Robert Carr
-
ObserverId/
ObserverID - 1540. By Robert Carr
-
observer_id.h: Fix copyright
- 1541. By Robert Carr
-
notify_
change_ by_id-> observers_ by_id - 1542. By Robert Carr
-
test_surface_
stack.cpp: Add test, notifies_ multiple_ observers
Robert Carr (robertcarr) wrote : | # |
Sorry about CMakeList changes...pushed wrong branch. Fixed copyright on observer_id.h. Renamed notify_change_by_id -> observers by id. ObserverId-
I think utilizing std::function as the identifier is a bad idea because its convenient to just be able to pass an anonymous lambda.
Alberto Aguirre (albaguirre) wrote : | # |
> (2) Needs Information: We potentially don't need to use ObserverId. The
> std::function is already unique and has operator== so could be used as the
> identifier itself...
> 48 + virtual scene::ObserverId
> add_change_
> 49 + virtual void remove_
> Then notify_change_by_id could become a std::set with a custom Compare
> template parameter. Or more simply a std::list with std::find.
>
This imposes the caller to save the std::function it passed even if they are lambdas, which is probably more awkward than obtaining an id.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1542
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Alberto Aguirre (albaguirre) wrote : | # |
Unresolved conflicts:
Text conflict in include/
Text conflict in src/server/
Text conflict in src/server/
Text conflict in tests/unit-
Text conflict in tests/unit-
Text conflict in tests/unit-
Robert Carr (robertcarr) wrote : | # |
Whoops...I got distracted in the middle of merging devel in to this during the sprint and thought I had finished it.
- 1543. By Robert Carr
-
Merge trunk
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1543
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Alberto Aguirre (albaguirre) wrote : | # |
LGTM,
Just fyi, this will conflict with the refactoring in:
https:/
Daniel van Vugt (vanvugt) wrote : | # |
I see activity but no time to re-review right now.
Alan Griffiths (alan-griffiths) wrote : | # |
I'm still not convinced by ObserverID - other elements of the scene are managing observers by smart pointers to the observer object (Surface is close to its final state, Session still needs some work).
In all cases the legacy approach of "something changed but I won't tell you what" notification is getting reworked. So these changes will be swept away by that anyway.
Unmerged revisions
- 1543. By Robert Carr
-
Merge trunk
- 1542. By Robert Carr
-
test_surface_
stack.cpp: Add test, notifies_ multiple_ observers - 1541. By Robert Carr
-
notify_
change_ by_id-> observers_ by_id - 1540. By Robert Carr
-
observer_id.h: Fix copyright
- 1539. By Robert Carr
-
ObserverId/
ObserverID - 1538. By Robert Carr
-
Rework Scene::
set_change_ callback to add/remove change callback to support multiple subscribers
Preview Diff
1 | === modified file 'include/server/mir/compositor/scene.h' | |||
2 | --- include/server/mir/compositor/scene.h 2014-04-04 17:48:23 +0000 | |||
3 | +++ include/server/mir/compositor/scene.h 2014-04-14 21:47:44 +0000 | |||
4 | @@ -21,6 +21,7 @@ | |||
5 | 21 | 21 | ||
6 | 22 | #include "mir/geometry/forward.h" | 22 | #include "mir/geometry/forward.h" |
7 | 23 | #include "mir/graphics/renderable.h" | 23 | #include "mir/graphics/renderable.h" |
8 | 24 | #include "mir/scene/observer_id.h" | ||
9 | 24 | 25 | ||
10 | 25 | #include <memory> | 26 | #include <memory> |
11 | 26 | #include <functional> | 27 | #include <functional> |
12 | @@ -42,14 +43,19 @@ | |||
13 | 42 | virtual graphics::RenderableList generate_renderable_list() const = 0; | 43 | virtual graphics::RenderableList generate_renderable_list() const = 0; |
14 | 43 | 44 | ||
15 | 44 | /** | 45 | /** |
17 | 45 | * Sets a callback to be called whenever the state of the | 46 | * Registers a callback to be called whenever the state of the |
18 | 46 | * Scene changes. | 47 | * Scene changes. |
19 | 47 | * | 48 | * |
20 | 49 | * The returned ObserverID may be passed to remove_change_callback | ||
21 | 50 | * to unregister for change notification. | ||
22 | 51 | * | ||
23 | 48 | * The supplied callback should not directly or indirectly (e.g., | 52 | * The supplied callback should not directly or indirectly (e.g., |
24 | 49 | * by changing a property of a surface) change the state of | 53 | * by changing a property of a surface) change the state of |
25 | 50 | * the Scene, otherwise a deadlock may occur. | 54 | * the Scene, otherwise a deadlock may occur. |
26 | 55 | * | ||
27 | 51 | */ | 56 | */ |
29 | 52 | virtual void set_change_callback(std::function<void()> const& f) = 0; | 57 | virtual scene::ObserverID add_change_callback(std::function<void()> const& f) = 0; |
30 | 58 | virtual void remove_change_callback(scene::ObserverID id) = 0; | ||
31 | 53 | 59 | ||
32 | 54 | protected: | 60 | protected: |
33 | 55 | Scene() = default; | 61 | Scene() = default; |
34 | 56 | 62 | ||
35 | === added file 'include/server/mir/scene/observer_id.h' | |||
36 | --- include/server/mir/scene/observer_id.h 1970-01-01 00:00:00 +0000 | |||
37 | +++ include/server/mir/scene/observer_id.h 2014-04-14 21:47:44 +0000 | |||
38 | @@ -0,0 +1,34 @@ | |||
39 | 1 | /* | ||
40 | 2 | * Copyright © 2014 Canonical Ltd. | ||
41 | 3 | * | ||
42 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
43 | 5 | * under the terms of the GNU General Public License version 3, | ||
44 | 6 | * as published by the Free Software Foundation. | ||
45 | 7 | * | ||
46 | 8 | * This program is distributed in the hope that it will be useful, | ||
47 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
48 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
49 | 11 | * GNU General Public License for more details. | ||
50 | 12 | * | ||
51 | 13 | * You should have received a copy of the GNU General Public License | ||
52 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
53 | 15 | * | ||
54 | 16 | * Authored By: Robert Carr <racarr@canonical.com> | ||
55 | 17 | */ | ||
56 | 18 | |||
57 | 19 | #ifndef MIR_SCENE_OBSERVER_NOTIFICATION_ID_H_ | ||
58 | 20 | #define MIR_SCENE_OBSERVER_NOTIFICATION_ID_H_ | ||
59 | 21 | |||
60 | 22 | #include "mir/int_wrapper.h" | ||
61 | 23 | |||
62 | 24 | namespace mir | ||
63 | 25 | { | ||
64 | 26 | namespace scene | ||
65 | 27 | { | ||
66 | 28 | namespace detail { struct ObserverIDTag; } | ||
67 | 29 | |||
68 | 30 | typedef IntWrapper<detail::ObserverIDTag> ObserverID; | ||
69 | 31 | } | ||
70 | 32 | } // namespace mir | ||
71 | 33 | |||
72 | 34 | #endif // MIR_SCENE_OBSERVER_NOTIFICATION_ID_H_ | ||
73 | 0 | 35 | ||
74 | === modified file 'include/test/mir_test_doubles/mock_scene.h' | |||
75 | --- include/test/mir_test_doubles/mock_scene.h 2014-04-03 00:14:45 +0000 | |||
76 | +++ include/test/mir_test_doubles/mock_scene.h 2014-04-14 21:47:44 +0000 | |||
77 | @@ -38,7 +38,10 @@ | |||
78 | 38 | .WillByDefault(testing::Return(graphics::RenderableList{})); | 38 | .WillByDefault(testing::Return(graphics::RenderableList{})); |
79 | 39 | } | 39 | } |
80 | 40 | MOCK_CONST_METHOD0(generate_renderable_list, graphics::RenderableList()); | 40 | MOCK_CONST_METHOD0(generate_renderable_list, graphics::RenderableList()); |
82 | 41 | MOCK_METHOD1(set_change_callback, void(std::function<void()> const&)); | 41 | |
83 | 42 | MOCK_METHOD1(add_change_callback, scene::ObserverID(std::function<void()> const&)); | ||
84 | 43 | MOCK_METHOD1(remove_change_callback, void(scene::ObserverID)); | ||
85 | 44 | |||
86 | 42 | MOCK_METHOD0(lock, void()); | 45 | MOCK_METHOD0(lock, void()); |
87 | 43 | MOCK_METHOD0(unlock, void()); | 46 | MOCK_METHOD0(unlock, void()); |
88 | 44 | }; | 47 | }; |
89 | 45 | 48 | ||
90 | === modified file 'src/server/compositor/multi_threaded_compositor.cpp' | |||
91 | --- src/server/compositor/multi_threaded_compositor.cpp 2014-04-09 17:39:31 +0000 | |||
92 | +++ src/server/compositor/multi_threaded_compositor.cpp 2014-04-14 21:47:44 +0000 | |||
93 | @@ -271,7 +271,7 @@ | |||
94 | 271 | } | 271 | } |
95 | 272 | 272 | ||
96 | 273 | /* Recomposite whenever the scene changes */ | 273 | /* Recomposite whenever the scene changes */ |
98 | 274 | scene->set_change_callback([this]() | 274 | change_registration = scene->add_change_callback([this]() |
99 | 275 | { | 275 | { |
100 | 276 | schedule_compositing(); | 276 | schedule_compositing(); |
101 | 277 | }); | 277 | }); |
102 | @@ -295,7 +295,7 @@ | |||
103 | 295 | } | 295 | } |
104 | 296 | 296 | ||
105 | 297 | lk.unlock(); | 297 | lk.unlock(); |
107 | 298 | scene->set_change_callback([]{}); | 298 | scene->remove_change_callback(change_registration); |
108 | 299 | lk.lock(); | 299 | lk.lock(); |
109 | 300 | 300 | ||
110 | 301 | for (auto& f : thread_functors) | 301 | for (auto& f : thread_functors) |
111 | 302 | 302 | ||
112 | === modified file 'src/server/compositor/multi_threaded_compositor.h' | |||
113 | --- src/server/compositor/multi_threaded_compositor.h 2014-03-07 03:15:55 +0000 | |||
114 | +++ src/server/compositor/multi_threaded_compositor.h 2014-04-14 21:47:44 +0000 | |||
115 | @@ -20,6 +20,7 @@ | |||
116 | 20 | #define MIR_COMPOSITOR_MULTI_THREADED_COMPOSITOR_H_ | 20 | #define MIR_COMPOSITOR_MULTI_THREADED_COMPOSITOR_H_ |
117 | 21 | 21 | ||
118 | 22 | #include "mir/compositor/compositor.h" | 22 | #include "mir/compositor/compositor.h" |
119 | 23 | #include "mir/scene/observer_id.h" | ||
120 | 23 | 24 | ||
121 | 24 | #include <mutex> | 25 | #include <mutex> |
122 | 25 | #include <memory> | 26 | #include <memory> |
123 | @@ -67,6 +68,8 @@ | |||
124 | 67 | bool compose_on_start; | 68 | bool compose_on_start; |
125 | 68 | 69 | ||
126 | 69 | void schedule_compositing(); | 70 | void schedule_compositing(); |
127 | 71 | |||
128 | 72 | scene::ObserverID change_registration; | ||
129 | 70 | }; | 73 | }; |
130 | 71 | 74 | ||
131 | 72 | } | 75 | } |
132 | 73 | 76 | ||
133 | === modified file 'src/server/scene/surface_stack.cpp' | |||
134 | --- src/server/scene/surface_stack.cpp 2014-04-14 11:31:04 +0000 | |||
135 | +++ src/server/scene/surface_stack.cpp 2014-04-14 21:47:44 +0000 | |||
136 | @@ -54,7 +54,7 @@ | |||
137 | 54 | input_registrar{input_registrar}, | 54 | input_registrar{input_registrar}, |
138 | 55 | report{report}, | 55 | report{report}, |
139 | 56 | change_cb{[this]() { emit_change_notification(); }}, | 56 | change_cb{[this]() { emit_change_notification(); }}, |
141 | 57 | notify_change{[]{}} | 57 | next_change_callback_id(0) |
142 | 58 | { | 58 | { |
143 | 59 | } | 59 | } |
144 | 60 | 60 | ||
145 | @@ -125,11 +125,26 @@ | |||
146 | 125 | return list; | 125 | return list; |
147 | 126 | } | 126 | } |
148 | 127 | 127 | ||
150 | 128 | void ms::SurfaceStack::set_change_callback(std::function<void()> const& f) | 128 | ms::ObserverID ms::SurfaceStack::add_change_callback(std::function<void()> const& f) |
151 | 129 | { | 129 | { |
152 | 130 | std::lock_guard<decltype(notify_change_mutex)> lg(notify_change_mutex); | 130 | std::lock_guard<decltype(notify_change_mutex)> lg(notify_change_mutex); |
153 | 131 | assert(f); | 131 | assert(f); |
155 | 132 | notify_change = f; | 132 | |
156 | 133 | auto id = ms::ObserverID{++next_change_callback_id}; | ||
157 | 134 | observers_by_id[id] = f; | ||
158 | 135 | |||
159 | 136 | return id; | ||
160 | 137 | } | ||
161 | 138 | |||
162 | 139 | void ms::SurfaceStack::remove_change_callback(ms::ObserverID id) | ||
163 | 140 | { | ||
164 | 141 | std::lock_guard<std::mutex> lg{notify_change_mutex}; | ||
165 | 142 | |||
166 | 143 | auto it = observers_by_id.find(id); | ||
167 | 144 | if (it == observers_by_id.end()) | ||
168 | 145 | BOOST_THROW_EXCEPTION(std::logic_error( | ||
169 | 146 | "Invalid change notification id (not previously registered, or already unregistered)")); | ||
170 | 147 | observers_by_id.erase(it); | ||
171 | 133 | } | 148 | } |
172 | 134 | 149 | ||
173 | 135 | void ms::SurfaceStack::add_surface( | 150 | void ms::SurfaceStack::add_surface( |
174 | @@ -183,7 +198,8 @@ | |||
175 | 183 | void ms::SurfaceStack::emit_change_notification() | 198 | void ms::SurfaceStack::emit_change_notification() |
176 | 184 | { | 199 | { |
177 | 185 | std::lock_guard<decltype(notify_change_mutex)> lg(notify_change_mutex); | 200 | std::lock_guard<decltype(notify_change_mutex)> lg(notify_change_mutex); |
179 | 186 | notify_change(); | 201 | for (auto kv : observers_by_id) |
180 | 202 | kv.second(); | ||
181 | 187 | } | 203 | } |
182 | 188 | 204 | ||
183 | 189 | void ms::SurfaceStack::for_each(std::function<void(std::shared_ptr<mi::InputChannel> const&)> const& callback) | 205 | void ms::SurfaceStack::for_each(std::function<void(std::shared_ptr<mi::InputChannel> const&)> const& callback) |
184 | 190 | 206 | ||
185 | === modified file 'src/server/scene/surface_stack.h' | |||
186 | --- src/server/scene/surface_stack.h 2014-04-04 22:32:51 +0000 | |||
187 | +++ src/server/scene/surface_stack.h 2014-04-14 21:47:44 +0000 | |||
188 | @@ -23,6 +23,7 @@ | |||
189 | 23 | 23 | ||
190 | 24 | #include "mir/compositor/scene.h" | 24 | #include "mir/compositor/scene.h" |
191 | 25 | #include "mir/scene/depth_id.h" | 25 | #include "mir/scene/depth_id.h" |
192 | 26 | #include "mir/scene/observer_id.h" | ||
193 | 26 | #include "mir/input/input_targets.h" | 27 | #include "mir/input/input_targets.h" |
194 | 27 | 28 | ||
195 | 28 | #include <memory> | 29 | #include <memory> |
196 | @@ -67,8 +68,10 @@ | |||
197 | 67 | 68 | ||
198 | 68 | // From Scene | 69 | // From Scene |
199 | 69 | graphics::RenderableList generate_renderable_list() const; | 70 | graphics::RenderableList generate_renderable_list() const; |
202 | 70 | virtual void set_change_callback(std::function<void()> const& f); | 71 | |
203 | 71 | 72 | virtual scene::ObserverID add_change_callback(std::function<void()> const& f); | |
204 | 73 | virtual void remove_change_callback(scene::ObserverID id); | ||
205 | 74 | |||
206 | 72 | // From InputTargets | 75 | // From InputTargets |
207 | 73 | void for_each(std::function<void(std::shared_ptr<input::InputChannel> const&)> const& callback); | 76 | void for_each(std::function<void(std::shared_ptr<input::InputChannel> const&)> const& callback); |
208 | 74 | 77 | ||
209 | @@ -96,7 +99,8 @@ | |||
210 | 96 | std::map<DepthId, Layer> layers_by_depth; | 99 | std::map<DepthId, Layer> layers_by_depth; |
211 | 97 | 100 | ||
212 | 98 | std::mutex notify_change_mutex; | 101 | std::mutex notify_change_mutex; |
214 | 99 | std::function<void()> notify_change; | 102 | int next_change_callback_id; |
215 | 103 | std::map<ObserverID, std::function<void()>> observers_by_id; | ||
216 | 100 | }; | 104 | }; |
217 | 101 | 105 | ||
218 | 102 | } | 106 | } |
219 | 103 | 107 | ||
220 | === modified file 'tests/integration-tests/test_surface_first_frame_sync.cpp' | |||
221 | --- tests/integration-tests/test_surface_first_frame_sync.cpp 2014-04-04 21:48:32 +0000 | |||
222 | +++ tests/integration-tests/test_surface_first_frame_sync.cpp 2014-04-14 21:47:44 +0000 | |||
223 | @@ -69,7 +69,7 @@ | |||
224 | 69 | 69 | ||
225 | 70 | void start() | 70 | void start() |
226 | 71 | { | 71 | { |
228 | 72 | scene->set_change_callback([this]() | 72 | change_id = scene->add_change_callback([this]() |
229 | 73 | { | 73 | { |
230 | 74 | display->for_each_display_buffer([this](mg::DisplayBuffer& display_buffer) | 74 | display->for_each_display_buffer([this](mg::DisplayBuffer& display_buffer) |
231 | 75 | { | 75 | { |
232 | @@ -80,13 +80,15 @@ | |||
233 | 80 | 80 | ||
234 | 81 | void stop() | 81 | void stop() |
235 | 82 | { | 82 | { |
237 | 83 | scene->set_change_callback([]{}); | 83 | scene->remove_change_callback(change_id); |
238 | 84 | } | 84 | } |
239 | 85 | 85 | ||
240 | 86 | private: | 86 | private: |
241 | 87 | std::shared_ptr<mg::Display> const display; | 87 | std::shared_ptr<mg::Display> const display; |
242 | 88 | std::shared_ptr<mc::Scene> const scene; | 88 | std::shared_ptr<mc::Scene> const scene; |
243 | 89 | std::unordered_map<mg::DisplayBuffer*,std::unique_ptr<mc::DisplayBufferCompositor>> display_buffer_compositor_map; | 89 | std::unordered_map<mg::DisplayBuffer*,std::unique_ptr<mc::DisplayBufferCompositor>> display_buffer_compositor_map; |
244 | 90 | |||
245 | 91 | ms::ObserverID change_id; | ||
246 | 90 | }; | 92 | }; |
247 | 91 | 93 | ||
248 | 92 | class StubRenderer : public mtd::StubRenderer | 94 | class StubRenderer : public mtd::StubRenderer |
249 | 93 | 95 | ||
250 | === modified file 'tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp' | |||
251 | --- tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp 2014-04-07 16:46:16 +0000 | |||
252 | +++ tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp 2014-04-14 21:47:44 +0000 | |||
253 | @@ -38,10 +38,11 @@ | |||
254 | 38 | 38 | ||
255 | 39 | namespace mg = mir::graphics; | 39 | namespace mg = mir::graphics; |
256 | 40 | namespace mc = mir::compositor; | 40 | namespace mc = mir::compositor; |
257 | 41 | namespace ms = mir::scene; | ||
258 | 42 | namespace mr = mir::report; | ||
259 | 41 | namespace geom = mir::geometry; | 43 | namespace geom = mir::geometry; |
260 | 42 | namespace mt = mir::test; | 44 | namespace mt = mir::test; |
261 | 43 | namespace mtd = mir::test::doubles; | 45 | namespace mtd = mir::test::doubles; |
262 | 44 | namespace mr = mir::report; | ||
263 | 45 | 46 | ||
264 | 46 | namespace | 47 | namespace |
265 | 47 | { | 48 | { |
266 | @@ -58,7 +59,14 @@ | |||
267 | 58 | return renderlist; | 59 | return renderlist; |
268 | 59 | } | 60 | } |
269 | 60 | 61 | ||
271 | 61 | void set_change_callback(std::function<void()> const&) {} | 62 | ms::ObserverID add_change_callback(std::function<void()> const&) override |
272 | 63 | { | ||
273 | 64 | return ms::ObserverID{}; | ||
274 | 65 | } | ||
275 | 66 | |||
276 | 67 | void remove_change_callback(ms::ObserverID) override | ||
277 | 68 | { | ||
278 | 69 | } | ||
279 | 62 | 70 | ||
280 | 63 | void change(mg::RenderableList const& new_renderlist) | 71 | void change(mg::RenderableList const& new_renderlist) |
281 | 64 | { | 72 | { |
282 | 65 | 73 | ||
283 | === modified file 'tests/unit-tests/compositor/test_multi_threaded_compositor.cpp' | |||
284 | --- tests/unit-tests/compositor/test_multi_threaded_compositor.cpp 2014-04-09 11:40:25 +0000 | |||
285 | +++ tests/unit-tests/compositor/test_multi_threaded_compositor.cpp 2014-04-14 21:47:44 +0000 | |||
286 | @@ -42,9 +42,10 @@ | |||
287 | 42 | 42 | ||
288 | 43 | namespace mc = mir::compositor; | 43 | namespace mc = mir::compositor; |
289 | 44 | namespace mg = mir::graphics; | 44 | namespace mg = mir::graphics; |
290 | 45 | namespace ms = mir::scene; | ||
291 | 46 | namespace mr = mir::report; | ||
292 | 45 | namespace geom = mir::geometry; | 47 | namespace geom = mir::geometry; |
293 | 46 | namespace mtd = mir::test::doubles; | 48 | namespace mtd = mir::test::doubles; |
294 | 47 | namespace mr = mir::report; | ||
295 | 48 | 49 | ||
296 | 49 | namespace | 50 | namespace |
297 | 50 | { | 51 | { |
298 | @@ -99,11 +100,20 @@ | |||
299 | 99 | return renderable_list; | 100 | return renderable_list; |
300 | 100 | } | 101 | } |
301 | 101 | 102 | ||
303 | 102 | void set_change_callback(std::function<void()> const& f) | 103 | |
304 | 104 | ms::ObserverID add_change_callback(std::function<void()> const& f) override | ||
305 | 103 | { | 105 | { |
306 | 104 | std::lock_guard<std::mutex> lock{callback_mutex}; | 106 | std::lock_guard<std::mutex> lock{callback_mutex}; |
307 | 105 | assert(f); | 107 | assert(f); |
308 | 106 | callback = f; | 108 | callback = f; |
309 | 109 | |||
310 | 110 | // Test only needs a single change callback. | ||
311 | 111 | return ms::ObserverID{0}; | ||
312 | 112 | } | ||
313 | 113 | void remove_change_callback(ms::ObserverID id) override | ||
314 | 114 | { | ||
315 | 115 | assert(id == ms::ObserverID{0}); | ||
316 | 116 | callback = [](){}; | ||
317 | 107 | } | 117 | } |
318 | 108 | 118 | ||
319 | 109 | void emit_change_event() | 119 | void emit_change_event() |
320 | @@ -563,12 +573,15 @@ | |||
321 | 563 | auto mock_scene = std::make_shared<mtd::MockScene>(); | 573 | auto mock_scene = std::make_shared<mtd::MockScene>(); |
322 | 564 | auto db_compositor_factory = std::make_shared<mtd::NullDisplayBufferCompositorFactory>(); | 574 | auto db_compositor_factory = std::make_shared<mtd::NullDisplayBufferCompositorFactory>(); |
323 | 565 | auto mock_report = std::make_shared<testing::NiceMock<mtd::MockCompositorReport>>(); | 575 | auto mock_report = std::make_shared<testing::NiceMock<mtd::MockCompositorReport>>(); |
324 | 576 | |||
325 | 566 | EXPECT_CALL(*mock_report, started()) | 577 | EXPECT_CALL(*mock_report, started()) |
326 | 567 | .Times(1); | 578 | .Times(1); |
327 | 568 | EXPECT_CALL(*mock_report, stopped()) | 579 | EXPECT_CALL(*mock_report, stopped()) |
328 | 569 | .Times(1); | 580 | .Times(1); |
331 | 570 | EXPECT_CALL(*mock_scene, set_change_callback(_)) | 581 | EXPECT_CALL(*mock_scene, add_change_callback(_)) |
332 | 571 | .Times(2); | 582 | .Times(1).WillOnce(Return(ms::ObserverID{})); |
333 | 583 | EXPECT_CALL(*mock_scene, remove_change_callback(_)) | ||
334 | 584 | .Times(1); | ||
335 | 572 | EXPECT_CALL(*mock_scene, generate_renderable_list()) | 585 | EXPECT_CALL(*mock_scene, generate_renderable_list()) |
336 | 573 | .Times(AtLeast(0)) | 586 | .Times(AtLeast(0)) |
337 | 574 | .WillRepeatedly(Return(mg::RenderableList{})); | 587 | .WillRepeatedly(Return(mg::RenderableList{})); |
338 | 575 | 588 | ||
339 | === modified file 'tests/unit-tests/scene/test_surface_stack.cpp' | |||
340 | --- tests/unit-tests/scene/test_surface_stack.cpp 2014-04-14 11:31:04 +0000 | |||
341 | +++ tests/unit-tests/scene/test_surface_stack.cpp 2014-04-14 21:47:44 +0000 | |||
342 | @@ -168,6 +168,69 @@ | |||
343 | 168 | EXPECT_THAT((*it)->id(), Eq(stub_surface3->id())); | 168 | EXPECT_THAT((*it)->id(), Eq(stub_surface3->id())); |
344 | 169 | } | 169 | } |
345 | 170 | 170 | ||
346 | 171 | TEST_F(SurfaceStack, notify_on_create_and_destroy_surface) | ||
347 | 172 | { | ||
348 | 173 | using namespace ::testing; | ||
349 | 174 | NiceMock<MockCallback> mock_cb; | ||
350 | 175 | EXPECT_CALL(mock_cb, call()) | ||
351 | 176 | .Times(2); | ||
352 | 177 | |||
353 | 178 | ms::SurfaceStack stack(mt::fake_shared(input_registrar), report); | ||
354 | 179 | |||
355 | 180 | stack.add_change_callback(std::bind(&MockCallback::call, &mock_cb)); | ||
356 | 181 | stack.add_surface(stub_surface1, default_params.depth, default_params.input_mode); | ||
357 | 182 | stack.remove_surface(stub_surface1); | ||
358 | 183 | } | ||
359 | 184 | |||
360 | 185 | TEST_F(SurfaceStack, remove_change_callback) | ||
361 | 186 | { | ||
362 | 187 | using namespace ::testing; | ||
363 | 188 | MockCallback mock_cb; | ||
364 | 189 | EXPECT_CALL(mock_cb, call()) | ||
365 | 190 | .Times(1); | ||
366 | 191 | |||
367 | 192 | ms::SurfaceStack stack(mt::fake_shared(input_registrar), report); | ||
368 | 193 | |||
369 | 194 | auto id = stack.add_change_callback(std::bind(&MockCallback::call, &mock_cb)); | ||
370 | 195 | stack.add_surface(stub_surface1, default_params.depth, default_params.input_mode); | ||
371 | 196 | stack.remove_change_callback(id); | ||
372 | 197 | |||
373 | 198 | EXPECT_CALL(mock_cb, call()).Times(0); | ||
374 | 199 | stack.remove_surface(stub_surface1); | ||
375 | 200 | } | ||
376 | 201 | |||
377 | 202 | TEST_F(SurfaceStack, notifies_multiple_observers) | ||
378 | 203 | { | ||
379 | 204 | using namespace ::testing; | ||
380 | 205 | MockCallback mock_cb1; | ||
381 | 206 | MockCallback mock_cb2; | ||
382 | 207 | |||
383 | 208 | EXPECT_CALL(mock_cb1, call()).Times(1); | ||
384 | 209 | EXPECT_CALL(mock_cb2, call()).Times(1); | ||
385 | 210 | |||
386 | 211 | ms::SurfaceStack stack(mt::fake_shared(input_registrar), report); | ||
387 | 212 | |||
388 | 213 | auto id1 = stack.add_change_callback(std::bind(&MockCallback::call, &mock_cb1)); | ||
389 | 214 | auto id2 = stack.add_change_callback(std::bind(&MockCallback::call, &mock_cb2)); | ||
390 | 215 | stack.add_surface(stub_surface1, default_params.depth, default_params.input_mode); | ||
391 | 216 | stack.remove_change_callback(id1); | ||
392 | 217 | stack.remove_change_callback(id2); | ||
393 | 218 | |||
394 | 219 | EXPECT_CALL(mock_cb1, call()).Times(0); | ||
395 | 220 | EXPECT_CALL(mock_cb2, call()).Times(0); | ||
396 | 221 | stack.remove_surface(stub_surface1); | ||
397 | 222 | } | ||
398 | 223 | |||
399 | 224 | TEST_F(SurfaceStack, remove_invalid_change_callback) | ||
400 | 225 | { | ||
401 | 226 | using namespace ::testing; | ||
402 | 227 | |||
403 | 228 | ms::SurfaceStack stack(mt::fake_shared(input_registrar), report); | ||
404 | 229 | EXPECT_THROW({ | ||
405 | 230 | stack.remove_change_callback(ms::ObserverID{1}); | ||
406 | 231 | }, std::logic_error); | ||
407 | 232 | } | ||
408 | 233 | |||
409 | 171 | TEST_F(SurfaceStack, surfaces_are_emitted_by_layer) | 234 | TEST_F(SurfaceStack, surfaces_are_emitted_by_layer) |
410 | 172 | { | 235 | { |
411 | 173 | using namespace testing; | 236 | using namespace testing; |
"Also told AlbertA needs this for some screencast stuff?"
Right, I want to optionally be able to get the screencast compositor to listen to scene changes so it can capture at scene change rate.
Lines 8-15, 114, 117, 119, 131, seems like a wrong merge resolution.
Also what about testing for multiple observer notifications? Maybe this:
TEST_F( SurfaceStack, notifies_ multiple_ observers)
{
using namespace ::testing;
MockCallback mock_cb1;
MockCallback mock_cb2;
EXPECT_ CALL(mock_ cb1, call()).Times(1); CALL(mock_ cb2, call()).Times(1);
EXPECT_
ms: :SurfaceStack stack(mt: :fake_shared( input_registrar ), report);
auto id1 = stack.add_ change_ callback( std::bind( &MockCallback: :call, &mock_cb1)); change_ callback( std::bind( &MockCallback: :call, &mock_cb2)); add_surface( stub_surface1, default_ params. depth, default_ params. input_mode) ; remove_ change_ callback( id1); remove_ change_ callback( id2);
auto id2 = stack.add_
stack.
stack.
stack.
EXPECT_ CALL(mock_ cb1, call()).Times(0); CALL(mock_ cb2, call()).Times(0); remove_ surface( stub_surface1) ;
EXPECT_
stack.
}