Changes in uspace/app/terminal/terminal.c [266ec54:77ffa01] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/terminal/terminal.c
r266ec54 r77ffa01 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * Copyright (c) 2012 Petr Koupy 4 4 * All rights reserved. … … 37 37 #include <adt/list.h> 38 38 #include <adt/prodcons.h> 39 #include <as.h> 39 40 #include <errno.h> 40 41 #include <fbfont/font-8x16.h> … … 42 43 #include <gfx/bitmap.h> 43 44 #include <gfx/context.h> 45 #include <gfx/render.h> 44 46 #include <io/con_srv.h> 45 47 #include <io/concaps.h> … … 48 50 #include <task.h> 49 51 #include <stdarg.h> 52 #include <stdio.h> 50 53 #include <stdlib.h> 51 54 #include <str.h> … … 85 88 static void term_set_cursor_visibility(con_srv_t *, bool); 86 89 static errno_t term_get_event(con_srv_t *, cons_event_t *); 90 static errno_t term_map(con_srv_t *, sysarg_t, sysarg_t, charfield_t **); 91 static void term_unmap(con_srv_t *); 92 static void term_buf_update(con_srv_t *, sysarg_t, sysarg_t, sysarg_t, 93 sysarg_t); 87 94 88 95 static con_ops_t con_ops = { … … 101 108 .set_rgb_color = term_set_rgb_color, 102 109 .set_cursor_visibility = term_set_cursor_visibility, 103 .get_event = term_get_event 110 .get_event = term_get_event, 111 .map = term_map, 112 .unmap = term_unmap, 113 .update = term_buf_update 104 114 }; 105 115 … … 331 341 332 342 bool update = false; 333 sysarg_t sx = 0 /*term->widget.hpos*/;334 sysarg_t sy = 0 /*term->widget.vpos*/;343 sysarg_t sx = 0; 344 sysarg_t sy = 0; 335 345 336 346 if (term_update_scroll(term, &pixelmap, sx, sy)) { … … 343 353 charfield_t *back_field = 344 354 chargrid_charfield_at(term->backbuf, x, y); 345 bool update = false;355 bool cupdate = false; 346 356 347 357 if ((front_field->flags & CHAR_FLAG_DIRTY) == … … 349 359 if (front_field->ch != back_field->ch) { 350 360 back_field->ch = front_field->ch; 351 update = true;361 cupdate = true; 352 362 } 353 363 … … 355 365 back_field->attrs)) { 356 366 back_field->attrs = front_field->attrs; 357 update = true;367 cupdate = true; 358 368 } 359 369 … … 361 371 } 362 372 363 if ( update) {373 if (cupdate) { 364 374 term_update_char(term, &pixelmap, sx, sy, x, y); 365 375 update = true; … … 524 534 term_write_char(term, str_decode(data, &off, size)); 525 535 536 gfx_update(term->gc); 526 537 *nwritten = size; 527 538 return EOK; … … 533 544 534 545 term_update(term); 546 gfx_update(term->gc); 535 547 } 536 548 … … 544 556 545 557 term_update(term); 558 gfx_update(term->gc); 546 559 } 547 560 … … 555 568 556 569 term_update(term); 570 gfx_update(term->gc); 557 571 } 558 572 … … 626 640 627 641 term_update(term); 642 gfx_update(term->gc); 628 643 } 629 644 … … 637 652 free(ev); 638 653 return EOK; 654 } 655 656 /** Create shared buffer for efficient rendering. 657 * 658 * @param srv Console server 659 * @param cols Number of columns in buffer 660 * @param rows Number of rows in buffer 661 * @param rbuf Place to store pointer to new sharable buffer 662 * 663 * @return EOK on sucess or an error code 664 */ 665 static errno_t term_map(con_srv_t *srv, sysarg_t cols, sysarg_t rows, 666 charfield_t **rbuf) 667 { 668 terminal_t *term = srv_to_terminal(srv); 669 void *buf; 670 671 fibril_mutex_lock(&term->mtx); 672 673 if (term->ubuf != NULL) { 674 fibril_mutex_unlock(&term->mtx); 675 return EBUSY; 676 } 677 678 buf = as_area_create(AS_AREA_ANY, cols * rows * sizeof(charfield_t), 679 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED); 680 if (buf == AS_MAP_FAILED) { 681 fibril_mutex_unlock(&term->mtx); 682 return ENOMEM; 683 } 684 685 term->ucols = cols; 686 term->urows = rows; 687 term->ubuf = buf; 688 fibril_mutex_unlock(&term->mtx); 689 690 *rbuf = buf; 691 return EOK; 692 } 693 694 /** Delete shared buffer. 695 * 696 * @param srv Console server 697 */ 698 static void term_unmap(con_srv_t *srv) 699 { 700 terminal_t *term = srv_to_terminal(srv); 701 void *buf; 702 703 fibril_mutex_lock(&term->mtx); 704 705 buf = term->ubuf; 706 term->ubuf = NULL; 707 708 if (buf != NULL) 709 as_area_destroy(buf); 710 711 fibril_mutex_unlock(&term->mtx); 712 } 713 714 /** Update area of terminal from shared buffer. 715 * 716 * @param srv Console server 717 * @param c0 Column coordinate of top-left corner (inclusive) 718 * @param r0 Row coordinate of top-left corner (inclusive) 719 * @param c1 Column coordinate of bottom-right corner (exclusive) 720 * @param r1 Row coordinate of bottom-right corner (exclusive) 721 */ 722 static void term_buf_update(con_srv_t *srv, sysarg_t c0, sysarg_t r0, 723 sysarg_t c1, sysarg_t r1) 724 { 725 terminal_t *term = srv_to_terminal(srv); 726 charfield_t *ch; 727 sysarg_t col, row; 728 729 fibril_mutex_lock(&term->mtx); 730 731 if (term->ubuf == NULL) { 732 fibril_mutex_unlock(&term->mtx); 733 return; 734 } 735 736 /* Make sure we have meaningful coordinates, within bounds */ 737 738 if (c1 > term->ucols) 739 c1 = term->ucols; 740 if (c1 > term->cols) 741 c1 = term->cols; 742 if (c0 >= c1) { 743 fibril_mutex_unlock(&term->mtx); 744 return; 745 } 746 if (r1 > term->urows) 747 r1 = term->urows; 748 if (r1 > term->rows) 749 r1 = term->rows; 750 if (r0 >= r1) { 751 fibril_mutex_unlock(&term->mtx); 752 return; 753 } 754 755 /* Update front buffer from user buffer */ 756 757 for (row = r0; row < r1; row++) { 758 for (col = c0; col < c1; col++) { 759 ch = chargrid_charfield_at(term->frontbuf, col, row); 760 *ch = term->ubuf[row * term->ucols + col]; 761 } 762 } 763 764 fibril_mutex_unlock(&term->mtx); 765 766 /* Update terminal */ 767 term_update(term); 768 gfx_update(term->gc); 639 769 } 640 770 … … 688 818 term->is_focused = true; 689 819 term_update(term); 820 gfx_update(term->gc); 690 821 } 691 822 … … 712 843 sysarg_t sy = -term->off.y; 713 844 714 if (event->type == POS_PRESS ) {845 if (event->type == POS_PRESS || event->type == POS_RELEASE) { 715 846 cevent.type = CEV_POS; 716 847 cevent.ev.pos.type = event->type; … … 731 862 term->is_focused = false; 732 863 term_update(term); 864 gfx_update(term->gc); 733 865 } 734 866
Note:
See TracChangeset
for help on using the changeset viewer.