Lines Matching defs:vb

47 #define	VTBUF_LOCK(vb)		mtx_lock_spin(&(vb)->vb_lock)
48 #define VTBUF_UNLOCK(vb) mtx_unlock_spin(&(vb)->vb_lock)
66 vthistory_seek(struct vt_buf *vb, int offset, int whence)
71 if ((vb->vb_flags & VBF_SCROLL) == 0) {
72 if (vb->vb_roffset != vb->vb_curroffset) {
73 vb->vb_roffset = vb->vb_curroffset;
78 top = (vb->vb_flags & VBF_HISTORY_FULL)?
79 (vb->vb_curroffset + vb->vb_scr_size.tp_row):vb->vb_history_size;
80 bottom = vb->vb_curroffset + vb->vb_history_size;
86 roffset = vb->vb_roffset + vb->vb_history_size;
89 roffset = offset + vb->vb_history_size;
96 roffset = vb->vb_curroffset + vb->vb_history_size;
103 roffset %= vb->vb_history_size;
105 if (vb->vb_roffset != roffset) {
106 diff = vb->vb_roffset - roffset;
107 vb->vb_roffset = roffset;
119 vthistory_addlines(struct vt_buf *vb, int offset)
122 vb->vb_curroffset += offset;
123 if (vb->vb_curroffset < 0)
124 vb->vb_curroffset = 0;
125 vb->vb_curroffset %= vb->vb_history_size;
126 if ((vb->vb_flags & VBF_SCROLL) == 0) {
127 vb->vb_roffset = vb->vb_curroffset;
132 vthistory_getpos(const struct vt_buf *vb, unsigned int *offset)
135 *offset = vb->vb_roffset;
141 vtbuf_wth(struct vt_buf *vb, int row)
144 return ((vb->vb_roffset + row) % vb->vb_history_size);
150 vtbuf_htw(struct vt_buf *vb, int row)
159 return ((row - vb->vb_roffset + vb->vb_history_size) %
160 vb->vb_history_size);
164 vtbuf_iscursor(struct vt_buf *vb, int row, int col)
168 if ((vb->vb_flags & (VBF_CURSOR|VBF_SCROLL)) == VBF_CURSOR &&
169 (vb->vb_cursor.tp_row == row) && (vb->vb_cursor.tp_col == col))
178 sc = vb->vb_mark_start.tp_col;
179 sr = vtbuf_htw(vb, vb->vb_mark_start.tp_row);
180 ec = vb->vb_mark_end.tp_col;
181 er = vtbuf_htw(vb, vb->vb_mark_end.tp_row);
231 vtbuf_dirty(struct vt_buf *vb, const term_rect_t *area)
234 VTBUF_LOCK(vb);
235 if (vb->vb_dirtyrect.tr_begin.tp_row > area->tr_begin.tp_row)
236 vb->vb_dirtyrect.tr_begin.tp_row = area->tr_begin.tp_row;
237 if (vb->vb_dirtyrect.tr_begin.tp_col > area->tr_begin.tp_col)
238 vb->vb_dirtyrect.tr_begin.tp_col = area->tr_begin.tp_col;
239 if (vb->vb_dirtyrect.tr_end.tp_row < area->tr_end.tp_row)
240 vb->vb_dirtyrect.tr_end.tp_row = area->tr_end.tp_row;
241 if (vb->vb_dirtyrect.tr_end.tp_col < area->tr_end.tp_col)
242 vb->vb_dirtyrect.tr_end.tp_col = area->tr_end.tp_col;
243 vb->vb_dirtymask.vbm_row |=
245 vb->vb_dirtymask.vbm_col |=
247 VTBUF_UNLOCK(vb);
251 vtbuf_dirty_cell(struct vt_buf *vb, const term_pos_t *p)
258 vtbuf_dirty(vb, &area);
262 vtbuf_make_undirty(struct vt_buf *vb)
265 vb->vb_dirtyrect.tr_begin = vb->vb_scr_size;
266 vb->vb_dirtyrect.tr_end.tp_row = vb->vb_dirtyrect.tr_end.tp_col = 0;
267 vb->vb_dirtymask.vbm_row = vb->vb_dirtymask.vbm_col = 0;
271 vtbuf_undirty(struct vt_buf *vb, term_rect_t *r, struct vt_bufmask *m)
274 VTBUF_LOCK(vb);
275 *r = vb->vb_dirtyrect;
276 *m = vb->vb_dirtymask;
277 vtbuf_make_undirty(vb);
278 VTBUF_UNLOCK(vb);
282 vtbuf_copy(struct vt_buf *vb, const term_rect_t *r, const term_pos_t *p2)
289 KASSERT(r->tr_begin.tp_row < vb->vb_scr_size.tp_row,
291 r->tr_begin.tp_row, vb->vb_scr_size.tp_row));
292 KASSERT(r->tr_begin.tp_col < vb->vb_scr_size.tp_col,
294 r->tr_begin.tp_col, vb->vb_scr_size.tp_col));
296 KASSERT(r->tr_end.tp_row <= vb->vb_scr_size.tp_row,
298 r->tr_end.tp_row, vb->vb_scr_size.tp_row));
299 KASSERT(r->tr_end.tp_col <= vb->vb_scr_size.tp_col,
301 r->tr_end.tp_col, vb->vb_scr_size.tp_col));
303 KASSERT(p2->tp_row < vb->vb_scr_size.tp_row,
305 p2->tp_row, vb->vb_scr_size.tp_row));
306 KASSERT(p2->tp_col < vb->vb_scr_size.tp_col,
308 p2->tp_col, vb->vb_scr_size.tp_col));
314 r->tr_end.tp_col == vb->vb_scr_size.tp_col && /* Full row. */
315 (rows + rdiff) == vb->vb_scr_size.tp_row && /* Whole screen. */
317 vthistory_addlines(vb, rdiff);
323 &VTBUF_FIELD(vb, p2->tp_row + pr, p2->tp_col),
324 &VTBUF_FIELD(vb, p1->tp_row + pr, p1->tp_col),
330 &VTBUF_FIELD(vb, p2->tp_row + pr, p2->tp_col),
331 &VTBUF_FIELD(vb, p1->tp_row + pr, p1->tp_col),
336 area.tr_end.tp_row = MIN(p2->tp_row + rows, vb->vb_scr_size.tp_row);
337 area.tr_end.tp_col = MIN(p2->tp_col + cols, vb->vb_scr_size.tp_col);
338 vtbuf_dirty(vb, &area);
342 vtbuf_fill(struct vt_buf *vb, const term_rect_t *r, term_char_t c)
348 row = vb->vb_rows[(vb->vb_curroffset + pr) %
349 VTBUF_MAX_HEIGHT(vb)];
357 vtbuf_fill_locked(struct vt_buf *vb, const term_rect_t *r, term_char_t c)
359 KASSERT(r->tr_begin.tp_row < vb->vb_scr_size.tp_row,
361 r->tr_begin.tp_row, vb->vb_scr_size.tp_row));
362 KASSERT(r->tr_begin.tp_col < vb->vb_scr_size.tp_col,
364 r->tr_begin.tp_col, vb->vb_scr_size.tp_col));
366 KASSERT(r->tr_end.tp_row <= vb->vb_scr_size.tp_row,
368 r->tr_end.tp_row, vb->vb_scr_size.tp_row));
369 KASSERT(r->tr_end.tp_col <= vb->vb_scr_size.tp_col,
371 r->tr_end.tp_col, vb->vb_scr_size.tp_col));
373 VTBUF_LOCK(vb);
374 vtbuf_fill(vb, r, c);
375 VTBUF_UNLOCK(vb);
377 vtbuf_dirty(vb, r);
381 vtbuf_init_rows(struct vt_buf *vb)
385 vb->vb_history_size = MAX(vb->vb_history_size, vb->vb_scr_size.tp_row);
387 for (r = 0; r < vb->vb_history_size; r++)
388 vb->vb_rows[r] = &vb->vb_buffer[r *
389 vb->vb_scr_size.tp_col];
393 vtbuf_init_early(struct vt_buf *vb)
396 vb->vb_flags |= VBF_CURSOR;
397 vb->vb_roffset = 0;
398 vb->vb_curroffset = 0;
399 vb->vb_mark_start.tp_row = 0;
400 vb->vb_mark_start.tp_col = 0;
401 vb->vb_mark_end.tp_row = 0;
402 vb->vb_mark_end.tp_col = 0;
404 vtbuf_init_rows(vb);
405 vtbuf_make_undirty(vb);
406 if ((vb->vb_flags & VBF_MTX_INIT) == 0) {
407 mtx_init(&vb->vb_lock, "vtbuf", NULL, MTX_SPIN);
408 vb->vb_flags |= VBF_MTX_INIT;
413 vtbuf_init(struct vt_buf *vb, const term_pos_t *p)
417 vb->vb_scr_size = *p;
418 vb->vb_history_size = VBF_DEFAULT_HISTORY_SIZE;
420 if ((vb->vb_flags & VBF_STATIC) == 0) {
421 sz = vb->vb_history_size * p->tp_col * sizeof(term_char_t);
422 vb->vb_buffer = malloc(sz, M_VTBUF, M_WAITOK | M_ZERO);
424 sz = vb->vb_history_size * sizeof(term_char_t *);
425 vb->vb_rows = malloc(sz, M_VTBUF, M_WAITOK | M_ZERO);
428 vtbuf_init_early(vb);
432 vtbuf_sethistory_size(struct vt_buf *vb, int size)
437 p.tp_row = vb->vb_scr_size.tp_row;
438 p.tp_col = vb->vb_scr_size.tp_col;
439 vtbuf_grow(vb, &p, size);
443 vtbuf_grow(struct vt_buf *vb, const term_pos_t *p, int history_size)
451 if (history_size > vb->vb_history_size || p->tp_col >
452 vb->vb_scr_size.tp_col) {
460 VTBUF_LOCK(vb);
461 old = vb->vb_flags & VBF_STATIC ? NULL : vb->vb_buffer;
462 oldrows = vb->vb_flags & VBF_STATIC ? NULL : vb->vb_rows;
463 copyrows = vb->vb_rows;
464 w = vb->vb_scr_size.tp_col;
465 h = vb->vb_history_size;
467 vb->vb_history_size = history_size;
468 vb->vb_buffer = new;
469 vb->vb_rows = rows;
470 vb->vb_flags &= ~VBF_STATIC;
471 vb->vb_scr_size = *p;
472 vtbuf_init_rows(vb);
489 vtbuf_fill(vb, &rect, VTBUF_SPACE_CHAR);
493 vtbuf_make_undirty(vb);
494 VTBUF_UNLOCK(vb);
502 vtbuf_putchar(struct vt_buf *vb, const term_pos_t *p, term_char_t c)
506 KASSERT(p->tp_row < vb->vb_scr_size.tp_row,
508 p->tp_row, vb->vb_scr_size.tp_row));
509 KASSERT(p->tp_col < vb->vb_scr_size.tp_col,
511 p->tp_col, vb->vb_scr_size.tp_col));
513 row = vb->vb_rows[(vb->vb_curroffset + p->tp_row) %
514 VTBUF_MAX_HEIGHT(vb)];
516 VTBUF_LOCK(vb);
518 VTBUF_UNLOCK(vb);
519 vtbuf_dirty_cell(vb, p);
524 vtbuf_cursor_position(struct vt_buf *vb, const term_pos_t *p)
527 if (vb->vb_flags & VBF_CURSOR) {
528 vtbuf_dirty_cell(vb, &vb->vb_cursor);
529 vb->vb_cursor = *p;
530 vtbuf_dirty_cell(vb, &vb->vb_cursor);
532 vb->vb_cursor = *p;
538 vtbuf_mouse_cursor_position(struct vt_buf *vb, int col, int row)
544 area.tr_end.tp_row = MIN(row + 2, vb->vb_scr_size.tp_row);
545 area.tr_end.tp_col = MIN(col + 2, vb->vb_scr_size.tp_col);
546 vtbuf_dirty(vb, &area);
550 vtbuf_flush_mark(struct vt_buf *vb)
556 if (vb->vb_mark_start.tp_col || vb->vb_mark_end.tp_col ||
557 vb->vb_mark_start.tp_row || vb->vb_mark_end.tp_row) {
559 s = vtbuf_htw(vb, vb->vb_mark_start.tp_row);
560 e = vtbuf_htw(vb, vb->vb_mark_end.tp_row);
565 area.tr_end.tp_col = vb->vb_scr_size.tp_col;
568 vtbuf_dirty(vb, &area);
573 vtbuf_get_marked_len(struct vt_buf *vb)
579 if (POS_INDEX(vtbuf_htw(vb, vb->vb_mark_start.tp_row),
580 vb->vb_mark_start.tp_col) >
581 POS_INDEX(vtbuf_htw(vb, vb->vb_mark_end.tp_row),
582 vb->vb_mark_end.tp_col)) {
583 POS_COPY(e, vb->vb_mark_start);
584 POS_COPY(s, vb->vb_mark_end);
586 POS_COPY(s, vb->vb_mark_start);
587 POS_COPY(e, vb->vb_mark_end);
590 si = s.tp_row * vb->vb_scr_size.tp_col + s.tp_col;
591 ei = e.tp_row * vb->vb_scr_size.tp_col + e.tp_col;
600 vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz)
606 if (POS_INDEX(vtbuf_htw(vb, vb->vb_mark_start.tp_row),
607 vb->vb_mark_start.tp_col) >
608 POS_INDEX(vtbuf_htw(vb, vb->vb_mark_end.tp_row),
609 vb->vb_mark_end.tp_col)) {
610 POS_COPY(e, vb->vb_mark_start);
611 POS_COPY(s, vb->vb_mark_end);
613 POS_COPY(s, vb->vb_mark_start);
614 POS_COPY(e, vb->vb_mark_end);
620 ce = (r == e.tp_row)?e.tp_col:vb->vb_scr_size.tp_col;
622 buf[i++] = vb->vb_rows[r][c];
633 vtbuf_set_mark(struct vt_buf *vb, int type, int col, int row)
640 if (vb->vb_mark_last != VTB_MARK_MOVE)
645 vtbuf_flush_mark(vb); /* Clean old mark. */
646 vb->vb_mark_end.tp_col = col;
647 vb->vb_mark_end.tp_row = vtbuf_wth(vb, row);
650 vtbuf_flush_mark(vb); /* Clean old mark. */
651 vb->vb_mark_start.tp_col = col;
652 vb->vb_mark_start.tp_row = vtbuf_wth(vb, row);
654 vb->vb_mark_end.tp_col = col;
655 vb->vb_mark_end.tp_row = vtbuf_wth(vb, row);
658 vtbuf_flush_mark(vb); /* Clean old mark. */
659 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row =
660 vtbuf_wth(vb, row);
661 r = vb->vb_rows[vb->vb_mark_start.tp_row];
664 vb->vb_mark_start.tp_col = i + 1;
668 for (i = col; i < vb->vb_scr_size.tp_col; i ++) {
670 vb->vb_mark_end.tp_col = i;
674 if (vb->vb_mark_start.tp_col > vb->vb_mark_end.tp_col)
675 vb->vb_mark_start.tp_col = vb->vb_mark_end.tp_col;
678 vtbuf_flush_mark(vb); /* Clean old mark. */
679 vb->vb_mark_start.tp_col = 0;
680 vb->vb_mark_end.tp_col = vb->vb_scr_size.tp_col;
681 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row =
682 vtbuf_wth(vb, row);
685 vb->vb_mark_last = type;
692 vb->vb_mark_last = type;
694 vtbuf_flush_mark(vb);
700 vtbuf_cursor_visibility(struct vt_buf *vb, int yes)
704 VTBUF_LOCK(vb);
705 oflags = vb->vb_flags;
707 vb->vb_flags |= VBF_CURSOR;
709 vb->vb_flags &= ~VBF_CURSOR;
710 nflags = vb->vb_flags;
711 VTBUF_UNLOCK(vb);
714 vtbuf_dirty_cell(vb, &vb->vb_cursor);
718 vtbuf_scroll_mode(struct vt_buf *vb, int yes)
722 VTBUF_LOCK(vb);
723 oflags = vb->vb_flags;
725 vb->vb_flags |= VBF_SCROLL;
727 vb->vb_flags &= ~VBF_SCROLL;
728 nflags = vb->vb_flags;
729 VTBUF_UNLOCK(vb);
732 vtbuf_dirty_cell(vb, &vb->vb_cursor);