Changeset b3c185b6 in mainline for uspace/srv/hid/display
- Timestamp:
- 2019-11-04T14:05:35Z (6 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)
- Location:
- uspace/srv/hid/display
- Files:
-
- 4 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
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.