Mir
mir_surface.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, 2015 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17  */
18 #ifndef MIR_CLIENT_MIR_SURFACE_H_
19 #define MIR_CLIENT_MIR_SURFACE_H_
20 
22 #include "client_buffer_stream.h"
23 #include "mir_wait_handle.h"
24 #include "rpc/mir_display_server.h"
26 
27 #include "mir/client_platform.h"
29 #include "mir/optional_value.h"
32 #include "mir_toolkit/common.h"
35 
36 #include <memory>
37 #include <functional>
38 #include <mutex>
39 #include <unordered_set>
40 
41 namespace mir
42 {
43 namespace dispatch
44 {
45 class ThreadedDispatcher;
46 }
47 namespace input
48 {
49 namespace receiver
50 {
51 class InputPlatform;
52 class XKBMapper;
53 }
54 }
55 namespace protobuf
56 {
57 class PersistentSurfaceId;
58 class Surface;
59 class SurfaceParameters;
60 class SurfaceSetting;
61 class Void;
62 }
63 namespace client
64 {
65 namespace rpc
66 {
67 class DisplayServer;
68 class DisplayServerDebug;
69 }
70 
71 class ClientBuffer;
72 class ClientBufferStream;
73 class ClientBufferStreamFactory;
74 
75 struct MemoryRegion;
76 }
77 }
78 
80 {
82  int stream_id;
84 };
85 
87 {
89  MirSurfaceSpec(MirConnection* connection, int width, int height, MirPixelFormat format);
90  MirSurfaceSpec(MirConnection* connection, MirSurfaceParameters const& params);
91 
92  struct AspectRatio { unsigned width; unsigned height; };
93 
94  // Required parameters
95  MirConnection* connection{nullptr};
96 
97  // Optional parameters
102 
105 
109 
111  std::shared_ptr<MirPersistentId> parent_id;
114 
125 
127  {
129  void* context;
130  };
133 };
134 
136 {
137 public:
138  MirPersistentId(std::string const& string_id);
139 
140  std::string const& as_string();
141 
142 private:
143  std::string const string_id;
144 };
145 
147 {
148 public:
149  MirSurface(MirSurface const &) = delete;
150  MirSurface& operator=(MirSurface const &) = delete;
151 
152  MirSurface(
153  std::string const& error,
154  MirConnection *allocating_connection,
155  mir::frontend::SurfaceId surface_id,
156  std::shared_ptr<MirWaitHandle> const& handle);
157 
158  MirSurface(
159  MirConnection *allocating_connection,
162  std::shared_ptr<mir::client::ClientBufferStream> const& buffer_stream,
163  std::shared_ptr<mir::input::receiver::InputPlatform> const& input_platform,
164  MirSurfaceSpec const& spec, mir::protobuf::Surface const& surface_proto,
165  std::shared_ptr<MirWaitHandle> const& handle);
166 
167  ~MirSurface();
168 
169  MirSurfaceParameters get_parameters() const;
170  char const * get_error_message();
171  int id() const;
172 
173  MirWaitHandle* configure(MirSurfaceAttrib a, int value);
174 
175  // TODO: Some sort of extension mechanism so that this can be moved
176  // out into a separate class in the libmirclient-debug DSO.
177  bool translate_to_screen_coordinates(int x, int y,
178  int* screen_x, int* screen_y);
179 
180  // Non-blocking
181  int attrib(MirSurfaceAttrib a) const;
182 
183  MirOrientation get_orientation() const;
184  MirWaitHandle* set_preferred_orientation(MirOrientationMode mode);
185 
186  void raise_surface(MirCookie const* cookie);
187 
189 
190  void set_event_handler(mir_surface_event_callback callback,
191  void* context);
192  void handle_event(MirEvent const& e);
193 
194  void request_and_wait_for_configure(MirSurfaceAttrib a, int value);
195 
196  mir::client::ClientBufferStream* get_buffer_stream();
197 
198  MirWaitHandle* modify(MirSurfaceSpec const& changes);
199 
200  static bool is_valid(MirSurface* query);
201 
202  MirWaitHandle* request_persistent_id(mir_surface_id_callback callback, void* context);
203  MirConnection* connection() const;
204 private:
205  std::mutex mutable mutex; // Protects all members of *this
206 
207  void on_configured();
208  void on_cursor_configured();
209  void acquired_persistent_id(mir_surface_id_callback callback, void* context);
210  MirPixelFormat convert_ipc_pf_to_geometry(google::protobuf::int32 pf) const;
211 
212  mir::client::rpc::DisplayServer* const server{nullptr};
213  mir::client::rpc::DisplayServerDebug* const debug{nullptr};
214  std::unique_ptr<mir::protobuf::Surface> const surface;
215  std::unique_ptr<mir::protobuf::PersistentSurfaceId> const persistent_id;
216  std::string const error_message;
217  std::string const name;
218  std::unique_ptr<mir::protobuf::Void> const void_response;
219 
220  void on_modified();
221  MirWaitHandle modify_wait_handle;
222  std::unique_ptr<mir::protobuf::Void> const modify_result;
223 
224  MirConnection* const connection_;
225 
226  MirWaitHandle configure_wait_handle;
227  MirWaitHandle configure_cursor_wait_handle;
228  MirWaitHandle persistent_id_wait_handle;
229 
230  std::shared_ptr<mir::client::ClientBufferStream> buffer_stream;
231  std::shared_ptr<mir::input::receiver::InputPlatform> const input_platform;
232  std::shared_ptr<mir::input::receiver::XKBMapper> const keymapper;
233 
234  std::unique_ptr<mir::protobuf::SurfaceSetting> const configure_result;
235 
236  // Cache of latest SurfaceSettings returned from the server
237  int attrib_cache[mir_surface_attribs];
239 
240  std::function<void(MirEvent const*)> handle_event_callback;
241  std::shared_ptr<mir::dispatch::ThreadedDispatcher> input_thread;
242  bool auto_resize_stream{true};
243 
244  //a bit batty, but the creation handle has to exist for as long as the MirSurface does,
245  //as we don't really manage the lifetime of MirWaitHandle sensibly.
246  std::shared_ptr<MirWaitHandle> const creation_handle;
247 };
248 
249 #endif /* MIR_CLIENT_PRIVATE_MIR_WAIT_HANDLE_H_ */
All things Mir.
Definition: atomic_callback.h:25
mir::geometry::Displacement displacement
Definition: mir_surface.h:81
mir::optional_value< AspectRatio > min_aspect
Definition: mir_surface.h:121
Definition: mir_surface.h:79
Definition: mir_surface.h:86
mir_surface_event_callback callback
Definition: mir_surface.h:128
Definition: mir_surface.h:146
void(* mir_surface_id_callback)(MirSurface *surface, MirPersistentId *id, void *context)
Definition: client_types.h:148
void * context
Definition: mir_surface.h:129
void(* mir_surface_event_callback)(MirSurface *surface, MirEvent const *event, void *context)
Callback for handling of surface events.
Definition: client_types.h:101
Definition: mir_surface.h:92
Definition: mir_wait_handle.h:31
Definition: common.h:45
mir::optional_value< int > max_height
Definition: mir_surface.h:118
mir::optional_value< MirBufferUsage > buffer_usage
Definition: mir_surface.h:101
std::shared_ptr< MirPersistentId > parent_id
Definition: mir_surface.h:111
mir::optional_value< int > width
Definition: mir_surface.h:98
mir::optional_value< EventHandler > event_handler
Definition: mir_surface.h:131
mir::optional_value< mir::geometry::Size > size
Definition: mir_surface.h:83
mir::optional_value< uint32_t > output_id
Definition: mir_surface.h:104
Definition: common.h:166
mir::optional_value< MirSurfaceType > type
Definition: mir_surface.h:106
mir::optional_value< MirEdgeAttachment > edge_attachment
Definition: mir_surface.h:113
MirOrientation
Direction relative to the "natural" orientation of the display.
Definition: common.h:164
struct MirPersistentId MirPersistentId
Definition: client_types.h:46
mir::optional_value< int > width_inc
Definition: mir_surface.h:119
Definition: mir_surface.h:135
struct MirSurface MirSurface
Definition: client_types.h:41
Definition: mir_display_server_debug.h:32
unsigned width
Definition: mir_surface.h:92
mir::optional_value< int > height_inc
Definition: mir_surface.h:120
mir::optional_value< int > min_width
Definition: mir_surface.h:115
mir::optional_value< MirRectangle > aux_rect
Definition: mir_surface.h:112
MirSurfaceAttrib
Attributes of a surface that the client and server/shell may wish to get or set over the wire...
Definition: common.h:34
unsigned int width
Definition: touchspot_image.c:4
MirPixelFormat
32-bit pixel formats (8888): The order of components in the enum matches the order of the components ...
Definition: common.h:134
Definition: displacement.h:32
Definition: cursor_configuration.h:34
struct MirSurfaceSpec MirSurfaceSpec
Definition: client_types.h:42
mir::optional_value< AspectRatio > max_aspect
Definition: mir_surface.h:122
mir::optional_value< std::vector< MirRectangle > > input_shape
Definition: mir_surface.h:124
mir::optional_value< MirOrientationMode > pref_orientation
Definition: mir_surface.h:108
mir::optional_value< std::string > surface_name
Definition: mir_surface.h:103
mir::optional_value< MirPixelFormat > pixel_format
Definition: mir_surface.h:100
Definition: client_buffer_stream.h:69
Definition: mir_surface.h:126
void configure_cursor(MirSurface *surface, unsigned int cursor_index)
Definition: cursors_demo_client.c:28
mir::optional_value< int > height
Definition: mir_surface.h:99
unsigned int height
Definition: touchspot_image.c:5
Definition: mir_connection.h:96
Definition: event_private.h:181
mir::optional_value< std::vector< ContentInfo > > streams
Definition: mir_surface.h:123
MirOrientationMode
Definition: common.h:172
Definition: dispatchable.h:33
int stream_id
Definition: mir_surface.h:82
mir::optional_value< MirShellChrome > shell_chrome
Definition: mir_surface.h:132
mir::optional_value< int > max_width
Definition: mir_surface.h:117
mir::optional_value< MirSurfaceState > state
Definition: mir_surface.h:107
Definition: mir_display_server.h:33
MirSurfaceParameters is the structure of minimum required information that you must provide to Mir in...
Definition: client_types.h:166
mir::optional_value< MirSurface * > parent
Definition: mir_surface.h:110
mir::optional_value< int > min_height
Definition: mir_surface.h:116

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016