source: mainline/uspace/srv/hid/display/main.c@ 9c40b834

Last change on this file since 9c40b834 was 9546146, checked in by Jiri Svoboda <jiri@…>, 16 months ago

Persistently store display/seat configuration.

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