source: mainline/uspace/srv/hid/display/main.c@ 6fbd1f9

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

Combine successive move/abs. move events in display server

Helps avoid the cursor lagging if re-drawing cannot keep up
with the rate of move events.

  • Property mode set to 100644
File size: 9.2 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"
[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]65const char *cfg_file_path = "/w/cfg/display.sif";
66
[c8cf261]67static void display_client_conn(ipc_call_t *, void *);
[be15256]68static void display_client_ev_pending(void *);
[913add60]69static void display_wmclient_ev_pending(void *);
[d8503fd]70static void display_cfgclient_ev_pending(void *);
[1766326]71static void display_gc_conn(ipc_call_t *, void *);
72static void display_wndmgt_conn(ipc_call_t *, void *);
[d8503fd]73static 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 */
79static 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 */
85static ds_display_flags_t disp_flags = df_none;
86#endif
87
[be15256]88static ds_client_cb_t display_client_cb = {
89 .ev_pending = display_client_ev_pending
90};
[c8cf261]91
[913add60]92static ds_wmclient_cb_t display_wmclient_cb = {
93 .ev_pending = display_wmclient_ev_pending
94};
95
[d8503fd]96static ds_cfgclient_cb_t display_cfgclient_cb = {
97 .ev_pending = display_cfgclient_ev_pending
98};
99
[be15256]100static 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]107static 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]114static 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]122static 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;
[1766326]128 port_id_t disp_port;
129 port_id_t gc_port;
130 port_id_t wm_port;
[d8503fd]131 port_id_t dc_port;
[4c6fd56]132 loc_srv_t *srv = NULL;
133 service_id_t sid = 0;
[c8cf261]134 errno_t rc;
135
[b3c185b6]136 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
137
[8aef01c]138 rc = ds_display_create(NULL, disp_flags, &disp);
[159776f]139 if (rc != EOK)
140 goto error;
141
[9546146]142 rc = ds_display_load_cfg(disp, cfg_file_path);
143 if (rc != EOK) {
144 log_msg(LOG_DEFAULT, LVL_NOTE,
145 "Starting with fresh configuration.");
146
147 /* Create first seat */
148 rc = ds_seat_create(disp, "Alice", &seat);
149 if (rc != EOK)
150 goto error;
151 }
[cf32dbd]152
[02f45748]153 rc = ds_output_create(&output);
[87a7cdb]154 if (rc != EOK)
155 goto error;
156
157 output->def_display = disp;
158 rc = ds_output_start_discovery(output);
159 if (rc != EOK)
160 goto error;
161
[6fbd1f9]162 rc = ds_ievent_init(disp);
163 if (rc != EOK)
164 goto error;
165
[dbf5d7c]166 rc = ds_input_open(disp);
167 if (rc != EOK)
168 goto error;
169
[1766326]170 rc = async_create_port(INTERFACE_DISPLAY, display_client_conn, disp,
171 &disp_port);
172 if (rc != EOK)
173 goto error;
174
175 rc = async_create_port(INTERFACE_GC, display_gc_conn, disp, &gc_port);
176 if (rc != EOK)
177 goto error;
178
179 rc = async_create_port(INTERFACE_WNDMGT, display_wndmgt_conn, disp,
180 &wm_port);
181 if (rc != EOK)
182 goto error;
[c8cf261]183
[d8503fd]184 rc = async_create_port(INTERFACE_DISPCFG, display_dispcfg_conn, disp,
185 &dc_port);
186 if (rc != EOK)
187 goto error;
188
[4c6fd56]189 rc = loc_server_register(NAME, &srv);
[c8cf261]190 if (rc != EOK) {
191 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
192 rc = EEXIST;
[8630748]193 goto error;
[c8cf261]194 }
195
[4c6fd56]196 rc = loc_service_register(srv, SERVICE_NAME_DISPLAY, &sid);
[c8cf261]197 if (rc != EOK) {
198 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
199 rc = EEXIST;
200 goto error;
201 }
202
[87a7cdb]203 *routput = output;
[c8cf261]204 return EOK;
205error:
[4c6fd56]206 if (sid != 0)
207 loc_service_unregister(srv, sid);
208 if (srv != NULL)
209 loc_server_unregister(srv);
[1766326]210 // XXX destroy disp_port
211 // XXX destroy gc_port
212 // XXX destroy wm_port
[d8503fd]213 // XXX destroy dc_port
[b3c185b6]214#if 0
215 if (disp->input != NULL)
216 ds_input_close(disp);
217#endif
[6fbd1f9]218 ds_ievent_fini(disp);
[87a7cdb]219 if (output != NULL)
220 ds_output_destroy(output);
[159776f]221 if (gc != NULL)
222 gfx_context_delete(gc);
[cf32dbd]223 if (seat != NULL)
224 ds_seat_destroy(seat);
[6af4b4f]225 if (disp != NULL)
226 ds_display_destroy(disp);
[c8cf261]227 return rc;
228}
229
230/** Handle client connection to display server */
231static void display_client_conn(ipc_call_t *icall, void *arg)
232{
233 display_srv_t srv;
234 sysarg_t svc_id;
[b3c185b6]235 ds_client_t *client = NULL;
[6af4b4f]236 ds_display_t *disp = (ds_display_t *) arg;
[b3c185b6]237 errno_t rc;
[c8cf261]238
[195b7b3]239 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
[c8cf261]240 ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
241 ipc_get_arg4(icall));
242
243 svc_id = ipc_get_arg2(icall);
244
245 if (svc_id != 0) {
[b3c185b6]246 /* Create client object */
[913add60]247 ds_display_lock(disp);
[be15256]248 rc = ds_client_create(disp, &display_client_cb, &srv, &client);
[913add60]249 ds_display_unlock(disp);
[b3c185b6]250 if (rc != EOK) {
251 async_answer_0(icall, ENOMEM);
252 return;
253 }
254
255 /* Set up protocol structure */
[959b7ec]256 display_srv_initialize(&srv);
[c8cf261]257 srv.ops = &display_srv_ops;
[b3c185b6]258 srv.arg = client;
[c8cf261]259
[b3c185b6]260 /* Handle connection */
[c8cf261]261 display_conn(icall, &srv);
[b3c185b6]262
[1762ceb]263 ds_display_lock(disp);
[b3c185b6]264 ds_client_destroy(client);
[1762ceb]265 ds_display_unlock(disp);
[1766326]266 }
267}
[b3c185b6]268
[1766326]269/** Handle GC connection to display server */
270static void display_gc_conn(ipc_call_t *icall, void *arg)
271{
272 sysarg_t wnd_id;
273 ds_window_t *wnd;
274 ds_display_t *disp = (ds_display_t *) arg;
275 gfx_context_t *gc;
[c8cf261]276
[1766326]277 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_gc_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
278 ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
279 ipc_get_arg4(icall));
280
281 wnd_id = ipc_get_arg3(icall);
282
283 /* Window GC connection */
284
285 wnd = ds_display_find_window(disp, wnd_id);
286 if (wnd == NULL) {
287 async_answer_0(icall, ENOENT);
288 return;
[c8cf261]289 }
[1766326]290
291 /*
292 * XXX We need a way to make sure that the connection does
293 * not stay active after the window had been destroyed
294 */
295 gc = ds_window_get_ctx(wnd);
296 gc_conn(icall, gc);
297}
298
299/** Handle window management connection to display server */
300static void display_wndmgt_conn(ipc_call_t *icall, void *arg)
301{
[7a05d924]302 ds_display_t *disp = (ds_display_t *) arg;
[913add60]303 errno_t rc;
[1766326]304 wndmgt_srv_t srv;
[913add60]305 ds_wmclient_t *wmclient = NULL;
306
307 /* Create WM client object */
308 ds_display_lock(disp);
309 rc = ds_wmclient_create(disp, &display_wmclient_cb, &srv, &wmclient);
310 ds_display_unlock(disp);
311 if (rc != EOK) {
312 async_answer_0(icall, ENOMEM);
313 return;
314 }
[1766326]315
316 /* Set up protocol structure */
317 wndmgt_srv_initialize(&srv);
318 srv.ops = &wndmgt_srv_ops;
[913add60]319 srv.arg = wmclient;
[1766326]320
321 /* Handle connection */
322 wndmgt_conn(icall, &srv);
[913add60]323
324 ds_display_lock(disp);
325 ds_wmclient_destroy(wmclient);
326 ds_display_unlock(disp);
[c8cf261]327}
328
[d8503fd]329/** Handle configuration connection to display server */
330static void display_dispcfg_conn(ipc_call_t *icall, void *arg)
331{
332 ds_display_t *disp = (ds_display_t *) arg;
333 errno_t rc;
334 dispcfg_srv_t srv;
335 ds_cfgclient_t *cfgclient = NULL;
336
337 /* Create CFG client object */
338 ds_display_lock(disp);
339 rc = ds_cfgclient_create(disp, &display_cfgclient_cb, &srv, &cfgclient);
340 ds_display_unlock(disp);
341 if (rc != EOK) {
342 async_answer_0(icall, ENOMEM);
343 return;
344 }
345
346 /* Set up protocol structure */
347 dispcfg_srv_initialize(&srv);
348 srv.ops = &dispcfg_srv_ops;
349 srv.arg = cfgclient;
350
351 /* Handle connection */
352 dispcfg_conn(icall, &srv);
353
354 ds_display_lock(disp);
355 ds_cfgclient_destroy(cfgclient);
356 ds_display_unlock(disp);
357}
358
[c8cf261]359int main(int argc, char *argv[])
360{
361 errno_t rc;
[87a7cdb]362 ds_output_t *output;
[c8cf261]363
364 printf("%s: Display server\n", NAME);
365
366 if (log_init(NAME) != EOK) {
367 printf(NAME ": Failed to initialize logging.\n");
368 return 1;
369 }
370
[87a7cdb]371 rc = display_srv_init(&output);
[c8cf261]372 if (rc != EOK)
373 return 1;
374
375 printf(NAME ": Accepting connections.\n");
376 task_retval(0);
377 async_manager();
378
379 return 0;
380}
381
382/** @}
383 */
Note: See TracBrowser for help on using the repository browser.