Changeset 1215db9 in mainline
- Timestamp:
- 2021-06-26T23:30:18Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e87415e6
- Parents:
- bb14312
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/memgfx/include/memgfx/memgc.h
rbb14312 r1215db9 46 46 47 47 extern errno_t mem_gc_create(gfx_rect_t *, gfx_bitmap_alloc_t *, 48 mem_gc_ invalidate_cb_t, mem_gc_update_cb_t, void *, mem_gc_t **);48 mem_gc_cb_t *, void *, mem_gc_t **); 49 49 extern errno_t mem_gc_delete(mem_gc_t *); 50 50 extern void mem_gc_retarget(mem_gc_t *, gfx_rect_t *, gfx_bitmap_alloc_t *); -
uspace/lib/memgfx/include/types/memgfx/memgc.h
rbb14312 r1215db9 37 37 #define _MEMGFX_TYPES_MEMGC_H 38 38 39 #include <errno.h> 40 #include <stdbool.h> 39 41 #include <types/gfx/coord.h> 40 42 … … 42 44 typedef struct mem_gc mem_gc_t; 43 45 44 typedef void (*mem_gc_invalidate_cb_t)(void *, gfx_rect_t *); 45 typedef void (*mem_gc_update_cb_t)(void *); 46 typedef struct { 47 /** Invalidate rectangle */ 48 void (*invalidate)(void *, gfx_rect_t *); 49 /** Update display */ 50 void (*update)(void *); 51 /** Get cursor position */ 52 errno_t (*cursor_get_pos)(void *, gfx_coord2_t *); 53 /** Set cursor position */ 54 errno_t (*cursor_set_pos)(void *, gfx_coord2_t *); 55 /** Set cursor visibility */ 56 errno_t (*cursor_set_visible)(void *, bool); 57 } mem_gc_cb_t; 46 58 47 59 #endif -
uspace/lib/memgfx/private/memgc.h
rbb14312 r1215db9 53 53 /** Allocation info */ 54 54 gfx_bitmap_alloc_t alloc; 55 /** Invalidate callback */ 56 mem_gc_invalidate_cb_t invalidate; 57 /** Update callback */ 58 mem_gc_update_cb_t update; 59 /** Argument to callback */ 55 /** Callbacks */ 56 mem_gc_cb_t *cb; 57 /** Argument to callbacks */ 60 58 void *cb_arg; 61 59 /** Current drawing color */ -
uspace/lib/memgfx/src/memgc.c
rbb14312 r1215db9 57 57 static errno_t mem_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 58 58 static errno_t mem_gc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 59 static errno_t mem_gc_cursor_get_pos(void *, gfx_coord2_t *); 60 static errno_t mem_gc_cursor_set_pos(void *, gfx_coord2_t *); 61 static errno_t mem_gc_cursor_set_visible(void *, bool); 59 62 static void mem_gc_invalidate_rect(mem_gc_t *, gfx_rect_t *); 60 63 … … 67 70 .bitmap_destroy = mem_gc_bitmap_destroy, 68 71 .bitmap_render = mem_gc_bitmap_render, 69 .bitmap_get_alloc = mem_gc_bitmap_get_alloc 72 .bitmap_get_alloc = mem_gc_bitmap_get_alloc, 73 .cursor_get_pos = mem_gc_cursor_get_pos, 74 .cursor_set_pos = mem_gc_cursor_set_pos, 75 .cursor_set_visible = mem_gc_cursor_set_visible 70 76 }; 71 77 … … 152 158 mem_gc_t *mgc = (mem_gc_t *) arg; 153 159 154 mgc-> update(mgc->cb_arg);160 mgc->cb->update(mgc->cb_arg); 155 161 return EOK; 156 162 } … … 162 168 * @param rect Bounding rectangle 163 169 * @param alloc Allocation info 164 * @param update_cb Function called to update a rectangle165 * @param cb_arg Argument to callback function 170 * @param cb Pointer to memory GC callbacks 171 * @param cb_arg Argument to callback functions 166 172 * @param rgc Place to store pointer to new memory GC 167 173 * … … 169 175 */ 170 176 errno_t mem_gc_create(gfx_rect_t *rect, gfx_bitmap_alloc_t *alloc, 171 mem_gc_invalidate_cb_t invalidate_cb, mem_gc_update_cb_t update_cb, 172 void *cb_arg, mem_gc_t **rgc) 177 mem_gc_cb_t *cb, void *cb_arg, mem_gc_t **rgc) 173 178 { 174 179 mem_gc_t *mgc = NULL; … … 191 196 mgc->alloc = *alloc; 192 197 193 mgc->invalidate = invalidate_cb; 194 mgc->update = update_cb; 198 mgc->cb = cb; 195 199 mgc->cb_arg = cb_arg; 196 200 … … 246 250 static void mem_gc_invalidate_rect(mem_gc_t *mgc, gfx_rect_t *rect) 247 251 { 248 mgc-> invalidate(mgc->cb_arg, rect);252 mgc->cb->invalidate(mgc->cb_arg, rect); 249 253 } 250 254 … … 464 468 } 465 469 470 /** Get cursor position on memory GC. 471 * 472 * @param arg Memory GC 473 * @param pos Place to store position 474 * 475 * @return EOK on success or an error code 476 */ 477 static errno_t mem_gc_cursor_get_pos(void *arg, gfx_coord2_t *pos) 478 { 479 mem_gc_t *mgc = (mem_gc_t *) arg; 480 481 if (mgc->cb->cursor_get_pos != NULL) 482 return mgc->cb->cursor_get_pos(mgc->cb_arg, pos); 483 else 484 return ENOTSUP; 485 } 486 487 /** Set cursor position on memory GC. 488 * 489 * @param arg Memory GC 490 * @param pos New position 491 * 492 * @return EOK on success or an error code 493 */ 494 static errno_t mem_gc_cursor_set_pos(void *arg, gfx_coord2_t *pos) 495 { 496 mem_gc_t *mgc = (mem_gc_t *) arg; 497 498 if (mgc->cb->cursor_set_pos != NULL) 499 return mgc->cb->cursor_set_pos(mgc->cb_arg, pos); 500 else 501 return ENOTSUP; 502 } 503 504 /** Set cursor visibility on memory GC. 505 * 506 * @param arg Memory GC 507 * @param visible @c true iff cursor should be made visible 508 * 509 * @return EOK on success or an error code 510 */ 511 static errno_t mem_gc_cursor_set_visible(void *arg, bool visible) 512 { 513 mem_gc_t *mgc = (mem_gc_t *) arg; 514 515 if (mgc->cb->cursor_set_visible != NULL) 516 return mgc->cb->cursor_set_visible(mgc->cb_arg, visible); 517 else 518 return ENOTSUP; 519 } 520 466 521 /** @} 467 522 */ -
uspace/lib/memgfx/test/memgfx.c
rbb14312 r1215db9 32 32 #include <gfx/coord.h> 33 33 #include <gfx/context.h> 34 #include <gfx/cursor.h> 34 35 #include <gfx/render.h> 35 36 #include <io/pixelmap.h> … … 44 45 static void test_invalidate_rect(void *arg, gfx_rect_t *rect); 45 46 static void test_update(void *arg); 47 static errno_t test_cursor_get_pos(void *arg, gfx_coord2_t *); 48 static errno_t test_cursor_set_pos(void *arg, gfx_coord2_t *); 49 static errno_t test_cursor_set_visible(void *arg, bool); 50 51 static mem_gc_cb_t test_mem_gc_cb = { 52 .invalidate = test_invalidate_rect, 53 .update = test_update, 54 .cursor_get_pos = test_cursor_get_pos, 55 .cursor_set_pos = test_cursor_set_pos, 56 .cursor_set_visible = test_cursor_set_visible 57 }; 46 58 47 59 typedef struct { 60 /** Return code to return */ 61 errno_t rc; 48 62 /** True if invalidate was called */ 49 63 bool invalidate_called; … … 52 66 /** True if update was called */ 53 67 bool update_called; 68 /** True if cursor_get_pos was called */ 69 bool cursor_get_pos_called; 70 /** Position to return from cursor_get_pos */ 71 gfx_coord2_t get_pos_pos; 72 /** True if cursor_set_pos was called */ 73 bool cursor_set_pos_called; 74 /** Position passed to cursor_set_pos */ 75 gfx_coord2_t set_pos_pos; 76 /** True if cursor_set_visible was called */ 77 bool cursor_set_visible_called; 78 /** Value passed to cursor_set_visible */ 79 bool set_visible_vis; 54 80 } test_resp_t; 55 81 … … 72 98 PCUT_ASSERT_NOT_NULL(alloc.pixels); 73 99 74 rc = mem_gc_create(&rect, &alloc, NULL, NULL, NULL,&mgc);100 rc = mem_gc_create(&rect, &alloc, NULL, NULL, &mgc); 75 101 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 76 102 … … 106 132 PCUT_ASSERT_NOT_NULL(alloc.pixels); 107 133 108 rc = mem_gc_create(&rect, &alloc, test_invalidate_rect, 109 test_update, &resp, &mgc); 134 rc = mem_gc_create(&rect, &alloc, &test_mem_gc_cb, &resp, &mgc); 110 135 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 111 136 … … 187 212 PCUT_ASSERT_NOT_NULL(alloc.pixels); 188 213 189 rc = mem_gc_create(&rect, &alloc, test_invalidate_rect, 190 test_update, &resp, &mgc); 214 rc = mem_gc_create(&rect, &alloc, &test_mem_gc_cb, &resp, &mgc); 191 215 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 192 216 … … 277 301 PCUT_ASSERT_NOT_NULL(alloc.pixels); 278 302 279 rc = mem_gc_create(&rect, &alloc, test_invalidate_rect, 280 test_update, &resp, &mgc); 303 rc = mem_gc_create(&rect, &alloc, &test_mem_gc_cb, &resp, &mgc); 281 304 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 282 305 … … 294 317 } 295 318 319 /** Test gfx_cursor_get_pos() on a memory GC */ 320 PCUT_TEST(gfx_cursor_get_pos) 321 { 322 mem_gc_t *mgc; 323 gfx_rect_t rect; 324 gfx_bitmap_alloc_t alloc; 325 gfx_coord2_t pos; 326 gfx_context_t *gc; 327 test_resp_t resp; 328 errno_t rc; 329 330 /* Bounding rectangle for memory GC */ 331 rect.p0.x = 0; 332 rect.p0.y = 0; 333 rect.p1.x = 10; 334 rect.p1.y = 10; 335 336 alloc.pitch = (rect.p1.x - rect.p0.x) * sizeof(uint32_t); 337 alloc.off0 = 0; 338 alloc.pixels = calloc(1, alloc.pitch * (rect.p1.y - rect.p0.y)); 339 PCUT_ASSERT_NOT_NULL(alloc.pixels); 340 341 rc = mem_gc_create(&rect, &alloc, &test_mem_gc_cb, &resp, &mgc); 342 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 343 344 gc = mem_gc_get_ctx(mgc); 345 PCUT_ASSERT_NOT_NULL(gc); 346 347 memset(&resp, 0, sizeof(resp)); 348 resp.rc = EOK; 349 resp.get_pos_pos.x = 1; 350 resp.get_pos_pos.y = 2; 351 PCUT_ASSERT_FALSE(resp.cursor_get_pos_called); 352 353 rc = gfx_cursor_get_pos(gc, &pos); 354 PCUT_ASSERT_TRUE(resp.cursor_get_pos_called); 355 PCUT_ASSERT_INT_EQUALS(resp.get_pos_pos.x, pos.x); 356 PCUT_ASSERT_INT_EQUALS(resp.get_pos_pos.y, pos.y); 357 358 mem_gc_delete(mgc); 359 free(alloc.pixels); 360 } 361 362 /** Test gfx_cursor_set_pos() on a memory GC */ 363 PCUT_TEST(gfx_cursor_set_pos) 364 { 365 mem_gc_t *mgc; 366 gfx_rect_t rect; 367 gfx_bitmap_alloc_t alloc; 368 gfx_coord2_t pos; 369 gfx_context_t *gc; 370 test_resp_t resp; 371 errno_t rc; 372 373 /* Bounding rectangle for memory GC */ 374 rect.p0.x = 0; 375 rect.p0.y = 0; 376 rect.p1.x = 10; 377 rect.p1.y = 10; 378 379 alloc.pitch = (rect.p1.x - rect.p0.x) * sizeof(uint32_t); 380 alloc.off0 = 0; 381 alloc.pixels = calloc(1, alloc.pitch * (rect.p1.y - rect.p0.y)); 382 PCUT_ASSERT_NOT_NULL(alloc.pixels); 383 384 rc = mem_gc_create(&rect, &alloc, &test_mem_gc_cb, &resp, &mgc); 385 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 386 387 gc = mem_gc_get_ctx(mgc); 388 PCUT_ASSERT_NOT_NULL(gc); 389 390 memset(&resp, 0, sizeof(resp)); 391 resp.rc = EOK; 392 pos.x = 1; 393 pos.y = 2; 394 PCUT_ASSERT_FALSE(resp.cursor_set_pos_called); 395 396 rc = gfx_cursor_set_pos(gc, &pos); 397 PCUT_ASSERT_TRUE(resp.cursor_set_pos_called); 398 PCUT_ASSERT_INT_EQUALS(pos.x, resp.set_pos_pos.x); 399 PCUT_ASSERT_INT_EQUALS(pos.y, resp.set_pos_pos.y); 400 401 mem_gc_delete(mgc); 402 free(alloc.pixels); 403 } 404 405 /** Test gfx_cursor_set_visible() on a memory GC */ 406 PCUT_TEST(gfx_cursor_set_visible) 407 { 408 mem_gc_t *mgc; 409 gfx_rect_t rect; 410 gfx_bitmap_alloc_t alloc; 411 gfx_context_t *gc; 412 test_resp_t resp; 413 errno_t rc; 414 415 /* Bounding rectangle for memory GC */ 416 rect.p0.x = 0; 417 rect.p0.y = 0; 418 rect.p1.x = 10; 419 rect.p1.y = 10; 420 421 alloc.pitch = (rect.p1.x - rect.p0.x) * sizeof(uint32_t); 422 alloc.off0 = 0; 423 alloc.pixels = calloc(1, alloc.pitch * (rect.p1.y - rect.p0.y)); 424 PCUT_ASSERT_NOT_NULL(alloc.pixels); 425 426 rc = mem_gc_create(&rect, &alloc, &test_mem_gc_cb, &resp, &mgc); 427 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 428 429 gc = mem_gc_get_ctx(mgc); 430 PCUT_ASSERT_NOT_NULL(gc); 431 432 memset(&resp, 0, sizeof(resp)); 433 resp.rc = EOK; 434 PCUT_ASSERT_FALSE(resp.cursor_set_visible_called); 435 436 rc = gfx_cursor_set_visible(gc, true); 437 PCUT_ASSERT_TRUE(resp.cursor_set_visible_called); 438 PCUT_ASSERT_TRUE(resp.set_visible_vis); 439 440 resp.cursor_set_visible_called = false; 441 442 rc = gfx_cursor_set_visible(gc, false); 443 PCUT_ASSERT_TRUE(resp.cursor_set_visible_called); 444 PCUT_ASSERT_FALSE(resp.set_visible_vis); 445 446 mem_gc_delete(mgc); 447 free(alloc.pixels); 448 } 449 296 450 /** Called by memory GC when a rectangle is modified. */ 297 451 static void test_invalidate_rect(void *arg, gfx_rect_t *rect) … … 311 465 } 312 466 467 /** Called by memory GC when cursor_get_pos is called. */ 468 static errno_t test_cursor_get_pos(void *arg, gfx_coord2_t *pos) 469 { 470 test_resp_t *resp = (test_resp_t *)arg; 471 472 resp->cursor_get_pos_called = true; 473 *pos = resp->get_pos_pos; 474 return resp->rc; 475 } 476 477 /** Called by memory GC when cursor_set_pos is called. */ 478 static errno_t test_cursor_set_pos(void *arg, gfx_coord2_t *pos) 479 { 480 test_resp_t *resp = (test_resp_t *)arg; 481 482 resp->cursor_set_pos_called = true; 483 resp->set_pos_pos = *pos; 484 return resp->rc; 485 } 486 487 /** Called by memory GC when cursor_set_visible is called. */ 488 static errno_t test_cursor_set_visible(void *arg, bool visible) 489 { 490 test_resp_t *resp = (test_resp_t *)arg; 491 492 resp->cursor_set_visible_called = true; 493 resp->set_visible_vis = visible; 494 return resp->rc; 495 } 496 313 497 PCUT_EXPORT(memgfx); -
uspace/lib/ui/src/window.c
rbb14312 r1215db9 39 39 #include <gfx/bitmap.h> 40 40 #include <gfx/context.h> 41 #include <gfx/cursor.h> 41 42 #include <gfx/render.h> 42 43 #include <io/kbd_event.h> … … 88 89 static void ui_window_invalidate(void *, gfx_rect_t *); 89 90 static void ui_window_update(void *); 91 static errno_t ui_window_cursor_get_pos(void *, gfx_coord2_t *); 92 static errno_t ui_window_cursor_set_pos(void *, gfx_coord2_t *); 93 static errno_t ui_window_cursor_set_visible(void *, bool); 94 95 /** Window memory GC callbacks */ 96 static mem_gc_cb_t ui_window_mem_gc_cb = { 97 .invalidate = ui_window_invalidate, 98 .update = ui_window_update, 99 .cursor_get_pos = ui_window_cursor_get_pos, 100 .cursor_set_pos = ui_window_cursor_set_pos, 101 .cursor_set_visible = ui_window_cursor_set_visible 102 }; 103 90 104 static void ui_window_app_invalidate(void *, gfx_rect_t *); 91 105 static void ui_window_app_update(void *); 106 107 /** Application area memory GC callbacks */ 108 static mem_gc_cb_t ui_window_app_mem_gc_cb = { 109 .invalidate = ui_window_app_invalidate, 110 .update = ui_window_app_update 111 }; 112 92 113 static void ui_window_expose_cb(void *); 93 114 … … 255 276 } 256 277 257 rc = mem_gc_create(&bparams.rect, &alloc, ui_window_invalidate,258 ui_window_update,(void *) window, &memgc);278 rc = mem_gc_create(&bparams.rect, &alloc, &ui_window_mem_gc_cb, 279 (void *) window, &memgc); 259 280 if (rc != EOK) { 260 281 gfx_bitmap_destroy(window->app_bmp); … … 267 288 window->realgc = gc; 268 289 #else 269 (void) ui_window_update; 270 (void) ui_window_invalidate; 290 (void) ui_window_mem_gc_cb; 271 291 (void) alloc; 272 292 (void) bparams; … … 618 638 } 619 639 620 rc = mem_gc_create(¶ms.rect, &alloc, ui_window_app_invalidate,621 ui_window_app_update, (void *) window, &memgc);640 rc = mem_gc_create(¶ms.rect, &alloc, 641 &ui_window_app_mem_gc_cb, (void *) window, &memgc); 622 642 if (rc != EOK) { 623 643 gfx_bitmap_destroy(window->app_bmp); … … 1003 1023 } 1004 1024 1025 /** Window cursor get position callback 1026 * 1027 * @param arg Argument (ui_window_t *) 1028 * @param pos Place to store position 1029 */ 1030 static errno_t ui_window_cursor_get_pos(void *arg, gfx_coord2_t *pos) 1031 { 1032 ui_window_t *window = (ui_window_t *) arg; 1033 1034 return gfx_cursor_get_pos(window->realgc, pos); 1035 } 1036 1037 /** Window cursor set position callback 1038 * 1039 * @param arg Argument (ui_window_t *) 1040 * @param pos New position 1041 */ 1042 static errno_t ui_window_cursor_set_pos(void *arg, gfx_coord2_t *pos) 1043 { 1044 ui_window_t *window = (ui_window_t *) arg; 1045 1046 return gfx_cursor_set_pos(window->realgc, pos); 1047 } 1048 1049 /** Window cursor set visibility callback 1050 * 1051 * @param arg Argument (ui_window_t *) 1052 * @param visible @c true iff cursor is to be made visible 1053 */ 1054 static errno_t ui_window_cursor_set_visible(void *arg, bool visible) 1055 { 1056 ui_window_t *window = (ui_window_t *) arg; 1057 1058 return gfx_cursor_set_visible(window->realgc, visible); 1059 } 1060 1005 1061 /** Application area invalidate callback 1006 1062 * -
uspace/srv/hid/display/display.c
rbb14312 r1215db9 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 53 53 static void ds_display_update_cb(void *); 54 54 55 static mem_gc_cb_t ds_display_mem_gc_cb = { 56 .invalidate = ds_display_invalidate_cb, 57 .update = ds_display_update_cb 58 }; 59 55 60 /** Create display. 56 61 * … … 459 464 goto error; 460 465 461 rc = mem_gc_create(&disp->rect, &alloc, 462 ds_display_invalidate_cb, ds_display_update_cb, (void *) disp, 463 &disp->bbgc); 466 rc = mem_gc_create(&disp->rect, &alloc, &ds_display_mem_gc_cb, 467 (void *) disp, &disp->bbgc); 464 468 if (rc != EOK) 465 469 goto error; -
uspace/srv/hid/display/window.c
rbb14312 r1215db9 53 53 static void ds_window_get_preview_rect(ds_window_t *, gfx_rect_t *); 54 54 55 static mem_gc_cb_t ds_window_mem_gc_cb = { 56 .invalidate = ds_window_invalidate_cb, 57 .update = ds_window_update_cb 58 }; 59 55 60 /** Create window. 56 61 * … … 108 113 } 109 114 110 rc = mem_gc_create(¶ms->rect, &alloc, ds_window_invalidate_cb,111 ds_window_update_cb,(void *)wnd, &wnd->mgc);115 rc = mem_gc_create(¶ms->rect, &alloc, &ds_window_mem_gc_cb, 116 (void *)wnd, &wnd->mgc); 112 117 if (rc != EOK) 113 118 goto error;
Note:
See TracChangeset
for help on using the changeset viewer.