Subversion Repositories HelenOS

Rev

Rev 4420 | Rev 4537 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4420 Rev 4439
Line 53... Line 53...
53
#include <event.h>
53
#include <event.h>
54
 
54
 
55
#include "console.h"
55
#include "console.h"
56
#include "gcons.h"
56
#include "gcons.h"
57
 
57
 
-
 
58
#define NAME  "console"
-
 
59
 
58
#define MAX_KEYREQUESTS_BUFFERED 32
60
#define MAX_KEYREQUESTS_BUFFERED  32
59
 
61
 
-
 
62
/** Size of cwrite_buf. */
60
#define NAME "console"
63
#define CWRITE_BUF_SIZE  256
61
 
64
 
62
/** Index of currently used virtual console.
65
/** Index of currently used virtual console.
63
 */
66
 */
64
int active_console = 0;
67
int active_console = 0;
65
int prev_console = 0;
68
int prev_console = 0;
Line 74... Line 77...
74
    ipcarg_t cols;      /**< Framebuffer columns */
77
    ipcarg_t cols;  /**< Framebuffer columns */
75
} fb_info;
78
} fb_info;
76
 
79
 
77
typedef struct {
80
typedef struct {
78
    keybuffer_t keybuffer;      /**< Buffer for incoming keys. */
81
    keybuffer_t keybuffer;        /**< Buffer for incoming keys. */
-
 
82
   
79
    /** Buffer for unsatisfied request for keys. */
83
    /** Buffer for unsatisfied request for keys. */
80
    FIFO_CREATE_STATIC(keyrequests, ipc_callid_t,
84
    FIFO_CREATE_STATIC(keyrequests, ipc_callid_t,
81
        MAX_KEYREQUESTS_BUFFERED); 
85
        MAX_KEYREQUESTS_BUFFERED);
-
 
86
   
82
    int keyrequest_counter;     /**< Number of requests in buffer. */
87
    int keyrequest_counter;       /**< Number of requests in buffer. */
83
    int client_phone;       /**< Phone to connected client. */
88
    int client_phone;             /**< Phone to connected client. */
84
    int used;           /**< 1 if this virtual console is
89
    int used;                     /**< 1 if this virtual console is
85
                     * connected to some client.*/
90
                                       connected to some client. */
86
    screenbuffer_t screenbuffer;    /**< Screenbuffer for saving screen
91
    screenbuffer_t screenbuffer;  /**< Screenbuffer for saving screen
87
                     * contents and related settings. */
92
                                       contents and related settings. */
88
} connection_t;
93
} connection_t;
89
 
94
 
90
static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual
-
 
91
                         * consoles */
95
/** Array of data for virtual consoles */
92
static keyfield_t *interbuffer = NULL;      /**< Pointer to memory shared
96
static connection_t connections[CONSOLE_COUNT];
-
 
97
 
93
                         * with framebufer used for
98
/** Pointer to memory shared with framebufer used for
94
                         * faster virtual console
99
    faster virtual console switching */
95
                         * switching */
100
static keyfield_t *interbuffer = NULL;
96
 
101
 
97
/** Information on row-span yet unsent to FB driver. */
102
/** Information on row-span yet unsent to FB driver. */
98
struct {
103
struct {
99
    int row;        /**< Row where the span lies. */
104
    int row;  /**< Row where the span lies. */
100
    int col;        /**< Leftmost column of the span. */
105
    int col;  /**< Leftmost column of the span. */
101
    int n;          /**< Width of the span. */
106
    int cnt;  /**< Width of the span. */
102
} fb_pending;
107
} fb_pending;
103
 
108
 
104
/** Size of cwrite_buf. */
-
 
105
#define CWRITE_BUF_SIZE 256
-
 
106
 
-
 
107
/** Buffer for receiving data via the CONSOLE_WRITE call from the client. */
109
/** Buffer for receiving data via the CONSOLE_WRITE call from the client. */
108
static char cwrite_buf[CWRITE_BUF_SIZE];
110
static char cwrite_buf[CWRITE_BUF_SIZE];
109
 
111
 
110
static void fb_putchar(wchar_t c, int row, int col);
-
 
111
 
-
 
112
 
-
 
113
/** Find unused virtual console.
112
/** Find unused virtual console.
114
 *
113
 *
115
 */
114
 */
116
static int find_free_connection(void)
115
static int find_free_connection(void)
117
{
116
{
Line 119... Line 118...
119
   
118
   
120
    for (i = 0; i < CONSOLE_COUNT; i++) {
119
    for (i = 0; i < CONSOLE_COUNT; i++) {
121
        if (!connections[i].used)
120
        if (!connections[i].used)
122
            return i;
121
            return i;
123
    }
122
    }
-
 
123
   
124
    return -1;
124
    return -1;
125
}
125
}
126
 
126
 
127
static void clrscr(void)
127
static void clrscr(void)
128
{
128
{
Line 183... Line 183...
183
{
183
{
184
    switch (attrs->t) {
184
    switch (attrs->t) {
185
    case at_style:
185
    case at_style:
186
        set_style(attrs->a.s.style);
186
        set_style(attrs->a.s.style);
187
        break;
187
        break;
188
 
-
 
189
    case at_idx:
188
    case at_idx:
190
        set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
189
        set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
191
            attrs->a.i.flags);
190
            attrs->a.i.flags);
192
        break;
191
        break;
193
 
-
 
194
    case at_rgb:
192
    case at_rgb:
195
        set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
193
        set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
196
        break;
194
        break;
197
    }
195
    }
198
}
196
}
199
 
197
 
200
/** Send an area of screenbuffer to the FB driver. */
198
/** Send an area of screenbuffer to the FB driver. */
201
static void fb_update_area(connection_t *conn, int x, int y, int w, int h)
199
static void fb_update_area(connection_t *conn, int x, int y, int w, int h)
202
{
200
{
203
    int i, j;
201
    int i;
204
    int rc;
202
    int j;
205
    attrs_t *attrs;
203
    attrs_t *attrs;
206
    keyfield_t *field;
204
    keyfield_t *field;
207
 
205
   
208
    if (interbuffer) {
206
    if (interbuffer) {
209
        for (j = 0; j < h; j++) {
207
        for (j = 0; j < h; j++) {
210
            for (i = 0; i < w; i++) {
208
            for (i = 0; i < w; i++) {
211
                interbuffer[i + j * w] =
209
                interbuffer[i + j * w] =
212
                    *get_field_at(&conn->screenbuffer,
210
                    *get_field_at(&conn->screenbuffer, x + i, y + j);
213
                    x + i, y + j);
-
 
214
            }
211
            }
215
        }
212
        }
216
 
213
       
217
        rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
214
        async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
218
            x, y, w, h);
215
            x, y, w, h);
219
    } else {
-
 
220
        rc = ENOTSUP;
-
 
221
    }
-
 
222
 
-
 
223
    if (rc != 0) {
-
 
224
        /*
-
 
225
        attrs = &conn->screenbuffer.attrs;
-
 
226
 
-
 
227
        for (j = 0; j < h; j++) {
-
 
228
            for (i = 0; i < w; i++) {
-
 
229
                field = get_field_at(&conn->screenbuffer,
-
 
230
                    x + i, y + j);
-
 
231
                if (!attrs_same(*attrs, field->attrs))
-
 
232
                    set_attrs(&field->attrs);
-
 
233
                attrs = &field->attrs;
-
 
234
 
-
 
235
                fb_putchar(field->character, y + j, x + i);
-
 
236
            }
-
 
237
        }*/
-
 
238
    }
216
    }
239
}
217
}
240
 
218
 
241
/** Flush pending cells to FB. */
219
/** Flush pending cells to FB. */
242
static void fb_pending_flush(void)
220
static void fb_pending_flush(void)
243
{
221
{
244
    screenbuffer_t *scr;
222
    screenbuffer_t *scr
-
 
223
        = &(connections[active_console].screenbuffer);
245
 
224
   
246
    scr = &(connections[active_console].screenbuffer);
-
 
247
 
-
 
248
    if (fb_pending.n > 0) {
225
    if (fb_pending.cnt > 0) {
249
        fb_update_area(&connections[active_console], fb_pending.col,
226
        fb_update_area(&connections[active_console], fb_pending.col,
250
            fb_pending.row, fb_pending.n, 1);
227
            fb_pending.row, fb_pending.cnt, 1);
251
        fb_pending.n = 0;
228
        fb_pending.cnt = 0;
252
    }
229
    }
253
}
230
}
254
 
231
 
255
/** Mark a character cell as changed.
232
/** Mark a character cell as changed.
256
 *
233
 *
257
 * This adds the cell to the pending rowspan if possible. Otherwise
234
 * This adds the cell to the pending rowspan if possible. Otherwise
258
 * the old span is flushed first.
235
 * the old span is flushed first.
-
 
236
 *
259
 */
237
 */
260
static void cell_mark_changed(int row, int col)
238
static void cell_mark_changed(int row, int col)
261
{
239
{
262
    if (fb_pending.n != 0) {
240
    if (fb_pending.cnt != 0) {
263
        if (row != fb_pending.row ||
241
        if ((row != fb_pending.row)
264
            col != fb_pending.col + fb_pending.n) {
242
            || (col != fb_pending.col + fb_pending.cnt)) {
265
            fb_pending_flush();
243
            fb_pending_flush();
266
        }
244
        }
267
    }
245
    }
268
 
246
   
269
    if (fb_pending.n == 0) {
247
    if (fb_pending.cnt == 0) {
270
        fb_pending.row = row;
248
        fb_pending.row = row;
271
        fb_pending.col = col;
249
        fb_pending.col = col;
272
    }
250
    }
273
 
251
   
274
    ++fb_pending.n;
252
    fb_pending.cnt++;
275
}
253
}
276
 
254
 
277
 
-
 
278
/** Print a character to the active VC with buffering. */
255
/** Print a character to the active VC with buffering. */
279
static void fb_putchar(wchar_t c, int row, int col)
256
static void fb_putchar(wchar_t c, int row, int col)
280
{
257
{
281
    async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
258
    async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
282
}
259
}
Line 338... Line 315...
338
 
315
 
339
/** Switch to new console */
316
/** Switch to new console */
340
static void change_console(int newcons)
317
static void change_console(int newcons)
341
{
318
{
342
    connection_t *conn;
319
    connection_t *conn;
-
 
320
    int i;
-
 
321
    int j;
343
    int i, j, rc;
322
    int rc;
344
    keyfield_t *field;
323
    keyfield_t *field;
345
    attrs_t *attrs;
324
    attrs_t *attrs;
346
   
325
   
347
    if (newcons == active_console)
326
    if (newcons == active_console)
348
        return;
327
        return;
Line 406... Line 385...
406
                    field = get_field_at(&conn->screenbuffer, i, j);
385
                    field = get_field_at(&conn->screenbuffer, i, j);
407
                    if (!attrs_same(*attrs, field->attrs))
386
                    if (!attrs_same(*attrs, field->attrs))
408
                        set_attrs(&field->attrs);
387
                        set_attrs(&field->attrs);
409
                    attrs = &field->attrs;
388
                    attrs = &field->attrs;
410
                    if ((field->character == ' ') &&
389
                    if ((field->character == ' ') &&
411
                        (attrs_same(field->attrs,
-
 
412
                        conn->screenbuffer.attrs)))
390
                        (attrs_same(field->attrs, conn->screenbuffer.attrs)))
413
                        continue;
391
                        continue;
414
 
392
                   
415
                    fb_putchar(field->character, j, i);
393
                    fb_putchar(field->character, j, i);
416
                }
394
                }
417
        }
395
        }
Line 433... Line 411...
433
    kbd_event_t ev;
411
    kbd_event_t ev;
434
    connection_t *conn;
412
    connection_t *conn;
435
    int newcon;
413
    int newcon;
436
   
414
   
437
    /* Ignore parameters, the connection is alread opened */
415
    /* Ignore parameters, the connection is alread opened */
438
    while (1) {
416
    while (true) {
439
        callid = async_get_call(&call);
417
        callid = async_get_call(&call);
440
        switch (IPC_GET_METHOD(call)) {
418
        switch (IPC_GET_METHOD(call)) {
441
        case IPC_M_PHONE_HUNGUP:
419
        case IPC_M_PHONE_HUNGUP:
442
            /* TODO: Handle hangup */
420
            /* TODO: Handle hangup */
443
            return;
421
            return;
Line 458... Line 436...
458
            ev.type = IPC_GET_ARG1(call);
436
            ev.type = IPC_GET_ARG1(call);
459
            ev.key = IPC_GET_ARG2(call);
437
            ev.key = IPC_GET_ARG2(call);
460
            ev.mods = IPC_GET_ARG3(call);
438
            ev.mods = IPC_GET_ARG3(call);
461
            ev.c = IPC_GET_ARG4(call);
439
            ev.c = IPC_GET_ARG4(call);
462
           
440
           
463
            /* switch to another virtual console */
441
            /* Switch to another virtual console */
464
           
-
 
465
            conn = &connections[active_console];
442
            conn = &connections[active_console];
466
 
443
           
467
            if ((ev.key >= KC_F1) && (ev.key < KC_F1 +
444
            if ((ev.key >= KC_F1) && (ev.key < KC_F1 +
468
                CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) {
445
                CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) {
469
                if (ev.key == KC_F12)
446
                if (ev.key == KC_F12)
Line 471... Line 448...
471
                else
448
                else
472
                    change_console(ev.key - KC_F1);
449
                    change_console(ev.key - KC_F1);
473
                break;
450
                break;
474
            }
451
            }
475
           
452
           
476
            /* if client is awaiting key, send it */
453
            /* If client is awaiting key, send it */
477
            if (conn->keyrequest_counter > 0) {    
454
            if (conn->keyrequest_counter > 0) {
478
                conn->keyrequest_counter--;
455
                conn->keyrequest_counter--;
479
                ipc_answer_4(fifo_pop(conn->keyrequests), EOK,
456
                ipc_answer_4(fifo_pop(conn->keyrequests), EOK,
480
                    ev.type, ev.key, ev.mods, ev.c);
457
                    ev.type, ev.key, ev.mods, ev.c);
481
                break;
458
                break;
Line 550... Line 527...
550
        clrscr();
527
        clrscr();
551
   
528
   
552
    /* Accept the connection */
529
    /* Accept the connection */
553
    ipc_answer_0(iid, EOK);
530
    ipc_answer_0(iid, EOK);
554
   
531
   
555
    while (1) {
532
    while (true) {
556
        async_serialize_end();
533
        async_serialize_end();
557
        callid = async_get_call(&call);
534
        callid = async_get_call(&call);
558
        async_serialize_start();
535
        async_serialize_start();
559
       
536
       
560
        arg1 = 0;
537
        arg1 = 0;
Line 746... Line 723...
746
 
723
   
747
    /* Set up shared memory buffer. */
724
    /* Set up shared memory buffer. */
748
    ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
725
    ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
749
    interbuffer = as_get_mappable_page(ib_size);
726
    interbuffer = as_get_mappable_page(ib_size);
750
 
727
   
751
    fb_pending.n = 0;
728
    fb_pending.cnt = 0;
752
 
729
   
753
    if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
730
    if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
754
        AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) {
731
        AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) {
755
        interbuffer = NULL;
732
        interbuffer = NULL;
756
    }
733
    }