Changeset 6af4b4f in mainline
- Timestamp:
- 2019-10-05T08:45:25Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bef51cf
- Parents:
- c8cf261
- git-author:
- Jiri Svoboda <jiri@…> (2019-10-04 17:52:54)
- git-committer:
- Jiri Svoboda <jiri@…> (2019-10-05 08:45:25)
- Location:
- uspace/srv/hid/display
- Files:
-
- 3 added
- 4 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/display.c
rc8cf261 r6af4b4f 37 37 #include <errno.h> 38 38 #include <io/log.h> 39 #include <stdlib.h> 40 #include "display.h" 41 #include "window.h" 39 42 40 43 static errno_t disp_window_create(void *, sysarg_t *); … … 48 51 static errno_t disp_window_create(void *arg, sysarg_t *rwnd_id) 49 52 { 53 errno_t rc; 54 ds_display_t *disp = (ds_display_t *) arg; 55 ds_window_t *wnd; 56 50 57 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()"); 51 *rwnd_id = 42; 58 59 rc = ds_window_create(disp, &wnd); 60 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc); 61 if (rc != EOK) 62 return rc; 63 64 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu", 65 wnd->id); 66 *rwnd_id = wnd->id; 52 67 return EOK; 53 68 } … … 55 70 static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id) 56 71 { 72 ds_display_t *disp = (ds_display_t *) arg; 73 ds_window_t *wnd; 74 75 wnd = ds_display_find_window(disp, wnd_id); 76 if (wnd == NULL) 77 return ENOENT; 78 57 79 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()"); 80 ds_display_remove_window(wnd); 81 ds_window_delete(wnd); 58 82 return EOK; 83 } 84 85 /** Create display. 86 * 87 * @param rdisp Place to store pointer to new display. 88 * @return EOK on success, ENOMEM if out of memory 89 */ 90 errno_t ds_display_create(ds_display_t **rdisp) 91 { 92 ds_display_t *disp; 93 94 disp = calloc(1, sizeof(ds_display_t)); 95 if (disp == NULL) 96 return ENOMEM; 97 98 list_initialize(&disp->windows); 99 disp->next_wnd_id = 1; 100 *rdisp = disp; 101 return EOK; 102 } 103 104 /** Destroy display. 105 * 106 * @param disp Display 107 */ 108 void ds_display_destroy(ds_display_t *disp) 109 { 110 assert(list_empty(&disp->windows)); 111 free(disp); 112 } 113 114 /** Add window to display. 115 * 116 * @param disp Display 117 * @param wnd Window 118 * @return EOK on success, ENOMEM if there are no free window identifiers 119 */ 120 errno_t ds_display_add_window(ds_display_t *disp, ds_window_t *wnd) 121 { 122 assert(wnd->display == NULL); 123 assert(!link_used(&wnd->lwindows)); 124 125 wnd->display = disp; 126 wnd->id = disp->next_wnd_id++; 127 list_append(&wnd->lwindows, &disp->windows); 128 129 return EOK; 130 } 131 132 /** Remove window from display. 133 * 134 * @param wnd Window 135 */ 136 void ds_display_remove_window(ds_window_t *wnd) 137 { 138 list_remove(&wnd->lwindows); 139 wnd->display = NULL; 140 } 141 142 /** Find window by ID. 143 * 144 * @param disp Display 145 * @param id Window ID 146 */ 147 ds_window_t *ds_display_find_window(ds_display_t *disp, ds_wnd_id_t id) 148 { 149 ds_window_t *wnd; 150 151 // TODO Make this faster 152 wnd = ds_display_first_window(disp); 153 while (wnd != NULL) { 154 if (wnd->id == id) 155 return wnd; 156 wnd = ds_display_next_window(wnd); 157 } 158 159 return NULL; 160 } 161 162 /** Get first window in display. 163 * 164 * @param disp Display 165 * @return First window or @c NULL if there is none 166 */ 167 ds_window_t *ds_display_first_window(ds_display_t *disp) 168 { 169 link_t *link = list_first(&disp->windows); 170 171 if (link == NULL) 172 return NULL; 173 174 return list_get_instance(link, ds_window_t, lwindows); 175 } 176 177 /** Get next window in display. 178 * 179 * @param wnd Current window 180 * @return Next window or @c NULL if there is none 181 */ 182 ds_window_t *ds_display_next_window(ds_window_t *wnd) 183 { 184 link_t *link = list_next(&wnd->lwindows, &wnd->display->windows); 185 186 if (link == NULL) 187 return NULL; 188 189 return list_get_instance(link, ds_window_t, lwindows); 59 190 } 60 191 -
uspace/srv/hid/display/display.h
rc8cf261 r6af4b4f 39 39 40 40 #include <disp_srv.h> 41 #include <errno.h> 42 #include "types/display/display.h" 43 #include "types/display/window.h" 41 44 42 45 extern display_ops_t display_srv_ops; 46 47 extern errno_t ds_display_create(ds_display_t **); 48 extern void ds_display_destroy(ds_display_t *); 49 extern errno_t ds_display_add_window(ds_display_t *, ds_window_t *); 50 extern void ds_display_remove_window(ds_window_t *); 51 extern ds_window_t *ds_display_find_window(ds_display_t *, ds_wnd_id_t); 52 extern ds_window_t *ds_display_first_window(ds_display_t *); 53 extern ds_window_t *ds_display_next_window(ds_window_t *); 43 54 44 55 #endif -
uspace/srv/hid/display/main.c
rc8cf261 r6af4b4f 46 46 #include <task.h> 47 47 #include "display.h" 48 #include "win gc.h"48 #include "window.h" 49 49 50 50 #define NAME "display" … … 55 55 static errno_t display_srv_init(void) 56 56 { 57 ds_display_t *disp = NULL; 57 58 errno_t rc; 59 60 rc = ds_display_create(&disp); 61 if (rc != EOK) 62 goto error; 58 63 59 64 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()"); 60 65 61 async_set_fallback_port_handler(display_client_conn, NULL/*parts*/);66 async_set_fallback_port_handler(display_client_conn, disp); 62 67 63 68 rc = loc_server_register(NAME); … … 77 82 return EOK; 78 83 error: 84 if (disp != NULL) 85 ds_display_destroy(disp); 79 86 return rc; 80 87 } … … 86 93 sysarg_t wnd_id; 87 94 sysarg_t svc_id; 88 win_gc_t *wgc = NULL; 95 ds_window_t *wnd; 96 ds_display_t *disp = (ds_display_t *) arg; 89 97 gfx_context_t *gc; 90 errno_t rc;91 98 92 99 log_msg(LOG_DEFAULT, LVL_NOTE, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.", … … 103 110 /* Display management */ 104 111 srv.ops = &display_srv_ops; 105 srv.arg = NULL;112 srv.arg = disp; 106 113 107 114 display_conn(icall, &srv); 108 115 } else { 109 (void) wnd_id;110 116 /* Window GC */ 111 rc = win_gc_create(&wgc);112 if ( rc != EOK) {113 async_answer_0(icall, ENO MEM);117 wnd = ds_display_find_window(disp, wnd_id); 118 if (wnd == NULL) { 119 async_answer_0(icall, ENOENT); 114 120 return; 115 121 } 116 122 117 gc = win_gc_get_ctx(wgc);123 gc = ds_window_get_ctx(wnd); 118 124 gc_conn(icall, gc); 119 120 win_gc_delete(wgc);121 125 } 122 126 } -
uspace/srv/hid/display/meson.build
rc8cf261 r6af4b4f 27 27 # 28 28 29 deps = [ 'ipcgfx', 'display' ]29 deps = [ 'ipcgfx', 'display', 'guigfx' ] 30 30 31 31 src = files( 32 32 'display.c', 33 33 'main.c', 34 'win gc.c'34 'window.c', 35 35 ) 36 37 test_src = files( 38 'display.c', 39 'window.c', 40 'test/main.c', 41 'test/display.c', 42 ) -
uspace/srv/hid/display/test/main.c
rc8cf261 r6af4b4f 27 27 */ 28 28 29 /** @addtogroup libipcgfx 30 * @{ 31 */ 32 /** 33 * @file GFX IPC backend 34 */ 29 #include <pcut/pcut.h> 35 30 36 #ifndef TYPES_WINGC_H 37 #define TYPES_WINGC_H 31 PCUT_INIT; 38 32 39 #include <gfx/context.h> 33 PCUT_IMPORT(display); 40 34 41 typedef struct win_gc { 42 /** Base graphic context */ 43 gfx_context_t *gc; 44 } win_gc_t; 45 46 #endif 47 48 /** @} 49 */ 35 PCUT_MAIN(); -
uspace/srv/hid/display/window.c
rc8cf261 r6af4b4f 41 41 #include <io/log.h> 42 42 #include <stdlib.h> 43 #include "wingc.h" 43 #include "display.h" 44 #include "window.h" 44 45 45 static errno_t win_gc_set_color(void *, gfx_color_t *);46 static errno_t win_gc_fill_rect(void *, gfx_rect_t *);46 static errno_t ds_window_set_color(void *, gfx_color_t *); 47 static errno_t ds_window_fill_rect(void *, gfx_rect_t *); 47 48 48 gfx_context_ops_t win_gc_ops = {49 .set_color = win_gc_set_color,50 .fill_rect = win_gc_fill_rect49 gfx_context_ops_t ds_window_ops = { 50 .set_color = ds_window_set_color, 51 .fill_rect = ds_window_fill_rect 51 52 }; 52 53 … … 60 61 * @return EOK on success or an error code 61 62 */ 62 static errno_t win_gc_set_color(void *arg, gfx_color_t *color)63 static errno_t ds_window_set_color(void *arg, gfx_color_t *color) 63 64 { 64 win_gc_t *wgc = (win_gc_t *) arg;65 ds_window_t *wnd = (ds_window_t *) arg; 65 66 66 (void) w gc;67 (void) wnd; 67 68 log_msg(LOG_DEFAULT, LVL_NOTE, "gc_set_color"); 68 69 return EOK; … … 71 72 /** Fill rectangle on window GC. 72 73 * 73 * @param arg ConsoleGC74 * @param arg Window GC 74 75 * @param rect Rectangle 75 76 * 76 77 * @return EOK on success or an error code 77 78 */ 78 static errno_t win_gc_fill_rect(void *arg, gfx_rect_t *rect)79 static errno_t ds_window_fill_rect(void *arg, gfx_rect_t *rect) 79 80 { 80 win_gc_t *wgc = (win_gc_t *) arg;81 ds_window_t *wnd = (ds_window_t *) arg; 81 82 82 (void) w gc;83 (void) wnd; 83 84 log_msg(LOG_DEFAULT, LVL_NOTE, "gc_fill_rect"); 84 85 return EOK; 85 86 } 86 87 87 /** Create window GC.88 /** Create window. 88 89 * 89 90 * Create graphics context for rendering into a window. 90 91 * 92 * @param disp Display to create window on 91 93 * @param rgc Place to store pointer to new GC. 92 94 * 93 95 * @return EOK on success or an error code 94 96 */ 95 errno_t win_gc_create(win_gc_t **rgc)97 errno_t ds_window_create(ds_display_t *disp, ds_window_t **rgc) 96 98 { 97 win_gc_t *wgc= NULL;99 ds_window_t *wnd = NULL; 98 100 gfx_context_t *gc = NULL; 99 101 errno_t rc; 100 102 101 w gc = calloc(1, sizeof(win_gc_t));102 if (w gc== NULL) {103 wnd = calloc(1, sizeof(ds_window_t)); 104 if (wnd == NULL) { 103 105 rc = ENOMEM; 104 106 goto error; 105 107 } 106 108 107 rc = gfx_context_new(& win_gc_ops, wgc, &gc);109 rc = gfx_context_new(&ds_window_ops, wnd, &gc); 108 110 if (rc != EOK) 109 111 goto error; 110 112 111 wgc->gc = gc; 112 *rgc = wgc; 113 ds_display_add_window(disp, wnd); 114 115 wnd->gc = gc; 116 *rgc = wnd; 113 117 return EOK; 114 118 error: 115 if (w gc!= NULL)116 free(w gc);119 if (wnd != NULL) 120 free(wnd); 117 121 gfx_context_delete(gc); 118 122 return rc; … … 121 125 /** Delete window GC. 122 126 * 123 * @param w gc ConsoleGC127 * @param wnd Window GC 124 128 */ 125 errno_t win_gc_delete(win_gc_t *wgc)129 errno_t ds_window_delete(ds_window_t *wnd) 126 130 { 127 131 errno_t rc; 128 132 129 rc = gfx_context_delete(w gc->gc);133 rc = gfx_context_delete(wnd->gc); 130 134 if (rc != EOK) 131 135 return rc; 132 136 133 free(w gc);137 free(wnd); 134 138 return EOK; 135 139 } 136 140 137 /** Get generic graphic context from window GC.141 /** Get generic graphic context from window. 138 142 * 139 * @param w gc Console GC143 * @param wnd Window 140 144 * @return Graphic context 141 145 */ 142 gfx_context_t * win_gc_get_ctx(win_gc_t *wgc)146 gfx_context_t *ds_window_get_ctx(ds_window_t *wnd) 143 147 { 144 return w gc->gc;148 return wnd->gc; 145 149 } 146 150 -
uspace/srv/hid/display/window.h
rc8cf261 r6af4b4f 31 31 */ 32 32 /** 33 * @file Window graphics context33 * @file Display server window 34 34 */ 35 35 36 #ifndef WIN GC_H37 #define WIN GC_H36 #ifndef WINDOW_H 37 #define WINDOW_H 38 38 39 #include <errno.h> 39 40 #include <types/gfx/context.h> 40 41 #include <types/gfx/ops/context.h> 41 #include "types/wingc.h" 42 #include "types/display/display.h" 43 #include "types/display/window.h" 42 44 43 extern gfx_context_ops_t win _gc_ops;45 extern gfx_context_ops_t window_gc_ops; 44 46 45 extern errno_t win_gc_create(win_gc_t **);46 extern errno_t win_gc_delete(win_gc_t *);47 extern gfx_context_t * win_gc_get_ctx(win_gc_t *);47 extern errno_t ds_window_create(ds_display_t *, ds_window_t **); 48 extern errno_t ds_window_delete(ds_window_t *); 49 extern gfx_context_t *ds_window_get_ctx(ds_window_t *); 48 50 49 51 #endif
Note:
See TracChangeset
for help on using the changeset viewer.