Changeset 4912dd59 in mainline
- Timestamp:
- 2020-05-19T10:21:12Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4c4d6142
- Parents:
- 4d8002d
- git-author:
- Jiri Svoboda <jiri@…> (2020-05-18 18:17:47)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-05-19 10:21:12)
- Location:
- uspace/srv/hid/display
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/cursor.c
r4d8002d r4912dd59 104 104 105 105 dgc = ds_display_get_gc(cursor->display); // XXX 106 if (dgc == NULL) 107 return EOK; 106 108 107 109 gfx_bitmap_params_init(&bparams); … … 144 146 } 145 147 } 146 147 return EOK;148 148 } 149 149 -
uspace/srv/hid/display/ddev.c
r4d8002d r4912dd59 42 42 #include "display.h" 43 43 #include "ddev.h" 44 45 /** Create display device object. 46 * 47 * @param display Parent display 48 * @param dd Display device 49 * @param info Display device info 50 * @param svc_id Display device service ID 51 * @param svc_name Display device service name 52 * @param gc Display device GC 53 * @param rddev Place to store pointer to new display device. 54 * @return EOK on success, ENOMEM if out of memory 55 */ 56 errno_t ds_ddev_create(ds_display_t *display, ddev_t *dd, 57 ddev_info_t *info, char *svc_name, service_id_t svc_id, 58 gfx_context_t *gc, ds_ddev_t **rddev) 59 { 60 ds_ddev_t *ddev; 61 62 ddev = calloc(1, sizeof(ds_ddev_t)); 63 if (ddev == NULL) 64 return ENOMEM; 65 66 ddev->svc_name = svc_name; 67 ddev->svc_id = svc_id; 68 ddev->dd = dd; 69 ddev->gc = gc; 70 ddev->info = *info; 71 72 ds_display_add_ddev(display, ddev); 73 74 *rddev = ddev; 75 return EOK; 76 } 44 77 45 78 /** Open display device. … … 95 128 } 96 129 97 ddev = calloc(1, sizeof(ds_ddev_t));98 if ( ddev == NULL) {130 rc = ds_ddev_create(display, dd, &info, name, svc_id, gc, &ddev); 131 if (rc != EOK) { 99 132 free(name); 100 133 ddev_close(dd); 101 return ENOMEM; 134 gfx_context_delete(gc); 135 return rc; 102 136 } 103 104 ddev->svc_name = name;105 ddev->svc_id = svc_id;106 ddev->dd = dd;107 ddev->gc = gc;108 ddev->info = info;109 110 ds_display_add_ddev(display, ddev);111 137 112 138 rc = ds_display_paint_bg(display, NULL); -
uspace/srv/hid/display/ddev.h
r4d8002d r4912dd59 42 42 #include "types/display/display.h" 43 43 44 extern errno_t ds_ddev_create(ds_display_t *, ddev_t *, ddev_info_t *, 45 char *, service_id_t, gfx_context_t *, ds_ddev_t **); 44 46 extern errno_t ds_ddev_open(ds_display_t *, service_id_t, ds_ddev_t **); 45 47 extern void ds_ddev_close(ds_ddev_t *); -
uspace/srv/hid/display/meson.build
r4d8002d r4912dd59 47 47 'cursimg.c', 48 48 'cursor.c', 49 'ddev.c', 49 50 'display.c', 50 51 'seat.c', -
uspace/srv/hid/display/test/cursor.c
r4d8002d r4912dd59 28 28 29 29 #include <errno.h> 30 #include <gfx/context.h> 31 #include <stdbool.h> 30 32 #include <pcut/pcut.h> 31 33 32 34 #include "../cursor.h" 33 35 #include "../cursimg.h" 36 #include "../ddev.h" 34 37 #include "../display.h" 38 #include "../display.h" 35 39 36 40 PCUT_INIT; 37 41 38 42 PCUT_TEST_SUITE(cursor); 43 44 static errno_t dummy_bitmap_create(void *, gfx_bitmap_params_t *, 45 gfx_bitmap_alloc_t *, void **); 46 static errno_t dummy_bitmap_destroy(void *); 47 static errno_t dummy_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 48 static errno_t dummy_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 49 50 static gfx_context_ops_t dummy_ops = { 51 .bitmap_create = dummy_bitmap_create, 52 .bitmap_destroy = dummy_bitmap_destroy, 53 .bitmap_render = dummy_bitmap_render, 54 .bitmap_get_alloc = dummy_bitmap_get_alloc 55 }; 56 57 58 typedef struct { 59 bool render_called; 60 } test_response_t; 61 62 typedef struct { 63 test_response_t *resp; 64 gfx_bitmap_alloc_t alloc; 65 } dummy_bitmap_t; 39 66 40 67 /** Test ds_cursor_create(), ds_cursor_destroy(). */ … … 59 86 PCUT_TEST(cursor_paint) 60 87 { 88 gfx_context_t *gc; 61 89 ds_display_t *disp; 62 90 ds_cursor_t *cursor; 91 ds_ddev_t *ddev; 92 ddev_info_t ddinfo; 93 gfx_coord2_t pos; 94 test_response_t resp; 63 95 errno_t rc; 64 96 65 rc = ds_display_create(NULL, &disp); 97 rc = gfx_context_new(&dummy_ops, &resp, &gc); 98 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 99 100 rc = ds_display_create(gc, &disp); 101 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 102 103 ddev_info_init(&ddinfo); 104 105 rc = ds_ddev_create(disp, NULL, &ddinfo, NULL, 0, gc, &ddev); 66 106 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 67 107 … … 70 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 71 111 112 resp.render_called = false; 113 114 pos.x = 0; 115 pos.y = 0; 116 ds_cursor_paint(cursor, &pos); 117 118 PCUT_ASSERT_TRUE(resp.render_called); 119 72 120 ds_cursor_destroy(cursor); 73 121 ds_display_destroy(disp); … … 79 127 ds_display_t *disp; 80 128 ds_cursor_t *cursor; 129 gfx_coord2_t pos1, pos2; 130 gfx_rect_t rect1, rect2; 81 131 errno_t rc; 82 132 … … 88 138 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 89 139 140 pos1.x = 10; 141 pos1.y = 11; 142 143 pos2.x = 22; 144 pos2.y = 23; 145 146 ds_cursor_get_rect(cursor, &pos1, &rect1); 147 ds_cursor_get_rect(cursor, &pos2, &rect2); 148 149 PCUT_ASSERT_FALSE(gfx_rect_is_empty(&rect1)); 150 PCUT_ASSERT_FALSE(gfx_rect_is_empty(&rect2)); 151 152 PCUT_ASSERT_INT_EQUALS(pos2.x - pos1.x, rect2.p0.x - rect1.p0.x); 153 PCUT_ASSERT_INT_EQUALS(pos2.y - pos1.y, rect2.p0.y - rect1.p0.y); 154 PCUT_ASSERT_INT_EQUALS(pos2.x - pos1.x, rect2.p1.x - rect1.p1.x); 155 PCUT_ASSERT_INT_EQUALS(pos2.y - pos1.y, rect2.p1.y - rect1.p1.y); 156 90 157 ds_cursor_destroy(cursor); 91 158 ds_display_destroy(disp); 92 159 } 93 160 161 static errno_t dummy_bitmap_create(void *arg, gfx_bitmap_params_t *params, 162 gfx_bitmap_alloc_t *alloc, void **rbm) 163 { 164 test_response_t *resp = (test_response_t *) arg; 165 dummy_bitmap_t *bm; 166 gfx_coord2_t dims; 167 168 gfx_rect_dims(¶ms->rect, &dims); 169 bm = calloc(1, sizeof(dummy_bitmap_t)); 170 if (bm == NULL) 171 return ENOMEM; 172 173 bm->resp = resp; 174 bm->alloc.pitch = dims.x * sizeof(uint32_t); 175 bm->alloc.off0 = 0; 176 177 bm->alloc.pixels = malloc(bm->alloc.pitch * dims.y * sizeof(uint32_t)); 178 if (bm->alloc.pixels == NULL) { 179 free(bm); 180 return ENOMEM; 181 } 182 183 *rbm = (void *) bm; 184 return EOK; 185 } 186 187 static errno_t dummy_bitmap_destroy(void *arg) 188 { 189 dummy_bitmap_t *bm = (dummy_bitmap_t *) arg; 190 191 free(bm); 192 return EOK; 193 } 194 195 static errno_t dummy_bitmap_render(void *arg, gfx_rect_t *rect, 196 gfx_coord2_t *dpos) 197 { 198 dummy_bitmap_t *bm = (dummy_bitmap_t *) arg; 199 200 bm->resp->render_called = true; 201 return EOK; 202 } 203 204 static errno_t dummy_bitmap_get_alloc(void *arg, gfx_bitmap_alloc_t *alloc) 205 { 206 dummy_bitmap_t *bm = (dummy_bitmap_t *) arg; 207 208 *alloc = bm->alloc; 209 return EOK; 210 } 211 212 94 213 PCUT_EXPORT(cursor); -
uspace/srv/hid/display/test/main.c
r4d8002d r4912dd59 32 32 33 33 PCUT_IMPORT(client); 34 PCUT_IMPORT(cursor); 34 35 PCUT_IMPORT(display); 35 36 PCUT_IMPORT(window);
Note:
See TracChangeset
for help on using the changeset viewer.