1 | /*
|
---|
2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistribution1s of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup display
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file Display server main
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <async.h>
|
---|
37 | #include <disp_srv.h>
|
---|
38 | #include <dispcfg_srv.h>
|
---|
39 | #include <errno.h>
|
---|
40 | #include <gfx/context.h>
|
---|
41 | #include <str_error.h>
|
---|
42 | #include <io/log.h>
|
---|
43 | #include <io/kbd_event.h>
|
---|
44 | #include <io/pos_event.h>
|
---|
45 | #include <ipc/services.h>
|
---|
46 | #include <ipcgfx/server.h>
|
---|
47 | #include <loc.h>
|
---|
48 | #include <stdio.h>
|
---|
49 | #include <task.h>
|
---|
50 | #include <wndmgt_srv.h>
|
---|
51 | #include "cfgclient.h"
|
---|
52 | #include "cfgops.h"
|
---|
53 | #include "client.h"
|
---|
54 | #include "display.h"
|
---|
55 | #include "dsops.h"
|
---|
56 | #include "input.h"
|
---|
57 | #include "main.h"
|
---|
58 | #include "output.h"
|
---|
59 | #include "seat.h"
|
---|
60 | #include "window.h"
|
---|
61 | #include "wmclient.h"
|
---|
62 | #include "wmops.h"
|
---|
63 |
|
---|
64 | static void display_client_conn(ipc_call_t *, void *);
|
---|
65 | static void display_client_ev_pending(void *);
|
---|
66 | static void display_wmclient_ev_pending(void *);
|
---|
67 | static void display_cfgclient_ev_pending(void *);
|
---|
68 | static void display_gc_conn(ipc_call_t *, void *);
|
---|
69 | static void display_wndmgt_conn(ipc_call_t *, void *);
|
---|
70 | static void display_dispcfg_conn(ipc_call_t *, void *);
|
---|
71 |
|
---|
72 | #ifdef CONFIG_DISP_DOUBLE_BUF
|
---|
73 | /*
|
---|
74 | * Double buffering is one way to provide flicker-free display.
|
---|
75 | */
|
---|
76 | static ds_display_flags_t disp_flags = df_disp_double_buf;
|
---|
77 | #else
|
---|
78 | /*
|
---|
79 | * With double buffering disabled, wet screen flicker since front-to-back
|
---|
80 | * rendering is not implemented.
|
---|
81 | */
|
---|
82 | static ds_display_flags_t disp_flags = df_none;
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | static ds_client_cb_t display_client_cb = {
|
---|
86 | .ev_pending = display_client_ev_pending
|
---|
87 | };
|
---|
88 |
|
---|
89 | static ds_wmclient_cb_t display_wmclient_cb = {
|
---|
90 | .ev_pending = display_wmclient_ev_pending
|
---|
91 | };
|
---|
92 |
|
---|
93 | static ds_cfgclient_cb_t display_cfgclient_cb = {
|
---|
94 | .ev_pending = display_cfgclient_ev_pending
|
---|
95 | };
|
---|
96 |
|
---|
97 | static void display_client_ev_pending(void *arg)
|
---|
98 | {
|
---|
99 | display_srv_t *srv = (display_srv_t *) arg;
|
---|
100 |
|
---|
101 | display_srv_ev_pending(srv);
|
---|
102 | }
|
---|
103 |
|
---|
104 | static void display_wmclient_ev_pending(void *arg)
|
---|
105 | {
|
---|
106 | wndmgt_srv_t *srv = (wndmgt_srv_t *) arg;
|
---|
107 |
|
---|
108 | wndmgt_srv_ev_pending(srv);
|
---|
109 | }
|
---|
110 |
|
---|
111 | static void display_cfgclient_ev_pending(void *arg)
|
---|
112 | {
|
---|
113 | dispcfg_srv_t *srv = (dispcfg_srv_t *) arg;
|
---|
114 |
|
---|
115 | dispcfg_srv_ev_pending(srv);
|
---|
116 | }
|
---|
117 |
|
---|
118 | /** Initialize display server */
|
---|
119 | static errno_t display_srv_init(ds_output_t **routput)
|
---|
120 | {
|
---|
121 | ds_display_t *disp = NULL;
|
---|
122 | ds_seat_t *seat = NULL;
|
---|
123 | ds_output_t *output = NULL;
|
---|
124 | gfx_context_t *gc = NULL;
|
---|
125 | port_id_t disp_port;
|
---|
126 | port_id_t gc_port;
|
---|
127 | port_id_t wm_port;
|
---|
128 | port_id_t dc_port;
|
---|
129 | errno_t rc;
|
---|
130 |
|
---|
131 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
|
---|
132 |
|
---|
133 | rc = ds_display_create(NULL, disp_flags, &disp);
|
---|
134 | if (rc != EOK)
|
---|
135 | goto error;
|
---|
136 |
|
---|
137 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
138 | if (rc != EOK)
|
---|
139 | goto error;
|
---|
140 |
|
---|
141 | rc = ds_output_create(&output);
|
---|
142 | if (rc != EOK)
|
---|
143 | goto error;
|
---|
144 |
|
---|
145 | output->def_display = disp;
|
---|
146 | rc = ds_output_start_discovery(output);
|
---|
147 | if (rc != EOK)
|
---|
148 | goto error;
|
---|
149 |
|
---|
150 | rc = ds_input_open(disp);
|
---|
151 | if (rc != EOK)
|
---|
152 | goto error;
|
---|
153 |
|
---|
154 | rc = async_create_port(INTERFACE_DISPLAY, display_client_conn, disp,
|
---|
155 | &disp_port);
|
---|
156 | if (rc != EOK)
|
---|
157 | goto error;
|
---|
158 |
|
---|
159 | rc = async_create_port(INTERFACE_GC, display_gc_conn, disp, &gc_port);
|
---|
160 | if (rc != EOK)
|
---|
161 | goto error;
|
---|
162 |
|
---|
163 | rc = async_create_port(INTERFACE_WNDMGT, display_wndmgt_conn, disp,
|
---|
164 | &wm_port);
|
---|
165 | if (rc != EOK)
|
---|
166 | goto error;
|
---|
167 |
|
---|
168 | rc = async_create_port(INTERFACE_DISPCFG, display_dispcfg_conn, disp,
|
---|
169 | &dc_port);
|
---|
170 | if (rc != EOK)
|
---|
171 | goto error;
|
---|
172 |
|
---|
173 | rc = loc_server_register(NAME);
|
---|
174 | if (rc != EOK) {
|
---|
175 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
|
---|
176 | rc = EEXIST;
|
---|
177 | goto error;
|
---|
178 | }
|
---|
179 |
|
---|
180 | service_id_t sid;
|
---|
181 | rc = loc_service_register(SERVICE_NAME_DISPLAY, &sid);
|
---|
182 | if (rc != EOK) {
|
---|
183 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
|
---|
184 | rc = EEXIST;
|
---|
185 | goto error;
|
---|
186 | }
|
---|
187 |
|
---|
188 | *routput = output;
|
---|
189 | return EOK;
|
---|
190 | error:
|
---|
191 | // XXX destroy disp_port
|
---|
192 | // XXX destroy gc_port
|
---|
193 | // XXX destroy wm_port
|
---|
194 | // XXX destroy dc_port
|
---|
195 | #if 0
|
---|
196 | if (disp->input != NULL)
|
---|
197 | ds_input_close(disp);
|
---|
198 | #endif
|
---|
199 | if (output != NULL)
|
---|
200 | ds_output_destroy(output);
|
---|
201 | if (gc != NULL)
|
---|
202 | gfx_context_delete(gc);
|
---|
203 | if (seat != NULL)
|
---|
204 | ds_seat_destroy(seat);
|
---|
205 | if (disp != NULL)
|
---|
206 | ds_display_destroy(disp);
|
---|
207 | return rc;
|
---|
208 | }
|
---|
209 |
|
---|
210 | /** Handle client connection to display server */
|
---|
211 | static void display_client_conn(ipc_call_t *icall, void *arg)
|
---|
212 | {
|
---|
213 | display_srv_t srv;
|
---|
214 | sysarg_t svc_id;
|
---|
215 | ds_client_t *client = NULL;
|
---|
216 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
217 | errno_t rc;
|
---|
218 |
|
---|
219 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
|
---|
220 | ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
|
---|
221 | ipc_get_arg4(icall));
|
---|
222 |
|
---|
223 | svc_id = ipc_get_arg2(icall);
|
---|
224 |
|
---|
225 | if (svc_id != 0) {
|
---|
226 | /* Create client object */
|
---|
227 | ds_display_lock(disp);
|
---|
228 | rc = ds_client_create(disp, &display_client_cb, &srv, &client);
|
---|
229 | ds_display_unlock(disp);
|
---|
230 | if (rc != EOK) {
|
---|
231 | async_answer_0(icall, ENOMEM);
|
---|
232 | return;
|
---|
233 | }
|
---|
234 |
|
---|
235 | /* Set up protocol structure */
|
---|
236 | display_srv_initialize(&srv);
|
---|
237 | srv.ops = &display_srv_ops;
|
---|
238 | srv.arg = client;
|
---|
239 |
|
---|
240 | /* Handle connection */
|
---|
241 | display_conn(icall, &srv);
|
---|
242 |
|
---|
243 | ds_display_lock(disp);
|
---|
244 | ds_client_destroy(client);
|
---|
245 | ds_display_unlock(disp);
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | /** Handle GC connection to display server */
|
---|
250 | static void display_gc_conn(ipc_call_t *icall, void *arg)
|
---|
251 | {
|
---|
252 | sysarg_t wnd_id;
|
---|
253 | ds_window_t *wnd;
|
---|
254 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
255 | gfx_context_t *gc;
|
---|
256 |
|
---|
257 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_gc_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
|
---|
258 | ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
|
---|
259 | ipc_get_arg4(icall));
|
---|
260 |
|
---|
261 | wnd_id = ipc_get_arg3(icall);
|
---|
262 |
|
---|
263 | /* Window GC connection */
|
---|
264 |
|
---|
265 | wnd = ds_display_find_window(disp, wnd_id);
|
---|
266 | if (wnd == NULL) {
|
---|
267 | async_answer_0(icall, ENOENT);
|
---|
268 | return;
|
---|
269 | }
|
---|
270 |
|
---|
271 | /*
|
---|
272 | * XXX We need a way to make sure that the connection does
|
---|
273 | * not stay active after the window had been destroyed
|
---|
274 | */
|
---|
275 | gc = ds_window_get_ctx(wnd);
|
---|
276 | gc_conn(icall, gc);
|
---|
277 | }
|
---|
278 |
|
---|
279 | /** Handle window management connection to display server */
|
---|
280 | static void display_wndmgt_conn(ipc_call_t *icall, void *arg)
|
---|
281 | {
|
---|
282 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
283 | errno_t rc;
|
---|
284 | wndmgt_srv_t srv;
|
---|
285 | ds_wmclient_t *wmclient = NULL;
|
---|
286 |
|
---|
287 | /* Create WM client object */
|
---|
288 | ds_display_lock(disp);
|
---|
289 | rc = ds_wmclient_create(disp, &display_wmclient_cb, &srv, &wmclient);
|
---|
290 | ds_display_unlock(disp);
|
---|
291 | if (rc != EOK) {
|
---|
292 | async_answer_0(icall, ENOMEM);
|
---|
293 | return;
|
---|
294 | }
|
---|
295 |
|
---|
296 | /* Set up protocol structure */
|
---|
297 | wndmgt_srv_initialize(&srv);
|
---|
298 | srv.ops = &wndmgt_srv_ops;
|
---|
299 | srv.arg = wmclient;
|
---|
300 |
|
---|
301 | /* Handle connection */
|
---|
302 | wndmgt_conn(icall, &srv);
|
---|
303 |
|
---|
304 | ds_display_lock(disp);
|
---|
305 | ds_wmclient_destroy(wmclient);
|
---|
306 | ds_display_unlock(disp);
|
---|
307 | }
|
---|
308 |
|
---|
309 | /** Handle configuration connection to display server */
|
---|
310 | static void display_dispcfg_conn(ipc_call_t *icall, void *arg)
|
---|
311 | {
|
---|
312 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
313 | errno_t rc;
|
---|
314 | dispcfg_srv_t srv;
|
---|
315 | ds_cfgclient_t *cfgclient = NULL;
|
---|
316 |
|
---|
317 | /* Create CFG client object */
|
---|
318 | ds_display_lock(disp);
|
---|
319 | rc = ds_cfgclient_create(disp, &display_cfgclient_cb, &srv, &cfgclient);
|
---|
320 | ds_display_unlock(disp);
|
---|
321 | if (rc != EOK) {
|
---|
322 | async_answer_0(icall, ENOMEM);
|
---|
323 | return;
|
---|
324 | }
|
---|
325 |
|
---|
326 | /* Set up protocol structure */
|
---|
327 | dispcfg_srv_initialize(&srv);
|
---|
328 | srv.ops = &dispcfg_srv_ops;
|
---|
329 | srv.arg = cfgclient;
|
---|
330 |
|
---|
331 | /* Handle connection */
|
---|
332 | dispcfg_conn(icall, &srv);
|
---|
333 |
|
---|
334 | ds_display_lock(disp);
|
---|
335 | ds_cfgclient_destroy(cfgclient);
|
---|
336 | ds_display_unlock(disp);
|
---|
337 | }
|
---|
338 |
|
---|
339 | int main(int argc, char *argv[])
|
---|
340 | {
|
---|
341 | errno_t rc;
|
---|
342 | ds_output_t *output;
|
---|
343 |
|
---|
344 | printf("%s: Display server\n", NAME);
|
---|
345 |
|
---|
346 | if (log_init(NAME) != EOK) {
|
---|
347 | printf(NAME ": Failed to initialize logging.\n");
|
---|
348 | return 1;
|
---|
349 | }
|
---|
350 |
|
---|
351 | rc = display_srv_init(&output);
|
---|
352 | if (rc != EOK)
|
---|
353 | return 1;
|
---|
354 |
|
---|
355 | printf(NAME ": Accepting connections.\n");
|
---|
356 | task_retval(0);
|
---|
357 | async_manager();
|
---|
358 |
|
---|
359 | return 0;
|
---|
360 | }
|
---|
361 |
|
---|
362 | /** @}
|
---|
363 | */
|
---|