1 | /*
|
---|
2 | * Copyright (c) 2025 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 "ievent.h"
|
---|
57 | #include "input.h"
|
---|
58 | #include "main.h"
|
---|
59 | #include "output.h"
|
---|
60 | #include "seat.h"
|
---|
61 | #include "window.h"
|
---|
62 | #include "wmclient.h"
|
---|
63 | #include "wmops.h"
|
---|
64 |
|
---|
65 | const char *cfg_file_path = "/w/cfg/display.sif";
|
---|
66 |
|
---|
67 | static void display_client_conn(ipc_call_t *, void *);
|
---|
68 | static void display_client_ev_pending(void *);
|
---|
69 | static void display_wmclient_ev_pending(void *);
|
---|
70 | static void display_cfgclient_ev_pending(void *);
|
---|
71 | static void display_gc_conn(ipc_call_t *, void *);
|
---|
72 | static void display_wndmgt_conn(ipc_call_t *, void *);
|
---|
73 | static void display_dispcfg_conn(ipc_call_t *, void *);
|
---|
74 |
|
---|
75 | #ifdef CONFIG_DISP_DOUBLE_BUF
|
---|
76 | /*
|
---|
77 | * Double buffering is one way to provide flicker-free display.
|
---|
78 | */
|
---|
79 | static ds_display_flags_t disp_flags = df_disp_double_buf;
|
---|
80 | #else
|
---|
81 | /*
|
---|
82 | * With double buffering disabled, wet screen flicker since front-to-back
|
---|
83 | * rendering is not implemented.
|
---|
84 | */
|
---|
85 | static ds_display_flags_t disp_flags = df_none;
|
---|
86 | #endif
|
---|
87 |
|
---|
88 | static ds_client_cb_t display_client_cb = {
|
---|
89 | .ev_pending = display_client_ev_pending
|
---|
90 | };
|
---|
91 |
|
---|
92 | static ds_wmclient_cb_t display_wmclient_cb = {
|
---|
93 | .ev_pending = display_wmclient_ev_pending
|
---|
94 | };
|
---|
95 |
|
---|
96 | static ds_cfgclient_cb_t display_cfgclient_cb = {
|
---|
97 | .ev_pending = display_cfgclient_ev_pending
|
---|
98 | };
|
---|
99 |
|
---|
100 | static void display_client_ev_pending(void *arg)
|
---|
101 | {
|
---|
102 | display_srv_t *srv = (display_srv_t *) arg;
|
---|
103 |
|
---|
104 | display_srv_ev_pending(srv);
|
---|
105 | }
|
---|
106 |
|
---|
107 | static void display_wmclient_ev_pending(void *arg)
|
---|
108 | {
|
---|
109 | wndmgt_srv_t *srv = (wndmgt_srv_t *) arg;
|
---|
110 |
|
---|
111 | wndmgt_srv_ev_pending(srv);
|
---|
112 | }
|
---|
113 |
|
---|
114 | static void display_cfgclient_ev_pending(void *arg)
|
---|
115 | {
|
---|
116 | dispcfg_srv_t *srv = (dispcfg_srv_t *) arg;
|
---|
117 |
|
---|
118 | dispcfg_srv_ev_pending(srv);
|
---|
119 | }
|
---|
120 |
|
---|
121 | /** Initialize display server */
|
---|
122 | static errno_t display_srv_init(ds_output_t **routput)
|
---|
123 | {
|
---|
124 | ds_display_t *disp = NULL;
|
---|
125 | ds_seat_t *seat = NULL;
|
---|
126 | ds_output_t *output = NULL;
|
---|
127 | gfx_context_t *gc = NULL;
|
---|
128 | port_id_t port = 0;
|
---|
129 | loc_srv_t *srv = NULL;
|
---|
130 | service_id_t sid = 0;
|
---|
131 | errno_t rc;
|
---|
132 |
|
---|
133 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
|
---|
134 |
|
---|
135 | rc = ds_display_create(NULL, disp_flags, &disp);
|
---|
136 | if (rc != EOK)
|
---|
137 | goto error;
|
---|
138 |
|
---|
139 | rc = ds_display_load_cfg(disp, cfg_file_path);
|
---|
140 | if (rc != EOK) {
|
---|
141 | log_msg(LOG_DEFAULT, LVL_NOTE,
|
---|
142 | "Starting with fresh configuration.");
|
---|
143 |
|
---|
144 | /* Create first seat */
|
---|
145 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
146 | if (rc != EOK)
|
---|
147 | goto error;
|
---|
148 | }
|
---|
149 |
|
---|
150 | rc = ds_output_create(&output);
|
---|
151 | if (rc != EOK)
|
---|
152 | goto error;
|
---|
153 |
|
---|
154 | output->def_display = disp;
|
---|
155 | rc = ds_output_start_discovery(output);
|
---|
156 | if (rc != EOK)
|
---|
157 | goto error;
|
---|
158 |
|
---|
159 | rc = ds_ievent_init(disp);
|
---|
160 | if (rc != EOK)
|
---|
161 | goto error;
|
---|
162 |
|
---|
163 | rc = ds_input_open(disp);
|
---|
164 | if (rc != EOK)
|
---|
165 | goto error;
|
---|
166 |
|
---|
167 | rc = async_create_port(INTERFACE_DISPLAY, display_client_conn, disp,
|
---|
168 | &port);
|
---|
169 | if (rc != EOK)
|
---|
170 | goto error;
|
---|
171 |
|
---|
172 | rc = async_port_create_interface(port, INTERFACE_GC, display_gc_conn,
|
---|
173 | disp);
|
---|
174 | if (rc != EOK)
|
---|
175 | goto error;
|
---|
176 |
|
---|
177 | rc = async_port_create_interface(port, INTERFACE_WNDMGT,
|
---|
178 | display_wndmgt_conn, disp);
|
---|
179 | if (rc != EOK)
|
---|
180 | goto error;
|
---|
181 |
|
---|
182 | rc = async_port_create_interface(port, INTERFACE_DISPCFG,
|
---|
183 | display_dispcfg_conn, disp);
|
---|
184 | if (rc != EOK)
|
---|
185 | goto error;
|
---|
186 |
|
---|
187 | rc = loc_server_register(NAME, &srv);
|
---|
188 | if (rc != EOK) {
|
---|
189 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
|
---|
190 | rc = EEXIST;
|
---|
191 | goto error;
|
---|
192 | }
|
---|
193 |
|
---|
194 | rc = loc_service_register(srv, SERVICE_NAME_DISPLAY, port, &sid);
|
---|
195 | if (rc != EOK) {
|
---|
196 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
|
---|
197 | rc = EEXIST;
|
---|
198 | goto error;
|
---|
199 | }
|
---|
200 |
|
---|
201 | *routput = output;
|
---|
202 | return EOK;
|
---|
203 | error:
|
---|
204 | if (sid != 0)
|
---|
205 | loc_service_unregister(srv, sid);
|
---|
206 | if (srv != NULL)
|
---|
207 | loc_server_unregister(srv);
|
---|
208 | if (port != 0)
|
---|
209 | async_port_destroy(port);
|
---|
210 | #if 0
|
---|
211 | if (disp->input != NULL)
|
---|
212 | ds_input_close(disp);
|
---|
213 | #endif
|
---|
214 | ds_ievent_fini(disp);
|
---|
215 | if (output != NULL)
|
---|
216 | ds_output_destroy(output);
|
---|
217 | if (gc != NULL)
|
---|
218 | gfx_context_delete(gc);
|
---|
219 | if (seat != NULL)
|
---|
220 | ds_seat_destroy(seat);
|
---|
221 | if (disp != NULL)
|
---|
222 | ds_display_destroy(disp);
|
---|
223 | return rc;
|
---|
224 | }
|
---|
225 |
|
---|
226 | /** Handle client connection to display server */
|
---|
227 | static void display_client_conn(ipc_call_t *icall, void *arg)
|
---|
228 | {
|
---|
229 | display_srv_t srv;
|
---|
230 | sysarg_t svc_id;
|
---|
231 | ds_client_t *client = NULL;
|
---|
232 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
233 | errno_t rc;
|
---|
234 |
|
---|
235 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
|
---|
236 | ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
|
---|
237 | ipc_get_arg4(icall));
|
---|
238 |
|
---|
239 | svc_id = ipc_get_arg2(icall);
|
---|
240 |
|
---|
241 | if (svc_id != 0) {
|
---|
242 | /* Create client object */
|
---|
243 | ds_display_lock(disp);
|
---|
244 | rc = ds_client_create(disp, &display_client_cb, &srv, &client);
|
---|
245 | ds_display_unlock(disp);
|
---|
246 | if (rc != EOK) {
|
---|
247 | async_answer_0(icall, ENOMEM);
|
---|
248 | return;
|
---|
249 | }
|
---|
250 |
|
---|
251 | /* Set up protocol structure */
|
---|
252 | display_srv_initialize(&srv);
|
---|
253 | srv.ops = &display_srv_ops;
|
---|
254 | srv.arg = client;
|
---|
255 |
|
---|
256 | /* Handle connection */
|
---|
257 | display_conn(icall, &srv);
|
---|
258 |
|
---|
259 | ds_display_lock(disp);
|
---|
260 | ds_client_destroy(client);
|
---|
261 | ds_display_unlock(disp);
|
---|
262 | }
|
---|
263 | }
|
---|
264 |
|
---|
265 | /** Handle GC connection to display server */
|
---|
266 | static void display_gc_conn(ipc_call_t *icall, void *arg)
|
---|
267 | {
|
---|
268 | sysarg_t wnd_id;
|
---|
269 | ds_window_t *wnd;
|
---|
270 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
271 | gfx_context_t *gc;
|
---|
272 |
|
---|
273 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_gc_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
|
---|
274 | ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
|
---|
275 | ipc_get_arg4(icall));
|
---|
276 |
|
---|
277 | wnd_id = ipc_get_arg3(icall);
|
---|
278 |
|
---|
279 | /* Window GC connection */
|
---|
280 |
|
---|
281 | wnd = ds_display_find_window(disp, wnd_id);
|
---|
282 | if (wnd == NULL) {
|
---|
283 | async_answer_0(icall, ENOENT);
|
---|
284 | return;
|
---|
285 | }
|
---|
286 |
|
---|
287 | /*
|
---|
288 | * XXX We need a way to make sure that the connection does
|
---|
289 | * not stay active after the window had been destroyed
|
---|
290 | */
|
---|
291 | gc = ds_window_get_ctx(wnd);
|
---|
292 | gc_conn(icall, gc);
|
---|
293 | }
|
---|
294 |
|
---|
295 | /** Handle window management connection to display server */
|
---|
296 | static void display_wndmgt_conn(ipc_call_t *icall, void *arg)
|
---|
297 | {
|
---|
298 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
299 | errno_t rc;
|
---|
300 | wndmgt_srv_t srv;
|
---|
301 | ds_wmclient_t *wmclient = NULL;
|
---|
302 |
|
---|
303 | /* Create WM client object */
|
---|
304 | ds_display_lock(disp);
|
---|
305 | rc = ds_wmclient_create(disp, &display_wmclient_cb, &srv, &wmclient);
|
---|
306 | ds_display_unlock(disp);
|
---|
307 | if (rc != EOK) {
|
---|
308 | async_answer_0(icall, ENOMEM);
|
---|
309 | return;
|
---|
310 | }
|
---|
311 |
|
---|
312 | /* Set up protocol structure */
|
---|
313 | wndmgt_srv_initialize(&srv);
|
---|
314 | srv.ops = &wndmgt_srv_ops;
|
---|
315 | srv.arg = wmclient;
|
---|
316 |
|
---|
317 | /* Handle connection */
|
---|
318 | wndmgt_conn(icall, &srv);
|
---|
319 |
|
---|
320 | ds_display_lock(disp);
|
---|
321 | ds_wmclient_destroy(wmclient);
|
---|
322 | ds_display_unlock(disp);
|
---|
323 | }
|
---|
324 |
|
---|
325 | /** Handle configuration connection to display server */
|
---|
326 | static void display_dispcfg_conn(ipc_call_t *icall, void *arg)
|
---|
327 | {
|
---|
328 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
329 | errno_t rc;
|
---|
330 | dispcfg_srv_t srv;
|
---|
331 | ds_cfgclient_t *cfgclient = NULL;
|
---|
332 |
|
---|
333 | /* Create CFG client object */
|
---|
334 | ds_display_lock(disp);
|
---|
335 | rc = ds_cfgclient_create(disp, &display_cfgclient_cb, &srv, &cfgclient);
|
---|
336 | ds_display_unlock(disp);
|
---|
337 | if (rc != EOK) {
|
---|
338 | async_answer_0(icall, ENOMEM);
|
---|
339 | return;
|
---|
340 | }
|
---|
341 |
|
---|
342 | /* Set up protocol structure */
|
---|
343 | dispcfg_srv_initialize(&srv);
|
---|
344 | srv.ops = &dispcfg_srv_ops;
|
---|
345 | srv.arg = cfgclient;
|
---|
346 |
|
---|
347 | /* Handle connection */
|
---|
348 | dispcfg_conn(icall, &srv);
|
---|
349 |
|
---|
350 | ds_display_lock(disp);
|
---|
351 | ds_cfgclient_destroy(cfgclient);
|
---|
352 | ds_display_unlock(disp);
|
---|
353 | }
|
---|
354 |
|
---|
355 | int main(int argc, char *argv[])
|
---|
356 | {
|
---|
357 | errno_t rc;
|
---|
358 | ds_output_t *output;
|
---|
359 |
|
---|
360 | printf("%s: Display server\n", NAME);
|
---|
361 |
|
---|
362 | if (log_init(NAME) != EOK) {
|
---|
363 | printf(NAME ": Failed to initialize logging.\n");
|
---|
364 | return 1;
|
---|
365 | }
|
---|
366 |
|
---|
367 | rc = display_srv_init(&output);
|
---|
368 | if (rc != EOK)
|
---|
369 | return 1;
|
---|
370 |
|
---|
371 | printf(NAME ": Accepting connections.\n");
|
---|
372 | task_retval(0);
|
---|
373 | async_manager();
|
---|
374 |
|
---|
375 | return 0;
|
---|
376 | }
|
---|
377 |
|
---|
378 | /** @}
|
---|
379 | */
|
---|