Mir
application_session.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013-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: Robert Carr <racarr@canonical.com>
17  */
18 
19 #ifndef MIR_SCENE_APPLICATION_SESSION_H_
20 #define MIR_SCENE_APPLICATION_SESSION_H_
21 
22 #include "mir/scene/session.h"
23 
25 
26 #include <atomic>
27 #include <map>
28 #include <mutex>
29 
30 namespace mir
31 {
32 namespace frontend
33 {
34 class EventSink;
35 class ClientBuffers;
36 }
37 namespace compositor { class BufferStream; }
38 namespace graphics
39 {
40 class DisplayConfiguration;
41 class GraphicBufferAllocator;
42 }
43 namespace shell { class SurfaceStack; }
44 namespace scene
45 {
46 class SessionListener;
47 class Surface;
48 class SnapshotStrategy;
49 class BufferStreamFactory;
50 class SurfaceFactory;
51 
53 {
54 public:
56  std::shared_ptr<shell::SurfaceStack> const& surface_stack,
57  std::shared_ptr<SurfaceFactory> const& surface_factory,
58  std::shared_ptr<BufferStreamFactory> const& buffer_stream_factory,
59  pid_t pid,
60  std::string const& session_name,
61  std::shared_ptr<SnapshotStrategy> const& snapshot_strategy,
62  std::shared_ptr<SessionListener> const& session_listener,
63  graphics::DisplayConfiguration const& initial_config,
64  std::shared_ptr<frontend::EventSink> const& sink,
65  std::shared_ptr<graphics::GraphicBufferAllocator> const& allocator);
66 
68 
69  frontend::SurfaceId create_surface(
70  SurfaceCreationParameters const& params,
71  std::shared_ptr<frontend::EventSink> const& surface_sink) override;
72  void destroy_surface(frontend::SurfaceId surface) override;
73  std::shared_ptr<frontend::Surface> get_surface(frontend::SurfaceId surface) const override;
74  std::shared_ptr<Surface> surface(frontend::SurfaceId surface) const override;
75  std::shared_ptr<Surface> surface_after(std::shared_ptr<Surface> const&) const override;
76 
77  void take_snapshot(SnapshotCallback const& snapshot_taken) override;
78  std::shared_ptr<Surface> default_surface() const override;
79 
80  std::string name() const override;
81  pid_t process_id() const override;
82 
83  void drop_outstanding_requests() override;
84 
85  void hide() override;
86  void show() override;
87 
88  void send_display_config(graphics::DisplayConfiguration const& info) override;
89  void send_input_device_change(std::vector<std::shared_ptr<input::Device>> const& devices) override;
90 
91  void set_lifecycle_state(MirLifecycleState state) override;
92 
93  void start_prompt_session() override;
94  void stop_prompt_session() override;
95  void suspend_prompt_session() override;
96  void resume_prompt_session() override;
97 
98  std::shared_ptr<frontend::BufferStream> get_buffer_stream(frontend::BufferStreamId stream) const override;
99  frontend::BufferStreamId create_buffer_stream(graphics::BufferProperties const& params) override;
100  void destroy_buffer_stream(frontend::BufferStreamId stream) override;
101  void configure_streams(Surface& surface, std::vector<shell::StreamSpecification> const& config) override;
102  void destroy_surface(std::weak_ptr<Surface> const& surface) override;
103 
104  graphics::BufferID create_buffer(graphics::BufferProperties const& properties) override;
105  void destroy_buffer(graphics::BufferID) override;
106  std::shared_ptr<graphics::Buffer> get_buffer(graphics::BufferID) override;
107 protected:
108  ApplicationSession(ApplicationSession const&) = delete;
109  ApplicationSession& operator=(ApplicationSession const&) = delete;
110 
111 private:
112  std::shared_ptr<shell::SurfaceStack> const surface_stack;
113  std::shared_ptr<SurfaceFactory> const surface_factory;
114  std::shared_ptr<BufferStreamFactory> const buffer_stream_factory;
115  pid_t const pid;
116  std::string const session_name;
117  std::shared_ptr<SnapshotStrategy> const snapshot_strategy;
118  std::shared_ptr<SessionListener> const session_listener;
119  std::shared_ptr<frontend::EventSink> const event_sink;
120  std::shared_ptr<frontend::ClientBuffers> const buffers;
121 
122  frontend::SurfaceId next_id();
123 
124  std::atomic<int> next_surface_id;
125 
126  OutputPropertiesCache output_cache;
127 
128  typedef std::map<frontend::SurfaceId, std::shared_ptr<Surface>> Surfaces;
129  typedef std::map<frontend::BufferStreamId, std::shared_ptr<compositor::BufferStream>> Streams;
130  Surfaces::const_iterator checked_find(frontend::SurfaceId id) const;
131  Streams::const_iterator checked_find(frontend::BufferStreamId id) const;
132  std::mutex mutable surfaces_and_streams_mutex;
133  Surfaces surfaces;
134  Streams streams;
135 
136  std::map<frontend::SurfaceId, frontend::BufferStreamId> default_content_map;
137 
138  void destroy_surface(std::unique_lock<std::mutex>& lock, Surfaces::const_iterator in_surfaces);
139 };
140 
141 }
142 } // namespace mir
143 
144 #endif // MIR_SCENE_APPLICATION_SESSION_H_
All things Mir.
Definition: atomic_callback.h:25
Definition: session.h:38
std::function< void(Snapshot const &)> SnapshotCallback
Definition: snapshot.h:39
Definition: application_session.h:52
MirLifecycleState
Definition: common.h:94
Definition: surface_creation_parameters.h:41
Buffer creation properties.
Definition: buffer_properties.h:48
Definition: surface.h:49
Definition: output_properties_cache.h:44
Interface to a configuration of display cards and outputs.
Definition: display_configuration.h:168

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016