Merge lp:~alan-griffiths/mir/introducing-SurfaceObserver into lp:mir
- introducing-SurfaceObserver
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Alan Griffiths |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1520 |
Proposed branch: | lp:~alan-griffiths/mir/introducing-SurfaceObserver |
Merge into: | lp:mir |
Prerequisite: | lp:~alan-griffiths/mir/remove-one-of-the-redundant-surface-factories |
Diff against target: |
1740 lines (+323/-219) 31 files modified
examples/render_surfaces.cpp (+0/-1) include/server/mir/scene/surface.h (+5/-0) include/server/mir/scene/surface_coordinator.h (+2/-4) include/server/mir/scene/surface_event_source.h (+49/-0) include/server/mir/scene/surface_factory.h (+2/-6) include/server/mir/scene/surface_observer.h (+45/-0) include/server/mir/shell/surface_factory.h (+3/-7) include/test/mir_test_doubles/mock_surface.h (+1/-2) include/test/mir_test_doubles/mock_surface_factory.h (+2/-3) src/server/scene/CMakeLists.txt (+1/-0) src/server/scene/application_session.cpp (+4/-1) src/server/scene/basic_surface.cpp (+46/-32) src/server/scene/basic_surface.h (+20/-6) src/server/scene/surface_allocator.cpp (+4/-6) src/server/scene/surface_allocator.h (+1/-3) src/server/scene/surface_controller.cpp (+4/-3) src/server/scene/surface_controller.h (+1/-7) src/server/scene/surface_event_source.cpp (+62/-0) src/server/shell/organising_surface_factory.cpp (+3/-4) src/server/shell/organising_surface_factory.h (+2/-3) tests/acceptance-tests/test_client_input.cpp (+5/-5) tests/integration-tests/graphics/android/test_internal_client.cpp (+3/-1) tests/integration-tests/test_session_manager.cpp (+1/-1) tests/unit-tests/scene/test_application_session.cpp (+11/-11) tests/unit-tests/scene/test_basic_surface.cpp (+0/-23) tests/unit-tests/scene/test_session_manager.cpp (+4/-6) tests/unit-tests/scene/test_surface.cpp (+7/-37) tests/unit-tests/scene/test_surface_controller.cpp (+13/-8) tests/unit-tests/scene/test_surface_impl.cpp (+12/-22) tests/unit-tests/scene/test_surface_stack.cpp (+0/-8) tests/unit-tests/shell/test_organising_surface_factory.cpp (+10/-9) |
To merge this branch: | bzr merge lp:~alan-griffiths/mir/introducing-SurfaceObserver |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andreas Pokorny (community) | Approve | ||
Alexandros Frantzis (community) | Approve | ||
Gerry Boland (community) | api | Approve | |
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+213431@code.launchpad.net |
Commit message
scene: Simplify BasicSurface creation by separating out an initial cut of SurfaceObserver.
Description of the change
scene: Simplify BasicSurface creation by separating out an initial cut of SurfaceObserver.
In this iteration SurfaceObserver is only used to support the MirEvents needed to feed the frontend EventSink. There are other "Observer" requirements that will be rolled into this hierarchy.
Andreas Pokorny (andreas-pokorny) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1523
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://
Gerry Boland (gerboland) wrote : | # |
I like this design a lot, +1 from me
Alan Griffiths (alan-griffiths) wrote : | # |
> Approve a part from:
>
> the name SurfaceEventSource is a bit misleading... on second read: was a but
> misleading. Now I am only curious whether we need it inside the public
> headers. Would someone replacing the scene or extending the surfaces need that
> implementation? Or would decorating the surface factory be sufficient?
I thought about it. Making it public ensures that it is easy for users that need to synthesize surface events (rather requiring duplication of our code for populating the MirEvent structure).
Alexandros Frantzis (afrantzis) wrote : | # |
Looks good.
> Making it public ensures that it is easy for users that need to synthesize surface events
I am OK with this, but I guess we could wait until it is actually needed before we promote it to public (unless you have a specific use case in mind for the near future).
Daniel van Vugt (vanvugt) wrote : | # |
I know Observer is a common pattern but that doesn't make it the best solution. Maybe think for a while if there's a better name/design that's less abstract than being based on a verb.
Alan Griffiths (alan-griffiths) wrote : | # |
> I know Observer is a common pattern but that doesn't make it the best
> solution. Maybe think for a while if there's a better name/design that's less
> abstract than being based on a verb.
This design has been under discussion since the end of last year.
The name has been chosen intentionally:
/1/ it matches the discussions about architecture improvements that has been taking place over the last three weeks;
/2/ and, "Observer" is widely understood from the GOF patterns catalog.
I think the fact that our most active user says "I like this design a lot" is more important than any concern you have that there has been too little thought go into it.
Andreas Pokorny (andreas-pokorny) : | # |
Preview Diff
1 | === modified file 'examples/render_surfaces.cpp' |
2 | --- examples/render_surfaces.cpp 2014-03-31 11:00:33 +0000 |
3 | +++ examples/render_surfaces.cpp 2014-03-31 11:00:33 +0000 |
4 | @@ -466,7 +466,6 @@ |
5 | for (auto& m : moveables) |
6 | { |
7 | auto const s = surface_coordinator->add_surface( |
8 | - mf::SurfaceId(), |
9 | msh::a_surface().of_size(surface_size) |
10 | .of_pixel_format(surface_pf) |
11 | .of_buffer_usage(mg::BufferUsage::hardware), |
12 | |
13 | === modified file 'include/server/mir/scene/surface.h' |
14 | --- include/server/mir/scene/surface.h 2014-03-25 10:21:00 +0000 |
15 | +++ include/server/mir/scene/surface.h 2014-03-31 11:00:33 +0000 |
16 | @@ -29,6 +29,8 @@ |
17 | |
18 | namespace scene |
19 | { |
20 | +class SurfaceObserver; |
21 | + |
22 | class Surface : |
23 | public graphics::Renderable, |
24 | public input::Surface, |
25 | @@ -47,6 +49,9 @@ |
26 | // TODO cleanest interface for this. |
27 | virtual std::shared_ptr<input::InputChannel> input_channel() const = 0; |
28 | virtual void on_change(std::function<void()> change_notification) = 0; |
29 | + |
30 | + virtual void add_observer(std::shared_ptr<SurfaceObserver> const& observer) = 0; |
31 | + virtual void remove_observer(std::shared_ptr<SurfaceObserver> const& observer) = 0; |
32 | }; |
33 | } |
34 | } |
35 | |
36 | === modified file 'include/server/mir/scene/surface_coordinator.h' |
37 | --- include/server/mir/scene/surface_coordinator.h 2014-03-31 11:00:33 +0000 |
38 | +++ include/server/mir/scene/surface_coordinator.h 2014-03-31 11:00:33 +0000 |
39 | @@ -21,13 +21,11 @@ |
40 | #define MIR_SCENE_SURFACE_COORDINATOR_H_ |
41 | |
42 | #include "mir/scene/surface_ranker.h" |
43 | -#include "mir/frontend/surface_id.h" |
44 | |
45 | #include <memory> |
46 | |
47 | namespace mir |
48 | { |
49 | -namespace frontend { class EventSink; } |
50 | namespace shell |
51 | { |
52 | struct SurfaceCreationParameters; |
53 | @@ -36,14 +34,14 @@ |
54 | namespace scene |
55 | { |
56 | class Surface; |
57 | +class SurfaceObserver; |
58 | |
59 | class SurfaceCoordinator : public SurfaceRanker |
60 | { |
61 | public: |
62 | virtual std::shared_ptr<Surface> add_surface( |
63 | - frontend::SurfaceId id, |
64 | shell::SurfaceCreationParameters const& params, |
65 | - std::shared_ptr<frontend::EventSink> const& event_sink) = 0; |
66 | + std::shared_ptr<SurfaceObserver> const& observer) = 0; |
67 | |
68 | virtual void remove_surface(std::weak_ptr<Surface> const& surface) = 0; |
69 | protected: |
70 | |
71 | === added file 'include/server/mir/scene/surface_event_source.h' |
72 | --- include/server/mir/scene/surface_event_source.h 1970-01-01 00:00:00 +0000 |
73 | +++ include/server/mir/scene/surface_event_source.h 2014-03-31 11:00:33 +0000 |
74 | @@ -0,0 +1,49 @@ |
75 | +/* |
76 | + * Copyright © 2014 Canonical Ltd. |
77 | + * |
78 | + * This program is free software: you can redistribute it and/or modify it |
79 | + * under the terms of the GNU General Public License version 3, |
80 | + * as published by the Free Software Foundation. |
81 | + * |
82 | + * This program is distributed in the hope that it will be useful, |
83 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
84 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
85 | + * GNU General Public License for more details. |
86 | + * |
87 | + * You should have received a copy of the GNU General Public License |
88 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
89 | + * |
90 | + * Authored by: Alan Griffiths <alan@octopull.co.uk> |
91 | + */ |
92 | + |
93 | +#ifndef MIR_SCENE_SURFACE_EVENT_SOURCE_H_ |
94 | +#define MIR_SCENE_SURFACE_EVENT_SOURCE_H_ |
95 | + |
96 | +#include "mir/scene/surface_observer.h" |
97 | +#include "mir/frontend/surface_id.h" |
98 | +#include "mir/frontend/event_sink.h" |
99 | + |
100 | +#include <memory> |
101 | + |
102 | +namespace mir |
103 | +{ |
104 | +namespace scene |
105 | +{ |
106 | +class SurfaceEventSource : public SurfaceObserver |
107 | +{ |
108 | +public: |
109 | + SurfaceEventSource( |
110 | + frontend::SurfaceId id, |
111 | + std::shared_ptr<frontend::EventSink> const& event_sink); |
112 | + |
113 | + void attrib_change(MirSurfaceAttrib attrib, int value); |
114 | + void resize(geometry::Size const& size); |
115 | + |
116 | +private: |
117 | + frontend::SurfaceId const id; |
118 | + std::shared_ptr<frontend::EventSink> const event_sink; |
119 | +}; |
120 | +} |
121 | +} |
122 | + |
123 | +#endif // MIR_SCENE_SURFACE_EVENT_SOURCE_H_ |
124 | |
125 | === modified file 'include/server/mir/scene/surface_factory.h' |
126 | --- include/server/mir/scene/surface_factory.h 2014-03-31 11:00:33 +0000 |
127 | +++ include/server/mir/scene/surface_factory.h 2014-03-31 11:00:33 +0000 |
128 | @@ -19,14 +19,11 @@ |
129 | #ifndef MIR_SCENE_SURFACE_FACTORY_H_ |
130 | #define MIR_SCENE_SURFACE_FACTORY_H_ |
131 | |
132 | -#include "mir/frontend/surface_id.h" |
133 | #include "mir/shell/surface_creation_parameters.h" |
134 | #include <memory> |
135 | -#include <functional> |
136 | |
137 | namespace mir |
138 | { |
139 | -namespace frontend { class EventSink; } |
140 | namespace scene |
141 | { |
142 | class Surface; |
143 | @@ -38,9 +35,8 @@ |
144 | virtual ~SurfaceFactory() = default; |
145 | |
146 | virtual std::shared_ptr<Surface> create_surface( |
147 | - frontend::SurfaceId id, |
148 | - shell::SurfaceCreationParameters const& params, |
149 | - std::shared_ptr<frontend::EventSink> const& event_sink) = 0; |
150 | + shell::SurfaceCreationParameters const& params) = 0; |
151 | + |
152 | private: |
153 | SurfaceFactory(const SurfaceFactory&) = delete; |
154 | SurfaceFactory& operator=(const SurfaceFactory&) = delete; |
155 | |
156 | === added file 'include/server/mir/scene/surface_observer.h' |
157 | --- include/server/mir/scene/surface_observer.h 1970-01-01 00:00:00 +0000 |
158 | +++ include/server/mir/scene/surface_observer.h 2014-03-31 11:00:33 +0000 |
159 | @@ -0,0 +1,45 @@ |
160 | +/* |
161 | + * Copyright © 2014 Canonical Ltd. |
162 | + * |
163 | + * This program is free software: you can redistribute it and/or modify it |
164 | + * under the terms of the GNU General Public License version 3, |
165 | + * as published by the Free Software Foundation. |
166 | + * |
167 | + * This program is distributed in the hope that it will be useful, |
168 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
169 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
170 | + * GNU General Public License for more details. |
171 | + * |
172 | + * You should have received a copy of the GNU General Public License |
173 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
174 | + * |
175 | + * Authored by: Alan Griffiths <alan@octopull.co.uk> |
176 | + */ |
177 | + |
178 | +#ifndef MIR_SCENE_SURFACE_OBSERVER_H_ |
179 | +#define MIR_SCENE_SURFACE_OBSERVER_H_ |
180 | + |
181 | +#include "mir/geometry/size.h" |
182 | +#include "mir_toolkit/common.h" |
183 | + |
184 | +namespace mir |
185 | +{ |
186 | +namespace scene |
187 | +{ |
188 | +// Initial cut - supporting the frontend requirement, more will follow |
189 | +class SurfaceObserver |
190 | +{ |
191 | +public: |
192 | + virtual void attrib_change(MirSurfaceAttrib attrib, int value) = 0; |
193 | + virtual void resize(geometry::Size const& size) = 0; |
194 | + |
195 | +protected: |
196 | + SurfaceObserver() = default; |
197 | + virtual ~SurfaceObserver() = default; |
198 | + SurfaceObserver(SurfaceObserver const&) = delete; |
199 | + SurfaceObserver& operator=(SurfaceObserver const&) = delete; |
200 | +}; |
201 | +} |
202 | +} |
203 | + |
204 | +#endif // MIR_SCENE_SURFACE_OBSERVER_H_ |
205 | |
206 | === modified file 'include/server/mir/shell/surface_factory.h' |
207 | --- include/server/mir/shell/surface_factory.h 2014-03-25 17:04:27 +0000 |
208 | +++ include/server/mir/shell/surface_factory.h 2014-03-31 11:00:33 +0000 |
209 | @@ -19,15 +19,12 @@ |
210 | #ifndef MIR_SHELL_SURFACE_FACTORY_H_ |
211 | #define MIR_SHELL_SURFACE_FACTORY_H_ |
212 | |
213 | -#include "mir/frontend/surface_id.h" |
214 | #include <memory> |
215 | |
216 | namespace mir |
217 | { |
218 | -namespace frontend |
219 | -{ |
220 | -class EventSink; |
221 | -} |
222 | +namespace scene { class SurfaceObserver; } |
223 | + |
224 | namespace shell |
225 | { |
226 | class Session; |
227 | @@ -40,8 +37,7 @@ |
228 | virtual std::shared_ptr<Surface> create_surface( |
229 | Session* session, |
230 | SurfaceCreationParameters const& params, |
231 | - frontend::SurfaceId id, |
232 | - std::shared_ptr<frontend::EventSink> const& sink) = 0; |
233 | + std::shared_ptr<scene::SurfaceObserver> const& observer) = 0; |
234 | |
235 | virtual void destroy_surface(std::shared_ptr<Surface> const& surface) = 0; |
236 | |
237 | |
238 | === modified file 'include/test/mir_test_doubles/mock_surface.h' |
239 | --- include/test/mir_test_doubles/mock_surface.h 2014-03-26 14:20:14 +0000 |
240 | +++ include/test/mir_test_doubles/mock_surface.h 2014-03-31 11:00:33 +0000 |
241 | @@ -35,14 +35,12 @@ |
242 | { |
243 | MockSurface() : |
244 | scene::BasicSurface( |
245 | - frontend::SurfaceId{}, |
246 | {}, |
247 | {{},{}}, |
248 | true, |
249 | {}, |
250 | {}, |
251 | {}, |
252 | - {}, |
253 | mir::report::null_scene_report()) |
254 | { |
255 | } |
256 | @@ -65,6 +63,7 @@ |
257 | |
258 | MOCK_METHOD2(configure, int(MirSurfaceAttrib, int)); |
259 | MOCK_METHOD1(take_input_focus, void(std::shared_ptr<shell::InputTargeter> const&)); |
260 | + MOCK_METHOD1(add_observer, void(std::shared_ptr<scene::SurfaceObserver> const&)); |
261 | }; |
262 | |
263 | } |
264 | |
265 | === modified file 'include/test/mir_test_doubles/mock_surface_factory.h' |
266 | --- include/test/mir_test_doubles/mock_surface_factory.h 2014-03-24 17:30:12 +0000 |
267 | +++ include/test/mir_test_doubles/mock_surface_factory.h 2014-03-31 11:00:33 +0000 |
268 | @@ -33,11 +33,10 @@ |
269 | |
270 | struct MockSurfaceFactory : public shell::SurfaceFactory |
271 | { |
272 | - MOCK_METHOD4(create_surface, std::shared_ptr<shell::Surface>( |
273 | + MOCK_METHOD3(create_surface, std::shared_ptr<shell::Surface>( |
274 | shell::Session*, |
275 | const shell::SurfaceCreationParameters&, |
276 | - frontend::SurfaceId, |
277 | - std::shared_ptr<frontend::EventSink> const&)); |
278 | + std::shared_ptr<scene::SurfaceObserver> const&)); |
279 | |
280 | void destroy_surface(std::shared_ptr<shell::Surface> const& /*surface*/) override {} |
281 | }; |
282 | |
283 | === modified file 'src/server/scene/CMakeLists.txt' |
284 | --- src/server/scene/CMakeLists.txt 2014-03-31 11:00:33 +0000 |
285 | +++ src/server/scene/CMakeLists.txt 2014-03-31 11:00:33 +0000 |
286 | @@ -13,5 +13,6 @@ |
287 | surface_allocator.cpp |
288 | surface_stack.cpp |
289 | surface_controller.cpp |
290 | + surface_event_source.cpp |
291 | threaded_snapshot_strategy.cpp |
292 | ) |
293 | |
294 | === modified file 'src/server/scene/application_session.cpp' |
295 | --- src/server/scene/application_session.cpp 2014-03-26 13:02:43 +0000 |
296 | +++ src/server/scene/application_session.cpp 2014-03-31 11:00:33 +0000 |
297 | @@ -18,6 +18,7 @@ |
298 | |
299 | #include "application_session.h" |
300 | #include "mir/shell/surface.h" |
301 | +#include "mir/scene/surface_event_source.h" |
302 | #include "mir/shell/surface_factory.h" |
303 | #include "snapshot_strategy.h" |
304 | #include "mir/shell/session_listener.h" |
305 | @@ -71,7 +72,9 @@ |
306 | mf::SurfaceId ms::ApplicationSession::create_surface(const msh::SurfaceCreationParameters& params) |
307 | { |
308 | auto const id = next_id(); |
309 | - auto surf = surface_factory->create_surface(this, params, id, event_sink); |
310 | + |
311 | + auto const observer = std::make_shared<scene::SurfaceEventSource>(id, event_sink); |
312 | + auto surf = surface_factory->create_surface(this, params, observer); |
313 | |
314 | std::unique_lock<std::mutex> lock(surfaces_mutex); |
315 | surfaces[id] = surf; |
316 | |
317 | === modified file 'src/server/scene/basic_surface.cpp' |
318 | --- src/server/scene/basic_surface.cpp 2014-03-26 14:20:14 +0000 |
319 | +++ src/server/scene/basic_surface.cpp 2014-03-31 11:00:33 +0000 |
320 | @@ -31,7 +31,7 @@ |
321 | #include <boost/throw_exception.hpp> |
322 | |
323 | #include <stdexcept> |
324 | -#include <cstring> |
325 | +#include <algorithm> |
326 | |
327 | namespace mc = mir::compositor; |
328 | namespace ms = mir::scene; |
329 | @@ -58,17 +58,45 @@ |
330 | notifier(); |
331 | } |
332 | |
333 | +void ms::SurfaceObservers::attrib_change(MirSurfaceAttrib attrib, int value) |
334 | +{ |
335 | + std::unique_lock<decltype(mutex)> lock(mutex); |
336 | + // TBD Maybe we should copy observers so we can release the lock? |
337 | + for (auto const& p : observers) |
338 | + p->attrib_change(attrib, value); |
339 | +} |
340 | + |
341 | +void ms::SurfaceObservers::resize(geometry::Size const& size) |
342 | +{ |
343 | + std::unique_lock<decltype(mutex)> lock(mutex); |
344 | + // TBD Maybe we should copy observers so we can release the lock? |
345 | + for (auto const& p : observers) |
346 | + p->resize(size); |
347 | +} |
348 | + |
349 | +void ms::SurfaceObservers::add(std::shared_ptr<SurfaceObserver> const& observer) |
350 | +{ |
351 | + if (observer) |
352 | + { |
353 | + std::unique_lock<decltype(mutex)> lock(mutex); |
354 | + observers.push_back(observer); |
355 | + } |
356 | +} |
357 | + |
358 | +void ms::SurfaceObservers::remove(std::shared_ptr<SurfaceObserver> const& observer) |
359 | +{ |
360 | + std::unique_lock<decltype(mutex)> lock(mutex); |
361 | + observers.erase(std::remove(observers.begin(),observers.end(), observer), observers.end()); |
362 | +} |
363 | + |
364 | ms::BasicSurface::BasicSurface( |
365 | - frontend::SurfaceId id, |
366 | std::string const& name, |
367 | geometry::Rectangle rect, |
368 | bool nonrectangular, |
369 | - std::shared_ptr<mc::BufferStream> const& buffer_stream, |
370 | + std::shared_ptr<compositor::BufferStream> const& buffer_stream, |
371 | std::shared_ptr<input::InputChannel> const& input_channel, |
372 | - std::shared_ptr<frontend::EventSink> const& event_sink, |
373 | std::shared_ptr<SurfaceConfigurator> const& configurator, |
374 | std::shared_ptr<SceneReport> const& report) : |
375 | - id(id), |
376 | notify_change([](){}), |
377 | surface_name(name), |
378 | surface_rect(rect), |
379 | @@ -79,7 +107,6 @@ |
380 | input_rectangles{surface_rect}, |
381 | surface_buffer_stream(buffer_stream), |
382 | server_input_channel(input_channel), |
383 | - event_sink(event_sink), |
384 | configurator(configurator), |
385 | report(report), |
386 | type_value(mir_surface_type_normal), |
387 | @@ -222,13 +249,7 @@ |
388 | surface_rect.size = size; |
389 | } |
390 | notify_change(); |
391 | - MirEvent e; |
392 | - memset(&e, 0, sizeof e); |
393 | - e.type = mir_event_type_resize; |
394 | - e.resize.surface_id = id.as_value(); |
395 | - e.resize.width = size.width.as_int(); |
396 | - e.resize.height = size.height.as_int(); |
397 | - event_sink->handle_event(e); |
398 | + observers.resize(size); |
399 | } |
400 | |
401 | geom::Point ms::BasicSurface::top_left() const |
402 | @@ -363,29 +384,12 @@ |
403 | state_value = s; |
404 | valid = true; |
405 | |
406 | - notify_attrib_change(mir_surface_attrib_state, s); |
407 | + observers.attrib_change(mir_surface_attrib_state, s); |
408 | } |
409 | |
410 | return valid; |
411 | } |
412 | |
413 | -void ms::BasicSurface::notify_attrib_change(MirSurfaceAttrib attrib, int value) |
414 | -{ |
415 | - MirEvent e; |
416 | - |
417 | - // This memset is not really required. However it does avoid some |
418 | - // harmless uninitialized memory reads that valgrind will complain |
419 | - // about, due to gaps in MirEvent. |
420 | - memset(&e, 0, sizeof e); |
421 | - |
422 | - e.type = mir_event_type_surface; |
423 | - e.surface.id = id.as_value(); |
424 | - e.surface.attrib = attrib; |
425 | - e.surface.value = value; |
426 | - |
427 | - event_sink->handle_event(e); |
428 | -} |
429 | - |
430 | void ms::BasicSurface::take_input_focus(std::shared_ptr<msh::InputTargeter> const& targeter) |
431 | { |
432 | targeter->focus_changed(input_channel()); |
433 | @@ -415,7 +419,7 @@ |
434 | result = state(); |
435 | break; |
436 | case mir_surface_attrib_focus: |
437 | - notify_attrib_change(attrib, value); |
438 | + observers.attrib_change(attrib, value); |
439 | break; |
440 | case mir_surface_attrib_swapinterval: |
441 | allow_dropping = (value == 0); |
442 | @@ -443,3 +447,13 @@ |
443 | set_hidden(false); |
444 | } |
445 | |
446 | + |
447 | +void ms::BasicSurface::add_observer(std::shared_ptr<SurfaceObserver> const& observer) |
448 | +{ |
449 | + observers.add(observer); |
450 | +} |
451 | + |
452 | +void ms::BasicSurface::remove_observer(std::shared_ptr<SurfaceObserver> const& observer) |
453 | +{ |
454 | + observers.remove(observer); |
455 | +} |
456 | |
457 | === modified file 'src/server/scene/basic_surface.h' |
458 | --- src/server/scene/basic_surface.h 2014-03-26 14:20:14 +0000 |
459 | +++ src/server/scene/basic_surface.h 2014-03-31 11:00:33 +0000 |
460 | @@ -20,8 +20,8 @@ |
461 | #define MIR_SCENE_BASIC_SURFACE_H_ |
462 | |
463 | #include "mir/scene/surface.h" |
464 | +#include "mir/scene/surface_observer.h" |
465 | |
466 | -#include "mir/frontend/surface_id.h" |
467 | #include "mir/geometry/rectangle.h" |
468 | |
469 | #include "mir_toolkit/common.h" |
470 | @@ -71,17 +71,30 @@ |
471 | std::function<void()> notify_change; |
472 | }; |
473 | |
474 | +class SurfaceObservers : public SurfaceObserver |
475 | +{ |
476 | +public: |
477 | + |
478 | + void attrib_change(MirSurfaceAttrib attrib, int value) override; |
479 | + void resize(geometry::Size const& size) override; |
480 | + |
481 | + void add(std::shared_ptr<SurfaceObserver> const& observer); |
482 | + void remove(std::shared_ptr<SurfaceObserver> const& observer); |
483 | + |
484 | +private: |
485 | + std::mutex mutex; |
486 | + std::vector<std::shared_ptr<SurfaceObserver>> observers; |
487 | +}; |
488 | + |
489 | class BasicSurface : public Surface |
490 | { |
491 | public: |
492 | BasicSurface( |
493 | - frontend::SurfaceId id, |
494 | std::string const& name, |
495 | geometry::Rectangle rect, |
496 | bool nonrectangular, |
497 | std::shared_ptr<compositor::BufferStream> const& buffer_stream, |
498 | std::shared_ptr<input::InputChannel> const& input_channel, |
499 | - std::shared_ptr<frontend::EventSink> const& event_sink, |
500 | std::shared_ptr<SurfaceConfigurator> const& configurator, |
501 | std::shared_ptr<SceneReport> const& report); |
502 | |
503 | @@ -136,13 +149,15 @@ |
504 | void hide() override; |
505 | void show() override; |
506 | |
507 | + void add_observer(std::shared_ptr<SurfaceObserver> const& observer) override; |
508 | + void remove_observer(std::shared_ptr<SurfaceObserver> const& observer) override; |
509 | + |
510 | private: |
511 | bool set_type(MirSurfaceType t); // Use configure() to make public changes |
512 | bool set_state(MirSurfaceState s); |
513 | - void notify_attrib_change(MirSurfaceAttrib attrib, int value); |
514 | |
515 | + SurfaceObservers observers; |
516 | std::mutex mutable guard; |
517 | - frontend::SurfaceId const id; |
518 | ThreadsafeCallback notify_change; |
519 | std::string const surface_name; |
520 | geometry::Rectangle surface_rect; |
521 | @@ -154,7 +169,6 @@ |
522 | std::vector<geometry::Rectangle> input_rectangles; |
523 | std::shared_ptr<compositor::BufferStream> const surface_buffer_stream; |
524 | std::shared_ptr<input::InputChannel> const server_input_channel; |
525 | - std::shared_ptr<frontend::EventSink> const event_sink; |
526 | std::shared_ptr<SurfaceConfigurator> const configurator; |
527 | std::shared_ptr<SceneReport> const report; |
528 | |
529 | |
530 | === modified file 'src/server/scene/surface_allocator.cpp' |
531 | --- src/server/scene/surface_allocator.cpp 2014-03-26 14:20:14 +0000 |
532 | +++ src/server/scene/surface_allocator.cpp 2014-03-31 11:00:33 +0000 |
533 | @@ -48,9 +48,7 @@ |
534 | } |
535 | |
536 | std::shared_ptr<ms::Surface> ms::SurfaceAllocator::create_surface( |
537 | - frontend::SurfaceId id, |
538 | - msh::SurfaceCreationParameters const& params, |
539 | - std::shared_ptr<frontend::EventSink> const& event_sink) |
540 | + shell::SurfaceCreationParameters const& params) |
541 | { |
542 | mg::BufferProperties buffer_properties{params.size, |
543 | params.pixel_format, |
544 | @@ -60,14 +58,14 @@ |
545 | |
546 | bool nonrectangular = has_alpha(params.pixel_format); |
547 | auto input_channel = input_factory->make_input_channel(); |
548 | - return std::make_shared<BasicSurface>( |
549 | - id, |
550 | + auto const surface = std::make_shared<BasicSurface>( |
551 | params.name, |
552 | actual_size, |
553 | nonrectangular, |
554 | buffer_stream, |
555 | input_channel, |
556 | - event_sink, |
557 | configurator, |
558 | report); |
559 | + |
560 | + return surface; |
561 | } |
562 | |
563 | === modified file 'src/server/scene/surface_allocator.h' |
564 | --- src/server/scene/surface_allocator.h 2014-03-31 11:00:33 +0000 |
565 | +++ src/server/scene/surface_allocator.h 2014-03-31 11:00:33 +0000 |
566 | @@ -42,9 +42,7 @@ |
567 | std::shared_ptr<SceneReport> const& report); |
568 | |
569 | std::shared_ptr<Surface> create_surface( |
570 | - frontend::SurfaceId id, |
571 | - shell::SurfaceCreationParameters const& params, |
572 | - std::shared_ptr<frontend::EventSink> const& event_sink) override; |
573 | + shell::SurfaceCreationParameters const& params) override; |
574 | |
575 | private: |
576 | std::shared_ptr<BufferStreamFactory> const buffer_stream_factory; |
577 | |
578 | === modified file 'src/server/scene/surface_controller.cpp' |
579 | --- src/server/scene/surface_controller.cpp 2014-03-31 11:00:33 +0000 |
580 | +++ src/server/scene/surface_controller.cpp 2014-03-31 11:00:33 +0000 |
581 | @@ -19,6 +19,7 @@ |
582 | #include "surface_controller.h" |
583 | #include "surface_stack_model.h" |
584 | #include "mir/scene/surface_factory.h" |
585 | +#include "mir/scene/surface.h" |
586 | |
587 | namespace ms = mir::scene; |
588 | namespace msh = mir::shell; |
589 | @@ -32,11 +33,11 @@ |
590 | } |
591 | |
592 | std::shared_ptr<ms::Surface> ms::SurfaceController::add_surface( |
593 | - frontend::SurfaceId id, |
594 | shell::SurfaceCreationParameters const& params, |
595 | - std::shared_ptr<frontend::EventSink> const& event_sink) |
596 | + std::shared_ptr<SurfaceObserver> const& observer) |
597 | { |
598 | - auto const surface = surface_factory->create_surface(id, params, event_sink); |
599 | + auto const surface = surface_factory->create_surface(params); |
600 | + surface->add_observer(observer); |
601 | surface_stack->add_surface(surface, params.depth, params.input_mode); |
602 | return surface; |
603 | } |
604 | |
605 | === modified file 'src/server/scene/surface_controller.h' |
606 | --- src/server/scene/surface_controller.h 2014-03-31 11:00:33 +0000 |
607 | +++ src/server/scene/surface_controller.h 2014-03-31 11:00:33 +0000 |
608 | @@ -24,11 +24,6 @@ |
609 | |
610 | namespace mir |
611 | { |
612 | -namespace shell |
613 | -{ |
614 | -class Session; |
615 | -} |
616 | - |
617 | namespace scene |
618 | { |
619 | class SurfaceStackModel; |
620 | @@ -43,9 +38,8 @@ |
621 | std::shared_ptr<SurfaceStackModel> const& surface_stack); |
622 | |
623 | std::shared_ptr<Surface> add_surface( |
624 | - frontend::SurfaceId id, |
625 | shell::SurfaceCreationParameters const& params, |
626 | - std::shared_ptr<frontend::EventSink> const& event_sink) override; |
627 | + std::shared_ptr<SurfaceObserver> const& observer) override; |
628 | |
629 | void remove_surface(std::weak_ptr<Surface> const& surface) override; |
630 | |
631 | |
632 | === added file 'src/server/scene/surface_event_source.cpp' |
633 | --- src/server/scene/surface_event_source.cpp 1970-01-01 00:00:00 +0000 |
634 | +++ src/server/scene/surface_event_source.cpp 2014-03-31 11:00:33 +0000 |
635 | @@ -0,0 +1,62 @@ |
636 | +/* |
637 | + * Copyright © 2014 Canonical Ltd. |
638 | + * |
639 | + * This program is free software: you can redistribute it and/or modify it |
640 | + * under the terms of the GNU General Public License version 3, |
641 | + * as published by the Free Software Foundation. |
642 | + * |
643 | + * This program is distributed in the hope that it will be useful, |
644 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
645 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
646 | + * GNU General Public License for more details. |
647 | + * |
648 | + * You should have received a copy of the GNU General Public License |
649 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
650 | + * |
651 | + * Authored by: Alan Griffiths <alan@octopull.co.uk> |
652 | + */ |
653 | + |
654 | +#include "mir/scene/surface_event_source.h" |
655 | + |
656 | +#include <cstring> |
657 | +#include <algorithm> |
658 | + |
659 | +namespace ms = mir::scene; |
660 | +namespace geom = mir::geometry; |
661 | + |
662 | +ms::SurfaceEventSource::SurfaceEventSource( |
663 | + frontend::SurfaceId id, |
664 | + std::shared_ptr<frontend::EventSink> const& event_sink) : |
665 | + id(id), |
666 | + event_sink(event_sink) |
667 | +{ |
668 | +} |
669 | + |
670 | +void ms::SurfaceEventSource::resize(geom::Size const& size) |
671 | +{ |
672 | + MirEvent e; |
673 | + memset(&e, 0, sizeof e); |
674 | + e.type = mir_event_type_resize; |
675 | + e.resize.surface_id = id.as_value(); |
676 | + e.resize.width = size.width.as_int(); |
677 | + e.resize.height = size.height.as_int(); |
678 | + event_sink->handle_event(e); |
679 | +} |
680 | + |
681 | + |
682 | +void ms::SurfaceEventSource::attrib_change(MirSurfaceAttrib attrib, int value) |
683 | +{ |
684 | + MirEvent e; |
685 | + |
686 | + // This memset is not really required. However it does avoid some |
687 | + // harmless uninitialized memory reads that valgrind will complain |
688 | + // about, due to gaps in MirEvent. |
689 | + memset(&e, 0, sizeof e); |
690 | + |
691 | + e.type = mir_event_type_surface; |
692 | + e.surface.id = id.as_value(); |
693 | + e.surface.attrib = attrib; |
694 | + e.surface.value = value; |
695 | + |
696 | + event_sink->handle_event(e); |
697 | +} |
698 | |
699 | === modified file 'src/server/shell/organising_surface_factory.cpp' |
700 | --- src/server/shell/organising_surface_factory.cpp 2014-03-31 11:00:33 +0000 |
701 | +++ src/server/shell/organising_surface_factory.cpp 2014-03-31 11:00:33 +0000 |
702 | @@ -42,13 +42,12 @@ |
703 | |
704 | std::shared_ptr<msh::Surface> msh::OrganisingSurfaceFactory::create_surface( |
705 | Session* session, |
706 | - shell::SurfaceCreationParameters const& params, |
707 | - frontend::SurfaceId id, |
708 | - std::shared_ptr<mf::EventSink> const& sender) |
709 | + SurfaceCreationParameters const& params, |
710 | + std::shared_ptr<scene::SurfaceObserver> const& observer) |
711 | { |
712 | auto placed_params = placement_strategy->place(*session, params); |
713 | |
714 | - return surface_coordinator->add_surface(id, placed_params, sender); |
715 | + return surface_coordinator->add_surface(placed_params, observer); |
716 | } |
717 | |
718 | void msh::OrganisingSurfaceFactory::destroy_surface(std::shared_ptr<Surface> const& surface) |
719 | |
720 | === modified file 'src/server/shell/organising_surface_factory.h' |
721 | --- src/server/shell/organising_surface_factory.h 2014-03-31 11:00:33 +0000 |
722 | +++ src/server/shell/organising_surface_factory.h 2014-03-31 11:00:33 +0000 |
723 | @@ -41,9 +41,8 @@ |
724 | |
725 | std::shared_ptr<Surface> create_surface( |
726 | Session* session, |
727 | - shell::SurfaceCreationParameters const& params, |
728 | - frontend::SurfaceId id, |
729 | - std::shared_ptr<frontend::EventSink> const& sink) override; |
730 | + SurfaceCreationParameters const& params, |
731 | + std::shared_ptr<scene::SurfaceObserver> const& observer) override; |
732 | |
733 | void destroy_surface(std::shared_ptr<Surface> const& surface) override; |
734 | |
735 | |
736 | === modified file 'tests/acceptance-tests/test_client_input.cpp' |
737 | --- tests/acceptance-tests/test_client_input.cpp 2014-03-26 14:20:14 +0000 |
738 | +++ tests/acceptance-tests/test_client_input.cpp 2014-03-31 11:00:33 +0000 |
739 | @@ -335,12 +335,12 @@ |
740 | { |
741 | } |
742 | |
743 | - std::shared_ptr<msh::Surface> create_surface(msh::Session* session, |
744 | - msh::SurfaceCreationParameters const& params, |
745 | - mf::SurfaceId id, |
746 | - std::shared_ptr<mf::EventSink> const& sink) |
747 | + std::shared_ptr<msh::Surface> create_surface( |
748 | + msh::Session* session, |
749 | + msh::SurfaceCreationParameters const& params, |
750 | + std::shared_ptr<ms::SurfaceObserver> const& observer) override |
751 | { |
752 | - auto surface = underlying_factory->create_surface(session, params, id, sink); |
753 | + auto surface = underlying_factory->create_surface(session, params, observer); |
754 | |
755 | surface->set_input_region(input_rectangles); |
756 | |
757 | |
758 | === modified file 'tests/integration-tests/graphics/android/test_internal_client.cpp' |
759 | --- tests/integration-tests/graphics/android/test_internal_client.cpp 2014-03-31 11:00:33 +0000 |
760 | +++ tests/integration-tests/graphics/android/test_internal_client.cpp 2014-03-31 11:00:33 +0000 |
761 | @@ -33,6 +33,7 @@ |
762 | #include "mir/scene/scene_report.h" |
763 | #include "src/server/scene/surface_allocator.h" |
764 | #include "mir/scene/surface.h" |
765 | +#include "mir/scene/surface_event_source.h" |
766 | #include "mir/shell/surface_creation_parameters.h" |
767 | #include "mir/frontend/surface_id.h" |
768 | #include "mir/input/input_channel_factory.h" |
769 | @@ -98,7 +99,8 @@ |
770 | auto surface_allocator = std::make_shared<ms::SurfaceAllocator>(buffer_stream_factory, stub_input_factory, std::make_shared<mtd::NullSurfaceConfigurator>(), scene_report); |
771 | auto ss = std::make_shared<ms::SurfaceStack>(stub_input_registrar, scene_report); |
772 | auto surface_controller = std::make_shared<ms::SurfaceController>(surface_allocator, ss); |
773 | - auto surface = surface_controller->add_surface(id, params, std::shared_ptr<mf::EventSink>()); |
774 | + auto const observer = std::make_shared<ms::SurfaceEventSource>(id, std::shared_ptr<mf::EventSink>()); |
775 | + auto surface = surface_controller->add_surface(params, observer); |
776 | surface->allow_framedropping(true); |
777 | auto mir_surface = as_internal_surface(surface); |
778 | |
779 | |
780 | === modified file 'tests/integration-tests/test_session_manager.cpp' |
781 | --- tests/integration-tests/test_session_manager.cpp 2014-03-06 06:05:17 +0000 |
782 | +++ tests/integration-tests/test_session_manager.cpp 2014-03-31 11:00:33 +0000 |
783 | @@ -60,7 +60,7 @@ |
784 | |
785 | } |
786 | |
787 | - mtd::MockSurfaceFactory surface_factory; |
788 | + mtd::MockSurfaceFactory surface_factory; // TODO this isn't used as a mock |
789 | ms::DefaultSessionContainer container; |
790 | mtd::MockFocusSetter focus_setter; |
791 | std::shared_ptr<mf::Session> new_session; |
792 | |
793 | === modified file 'tests/unit-tests/scene/test_application_session.cpp' |
794 | --- tests/unit-tests/scene/test_application_session.cpp 2014-03-31 11:00:33 +0000 |
795 | +++ tests/unit-tests/scene/test_application_session.cpp 2014-03-31 11:00:33 +0000 |
796 | @@ -84,7 +84,7 @@ |
797 | mtd::NullEventSink sender; |
798 | mtd::MockSurfaceFactory surface_factory; |
799 | |
800 | - EXPECT_CALL(surface_factory, create_surface(_, _, _, _)) |
801 | + EXPECT_CALL(surface_factory, create_surface(_, _, _)) |
802 | .WillOnce(Return(mock_surface)); |
803 | |
804 | mtd::MockSessionListener listener; |
805 | @@ -115,9 +115,9 @@ |
806 | |
807 | mtd::NullEventSink sender; |
808 | mtd::MockSurfaceFactory surface_factory; |
809 | - ON_CALL(surface_factory, create_surface(_,_,_,_)).WillByDefault(Return(mock_surface)); |
810 | + ON_CALL(surface_factory, create_surface(_,_,_)).WillByDefault(Return(mock_surface)); |
811 | |
812 | - EXPECT_CALL(surface_factory, create_surface(_, _, _, _)); |
813 | + EXPECT_CALL(surface_factory, create_surface(_, _, _)); |
814 | |
815 | mtd::MockSessionListener listener; |
816 | EXPECT_CALL(listener, surface_created(_, _)).Times(1); |
817 | @@ -146,11 +146,11 @@ |
818 | |
819 | { |
820 | InSequence seq; |
821 | - EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1) |
822 | - .WillOnce(Return(make_mock_surface())); |
823 | - EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1) |
824 | - .WillOnce(Return(make_mock_surface())); |
825 | - EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1) |
826 | + EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1) |
827 | + .WillOnce(Return(make_mock_surface())); |
828 | + EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1) |
829 | + .WillOnce(Return(make_mock_surface())); |
830 | + EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1) |
831 | .WillOnce(Return(make_mock_surface())); |
832 | } |
833 | |
834 | @@ -189,7 +189,7 @@ |
835 | auto mock_surface = make_mock_surface(); |
836 | |
837 | mtd::MockSurfaceFactory surface_factory; |
838 | - ON_CALL(surface_factory, create_surface(_, _, _, _)).WillByDefault(Return(mock_surface)); |
839 | + ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault(Return(mock_surface)); |
840 | |
841 | ms::ApplicationSession app_session( |
842 | mt::fake_shared(surface_factory), |
843 | @@ -199,7 +199,7 @@ |
844 | std::make_shared<msh::NullSessionListener>(), |
845 | mt::fake_shared(sender)); |
846 | |
847 | - EXPECT_CALL(surface_factory, create_surface(_, _, _, _)); |
848 | + EXPECT_CALL(surface_factory, create_surface(_, _, _)); |
849 | |
850 | { |
851 | InSequence seq; |
852 | @@ -269,7 +269,7 @@ |
853 | std::static_pointer_cast<msh::SurfaceBufferAccess>(default_surface); |
854 | auto const snapshot_strategy = std::make_shared<MockSnapshotStrategy>(); |
855 | |
856 | - EXPECT_CALL(surface_factory, create_surface(_,_,_,_)) |
857 | + EXPECT_CALL(surface_factory, create_surface(_,_,_)) |
858 | .WillOnce(Return(default_surface)); |
859 | |
860 | EXPECT_CALL(*snapshot_strategy, |
861 | |
862 | === modified file 'tests/unit-tests/scene/test_basic_surface.cpp' |
863 | --- tests/unit-tests/scene/test_basic_surface.cpp 2014-03-26 14:20:14 +0000 |
864 | +++ tests/unit-tests/scene/test_basic_surface.cpp 2014-03-31 11:00:33 +0000 |
865 | @@ -85,7 +85,6 @@ |
866 | std::function<void()> mock_change_cb; |
867 | std::shared_ptr<testing::NiceMock<mtd::MockBufferStream>> mock_buffer_stream = |
868 | std::make_shared<testing::NiceMock<mtd::MockBufferStream>>(); |
869 | - std::shared_ptr<StubEventSink> const stub_event_sink = std::make_shared<StubEventSink>(); |
870 | std::shared_ptr<StubSurfaceConfigurator> const stub_configurator = std::make_shared<StubSurfaceConfigurator>(); |
871 | std::shared_ptr<ms::SceneReport> const report = mr::null_scene_report(); |
872 | }; |
873 | @@ -95,13 +94,11 @@ |
874 | TEST_F(BasicSurfaceTest, basics) |
875 | { |
876 | ms::BasicSurface surface{ |
877 | - mf::SurfaceId(), |
878 | name, |
879 | rect, |
880 | false, |
881 | mock_buffer_stream, |
882 | std::shared_ptr<mi::InputChannel>(), |
883 | - stub_event_sink, |
884 | stub_configurator, |
885 | report}; |
886 | |
887 | @@ -117,13 +114,11 @@ |
888 | .Times(1); |
889 | |
890 | ms::BasicSurface surface{ |
891 | - mf::SurfaceId(), |
892 | name, |
893 | rect, |
894 | false, |
895 | mock_buffer_stream, |
896 | std::shared_ptr<mi::InputChannel>(), |
897 | - stub_event_sink, |
898 | stub_configurator, |
899 | report}; |
900 | |
901 | @@ -144,13 +139,11 @@ |
902 | .Times(1); |
903 | |
904 | ms::BasicSurface surface{ |
905 | - mf::SurfaceId(), |
906 | name, |
907 | rect, |
908 | false, |
909 | mock_buffer_stream, |
910 | std::shared_ptr<mi::InputChannel>(), |
911 | - stub_event_sink, |
912 | stub_configurator, |
913 | report}; |
914 | |
915 | @@ -173,13 +166,11 @@ |
916 | .Times(1); |
917 | |
918 | ms::BasicSurface surface{ |
919 | - mf::SurfaceId(), |
920 | name, |
921 | rect, |
922 | false, |
923 | mock_buffer_stream, |
924 | std::shared_ptr<mi::InputChannel>(), |
925 | - stub_event_sink, |
926 | stub_configurator, |
927 | report}; |
928 | |
929 | @@ -204,13 +195,11 @@ |
930 | .Times(1); |
931 | |
932 | ms::BasicSurface surface{ |
933 | - mf::SurfaceId(), |
934 | name, |
935 | rect, |
936 | false, |
937 | mock_buffer_stream, |
938 | std::shared_ptr<mi::InputChannel>(), |
939 | - stub_event_sink, |
940 | stub_configurator, |
941 | report}; |
942 | |
943 | @@ -225,13 +214,11 @@ |
944 | { |
945 | using namespace testing; |
946 | ms::BasicSurface surface{ |
947 | - mf::SurfaceId(), |
948 | name, |
949 | rect, |
950 | false, |
951 | mock_buffer_stream, |
952 | std::shared_ptr<mi::InputChannel>(), |
953 | - stub_event_sink, |
954 | stub_configurator, |
955 | report}; |
956 | |
957 | @@ -242,13 +229,11 @@ |
958 | TEST_F(BasicSurfaceTest, test_surface_should_be_rendered_in) |
959 | { |
960 | ms::BasicSurface surface{ |
961 | - mf::SurfaceId(), |
962 | name, |
963 | rect, |
964 | false, |
965 | mock_buffer_stream, |
966 | std::shared_ptr<mi::InputChannel>(), |
967 | - stub_event_sink, |
968 | stub_configurator, |
969 | report}; |
970 | |
971 | @@ -281,13 +266,11 @@ |
972 | .Times(1); |
973 | |
974 | ms::BasicSurface surface{ |
975 | - mf::SurfaceId(), |
976 | name, |
977 | rect, |
978 | false, |
979 | mock_buffer_stream, |
980 | std::shared_ptr<mi::InputChannel>(), |
981 | - stub_event_sink, |
982 | stub_configurator, |
983 | report}; |
984 | |
985 | @@ -303,13 +286,11 @@ |
986 | .Times(1); |
987 | |
988 | ms::BasicSurface surface{ |
989 | - mf::SurfaceId(), |
990 | name, |
991 | rect, |
992 | false, |
993 | mock_buffer_stream, |
994 | std::shared_ptr<mi::InputChannel>(), |
995 | - stub_event_sink, |
996 | stub_configurator, |
997 | report}; |
998 | |
999 | @@ -324,13 +305,11 @@ |
1000 | geom::Point pt(1,1); |
1001 | geom::Size one_by_one{geom::Width{1}, geom::Height{1}}; |
1002 | ms::BasicSurface surface{ |
1003 | - mf::SurfaceId(), |
1004 | name, |
1005 | geom::Rectangle{pt, one_by_one}, |
1006 | false, |
1007 | mock_buffer_stream, |
1008 | std::shared_ptr<mi::InputChannel>(), |
1009 | - stub_event_sink, |
1010 | stub_configurator, |
1011 | report}; |
1012 | |
1013 | @@ -367,13 +346,11 @@ |
1014 | }; |
1015 | |
1016 | ms::BasicSurface surface{ |
1017 | - mf::SurfaceId(), |
1018 | name, |
1019 | rect, |
1020 | false, |
1021 | mock_buffer_stream, |
1022 | std::shared_ptr<mi::InputChannel>(), |
1023 | - stub_event_sink, |
1024 | stub_configurator, |
1025 | report}; |
1026 | |
1027 | |
1028 | === modified file 'tests/unit-tests/scene/test_session_manager.cpp' |
1029 | --- tests/unit-tests/scene/test_session_manager.cpp 2014-03-31 11:00:33 +0000 |
1030 | +++ tests/unit-tests/scene/test_session_manager.cpp 2014-03-31 11:00:33 +0000 |
1031 | @@ -85,13 +85,11 @@ |
1032 | } |
1033 | |
1034 | std::shared_ptr<ms::Surface> dummy_surface = std::make_shared<ms::BasicSurface>( |
1035 | - mf::SurfaceId(), |
1036 | std::string("stub"), |
1037 | geom::Rectangle{{},{}}, |
1038 | false, |
1039 | std::make_shared<mtd::StubBufferStream>(), |
1040 | std::shared_ptr<mi::InputChannel>(), |
1041 | - std::shared_ptr<mf::EventSink>(), |
1042 | std::shared_ptr<ms::SurfaceConfigurator>(), |
1043 | mir::report::null_scene_report()); |
1044 | mtd::MockSurfaceFactory surface_factory; |
1045 | @@ -121,9 +119,9 @@ |
1046 | { |
1047 | using namespace ::testing; |
1048 | |
1049 | - EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1); |
1050 | + EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1); |
1051 | |
1052 | - ON_CALL(surface_factory, create_surface(_, _, _, _)).WillByDefault( |
1053 | + ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault( |
1054 | Return(dummy_surface)); |
1055 | |
1056 | EXPECT_CALL(container, insert_session(_)).Times(1); |
1057 | @@ -153,7 +151,7 @@ |
1058 | TEST_F(SessionManagerSetup, create_surface_for_session_forwards_and_then_focuses_session) |
1059 | { |
1060 | using namespace ::testing; |
1061 | - ON_CALL(surface_factory, create_surface(_, _, _, _)).WillByDefault( |
1062 | + ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault( |
1063 | Return(dummy_surface)); |
1064 | |
1065 | // Once for session creation and once for surface creation |
1066 | @@ -161,7 +159,7 @@ |
1067 | InSequence seq; |
1068 | |
1069 | EXPECT_CALL(focus_setter, set_focus_to(_)).Times(1); // Session creation |
1070 | - EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1); |
1071 | + EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1); |
1072 | EXPECT_CALL(focus_setter, set_focus_to(_)).Times(1); // Post Surface creation |
1073 | } |
1074 | |
1075 | |
1076 | === modified file 'tests/unit-tests/scene/test_surface.cpp' |
1077 | --- tests/unit-tests/scene/test_surface.cpp 2014-03-26 14:20:14 +0000 |
1078 | +++ tests/unit-tests/scene/test_surface.cpp 2014-03-31 11:00:33 +0000 |
1079 | @@ -21,6 +21,7 @@ |
1080 | #include "mir/frontend/event_sink.h" |
1081 | #include "mir/shell/surface_creation_parameters.h" |
1082 | #include "mir/scene/surface_configurator.h" |
1083 | +#include "mir/scene/surface_event_source.h" |
1084 | #include "mir/input/input_channel.h" |
1085 | |
1086 | #include "mir_test_doubles/mock_buffer_stream.h" |
1087 | @@ -209,7 +210,6 @@ |
1088 | std::function<void()> change_notification; |
1089 | int notification_count; |
1090 | mtd::StubBuffer stub_buffer; |
1091 | - std::shared_ptr<StubEventSink> const stub_event_sink = std::make_shared<StubEventSink>(); |
1092 | std::shared_ptr<StubSurfaceConfigurator> const stub_configurator = std::make_shared<StubSurfaceConfigurator>(); |
1093 | }; |
1094 | |
1095 | @@ -219,13 +219,11 @@ |
1096 | { |
1097 | using namespace testing; |
1098 | ms::BasicSurface surf( |
1099 | - mf::SurfaceId(), |
1100 | surface_name, |
1101 | rect, |
1102 | false, |
1103 | mock_buffer_stream, |
1104 | std::shared_ptr<mi::InputChannel>(), |
1105 | - stub_event_sink, |
1106 | stub_configurator, |
1107 | report); |
1108 | |
1109 | @@ -241,13 +239,11 @@ |
1110 | TEST_F(SurfaceCreation, test_surface_gets_right_name) |
1111 | { |
1112 | ms::BasicSurface surf( |
1113 | - mf::SurfaceId(), |
1114 | surface_name, |
1115 | rect, |
1116 | false, |
1117 | mock_buffer_stream, |
1118 | std::shared_ptr<mi::InputChannel>(), |
1119 | - stub_event_sink, |
1120 | stub_configurator, |
1121 | report); |
1122 | |
1123 | @@ -257,13 +253,11 @@ |
1124 | TEST_F(SurfaceCreation, test_surface_queries_state_for_size) |
1125 | { |
1126 | ms::BasicSurface surf( |
1127 | - mf::SurfaceId(), |
1128 | surface_name, |
1129 | rect, |
1130 | false, |
1131 | mock_buffer_stream, |
1132 | std::shared_ptr<mi::InputChannel>(), |
1133 | - stub_event_sink, |
1134 | stub_configurator, |
1135 | report); |
1136 | |
1137 | @@ -274,13 +268,11 @@ |
1138 | { |
1139 | using namespace testing; |
1140 | ms::BasicSurface surf( |
1141 | - mf::SurfaceId(), |
1142 | surface_name, |
1143 | rect, |
1144 | false, |
1145 | mock_buffer_stream, |
1146 | std::shared_ptr<mi::InputChannel>(), |
1147 | - stub_event_sink, |
1148 | stub_configurator, |
1149 | report); |
1150 | |
1151 | @@ -302,13 +294,11 @@ |
1152 | mtd::StubBuffer stub_buffer; |
1153 | |
1154 | ms::BasicSurface surf( |
1155 | - mf::SurfaceId(), |
1156 | surface_name, |
1157 | rect, |
1158 | false, |
1159 | mock_buffer_stream, |
1160 | std::shared_ptr<mi::InputChannel>(), |
1161 | - stub_event_sink, |
1162 | stub_configurator, |
1163 | report); |
1164 | |
1165 | @@ -324,13 +314,11 @@ |
1166 | TEST_F(SurfaceCreation, test_surface_gets_top_left) |
1167 | { |
1168 | ms::BasicSurface surf( |
1169 | - mf::SurfaceId(), |
1170 | surface_name, |
1171 | rect, |
1172 | false, |
1173 | mock_buffer_stream, |
1174 | std::shared_ptr<mi::InputChannel>(), |
1175 | - stub_event_sink, |
1176 | stub_configurator, |
1177 | report); |
1178 | |
1179 | @@ -343,13 +331,11 @@ |
1180 | geom::Point p{55, 66}; |
1181 | |
1182 | ms::BasicSurface surf( |
1183 | - mf::SurfaceId(), |
1184 | surface_name, |
1185 | rect, |
1186 | false, |
1187 | mock_buffer_stream, |
1188 | std::shared_ptr<mi::InputChannel>(), |
1189 | - stub_event_sink, |
1190 | stub_configurator, |
1191 | report); |
1192 | |
1193 | @@ -366,18 +352,19 @@ |
1194 | .Times(1); |
1195 | |
1196 | auto const mock_event_sink = std::make_shared<MockEventSink>(); |
1197 | + auto const observer = std::make_shared<ms::SurfaceEventSource>(mf::SurfaceId(), mock_event_sink); |
1198 | |
1199 | ms::BasicSurface surf( |
1200 | - mf::SurfaceId(), |
1201 | surface_name, |
1202 | rect, |
1203 | false, |
1204 | mock_buffer_stream, |
1205 | std::shared_ptr<mi::InputChannel>(), |
1206 | - mock_event_sink, |
1207 | stub_configurator, |
1208 | report); |
1209 | |
1210 | + surf.add_observer(observer); |
1211 | + |
1212 | ASSERT_THAT(surf.size(), Ne(new_size)); |
1213 | |
1214 | EXPECT_CALL(*mock_event_sink, handle_event(_)).Times(1); |
1215 | @@ -390,18 +377,19 @@ |
1216 | using namespace testing; |
1217 | geom::Size const new_size{123, 456}; |
1218 | auto const mock_event_sink = std::make_shared<MockEventSink>(); |
1219 | + auto const observer = std::make_shared<ms::SurfaceEventSource>(mf::SurfaceId(), mock_event_sink); |
1220 | |
1221 | ms::BasicSurface surf( |
1222 | - mf::SurfaceId(), |
1223 | surface_name, |
1224 | rect, |
1225 | false, |
1226 | mock_buffer_stream, |
1227 | std::shared_ptr<mi::InputChannel>(), |
1228 | - mock_event_sink, |
1229 | stub_configurator, |
1230 | report); |
1231 | |
1232 | + surf.add_observer(observer); |
1233 | + |
1234 | ASSERT_THAT(surf.size(), Ne(new_size)); |
1235 | |
1236 | EXPECT_CALL(*mock_buffer_stream, resize(new_size)).Times(1); |
1237 | @@ -428,13 +416,11 @@ |
1238 | .WillOnce(Throw(std::runtime_error("bad resize"))); |
1239 | |
1240 | ms::BasicSurface surf( |
1241 | - mf::SurfaceId(), |
1242 | surface_name, |
1243 | rect, |
1244 | false, |
1245 | mock_buffer_stream, |
1246 | std::shared_ptr<mi::InputChannel>(), |
1247 | - stub_event_sink, |
1248 | stub_configurator, |
1249 | report); |
1250 | |
1251 | @@ -459,13 +445,11 @@ |
1252 | }; |
1253 | |
1254 | ms::BasicSurface surf( |
1255 | - mf::SurfaceId(), |
1256 | surface_name, |
1257 | rect, |
1258 | false, |
1259 | mock_buffer_stream, |
1260 | std::shared_ptr<mi::InputChannel>(), |
1261 | - stub_event_sink, |
1262 | stub_configurator, |
1263 | report); |
1264 | |
1265 | @@ -484,13 +468,11 @@ |
1266 | { |
1267 | auto mock_channel = std::make_shared<MockInputChannel>(); |
1268 | ms::BasicSurface surf( |
1269 | - mf::SurfaceId(), |
1270 | surface_name, |
1271 | rect, |
1272 | false, |
1273 | mock_buffer_stream, |
1274 | mock_channel, |
1275 | - stub_event_sink, |
1276 | stub_configurator, |
1277 | report); |
1278 | |
1279 | @@ -503,13 +485,11 @@ |
1280 | |
1281 | float alpha = 0.5f; |
1282 | ms::BasicSurface surf( |
1283 | - mf::SurfaceId(), |
1284 | surface_name, |
1285 | rect, |
1286 | false, |
1287 | mock_buffer_stream, |
1288 | std::shared_ptr<mi::InputChannel>(), |
1289 | - stub_event_sink, |
1290 | stub_configurator, |
1291 | report); |
1292 | |
1293 | @@ -524,13 +504,11 @@ |
1294 | EXPECT_CALL(*mock_buffer_stream, force_requests_to_complete()).Times(Exactly(1)); |
1295 | |
1296 | ms::BasicSurface surf( |
1297 | - mf::SurfaceId(), |
1298 | surface_name, |
1299 | rect, |
1300 | false, |
1301 | mock_buffer_stream, |
1302 | std::shared_ptr<mi::InputChannel>(), |
1303 | - stub_event_sink, |
1304 | stub_configurator, |
1305 | report); |
1306 | |
1307 | @@ -545,13 +523,11 @@ |
1308 | .Times(1); |
1309 | |
1310 | ms::BasicSurface surf( |
1311 | - mf::SurfaceId(), |
1312 | surface_name, |
1313 | rect, |
1314 | false, |
1315 | mock_buffer_stream, |
1316 | std::shared_ptr<mi::InputChannel>(), |
1317 | - stub_event_sink, |
1318 | stub_configurator, |
1319 | report); |
1320 | |
1321 | @@ -561,13 +537,11 @@ |
1322 | TEST_F(SurfaceCreation, test_surface_next_buffer_tells_state_on_first_frame) |
1323 | { |
1324 | ms::BasicSurface surf( |
1325 | - mf::SurfaceId(), |
1326 | surface_name, |
1327 | rect, |
1328 | false, |
1329 | mock_buffer_stream, |
1330 | std::shared_ptr<mi::InputChannel>(), |
1331 | - stub_event_sink, |
1332 | stub_configurator, |
1333 | report); |
1334 | |
1335 | @@ -589,13 +563,11 @@ |
1336 | using namespace testing; |
1337 | |
1338 | ms::BasicSurface surf( |
1339 | - mf::SurfaceId(), |
1340 | surface_name, |
1341 | rect, |
1342 | false, |
1343 | mock_buffer_stream, |
1344 | std::shared_ptr<mi::InputChannel>(), |
1345 | - stub_event_sink, |
1346 | stub_configurator, |
1347 | report); |
1348 | |
1349 | @@ -608,12 +580,10 @@ |
1350 | EXPECT_CALL(channel, client_fd()).Times(1).WillOnce(Return(client_fd)); |
1351 | |
1352 | ms::BasicSurface input_surf( |
1353 | - mf::SurfaceId(), |
1354 | surface_name, |
1355 | rect, |
1356 | false, |
1357 | mock_buffer_stream,mt::fake_shared(channel), |
1358 | - stub_event_sink, |
1359 | stub_configurator, |
1360 | report); |
1361 | |
1362 | |
1363 | === modified file 'tests/unit-tests/scene/test_surface_controller.cpp' |
1364 | --- tests/unit-tests/scene/test_surface_controller.cpp 2014-03-31 11:00:33 +0000 |
1365 | +++ tests/unit-tests/scene/test_surface_controller.cpp 2014-03-31 11:00:33 +0000 |
1366 | @@ -21,6 +21,7 @@ |
1367 | #include "mir/scene/surface_factory.h" |
1368 | #include "mir/shell/surface_creation_parameters.h" |
1369 | |
1370 | +#include "mir_test_doubles/mock_surface.h" |
1371 | #include "mir_test/fake_shared.h" |
1372 | |
1373 | #include <gtest/gtest.h> |
1374 | @@ -30,15 +31,14 @@ |
1375 | namespace msh = mir::shell; |
1376 | namespace ms = mir::scene; |
1377 | namespace mt = mir::test; |
1378 | +namespace mtd = mir::test::doubles; |
1379 | |
1380 | namespace |
1381 | { |
1382 | struct MockSurfaceAllocator : public ms::SurfaceFactory |
1383 | { |
1384 | - MOCK_METHOD3(create_surface, std::shared_ptr<ms::Surface>( |
1385 | - mf::SurfaceId id, |
1386 | - msh::SurfaceCreationParameters const&, |
1387 | - std::shared_ptr<mf::EventSink> const&)); |
1388 | + MOCK_METHOD1(create_surface, std::shared_ptr<ms::Surface>( |
1389 | + msh::SurfaceCreationParameters const&)); |
1390 | }; |
1391 | |
1392 | struct MockSurfaceStackModel : public ms::SurfaceStackModel |
1393 | @@ -56,19 +56,24 @@ |
1394 | { |
1395 | using namespace ::testing; |
1396 | |
1397 | - std::shared_ptr<ms::Surface> null_surface; |
1398 | + mtd::MockSurface mock_surface; |
1399 | + std::shared_ptr<ms::Surface> const expect_surface = mt::fake_shared(mock_surface); |
1400 | + auto const surface = std::make_shared<mtd::MockSurface>(); |
1401 | testing::NiceMock<MockSurfaceAllocator> mock_surface_allocator; |
1402 | MockSurfaceStackModel model; |
1403 | |
1404 | ms::SurfaceController controller(mt::fake_shared(mock_surface_allocator), mt::fake_shared(model)); |
1405 | |
1406 | InSequence seq; |
1407 | - EXPECT_CALL(mock_surface_allocator, create_surface(_,_,_)).Times(1).WillOnce(Return(null_surface)); |
1408 | + EXPECT_CALL(mock_surface_allocator, create_surface(_)).Times(1).WillOnce(Return(expect_surface)); |
1409 | + EXPECT_CALL(mock_surface, add_observer(_)).Times(1); |
1410 | EXPECT_CALL(model, add_surface(_,_,_)).Times(1); |
1411 | EXPECT_CALL(model, remove_surface(_)).Times(1); |
1412 | |
1413 | - auto surface = controller.add_surface(mf::SurfaceId(), msh::a_surface(), {}); |
1414 | - controller.remove_surface(surface); |
1415 | + auto actual_surface = controller.add_surface(msh::a_surface(), std::shared_ptr<ms::SurfaceObserver>()); |
1416 | + |
1417 | + EXPECT_THAT(actual_surface, Eq(expect_surface)); |
1418 | + controller.remove_surface(actual_surface); |
1419 | } |
1420 | |
1421 | TEST(SurfaceController, raise_surface) |
1422 | |
1423 | === modified file 'tests/unit-tests/scene/test_surface_impl.cpp' |
1424 | --- tests/unit-tests/scene/test_surface_impl.cpp 2014-03-31 11:00:33 +0000 |
1425 | +++ tests/unit-tests/scene/test_surface_impl.cpp 2014-03-31 11:00:33 +0000 |
1426 | @@ -17,6 +17,8 @@ |
1427 | */ |
1428 | |
1429 | #include "src/server/scene/basic_surface.h" |
1430 | +#include "mir/scene/surface_observer.h" |
1431 | +#include "mir/scene/surface_event_source.h" |
1432 | #include "src/server/report/null_report_factory.h" |
1433 | #include "mir/frontend/event_sink.h" |
1434 | #include "mir/graphics/display_configuration.h" |
1435 | @@ -65,7 +67,6 @@ |
1436 | |
1437 | Surface() : |
1438 | buffer_stream(std::make_shared<StubBufferStream>()), |
1439 | - stub_sender(std::make_shared<mtd::NullEventSink>()), |
1440 | null_configurator(std::make_shared<mtd::NullSurfaceConfigurator>()) |
1441 | { |
1442 | using namespace testing; |
1443 | @@ -76,7 +77,6 @@ |
1444 | .WillByDefault(InvokeArgument<1>(nullptr)); |
1445 | } |
1446 | mf::SurfaceId stub_id; |
1447 | - std::shared_ptr<mf::EventSink> stub_sender; |
1448 | std::shared_ptr<ms::SurfaceConfigurator> null_configurator; |
1449 | std::shared_ptr<ms::SceneReport> const report = mr::null_scene_report(); |
1450 | }; |
1451 | @@ -87,13 +87,11 @@ |
1452 | using namespace testing; |
1453 | |
1454 | ms::BasicSurface surf( |
1455 | - stub_id, |
1456 | std::string("stub"), |
1457 | geom::Rectangle{{},{}}, |
1458 | false, |
1459 | buffer_stream, |
1460 | std::shared_ptr<mi::InputChannel>(), |
1461 | - stub_sender, |
1462 | null_configurator, |
1463 | report); |
1464 | |
1465 | @@ -107,13 +105,11 @@ |
1466 | using namespace testing; |
1467 | |
1468 | ms::BasicSurface surf( |
1469 | - stub_id, |
1470 | std::string("stub"), |
1471 | geom::Rectangle{{},{}}, |
1472 | false, |
1473 | buffer_stream, |
1474 | std::shared_ptr<mi::InputChannel>(), |
1475 | - stub_sender, |
1476 | null_configurator, |
1477 | report); |
1478 | |
1479 | @@ -148,13 +144,11 @@ |
1480 | using namespace testing; |
1481 | |
1482 | ms::BasicSurface surf( |
1483 | - stub_id, |
1484 | std::string("stub"), |
1485 | geom::Rectangle{{},{}}, |
1486 | false, |
1487 | buffer_stream, |
1488 | std::shared_ptr<mi::InputChannel>(), |
1489 | - stub_sender, |
1490 | null_configurator, |
1491 | report); |
1492 | |
1493 | @@ -196,18 +190,19 @@ |
1494 | |
1495 | geom::Size const new_size{123, 456}; |
1496 | auto sink = std::make_shared<MockEventSink>(); |
1497 | + auto const observer = std::make_shared<ms::SurfaceEventSource>(stub_id, sink); |
1498 | |
1499 | ms::BasicSurface surf( |
1500 | - stub_id, |
1501 | std::string("stub"), |
1502 | geom::Rectangle{{},{}}, |
1503 | false, |
1504 | buffer_stream, |
1505 | std::shared_ptr<mi::InputChannel>(), |
1506 | - sink, |
1507 | null_configurator, |
1508 | report); |
1509 | |
1510 | + surf.add_observer(observer); |
1511 | + |
1512 | MirEvent e; |
1513 | memset(&e, 0, sizeof e); |
1514 | e.type = mir_event_type_resize; |
1515 | @@ -228,18 +223,19 @@ |
1516 | geom::Size const new_size{123, 456}; |
1517 | geom::Size const new_size2{789, 1011}; |
1518 | auto sink = std::make_shared<MockEventSink>(); |
1519 | + auto const observer = std::make_shared<ms::SurfaceEventSource>(stub_id, sink); |
1520 | |
1521 | ms::BasicSurface surf( |
1522 | - stub_id, |
1523 | std::string("stub"), |
1524 | geom::Rectangle{{},{}}, |
1525 | false, |
1526 | buffer_stream, |
1527 | std::shared_ptr<mi::InputChannel>(), |
1528 | - sink, |
1529 | null_configurator, |
1530 | report); |
1531 | |
1532 | + surf.add_observer(observer); |
1533 | + |
1534 | MirEvent e; |
1535 | memset(&e, 0, sizeof e); |
1536 | e.type = mir_event_type_resize; |
1537 | @@ -272,13 +268,11 @@ |
1538 | TEST_F(Surface, remembers_alpha) |
1539 | { |
1540 | ms::BasicSurface surf( |
1541 | - stub_id, |
1542 | std::string("stub"), |
1543 | geom::Rectangle{{},{}}, |
1544 | false, |
1545 | buffer_stream, |
1546 | std::shared_ptr<mi::InputChannel>(), |
1547 | - stub_sender, |
1548 | null_configurator, |
1549 | report); |
1550 | |
1551 | @@ -311,17 +305,19 @@ |
1552 | .Times(1); |
1553 | } |
1554 | |
1555 | + auto const observer = std::make_shared<ms::SurfaceEventSource>(stub_id, mt::fake_shared(sink)); |
1556 | + |
1557 | ms::BasicSurface surf( |
1558 | - stub_id, |
1559 | std::string("stub"), |
1560 | geom::Rectangle{{},{}}, |
1561 | false, |
1562 | buffer_stream, |
1563 | std::shared_ptr<mi::InputChannel>(), |
1564 | - mt::fake_shared(sink), |
1565 | null_configurator, |
1566 | report); |
1567 | |
1568 | + surf.add_observer(observer); |
1569 | + |
1570 | surf.configure(mir_surface_attrib_focus, mir_surface_focused); |
1571 | surf.configure(mir_surface_attrib_focus, mir_surface_unfocused); |
1572 | } |
1573 | @@ -337,13 +333,11 @@ |
1574 | EXPECT_CALL(configurator, attribute_set(_, mir_surface_attrib_state, mir_surface_state_minimized)).Times(1); |
1575 | |
1576 | ms::BasicSurface surf( |
1577 | - stub_id, |
1578 | std::string("stub"), |
1579 | geom::Rectangle{{},{}}, |
1580 | false, |
1581 | buffer_stream, |
1582 | std::shared_ptr<mi::InputChannel>(), |
1583 | - stub_sender, |
1584 | mt::fake_shared(configurator), |
1585 | report); |
1586 | |
1587 | @@ -355,13 +349,11 @@ |
1588 | using namespace ::testing; |
1589 | |
1590 | ms::BasicSurface surf( |
1591 | - stub_id, |
1592 | std::string("stub"), |
1593 | geom::Rectangle{{},{}}, |
1594 | false, |
1595 | buffer_stream, |
1596 | std::shared_ptr<mi::InputChannel>(), |
1597 | - stub_sender, |
1598 | null_configurator, |
1599 | report); |
1600 | |
1601 | @@ -376,13 +368,11 @@ |
1602 | auto stub_buffer_stream = std::make_shared<mtd::StubBufferStream>(); |
1603 | |
1604 | ms::BasicSurface surf( |
1605 | - stub_id, |
1606 | std::string("stub"), |
1607 | geom::Rectangle{{},{}}, |
1608 | false, |
1609 | stub_buffer_stream, |
1610 | std::shared_ptr<mi::InputChannel>(), |
1611 | - stub_sender, |
1612 | null_configurator, |
1613 | report); |
1614 | |
1615 | |
1616 | === modified file 'tests/unit-tests/scene/test_surface_stack.cpp' |
1617 | --- tests/unit-tests/scene/test_surface_stack.cpp 2014-03-26 14:20:14 +0000 |
1618 | +++ tests/unit-tests/scene/test_surface_stack.cpp 2014-03-31 11:00:33 +0000 |
1619 | @@ -128,35 +128,29 @@ |
1620 | default_params = msh::a_surface().of_size(geom::Size{geom::Width{1024}, geom::Height{768}}); |
1621 | |
1622 | stub_surface1 = std::make_shared<ms::BasicSurface>( |
1623 | - mf::SurfaceId(__LINE__), |
1624 | std::string("stub"), |
1625 | geom::Rectangle{{},{}}, |
1626 | false, |
1627 | std::make_shared<mtd::StubBufferStream>(), |
1628 | std::shared_ptr<mir::input::InputChannel>(), |
1629 | - std::shared_ptr<mf::EventSink>(), |
1630 | std::shared_ptr<ms::SurfaceConfigurator>(), |
1631 | report); |
1632 | |
1633 | stub_surface2 = std::make_shared<ms::BasicSurface>( |
1634 | - mf::SurfaceId(__LINE__), |
1635 | std::string("stub"), |
1636 | geom::Rectangle{{},{}}, |
1637 | false, |
1638 | std::make_shared<mtd::StubBufferStream>(), |
1639 | std::shared_ptr<mir::input::InputChannel>(), |
1640 | - std::shared_ptr<mf::EventSink>(), |
1641 | std::shared_ptr<ms::SurfaceConfigurator>(), |
1642 | report); |
1643 | |
1644 | stub_surface3 = std::make_shared<ms::BasicSurface>( |
1645 | - mf::SurfaceId(__LINE__), |
1646 | std::string("stub"), |
1647 | geom::Rectangle{{},{}}, |
1648 | false, |
1649 | std::make_shared<mtd::StubBufferStream>(), |
1650 | std::shared_ptr<mir::input::InputChannel>(), |
1651 | - std::shared_ptr<mf::EventSink>(), |
1652 | std::shared_ptr<ms::SurfaceConfigurator>(), |
1653 | report); |
1654 | } |
1655 | @@ -568,13 +562,11 @@ |
1656 | for(auto i = 0u; i < num_surfaces; i++) |
1657 | { |
1658 | auto const surface = std::make_shared<ms::BasicSurface>( |
1659 | - mf::SurfaceId(__LINE__), |
1660 | std::string("stub"), |
1661 | geom::Rectangle{geom::Point{3 * i, 4 * i},geom::Size{1 * i, 2 * i}}, |
1662 | true, |
1663 | std::make_shared<mtd::StubBufferStream>(), |
1664 | std::shared_ptr<mir::input::InputChannel>(), |
1665 | - std::shared_ptr<mf::EventSink>(), |
1666 | std::shared_ptr<ms::SurfaceConfigurator>(), |
1667 | report); |
1668 | |
1669 | |
1670 | === modified file 'tests/unit-tests/shell/test_organising_surface_factory.cpp' |
1671 | --- tests/unit-tests/shell/test_organising_surface_factory.cpp 2014-03-31 11:00:33 +0000 |
1672 | +++ tests/unit-tests/shell/test_organising_surface_factory.cpp 2014-03-31 11:00:33 +0000 |
1673 | @@ -20,6 +20,8 @@ |
1674 | #include "mir/shell/placement_strategy.h" |
1675 | #include "mir/shell/surface_creation_parameters.h" |
1676 | #include "mir/shell/session.h" |
1677 | +#include "mir/scene/surface.h" |
1678 | +#include "mir/scene/surface_event_source.h" |
1679 | #include "mir/scene/surface_coordinator.h" |
1680 | |
1681 | #include "mir_test_doubles/stub_shell_session.h" |
1682 | @@ -38,10 +40,9 @@ |
1683 | { |
1684 | struct MockSurfaceCoordinator : public ms::SurfaceCoordinator |
1685 | { |
1686 | - MOCK_METHOD3(add_surface, std::shared_ptr<ms::Surface>( |
1687 | - mf::SurfaceId, |
1688 | + MOCK_METHOD2(add_surface, std::shared_ptr<ms::Surface>( |
1689 | msh::SurfaceCreationParameters const&, |
1690 | - std::shared_ptr<mf::EventSink> const&)); |
1691 | + std::shared_ptr<ms::SurfaceObserver> const&)); |
1692 | |
1693 | void remove_surface(std::weak_ptr<ms::Surface> const& /*surface*/) override {} |
1694 | void raise(std::weak_ptr<ms::Surface> const& /*surface*/) override {} |
1695 | @@ -57,10 +58,11 @@ |
1696 | void SetUp() |
1697 | { |
1698 | using namespace ::testing; |
1699 | - ON_CALL(*surface_coordinator, add_surface(_, _, _)).WillByDefault(Return(null_surface)); |
1700 | + ON_CALL(*surface_coordinator, add_surface(_, _)).WillByDefault(Return(null_surface)); |
1701 | } |
1702 | std::shared_ptr<ms::Surface> null_surface; |
1703 | std::shared_ptr<MockSurfaceCoordinator> surface_coordinator = std::make_shared<MockSurfaceCoordinator>(); |
1704 | + std::shared_ptr<ms::SurfaceObserver> const observer = std::make_shared<ms::SurfaceEventSource>(mf::SurfaceId(), std::make_shared<mtd::NullEventSink>()); |
1705 | std::shared_ptr<MockPlacementStrategy> placement_strategy = std::make_shared<MockPlacementStrategy>(); |
1706 | }; |
1707 | |
1708 | @@ -73,13 +75,13 @@ |
1709 | msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy); |
1710 | |
1711 | mtd::StubShellSession session; |
1712 | - EXPECT_CALL(*surface_coordinator, add_surface(_, _, _)).Times(1); |
1713 | + EXPECT_CALL(*surface_coordinator, add_surface(_, _)).Times(1); |
1714 | |
1715 | auto params = msh::a_surface(); |
1716 | EXPECT_CALL(*placement_strategy, place(Ref(session), Ref(params))).Times(1) |
1717 | .WillOnce(Return(msh::a_surface())); |
1718 | |
1719 | - factory.create_surface(&session, params, mf::SurfaceId(), std::make_shared<mtd::NullEventSink>()); |
1720 | + factory.create_surface(&session, params, observer); |
1721 | } |
1722 | |
1723 | TEST_F(OrganisingSurfaceFactorySetup, forwards_create_surface_parameters_from_placement_strategy_to_underlying_factory) |
1724 | @@ -88,14 +90,13 @@ |
1725 | |
1726 | msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy); |
1727 | |
1728 | - std::shared_ptr<mf::EventSink> sink = std::make_shared<mtd::NullEventSink>(); |
1729 | auto params = msh::a_surface(); |
1730 | auto placed_params = params; |
1731 | placed_params.size.width = geom::Width{100}; |
1732 | |
1733 | EXPECT_CALL(*placement_strategy, place(_, Ref(params))).Times(1) |
1734 | .WillOnce(Return(placed_params)); |
1735 | - EXPECT_CALL(*surface_coordinator, add_surface(mf::SurfaceId(), placed_params, sink)); |
1736 | + EXPECT_CALL(*surface_coordinator, add_surface(placed_params, _)); |
1737 | |
1738 | - factory.create_surface(nullptr, params, mf::SurfaceId(), sink); |
1739 | + factory.create_surface(nullptr, params, observer); |
1740 | } |
Approve a part from:
the name SurfaceEventSource is a bit misleading... on second read: was a but misleading. Now I am only curious whether we need it inside the public headers. Would someone replacing the scene or extending the surfaces need that implementation? Or would decorating the surface factory be sufficient?