Changeset 6d5e378 in mainline for uspace/srv/hid/output/proto


Ignore:
Timestamp:
2012-08-16T19:27:44Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4f351432, 7d27f422
Parents:
c9d011e4
Message:

cherrypick GUI implementation (originally by Petr Koupy), with several major changes

  • for character-oriented devices a new output server and output protocol was created based on the original fb server
  • DDF visualizer drivers are pixel-oriented only
  • console and compositor can coexist in the same build
  • terminal widget is self-sufficient, no strange console nesting is needed
Location:
uspace/srv/hid/output/proto
Files:
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/output/proto/vt100.c

    rc9d011e4 r6d5e378  
    3232#include <sys/types.h>
    3333#include <inttypes.h>
     34#include <errno.h>
    3435#include <stdio.h>
     36#include <unistd.h>
     37#include <malloc.h>
    3538#include <io/color.h>
    36 #include <malloc.h>
    37 #include <errno.h>
    3839#include "vt100.h"
    3940
    4041#define MAX_CONTROL  20
    41 
    42 #define BACKBUF_POS(state, x, y)  ((y) * ((state)->width) + (x))
    43 
    44 struct vt100_state {
    45         vt100_putchar_t putchar;
    46         vt100_control_puts_t control_puts;
    47        
    48         sysarg_t width;
    49         sysarg_t height;
    50        
    51         sysarg_t cur_col;
    52         sysarg_t cur_row;
    53        
    54         char_attrs_t cur_attrs;
    55        
    56         charfield_t backbuf[];
    57 };
    5842
    5943typedef enum {
     
    154138}
    155139
    156 vt100_state_t *vt100_state_create(sysarg_t width, sysarg_t height,
     140vt100_state_t *vt100_state_create(sysarg_t cols, sysarg_t rows,
    157141    vt100_putchar_t putchar_fn, vt100_control_puts_t control_puts_fn)
    158142{
    159         size_t sz = width * height * sizeof(charfield_t);
    160        
    161143        vt100_state_t *state =
    162             malloc(sizeof(vt100_state_t) + sz);
     144            malloc(sizeof(vt100_state_t));
    163145        if (state == NULL)
    164146                return NULL;
     
    167149        state->control_puts = control_puts_fn;
    168150       
    169         state->width = width;
    170         state->height = height;
     151        state->cols = cols;
     152        state->rows = rows;
    171153       
    172154        state->cur_col = (sysarg_t) -1;
     
    175157        state->cur_attrs.type = CHAR_ATTR_STYLE;
    176158        state->cur_attrs.val.style = STYLE_NORMAL;
    177        
    178         memset(state->backbuf, 0, sz);
    179159       
    180160        /* Initialize graphic rendition attributes */
     
    183163        vt100_sgr(state, SGR_BGCOLOR + CI_WHITE);
    184164        state->control_puts("\033[2J");
     165        state->control_puts("\033[?25l");
    185166       
    186167        return state;
    187168}
    188169
    189 void vt100_get_resolution(vt100_state_t *state, sysarg_t *width,
    190     sysarg_t *height)
    191 {
    192         *width = state->width;
    193         *height = state->height;
     170void vt100_state_destroy(vt100_state_t *state)
     171{
     172        free(state);
     173}
     174
     175void vt100_get_dimensions(vt100_state_t *state, sysarg_t *cols,
     176    sysarg_t *rows)
     177{
     178        *cols = state->cols;
     179        *rows = state->rows;
    194180}
    195181
     
    201187int vt100_claim(vt100_state_t *state)
    202188{
    203         for (sysarg_t row = 0; row < state->height; row++) {
    204                 vt100_set_pos(state, 0, row);
    205                 for (sysarg_t col = 0; col < state->width; col++) {
    206                         charfield_t *field = state->backbuf +
    207                             BACKBUF_POS(state, col, row);
    208                         vt100_set_sgr(state, field->attrs);
    209                         state->putchar(field->ch);
    210                 }
    211         }
    212        
    213         vt100_set_pos(state, state->cur_col, state->cur_row);
    214         vt100_set_sgr(state, state->cur_attrs);
    215        
    216189        return EOK;
    217190}
    218191
    219 void vt100_putchar(vt100_state_t *state, wchar_t ch)
    220 {
    221         charfield_t *field = state->backbuf +
    222             BACKBUF_POS(state, state->cur_col, state->cur_row);
    223         field->ch = ch;
    224         field->attrs = state->cur_attrs;
    225        
    226         state->putchar(ch);
    227         state->cur_col++;
    228        
    229         if (state->cur_col >= state->width) {
    230                 state->cur_row += state->cur_col / state->width;
    231                 state->cur_col %= state->width;
    232         }
    233 }
    234 
    235 void vt100_set_attr(vt100_state_t *state, char_attrs_t attrs)
    236 {
    237         if (!attrs_same(state->cur_attrs, attrs)) {
    238                 vt100_set_sgr(state, attrs);
    239                 state->cur_attrs = attrs;
    240         }
    241 }
    242 
    243192void vt100_goto(vt100_state_t *state, sysarg_t col, sysarg_t row)
    244193{
    245         if ((col >= state->width) || (row >= state->height))
     194        if ((col >= state->cols) || (row >= state->rows))
    246195                return;
    247196       
     
    253202}
    254203
     204void vt100_set_attr(vt100_state_t *state, char_attrs_t attrs)
     205{
     206        if (!attrs_same(state->cur_attrs, attrs)) {
     207                vt100_set_sgr(state, attrs);
     208                state->cur_attrs = attrs;
     209        }
     210}
     211
    255212void vt100_cursor_visibility(vt100_state_t *state, bool visible)
    256213{
     
    261218}
    262219
     220void vt100_putchar(vt100_state_t *state, wchar_t ch)
     221{
     222        state->putchar(ch == 0 ? ' ' : ch);
     223        state->cur_col++;
     224       
     225        if (state->cur_col >= state->cols) {
     226                state->cur_row += state->cur_col / state->cols;
     227                state->cur_col %= state->cols;
     228        }
     229}
     230
    263231/** @}
    264232 */
  • uspace/srv/hid/output/proto/vt100.h

    rc9d011e4 r6d5e378  
    3030 */
    3131
    32 #ifndef FB_PROTO_VT100_H_
    33 #define FB_PROTO_VT100_H_
     32#ifndef OUTPUT_PROTO_VT100_H_
     33#define OUTPUT_PROTO_VT100_H_
    3434
    3535#include <sys/types.h>
    36 #include <screenbuffer.h>
     36#include <io/charfield.h>
    3737
    3838typedef void (* vt100_putchar_t)(wchar_t ch);
    3939typedef void (* vt100_control_puts_t)(const char *str);
    4040
    41 /** Forward declaration */
    42 struct vt100_state;
    43 typedef struct vt100_state vt100_state_t;
     41typedef struct {
     42        sysarg_t cols;
     43        sysarg_t rows;
     44       
     45        sysarg_t cur_col;
     46        sysarg_t cur_row;
     47        char_attrs_t cur_attrs;
     48       
     49        vt100_putchar_t putchar;
     50        vt100_control_puts_t control_puts;
     51} vt100_state_t;
    4452
    4553extern vt100_state_t *vt100_state_create(sysarg_t, sysarg_t, vt100_putchar_t,
    4654    vt100_control_puts_t);
    47 extern void vt100_get_resolution(vt100_state_t *, sysarg_t *, sysarg_t *);
     55extern void vt100_state_destroy(vt100_state_t *);
     56
    4857extern int vt100_yield(vt100_state_t *);
    4958extern int vt100_claim(vt100_state_t *);
     59extern void vt100_get_dimensions(vt100_state_t *, sysarg_t *, sysarg_t *);
    5060
     61extern void vt100_goto(vt100_state_t *, sysarg_t, sysarg_t);
     62extern void vt100_set_attr(vt100_state_t *, char_attrs_t);
     63extern void vt100_cursor_visibility(vt100_state_t *, bool);
    5164extern void vt100_putchar(vt100_state_t *, wchar_t);
    52 
    53 extern void vt100_set_attr(vt100_state_t *, char_attrs_t);
    54 extern void vt100_goto(vt100_state_t *, sysarg_t, sysarg_t);
    55 extern void vt100_cursor_visibility(vt100_state_t *, bool);
    5665
    5766#endif
Note: See TracChangeset for help on using the changeset viewer.