Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
session_mediator.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012-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 
20 #ifndef MIR_FRONTEND_SESSION_MEDIATOR_H_
21 #define MIR_FRONTEND_SESSION_MEDIATOR_H_
22 
23 #include "mir_protobuf.pb.h"
25 #include "mir_toolkit/common.h"
26 
27 #include <functional>
28 #include <unordered_map>
29 #include <memory>
30 #include <mutex>
31 #include <vector>
32 
33 namespace mir
34 {
35 namespace graphics
36 {
37 class Buffer;
38 class Platform;
39 class Display;
40 class GraphicBufferAllocator;
41 }
42 
43 
46 namespace frontend
47 {
48 class ClientBufferTracker;
49 class Shell;
50 class Session;
51 class Surface;
52 class ResourceCache;
53 class SessionMediatorReport;
54 class EventSink;
55 class DisplayChanger;
56 class Screencast;
57 
58 // SessionMediator relays requests from the client process into the server.
59 class SessionMediator : public mir::protobuf::DisplayServer
60 {
61 public:
63  pid_t client_pid,
64  std::shared_ptr<Shell> const& shell,
65  std::shared_ptr<graphics::Platform> const& graphics_platform,
66  std::shared_ptr<frontend::DisplayChanger> const& display_changer,
67  std::vector<MirPixelFormat> const& surface_pixel_formats,
68  std::shared_ptr<SessionMediatorReport> const& report,
69  std::shared_ptr<EventSink> const& event_sink,
70  std::shared_ptr<ResourceCache> const& resource_cache,
71  std::shared_ptr<Screencast> const& screencast);
72 
73  ~SessionMediator() noexcept;
74 
75  /* Platform independent requests */
76  void connect(::google::protobuf::RpcController* controller,
77  const ::mir::protobuf::ConnectParameters* request,
78  ::mir::protobuf::Connection* response,
79  ::google::protobuf::Closure* done) override;
80 
81  void create_surface(google::protobuf::RpcController* controller,
82  const mir::protobuf::SurfaceParameters* request,
83  mir::protobuf::Surface* response,
84  google::protobuf::Closure* done) override;
85 
86  void next_buffer(
87  google::protobuf::RpcController* controller,
88  mir::protobuf::SurfaceId const* request,
89  mir::protobuf::Buffer* response,
90  google::protobuf::Closure* done) override;
91 
92  void release_surface(google::protobuf::RpcController* controller,
94  mir::protobuf::Void*,
95  google::protobuf::Closure* done) override;
96 
97  void disconnect(google::protobuf::RpcController* controller,
98  const mir::protobuf::Void* request,
99  mir::protobuf::Void* response,
100  google::protobuf::Closure* done) override;
101 
102  void configure_surface(google::protobuf::RpcController* controller,
103  const mir::protobuf::SurfaceSetting*,
104  mir::protobuf::SurfaceSetting*,
105  google::protobuf::Closure* done) override;
106 
107  void configure_display(::google::protobuf::RpcController* controller,
108  const ::mir::protobuf::DisplayConfiguration* request,
109  ::mir::protobuf::DisplayConfiguration* response,
110  ::google::protobuf::Closure* done) override;
111 
112  void create_screencast(google::protobuf::RpcController*,
113  const mir::protobuf::ScreencastParameters*,
114  mir::protobuf::Screencast*,
115  google::protobuf::Closure* done);
116 
117  void release_screencast(google::protobuf::RpcController*,
118  const mir::protobuf::ScreencastId*,
119  mir::protobuf::Void*,
120  google::protobuf::Closure* done);
121 
122  void screencast_buffer(google::protobuf::RpcController*,
123  const mir::protobuf::ScreencastId*,
124  mir::protobuf::Buffer*,
125  google::protobuf::Closure* done);
126 
127  /* Platform specific requests */
128  void drm_auth_magic(google::protobuf::RpcController* controller,
129  const mir::protobuf::DRMMagic* request,
130  mir::protobuf::DRMAuthMagicStatus* response,
131  google::protobuf::Closure* done) override;
132 
133 private:
134  void pack_protobuf_buffer(protobuf::Buffer& protobuf_buffer,
135  graphics::Buffer* graphics_buffer,
136  bool need_full_ipc);
137 
138  void advance_buffer(SurfaceId surf_id, Surface& surface, std::function<void(graphics::Buffer*, bool)> complete);
139  pid_t client_pid;
140  std::shared_ptr<Shell> const shell;
141  std::shared_ptr<graphics::Platform> const graphics_platform;
142 
143  std::vector<MirPixelFormat> const surface_pixel_formats;
144 
145  std::shared_ptr<frontend::DisplayChanger> const display_changer;
146  std::shared_ptr<SessionMediatorReport> const report;
147  std::shared_ptr<EventSink> const event_sink;
148  std::shared_ptr<ResourceCache> const resource_cache;
149  std::shared_ptr<Screencast> const screencast;
150 
151  std::unordered_map<SurfaceId,graphics::Buffer*> client_buffer_resource;
152  std::unordered_map<SurfaceId, std::shared_ptr<ClientBufferTracker>> client_buffer_tracker;
153 
154  std::mutex session_mutex;
155  std::weak_ptr<Session> weak_session;
156 };
157 
158 }
159 }
160 
161 
162 #endif /* MIR_FRONTEND_SESSION_MEDIATOR_H_ */
IntWrapper< detail::SessionsSurfaceIdTag > SurfaceId
Definition: surface_id.h:29
void release_surface(google::protobuf::RpcController *controller, const mir::protobuf::SurfaceId *, mir::protobuf::Void *, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:228
void configure_surface(google::protobuf::RpcController *controller, const mir::protobuf::SurfaceSetting *, mir::protobuf::SurfaceSetting *, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:277
void configure_display(::google::protobuf::RpcController *controller, const ::mir::protobuf::DisplayConfiguration *request,::mir::protobuf::DisplayConfiguration *response,::google::protobuf::Closure *done) override
Definition: session_mediator.cpp:309
void next_buffer(google::protobuf::RpcController *controller, mir::protobuf::SurfaceId const *request, mir::protobuf::Buffer *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:198
void disconnect(google::protobuf::RpcController *controller, const mir::protobuf::Void *request, mir::protobuf::Void *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:254
Definition: session_mediator.h:59
void drm_auth_magic(google::protobuf::RpcController *controller, const mir::protobuf::DRMMagic *request, mir::protobuf::DRMAuthMagicStatus *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:413
~SessionMediator() noexcept
Definition: session_mediator.cpp:83
void create_surface(google::protobuf::RpcController *controller, const mir::protobuf::SurfaceParameters *request, mir::protobuf::Surface *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:148
Definition: int_wrapper.h:27
void connect(::google::protobuf::RpcController *controller, const ::mir::protobuf::ConnectParameters *request,::mir::protobuf::Connection *response,::google::protobuf::Closure *done) override
Definition: session_mediator.cpp:92
void create_screencast(google::protobuf::RpcController *, const mir::protobuf::ScreencastParameters *, mir::protobuf::Screencast *, google::protobuf::Closure *done)
Definition: session_mediator.cpp:355
void screencast_buffer(google::protobuf::RpcController *, const mir::protobuf::ScreencastId *, mir::protobuf::Buffer *, google::protobuf::Closure *done)
Definition: session_mediator.cpp:394
Definition: surface.h:48
SessionMediator(pid_t client_pid, std::shared_ptr< Shell > const &shell, std::shared_ptr< graphics::Platform > const &graphics_platform, std::shared_ptr< frontend::DisplayChanger > const &display_changer, std::vector< MirPixelFormat > const &surface_pixel_formats, std::shared_ptr< SessionMediatorReport > const &report, std::shared_ptr< EventSink > const &event_sink, std::shared_ptr< ResourceCache > const &resource_cache, std::shared_ptr< Screencast > const &screencast)
Definition: session_mediator.cpp:61
Definition: buffer.h:34
void release_screencast(google::protobuf::RpcController *, const mir::protobuf::ScreencastId *, mir::protobuf::Void *, google::protobuf::Closure *done)
Definition: session_mediator.cpp:382

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Apr 11 21:14:53 UTC 2014