Mir

Merge lp:~alan-griffiths/mir/introducing-SurfaceObserver into lp:mir

Proposed by Alan Griffiths
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
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.

To post a comment you must log in.
Revision history for this message
Andreas Pokorny (andreas-pokorny) 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?

review: Needs Information
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

I like this design a lot, +1 from me

review: Approve (api)
Revision history for this message
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).

Revision history for this message
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).

review: Approve
Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
Andreas Pokorny (andreas-pokorny) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/render_surfaces.cpp'
--- examples/render_surfaces.cpp 2014-03-31 11:00:33 +0000
+++ examples/render_surfaces.cpp 2014-03-31 11:00:33 +0000
@@ -466,7 +466,6 @@
466 for (auto& m : moveables)466 for (auto& m : moveables)
467 {467 {
468 auto const s = surface_coordinator->add_surface(468 auto const s = surface_coordinator->add_surface(
469 mf::SurfaceId(),
470 msh::a_surface().of_size(surface_size)469 msh::a_surface().of_size(surface_size)
471 .of_pixel_format(surface_pf)470 .of_pixel_format(surface_pf)
472 .of_buffer_usage(mg::BufferUsage::hardware),471 .of_buffer_usage(mg::BufferUsage::hardware),
473472
=== modified file 'include/server/mir/scene/surface.h'
--- include/server/mir/scene/surface.h 2014-03-25 10:21:00 +0000
+++ include/server/mir/scene/surface.h 2014-03-31 11:00:33 +0000
@@ -29,6 +29,8 @@
2929
30namespace scene30namespace scene
31{31{
32class SurfaceObserver;
33
32class Surface :34class Surface :
33 public graphics::Renderable,35 public graphics::Renderable,
34 public input::Surface,36 public input::Surface,
@@ -47,6 +49,9 @@
47 // TODO cleanest interface for this.49 // TODO cleanest interface for this.
48 virtual std::shared_ptr<input::InputChannel> input_channel() const = 0;50 virtual std::shared_ptr<input::InputChannel> input_channel() const = 0;
49 virtual void on_change(std::function<void()> change_notification) = 0;51 virtual void on_change(std::function<void()> change_notification) = 0;
52
53 virtual void add_observer(std::shared_ptr<SurfaceObserver> const& observer) = 0;
54 virtual void remove_observer(std::shared_ptr<SurfaceObserver> const& observer) = 0;
50};55};
51}56}
52}57}
5358
=== modified file 'include/server/mir/scene/surface_coordinator.h'
--- include/server/mir/scene/surface_coordinator.h 2014-03-31 11:00:33 +0000
+++ include/server/mir/scene/surface_coordinator.h 2014-03-31 11:00:33 +0000
@@ -21,13 +21,11 @@
21#define MIR_SCENE_SURFACE_COORDINATOR_H_21#define MIR_SCENE_SURFACE_COORDINATOR_H_
2222
23#include "mir/scene/surface_ranker.h"23#include "mir/scene/surface_ranker.h"
24#include "mir/frontend/surface_id.h"
2524
26#include <memory>25#include <memory>
2726
28namespace mir27namespace mir
29{28{
30namespace frontend { class EventSink; }
31namespace shell29namespace shell
32{30{
33struct SurfaceCreationParameters;31struct SurfaceCreationParameters;
@@ -36,14 +34,14 @@
36namespace scene34namespace scene
37{35{
38class Surface;36class Surface;
37class SurfaceObserver;
3938
40class SurfaceCoordinator : public SurfaceRanker39class SurfaceCoordinator : public SurfaceRanker
41{40{
42public:41public:
43 virtual std::shared_ptr<Surface> add_surface(42 virtual std::shared_ptr<Surface> add_surface(
44 frontend::SurfaceId id,
45 shell::SurfaceCreationParameters const& params,43 shell::SurfaceCreationParameters const& params,
46 std::shared_ptr<frontend::EventSink> const& event_sink) = 0;44 std::shared_ptr<SurfaceObserver> const& observer) = 0;
4745
48 virtual void remove_surface(std::weak_ptr<Surface> const& surface) = 0;46 virtual void remove_surface(std::weak_ptr<Surface> const& surface) = 0;
49protected:47protected:
5048
=== added file 'include/server/mir/scene/surface_event_source.h'
--- include/server/mir/scene/surface_event_source.h 1970-01-01 00:00:00 +0000
+++ include/server/mir/scene/surface_event_source.h 2014-03-31 11:00:33 +0000
@@ -0,0 +1,49 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#ifndef MIR_SCENE_SURFACE_EVENT_SOURCE_H_
20#define MIR_SCENE_SURFACE_EVENT_SOURCE_H_
21
22#include "mir/scene/surface_observer.h"
23#include "mir/frontend/surface_id.h"
24#include "mir/frontend/event_sink.h"
25
26#include <memory>
27
28namespace mir
29{
30namespace scene
31{
32class SurfaceEventSource : public SurfaceObserver
33{
34public:
35 SurfaceEventSource(
36 frontend::SurfaceId id,
37 std::shared_ptr<frontend::EventSink> const& event_sink);
38
39 void attrib_change(MirSurfaceAttrib attrib, int value);
40 void resize(geometry::Size const& size);
41
42private:
43 frontend::SurfaceId const id;
44 std::shared_ptr<frontend::EventSink> const event_sink;
45};
46}
47}
48
49#endif // MIR_SCENE_SURFACE_EVENT_SOURCE_H_
050
=== modified file 'include/server/mir/scene/surface_factory.h'
--- include/server/mir/scene/surface_factory.h 2014-03-31 11:00:33 +0000
+++ include/server/mir/scene/surface_factory.h 2014-03-31 11:00:33 +0000
@@ -19,14 +19,11 @@
19#ifndef MIR_SCENE_SURFACE_FACTORY_H_19#ifndef MIR_SCENE_SURFACE_FACTORY_H_
20#define MIR_SCENE_SURFACE_FACTORY_H_20#define MIR_SCENE_SURFACE_FACTORY_H_
2121
22#include "mir/frontend/surface_id.h"
23#include "mir/shell/surface_creation_parameters.h"22#include "mir/shell/surface_creation_parameters.h"
24#include <memory>23#include <memory>
25#include <functional>
2624
27namespace mir25namespace mir
28{26{
29namespace frontend { class EventSink; }
30namespace scene27namespace scene
31{28{
32class Surface;29class Surface;
@@ -38,9 +35,8 @@
38 virtual ~SurfaceFactory() = default;35 virtual ~SurfaceFactory() = default;
3936
40 virtual std::shared_ptr<Surface> create_surface(37 virtual std::shared_ptr<Surface> create_surface(
41 frontend::SurfaceId id,38 shell::SurfaceCreationParameters const& params) = 0;
42 shell::SurfaceCreationParameters const& params,39
43 std::shared_ptr<frontend::EventSink> const& event_sink) = 0;
44private:40private:
45 SurfaceFactory(const SurfaceFactory&) = delete;41 SurfaceFactory(const SurfaceFactory&) = delete;
46 SurfaceFactory& operator=(const SurfaceFactory&) = delete;42 SurfaceFactory& operator=(const SurfaceFactory&) = delete;
4743
=== added file 'include/server/mir/scene/surface_observer.h'
--- include/server/mir/scene/surface_observer.h 1970-01-01 00:00:00 +0000
+++ include/server/mir/scene/surface_observer.h 2014-03-31 11:00:33 +0000
@@ -0,0 +1,45 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#ifndef MIR_SCENE_SURFACE_OBSERVER_H_
20#define MIR_SCENE_SURFACE_OBSERVER_H_
21
22#include "mir/geometry/size.h"
23#include "mir_toolkit/common.h"
24
25namespace mir
26{
27namespace scene
28{
29// Initial cut - supporting the frontend requirement, more will follow
30class SurfaceObserver
31{
32public:
33 virtual void attrib_change(MirSurfaceAttrib attrib, int value) = 0;
34 virtual void resize(geometry::Size const& size) = 0;
35
36protected:
37 SurfaceObserver() = default;
38 virtual ~SurfaceObserver() = default;
39 SurfaceObserver(SurfaceObserver const&) = delete;
40 SurfaceObserver& operator=(SurfaceObserver const&) = delete;
41};
42}
43}
44
45#endif // MIR_SCENE_SURFACE_OBSERVER_H_
046
=== modified file 'include/server/mir/shell/surface_factory.h'
--- include/server/mir/shell/surface_factory.h 2014-03-25 17:04:27 +0000
+++ include/server/mir/shell/surface_factory.h 2014-03-31 11:00:33 +0000
@@ -19,15 +19,12 @@
19#ifndef MIR_SHELL_SURFACE_FACTORY_H_19#ifndef MIR_SHELL_SURFACE_FACTORY_H_
20#define MIR_SHELL_SURFACE_FACTORY_H_20#define MIR_SHELL_SURFACE_FACTORY_H_
2121
22#include "mir/frontend/surface_id.h"
23#include <memory>22#include <memory>
2423
25namespace mir24namespace mir
26{25{
27namespace frontend26namespace scene { class SurfaceObserver; }
28{27
29class EventSink;
30}
31namespace shell28namespace shell
32{29{
33class Session;30class Session;
@@ -40,8 +37,7 @@
40 virtual std::shared_ptr<Surface> create_surface(37 virtual std::shared_ptr<Surface> create_surface(
41 Session* session,38 Session* session,
42 SurfaceCreationParameters const& params,39 SurfaceCreationParameters const& params,
43 frontend::SurfaceId id,40 std::shared_ptr<scene::SurfaceObserver> const& observer) = 0;
44 std::shared_ptr<frontend::EventSink> const& sink) = 0;
4541
46 virtual void destroy_surface(std::shared_ptr<Surface> const& surface) = 0;42 virtual void destroy_surface(std::shared_ptr<Surface> const& surface) = 0;
4743
4844
=== modified file 'include/test/mir_test_doubles/mock_surface.h'
--- include/test/mir_test_doubles/mock_surface.h 2014-03-26 14:20:14 +0000
+++ include/test/mir_test_doubles/mock_surface.h 2014-03-31 11:00:33 +0000
@@ -35,14 +35,12 @@
35{35{
36 MockSurface() :36 MockSurface() :
37 scene::BasicSurface(37 scene::BasicSurface(
38 frontend::SurfaceId{},
39 {},38 {},
40 {{},{}},39 {{},{}},
41 true,40 true,
42 {},41 {},
43 {},42 {},
44 {},43 {},
45 {},
46 mir::report::null_scene_report())44 mir::report::null_scene_report())
47 {45 {
48 }46 }
@@ -65,6 +63,7 @@
6563
66 MOCK_METHOD2(configure, int(MirSurfaceAttrib, int));64 MOCK_METHOD2(configure, int(MirSurfaceAttrib, int));
67 MOCK_METHOD1(take_input_focus, void(std::shared_ptr<shell::InputTargeter> const&));65 MOCK_METHOD1(take_input_focus, void(std::shared_ptr<shell::InputTargeter> const&));
66 MOCK_METHOD1(add_observer, void(std::shared_ptr<scene::SurfaceObserver> const&));
68};67};
6968
70}69}
7170
=== modified file 'include/test/mir_test_doubles/mock_surface_factory.h'
--- include/test/mir_test_doubles/mock_surface_factory.h 2014-03-24 17:30:12 +0000
+++ include/test/mir_test_doubles/mock_surface_factory.h 2014-03-31 11:00:33 +0000
@@ -33,11 +33,10 @@
3333
34struct MockSurfaceFactory : public shell::SurfaceFactory34struct MockSurfaceFactory : public shell::SurfaceFactory
35{35{
36 MOCK_METHOD4(create_surface, std::shared_ptr<shell::Surface>(36 MOCK_METHOD3(create_surface, std::shared_ptr<shell::Surface>(
37 shell::Session*,37 shell::Session*,
38 const shell::SurfaceCreationParameters&,38 const shell::SurfaceCreationParameters&,
39 frontend::SurfaceId,39 std::shared_ptr<scene::SurfaceObserver> const&));
40 std::shared_ptr<frontend::EventSink> const&));
4140
42 void destroy_surface(std::shared_ptr<shell::Surface> const& /*surface*/) override {}41 void destroy_surface(std::shared_ptr<shell::Surface> const& /*surface*/) override {}
43};42};
4443
=== modified file 'src/server/scene/CMakeLists.txt'
--- src/server/scene/CMakeLists.txt 2014-03-31 11:00:33 +0000
+++ src/server/scene/CMakeLists.txt 2014-03-31 11:00:33 +0000
@@ -13,5 +13,6 @@
13 surface_allocator.cpp13 surface_allocator.cpp
14 surface_stack.cpp14 surface_stack.cpp
15 surface_controller.cpp15 surface_controller.cpp
16 surface_event_source.cpp
16 threaded_snapshot_strategy.cpp17 threaded_snapshot_strategy.cpp
17)18)
1819
=== modified file 'src/server/scene/application_session.cpp'
--- src/server/scene/application_session.cpp 2014-03-26 13:02:43 +0000
+++ src/server/scene/application_session.cpp 2014-03-31 11:00:33 +0000
@@ -18,6 +18,7 @@
1818
19#include "application_session.h"19#include "application_session.h"
20#include "mir/shell/surface.h"20#include "mir/shell/surface.h"
21#include "mir/scene/surface_event_source.h"
21#include "mir/shell/surface_factory.h"22#include "mir/shell/surface_factory.h"
22#include "snapshot_strategy.h"23#include "snapshot_strategy.h"
23#include "mir/shell/session_listener.h"24#include "mir/shell/session_listener.h"
@@ -71,7 +72,9 @@
71mf::SurfaceId ms::ApplicationSession::create_surface(const msh::SurfaceCreationParameters& params)72mf::SurfaceId ms::ApplicationSession::create_surface(const msh::SurfaceCreationParameters& params)
72{73{
73 auto const id = next_id();74 auto const id = next_id();
74 auto surf = surface_factory->create_surface(this, params, id, event_sink);75
76 auto const observer = std::make_shared<scene::SurfaceEventSource>(id, event_sink);
77 auto surf = surface_factory->create_surface(this, params, observer);
7578
76 std::unique_lock<std::mutex> lock(surfaces_mutex);79 std::unique_lock<std::mutex> lock(surfaces_mutex);
77 surfaces[id] = surf;80 surfaces[id] = surf;
7881
=== modified file 'src/server/scene/basic_surface.cpp'
--- src/server/scene/basic_surface.cpp 2014-03-26 14:20:14 +0000
+++ src/server/scene/basic_surface.cpp 2014-03-31 11:00:33 +0000
@@ -31,7 +31,7 @@
31#include <boost/throw_exception.hpp>31#include <boost/throw_exception.hpp>
3232
33#include <stdexcept>33#include <stdexcept>
34#include <cstring>34#include <algorithm>
3535
36namespace mc = mir::compositor;36namespace mc = mir::compositor;
37namespace ms = mir::scene;37namespace ms = mir::scene;
@@ -58,17 +58,45 @@
58 notifier();58 notifier();
59}59}
6060
61void ms::SurfaceObservers::attrib_change(MirSurfaceAttrib attrib, int value)
62{
63 std::unique_lock<decltype(mutex)> lock(mutex);
64 // TBD Maybe we should copy observers so we can release the lock?
65 for (auto const& p : observers)
66 p->attrib_change(attrib, value);
67}
68
69void ms::SurfaceObservers::resize(geometry::Size const& size)
70{
71 std::unique_lock<decltype(mutex)> lock(mutex);
72 // TBD Maybe we should copy observers so we can release the lock?
73 for (auto const& p : observers)
74 p->resize(size);
75}
76
77void ms::SurfaceObservers::add(std::shared_ptr<SurfaceObserver> const& observer)
78{
79 if (observer)
80 {
81 std::unique_lock<decltype(mutex)> lock(mutex);
82 observers.push_back(observer);
83 }
84}
85
86void ms::SurfaceObservers::remove(std::shared_ptr<SurfaceObserver> const& observer)
87{
88 std::unique_lock<decltype(mutex)> lock(mutex);
89 observers.erase(std::remove(observers.begin(),observers.end(), observer), observers.end());
90}
91
61ms::BasicSurface::BasicSurface(92ms::BasicSurface::BasicSurface(
62 frontend::SurfaceId id,
63 std::string const& name,93 std::string const& name,
64 geometry::Rectangle rect,94 geometry::Rectangle rect,
65 bool nonrectangular,95 bool nonrectangular,
66 std::shared_ptr<mc::BufferStream> const& buffer_stream,96 std::shared_ptr<compositor::BufferStream> const& buffer_stream,
67 std::shared_ptr<input::InputChannel> const& input_channel,97 std::shared_ptr<input::InputChannel> const& input_channel,
68 std::shared_ptr<frontend::EventSink> const& event_sink,
69 std::shared_ptr<SurfaceConfigurator> const& configurator,98 std::shared_ptr<SurfaceConfigurator> const& configurator,
70 std::shared_ptr<SceneReport> const& report) :99 std::shared_ptr<SceneReport> const& report) :
71 id(id),
72 notify_change([](){}),100 notify_change([](){}),
73 surface_name(name),101 surface_name(name),
74 surface_rect(rect),102 surface_rect(rect),
@@ -79,7 +107,6 @@
79 input_rectangles{surface_rect},107 input_rectangles{surface_rect},
80 surface_buffer_stream(buffer_stream),108 surface_buffer_stream(buffer_stream),
81 server_input_channel(input_channel),109 server_input_channel(input_channel),
82 event_sink(event_sink),
83 configurator(configurator),110 configurator(configurator),
84 report(report),111 report(report),
85 type_value(mir_surface_type_normal),112 type_value(mir_surface_type_normal),
@@ -222,13 +249,7 @@
222 surface_rect.size = size;249 surface_rect.size = size;
223 }250 }
224 notify_change();251 notify_change();
225 MirEvent e;252 observers.resize(size);
226 memset(&e, 0, sizeof e);
227 e.type = mir_event_type_resize;
228 e.resize.surface_id = id.as_value();
229 e.resize.width = size.width.as_int();
230 e.resize.height = size.height.as_int();
231 event_sink->handle_event(e);
232}253}
233254
234geom::Point ms::BasicSurface::top_left() const255geom::Point ms::BasicSurface::top_left() const
@@ -363,29 +384,12 @@
363 state_value = s;384 state_value = s;
364 valid = true;385 valid = true;
365386
366 notify_attrib_change(mir_surface_attrib_state, s);387 observers.attrib_change(mir_surface_attrib_state, s);
367 }388 }
368389
369 return valid;390 return valid;
370}391}
371392
372void ms::BasicSurface::notify_attrib_change(MirSurfaceAttrib attrib, int value)
373{
374 MirEvent e;
375
376 // This memset is not really required. However it does avoid some
377 // harmless uninitialized memory reads that valgrind will complain
378 // about, due to gaps in MirEvent.
379 memset(&e, 0, sizeof e);
380
381 e.type = mir_event_type_surface;
382 e.surface.id = id.as_value();
383 e.surface.attrib = attrib;
384 e.surface.value = value;
385
386 event_sink->handle_event(e);
387}
388
389void ms::BasicSurface::take_input_focus(std::shared_ptr<msh::InputTargeter> const& targeter)393void ms::BasicSurface::take_input_focus(std::shared_ptr<msh::InputTargeter> const& targeter)
390{394{
391 targeter->focus_changed(input_channel());395 targeter->focus_changed(input_channel());
@@ -415,7 +419,7 @@
415 result = state();419 result = state();
416 break;420 break;
417 case mir_surface_attrib_focus:421 case mir_surface_attrib_focus:
418 notify_attrib_change(attrib, value);422 observers.attrib_change(attrib, value);
419 break;423 break;
420 case mir_surface_attrib_swapinterval:424 case mir_surface_attrib_swapinterval:
421 allow_dropping = (value == 0);425 allow_dropping = (value == 0);
@@ -443,3 +447,13 @@
443 set_hidden(false);447 set_hidden(false);
444}448}
445449
450
451void ms::BasicSurface::add_observer(std::shared_ptr<SurfaceObserver> const& observer)
452{
453 observers.add(observer);
454}
455
456void ms::BasicSurface::remove_observer(std::shared_ptr<SurfaceObserver> const& observer)
457{
458 observers.remove(observer);
459}
446460
=== modified file 'src/server/scene/basic_surface.h'
--- src/server/scene/basic_surface.h 2014-03-26 14:20:14 +0000
+++ src/server/scene/basic_surface.h 2014-03-31 11:00:33 +0000
@@ -20,8 +20,8 @@
20#define MIR_SCENE_BASIC_SURFACE_H_20#define MIR_SCENE_BASIC_SURFACE_H_
2121
22#include "mir/scene/surface.h"22#include "mir/scene/surface.h"
23#include "mir/scene/surface_observer.h"
2324
24#include "mir/frontend/surface_id.h"
25#include "mir/geometry/rectangle.h"25#include "mir/geometry/rectangle.h"
2626
27#include "mir_toolkit/common.h"27#include "mir_toolkit/common.h"
@@ -71,17 +71,30 @@
71 std::function<void()> notify_change;71 std::function<void()> notify_change;
72};72};
7373
74class SurfaceObservers : public SurfaceObserver
75{
76public:
77
78 void attrib_change(MirSurfaceAttrib attrib, int value) override;
79 void resize(geometry::Size const& size) override;
80
81 void add(std::shared_ptr<SurfaceObserver> const& observer);
82 void remove(std::shared_ptr<SurfaceObserver> const& observer);
83
84private:
85 std::mutex mutex;
86 std::vector<std::shared_ptr<SurfaceObserver>> observers;
87};
88
74class BasicSurface : public Surface89class BasicSurface : public Surface
75{90{
76public:91public:
77 BasicSurface(92 BasicSurface(
78 frontend::SurfaceId id,
79 std::string const& name,93 std::string const& name,
80 geometry::Rectangle rect,94 geometry::Rectangle rect,
81 bool nonrectangular,95 bool nonrectangular,
82 std::shared_ptr<compositor::BufferStream> const& buffer_stream,96 std::shared_ptr<compositor::BufferStream> const& buffer_stream,
83 std::shared_ptr<input::InputChannel> const& input_channel,97 std::shared_ptr<input::InputChannel> const& input_channel,
84 std::shared_ptr<frontend::EventSink> const& event_sink,
85 std::shared_ptr<SurfaceConfigurator> const& configurator,98 std::shared_ptr<SurfaceConfigurator> const& configurator,
86 std::shared_ptr<SceneReport> const& report);99 std::shared_ptr<SceneReport> const& report);
87100
@@ -136,13 +149,15 @@
136 void hide() override;149 void hide() override;
137 void show() override;150 void show() override;
138151
152 void add_observer(std::shared_ptr<SurfaceObserver> const& observer) override;
153 void remove_observer(std::shared_ptr<SurfaceObserver> const& observer) override;
154
139private:155private:
140 bool set_type(MirSurfaceType t); // Use configure() to make public changes156 bool set_type(MirSurfaceType t); // Use configure() to make public changes
141 bool set_state(MirSurfaceState s);157 bool set_state(MirSurfaceState s);
142 void notify_attrib_change(MirSurfaceAttrib attrib, int value);
143158
159 SurfaceObservers observers;
144 std::mutex mutable guard;160 std::mutex mutable guard;
145 frontend::SurfaceId const id;
146 ThreadsafeCallback notify_change;161 ThreadsafeCallback notify_change;
147 std::string const surface_name;162 std::string const surface_name;
148 geometry::Rectangle surface_rect;163 geometry::Rectangle surface_rect;
@@ -154,7 +169,6 @@
154 std::vector<geometry::Rectangle> input_rectangles;169 std::vector<geometry::Rectangle> input_rectangles;
155 std::shared_ptr<compositor::BufferStream> const surface_buffer_stream;170 std::shared_ptr<compositor::BufferStream> const surface_buffer_stream;
156 std::shared_ptr<input::InputChannel> const server_input_channel;171 std::shared_ptr<input::InputChannel> const server_input_channel;
157 std::shared_ptr<frontend::EventSink> const event_sink;
158 std::shared_ptr<SurfaceConfigurator> const configurator;172 std::shared_ptr<SurfaceConfigurator> const configurator;
159 std::shared_ptr<SceneReport> const report;173 std::shared_ptr<SceneReport> const report;
160174
161175
=== modified file 'src/server/scene/surface_allocator.cpp'
--- src/server/scene/surface_allocator.cpp 2014-03-26 14:20:14 +0000
+++ src/server/scene/surface_allocator.cpp 2014-03-31 11:00:33 +0000
@@ -48,9 +48,7 @@
48}48}
4949
50std::shared_ptr<ms::Surface> ms::SurfaceAllocator::create_surface(50std::shared_ptr<ms::Surface> ms::SurfaceAllocator::create_surface(
51 frontend::SurfaceId id,51 shell::SurfaceCreationParameters const& params)
52 msh::SurfaceCreationParameters const& params,
53 std::shared_ptr<frontend::EventSink> const& event_sink)
54{52{
55 mg::BufferProperties buffer_properties{params.size,53 mg::BufferProperties buffer_properties{params.size,
56 params.pixel_format,54 params.pixel_format,
@@ -60,14 +58,14 @@
6058
61 bool nonrectangular = has_alpha(params.pixel_format);59 bool nonrectangular = has_alpha(params.pixel_format);
62 auto input_channel = input_factory->make_input_channel();60 auto input_channel = input_factory->make_input_channel();
63 return std::make_shared<BasicSurface>(61 auto const surface = std::make_shared<BasicSurface>(
64 id,
65 params.name,62 params.name,
66 actual_size,63 actual_size,
67 nonrectangular,64 nonrectangular,
68 buffer_stream,65 buffer_stream,
69 input_channel,66 input_channel,
70 event_sink,
71 configurator,67 configurator,
72 report);68 report);
69
70 return surface;
73}71}
7472
=== modified file 'src/server/scene/surface_allocator.h'
--- src/server/scene/surface_allocator.h 2014-03-31 11:00:33 +0000
+++ src/server/scene/surface_allocator.h 2014-03-31 11:00:33 +0000
@@ -42,9 +42,7 @@
42 std::shared_ptr<SceneReport> const& report);42 std::shared_ptr<SceneReport> const& report);
4343
44 std::shared_ptr<Surface> create_surface(44 std::shared_ptr<Surface> create_surface(
45 frontend::SurfaceId id,45 shell::SurfaceCreationParameters const& params) override;
46 shell::SurfaceCreationParameters const& params,
47 std::shared_ptr<frontend::EventSink> const& event_sink) override;
4846
49private:47private:
50 std::shared_ptr<BufferStreamFactory> const buffer_stream_factory;48 std::shared_ptr<BufferStreamFactory> const buffer_stream_factory;
5149
=== modified file 'src/server/scene/surface_controller.cpp'
--- src/server/scene/surface_controller.cpp 2014-03-31 11:00:33 +0000
+++ src/server/scene/surface_controller.cpp 2014-03-31 11:00:33 +0000
@@ -19,6 +19,7 @@
19#include "surface_controller.h"19#include "surface_controller.h"
20#include "surface_stack_model.h"20#include "surface_stack_model.h"
21#include "mir/scene/surface_factory.h"21#include "mir/scene/surface_factory.h"
22#include "mir/scene/surface.h"
2223
23namespace ms = mir::scene;24namespace ms = mir::scene;
24namespace msh = mir::shell;25namespace msh = mir::shell;
@@ -32,11 +33,11 @@
32}33}
3334
34std::shared_ptr<ms::Surface> ms::SurfaceController::add_surface(35std::shared_ptr<ms::Surface> ms::SurfaceController::add_surface(
35 frontend::SurfaceId id,
36 shell::SurfaceCreationParameters const& params,36 shell::SurfaceCreationParameters const& params,
37 std::shared_ptr<frontend::EventSink> const& event_sink)37 std::shared_ptr<SurfaceObserver> const& observer)
38{38{
39 auto const surface = surface_factory->create_surface(id, params, event_sink);39 auto const surface = surface_factory->create_surface(params);
40 surface->add_observer(observer);
40 surface_stack->add_surface(surface, params.depth, params.input_mode);41 surface_stack->add_surface(surface, params.depth, params.input_mode);
41 return surface;42 return surface;
42}43}
4344
=== modified file 'src/server/scene/surface_controller.h'
--- src/server/scene/surface_controller.h 2014-03-31 11:00:33 +0000
+++ src/server/scene/surface_controller.h 2014-03-31 11:00:33 +0000
@@ -24,11 +24,6 @@
2424
25namespace mir25namespace mir
26{26{
27namespace shell
28{
29class Session;
30}
31
32namespace scene27namespace scene
33{28{
34class SurfaceStackModel;29class SurfaceStackModel;
@@ -43,9 +38,8 @@
43 std::shared_ptr<SurfaceStackModel> const& surface_stack);38 std::shared_ptr<SurfaceStackModel> const& surface_stack);
4439
45 std::shared_ptr<Surface> add_surface(40 std::shared_ptr<Surface> add_surface(
46 frontend::SurfaceId id,
47 shell::SurfaceCreationParameters const& params,41 shell::SurfaceCreationParameters const& params,
48 std::shared_ptr<frontend::EventSink> const& event_sink) override;42 std::shared_ptr<SurfaceObserver> const& observer) override;
4943
50 void remove_surface(std::weak_ptr<Surface> const& surface) override;44 void remove_surface(std::weak_ptr<Surface> const& surface) override;
5145
5246
=== added file 'src/server/scene/surface_event_source.cpp'
--- src/server/scene/surface_event_source.cpp 1970-01-01 00:00:00 +0000
+++ src/server/scene/surface_event_source.cpp 2014-03-31 11:00:33 +0000
@@ -0,0 +1,62 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#include "mir/scene/surface_event_source.h"
20
21#include <cstring>
22#include <algorithm>
23
24namespace ms = mir::scene;
25namespace geom = mir::geometry;
26
27ms::SurfaceEventSource::SurfaceEventSource(
28 frontend::SurfaceId id,
29 std::shared_ptr<frontend::EventSink> const& event_sink) :
30 id(id),
31 event_sink(event_sink)
32{
33}
34
35void ms::SurfaceEventSource::resize(geom::Size const& size)
36{
37 MirEvent e;
38 memset(&e, 0, sizeof e);
39 e.type = mir_event_type_resize;
40 e.resize.surface_id = id.as_value();
41 e.resize.width = size.width.as_int();
42 e.resize.height = size.height.as_int();
43 event_sink->handle_event(e);
44}
45
46
47void ms::SurfaceEventSource::attrib_change(MirSurfaceAttrib attrib, int value)
48{
49 MirEvent e;
50
51 // This memset is not really required. However it does avoid some
52 // harmless uninitialized memory reads that valgrind will complain
53 // about, due to gaps in MirEvent.
54 memset(&e, 0, sizeof e);
55
56 e.type = mir_event_type_surface;
57 e.surface.id = id.as_value();
58 e.surface.attrib = attrib;
59 e.surface.value = value;
60
61 event_sink->handle_event(e);
62}
063
=== modified file 'src/server/shell/organising_surface_factory.cpp'
--- src/server/shell/organising_surface_factory.cpp 2014-03-31 11:00:33 +0000
+++ src/server/shell/organising_surface_factory.cpp 2014-03-31 11:00:33 +0000
@@ -42,13 +42,12 @@
4242
43std::shared_ptr<msh::Surface> msh::OrganisingSurfaceFactory::create_surface(43std::shared_ptr<msh::Surface> msh::OrganisingSurfaceFactory::create_surface(
44 Session* session,44 Session* session,
45 shell::SurfaceCreationParameters const& params,45 SurfaceCreationParameters const& params,
46 frontend::SurfaceId id,46 std::shared_ptr<scene::SurfaceObserver> const& observer)
47 std::shared_ptr<mf::EventSink> const& sender)
48{47{
49 auto placed_params = placement_strategy->place(*session, params);48 auto placed_params = placement_strategy->place(*session, params);
5049
51 return surface_coordinator->add_surface(id, placed_params, sender);50 return surface_coordinator->add_surface(placed_params, observer);
52}51}
5352
54void msh::OrganisingSurfaceFactory::destroy_surface(std::shared_ptr<Surface> const& surface)53void msh::OrganisingSurfaceFactory::destroy_surface(std::shared_ptr<Surface> const& surface)
5554
=== modified file 'src/server/shell/organising_surface_factory.h'
--- src/server/shell/organising_surface_factory.h 2014-03-31 11:00:33 +0000
+++ src/server/shell/organising_surface_factory.h 2014-03-31 11:00:33 +0000
@@ -41,9 +41,8 @@
4141
42 std::shared_ptr<Surface> create_surface(42 std::shared_ptr<Surface> create_surface(
43 Session* session,43 Session* session,
44 shell::SurfaceCreationParameters const& params,44 SurfaceCreationParameters const& params,
45 frontend::SurfaceId id,45 std::shared_ptr<scene::SurfaceObserver> const& observer) override;
46 std::shared_ptr<frontend::EventSink> const& sink) override;
4746
48 void destroy_surface(std::shared_ptr<Surface> const& surface) override;47 void destroy_surface(std::shared_ptr<Surface> const& surface) override;
4948
5049
=== modified file 'tests/acceptance-tests/test_client_input.cpp'
--- tests/acceptance-tests/test_client_input.cpp 2014-03-26 14:20:14 +0000
+++ tests/acceptance-tests/test_client_input.cpp 2014-03-31 11:00:33 +0000
@@ -335,12 +335,12 @@
335 {335 {
336 }336 }
337337
338 std::shared_ptr<msh::Surface> create_surface(msh::Session* session,338 std::shared_ptr<msh::Surface> create_surface(
339 msh::SurfaceCreationParameters const& params,339 msh::Session* session,
340 mf::SurfaceId id,340 msh::SurfaceCreationParameters const& params,
341 std::shared_ptr<mf::EventSink> const& sink)341 std::shared_ptr<ms::SurfaceObserver> const& observer) override
342 {342 {
343 auto surface = underlying_factory->create_surface(session, params, id, sink);343 auto surface = underlying_factory->create_surface(session, params, observer);
344344
345 surface->set_input_region(input_rectangles);345 surface->set_input_region(input_rectangles);
346346
347347
=== modified file 'tests/integration-tests/graphics/android/test_internal_client.cpp'
--- tests/integration-tests/graphics/android/test_internal_client.cpp 2014-03-31 11:00:33 +0000
+++ tests/integration-tests/graphics/android/test_internal_client.cpp 2014-03-31 11:00:33 +0000
@@ -33,6 +33,7 @@
33#include "mir/scene/scene_report.h"33#include "mir/scene/scene_report.h"
34#include "src/server/scene/surface_allocator.h"34#include "src/server/scene/surface_allocator.h"
35#include "mir/scene/surface.h"35#include "mir/scene/surface.h"
36#include "mir/scene/surface_event_source.h"
36#include "mir/shell/surface_creation_parameters.h"37#include "mir/shell/surface_creation_parameters.h"
37#include "mir/frontend/surface_id.h"38#include "mir/frontend/surface_id.h"
38#include "mir/input/input_channel_factory.h"39#include "mir/input/input_channel_factory.h"
@@ -98,7 +99,8 @@
98 auto surface_allocator = std::make_shared<ms::SurfaceAllocator>(buffer_stream_factory, stub_input_factory, std::make_shared<mtd::NullSurfaceConfigurator>(), scene_report);99 auto surface_allocator = std::make_shared<ms::SurfaceAllocator>(buffer_stream_factory, stub_input_factory, std::make_shared<mtd::NullSurfaceConfigurator>(), scene_report);
99 auto ss = std::make_shared<ms::SurfaceStack>(stub_input_registrar, scene_report);100 auto ss = std::make_shared<ms::SurfaceStack>(stub_input_registrar, scene_report);
100 auto surface_controller = std::make_shared<ms::SurfaceController>(surface_allocator, ss);101 auto surface_controller = std::make_shared<ms::SurfaceController>(surface_allocator, ss);
101 auto surface = surface_controller->add_surface(id, params, std::shared_ptr<mf::EventSink>());102 auto const observer = std::make_shared<ms::SurfaceEventSource>(id, std::shared_ptr<mf::EventSink>());
103 auto surface = surface_controller->add_surface(params, observer);
102 surface->allow_framedropping(true);104 surface->allow_framedropping(true);
103 auto mir_surface = as_internal_surface(surface);105 auto mir_surface = as_internal_surface(surface);
104106
105107
=== modified file 'tests/integration-tests/test_session_manager.cpp'
--- tests/integration-tests/test_session_manager.cpp 2014-03-06 06:05:17 +0000
+++ tests/integration-tests/test_session_manager.cpp 2014-03-31 11:00:33 +0000
@@ -60,7 +60,7 @@
6060
61 }61 }
6262
63 mtd::MockSurfaceFactory surface_factory;63 mtd::MockSurfaceFactory surface_factory; // TODO this isn't used as a mock
64 ms::DefaultSessionContainer container;64 ms::DefaultSessionContainer container;
65 mtd::MockFocusSetter focus_setter;65 mtd::MockFocusSetter focus_setter;
66 std::shared_ptr<mf::Session> new_session;66 std::shared_ptr<mf::Session> new_session;
6767
=== modified file 'tests/unit-tests/scene/test_application_session.cpp'
--- tests/unit-tests/scene/test_application_session.cpp 2014-03-31 11:00:33 +0000
+++ tests/unit-tests/scene/test_application_session.cpp 2014-03-31 11:00:33 +0000
@@ -84,7 +84,7 @@
84 mtd::NullEventSink sender;84 mtd::NullEventSink sender;
85 mtd::MockSurfaceFactory surface_factory;85 mtd::MockSurfaceFactory surface_factory;
8686
87 EXPECT_CALL(surface_factory, create_surface(_, _, _, _))87 EXPECT_CALL(surface_factory, create_surface(_, _, _))
88 .WillOnce(Return(mock_surface));88 .WillOnce(Return(mock_surface));
8989
90 mtd::MockSessionListener listener;90 mtd::MockSessionListener listener;
@@ -115,9 +115,9 @@
115115
116 mtd::NullEventSink sender;116 mtd::NullEventSink sender;
117 mtd::MockSurfaceFactory surface_factory;117 mtd::MockSurfaceFactory surface_factory;
118 ON_CALL(surface_factory, create_surface(_,_,_,_)).WillByDefault(Return(mock_surface));118 ON_CALL(surface_factory, create_surface(_,_,_)).WillByDefault(Return(mock_surface));
119119
120 EXPECT_CALL(surface_factory, create_surface(_, _, _, _));120 EXPECT_CALL(surface_factory, create_surface(_, _, _));
121121
122 mtd::MockSessionListener listener;122 mtd::MockSessionListener listener;
123 EXPECT_CALL(listener, surface_created(_, _)).Times(1);123 EXPECT_CALL(listener, surface_created(_, _)).Times(1);
@@ -146,11 +146,11 @@
146146
147 {147 {
148 InSequence seq;148 InSequence seq;
149 EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1)149 EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1)
150 .WillOnce(Return(make_mock_surface()));150 .WillOnce(Return(make_mock_surface()));
151 EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1)151 EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1)
152 .WillOnce(Return(make_mock_surface()));152 .WillOnce(Return(make_mock_surface()));
153 EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1)153 EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1)
154 .WillOnce(Return(make_mock_surface()));154 .WillOnce(Return(make_mock_surface()));
155 }155 }
156156
@@ -189,7 +189,7 @@
189 auto mock_surface = make_mock_surface();189 auto mock_surface = make_mock_surface();
190190
191 mtd::MockSurfaceFactory surface_factory;191 mtd::MockSurfaceFactory surface_factory;
192 ON_CALL(surface_factory, create_surface(_, _, _, _)).WillByDefault(Return(mock_surface));192 ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault(Return(mock_surface));
193193
194 ms::ApplicationSession app_session(194 ms::ApplicationSession app_session(
195 mt::fake_shared(surface_factory),195 mt::fake_shared(surface_factory),
@@ -199,7 +199,7 @@
199 std::make_shared<msh::NullSessionListener>(),199 std::make_shared<msh::NullSessionListener>(),
200 mt::fake_shared(sender));200 mt::fake_shared(sender));
201201
202 EXPECT_CALL(surface_factory, create_surface(_, _, _, _));202 EXPECT_CALL(surface_factory, create_surface(_, _, _));
203203
204 {204 {
205 InSequence seq;205 InSequence seq;
@@ -269,7 +269,7 @@
269 std::static_pointer_cast<msh::SurfaceBufferAccess>(default_surface);269 std::static_pointer_cast<msh::SurfaceBufferAccess>(default_surface);
270 auto const snapshot_strategy = std::make_shared<MockSnapshotStrategy>();270 auto const snapshot_strategy = std::make_shared<MockSnapshotStrategy>();
271271
272 EXPECT_CALL(surface_factory, create_surface(_,_,_,_))272 EXPECT_CALL(surface_factory, create_surface(_,_,_))
273 .WillOnce(Return(default_surface));273 .WillOnce(Return(default_surface));
274274
275 EXPECT_CALL(*snapshot_strategy,275 EXPECT_CALL(*snapshot_strategy,
276276
=== modified file 'tests/unit-tests/scene/test_basic_surface.cpp'
--- tests/unit-tests/scene/test_basic_surface.cpp 2014-03-26 14:20:14 +0000
+++ tests/unit-tests/scene/test_basic_surface.cpp 2014-03-31 11:00:33 +0000
@@ -85,7 +85,6 @@
85 std::function<void()> mock_change_cb;85 std::function<void()> mock_change_cb;
86 std::shared_ptr<testing::NiceMock<mtd::MockBufferStream>> mock_buffer_stream =86 std::shared_ptr<testing::NiceMock<mtd::MockBufferStream>> mock_buffer_stream =
87 std::make_shared<testing::NiceMock<mtd::MockBufferStream>>();87 std::make_shared<testing::NiceMock<mtd::MockBufferStream>>();
88 std::shared_ptr<StubEventSink> const stub_event_sink = std::make_shared<StubEventSink>();
89 std::shared_ptr<StubSurfaceConfigurator> const stub_configurator = std::make_shared<StubSurfaceConfigurator>();88 std::shared_ptr<StubSurfaceConfigurator> const stub_configurator = std::make_shared<StubSurfaceConfigurator>();
90 std::shared_ptr<ms::SceneReport> const report = mr::null_scene_report();89 std::shared_ptr<ms::SceneReport> const report = mr::null_scene_report();
91};90};
@@ -95,13 +94,11 @@
95TEST_F(BasicSurfaceTest, basics)94TEST_F(BasicSurfaceTest, basics)
96{95{
97 ms::BasicSurface surface{96 ms::BasicSurface surface{
98 mf::SurfaceId(),
99 name,97 name,
100 rect,98 rect,
101 false,99 false,
102 mock_buffer_stream,100 mock_buffer_stream,
103 std::shared_ptr<mi::InputChannel>(),101 std::shared_ptr<mi::InputChannel>(),
104 stub_event_sink,
105 stub_configurator,102 stub_configurator,
106 report};103 report};
107104
@@ -117,13 +114,11 @@
117 .Times(1);114 .Times(1);
118115
119 ms::BasicSurface surface{116 ms::BasicSurface surface{
120 mf::SurfaceId(),
121 name,117 name,
122 rect,118 rect,
123 false,119 false,
124 mock_buffer_stream,120 mock_buffer_stream,
125 std::shared_ptr<mi::InputChannel>(),121 std::shared_ptr<mi::InputChannel>(),
126 stub_event_sink,
127 stub_configurator,122 stub_configurator,
128 report};123 report};
129124
@@ -144,13 +139,11 @@
144 .Times(1);139 .Times(1);
145140
146 ms::BasicSurface surface{141 ms::BasicSurface surface{
147 mf::SurfaceId(),
148 name,142 name,
149 rect,143 rect,
150 false,144 false,
151 mock_buffer_stream,145 mock_buffer_stream,
152 std::shared_ptr<mi::InputChannel>(),146 std::shared_ptr<mi::InputChannel>(),
153 stub_event_sink,
154 stub_configurator,147 stub_configurator,
155 report};148 report};
156149
@@ -173,13 +166,11 @@
173 .Times(1);166 .Times(1);
174167
175 ms::BasicSurface surface{168 ms::BasicSurface surface{
176 mf::SurfaceId(),
177 name,169 name,
178 rect,170 rect,
179 false,171 false,
180 mock_buffer_stream,172 mock_buffer_stream,
181 std::shared_ptr<mi::InputChannel>(),173 std::shared_ptr<mi::InputChannel>(),
182 stub_event_sink,
183 stub_configurator,174 stub_configurator,
184 report};175 report};
185176
@@ -204,13 +195,11 @@
204 .Times(1);195 .Times(1);
205196
206 ms::BasicSurface surface{197 ms::BasicSurface surface{
207 mf::SurfaceId(),
208 name,198 name,
209 rect,199 rect,
210 false,200 false,
211 mock_buffer_stream,201 mock_buffer_stream,
212 std::shared_ptr<mi::InputChannel>(),202 std::shared_ptr<mi::InputChannel>(),
213 stub_event_sink,
214 stub_configurator,203 stub_configurator,
215 report};204 report};
216205
@@ -225,13 +214,11 @@
225{214{
226 using namespace testing;215 using namespace testing;
227 ms::BasicSurface surface{216 ms::BasicSurface surface{
228 mf::SurfaceId(),
229 name,217 name,
230 rect,218 rect,
231 false,219 false,
232 mock_buffer_stream,220 mock_buffer_stream,
233 std::shared_ptr<mi::InputChannel>(),221 std::shared_ptr<mi::InputChannel>(),
234 stub_event_sink,
235 stub_configurator,222 stub_configurator,
236 report};223 report};
237224
@@ -242,13 +229,11 @@
242TEST_F(BasicSurfaceTest, test_surface_should_be_rendered_in)229TEST_F(BasicSurfaceTest, test_surface_should_be_rendered_in)
243{230{
244 ms::BasicSurface surface{231 ms::BasicSurface surface{
245 mf::SurfaceId(),
246 name,232 name,
247 rect,233 rect,
248 false,234 false,
249 mock_buffer_stream,235 mock_buffer_stream,
250 std::shared_ptr<mi::InputChannel>(),236 std::shared_ptr<mi::InputChannel>(),
251 stub_event_sink,
252 stub_configurator,237 stub_configurator,
253 report};238 report};
254239
@@ -281,13 +266,11 @@
281 .Times(1);266 .Times(1);
282267
283 ms::BasicSurface surface{268 ms::BasicSurface surface{
284 mf::SurfaceId(),
285 name,269 name,
286 rect,270 rect,
287 false,271 false,
288 mock_buffer_stream,272 mock_buffer_stream,
289 std::shared_ptr<mi::InputChannel>(),273 std::shared_ptr<mi::InputChannel>(),
290 stub_event_sink,
291 stub_configurator,274 stub_configurator,
292 report};275 report};
293276
@@ -303,13 +286,11 @@
303 .Times(1);286 .Times(1);
304287
305 ms::BasicSurface surface{288 ms::BasicSurface surface{
306 mf::SurfaceId(),
307 name,289 name,
308 rect,290 rect,
309 false,291 false,
310 mock_buffer_stream,292 mock_buffer_stream,
311 std::shared_ptr<mi::InputChannel>(),293 std::shared_ptr<mi::InputChannel>(),
312 stub_event_sink,
313 stub_configurator,294 stub_configurator,
314 report};295 report};
315296
@@ -324,13 +305,11 @@
324 geom::Point pt(1,1);305 geom::Point pt(1,1);
325 geom::Size one_by_one{geom::Width{1}, geom::Height{1}};306 geom::Size one_by_one{geom::Width{1}, geom::Height{1}};
326 ms::BasicSurface surface{307 ms::BasicSurface surface{
327 mf::SurfaceId(),
328 name,308 name,
329 geom::Rectangle{pt, one_by_one},309 geom::Rectangle{pt, one_by_one},
330 false,310 false,
331 mock_buffer_stream,311 mock_buffer_stream,
332 std::shared_ptr<mi::InputChannel>(),312 std::shared_ptr<mi::InputChannel>(),
333 stub_event_sink,
334 stub_configurator,313 stub_configurator,
335 report};314 report};
336315
@@ -367,13 +346,11 @@
367 };346 };
368347
369 ms::BasicSurface surface{348 ms::BasicSurface surface{
370 mf::SurfaceId(),
371 name,349 name,
372 rect,350 rect,
373 false,351 false,
374 mock_buffer_stream,352 mock_buffer_stream,
375 std::shared_ptr<mi::InputChannel>(),353 std::shared_ptr<mi::InputChannel>(),
376 stub_event_sink,
377 stub_configurator,354 stub_configurator,
378 report};355 report};
379356
380357
=== modified file 'tests/unit-tests/scene/test_session_manager.cpp'
--- tests/unit-tests/scene/test_session_manager.cpp 2014-03-31 11:00:33 +0000
+++ tests/unit-tests/scene/test_session_manager.cpp 2014-03-31 11:00:33 +0000
@@ -85,13 +85,11 @@
85 }85 }
8686
87 std::shared_ptr<ms::Surface> dummy_surface = std::make_shared<ms::BasicSurface>(87 std::shared_ptr<ms::Surface> dummy_surface = std::make_shared<ms::BasicSurface>(
88 mf::SurfaceId(),
89 std::string("stub"),88 std::string("stub"),
90 geom::Rectangle{{},{}},89 geom::Rectangle{{},{}},
91 false,90 false,
92 std::make_shared<mtd::StubBufferStream>(),91 std::make_shared<mtd::StubBufferStream>(),
93 std::shared_ptr<mi::InputChannel>(),92 std::shared_ptr<mi::InputChannel>(),
94 std::shared_ptr<mf::EventSink>(),
95 std::shared_ptr<ms::SurfaceConfigurator>(),93 std::shared_ptr<ms::SurfaceConfigurator>(),
96 mir::report::null_scene_report());94 mir::report::null_scene_report());
97 mtd::MockSurfaceFactory surface_factory;95 mtd::MockSurfaceFactory surface_factory;
@@ -121,9 +119,9 @@
121{119{
122 using namespace ::testing;120 using namespace ::testing;
123121
124 EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1);122 EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1);
125123
126 ON_CALL(surface_factory, create_surface(_, _, _, _)).WillByDefault(124 ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault(
127 Return(dummy_surface));125 Return(dummy_surface));
128126
129 EXPECT_CALL(container, insert_session(_)).Times(1);127 EXPECT_CALL(container, insert_session(_)).Times(1);
@@ -153,7 +151,7 @@
153TEST_F(SessionManagerSetup, create_surface_for_session_forwards_and_then_focuses_session)151TEST_F(SessionManagerSetup, create_surface_for_session_forwards_and_then_focuses_session)
154{152{
155 using namespace ::testing;153 using namespace ::testing;
156 ON_CALL(surface_factory, create_surface(_, _, _, _)).WillByDefault(154 ON_CALL(surface_factory, create_surface(_, _, _)).WillByDefault(
157 Return(dummy_surface));155 Return(dummy_surface));
158156
159 // Once for session creation and once for surface creation157 // Once for session creation and once for surface creation
@@ -161,7 +159,7 @@
161 InSequence seq;159 InSequence seq;
162160
163 EXPECT_CALL(focus_setter, set_focus_to(_)).Times(1); // Session creation161 EXPECT_CALL(focus_setter, set_focus_to(_)).Times(1); // Session creation
164 EXPECT_CALL(surface_factory, create_surface(_, _, _, _)).Times(1);162 EXPECT_CALL(surface_factory, create_surface(_, _, _)).Times(1);
165 EXPECT_CALL(focus_setter, set_focus_to(_)).Times(1); // Post Surface creation163 EXPECT_CALL(focus_setter, set_focus_to(_)).Times(1); // Post Surface creation
166 }164 }
167165
168166
=== modified file 'tests/unit-tests/scene/test_surface.cpp'
--- tests/unit-tests/scene/test_surface.cpp 2014-03-26 14:20:14 +0000
+++ tests/unit-tests/scene/test_surface.cpp 2014-03-31 11:00:33 +0000
@@ -21,6 +21,7 @@
21#include "mir/frontend/event_sink.h"21#include "mir/frontend/event_sink.h"
22#include "mir/shell/surface_creation_parameters.h"22#include "mir/shell/surface_creation_parameters.h"
23#include "mir/scene/surface_configurator.h"23#include "mir/scene/surface_configurator.h"
24#include "mir/scene/surface_event_source.h"
24#include "mir/input/input_channel.h"25#include "mir/input/input_channel.h"
2526
26#include "mir_test_doubles/mock_buffer_stream.h"27#include "mir_test_doubles/mock_buffer_stream.h"
@@ -209,7 +210,6 @@
209 std::function<void()> change_notification;210 std::function<void()> change_notification;
210 int notification_count;211 int notification_count;
211 mtd::StubBuffer stub_buffer;212 mtd::StubBuffer stub_buffer;
212 std::shared_ptr<StubEventSink> const stub_event_sink = std::make_shared<StubEventSink>();
213 std::shared_ptr<StubSurfaceConfigurator> const stub_configurator = std::make_shared<StubSurfaceConfigurator>();213 std::shared_ptr<StubSurfaceConfigurator> const stub_configurator = std::make_shared<StubSurfaceConfigurator>();
214};214};
215215
@@ -219,13 +219,11 @@
219{219{
220 using namespace testing;220 using namespace testing;
221 ms::BasicSurface surf(221 ms::BasicSurface surf(
222 mf::SurfaceId(),
223 surface_name,222 surface_name,
224 rect,223 rect,
225 false,224 false,
226 mock_buffer_stream,225 mock_buffer_stream,
227 std::shared_ptr<mi::InputChannel>(),226 std::shared_ptr<mi::InputChannel>(),
228 stub_event_sink,
229 stub_configurator,227 stub_configurator,
230 report);228 report);
231229
@@ -241,13 +239,11 @@
241TEST_F(SurfaceCreation, test_surface_gets_right_name)239TEST_F(SurfaceCreation, test_surface_gets_right_name)
242{240{
243 ms::BasicSurface surf(241 ms::BasicSurface surf(
244 mf::SurfaceId(),
245 surface_name,242 surface_name,
246 rect,243 rect,
247 false,244 false,
248 mock_buffer_stream,245 mock_buffer_stream,
249 std::shared_ptr<mi::InputChannel>(),246 std::shared_ptr<mi::InputChannel>(),
250 stub_event_sink,
251 stub_configurator,247 stub_configurator,
252 report);248 report);
253249
@@ -257,13 +253,11 @@
257TEST_F(SurfaceCreation, test_surface_queries_state_for_size)253TEST_F(SurfaceCreation, test_surface_queries_state_for_size)
258{254{
259 ms::BasicSurface surf(255 ms::BasicSurface surf(
260 mf::SurfaceId(),
261 surface_name,256 surface_name,
262 rect,257 rect,
263 false,258 false,
264 mock_buffer_stream,259 mock_buffer_stream,
265 std::shared_ptr<mi::InputChannel>(),260 std::shared_ptr<mi::InputChannel>(),
266 stub_event_sink,
267 stub_configurator,261 stub_configurator,
268 report);262 report);
269263
@@ -274,13 +268,11 @@
274{268{
275 using namespace testing;269 using namespace testing;
276 ms::BasicSurface surf(270 ms::BasicSurface surf(
277 mf::SurfaceId(),
278 surface_name,271 surface_name,
279 rect,272 rect,
280 false,273 false,
281 mock_buffer_stream,274 mock_buffer_stream,
282 std::shared_ptr<mi::InputChannel>(),275 std::shared_ptr<mi::InputChannel>(),
283 stub_event_sink,
284 stub_configurator,276 stub_configurator,
285 report);277 report);
286278
@@ -302,13 +294,11 @@
302 mtd::StubBuffer stub_buffer;294 mtd::StubBuffer stub_buffer;
303295
304 ms::BasicSurface surf(296 ms::BasicSurface surf(
305 mf::SurfaceId(),
306 surface_name,297 surface_name,
307 rect,298 rect,
308 false,299 false,
309 mock_buffer_stream,300 mock_buffer_stream,
310 std::shared_ptr<mi::InputChannel>(),301 std::shared_ptr<mi::InputChannel>(),
311 stub_event_sink,
312 stub_configurator,302 stub_configurator,
313 report);303 report);
314304
@@ -324,13 +314,11 @@
324TEST_F(SurfaceCreation, test_surface_gets_top_left)314TEST_F(SurfaceCreation, test_surface_gets_top_left)
325{315{
326 ms::BasicSurface surf(316 ms::BasicSurface surf(
327 mf::SurfaceId(),
328 surface_name,317 surface_name,
329 rect,318 rect,
330 false,319 false,
331 mock_buffer_stream,320 mock_buffer_stream,
332 std::shared_ptr<mi::InputChannel>(),321 std::shared_ptr<mi::InputChannel>(),
333 stub_event_sink,
334 stub_configurator,322 stub_configurator,
335 report);323 report);
336324
@@ -343,13 +331,11 @@
343 geom::Point p{55, 66};331 geom::Point p{55, 66};
344332
345 ms::BasicSurface surf(333 ms::BasicSurface surf(
346 mf::SurfaceId(),
347 surface_name,334 surface_name,
348 rect,335 rect,
349 false,336 false,
350 mock_buffer_stream,337 mock_buffer_stream,
351 std::shared_ptr<mi::InputChannel>(),338 std::shared_ptr<mi::InputChannel>(),
352 stub_event_sink,
353 stub_configurator,339 stub_configurator,
354 report);340 report);
355341
@@ -366,18 +352,19 @@
366 .Times(1);352 .Times(1);
367353
368 auto const mock_event_sink = std::make_shared<MockEventSink>();354 auto const mock_event_sink = std::make_shared<MockEventSink>();
355 auto const observer = std::make_shared<ms::SurfaceEventSource>(mf::SurfaceId(), mock_event_sink);
369356
370 ms::BasicSurface surf(357 ms::BasicSurface surf(
371 mf::SurfaceId(),
372 surface_name,358 surface_name,
373 rect,359 rect,
374 false,360 false,
375 mock_buffer_stream,361 mock_buffer_stream,
376 std::shared_ptr<mi::InputChannel>(),362 std::shared_ptr<mi::InputChannel>(),
377 mock_event_sink,
378 stub_configurator,363 stub_configurator,
379 report);364 report);
380365
366 surf.add_observer(observer);
367
381 ASSERT_THAT(surf.size(), Ne(new_size));368 ASSERT_THAT(surf.size(), Ne(new_size));
382369
383 EXPECT_CALL(*mock_event_sink, handle_event(_)).Times(1);370 EXPECT_CALL(*mock_event_sink, handle_event(_)).Times(1);
@@ -390,18 +377,19 @@
390 using namespace testing;377 using namespace testing;
391 geom::Size const new_size{123, 456};378 geom::Size const new_size{123, 456};
392 auto const mock_event_sink = std::make_shared<MockEventSink>();379 auto const mock_event_sink = std::make_shared<MockEventSink>();
380 auto const observer = std::make_shared<ms::SurfaceEventSource>(mf::SurfaceId(), mock_event_sink);
393381
394 ms::BasicSurface surf(382 ms::BasicSurface surf(
395 mf::SurfaceId(),
396 surface_name,383 surface_name,
397 rect,384 rect,
398 false,385 false,
399 mock_buffer_stream,386 mock_buffer_stream,
400 std::shared_ptr<mi::InputChannel>(),387 std::shared_ptr<mi::InputChannel>(),
401 mock_event_sink,
402 stub_configurator,388 stub_configurator,
403 report);389 report);
404390
391 surf.add_observer(observer);
392
405 ASSERT_THAT(surf.size(), Ne(new_size));393 ASSERT_THAT(surf.size(), Ne(new_size));
406394
407 EXPECT_CALL(*mock_buffer_stream, resize(new_size)).Times(1);395 EXPECT_CALL(*mock_buffer_stream, resize(new_size)).Times(1);
@@ -428,13 +416,11 @@
428 .WillOnce(Throw(std::runtime_error("bad resize")));416 .WillOnce(Throw(std::runtime_error("bad resize")));
429417
430 ms::BasicSurface surf(418 ms::BasicSurface surf(
431 mf::SurfaceId(),
432 surface_name,419 surface_name,
433 rect,420 rect,
434 false,421 false,
435 mock_buffer_stream,422 mock_buffer_stream,
436 std::shared_ptr<mi::InputChannel>(),423 std::shared_ptr<mi::InputChannel>(),
437 stub_event_sink,
438 stub_configurator,424 stub_configurator,
439 report);425 report);
440426
@@ -459,13 +445,11 @@
459 };445 };
460446
461 ms::BasicSurface surf(447 ms::BasicSurface surf(
462 mf::SurfaceId(),
463 surface_name,448 surface_name,
464 rect,449 rect,
465 false,450 false,
466 mock_buffer_stream,451 mock_buffer_stream,
467 std::shared_ptr<mi::InputChannel>(),452 std::shared_ptr<mi::InputChannel>(),
468 stub_event_sink,
469 stub_configurator,453 stub_configurator,
470 report);454 report);
471455
@@ -484,13 +468,11 @@
484{468{
485 auto mock_channel = std::make_shared<MockInputChannel>();469 auto mock_channel = std::make_shared<MockInputChannel>();
486 ms::BasicSurface surf(470 ms::BasicSurface surf(
487 mf::SurfaceId(),
488 surface_name,471 surface_name,
489 rect,472 rect,
490 false,473 false,
491 mock_buffer_stream,474 mock_buffer_stream,
492 mock_channel,475 mock_channel,
493 stub_event_sink,
494 stub_configurator,476 stub_configurator,
495 report);477 report);
496478
@@ -503,13 +485,11 @@
503485
504 float alpha = 0.5f;486 float alpha = 0.5f;
505 ms::BasicSurface surf(487 ms::BasicSurface surf(
506 mf::SurfaceId(),
507 surface_name,488 surface_name,
508 rect,489 rect,
509 false,490 false,
510 mock_buffer_stream,491 mock_buffer_stream,
511 std::shared_ptr<mi::InputChannel>(),492 std::shared_ptr<mi::InputChannel>(),
512 stub_event_sink,
513 stub_configurator,493 stub_configurator,
514 report);494 report);
515495
@@ -524,13 +504,11 @@
524 EXPECT_CALL(*mock_buffer_stream, force_requests_to_complete()).Times(Exactly(1));504 EXPECT_CALL(*mock_buffer_stream, force_requests_to_complete()).Times(Exactly(1));
525505
526 ms::BasicSurface surf(506 ms::BasicSurface surf(
527 mf::SurfaceId(),
528 surface_name,507 surface_name,
529 rect,508 rect,
530 false,509 false,
531 mock_buffer_stream,510 mock_buffer_stream,
532 std::shared_ptr<mi::InputChannel>(),511 std::shared_ptr<mi::InputChannel>(),
533 stub_event_sink,
534 stub_configurator,512 stub_configurator,
535 report);513 report);
536514
@@ -545,13 +523,11 @@
545 .Times(1);523 .Times(1);
546524
547 ms::BasicSurface surf(525 ms::BasicSurface surf(
548 mf::SurfaceId(),
549 surface_name,526 surface_name,
550 rect,527 rect,
551 false,528 false,
552 mock_buffer_stream,529 mock_buffer_stream,
553 std::shared_ptr<mi::InputChannel>(),530 std::shared_ptr<mi::InputChannel>(),
554 stub_event_sink,
555 stub_configurator,531 stub_configurator,
556 report);532 report);
557533
@@ -561,13 +537,11 @@
561TEST_F(SurfaceCreation, test_surface_next_buffer_tells_state_on_first_frame)537TEST_F(SurfaceCreation, test_surface_next_buffer_tells_state_on_first_frame)
562{538{
563 ms::BasicSurface surf(539 ms::BasicSurface surf(
564 mf::SurfaceId(),
565 surface_name,540 surface_name,
566 rect,541 rect,
567 false,542 false,
568 mock_buffer_stream,543 mock_buffer_stream,
569 std::shared_ptr<mi::InputChannel>(),544 std::shared_ptr<mi::InputChannel>(),
570 stub_event_sink,
571 stub_configurator,545 stub_configurator,
572 report);546 report);
573547
@@ -589,13 +563,11 @@
589 using namespace testing;563 using namespace testing;
590564
591 ms::BasicSurface surf(565 ms::BasicSurface surf(
592 mf::SurfaceId(),
593 surface_name,566 surface_name,
594 rect,567 rect,
595 false,568 false,
596 mock_buffer_stream,569 mock_buffer_stream,
597 std::shared_ptr<mi::InputChannel>(),570 std::shared_ptr<mi::InputChannel>(),
598 stub_event_sink,
599 stub_configurator,571 stub_configurator,
600 report);572 report);
601573
@@ -608,12 +580,10 @@
608 EXPECT_CALL(channel, client_fd()).Times(1).WillOnce(Return(client_fd));580 EXPECT_CALL(channel, client_fd()).Times(1).WillOnce(Return(client_fd));
609581
610 ms::BasicSurface input_surf(582 ms::BasicSurface input_surf(
611 mf::SurfaceId(),
612 surface_name,583 surface_name,
613 rect,584 rect,
614 false,585 false,
615 mock_buffer_stream,mt::fake_shared(channel),586 mock_buffer_stream,mt::fake_shared(channel),
616 stub_event_sink,
617 stub_configurator,587 stub_configurator,
618 report);588 report);
619589
620590
=== modified file 'tests/unit-tests/scene/test_surface_controller.cpp'
--- tests/unit-tests/scene/test_surface_controller.cpp 2014-03-31 11:00:33 +0000
+++ tests/unit-tests/scene/test_surface_controller.cpp 2014-03-31 11:00:33 +0000
@@ -21,6 +21,7 @@
21#include "mir/scene/surface_factory.h"21#include "mir/scene/surface_factory.h"
22#include "mir/shell/surface_creation_parameters.h"22#include "mir/shell/surface_creation_parameters.h"
2323
24#include "mir_test_doubles/mock_surface.h"
24#include "mir_test/fake_shared.h"25#include "mir_test/fake_shared.h"
2526
26#include <gtest/gtest.h>27#include <gtest/gtest.h>
@@ -30,15 +31,14 @@
30namespace msh = mir::shell;31namespace msh = mir::shell;
31namespace ms = mir::scene;32namespace ms = mir::scene;
32namespace mt = mir::test;33namespace mt = mir::test;
34namespace mtd = mir::test::doubles;
3335
34namespace36namespace
35{37{
36struct MockSurfaceAllocator : public ms::SurfaceFactory38struct MockSurfaceAllocator : public ms::SurfaceFactory
37{39{
38 MOCK_METHOD3(create_surface, std::shared_ptr<ms::Surface>(40 MOCK_METHOD1(create_surface, std::shared_ptr<ms::Surface>(
39 mf::SurfaceId id,41 msh::SurfaceCreationParameters const&));
40 msh::SurfaceCreationParameters const&,
41 std::shared_ptr<mf::EventSink> const&));
42};42};
4343
44struct MockSurfaceStackModel : public ms::SurfaceStackModel44struct MockSurfaceStackModel : public ms::SurfaceStackModel
@@ -56,19 +56,24 @@
56{56{
57 using namespace ::testing;57 using namespace ::testing;
5858
59 std::shared_ptr<ms::Surface> null_surface;59 mtd::MockSurface mock_surface;
60 std::shared_ptr<ms::Surface> const expect_surface = mt::fake_shared(mock_surface);
61 auto const surface = std::make_shared<mtd::MockSurface>();
60 testing::NiceMock<MockSurfaceAllocator> mock_surface_allocator;62 testing::NiceMock<MockSurfaceAllocator> mock_surface_allocator;
61 MockSurfaceStackModel model;63 MockSurfaceStackModel model;
6264
63 ms::SurfaceController controller(mt::fake_shared(mock_surface_allocator), mt::fake_shared(model));65 ms::SurfaceController controller(mt::fake_shared(mock_surface_allocator), mt::fake_shared(model));
6466
65 InSequence seq;67 InSequence seq;
66 EXPECT_CALL(mock_surface_allocator, create_surface(_,_,_)).Times(1).WillOnce(Return(null_surface));68 EXPECT_CALL(mock_surface_allocator, create_surface(_)).Times(1).WillOnce(Return(expect_surface));
69 EXPECT_CALL(mock_surface, add_observer(_)).Times(1);
67 EXPECT_CALL(model, add_surface(_,_,_)).Times(1);70 EXPECT_CALL(model, add_surface(_,_,_)).Times(1);
68 EXPECT_CALL(model, remove_surface(_)).Times(1);71 EXPECT_CALL(model, remove_surface(_)).Times(1);
6972
70 auto surface = controller.add_surface(mf::SurfaceId(), msh::a_surface(), {});73 auto actual_surface = controller.add_surface(msh::a_surface(), std::shared_ptr<ms::SurfaceObserver>());
71 controller.remove_surface(surface);74
75 EXPECT_THAT(actual_surface, Eq(expect_surface));
76 controller.remove_surface(actual_surface);
72}77}
7378
74TEST(SurfaceController, raise_surface)79TEST(SurfaceController, raise_surface)
7580
=== modified file 'tests/unit-tests/scene/test_surface_impl.cpp'
--- tests/unit-tests/scene/test_surface_impl.cpp 2014-03-31 11:00:33 +0000
+++ tests/unit-tests/scene/test_surface_impl.cpp 2014-03-31 11:00:33 +0000
@@ -17,6 +17,8 @@
17 */17 */
1818
19#include "src/server/scene/basic_surface.h"19#include "src/server/scene/basic_surface.h"
20#include "mir/scene/surface_observer.h"
21#include "mir/scene/surface_event_source.h"
20#include "src/server/report/null_report_factory.h"22#include "src/server/report/null_report_factory.h"
21#include "mir/frontend/event_sink.h"23#include "mir/frontend/event_sink.h"
22#include "mir/graphics/display_configuration.h"24#include "mir/graphics/display_configuration.h"
@@ -65,7 +67,6 @@
6567
66 Surface() :68 Surface() :
67 buffer_stream(std::make_shared<StubBufferStream>()),69 buffer_stream(std::make_shared<StubBufferStream>()),
68 stub_sender(std::make_shared<mtd::NullEventSink>()),
69 null_configurator(std::make_shared<mtd::NullSurfaceConfigurator>())70 null_configurator(std::make_shared<mtd::NullSurfaceConfigurator>())
70 {71 {
71 using namespace testing;72 using namespace testing;
@@ -76,7 +77,6 @@
76 .WillByDefault(InvokeArgument<1>(nullptr));77 .WillByDefault(InvokeArgument<1>(nullptr));
77 }78 }
78 mf::SurfaceId stub_id;79 mf::SurfaceId stub_id;
79 std::shared_ptr<mf::EventSink> stub_sender;
80 std::shared_ptr<ms::SurfaceConfigurator> null_configurator;80 std::shared_ptr<ms::SurfaceConfigurator> null_configurator;
81 std::shared_ptr<ms::SceneReport> const report = mr::null_scene_report();81 std::shared_ptr<ms::SceneReport> const report = mr::null_scene_report();
82};82};
@@ -87,13 +87,11 @@
87 using namespace testing;87 using namespace testing;
8888
89 ms::BasicSurface surf(89 ms::BasicSurface surf(
90 stub_id,
91 std::string("stub"),90 std::string("stub"),
92 geom::Rectangle{{},{}},91 geom::Rectangle{{},{}},
93 false,92 false,
94 buffer_stream,93 buffer_stream,
95 std::shared_ptr<mi::InputChannel>(),94 std::shared_ptr<mi::InputChannel>(),
96 stub_sender,
97 null_configurator,95 null_configurator,
98 report);96 report);
9997
@@ -107,13 +105,11 @@
107 using namespace testing;105 using namespace testing;
108106
109 ms::BasicSurface surf(107 ms::BasicSurface surf(
110 stub_id,
111 std::string("stub"),108 std::string("stub"),
112 geom::Rectangle{{},{}},109 geom::Rectangle{{},{}},
113 false,110 false,
114 buffer_stream,111 buffer_stream,
115 std::shared_ptr<mi::InputChannel>(),112 std::shared_ptr<mi::InputChannel>(),
116 stub_sender,
117 null_configurator,113 null_configurator,
118 report);114 report);
119115
@@ -148,13 +144,11 @@
148 using namespace testing;144 using namespace testing;
149145
150 ms::BasicSurface surf(146 ms::BasicSurface surf(
151 stub_id,
152 std::string("stub"),147 std::string("stub"),
153 geom::Rectangle{{},{}},148 geom::Rectangle{{},{}},
154 false,149 false,
155 buffer_stream,150 buffer_stream,
156 std::shared_ptr<mi::InputChannel>(),151 std::shared_ptr<mi::InputChannel>(),
157 stub_sender,
158 null_configurator,152 null_configurator,
159 report);153 report);
160154
@@ -196,18 +190,19 @@
196190
197 geom::Size const new_size{123, 456};191 geom::Size const new_size{123, 456};
198 auto sink = std::make_shared<MockEventSink>();192 auto sink = std::make_shared<MockEventSink>();
193 auto const observer = std::make_shared<ms::SurfaceEventSource>(stub_id, sink);
199194
200 ms::BasicSurface surf(195 ms::BasicSurface surf(
201 stub_id,
202 std::string("stub"),196 std::string("stub"),
203 geom::Rectangle{{},{}},197 geom::Rectangle{{},{}},
204 false,198 false,
205 buffer_stream,199 buffer_stream,
206 std::shared_ptr<mi::InputChannel>(),200 std::shared_ptr<mi::InputChannel>(),
207 sink,
208 null_configurator,201 null_configurator,
209 report);202 report);
210203
204 surf.add_observer(observer);
205
211 MirEvent e;206 MirEvent e;
212 memset(&e, 0, sizeof e);207 memset(&e, 0, sizeof e);
213 e.type = mir_event_type_resize;208 e.type = mir_event_type_resize;
@@ -228,18 +223,19 @@
228 geom::Size const new_size{123, 456};223 geom::Size const new_size{123, 456};
229 geom::Size const new_size2{789, 1011};224 geom::Size const new_size2{789, 1011};
230 auto sink = std::make_shared<MockEventSink>();225 auto sink = std::make_shared<MockEventSink>();
226 auto const observer = std::make_shared<ms::SurfaceEventSource>(stub_id, sink);
231227
232 ms::BasicSurface surf(228 ms::BasicSurface surf(
233 stub_id,
234 std::string("stub"),229 std::string("stub"),
235 geom::Rectangle{{},{}},230 geom::Rectangle{{},{}},
236 false,231 false,
237 buffer_stream,232 buffer_stream,
238 std::shared_ptr<mi::InputChannel>(),233 std::shared_ptr<mi::InputChannel>(),
239 sink,
240 null_configurator,234 null_configurator,
241 report);235 report);
242236
237 surf.add_observer(observer);
238
243 MirEvent e;239 MirEvent e;
244 memset(&e, 0, sizeof e);240 memset(&e, 0, sizeof e);
245 e.type = mir_event_type_resize;241 e.type = mir_event_type_resize;
@@ -272,13 +268,11 @@
272TEST_F(Surface, remembers_alpha)268TEST_F(Surface, remembers_alpha)
273{269{
274 ms::BasicSurface surf(270 ms::BasicSurface surf(
275 stub_id,
276 std::string("stub"),271 std::string("stub"),
277 geom::Rectangle{{},{}},272 geom::Rectangle{{},{}},
278 false,273 false,
279 buffer_stream,274 buffer_stream,
280 std::shared_ptr<mi::InputChannel>(),275 std::shared_ptr<mi::InputChannel>(),
281 stub_sender,
282 null_configurator,276 null_configurator,
283 report);277 report);
284278
@@ -311,17 +305,19 @@
311 .Times(1);305 .Times(1);
312 }306 }
313307
308 auto const observer = std::make_shared<ms::SurfaceEventSource>(stub_id, mt::fake_shared(sink));
309
314 ms::BasicSurface surf(310 ms::BasicSurface surf(
315 stub_id,
316 std::string("stub"),311 std::string("stub"),
317 geom::Rectangle{{},{}},312 geom::Rectangle{{},{}},
318 false,313 false,
319 buffer_stream,314 buffer_stream,
320 std::shared_ptr<mi::InputChannel>(),315 std::shared_ptr<mi::InputChannel>(),
321 mt::fake_shared(sink),
322 null_configurator,316 null_configurator,
323 report);317 report);
324318
319 surf.add_observer(observer);
320
325 surf.configure(mir_surface_attrib_focus, mir_surface_focused);321 surf.configure(mir_surface_attrib_focus, mir_surface_focused);
326 surf.configure(mir_surface_attrib_focus, mir_surface_unfocused);322 surf.configure(mir_surface_attrib_focus, mir_surface_unfocused);
327}323}
@@ -337,13 +333,11 @@
337 EXPECT_CALL(configurator, attribute_set(_, mir_surface_attrib_state, mir_surface_state_minimized)).Times(1);333 EXPECT_CALL(configurator, attribute_set(_, mir_surface_attrib_state, mir_surface_state_minimized)).Times(1);
338334
339 ms::BasicSurface surf(335 ms::BasicSurface surf(
340 stub_id,
341 std::string("stub"),336 std::string("stub"),
342 geom::Rectangle{{},{}},337 geom::Rectangle{{},{}},
343 false,338 false,
344 buffer_stream,339 buffer_stream,
345 std::shared_ptr<mi::InputChannel>(),340 std::shared_ptr<mi::InputChannel>(),
346 stub_sender,
347 mt::fake_shared(configurator),341 mt::fake_shared(configurator),
348 report);342 report);
349343
@@ -355,13 +349,11 @@
355 using namespace ::testing;349 using namespace ::testing;
356350
357 ms::BasicSurface surf(351 ms::BasicSurface surf(
358 stub_id,
359 std::string("stub"),352 std::string("stub"),
360 geom::Rectangle{{},{}},353 geom::Rectangle{{},{}},
361 false,354 false,
362 buffer_stream,355 buffer_stream,
363 std::shared_ptr<mi::InputChannel>(),356 std::shared_ptr<mi::InputChannel>(),
364 stub_sender,
365 null_configurator,357 null_configurator,
366 report);358 report);
367359
@@ -376,13 +368,11 @@
376 auto stub_buffer_stream = std::make_shared<mtd::StubBufferStream>();368 auto stub_buffer_stream = std::make_shared<mtd::StubBufferStream>();
377369
378 ms::BasicSurface surf(370 ms::BasicSurface surf(
379 stub_id,
380 std::string("stub"),371 std::string("stub"),
381 geom::Rectangle{{},{}},372 geom::Rectangle{{},{}},
382 false,373 false,
383 stub_buffer_stream,374 stub_buffer_stream,
384 std::shared_ptr<mi::InputChannel>(),375 std::shared_ptr<mi::InputChannel>(),
385 stub_sender,
386 null_configurator,376 null_configurator,
387 report);377 report);
388378
389379
=== modified file 'tests/unit-tests/scene/test_surface_stack.cpp'
--- tests/unit-tests/scene/test_surface_stack.cpp 2014-03-26 14:20:14 +0000
+++ tests/unit-tests/scene/test_surface_stack.cpp 2014-03-31 11:00:33 +0000
@@ -128,35 +128,29 @@
128 default_params = msh::a_surface().of_size(geom::Size{geom::Width{1024}, geom::Height{768}});128 default_params = msh::a_surface().of_size(geom::Size{geom::Width{1024}, geom::Height{768}});
129129
130 stub_surface1 = std::make_shared<ms::BasicSurface>(130 stub_surface1 = std::make_shared<ms::BasicSurface>(
131 mf::SurfaceId(__LINE__),
132 std::string("stub"),131 std::string("stub"),
133 geom::Rectangle{{},{}},132 geom::Rectangle{{},{}},
134 false,133 false,
135 std::make_shared<mtd::StubBufferStream>(),134 std::make_shared<mtd::StubBufferStream>(),
136 std::shared_ptr<mir::input::InputChannel>(),135 std::shared_ptr<mir::input::InputChannel>(),
137 std::shared_ptr<mf::EventSink>(),
138 std::shared_ptr<ms::SurfaceConfigurator>(),136 std::shared_ptr<ms::SurfaceConfigurator>(),
139 report);137 report);
140138
141 stub_surface2 = std::make_shared<ms::BasicSurface>(139 stub_surface2 = std::make_shared<ms::BasicSurface>(
142 mf::SurfaceId(__LINE__),
143 std::string("stub"),140 std::string("stub"),
144 geom::Rectangle{{},{}},141 geom::Rectangle{{},{}},
145 false,142 false,
146 std::make_shared<mtd::StubBufferStream>(),143 std::make_shared<mtd::StubBufferStream>(),
147 std::shared_ptr<mir::input::InputChannel>(),144 std::shared_ptr<mir::input::InputChannel>(),
148 std::shared_ptr<mf::EventSink>(),
149 std::shared_ptr<ms::SurfaceConfigurator>(),145 std::shared_ptr<ms::SurfaceConfigurator>(),
150 report);146 report);
151147
152 stub_surface3 = std::make_shared<ms::BasicSurface>(148 stub_surface3 = std::make_shared<ms::BasicSurface>(
153 mf::SurfaceId(__LINE__),
154 std::string("stub"),149 std::string("stub"),
155 geom::Rectangle{{},{}},150 geom::Rectangle{{},{}},
156 false,151 false,
157 std::make_shared<mtd::StubBufferStream>(),152 std::make_shared<mtd::StubBufferStream>(),
158 std::shared_ptr<mir::input::InputChannel>(),153 std::shared_ptr<mir::input::InputChannel>(),
159 std::shared_ptr<mf::EventSink>(),
160 std::shared_ptr<ms::SurfaceConfigurator>(),154 std::shared_ptr<ms::SurfaceConfigurator>(),
161 report);155 report);
162 }156 }
@@ -568,13 +562,11 @@
568 for(auto i = 0u; i < num_surfaces; i++)562 for(auto i = 0u; i < num_surfaces; i++)
569 {563 {
570 auto const surface = std::make_shared<ms::BasicSurface>(564 auto const surface = std::make_shared<ms::BasicSurface>(
571 mf::SurfaceId(__LINE__),
572 std::string("stub"),565 std::string("stub"),
573 geom::Rectangle{geom::Point{3 * i, 4 * i},geom::Size{1 * i, 2 * i}},566 geom::Rectangle{geom::Point{3 * i, 4 * i},geom::Size{1 * i, 2 * i}},
574 true,567 true,
575 std::make_shared<mtd::StubBufferStream>(),568 std::make_shared<mtd::StubBufferStream>(),
576 std::shared_ptr<mir::input::InputChannel>(),569 std::shared_ptr<mir::input::InputChannel>(),
577 std::shared_ptr<mf::EventSink>(),
578 std::shared_ptr<ms::SurfaceConfigurator>(),570 std::shared_ptr<ms::SurfaceConfigurator>(),
579 report);571 report);
580572
581573
=== modified file 'tests/unit-tests/shell/test_organising_surface_factory.cpp'
--- tests/unit-tests/shell/test_organising_surface_factory.cpp 2014-03-31 11:00:33 +0000
+++ tests/unit-tests/shell/test_organising_surface_factory.cpp 2014-03-31 11:00:33 +0000
@@ -20,6 +20,8 @@
20#include "mir/shell/placement_strategy.h"20#include "mir/shell/placement_strategy.h"
21#include "mir/shell/surface_creation_parameters.h"21#include "mir/shell/surface_creation_parameters.h"
22#include "mir/shell/session.h"22#include "mir/shell/session.h"
23#include "mir/scene/surface.h"
24#include "mir/scene/surface_event_source.h"
23#include "mir/scene/surface_coordinator.h"25#include "mir/scene/surface_coordinator.h"
2426
25#include "mir_test_doubles/stub_shell_session.h"27#include "mir_test_doubles/stub_shell_session.h"
@@ -38,10 +40,9 @@
38{40{
39struct MockSurfaceCoordinator : public ms::SurfaceCoordinator41struct MockSurfaceCoordinator : public ms::SurfaceCoordinator
40{42{
41 MOCK_METHOD3(add_surface, std::shared_ptr<ms::Surface>(43 MOCK_METHOD2(add_surface, std::shared_ptr<ms::Surface>(
42 mf::SurfaceId,
43 msh::SurfaceCreationParameters const&,44 msh::SurfaceCreationParameters const&,
44 std::shared_ptr<mf::EventSink> const&));45 std::shared_ptr<ms::SurfaceObserver> const&));
4546
46 void remove_surface(std::weak_ptr<ms::Surface> const& /*surface*/) override {}47 void remove_surface(std::weak_ptr<ms::Surface> const& /*surface*/) override {}
47 void raise(std::weak_ptr<ms::Surface> const& /*surface*/) override {}48 void raise(std::weak_ptr<ms::Surface> const& /*surface*/) override {}
@@ -57,10 +58,11 @@
57 void SetUp()58 void SetUp()
58 {59 {
59 using namespace ::testing;60 using namespace ::testing;
60 ON_CALL(*surface_coordinator, add_surface(_, _, _)).WillByDefault(Return(null_surface));61 ON_CALL(*surface_coordinator, add_surface(_, _)).WillByDefault(Return(null_surface));
61 }62 }
62 std::shared_ptr<ms::Surface> null_surface;63 std::shared_ptr<ms::Surface> null_surface;
63 std::shared_ptr<MockSurfaceCoordinator> surface_coordinator = std::make_shared<MockSurfaceCoordinator>();64 std::shared_ptr<MockSurfaceCoordinator> surface_coordinator = std::make_shared<MockSurfaceCoordinator>();
65 std::shared_ptr<ms::SurfaceObserver> const observer = std::make_shared<ms::SurfaceEventSource>(mf::SurfaceId(), std::make_shared<mtd::NullEventSink>());
64 std::shared_ptr<MockPlacementStrategy> placement_strategy = std::make_shared<MockPlacementStrategy>();66 std::shared_ptr<MockPlacementStrategy> placement_strategy = std::make_shared<MockPlacementStrategy>();
65};67};
6668
@@ -73,13 +75,13 @@
73 msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy);75 msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy);
7476
75 mtd::StubShellSession session;77 mtd::StubShellSession session;
76 EXPECT_CALL(*surface_coordinator, add_surface(_, _, _)).Times(1);78 EXPECT_CALL(*surface_coordinator, add_surface(_, _)).Times(1);
7779
78 auto params = msh::a_surface();80 auto params = msh::a_surface();
79 EXPECT_CALL(*placement_strategy, place(Ref(session), Ref(params))).Times(1)81 EXPECT_CALL(*placement_strategy, place(Ref(session), Ref(params))).Times(1)
80 .WillOnce(Return(msh::a_surface()));82 .WillOnce(Return(msh::a_surface()));
8183
82 factory.create_surface(&session, params, mf::SurfaceId(), std::make_shared<mtd::NullEventSink>());84 factory.create_surface(&session, params, observer);
83}85}
8486
85TEST_F(OrganisingSurfaceFactorySetup, forwards_create_surface_parameters_from_placement_strategy_to_underlying_factory)87TEST_F(OrganisingSurfaceFactorySetup, forwards_create_surface_parameters_from_placement_strategy_to_underlying_factory)
@@ -88,14 +90,13 @@
8890
89 msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy);91 msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy);
9092
91 std::shared_ptr<mf::EventSink> sink = std::make_shared<mtd::NullEventSink>();
92 auto params = msh::a_surface();93 auto params = msh::a_surface();
93 auto placed_params = params;94 auto placed_params = params;
94 placed_params.size.width = geom::Width{100};95 placed_params.size.width = geom::Width{100};
9596
96 EXPECT_CALL(*placement_strategy, place(_, Ref(params))).Times(1)97 EXPECT_CALL(*placement_strategy, place(_, Ref(params))).Times(1)
97 .WillOnce(Return(placed_params));98 .WillOnce(Return(placed_params));
98 EXPECT_CALL(*surface_coordinator, add_surface(mf::SurfaceId(), placed_params, sink));99 EXPECT_CALL(*surface_coordinator, add_surface(placed_params, _));
99100
100 factory.create_surface(nullptr, params, mf::SurfaceId(), sink);101 factory.create_surface(nullptr, params, observer);
101}102}

Subscribers

People subscribed via source and target branches