Merge lp:~afrantzis/mir/platform-operation-client-api-remove-opcode into lp:mir/0.11
- platform-operation-client-api-remove-opcode
- Merge into 0.11
Proposed by
Alexandros Frantzis
Status: | Superseded |
---|---|
Proposed branch: | lp:~afrantzis/mir/platform-operation-client-api-remove-opcode |
Merge into: | lp:mir/0.11 |
Diff against target: |
875 lines (+313/-159) 21 files modified
client-ABI-sha1sums (+1/-1) include/client/mir_toolkit/mir_connection.h (+1/-2) src/client/mir_connection.cpp (+9/-22) src/client/mir_connection.h (+0/-9) src/client/mir_connection_api.cpp (+37/-14) src/include/client/mir/client_platform.h (+11/-0) src/platforms/android/client/android_client_platform.cpp (+6/-0) src/platforms/android/client/android_client_platform.h (+1/-1) src/platforms/mesa/client/client_platform.cpp (+46/-1) src/platforms/mesa/client/client_platform.h (+4/-0) src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h (+19/-2) src/server/graphics/nested/mir_client_host_connection.cpp (+1/-1) tests/acceptance-tests/CMakeLists.txt (+0/-1) tests/acceptance-tests/test_client_library_drm.cpp (+0/-46) tests/acceptance-tests/test_client_library_errors.cpp (+5/-0) tests/acceptance-tests/test_client_platform_operation.cpp (+2/-2) tests/include/mir_test_framework/client_platform_factory.h (+3/-9) tests/mir_test_framework/stub_client_platform_factory.cpp (+5/-0) tests/unit-tests/client/mesa/test_client_platform.cpp (+77/-6) tests/unit-tests/client/test_client_mir_surface.cpp (+6/-0) tests/unit-tests/client/test_mir_connection.cpp (+79/-42) |
To merge this branch: | bzr merge lp:~afrantzis/mir/platform-operation-client-api-remove-opcode |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir development team | Pending | ||
Review via email: mp+248255@code.launchpad.net |
This proposal has been superseded by a proposal from 2015-02-02.
Commit message
client: Remove redundant opcode parameter from platform operation API
Description of the change
client: Remove redundant opcode parameter from platform operation API
During development/
This is a client API/ABI break, but since the platform operation API is not currently used by external code (and could not have been used because we didn't expose any operations), we can get away with it.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'client-ABI-sha1sums' |
2 | --- client-ABI-sha1sums 2015-01-29 04:34:12 +0000 |
3 | +++ client-ABI-sha1sums 2015-02-02 14:38:00 +0000 |
4 | @@ -1,7 +1,7 @@ |
5 | afd66e984f4f8c0303fd25fb6fea32fa47bbd37f include/client/mir_toolkit/debug/surface.h |
6 | b53736bcb22ddc09aab8275cfdd05c109fdd0f12 include/client/mir_toolkit/mir_client_library_drm.h |
7 | 532af89e0f48d8d2a7cf01621db25d3338ae3abf include/client/mir_toolkit/mir_client_library.h |
8 | -750aa35e6a5173bcba47cb524c508d05a4df746c include/client/mir_toolkit/mir_connection.h |
9 | +615df675ffba805fb0594e19fb006f514f2100a7 include/client/mir_toolkit/mir_connection.h |
10 | 1ef8f51a3e3f8d1559266c5af58fbfde7cfabf0a include/client/mir_toolkit/mir_cursor_configuration.h |
11 | d739af6e64db6b314a727b5fb00be662b98ccd57 include/client/mir_toolkit/mir_platform_message.h |
12 | 9d50df5a141ca03ee8a79f7e844ed4b8b3b7d5d3 include/client/mir_toolkit/mir_prompt_session.h |
13 | |
14 | === modified file 'include/client/mir_toolkit/mir_connection.h' |
15 | --- include/client/mir_toolkit/mir_connection.h 2015-01-14 06:39:13 +0000 |
16 | +++ include/client/mir_toolkit/mir_connection.h 2015-02-02 14:38:00 +0000 |
17 | @@ -178,14 +178,13 @@ |
18 | * until this operation finishes. |
19 | * |
20 | * \param [in] connection The connection |
21 | - * \param [in] opcode The opcode of the operation to perform |
22 | * \param [in] request The message used for this operation |
23 | * \param [in] callback The callback to call when the operation finishes |
24 | * \param [in,out] context User data passed to the callback function |
25 | * \return A handle that can be passed to mir_wait_for |
26 | */ |
27 | MirWaitHandle* mir_connection_platform_operation( |
28 | - MirConnection* connection, unsigned int opcode, |
29 | + MirConnection* connection, |
30 | MirPlatformMessage const* request, |
31 | mir_platform_operation_callback callback, void* context); |
32 | |
33 | |
34 | === modified file 'src/client/mir_connection.cpp' |
35 | --- src/client/mir_connection.cpp 2015-01-30 14:24:06 +0000 |
36 | +++ src/client/mir_connection.cpp 2015-02-02 14:38:00 +0000 |
37 | @@ -357,13 +357,20 @@ |
38 | } |
39 | |
40 | MirWaitHandle* MirConnection::platform_operation( |
41 | - unsigned int opcode, |
42 | MirPlatformMessage const* request, |
43 | mir_platform_operation_callback callback, void* context) |
44 | { |
45 | + auto const client_response = platform->platform_operation(request); |
46 | + if (client_response) |
47 | + { |
48 | + set_error_message(""); |
49 | + callback(this, client_response, context); |
50 | + return nullptr; |
51 | + } |
52 | + |
53 | mir::protobuf::PlatformOperationMessage protobuf_request; |
54 | |
55 | - protobuf_request.set_opcode(opcode); |
56 | + protobuf_request.set_opcode(mir_platform_message_get_opcode(request)); |
57 | auto const request_data = mir_platform_message_get_data(request); |
58 | auto const request_fds = mir_platform_message_get_fds(request); |
59 | |
60 | @@ -420,11 +427,6 @@ |
61 | platform_package.fd_items = platform.fd_size(); |
62 | for (int i = 0; i != platform.fd_size(); ++i) |
63 | platform_package.fd[i] = platform.fd(i); |
64 | - |
65 | - // TODO: Replace the extra platform data mechanism with a |
66 | - // client side, platform specific operation |
67 | - for (auto d : extra_platform_data) |
68 | - platform_package.data[platform_package.data_items++] = d; |
69 | } |
70 | else |
71 | { |
72 | @@ -567,21 +569,6 @@ |
73 | return &configure_display_wait_handle; |
74 | } |
75 | |
76 | -bool MirConnection::set_extra_platform_data( |
77 | - std::vector<int> const& extra_platform_data_arg) |
78 | -{ |
79 | - std::lock_guard<decltype(mutex)> lock(mutex); |
80 | - |
81 | - auto const total_data_size = |
82 | - connect_result.platform().data_size() + extra_platform_data_arg.size(); |
83 | - |
84 | - if (total_data_size > mir_platform_package_max) |
85 | - return false; |
86 | - |
87 | - extra_platform_data = extra_platform_data_arg; |
88 | - return true; |
89 | -} |
90 | - |
91 | mir::protobuf::DisplayServer& MirConnection::display_server() |
92 | { |
93 | return server; |
94 | |
95 | === modified file 'src/client/mir_connection.h' |
96 | --- src/client/mir_connection.h 2015-01-30 14:24:06 +0000 |
97 | +++ src/client/mir_connection.h 2015-02-02 14:38:00 +0000 |
98 | @@ -107,12 +107,7 @@ |
99 | |
100 | MirWaitHandle* disconnect(); |
101 | |
102 | - MirWaitHandle* drm_auth_magic(unsigned int magic, |
103 | - mir_drm_auth_magic_callback callback, |
104 | - void* context); |
105 | - |
106 | MirWaitHandle* platform_operation( |
107 | - unsigned int opcode, |
108 | MirPlatformMessage const* request, |
109 | mir_platform_operation_callback callback, void* context); |
110 | |
111 | @@ -137,8 +132,6 @@ |
112 | MirWaitHandle* configure_display(MirDisplayConfiguration* configuration); |
113 | void done_display_configure(); |
114 | |
115 | - bool set_extra_platform_data(std::vector<int> const& extra_platform_data); |
116 | - |
117 | std::shared_ptr<google::protobuf::RpcChannel> rpc_channel() const |
118 | { |
119 | return channel; |
120 | @@ -197,8 +190,6 @@ |
121 | std::shared_ptr<mir::client::EventHandlerRegister> const event_handler_register; |
122 | |
123 | std::unique_ptr<mir::dispatch::SimpleDispatchThread> const eventloop; |
124 | - |
125 | - std::vector<int> extra_platform_data; |
126 | |
127 | std::shared_ptr<mir::client::ClientBufferStreamFactory> buffer_stream_factory; |
128 | |
129 | |
130 | === modified file 'src/client/mir_connection_api.cpp' |
131 | --- src/client/mir_connection_api.cpp 2015-01-26 15:53:18 +0000 |
132 | +++ src/client/mir_connection_api.cpp 2015-02-02 14:38:00 +0000 |
133 | @@ -51,11 +51,6 @@ |
134 | *context = result; |
135 | } |
136 | |
137 | -size_t division_ceiling(size_t a, size_t b) |
138 | -{ |
139 | - return ((a - 1) / b) + 1; |
140 | -} |
141 | - |
142 | class DefaultMirConnectionAPI : public mcl::MirConnectionAPI |
143 | { |
144 | public: |
145 | @@ -311,13 +306,13 @@ |
146 | } |
147 | |
148 | MirWaitHandle* mir_connection_platform_operation( |
149 | - MirConnection* connection, unsigned int opcode, |
150 | + MirConnection* connection, |
151 | MirPlatformMessage const* request, |
152 | mir_platform_operation_callback callback, void* context) |
153 | { |
154 | try |
155 | { |
156 | - return connection->platform_operation(opcode, request, callback, context); |
157 | + return connection->platform_operation(request, callback, context); |
158 | } |
159 | catch (std::exception const& ex) |
160 | { |
161 | @@ -356,6 +351,21 @@ |
162 | auth_magic_context->callback(auth_response->status, auth_magic_context->context); |
163 | } |
164 | |
165 | +void assign_set_gbm_device_status( |
166 | + MirConnection*, MirPlatformMessage* response, void* context) |
167 | +{ |
168 | + auto const response_msg = mir::raii::deleter_for( |
169 | + response, |
170 | + &mir_platform_message_release); |
171 | + |
172 | + auto const response_data = mir_platform_message_get_data(response_msg.get()); |
173 | + auto const set_gbm_device_response_ptr = |
174 | + reinterpret_cast<MirMesaSetGBMDeviceResponse const*>(response_data.data); |
175 | + |
176 | + auto status_ptr = static_cast<int*>(context); |
177 | + *status_ptr = set_gbm_device_response_ptr->status; |
178 | +} |
179 | + |
180 | } |
181 | |
182 | MirWaitHandle* mir_connection_drm_auth_magic(MirConnection* connection, |
183 | @@ -377,7 +387,6 @@ |
184 | |
185 | return mir_connection_platform_operation( |
186 | connection, |
187 | - MirMesaPlatformOperation::auth_magic, |
188 | msg.get(), |
189 | platform_operation_to_auth_magic_callback, |
190 | auth_magic_op_context); |
191 | @@ -386,10 +395,24 @@ |
192 | int mir_connection_drm_set_gbm_device(MirConnection* connection, |
193 | struct gbm_device* gbm_dev) |
194 | { |
195 | - size_t const pointer_size_in_ints = division_ceiling(sizeof(gbm_dev), sizeof(int)); |
196 | - std::vector<int> extra_data(pointer_size_in_ints); |
197 | - |
198 | - memcpy(extra_data.data(), &gbm_dev, sizeof(gbm_dev)); |
199 | - |
200 | - return connection->set_extra_platform_data(extra_data); |
201 | + MirMesaSetGBMDeviceRequest const request{gbm_dev}; |
202 | + |
203 | + auto const msg = mir::raii::deleter_for( |
204 | + mir_platform_message_create(MirMesaPlatformOperation::set_gbm_device), |
205 | + &mir_platform_message_release); |
206 | + |
207 | + mir_platform_message_set_data(msg.get(), &request, sizeof(request)); |
208 | + |
209 | + static int const success{0}; |
210 | + int status{-1}; |
211 | + |
212 | + auto wh = mir_connection_platform_operation( |
213 | + connection, |
214 | + msg.get(), |
215 | + assign_set_gbm_device_status, |
216 | + &status); |
217 | + |
218 | + mir_wait_for(wh); |
219 | + |
220 | + return status == success; |
221 | } |
222 | |
223 | === modified file 'src/include/client/mir/client_platform.h' |
224 | --- src/include/client/mir/client_platform.h 2015-01-29 14:57:00 +0000 |
225 | +++ src/include/client/mir/client_platform.h 2015-02-02 14:38:00 +0000 |
226 | @@ -49,6 +49,17 @@ |
227 | |
228 | virtual MirPlatformType platform_type() const = 0; |
229 | virtual void populate(MirPlatformPackage& package) const = 0; |
230 | + /** |
231 | + * Perform a platform operation. |
232 | + * |
233 | + * The returned platform message is owned by the caller and should be |
234 | + * released with mir_platform_message_release(). |
235 | + * |
236 | + * \param [in] request The platform operation request |
237 | + * \return The platform operation reply, or a nullptr if the |
238 | + * requested operation is not supported |
239 | + */ |
240 | + virtual MirPlatformMessage* platform_operation(MirPlatformMessage const* request) = 0; |
241 | virtual std::shared_ptr<ClientBufferFactory> create_buffer_factory() = 0; |
242 | virtual std::shared_ptr<EGLNativeWindowType> create_egl_native_window(EGLNativeSurface *surface) = 0; |
243 | virtual std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() = 0; |
244 | |
245 | === modified file 'src/platforms/android/client/android_client_platform.cpp' |
246 | --- src/platforms/android/client/android_client_platform.cpp 2015-01-29 14:57:00 +0000 |
247 | +++ src/platforms/android/client/android_client_platform.cpp 2015-02-02 14:38:00 +0000 |
248 | @@ -112,6 +112,12 @@ |
249 | context->populate_server_package(package); |
250 | } |
251 | |
252 | +MirPlatformMessage* mcla::AndroidClientPlatform::platform_operation( |
253 | + MirPlatformMessage const*) |
254 | +{ |
255 | + return nullptr; |
256 | +} |
257 | + |
258 | MirNativeBuffer* mcla::AndroidClientPlatform::convert_native_buffer(graphics::NativeBuffer* buf) const |
259 | { |
260 | return buf->anwb(); |
261 | |
262 | === modified file 'src/platforms/android/client/android_client_platform.h' |
263 | --- src/platforms/android/client/android_client_platform.h 2015-01-30 14:25:39 +0000 |
264 | +++ src/platforms/android/client/android_client_platform.h 2015-02-02 14:38:00 +0000 |
265 | @@ -35,6 +35,7 @@ |
266 | AndroidClientPlatform(ClientContext* const context); |
267 | MirPlatformType platform_type() const override; |
268 | void populate(MirPlatformPackage& package) const override; |
269 | + MirPlatformMessage* platform_operation(MirPlatformMessage const* request) override; |
270 | std::shared_ptr<ClientBufferFactory> create_buffer_factory() override; |
271 | std::shared_ptr<EGLNativeWindowType> create_egl_native_window(EGLNativeSurface *surface) override; |
272 | std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() override; |
273 | @@ -42,7 +43,6 @@ |
274 | |
275 | private: |
276 | ClientContext* const context; |
277 | - |
278 | }; |
279 | |
280 | } |
281 | |
282 | === modified file 'src/platforms/mesa/client/client_platform.cpp' |
283 | --- src/platforms/mesa/client/client_platform.cpp 2015-01-29 14:57:00 +0000 |
284 | +++ src/platforms/mesa/client/client_platform.cpp 2015-02-02 14:38:00 +0000 |
285 | @@ -23,6 +23,9 @@ |
286 | #include "native_surface.h" |
287 | #include "mir/client_buffer_factory.h" |
288 | #include "mir/client_context.h" |
289 | +#include "mir_toolkit/mesa/platform_operation.h" |
290 | + |
291 | +#include <cstring> |
292 | |
293 | namespace mcl=mir::client; |
294 | namespace mclm=mir::client::mesa; |
295 | @@ -47,6 +50,11 @@ |
296 | mcl::EGLNativeDisplayContainer& container; |
297 | }; |
298 | |
299 | +constexpr size_t division_ceiling(size_t a, size_t b) |
300 | +{ |
301 | + return ((a - 1) / b) + 1; |
302 | +} |
303 | + |
304 | } |
305 | |
306 | mclm::ClientPlatform::ClientPlatform( |
307 | @@ -55,7 +63,8 @@ |
308 | mcl::EGLNativeDisplayContainer& display_container) |
309 | : context{context}, |
310 | buffer_file_ops{buffer_file_ops}, |
311 | - display_container(display_container) |
312 | + display_container(display_container), |
313 | + gbm_dev{nullptr} |
314 | { |
315 | } |
316 | |
317 | @@ -108,7 +117,43 @@ |
318 | |
319 | void mclm::ClientPlatform::populate(MirPlatformPackage& package) const |
320 | { |
321 | + size_t constexpr pointer_size_in_ints = division_ceiling(sizeof(gbm_dev), sizeof(int)); |
322 | + |
323 | context->populate_server_package(package); |
324 | + |
325 | + auto const total_data_size = package.data_items + pointer_size_in_ints; |
326 | + if (gbm_dev && total_data_size <= mir_platform_package_max) |
327 | + { |
328 | + int gbm_ptr[pointer_size_in_ints]{}; |
329 | + std::memcpy(&gbm_ptr, &gbm_dev, sizeof(gbm_dev)); |
330 | + |
331 | + for (auto i : gbm_ptr) |
332 | + package.data[package.data_items++] = i; |
333 | + } |
334 | +} |
335 | + |
336 | +MirPlatformMessage* mclm::ClientPlatform::platform_operation( |
337 | + MirPlatformMessage const* msg) |
338 | +{ |
339 | + auto const op = mir_platform_message_get_opcode(msg); |
340 | + |
341 | + if (op == MirMesaPlatformOperation::set_gbm_device) |
342 | + { |
343 | + auto const msg_data = mir_platform_message_get_data(msg); |
344 | + auto const set_gbm_device_request_ptr = |
345 | + reinterpret_cast<MirMesaSetGBMDeviceRequest const*>(msg_data.data); |
346 | + |
347 | + gbm_dev = set_gbm_device_request_ptr->device; |
348 | + |
349 | + static int const success{0}; |
350 | + MirMesaSetGBMDeviceResponse const response{success}; |
351 | + auto const response_msg = mir_platform_message_create(op); |
352 | + mir_platform_message_set_data(response_msg, &response, sizeof(response)); |
353 | + |
354 | + return response_msg; |
355 | + } |
356 | + |
357 | + return nullptr; |
358 | } |
359 | |
360 | MirNativeBuffer* mclm::ClientPlatform::convert_native_buffer(graphics::NativeBuffer* buf) const |
361 | |
362 | === modified file 'src/platforms/mesa/client/client_platform.h' |
363 | --- src/platforms/mesa/client/client_platform.h 2015-01-30 14:25:39 +0000 |
364 | +++ src/platforms/mesa/client/client_platform.h 2015-02-02 14:38:00 +0000 |
365 | @@ -20,6 +20,8 @@ |
366 | |
367 | #include "mir/client_platform.h" |
368 | |
369 | +struct gbm_device; |
370 | + |
371 | namespace mir |
372 | { |
373 | namespace client |
374 | @@ -41,6 +43,7 @@ |
375 | |
376 | MirPlatformType platform_type() const override; |
377 | void populate(MirPlatformPackage& package) const override; |
378 | + MirPlatformMessage* platform_operation(MirPlatformMessage const* request) override; |
379 | std::shared_ptr<ClientBufferFactory> create_buffer_factory() override; |
380 | std::shared_ptr<EGLNativeWindowType> create_egl_native_window(EGLNativeSurface *surface) override; |
381 | std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() override; |
382 | @@ -50,6 +53,7 @@ |
383 | ClientContext* const context; |
384 | std::shared_ptr<BufferFileOps> const buffer_file_ops; |
385 | EGLNativeDisplayContainer& display_container; |
386 | + gbm_device* gbm_dev; |
387 | }; |
388 | |
389 | } |
390 | |
391 | === modified file 'src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h' |
392 | --- src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h 2015-01-27 14:59:08 +0000 |
393 | +++ src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h 2015-02-02 14:38:00 +0000 |
394 | @@ -35,7 +35,8 @@ |
395 | enum MirMesaPlatformOperation |
396 | { |
397 | auth_magic = 1, |
398 | - auth_fd = 2 |
399 | + auth_fd = 2, |
400 | + set_gbm_device = 3 |
401 | }; |
402 | |
403 | /* |
404 | @@ -49,7 +50,23 @@ |
405 | |
406 | struct MirMesaAuthMagicResponse |
407 | { |
408 | - int status; |
409 | + int status; /* 0 on success, a positive error number on failure */ |
410 | +}; |
411 | + |
412 | +/* |
413 | + * MesaPlatformOperation::set_gbm_device related structures |
414 | + */ |
415 | + |
416 | +struct gbm_device; |
417 | + |
418 | +struct MirMesaSetGBMDeviceRequest |
419 | +{ |
420 | + struct gbm_device* device; |
421 | +}; |
422 | + |
423 | +struct MirMesaSetGBMDeviceResponse |
424 | +{ |
425 | + int status; /* 0 on success, a positive error number on failure */ |
426 | }; |
427 | |
428 | #ifdef __cplusplus |
429 | |
430 | === modified file 'src/server/graphics/nested/mir_client_host_connection.cpp' |
431 | --- src/server/graphics/nested/mir_client_host_connection.cpp 2015-01-26 15:53:18 +0000 |
432 | +++ src/server/graphics/nested/mir_client_host_connection.cpp 2015-02-02 14:38:00 +0000 |
433 | @@ -185,7 +185,7 @@ |
434 | MirPlatformMessage* raw_reply{nullptr}; |
435 | |
436 | auto const wh = mir_connection_platform_operation( |
437 | - mir_connection, op, msg.get(), platform_operation_callback, &raw_reply); |
438 | + mir_connection, msg.get(), platform_operation_callback, &raw_reply); |
439 | mir_wait_for(wh); |
440 | |
441 | auto const reply = mir::raii::deleter_for( |
442 | |
443 | === modified file 'tests/acceptance-tests/CMakeLists.txt' |
444 | --- tests/acceptance-tests/CMakeLists.txt 2015-01-19 06:55:41 +0000 |
445 | +++ tests/acceptance-tests/CMakeLists.txt 2015-02-02 14:38:00 +0000 |
446 | @@ -25,7 +25,6 @@ |
447 | test_display_configuration.cpp |
448 | test_surfaces_with_output_id.cpp |
449 | test_server_disconnect.cpp |
450 | - test_client_library_drm.cpp |
451 | test_prompt_session_client_api.cpp |
452 | test_client_screencast.cpp |
453 | test_client_surface_visibility.cpp |
454 | |
455 | === removed file 'tests/acceptance-tests/test_client_library_drm.cpp' |
456 | --- tests/acceptance-tests/test_client_library_drm.cpp 2015-01-14 06:39:13 +0000 |
457 | +++ tests/acceptance-tests/test_client_library_drm.cpp 1970-01-01 00:00:00 +0000 |
458 | @@ -1,46 +0,0 @@ |
459 | -/* |
460 | - * Copyright © 2013-2014 Canonical Ltd. |
461 | - * |
462 | - * This program is free software: you can redistribute it and/or modify |
463 | - * it under the terms of the GNU General Public License version 3 as |
464 | - * published by the Free Software Foundation. |
465 | - * |
466 | - * This program is distributed in the hope that it will be useful, |
467 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
468 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
469 | - * GNU General Public License for more details. |
470 | - * |
471 | - * You should have received a copy of the GNU General Public License |
472 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
473 | - * |
474 | - * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com> |
475 | - */ |
476 | - |
477 | -#include "mir_toolkit/mir_client_library_drm.h" |
478 | - |
479 | -#include "mir_test_framework/connected_client_headless_server.h" |
480 | - |
481 | -#include <gtest/gtest.h> |
482 | -#include <gmock/gmock.h> |
483 | - |
484 | -namespace mtf = mir_test_framework; |
485 | -using namespace testing; |
486 | - |
487 | -using MirClientLibraryDrmTest = mtf::ConnectedClientHeadlessServer; |
488 | - |
489 | -TEST_F(MirClientLibraryDrmTest, sets_gbm_device_in_platform_data) |
490 | -{ |
491 | - struct gbm_device* dev = reinterpret_cast<struct gbm_device*>(connection); |
492 | - |
493 | - MirPlatformPackage pkg; |
494 | - |
495 | - mir_connection_get_platform(connection, &pkg); |
496 | - int const previous_data_count{pkg.data_items}; |
497 | - |
498 | - mir_connection_drm_set_gbm_device(connection, dev); |
499 | - mir_connection_get_platform(connection, &pkg); |
500 | - |
501 | - EXPECT_THAT(pkg.data_items, Eq(previous_data_count + (sizeof(dev) / sizeof(int)))); |
502 | - EXPECT_THAT(reinterpret_cast<struct gbm_device*>(pkg.data[previous_data_count]), |
503 | - Eq(dev)); |
504 | -} |
505 | |
506 | === modified file 'tests/acceptance-tests/test_client_library_errors.cpp' |
507 | --- tests/acceptance-tests/test_client_library_errors.cpp 2015-01-29 14:57:00 +0000 |
508 | +++ tests/acceptance-tests/test_client_library_errors.cpp 2015-02-02 14:38:00 +0000 |
509 | @@ -77,6 +77,11 @@ |
510 | { |
511 | } |
512 | |
513 | + MirPlatformMessage* platform_operation(MirPlatformMessage const*) override |
514 | + { |
515 | + return nullptr; |
516 | + } |
517 | + |
518 | MirPlatformType platform_type() const |
519 | { |
520 | BOOST_THROW_EXCEPTION(std::runtime_error{exception_text}); |
521 | |
522 | === modified file 'tests/acceptance-tests/test_client_platform_operation.cpp' |
523 | --- tests/acceptance-tests/test_client_platform_operation.cpp 2014-12-11 08:54:04 +0000 |
524 | +++ tests/acceptance-tests/test_client_platform_operation.cpp 2015-02-02 14:38:00 +0000 |
525 | @@ -39,7 +39,7 @@ |
526 | MirPlatformMessage* reply; |
527 | |
528 | auto const platform_op_done = mir_connection_platform_operation( |
529 | - connection, add_opcode, request, assign_reply, &reply); |
530 | + connection, request, assign_reply, &reply); |
531 | mir_wait_for(platform_op_done); |
532 | |
533 | mir_platform_message_release(request); |
534 | @@ -57,7 +57,7 @@ |
535 | MirPlatformMessage* reply; |
536 | |
537 | auto const platform_op_done = mir_connection_platform_operation( |
538 | - connection, echo_fd_opcode, request, assign_reply, &reply); |
539 | + connection, request, assign_reply, &reply); |
540 | mir_wait_for(platform_op_done); |
541 | |
542 | mir_platform_message_release(request); |
543 | |
544 | === modified file 'tests/include/mir_test_framework/client_platform_factory.h' |
545 | --- tests/include/mir_test_framework/client_platform_factory.h 2015-01-29 14:57:00 +0000 |
546 | +++ tests/include/mir_test_framework/client_platform_factory.h 2015-02-02 14:38:00 +0000 |
547 | @@ -42,19 +42,13 @@ |
548 | return platform_factory(&ctx); |
549 | } |
550 | |
551 | -std::shared_ptr<mir::client::ClientPlatform> create_mesa_client_platform() |
552 | +std::shared_ptr<mir::client::ClientPlatform> create_mesa_client_platform( |
553 | + mir::client::ClientContext* client_context) |
554 | { |
555 | using namespace testing; |
556 | - mtd::MockClientContext ctx; |
557 | - ON_CALL(ctx, populate_server_package(_)) |
558 | - .WillByDefault(Invoke([](MirPlatformPackage& package) |
559 | - { |
560 | - ::memset(&package, 0, sizeof(package)); |
561 | - package.fd_items = 1; |
562 | - })); |
563 | platform_library = std::make_shared<mir::SharedLibrary>(client_platform("mesa.so")); |
564 | auto platform_factory = platform_library->load_function<mir::client::CreateClientPlatform>("create_client_platform"); |
565 | - return platform_factory(&ctx); |
566 | + return platform_factory(client_context); |
567 | } |
568 | |
569 | std::shared_ptr<mir::SharedLibrary> |
570 | |
571 | === modified file 'tests/mir_test_framework/stub_client_platform_factory.cpp' |
572 | --- tests/mir_test_framework/stub_client_platform_factory.cpp 2015-01-29 14:57:00 +0000 |
573 | +++ tests/mir_test_framework/stub_client_platform_factory.cpp 2015-02-02 14:38:00 +0000 |
574 | @@ -50,6 +50,11 @@ |
575 | context->populate_server_package(package); |
576 | } |
577 | |
578 | + MirPlatformMessage* platform_operation(MirPlatformMessage const*) override |
579 | + { |
580 | + return nullptr; |
581 | + } |
582 | + |
583 | std::shared_ptr<mcl::ClientBufferFactory> create_buffer_factory() |
584 | { |
585 | return std::make_shared<mtd::StubClientBufferFactory>(); |
586 | |
587 | === modified file 'tests/unit-tests/client/mesa/test_client_platform.cpp' |
588 | --- tests/unit-tests/client/mesa/test_client_platform.cpp 2015-01-22 21:42:26 +0000 |
589 | +++ tests/unit-tests/client/mesa/test_client_platform.cpp 2015-02-02 14:38:00 +0000 |
590 | @@ -18,23 +18,56 @@ |
591 | |
592 | #include "mir/client_platform.h" |
593 | #include "mir/shared_library.h" |
594 | +#include "mir/raii.h" |
595 | #include "src/platforms/mesa/client/mesa_native_display_container.h" |
596 | #include "mir_test_framework/client_platform_factory.h" |
597 | -#include "mir_test_doubles/mock_egl_native_surface.h" |
598 | |
599 | +#include "mir_toolkit/mir_client_library.h" |
600 | #include "mir_toolkit/mesa/native_display.h" |
601 | +#include "mir_toolkit/mesa/platform_operation.h" |
602 | |
603 | #include <gtest/gtest.h> |
604 | +#include <gmock/gmock.h> |
605 | |
606 | namespace mcl = mir::client; |
607 | namespace mclm = mir::client::mesa; |
608 | -namespace mt = mir::test; |
609 | -namespace mtd = mir::test::doubles; |
610 | namespace mtf = mir_test_framework; |
611 | |
612 | -TEST(MesaClientPlatformTest, egl_native_display_is_valid_until_released) |
613 | -{ |
614 | - auto platform = mtf::create_mesa_client_platform(); |
615 | +namespace |
616 | +{ |
617 | + |
618 | +struct StubClientContext : mcl::ClientContext |
619 | +{ |
620 | + void populate_server_package(MirPlatformPackage& platform_package) override |
621 | + { |
622 | + platform_package.data_items = 0; |
623 | + platform_package.fd_items = 1; |
624 | + } |
625 | + |
626 | +}; |
627 | + |
628 | +struct MesaClientPlatformTest : testing::Test |
629 | +{ |
630 | + MirPlatformMessage* set_gbm_device(gbm_device* dev) |
631 | + { |
632 | + auto request_msg = mir::raii::deleter_for( |
633 | + mir_platform_message_create(MirMesaPlatformOperation::set_gbm_device), |
634 | + &mir_platform_message_release); |
635 | + MirMesaSetGBMDeviceRequest const request{dev}; |
636 | + mir_platform_message_set_data(request_msg.get(), &request, sizeof(request)); |
637 | + |
638 | + return platform->platform_operation(request_msg.get()); |
639 | + } |
640 | + |
641 | + StubClientContext client_context; |
642 | + std::shared_ptr<mir::client::ClientPlatform> platform = |
643 | + mtf::create_mesa_client_platform(&client_context); |
644 | +}; |
645 | + |
646 | +} |
647 | + |
648 | +TEST_F(MesaClientPlatformTest, egl_native_display_is_valid_until_released) |
649 | +{ |
650 | auto platform_lib = mtf::get_platform_library(); |
651 | |
652 | MirMesaEGLNativeDisplay* nd; |
653 | @@ -47,3 +80,41 @@ |
654 | } |
655 | EXPECT_EQ(MIR_MESA_FALSE, mclm::mir_client_mesa_egl_native_display_is_valid(nd)); |
656 | } |
657 | + |
658 | +TEST_F(MesaClientPlatformTest, handles_set_gbm_device_platform_operation) |
659 | +{ |
660 | + using namespace testing; |
661 | + |
662 | + int const success{0}; |
663 | + auto const gbm_dev_dummy = reinterpret_cast<gbm_device*>(this); |
664 | + |
665 | + auto response_msg = mir::raii::deleter_for( |
666 | + set_gbm_device(gbm_dev_dummy), |
667 | + &mir_platform_message_release); |
668 | + |
669 | + ASSERT_THAT(response_msg, NotNull()); |
670 | + auto const response_data = mir_platform_message_get_data(response_msg.get()); |
671 | + ASSERT_THAT(response_data.size, Eq(sizeof(MirMesaSetGBMDeviceResponse))); |
672 | + auto const response_ptr = |
673 | + reinterpret_cast<MirMesaSetGBMDeviceResponse const*>(response_data.data); |
674 | + EXPECT_THAT(response_ptr->status, Eq(success)); |
675 | +} |
676 | + |
677 | +TEST_F(MesaClientPlatformTest, appends_gbm_device_to_platform_package) |
678 | +{ |
679 | + using namespace testing; |
680 | + |
681 | + MirPlatformPackage pkg; |
682 | + platform->populate(pkg); |
683 | + int const previous_data_count{pkg.data_items}; |
684 | + auto const gbm_dev_dummy = reinterpret_cast<gbm_device*>(this); |
685 | + |
686 | + auto response_msg = mir::raii::deleter_for( |
687 | + set_gbm_device(gbm_dev_dummy), |
688 | + &mir_platform_message_release); |
689 | + |
690 | + platform->populate(pkg); |
691 | + EXPECT_THAT(pkg.data_items, Eq(previous_data_count + (sizeof(gbm_dev_dummy) / sizeof(int)))); |
692 | + EXPECT_THAT(reinterpret_cast<struct gbm_device*>(pkg.data[previous_data_count]), |
693 | + Eq(gbm_dev_dummy)); |
694 | +} |
695 | |
696 | === modified file 'tests/unit-tests/client/test_client_mir_surface.cpp' |
697 | --- tests/unit-tests/client/test_client_mir_surface.cpp 2015-01-29 14:57:00 +0000 |
698 | +++ tests/unit-tests/client/test_client_mir_surface.cpp 2015-02-02 14:38:00 +0000 |
699 | @@ -211,6 +211,12 @@ |
700 | { |
701 | } |
702 | |
703 | + MirPlatformMessage* platform_operation( |
704 | + MirPlatformMessage const*) override |
705 | + { |
706 | + return nullptr; |
707 | + } |
708 | + |
709 | std::shared_ptr<mcl::ClientBufferFactory> create_buffer_factory() |
710 | { |
711 | return std::make_shared<mtd::StubClientBufferFactory>(); |
712 | |
713 | === modified file 'tests/unit-tests/client/test_mir_connection.cpp' |
714 | --- tests/unit-tests/client/test_mir_connection.cpp 2015-01-30 14:24:06 +0000 |
715 | +++ tests/unit-tests/client/test_mir_connection.cpp 2015-02-02 14:38:00 +0000 |
716 | @@ -28,6 +28,7 @@ |
717 | #include "src/client/mir_surface.h" |
718 | #include "mir/client_buffer_factory.h" |
719 | #include "mir/dispatch/dispatchable.h" |
720 | +#include "mir/raii.h" |
721 | |
722 | #include "src/server/frontend/resource_cache.h" /* needed by test_server.h */ |
723 | #include "mir_test/test_protobuf_server.h" |
724 | @@ -74,12 +75,19 @@ |
725 | { |
726 | configure_display_sent(static_cast<mp::DisplayConfiguration const*>(parameters)); |
727 | } |
728 | + else if (method->name() == "platform_operation") |
729 | + { |
730 | + platform_operation(static_cast<mp::PlatformOperationMessage const*>(parameters), |
731 | + static_cast<mp::PlatformOperationMessage*>(response)); |
732 | + } |
733 | |
734 | complete->Run(); |
735 | } |
736 | |
737 | MOCK_METHOD2(connect, void(mp::ConnectParameters const*,mp::Connection*)); |
738 | MOCK_METHOD1(configure_display_sent, void(mp::DisplayConfiguration const*)); |
739 | + MOCK_METHOD2(platform_operation, |
740 | + void(mp::PlatformOperationMessage const*, mp::PlatformOperationMessage*)); |
741 | |
742 | MOCK_CONST_METHOD0(watch_fd, mir::Fd()); |
743 | MOCK_METHOD1(dispatch, bool(md::FdEvents)); |
744 | @@ -101,6 +109,8 @@ |
745 | .WillByDefault(Return(std::make_shared<mtd::StubClientBufferFactory>())); |
746 | ON_CALL(*this, create_egl_native_window(_)) |
747 | .WillByDefault(Return(std::shared_ptr<EGLNativeWindowType>())); |
748 | + ON_CALL(*this, platform_operation(_)) |
749 | + .WillByDefault(Return(nullptr)); |
750 | } |
751 | |
752 | void set_client_context(mcl::ClientContext* ctx) |
753 | @@ -115,6 +125,7 @@ |
754 | |
755 | MOCK_CONST_METHOD1(convert_native_buffer, MirNativeBuffer*(mir::graphics::NativeBuffer*)); |
756 | MOCK_CONST_METHOD0(platform_type, MirPlatformType()); |
757 | + MOCK_METHOD1(platform_operation, MirPlatformMessage*(MirPlatformMessage const*)); |
758 | MOCK_METHOD0(create_buffer_factory, std::shared_ptr<mcl::ClientBufferFactory>()); |
759 | MOCK_METHOD1(create_egl_native_window, std::shared_ptr<EGLNativeWindowType>(mcl::EGLNativeSurface*)); |
760 | MOCK_METHOD0(create_egl_native_display, std::shared_ptr<EGLNativeDisplayType>()); |
761 | @@ -568,46 +579,72 @@ |
762 | namespace |
763 | { |
764 | |
765 | -ACTION_P(FillPlatformDataWith, sample_data) |
766 | -{ |
767 | - for (auto d : sample_data) |
768 | - arg1->mutable_platform()->add_data(d); |
769 | -} |
770 | - |
771 | -} |
772 | - |
773 | -TEST_F(MirConnectionTest, sets_extra_platform_data) |
774 | -{ |
775 | - using namespace testing; |
776 | - std::vector<int> const initial_data{0x66, 0x67, 0x68}; |
777 | - std::vector<int> const extra_data{0x11, 0x12, 0x13}; |
778 | - |
779 | - EXPECT_CALL(*mock_channel, connect(_,_)) |
780 | - .WillOnce(FillPlatformDataWith(initial_data)); |
781 | - |
782 | - MirWaitHandle *wait_handle = |
783 | - connection->connect("MirClientSurfaceTest", &connected_callback, nullptr); |
784 | - wait_handle->wait_for_all(); |
785 | - |
786 | - MirPlatformPackage pkg; |
787 | - |
788 | - /* Check initial data */ |
789 | - connection->populate(pkg); |
790 | - |
791 | - EXPECT_EQ(initial_data.size(), static_cast<size_t>(pkg.data_items)); |
792 | - for (size_t i = 0; i < initial_data.size(); i++) |
793 | - EXPECT_EQ(initial_data[i], pkg.data[i]) << " i=" << i; |
794 | - |
795 | - /* Check initial data plus extra data*/ |
796 | - connection->set_extra_platform_data(extra_data); |
797 | - connection->populate(pkg); |
798 | - |
799 | - EXPECT_EQ(initial_data.size() + extra_data.size(), |
800 | - static_cast<size_t>(pkg.data_items)); |
801 | - |
802 | - for (size_t i = 0; i < initial_data.size(); i++) |
803 | - EXPECT_EQ(initial_data[i], pkg.data[i]) << " i=" << i; |
804 | - |
805 | - for (size_t i = 0; i < extra_data.size(); i++) |
806 | - EXPECT_EQ(extra_data[i], pkg.data[i + initial_data.size()]) << " i=" << i; |
807 | +void assign_response(MirConnection*, MirPlatformMessage* response, void* context) |
808 | +{ |
809 | + auto response_ptr = static_cast<MirPlatformMessage**>(context); |
810 | + *response_ptr = response; |
811 | +} |
812 | + |
813 | +ACTION(CopyRequestToResponse) |
814 | +{ |
815 | + *arg1 = *arg0; |
816 | +} |
817 | +} |
818 | + |
819 | +TEST_F(MirConnectionTest, uses_client_platform_for_platform_operation) |
820 | +{ |
821 | + using namespace testing; |
822 | + |
823 | + unsigned int const opcode{42}; |
824 | + auto const request = mir::raii::deleter_for( |
825 | + mir_platform_message_create(opcode), |
826 | + &mir_platform_message_release); |
827 | + auto const response = mir::raii::deleter_for( |
828 | + mir_platform_message_create(opcode), |
829 | + &mir_platform_message_release); |
830 | + |
831 | + EXPECT_CALL(*mock_platform, platform_operation(request.get())) |
832 | + .WillOnce(Return(response.get())); |
833 | + EXPECT_CALL(*mock_channel, platform_operation(_,_)) |
834 | + .Times(0); |
835 | + |
836 | + auto connect_wh = |
837 | + connection->connect("MirClientSurfaceTest", &connected_callback, nullptr); |
838 | + mir_wait_for(connect_wh); |
839 | + |
840 | + MirPlatformMessage* returned_response{nullptr}; |
841 | + |
842 | + auto op_wh = connection->platform_operation( |
843 | + request.get(), assign_response, &returned_response); |
844 | + mir_wait_for(op_wh); |
845 | + |
846 | + EXPECT_THAT(returned_response, Eq(response.get())); |
847 | +} |
848 | + |
849 | +TEST_F(MirConnectionTest, contacts_server_if_client_platform_cannot_handle_platform_operation) |
850 | +{ |
851 | + using namespace testing; |
852 | + |
853 | + unsigned int const opcode{42}; |
854 | + auto const request = mir::raii::deleter_for( |
855 | + mir_platform_message_create(opcode), |
856 | + &mir_platform_message_release); |
857 | + |
858 | + EXPECT_CALL(*mock_platform, platform_operation(_)) |
859 | + .WillOnce(Return(nullptr)); |
860 | + EXPECT_CALL(*mock_channel, platform_operation(_,_)) |
861 | + .WillOnce(CopyRequestToResponse()); |
862 | + |
863 | + auto connect_wh = |
864 | + connection->connect("MirClientSurfaceTest", &connected_callback, nullptr); |
865 | + mir_wait_for(connect_wh); |
866 | + |
867 | + MirPlatformMessage* returned_response{nullptr}; |
868 | + |
869 | + auto op_wh = connection->platform_operation( |
870 | + request.get(), assign_response, &returned_response); |
871 | + mir_wait_for(op_wh); |
872 | + |
873 | + EXPECT_THAT(mir_platform_message_get_opcode(returned_response), Eq(opcode)); |
874 | + mir_platform_message_release(returned_response); |
875 | } |