[c8cf261] | 1 | /*
|
---|
[1766326] | 2 | * Copyright (c) 2022 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>
|
---|
| 38 | #include <errno.h>
|
---|
| 39 | #include <gfx/context.h>
|
---|
| 40 | #include <str_error.h>
|
---|
| 41 | #include <io/log.h>
|
---|
[24cf391a] | 42 | #include <io/kbd_event.h>
|
---|
| 43 | #include <io/pos_event.h>
|
---|
[c8cf261] | 44 | #include <ipc/services.h>
|
---|
| 45 | #include <ipcgfx/server.h>
|
---|
| 46 | #include <loc.h>
|
---|
| 47 | #include <stdio.h>
|
---|
| 48 | #include <task.h>
|
---|
[1766326] | 49 | #include <wndmgt_srv.h>
|
---|
[b3c185b6] | 50 | #include "client.h"
|
---|
[c8cf261] | 51 | #include "display.h"
|
---|
[38e5f36c] | 52 | #include "dsops.h"
|
---|
[02f45748] | 53 | #include "input.h"
|
---|
[b3c185b6] | 54 | #include "main.h"
|
---|
[159776f] | 55 | #include "output.h"
|
---|
[cf32dbd] | 56 | #include "seat.h"
|
---|
[6af4b4f] | 57 | #include "window.h"
|
---|
[913add60] | 58 | #include "wmclient.h"
|
---|
[1766326] | 59 | #include "wmops.h"
|
---|
[c8cf261] | 60 |
|
---|
| 61 | static void display_client_conn(ipc_call_t *, void *);
|
---|
[be15256] | 62 | static void display_client_ev_pending(void *);
|
---|
[913add60] | 63 | static void display_wmclient_ev_pending(void *);
|
---|
[1766326] | 64 | static void display_gc_conn(ipc_call_t *, void *);
|
---|
| 65 | static void display_wndmgt_conn(ipc_call_t *, void *);
|
---|
[be15256] | 66 |
|
---|
[8aef01c] | 67 | #ifdef CONFIG_DISP_DOUBLE_BUF
|
---|
| 68 | /*
|
---|
| 69 | * Double buffering is one way to provide flicker-free display.
|
---|
| 70 | */
|
---|
| 71 | static ds_display_flags_t disp_flags = df_disp_double_buf;
|
---|
| 72 | #else
|
---|
| 73 | /*
|
---|
| 74 | * With double buffering disabled, wet screen flicker since front-to-back
|
---|
| 75 | * rendering is not implemented.
|
---|
| 76 | */
|
---|
| 77 | static ds_display_flags_t disp_flags = df_none;
|
---|
| 78 | #endif
|
---|
| 79 |
|
---|
[be15256] | 80 | static ds_client_cb_t display_client_cb = {
|
---|
| 81 | .ev_pending = display_client_ev_pending
|
---|
| 82 | };
|
---|
[c8cf261] | 83 |
|
---|
[913add60] | 84 | static ds_wmclient_cb_t display_wmclient_cb = {
|
---|
| 85 | .ev_pending = display_wmclient_ev_pending
|
---|
| 86 | };
|
---|
| 87 |
|
---|
[be15256] | 88 | static void display_client_ev_pending(void *arg)
|
---|
| 89 | {
|
---|
| 90 | display_srv_t *srv = (display_srv_t *) arg;
|
---|
[6c2aba3] | 91 |
|
---|
[be15256] | 92 | display_srv_ev_pending(srv);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[913add60] | 95 | static void display_wmclient_ev_pending(void *arg)
|
---|
| 96 | {
|
---|
| 97 | wndmgt_srv_t *srv = (wndmgt_srv_t *) arg;
|
---|
| 98 |
|
---|
| 99 | wndmgt_srv_ev_pending(srv);
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[c8cf261] | 102 | /** Initialize display server */
|
---|
[87a7cdb] | 103 | static errno_t display_srv_init(ds_output_t **routput)
|
---|
[c8cf261] | 104 | {
|
---|
[6af4b4f] | 105 | ds_display_t *disp = NULL;
|
---|
[cf32dbd] | 106 | ds_seat_t *seat = NULL;
|
---|
[87a7cdb] | 107 | ds_output_t *output = NULL;
|
---|
[159776f] | 108 | gfx_context_t *gc = NULL;
|
---|
[1766326] | 109 | port_id_t disp_port;
|
---|
| 110 | port_id_t gc_port;
|
---|
| 111 | port_id_t wm_port;
|
---|
[c8cf261] | 112 | errno_t rc;
|
---|
| 113 |
|
---|
[b3c185b6] | 114 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
|
---|
| 115 |
|
---|
[8aef01c] | 116 | rc = ds_display_create(NULL, disp_flags, &disp);
|
---|
[159776f] | 117 | if (rc != EOK)
|
---|
| 118 | goto error;
|
---|
| 119 |
|
---|
[cf32dbd] | 120 | rc = ds_seat_create(disp, &seat);
|
---|
| 121 | if (rc != EOK)
|
---|
| 122 | goto error;
|
---|
| 123 |
|
---|
[02f45748] | 124 | rc = ds_output_create(&output);
|
---|
[87a7cdb] | 125 | if (rc != EOK)
|
---|
| 126 | goto error;
|
---|
| 127 |
|
---|
| 128 | output->def_display = disp;
|
---|
| 129 | rc = ds_output_start_discovery(output);
|
---|
| 130 | if (rc != EOK)
|
---|
| 131 | goto error;
|
---|
| 132 |
|
---|
[dbf5d7c] | 133 | rc = ds_input_open(disp);
|
---|
| 134 | if (rc != EOK)
|
---|
| 135 | goto error;
|
---|
| 136 |
|
---|
[1766326] | 137 | rc = async_create_port(INTERFACE_DISPLAY, display_client_conn, disp,
|
---|
| 138 | &disp_port);
|
---|
| 139 | if (rc != EOK)
|
---|
| 140 | goto error;
|
---|
| 141 |
|
---|
| 142 | rc = async_create_port(INTERFACE_GC, display_gc_conn, disp, &gc_port);
|
---|
| 143 | if (rc != EOK)
|
---|
| 144 | goto error;
|
---|
| 145 |
|
---|
| 146 | rc = async_create_port(INTERFACE_WNDMGT, display_wndmgt_conn, disp,
|
---|
| 147 | &wm_port);
|
---|
| 148 | if (rc != EOK)
|
---|
| 149 | goto error;
|
---|
[c8cf261] | 150 |
|
---|
| 151 | rc = loc_server_register(NAME);
|
---|
| 152 | if (rc != EOK) {
|
---|
| 153 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
|
---|
| 154 | rc = EEXIST;
|
---|
[8630748] | 155 | goto error;
|
---|
[c8cf261] | 156 | }
|
---|
| 157 |
|
---|
| 158 | service_id_t sid;
|
---|
| 159 | rc = loc_service_register(SERVICE_NAME_DISPLAY, &sid);
|
---|
| 160 | if (rc != EOK) {
|
---|
| 161 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
|
---|
| 162 | rc = EEXIST;
|
---|
| 163 | goto error;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[87a7cdb] | 166 | *routput = output;
|
---|
[c8cf261] | 167 | return EOK;
|
---|
| 168 | error:
|
---|
[1766326] | 169 | // XXX destroy disp_port
|
---|
| 170 | // XXX destroy gc_port
|
---|
| 171 | // XXX destroy wm_port
|
---|
[b3c185b6] | 172 | #if 0
|
---|
| 173 | if (disp->input != NULL)
|
---|
| 174 | ds_input_close(disp);
|
---|
| 175 | #endif
|
---|
[87a7cdb] | 176 | if (output != NULL)
|
---|
| 177 | ds_output_destroy(output);
|
---|
[159776f] | 178 | if (gc != NULL)
|
---|
| 179 | gfx_context_delete(gc);
|
---|
[cf32dbd] | 180 | if (seat != NULL)
|
---|
| 181 | ds_seat_destroy(seat);
|
---|
[6af4b4f] | 182 | if (disp != NULL)
|
---|
| 183 | ds_display_destroy(disp);
|
---|
[c8cf261] | 184 | return rc;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | /** Handle client connection to display server */
|
---|
| 188 | static void display_client_conn(ipc_call_t *icall, void *arg)
|
---|
| 189 | {
|
---|
| 190 | display_srv_t srv;
|
---|
| 191 | sysarg_t svc_id;
|
---|
[b3c185b6] | 192 | ds_client_t *client = NULL;
|
---|
[6af4b4f] | 193 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
[b3c185b6] | 194 | errno_t rc;
|
---|
[c8cf261] | 195 |
|
---|
[195b7b3] | 196 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
|
---|
[c8cf261] | 197 | ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
|
---|
| 198 | ipc_get_arg4(icall));
|
---|
| 199 |
|
---|
| 200 | svc_id = ipc_get_arg2(icall);
|
---|
| 201 |
|
---|
| 202 | if (svc_id != 0) {
|
---|
[b3c185b6] | 203 | /* Create client object */
|
---|
[913add60] | 204 | ds_display_lock(disp);
|
---|
[be15256] | 205 | rc = ds_client_create(disp, &display_client_cb, &srv, &client);
|
---|
[913add60] | 206 | ds_display_unlock(disp);
|
---|
[b3c185b6] | 207 | if (rc != EOK) {
|
---|
| 208 | async_answer_0(icall, ENOMEM);
|
---|
| 209 | return;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | /* Set up protocol structure */
|
---|
[959b7ec] | 213 | display_srv_initialize(&srv);
|
---|
[c8cf261] | 214 | srv.ops = &display_srv_ops;
|
---|
[b3c185b6] | 215 | srv.arg = client;
|
---|
[c8cf261] | 216 |
|
---|
[b3c185b6] | 217 | /* Handle connection */
|
---|
[c8cf261] | 218 | display_conn(icall, &srv);
|
---|
[b3c185b6] | 219 |
|
---|
[1762ceb] | 220 | ds_display_lock(disp);
|
---|
[b3c185b6] | 221 | ds_client_destroy(client);
|
---|
[1762ceb] | 222 | ds_display_unlock(disp);
|
---|
[1766326] | 223 | }
|
---|
| 224 | }
|
---|
[b3c185b6] | 225 |
|
---|
[1766326] | 226 | /** Handle GC connection to display server */
|
---|
| 227 | static void display_gc_conn(ipc_call_t *icall, void *arg)
|
---|
| 228 | {
|
---|
| 229 | sysarg_t wnd_id;
|
---|
| 230 | ds_window_t *wnd;
|
---|
| 231 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
| 232 | gfx_context_t *gc;
|
---|
[c8cf261] | 233 |
|
---|
[1766326] | 234 | log_msg(LOG_DEFAULT, LVL_DEBUG, "display_gc_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
|
---|
| 235 | ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
|
---|
| 236 | ipc_get_arg4(icall));
|
---|
| 237 |
|
---|
| 238 | wnd_id = ipc_get_arg3(icall);
|
---|
| 239 |
|
---|
| 240 | /* Window GC connection */
|
---|
| 241 |
|
---|
| 242 | wnd = ds_display_find_window(disp, wnd_id);
|
---|
| 243 | if (wnd == NULL) {
|
---|
| 244 | async_answer_0(icall, ENOENT);
|
---|
| 245 | return;
|
---|
[c8cf261] | 246 | }
|
---|
[1766326] | 247 |
|
---|
| 248 | /*
|
---|
| 249 | * XXX We need a way to make sure that the connection does
|
---|
| 250 | * not stay active after the window had been destroyed
|
---|
| 251 | */
|
---|
| 252 | gc = ds_window_get_ctx(wnd);
|
---|
| 253 | gc_conn(icall, gc);
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | /** Handle window management connection to display server */
|
---|
| 257 | static void display_wndmgt_conn(ipc_call_t *icall, void *arg)
|
---|
| 258 | {
|
---|
[7a05d924] | 259 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
[913add60] | 260 | errno_t rc;
|
---|
[1766326] | 261 | wndmgt_srv_t srv;
|
---|
[913add60] | 262 | ds_wmclient_t *wmclient = NULL;
|
---|
| 263 |
|
---|
| 264 | /* Create WM client object */
|
---|
| 265 | ds_display_lock(disp);
|
---|
| 266 | rc = ds_wmclient_create(disp, &display_wmclient_cb, &srv, &wmclient);
|
---|
| 267 | ds_display_unlock(disp);
|
---|
| 268 | if (rc != EOK) {
|
---|
| 269 | async_answer_0(icall, ENOMEM);
|
---|
| 270 | return;
|
---|
| 271 | }
|
---|
[1766326] | 272 |
|
---|
| 273 | /* Set up protocol structure */
|
---|
| 274 | wndmgt_srv_initialize(&srv);
|
---|
| 275 | srv.ops = &wndmgt_srv_ops;
|
---|
[913add60] | 276 | srv.arg = wmclient;
|
---|
[1766326] | 277 |
|
---|
| 278 | /* Handle connection */
|
---|
| 279 | wndmgt_conn(icall, &srv);
|
---|
[913add60] | 280 |
|
---|
| 281 | ds_display_lock(disp);
|
---|
| 282 | ds_wmclient_destroy(wmclient);
|
---|
| 283 | ds_display_unlock(disp);
|
---|
[c8cf261] | 284 | }
|
---|
| 285 |
|
---|
| 286 | int main(int argc, char *argv[])
|
---|
| 287 | {
|
---|
| 288 | errno_t rc;
|
---|
[87a7cdb] | 289 | ds_output_t *output;
|
---|
[c8cf261] | 290 |
|
---|
| 291 | printf("%s: Display server\n", NAME);
|
---|
| 292 |
|
---|
| 293 | if (log_init(NAME) != EOK) {
|
---|
| 294 | printf(NAME ": Failed to initialize logging.\n");
|
---|
| 295 | return 1;
|
---|
| 296 | }
|
---|
| 297 |
|
---|
[87a7cdb] | 298 | rc = display_srv_init(&output);
|
---|
[c8cf261] | 299 | if (rc != EOK)
|
---|
| 300 | return 1;
|
---|
| 301 |
|
---|
| 302 | printf(NAME ": Accepting connections.\n");
|
---|
| 303 | task_retval(0);
|
---|
| 304 | async_manager();
|
---|
| 305 |
|
---|
| 306 | return 0;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | /** @}
|
---|
| 310 | */
|
---|