Changeset b3c185b6 in mainline
- Timestamp:
- 2019-11-04T14:05:35Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- be15256
- Parents:
- 22faaf2
- git-author:
- Jiri Svoboda <jiri@…> (2019-10-03 18:05:09)
- git-committer:
- Jiri Svoboda <jiri@…> (2019-11-04 14:05:35)
- Files:
-
- 6 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
abi/include/abi/ipc/interfaces.h
r22faaf2 rb3c185b6 190 190 INTERFACE_DISPLAY = 191 191 FOURCC_COMPACT('d', 's', 'p', 'l') | IFACE_EXCHANGE_SERIALIZE, 192 INTERFACE_DISPLAY_CB = 193 FOURCC_COMPACT('d', 's', 'p', 'l') | IFACE_EXCHANGE_SERIALIZE | IFACE_MOD_CALLBACK, 192 194 INTERFACE_GC = 193 195 FOURCC_COMPACT('g', 'f', 'x', 'c') | IFACE_EXCHANGE_SERIALIZE, -
uspace/app/gfxdemo/gfxdemo.c
r22faaf2 rb3c185b6 44 44 #include <io/console.h> 45 45 #include <io/pixelmap.h> 46 #include <stdbool.h> 46 47 #include <stdlib.h> 47 48 #include <str.h> 48 49 #include <window.h> 50 51 static void wnd_kbd_event(void *, kbd_event_t *); 52 53 static display_wnd_cb_t wnd_cb = { 54 .kbd_event = wnd_kbd_event 55 }; 56 57 static bool quit = false; 49 58 50 59 /** Clear screen. … … 126 135 127 136 fibril_usleep(500 * 1000); 137 138 if (quit) 139 break; 128 140 } 129 141 … … 245 257 goto error; 246 258 fibril_usleep(250 * 1000); 259 260 if (quit) 261 break; 247 262 } 248 263 } … … 298 313 299 314 fibril_usleep(500 * 1000); 315 316 if (quit) 317 break; 300 318 } 301 319 … … 318 336 errno_t rc; 319 337 320 while ( true) {338 while (!quit) { 321 339 rc = demo_rects(gc, w, h); 322 340 if (rc != EOK) … … 331 349 return rc; 332 350 } 351 352 return EOK; 333 353 } 334 354 … … 444 464 } 445 465 446 rc = display_window_create(display, &w indow);466 rc = display_window_create(display, &wnd_cb, NULL, &window); 447 467 if (rc != EOK) { 448 468 printf("Error creating window.\n"); … … 464 484 465 485 return EOK; 486 } 487 488 static void wnd_kbd_event(void *arg, kbd_event_t *event) 489 { 490 printf("Keyboard event type=%d key=%d\n", event->type, event->key); 491 quit = true; 466 492 } 467 493 -
uspace/lib/display/include/disp_srv.h
r22faaf2 rb3c185b6 38 38 #include <async.h> 39 39 #include <errno.h> 40 #include <types/display/event.h> 40 41 41 42 typedef struct display_ops display_ops_t; … … 51 52 errno_t (*window_create)(void *, sysarg_t *); 52 53 errno_t (*window_destroy)(void *, sysarg_t); 54 errno_t (*get_event)(void *, sysarg_t *, display_wnd_ev_t *); 53 55 }; 54 56 55 57 extern void display_conn(ipc_call_t *, display_srv_t *); 58 extern void display_srv_ev_pending(display_srv_t *); 56 59 57 60 #endif -
uspace/lib/display/include/display.h
r22faaf2 rb3c185b6 43 43 extern errno_t display_open(const char *, display_t **); 44 44 extern void display_close(display_t *); 45 extern errno_t display_window_create(display_t *, display_window_t **); 45 extern errno_t display_window_create(display_t *, display_wnd_cb_t *, 46 void *, display_window_t **); 46 47 extern errno_t display_window_destroy(display_window_t *); 47 48 extern errno_t display_window_get_gc(display_window_t *, gfx_context_t **); -
uspace/lib/display/include/ipc/display.h
r22faaf2 rb3c185b6 39 39 40 40 typedef enum { 41 DISPLAY_WINDOW_CREATE = IPC_FIRST_USER_METHOD, 41 DISPLAY_CALLBACK_CREATE = IPC_FIRST_USER_METHOD, 42 DISPLAY_WINDOW_CREATE, 42 43 DISPLAY_WINDOW_DESTROY, 43 DISPLAY_ WINDOW_GC44 DISPLAY_GET_EVENT 44 45 } display_request_t; 46 47 typedef enum { 48 DISPLAY_EV_PENDING = IPC_FIRST_USER_METHOD 49 } display_event_t; 45 50 46 51 #endif -
uspace/lib/display/include/types/display.h
r22faaf2 rb3c185b6 37 37 38 38 #include <async.h> 39 #include <fibril_synch.h> 40 #include <io/kbd_event.h> 39 41 #include <ipc/devman.h> 40 42 #include <stdint.h> … … 44 46 /** Session with display server */ 45 47 async_sess_t *sess; 48 /** Synchronize access to display object */ 49 fibril_mutex_t lock; 50 /** @c true if callback handler terminated */ 51 bool cb_done; 52 /** Signalled when cb_done or ev_pending is changed */ 53 fibril_condvar_t cv; 54 /** Windows (of display_window_t) */ 55 list_t windows; 46 56 } display_t; 57 58 /** Display window callbacks */ 59 typedef struct { 60 void (*kbd_event)(void *, kbd_event_t *); 61 } display_wnd_cb_t; 62 63 typedef struct { 64 kbd_event_t kbd_event; 65 } display_wnd_ev_t; 47 66 48 67 /** Display window */ … … 50 69 /** Display associated with the window */ 51 70 display_t *display; 71 /** Link to @c display->windows */ 72 link_t lwindows; 52 73 /** Window ID */ 53 74 sysarg_t id; 75 /** Callback functions */ 76 display_wnd_cb_t *cb; 77 /** Argument to callback functions */ 78 void *cb_arg; 54 79 } display_window_t; 55 80 -
uspace/lib/display/src/disp_srv.c
r22faaf2 rb3c185b6 36 36 37 37 #include <disp_srv.h> 38 #include <display/event.h> 38 39 #include <errno.h> 40 #include <io/log.h> 39 41 #include <ipc/display.h> 40 42 #include <stdlib.h> 41 43 #include <stddef.h> 44 45 #include <stdio.h> 46 static void display_callback_create_srv(display_srv_t *srv, ipc_call_t *call) 47 { 48 printf("display_callback_create_srv\n"); 49 50 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); 51 if (sess == NULL) { 52 async_answer_0(call, ENOMEM); 53 return; 54 } 55 56 srv->client_sess = sess; 57 async_answer_0(call, EOK); 58 } 42 59 43 60 static void display_window_create_srv(display_srv_t *srv, ipc_call_t *icall) … … 45 62 sysarg_t wnd_id; 46 63 errno_t rc; 64 65 printf("display_window_create_srv\n"); 47 66 48 67 if (srv->ops->window_create == NULL) { … … 60 79 errno_t rc; 61 80 81 printf("display_window_destroy_srv\n"); 82 62 83 wnd_id = ipc_get_arg1(icall); 63 84 … … 71 92 } 72 93 94 static void display_get_event_srv(display_srv_t *srv, ipc_call_t *icall) 95 { 96 sysarg_t wnd_id; 97 display_wnd_ev_t event; 98 ipc_call_t call; 99 size_t size; 100 errno_t rc; 101 102 printf("display_get_event_srv\n"); 103 104 if (srv->ops->get_event == NULL) { 105 async_answer_0(icall, ENOTSUP); 106 return; 107 } 108 109 rc = srv->ops->get_event(srv->arg, &wnd_id, &event); 110 if (rc != EOK) 111 async_answer_0(icall, rc); 112 113 /* Transfer event data */ 114 if (!async_data_read_receive(&call, &size)) { 115 async_answer_0(icall, EREFUSED); 116 return; 117 } 118 119 if (size != sizeof(event)) { 120 async_answer_0(icall, EREFUSED); 121 async_answer_0(&call, EREFUSED); 122 return; 123 } 124 125 rc = async_data_read_finalize(&call, &event, sizeof(event)); 126 if (rc != EOK) { 127 async_answer_0(icall, rc); 128 async_answer_0(&call, rc); 129 return; 130 } 131 132 async_answer_1(icall, EOK, wnd_id); 133 } 134 73 135 void display_conn(ipc_call_t *icall, display_srv_t *srv) 74 136 { 75 137 /* Accept the connection */ 76 138 async_accept_0(icall); 139 printf("display_conn\n"); 77 140 78 141 while (true) { … … 88 151 } 89 152 153 printf("display_conn method=%lu\n", method); 90 154 switch (method) { 155 case DISPLAY_CALLBACK_CREATE: 156 display_callback_create_srv(srv, &call); 157 break; 91 158 case DISPLAY_WINDOW_CREATE: 92 159 display_window_create_srv(srv, &call); … … 94 161 case DISPLAY_WINDOW_DESTROY: 95 162 display_window_destroy_srv(srv, &call); 163 break; 164 case DISPLAY_GET_EVENT: 165 display_get_event_srv(srv, &call); 96 166 break; 97 167 default: … … 101 171 } 102 172 173 /** Send 'pending' event to client. 174 * 175 * @param srv Display server structure 176 */ 177 void display_srv_ev_pending(display_srv_t *srv) 178 { 179 async_exch_t *exch; 180 181 printf("display_srv_ev_pending()\n"); 182 183 exch = async_exchange_begin(srv->client_sess); 184 async_msg_0(exch, DISPLAY_EV_PENDING); 185 async_exchange_end(exch); 186 } 187 103 188 /** @} 104 189 */ -
uspace/lib/display/src/display.c
r22faaf2 rb3c185b6 30 30 #include <display.h> 31 31 #include <errno.h> 32 #include <fibril_synch.h> 32 33 #include <ipc/display.h> 33 34 #include <ipc/services.h> … … 36 37 #include <stdlib.h> 37 38 39 static errno_t display_callback_create(display_t *); 40 static void display_cb_conn(ipc_call_t *, void *); 41 static errno_t display_get_window(display_t *, sysarg_t, display_window_t **); 42 38 43 /** Open display service. 39 44 * … … 51 56 if (display == NULL) 52 57 return ENOMEM; 58 59 list_initialize(&display->windows); 53 60 54 61 if (dsname == NULL) … … 68 75 } 69 76 77 rc = display_callback_create(display); 78 if (rc != EOK) { 79 async_hangup(display->sess); 80 free(display); 81 return EIO; 82 } 83 70 84 *rdisplay = display; 71 85 return EOK; 72 86 } 73 87 88 /** Create callback connection from display service. 89 * 90 * @param display Display session 91 * @return EOK on success or an error code 92 */ 93 static errno_t display_callback_create(display_t *display) 94 { 95 async_exch_t *exch = async_exchange_begin(display->sess); 96 97 aid_t req = async_send_0(exch, DISPLAY_CALLBACK_CREATE, NULL); 98 99 port_id_t port; 100 errno_t rc = async_create_callback_port(exch, INTERFACE_DISPLAY_CB, 0, 0, 101 display_cb_conn, display, &port); 102 103 async_exchange_end(exch); 104 105 if (rc != EOK) 106 return rc; 107 108 errno_t retval; 109 async_wait_for(req, &retval); 110 111 return retval; 112 } 113 74 114 /** Close display service. 75 115 * … … 79 119 { 80 120 async_hangup(display->sess); 121 122 /* Wait for callback handler to terminate */ 123 124 fibril_mutex_lock(&display->lock); 125 while (!display->cb_done) 126 fibril_condvar_wait(&display->cv, &display->lock); 127 fibril_mutex_unlock(&display->lock); 128 81 129 free(display); 82 130 } … … 85 133 * 86 134 * @param display Display 135 * @param cb Callback functions 136 * @param cb_arg Argument to callback functions 87 137 * @param rwindow Place to store pointer to new window 88 138 * @return EOK on success or an error code 89 139 */ 90 errno_t display_window_create(display_t *display, display_window_t **rwindow) 140 errno_t display_window_create(display_t *display, display_wnd_cb_t *cb, 141 void *cb_arg, display_window_t **rwindow) 91 142 { 92 143 display_window_t *window; … … 111 162 window->display = display; 112 163 window->id = wnd_id; 164 window->cb = cb; 165 window->cb_arg = cb_arg; 166 167 list_append(&window->lwindows, &display->windows); 113 168 *rwindow = window; 114 169 return EOK; … … 166 221 } 167 222 223 /** Get display event. 224 * 225 * @param display Display 226 * @param rwindow Place to store pointe to window that received event 227 * @param event Place to store event 228 * @return EOK on success or an error code 229 */ 230 static errno_t display_get_event(display_t *display, display_window_t **rwindow, 231 display_wnd_ev_t *event) 232 { 233 async_exch_t *exch; 234 ipc_call_t answer; 235 aid_t req; 236 errno_t rc; 237 sysarg_t wnd_id; 238 display_window_t *window; 239 240 exch = async_exchange_begin(display->sess); 241 req = async_send_0(exch, DISPLAY_GET_EVENT, &answer); 242 rc = async_data_read_start(exch, event, sizeof(*event)); 243 if (rc != EOK) { 244 async_forget(req); 245 return rc; 246 } 247 248 async_exchange_end(exch); 249 250 async_wait_for(req, &rc); 251 if (rc != EOK) 252 return rc; 253 254 wnd_id = ipc_get_arg1(&answer); 255 rc = display_get_window(display, wnd_id, &window); 256 if (rc != EOK) 257 return EIO; 258 259 *rwindow = window; 260 return EOK; 261 } 262 263 /** Display events are pending. 264 * 265 * @param display Display 266 * @param icall Call data 267 */ 268 static void display_ev_pending(display_t *display, ipc_call_t *icall) 269 { 270 errno_t rc; 271 display_window_t *window = NULL; 272 display_wnd_ev_t event; 273 274 while (true) { 275 rc = display_get_event(display, &window, &event); 276 if (rc != EOK) 277 break; 278 279 if (window->cb->kbd_event != NULL) 280 window->cb->kbd_event(window->cb_arg, &event.kbd_event); 281 } 282 283 async_answer_0(icall, EOK); 284 } 285 286 /** Callback connection handler. 287 * 288 * @param icall Connect call data 289 * @param arg Argument, display_t * 290 */ 291 static void display_cb_conn(ipc_call_t *icall, void *arg) 292 { 293 display_t *display = (display_t *) arg; 294 295 while (true) { 296 ipc_call_t call; 297 async_get_call(&call); 298 299 if (!ipc_get_imethod(&call)) { 300 /* Hangup */ 301 async_answer_0(&call, EOK); 302 goto out; 303 } 304 305 switch (ipc_get_imethod(&call)) { 306 case DISPLAY_EV_PENDING: 307 display_ev_pending(display, &call); 308 break; 309 default: 310 async_answer_0(&call, ENOTSUP); 311 break; 312 } 313 } 314 315 out: 316 fibril_mutex_lock(&display->lock); 317 display->cb_done = true; 318 fibril_mutex_unlock(&display->lock); 319 fibril_condvar_broadcast(&display->cv); 320 } 321 322 /** Find window by ID. 323 * 324 * @param display Display 325 * @param wnd_id Window ID 326 * @param rwindow Place to store pointer to window 327 * @return EOK on success, ENOENT if not found 328 */ 329 static errno_t display_get_window(display_t *display, sysarg_t wnd_id, 330 display_window_t **rwindow) 331 { 332 link_t *link; 333 display_window_t *window; 334 335 link = list_first(&display->windows); 336 while (link != NULL) { 337 window = list_get_instance(link, display_window_t, lwindows); 338 if (window->id == wnd_id) { 339 *rwindow = window; 340 return EOK; 341 } 342 343 link = list_next(link, &display->windows); 344 } 345 346 return ENOENT; 347 } 348 168 349 /** @} 169 350 */ -
uspace/srv/hid/display/display.c
r22faaf2 rb3c185b6 39 39 #include <io/log.h> 40 40 #include <stdlib.h> 41 #include "client.h" 42 #include "window.h" 41 43 #include "display.h" 42 #include "window.h"43 44 44 45 static errno_t disp_window_create(void *, sysarg_t *); 45 46 static errno_t disp_window_destroy(void *, sysarg_t); 47 static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *); 46 48 47 49 display_ops_t display_srv_ops = { 48 50 .window_create = disp_window_create, 49 .window_destroy = disp_window_destroy 51 .window_destroy = disp_window_destroy, 52 .get_event = disp_get_event 50 53 }; 51 54 … … 53 56 { 54 57 errno_t rc; 55 ds_ display_t *disp = (ds_display_t *) arg;58 ds_client_t *client = (ds_client_t *) arg; 56 59 ds_window_t *wnd; 57 60 58 61 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()"); 59 62 60 rc = ds_window_create( disp, &wnd);63 rc = ds_window_create(client, &wnd); 61 64 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc); 62 65 if (rc != EOK) … … 75 78 static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id) 76 79 { 77 ds_ display_t *disp = (ds_display_t *) arg;78 ds_window_t *wnd; 79 80 wnd = ds_ display_find_window(disp, wnd_id);80 ds_client_t *client = (ds_client_t *) arg; 81 ds_window_t *wnd; 82 83 wnd = ds_client_find_window(client, wnd_id); 81 84 if (wnd == NULL) 82 85 return ENOENT; 83 86 84 87 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()"); 85 ds_ display_remove_window(wnd);88 ds_client_remove_window(wnd); 86 89 ds_window_delete(wnd); 90 return EOK; 91 } 92 93 static errno_t disp_get_event(void *arg, sysarg_t *wnd_id, 94 display_wnd_ev_t *event) 95 { 96 ds_client_t *client = (ds_client_t *) arg; 97 ds_window_t *wnd; 98 errno_t rc; 99 100 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_event()"); 101 102 rc = ds_client_get_event(client, &wnd, event); 103 if (rc != EOK) 104 return rc; 105 106 *wnd_id = wnd->id; 87 107 return EOK; 88 108 } … … 102 122 return ENOMEM; 103 123 104 list_initialize(&disp->windows); 124 list_initialize(&disp->clients); 125 disp->gc = gc; 105 126 disp->next_wnd_id = 1; 106 disp->gc = gc;107 127 *rdisp = disp; 108 128 return EOK; … … 115 135 void ds_display_destroy(ds_display_t *disp) 116 136 { 117 assert(list_empty(&disp-> windows));137 assert(list_empty(&disp->clients)); 118 138 free(disp); 119 139 } 120 140 121 /** Add windowto display.141 /** Add client to display. 122 142 * 123 143 * @param disp Display 124 * @param wnd Window 125 * @return EOK on success, ENOMEM if there are no free window identifiers 126 */ 127 errno_t ds_display_add_window(ds_display_t *disp, ds_window_t *wnd) 128 { 129 assert(wnd->display == NULL); 130 assert(!link_used(&wnd->lwindows)); 131 132 wnd->display = disp; 133 wnd->id = disp->next_wnd_id++; 134 list_append(&wnd->lwindows, &disp->windows); 135 136 return EOK; 137 } 138 139 /** Remove window from display. 140 * 141 * @param wnd Window 142 */ 143 void ds_display_remove_window(ds_window_t *wnd) 144 { 145 list_remove(&wnd->lwindows); 146 wnd->display = NULL; 147 } 148 149 /** Find window by ID. 144 * @param client client 145 */ 146 void ds_display_add_client(ds_display_t *disp, ds_client_t *client) 147 { 148 assert(client->display == NULL); 149 assert(!link_used(&client->lclients)); 150 151 client->display = disp; 152 list_append(&client->lclients, &disp->clients); 153 } 154 155 /** Remove client from display. 156 * 157 * @param client client 158 */ 159 void ds_display_remove_client(ds_client_t *client) 160 { 161 list_remove(&client->lclients); 162 client->display = NULL; 163 } 164 165 /** Get first client in display. 150 166 * 151 167 * @param disp Display 152 * @param id Window ID 153 */ 154 ds_window_t *ds_display_find_window(ds_display_t *disp, ds_wnd_id_t id) 155 { 156 ds_window_t *wnd; 157 158 // TODO Make this faster 159 wnd = ds_display_first_window(disp); 160 while (wnd != NULL) { 161 if (wnd->id == id) 162 return wnd; 163 wnd = ds_display_next_window(wnd); 164 } 165 166 return NULL; 167 } 168 169 /** Get first window in display. 170 * 171 * @param disp Display 172 * @return First window or @c NULL if there is none 173 */ 174 ds_window_t *ds_display_first_window(ds_display_t *disp) 175 { 176 link_t *link = list_first(&disp->windows); 168 * @return First client or @c NULL if there is none 169 */ 170 ds_client_t *ds_display_first_client(ds_display_t *disp) 171 { 172 link_t *link = list_first(&disp->clients); 177 173 178 174 if (link == NULL) 179 175 return NULL; 180 176 181 return list_get_instance(link, ds_ window_t, lwindows);182 } 183 184 /** Get next windowin display.185 * 186 * @param wnd Current window187 * @return Next windowor @c NULL if there is none188 */ 189 ds_ window_t *ds_display_next_window(ds_window_t *wnd)190 { 191 link_t *link = list_next(& wnd->lwindows, &wnd->display->windows);177 return list_get_instance(link, ds_client_t, lclients); 178 } 179 180 /** Get next client in display. 181 * 182 * @param client Current client 183 * @return Next client or @c NULL if there is none 184 */ 185 ds_client_t *ds_display_next_client(ds_client_t *client) 186 { 187 link_t *link = list_next(&client->lclients, &client->display->clients); 192 188 193 189 if (link == NULL) 194 190 return NULL; 195 191 196 return list_get_instance(link, ds_window_t, lwindows); 192 return list_get_instance(link, ds_client_t, lclients); 193 } 194 195 /** Find window in all clients by ID. 196 * 197 * XXX This is just a hack needed to match GC connection to a window, 198 * as we don't have a good safe way to pass the GC endpoint to our client 199 * on demand. 200 * 201 * @param display Display 202 * @param id Window ID 203 */ 204 #include <stdio.h> 205 ds_window_t *ds_display_find_window(ds_display_t *display, ds_wnd_id_t id) 206 { 207 ds_client_t *client; 208 ds_window_t *wnd; 209 210 printf("ds_display_find_window: id=0x%lx\n", id); 211 212 client = ds_display_first_client(display); 213 while (client != NULL) { 214 printf("ds_display_find_window: client=%p\n", client); 215 wnd = ds_client_find_window(client, id); 216 if (wnd != NULL) { 217 printf("ds_display_find_window: found wnd=%p id=0x%lx\n", 218 wnd, wnd->id); 219 return wnd; 220 } 221 client = ds_display_next_client(client); 222 } 223 224 printf("ds_display_find_window: not found\n"); 225 return NULL; 226 } 227 228 errno_t ds_display_post_kbd_event(ds_display_t *display, kbd_event_t *event) 229 { 230 ds_client_t *client; 231 ds_window_t *wnd; 232 233 // XXX Correctly determine destination window 234 235 client = ds_display_first_client(display); 236 if (client == NULL) 237 return EOK; 238 239 wnd = ds_client_first_window(client); 240 if (wnd == NULL) 241 return EOK; 242 243 return ds_client_post_kbd_event(client, wnd, event); 197 244 } 198 245 -
uspace/srv/hid/display/display.h
r22faaf2 rb3c185b6 41 41 #include <errno.h> 42 42 #include <gfx/context.h> 43 #include <io/kbd_event.h> 44 #include "types/display/client.h" 43 45 #include "types/display/display.h" 44 #include "types/display/window.h"45 46 46 47 extern display_ops_t display_srv_ops; … … 48 49 extern errno_t ds_display_create(gfx_context_t *, ds_display_t **); 49 50 extern void ds_display_destroy(ds_display_t *); 50 extern errno_t ds_display_add_window(ds_display_t *, ds_window_t *); 51 extern void ds_display_remove_window(ds_window_t *); 51 extern void ds_display_add_client(ds_display_t *, ds_client_t *); 52 extern void ds_display_remove_client(ds_client_t *); 53 extern ds_client_t *ds_display_first_client(ds_display_t *); 54 extern ds_client_t *ds_display_next_client(ds_client_t *); 52 55 extern ds_window_t *ds_display_find_window(ds_display_t *, ds_wnd_id_t); 53 extern ds_window_t *ds_display_first_window(ds_display_t *); 54 extern ds_window_t *ds_display_next_window(ds_window_t *); 56 extern errno_t ds_display_post_kbd_event(ds_display_t *, kbd_event_t *); 55 57 56 58 #endif -
uspace/srv/hid/display/main.c
r22faaf2 rb3c185b6 45 45 #include <stdio.h> 46 46 #include <task.h> 47 #include "client.h" 47 48 #include "display.h" 49 #include "main.h" 48 50 #include "output.h" 49 51 #include "window.h" 50 52 51 #define NAME "display" 53 static void display_client_conn(ipc_call_t *, void *); 52 54 53 static void display_client_conn(ipc_call_t *, void *); 55 static void display_kbd_event(void *arg, kbd_event_t *event) 56 { 57 ds_display_t *disp = (ds_display_t *) arg; 58 59 printf("display_kbd_event\n"); 60 ds_display_post_kbd_event(disp, event); 61 } 54 62 55 63 /** Initialize display server */ … … 60 68 errno_t rc; 61 69 62 rc = output_init(&gc); 70 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()"); 71 72 rc = ds_display_create(NULL, &disp); 63 73 if (rc != EOK) 64 74 goto error; 65 75 66 rc = ds_display_create(gc, &disp);76 rc = output_init(display_kbd_event, (void *) disp, &gc); 67 77 if (rc != EOK) 68 78 goto error; 69 79 70 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()"); 71 80 disp->gc = gc; 81 #if 0 82 rc = ds_input_open(disp); 83 if (rc != EOK) 84 goto error; 85 #endif 72 86 async_set_fallback_port_handler(display_client_conn, disp); 73 87 … … 88 102 return EOK; 89 103 error: 104 #if 0 105 if (disp->input != NULL) 106 ds_input_close(disp); 107 #endif 90 108 if (gc != NULL) 91 109 gfx_context_delete(gc); … … 101 119 sysarg_t wnd_id; 102 120 sysarg_t svc_id; 121 ds_client_t *client = NULL; 103 122 ds_window_t *wnd; 104 123 ds_display_t *disp = (ds_display_t *) arg; 105 124 gfx_context_t *gc; 125 errno_t rc; 106 126 107 127 log_msg(LOG_DEFAULT, LVL_NOTE, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.", … … 116 136 117 137 if (svc_id != 0) { 118 /* Display management */ 138 /* Create client object */ 139 rc = ds_client_create(disp, &srv, &client); 140 if (rc != EOK) { 141 async_answer_0(icall, ENOMEM); 142 return; 143 } 144 145 /* Set up protocol structure */ 119 146 srv.ops = &display_srv_ops; 120 srv.arg = disp;147 srv.arg = client; 121 148 149 /* Handle connection */ 122 150 display_conn(icall, &srv); 151 152 ds_client_destroy(client); 123 153 } else { 124 /* Window GC */ 154 /* Window GC connection */ 155 125 156 wnd = ds_display_find_window(disp, wnd_id); 126 157 if (wnd == NULL) { … … 132 163 gc_conn(icall, gc); 133 164 } 165 134 166 } 135 167 -
uspace/srv/hid/display/meson.build
r22faaf2 rb3c185b6 30 30 31 31 src = files( 32 'client.c', 32 33 'display.c', 33 34 'main.c', … … 37 38 38 39 test_src = files( 40 'client.c', 39 41 'display.c', 40 42 'window.c', -
uspace/srv/hid/display/output.c
r22faaf2 rb3c185b6 42 42 #include "output.h" 43 43 44 errno_t output_init(gfx_context_t **rgc) 44 static void (*kbd_ev_handler)(void *, kbd_event_t *); 45 static void *kbd_ev_arg; 46 47 static void on_keyboard_event(widget_t *widget, void *data) 48 { 49 printf("Keyboard event\n"); 50 kbd_ev_handler(kbd_ev_arg, (kbd_event_t *) data); 51 } 52 53 errno_t output_init(void (*kbd_event_handler)(void *, kbd_event_t *), 54 void *arg, gfx_context_t **rgc) 45 55 { 46 56 canvas_gc_t *cgc = NULL; … … 53 63 54 64 printf("Init canvas..\n"); 65 kbd_ev_handler = kbd_event_handler; 66 kbd_ev_arg = arg; 55 67 56 68 window = window_open("comp:0/winreg", NULL, … … 83 95 } 84 96 97 sig_connect(&canvas->keyboard_event, NULL, on_keyboard_event); 98 85 99 window_resize(window, 0, 0, vw + 10, vh + 30, WINDOW_PLACEMENT_ANY); 86 100 window_exec(window); -
uspace/srv/hid/display/output.h
r22faaf2 rb3c185b6 39 39 #include <gfx/context.h> 40 40 41 extern errno_t output_init(gfx_context_t **); 41 extern errno_t output_init(void (*)(void *, kbd_event_t *), void *, 42 gfx_context_t **); 42 43 43 44 #endif -
uspace/srv/hid/display/test/display.c
r22faaf2 rb3c185b6 32 32 #include <str.h> 33 33 34 #include "../client.h" 34 35 #include "../display.h" 35 #include "../window.h"36 36 37 37 PCUT_INIT; … … 51 51 } 52 52 53 /** Basic windowoperation. */54 PCUT_TEST(display_ window)53 /** Basic client operation. */ 54 PCUT_TEST(display_client) 55 55 { 56 56 ds_display_t *disp; 57 ds_ window_t *wnd;58 ds_ window_t *w0, *w1, *w2;57 ds_client_t *client; 58 ds_client_t *c0, *c1; 59 59 errno_t rc; 60 60 … … 62 62 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 63 63 64 rc = ds_ window_create(disp, &wnd);64 rc = ds_client_create(disp, NULL, &client); 65 65 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 66 66 67 w0 = ds_display_first_window(disp);68 PCUT_ASSERT_EQUALS( w0, wnd);67 c0 = ds_display_first_client(disp); 68 PCUT_ASSERT_EQUALS(c0, client); 69 69 70 w1 = ds_display_next_window(w0);71 PCUT_ASSERT_NULL( w1);70 c1 = ds_display_next_client(c0); 71 PCUT_ASSERT_NULL(c1); 72 72 73 w2 = ds_display_find_window(disp, wnd->id); 74 PCUT_ASSERT_EQUALS(w2, wnd); 75 76 ds_window_delete(wnd); 73 ds_client_destroy(client); 77 74 ds_display_destroy(disp); 78 75 } -
uspace/srv/hid/display/test/window.c
r22faaf2 rb3c185b6 32 32 #include <str.h> 33 33 34 #include "../ display.h"34 #include "../client.h" 35 35 #include "../window.h" 36 36 … … 42 42 PCUT_TEST(window_get_ctx) 43 43 { 44 ds_ display_t *disp;44 ds_client_t *client; 45 45 ds_window_t *wnd; 46 46 gfx_context_t *gc; 47 47 errno_t rc; 48 48 49 rc = ds_ display_create(NULL, &disp);49 rc = ds_client_create(NULL, NULL, &client); 50 50 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 51 51 52 rc = ds_window_create( disp, &wnd);52 rc = ds_window_create(client, &wnd); 53 53 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 54 54 … … 57 57 58 58 ds_window_delete(wnd); 59 ds_ display_destroy(disp);59 ds_client_destroy(client); 60 60 } 61 61 -
uspace/srv/hid/display/types/display/display.h
r22faaf2 rb3c185b6 27 27 */ 28 28 29 /** @addtogroup libipcgfx29 /** @addtogroup display 30 30 * @{ 31 31 */ … … 39 39 #include <adt/list.h> 40 40 #include <gfx/context.h> 41 #include <io/input.h> 41 42 #include "window.h" 42 43 44 /** Display server display */ 43 45 typedef struct ds_display { 44 /** Windows (of ds_window_t) */ 45 list_t windows; 46 /** Next ID to assign to a window */ 47 ds_wnd_id_t next_wnd_id; 46 /** Clients (of ds_client_t) */ 47 list_t clients; 48 48 /** Output GC */ 49 49 gfx_context_t *gc; 50 51 /** Next ID to assign to a window. 52 * 53 * XXX Window IDs need to be unique per display just because 54 * we don't have a way to match GC connection to the proper 55 * client. Really this should be in ds_client_t and the ID 56 * space should be per client. 57 */ 58 ds_wnd_id_t next_wnd_id; 59 /** Input service */ 60 input_t *input; 50 61 } ds_display_t; 51 62 -
uspace/srv/hid/display/types/display/window.h
r22faaf2 rb3c185b6 27 27 */ 28 28 29 /** @addtogroup libipcgfx29 /** @addtogroup display 30 30 * @{ 31 31 */ … … 38 38 39 39 #include <adt/list.h> 40 #include <display/event.h> 40 41 #include <gfx/context.h> 41 42 #include <gfx/coord.h> … … 45 46 /** Display server window */ 46 47 typedef struct ds_window { 47 /** Parent display*/48 struct ds_ display *display;49 /** Link to @c display->windows */48 /** Parent client */ 49 struct ds_client *client; 50 /** Link to @c client->windows */ 50 51 link_t lwindows; 51 52 /** Display position */ … … 56 57 gfx_context_t *gc; 57 58 } ds_window_t; 59 60 /** Window event queue entry */ 61 typedef struct { 62 /** Link to event queue */ 63 link_t levents; 64 /** Window to which the event is delivered */ 65 ds_window_t *window; 66 /** Event */ 67 display_wnd_ev_t event; 68 } ds_window_ev_t; 58 69 59 70 /** Bitmap in display server window GC */ -
uspace/srv/hid/display/window.c
r22faaf2 rb3c185b6 43 43 #include <io/log.h> 44 44 #include <stdlib.h> 45 #include "client.h" 45 46 #include "display.h" 46 47 #include "window.h" … … 76 77 ds_window_t *wnd = (ds_window_t *) arg; 77 78 78 log_msg(LOG_DEFAULT, LVL_NOTE, "gc_set_color ");79 return gfx_set_color(wnd-> display->gc, color);79 log_msg(LOG_DEFAULT, LVL_NOTE, "gc_set_color gc=%p", wnd->client->display->gc); 80 return gfx_set_color(wnd->client->display->gc, color); 80 81 } 81 82 … … 94 95 log_msg(LOG_DEFAULT, LVL_NOTE, "gc_fill_rect"); 95 96 gfx_rect_translate(&wnd->dpos, rect, &drect); 96 return gfx_fill_rect(wnd-> display->gc, &drect);97 return gfx_fill_rect(wnd->client->display->gc, &drect); 97 98 } 98 99 … … 116 117 return ENOMEM; 117 118 118 rc = gfx_bitmap_create(wnd->display->gc, params, alloc, &cbm->bitmap); 119 rc = gfx_bitmap_create(wnd->client->display->gc, params, alloc, 120 &cbm->bitmap); 119 121 if (rc != EOK) 120 122 goto error; … … 181 183 * Create graphics context for rendering into a window. 182 184 * 183 * @param disp Display to create window on185 * @param client Client owning the window 184 186 * @param rgc Place to store pointer to new GC. 185 187 * 186 188 * @return EOK on success or an error code 187 189 */ 188 errno_t ds_window_create(ds_ display_t *disp, ds_window_t **rgc)190 errno_t ds_window_create(ds_client_t *client, ds_window_t **rgc) 189 191 { 190 192 ds_window_t *wnd = NULL; … … 202 204 goto error; 203 205 204 ds_ display_add_window(disp, wnd);206 ds_client_add_window(client, wnd); 205 207 206 208 wnd->gc = gc; … … 222 224 errno_t rc; 223 225 224 ds_ display_remove_window(wnd);226 ds_client_remove_window(wnd); 225 227 226 228 rc = gfx_context_delete(wnd->gc); -
uspace/srv/hid/display/window.h
r22faaf2 rb3c185b6 37 37 #define WINDOW_H 38 38 39 #include <display/event.h> 39 40 #include <errno.h> 40 41 #include <types/gfx/context.h> … … 45 46 extern gfx_context_ops_t window_gc_ops; 46 47 47 extern errno_t ds_window_create(ds_ display_t *, ds_window_t **);48 extern errno_t ds_window_create(ds_client_t *, ds_window_t **); 48 49 extern errno_t ds_window_delete(ds_window_t *); 49 50 extern gfx_context_t *ds_window_get_ctx(ds_window_t *);
Note:
See TracChangeset
for help on using the changeset viewer.