[c8cf261] | 1 | /*
|
---|
[ca48672] | 2 | * Copyright (c) 2025 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"
|
---|
[6fbd1f9] | 56 | #include "ievent.h"
|
---|
[02f45748] | 57 | #include "input.h"
|
---|
[b3c185b6] | 58 | #include "main.h"
|
---|
[159776f] | 59 | #include "output.h"
|
---|
[cf32dbd] | 60 | #include "seat.h"
|
---|
[6af4b4f] | 61 | #include "window.h"
|
---|
[913add60] | 62 | #include "wmclient.h"
|
---|
[1766326] | 63 | #include "wmops.h"
|
---|
[c8cf261] | 64 |
|
---|
[9546146] | 65 | const char *cfg_file_path = "/w/cfg/display.sif";
|
---|
| 66 |
|
---|
[c8cf261] | 67 | static void display_client_conn(ipc_call_t *, void *);
|
---|
[be15256] | 68 | static void display_client_ev_pending(void *);
|
---|
[913add60] | 69 | static void display_wmclient_ev_pending(void *);
|
---|
[d8503fd] | 70 | static void display_cfgclient_ev_pending(void *);
|
---|
[1766326] | 71 | static void display_gc_conn(ipc_call_t *, void *);
|
---|
| 72 | static void display_wndmgt_conn(ipc_call_t *, void *);
|
---|
[d8503fd] | 73 | static void display_dispcfg_conn(ipc_call_t *, void *);
|
---|
[be15256] | 74 |
|
---|
[8aef01c] | 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 |
|
---|
[be15256] | 88 | static ds_client_cb_t display_client_cb = {
|
---|
| 89 | .ev_pending = display_client_ev_pending
|
---|
| 90 | };
|
---|
[c8cf261] | 91 |
|
---|
[913add60] | 92 | static ds_wmclient_cb_t display_wmclient_cb = {
|
---|
| 93 | .ev_pending = display_wmclient_ev_pending
|
---|
| 94 | };
|
---|
| 95 |
|
---|
[d8503fd] | 96 | static ds_cfgclient_cb_t display_cfgclient_cb = {
|
---|
| 97 | .ev_pending = display_cfgclient_ev_pending
|
---|
| 98 | };
|
---|
| 99 |
|
---|
[be15256] | 100 | static void display_client_ev_pending(void *arg)
|
---|
| 101 | {
|
---|
| 102 | display_srv_t *srv = (display_srv_t *) arg;
|
---|
[6c2aba3] | 103 |
|
---|
[be15256] | 104 | display_srv_ev_pending(srv);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[913add60] | 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 |
|
---|
[d8503fd] | 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 |
|
---|
[c8cf261] | 121 | /** Initialize display server */
|
---|
[87a7cdb] | 122 | static errno_t display_srv_init(ds_output_t **routput)
|
---|
[c8cf261] | 123 | {
|
---|
[6af4b4f] | 124 | ds_display_t *disp = NULL;
|
---|
[cf32dbd] | 125 | ds_seat_t *seat = NULL;
|
---|
[87a7cdb] | 126 | ds_output_t *output = NULL;
|
---|
[159776f] | 127 | gfx_context_t *gc = NULL;
|
---|
[ca48672] | 128 | port_id_t port = 0;
|
---|
[4c6fd56] | 129 | loc_srv_t *srv = NULL;
|
---|
| 130 | service_id_t sid = 0;
|
---|
[c8cf261] | 131 | errno_t rc;
|
---|
| 132 |
|
---|
[b3c185b6] | 133 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
|
---|
| 134 |
|
---|
[8aef01c] | 135 | rc = ds_display_create(NULL, disp_flags, &disp);
|
---|
[159776f] | 136 | if (rc != EOK)
|
---|
| 137 | goto error;
|
---|
| 138 |
|
---|
[9546146] | 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 | }
|
---|
[cf32dbd] | 149 |
|
---|
[02f45748] | 150 | rc = ds_output_create(&output);
|
---|
[87a7cdb] | 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 |
|
---|
[6fbd1f9] | 159 | rc = ds_ievent_init(disp);
|
---|
| 160 | if (rc != EOK)
|
---|
| 161 | goto error;
|
---|
| 162 |
|
---|
[dbf5d7c] | 163 | rc = ds_input_open(disp);
|
---|
| 164 | if (rc != EOK)
|
---|
| 165 | goto error;
|
---|
| 166 |
|
---|
[1766326] | 167 | rc = async_create_port(INTERFACE_DISPLAY, display_client_conn, disp,
|
---|
[ca48672] | 168 | &port);
|
---|
[1766326] | 169 | if (rc != EOK)
|
---|
| 170 | goto error;
|
---|
| 171 |
|
---|
[ca48672] | 172 | rc = async_port_create_interface(port, INTERFACE_GC, display_gc_conn,
|
---|
| 173 | disp);
|
---|
[1766326] | 174 | if (rc != EOK)
|
---|
| 175 | goto error;
|
---|
| 176 |
|
---|
[ca48672] | 177 | rc = async_port_create_interface(port, INTERFACE_WNDMGT,
|
---|
| 178 | display_wndmgt_conn, disp);
|
---|
[1766326] | 179 | if (rc != EOK)
|
---|
| 180 | goto error;
|
---|
[c8cf261] | 181 |
|
---|
[ca48672] | 182 | rc = async_port_create_interface(port, INTERFACE_DISPCFG,
|
---|
| 183 | display_dispcfg_conn, disp);
|
---|
[d8503fd] | 184 | if (rc != EOK)
|
---|
| 185 | goto error;
|
---|
| 186 |
|
---|
[4c6fd56] | 187 | rc = loc_server_register(NAME, &srv);
|
---|
[c8cf261] | 188 | if (rc != EOK) {
|
---|
| 189 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
|
---|
| 190 | rc = EEXIST;
|
---|
[8630748] | 191 | goto error;
|
---|
[c8cf261] | 192 | }
|
---|
| 193 |
|
---|
[ca48672] | 194 | rc = loc_service_register(srv, SERVICE_NAME_DISPLAY, port, &sid);
|
---|
[c8cf261] | 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 |
|
---|
[87a7cdb] | 201 | *routput = output;
|
---|
[c8cf261] | 202 | return EOK;
|
---|
| 203 | error:
|
---|
[4c6fd56] | 204 | if (sid != 0)
|
---|
| 205 | loc_service_unregister(srv, sid);
|
---|
| 206 | if (srv != NULL)
|
---|
| 207 | loc_server_unregister(srv);
|
---|
[ca48672] | 208 | if (port != 0)
|
---|
| 209 | async_port_destroy(port);
|
---|
[b3c185b6] | 210 | #if 0
|
---|
| 211 | if (disp->input != NULL)
|
---|
| 212 | ds_input_close(disp);
|
---|
| 213 | #endif
|
---|
[6fbd1f9] | 214 | ds_ievent_fini(disp);
|
---|
[87a7cdb] | 215 | if (output != NULL)
|
---|
| 216 | ds_output_destroy(output);
|
---|
[159776f] | 217 | if (gc != NULL)
|
---|
| 218 | gfx_context_delete(gc);
|
---|
[cf32dbd] | 219 | if (seat != NULL)
|
---|
| 220 | ds_seat_destroy(seat);
|
---|
[6af4b4f] | 221 | if (disp != NULL)
|
---|
| 222 | ds_display_destroy(disp);
|
---|
[c8cf261] | 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;
|
---|
[b3c185b6] | 231 | ds_client_t *client = NULL;
|
---|
[6af4b4f] | 232 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
[b3c185b6] | 233 | errno_t rc;
|
---|
[c8cf261] | 234 |
|
---|
[195b7b3] | 235 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
|
---|
[c8cf261] | 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) {
|
---|
[b3c185b6] | 242 | /* Create client object */
|
---|
[913add60] | 243 | ds_display_lock(disp);
|
---|
[be15256] | 244 | rc = ds_client_create(disp, &display_client_cb, &srv, &client);
|
---|
[913add60] | 245 | ds_display_unlock(disp);
|
---|
[b3c185b6] | 246 | if (rc != EOK) {
|
---|
| 247 | async_answer_0(icall, ENOMEM);
|
---|
| 248 | return;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | /* Set up protocol structure */
|
---|
[959b7ec] | 252 | display_srv_initialize(&srv);
|
---|
[c8cf261] | 253 | srv.ops = &display_srv_ops;
|
---|
[b3c185b6] | 254 | srv.arg = client;
|
---|
[c8cf261] | 255 |
|
---|
[b3c185b6] | 256 | /* Handle connection */
|
---|
[c8cf261] | 257 | display_conn(icall, &srv);
|
---|
[b3c185b6] | 258 |
|
---|
[1762ceb] | 259 | ds_display_lock(disp);
|
---|
[b3c185b6] | 260 | ds_client_destroy(client);
|
---|
[1762ceb] | 261 | ds_display_unlock(disp);
|
---|
[1766326] | 262 | }
|
---|
| 263 | }
|
---|
[b3c185b6] | 264 |
|
---|
[1766326] | 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;
|
---|
[c8cf261] | 272 |
|
---|
[1766326] | 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;
|
---|
[c8cf261] | 285 | }
|
---|
[1766326] | 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 | {
|
---|
[7a05d924] | 298 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
[913add60] | 299 | errno_t rc;
|
---|
[1766326] | 300 | wndmgt_srv_t srv;
|
---|
[913add60] | 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 | }
|
---|
[1766326] | 311 |
|
---|
| 312 | /* Set up protocol structure */
|
---|
| 313 | wndmgt_srv_initialize(&srv);
|
---|
| 314 | srv.ops = &wndmgt_srv_ops;
|
---|
[913add60] | 315 | srv.arg = wmclient;
|
---|
[1766326] | 316 |
|
---|
| 317 | /* Handle connection */
|
---|
| 318 | wndmgt_conn(icall, &srv);
|
---|
[913add60] | 319 |
|
---|
| 320 | ds_display_lock(disp);
|
---|
| 321 | ds_wmclient_destroy(wmclient);
|
---|
| 322 | ds_display_unlock(disp);
|
---|
[c8cf261] | 323 | }
|
---|
| 324 |
|
---|
[d8503fd] | 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 |
|
---|
[c8cf261] | 355 | int main(int argc, char *argv[])
|
---|
| 356 | {
|
---|
| 357 | errno_t rc;
|
---|
[87a7cdb] | 358 | ds_output_t *output;
|
---|
[c8cf261] | 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 |
|
---|
[87a7cdb] | 367 | rc = display_srv_init(&output);
|
---|
[c8cf261] | 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 | */
|
---|