source: mainline/uspace/srv/hid/display/main.c@ 7a05d924

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7a05d924 was 7a05d924, checked in by Jiri Svoboda <jiri@…>, 3 years ago

Return correct number of windows from display server

But not the caption since the display server does not have it

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