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 
126 
128  {
130  void* context;
131  };
134 };
135 
137 {
138 public:
139  MirPersistentId(std::string const& string_id);
140 
141  std::string const& as_string();
142 
143 private:
144  std::string const string_id;
145 };
146 
148 {
149 public:
150  MirSurface(MirSurface const &) = delete;
151  MirSurface& operator=(MirSurface const &) = delete;
152 
153  MirSurface(
154  std::string const& error,
155  MirConnection *allocating_connection,
156  mir::frontend::SurfaceId surface_id,
157  std::shared_ptr<MirWaitHandle> const& handle);
158 
159  MirSurface(
160  MirConnection *allocating_connection,
163  std::shared_ptr<mir::client::ClientBufferStream> const& buffer_stream,
164  std::shared_ptr<mir::input::receiver::InputPlatform> const& input_platform,
165  MirSurfaceSpec const& spec, mir::protobuf::Surface const& surface_proto,
166  std::shared_ptr<MirWaitHandle> const& handle);
167 
168  ~MirSurface();
169 
170  MirSurfaceParameters get_parameters() const;
171  char const * get_error_message();
172  int id() const;
173 
174  MirWaitHandle* configure(MirSurfaceAttrib a, int value);
175 
176  // TODO: Some sort of extension mechanism so that this can be moved
177  // out into a separate class in the libmirclient-debug DSO.
178  bool translate_to_screen_coordinates(int x, int y,
179  int* screen_x, int* screen_y);
180 
181  // Non-blocking
182  int attrib(MirSurfaceAttrib a) const;
183 
184  MirOrientation get_orientation() const;
185  MirWaitHandle* set_preferred_orientation(MirOrientationMode mode);
186 
187  void raise_surface(MirCookie const* cookie);
188 
190 
191  void set_event_handler(mir_surface_event_callback callback,
192  void* context);
193  void handle_event(MirEvent const& e);
194 
195  void request_and_wait_for_configure(MirSurfaceAttrib a, int value);
196 
197  mir::client::ClientBufferStream* get_buffer_stream();
198 
199  MirWaitHandle* modify(MirSurfaceSpec const& changes);
200 
201  static bool is_valid(MirSurface* query);
202 
203  MirWaitHandle* request_persistent_id(mir_surface_id_callback callback, void* context);
204  MirConnection* connection() const;
205 private:
206  std::mutex mutable mutex; // Protects all members of *this
207 
208  void on_configured();
209  void on_cursor_configured();
210  void acquired_persistent_id(mir_surface_id_callback callback, void* context);
211  MirPixelFormat convert_ipc_pf_to_geometry(google::protobuf::int32 pf) const;
212 
213  mir::client::rpc::DisplayServer* const server{nullptr};
214  mir::client::rpc::DisplayServerDebug* const debug{nullptr};
215  std::unique_ptr<mir::protobuf::Surface> const surface;
216  std::unique_ptr<mir::protobuf::PersistentSurfaceId> const persistent_id;
217  std::string const error_message;
218  std::string const name;
219  std::unique_ptr<mir::protobuf::Void> const void_response;
220 
221  void on_modified();
222  MirWaitHandle modify_wait_handle;
223  std::unique_ptr<mir::protobuf::Void> const modify_result;
224 
225  MirConnection* const connection_;
226 
227  MirWaitHandle configure_wait_handle;
228  MirWaitHandle configure_cursor_wait_handle;
229  MirWaitHandle persistent_id_wait_handle;
230 
231  //Deprecated functions can cause MirSurfaces to be created with a default stream
232  std::shared_ptr<mir::client::ClientBufferStream> default_stream;
233  std::shared_ptr<mir::input::receiver::InputPlatform> const input_platform;
234  std::shared_ptr<mir::input::receiver::XKBMapper> const keymapper;
235 
236  std::unique_ptr<mir::protobuf::SurfaceSetting> const configure_result;
237 
238  // Cache of latest SurfaceSettings returned from the server
239  int attrib_cache[mir_surface_attribs];
241 
242  std::function<void(MirEvent const*)> handle_event_callback;
243  std::shared_ptr<mir::dispatch::ThreadedDispatcher> input_thread;
244 
245  //a bit batty, but the creation handle has to exist for as long as the MirSurface does,
246  //as we don't really manage the lifetime of MirWaitHandle sensibly.
247  std::shared_ptr<MirWaitHandle> const creation_handle;
249  MirPixelFormat format;
250  MirBufferUsage usage;
251  uint32_t output_id;
252 
253 };
254 
255 #endif /* MIR_CLIENT_PRIVATE_MIR_WAIT_HANDLE_H_ */
Definition: size.h:30
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:129
Definition: mir_surface.h:147
void(* mir_surface_id_callback)(MirSurface *surface, MirPersistentId *id, void *context)
Definition: client_types.h:151
void * context
Definition: mir_surface.h:130
void(* mir_surface_event_callback)(MirSurface *surface, MirEvent const *event, void *context)
Callback for handling of surface events.
Definition: client_types.h:104
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:132
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< bool > confine_pointer
Definition: mir_surface.h:125
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:47
mir::optional_value< int > width_inc
Definition: mir_surface.h:119
Definition: mir_surface.h:136
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
MirBufferUsage
MirBufferUsage specifies how a surface can and will be used.
Definition: client_types.h:159
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:68
Definition: mir_surface.h:127
void configure_cursor(MirSurface *surface, unsigned int cursor_index)
Definition: cursors_demo_client.c:29
mir::optional_value< int > height
Definition: mir_surface.h:99
unsigned int height
Definition: touchspot_image.c:5
Definition: mir_connection.h:96
mir::optional_value< std::vector< ContentInfo > > streams
Definition: mir_surface.h:123
MirOrientationMode
Definition: common.h:180
Definition: dispatchable.h:33
int stream_id
Definition: mir_surface.h:82
mir::optional_value< MirShellChrome > shell_chrome
Definition: mir_surface.h:133
int const size
Definition: make_socket_rpc_channel.cpp:51
mir::optional_value< int > max_width
Definition: mir_surface.h:117
Definition: event.h:30
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:169
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 Thu Sep 8 14:50:19 UTC 2016