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
Line 
1/*
2 * Copyright (c) 2024 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
65const char *cfg_file_path = "/w/cfg/display.sif";
66
67static void display_client_conn(ipc_call_t *, void *);
68static void display_client_ev_pending(void *);
69static void display_wmclient_ev_pending(void *);
70static void display_cfgclient_ev_pending(void *);
71static void display_gc_conn(ipc_call_t *, void *);
72static void display_wndmgt_conn(ipc_call_t *, void *);
73static 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 */
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
88static ds_client_cb_t display_client_cb = {
89 .ev_pending = display_client_ev_pending
90};
91
92static ds_wmclient_cb_t display_wmclient_cb = {
93 .ev_pending = display_wmclient_ev_pending
94};
95
96static ds_cfgclient_cb_t display_cfgclient_cb = {
97 .ev_pending = display_cfgclient_ev_pending
98};
99
100static 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
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
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
121/** Initialize display server */
122static 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 disp_port;
129 port_id_t gc_port;
130 port_id_t wm_port;
131 port_id_t dc_port;
132 loc_srv_t *srv = NULL;
133 service_id_t sid = 0;
134 errno_t rc;
135
136 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
137
138 rc = ds_display_create(NULL, disp_flags, &disp);
139 if (rc != EOK)
140 goto error;
141
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 }
152
153 rc = ds_output_create(&output);
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
162 rc = ds_ievent_init(disp);
163 if (rc != EOK)
164 goto error;
165
166 rc = ds_input_open(disp);
167 if (rc != EOK)
168 goto error;
169
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;
183
184 rc = async_create_port(INTERFACE_DISPCFG, display_dispcfg_conn, disp,
185 &dc_port);
186 if (rc != EOK)
187 goto error;
188
189 rc = loc_server_register(NAME, &srv);
190 if (rc != EOK) {
191 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
192 rc = EEXIST;
193 goto error;
194 }
195
196 rc = loc_service_register(srv, SERVICE_NAME_DISPLAY, &sid);
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
203 *routput = output;
204 return EOK;
205error:
206 if (sid != 0)
207 loc_service_unregister(srv, sid);
208 if (srv != NULL)
209 loc_server_unregister(srv);
210 // XXX destroy disp_port
211 // XXX destroy gc_port
212 // XXX destroy wm_port
213 // XXX destroy dc_port
214#if 0
215 if (disp->input != NULL)
216 ds_input_close(disp);
217#endif
218 ds_ievent_fini(disp);
219 if (output != NULL)
220 ds_output_destroy(output);
221 if (gc != NULL)
222 gfx_context_delete(gc);
223 if (seat != NULL)
224 ds_seat_destroy(seat);
225 if (disp != NULL)
226 ds_display_destroy(disp);
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;
235 ds_client_t *client = NULL;
236 ds_display_t *disp = (ds_display_t *) arg;
237 errno_t rc;
238
239 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
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) {
246 /* Create client object */
247 ds_display_lock(disp);
248 rc = ds_client_create(disp, &display_client_cb, &srv, &client);
249 ds_display_unlock(disp);
250 if (rc != EOK) {
251 async_answer_0(icall, ENOMEM);
252 return;
253 }
254
255 /* Set up protocol structure */
256 display_srv_initialize(&srv);
257 srv.ops = &display_srv_ops;
258 srv.arg = client;
259
260 /* Handle connection */
261 display_conn(icall, &srv);
262
263 ds_display_lock(disp);
264 ds_client_destroy(client);
265 ds_display_unlock(disp);
266 }
267}
268
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;
276
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;
289 }
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{
302 ds_display_t *disp = (ds_display_t *) arg;
303 errno_t rc;
304 wndmgt_srv_t srv;
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 }
315
316 /* Set up protocol structure */
317 wndmgt_srv_initialize(&srv);
318 srv.ops = &wndmgt_srv_ops;
319 srv.arg = wmclient;
320
321 /* Handle connection */
322 wndmgt_conn(icall, &srv);
323
324 ds_display_lock(disp);
325 ds_wmclient_destroy(wmclient);
326 ds_display_unlock(disp);
327}
328
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
359int main(int argc, char *argv[])
360{
361 errno_t rc;
362 ds_output_t *output;
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
371 rc = display_srv_init(&output);
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.