Subversion Repositories HelenOS

Rev

Rev 4164 | Rev 4168 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4164 Rev 4167
Line 60... Line 60...
60
/** Index of currently used virtual console.
60
/** Index of currently used virtual console.
61
 */
61
 */
62
int active_console = 0;
62
int active_console = 0;
63
int prev_console = 0;
63
int prev_console = 0;
64
 
64
 
65
/** Information about framebuffer
65
/** Information about framebuffer */
66
 */
-
 
67
struct {
66
struct {
68
    int phone;      /**< Framebuffer phone */
67
    int phone;      /**< Framebuffer phone */
69
    ipcarg_t rows;      /**< Framebuffer rows */
68
    ipcarg_t rows;      /**< Framebuffer rows */
70
    ipcarg_t cols;      /**< Framebuffer columns */
69
    ipcarg_t cols;      /**< Framebuffer columns */
71
} fb_info;
70
} fb_info;
Line 87... Line 86...
87
                         * consoles */
86
                         * consoles */
88
static keyfield_t *interbuffer = NULL;      /**< Pointer to memory shared
87
static keyfield_t *interbuffer = NULL;      /**< Pointer to memory shared
89
                         * with framebufer used for
88
                         * with framebufer used for
90
                         * faster virtual console
89
                         * faster virtual console
91
                         * switching */
90
                         * switching */
92
/** Size of fb_buf. */
-
 
93
#define FB_BUF_SIZE 256
-
 
94
 
-
 
95
/** Buffer for sending characters to FB driver. */
-
 
96
static char fb_buf[FB_BUF_SIZE];
-
 
97
 
91
 
98
/* Properties of fb_buf data. */
92
/** Information on row-span yet unsent to FB driver. */
-
 
93
struct {
99
static int fb_buf_row;      /**< Row where fb_buf data belong. */
94
    int row;        /**< Row where the span lies. */
100
static int fb_buf_col;      /**< Column where fb_buf data start. */
95
    int col;        /**< Leftmost column of the span. */
101
static int fb_console;      /**< VC to which fb_buf data belong. */
96
    int n;          /**< Width of the span. */
102
int fb_bi = 0;          /**< Number of valid chars in fb_buf. */
97
} fb_pending;
103
 
98
 
104
/** Size of cwrite_buf. */
99
/** Size of cwrite_buf. */
105
#define CWRITE_BUF_SIZE 256
100
#define CWRITE_BUF_SIZE 256
106
 
101
 
107
/** Buffer for receiving data via the CONSOLE_WRITE call from the client. */
102
/** Buffer for receiving data via the CONSOLE_WRITE call from the client. */
108
static char cwrite_buf[CWRITE_BUF_SIZE];
103
static char cwrite_buf[CWRITE_BUF_SIZE];
109
 
104
 
-
 
105
static void fb_putchar(char c, int row, int col);
-
 
106
 
110
 
107
 
111
/** Find unused virtual console.
108
/** Find unused virtual console.
112
 *
109
 *
113
 */
110
 */
114
static int find_free_connection(void)
111
static int find_free_connection(void)
Line 173... Line 170...
173
        set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
170
        set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
174
        break;
171
        break;
175
    }
172
    }
176
}
173
}
177
 
174
 
178
/** Write a character vector to FB driver via IPC. */
175
/** Send an area of screenbuffer to the FB driver. */
179
static ssize_t fb_write(const char *buf, size_t nbyte, int row, int col)
176
static void fb_update_area(connection_t *conn, int x, int y, int w, int h)
180
{
177
{
181
    ipcarg_t rc;
178
    int i, j;
182
    ipc_call_t answer;
179
    int rc;
183
    aid_t req;
180
    attrs_t *attrs;
184
 
-
 
185
    async_serialize_start();
181
    keyfield_t *field;
186
   
-
 
187
    req = async_send_2(fb_info.phone, FB_WRITE, row, col, &answer);
-
 
188
    rc = ipc_data_write_start(fb_info.phone, (void *) buf, nbyte);
-
 
189
 
182
 
190
    if (rc != EOK) {
183
    if (interbuffer) {
-
 
184
        for (j = 0; j < h; j++) {
191
        async_wait_for(req, NULL);
185
            for (i = 0; i < w; i++) {
192
        async_serialize_end();
186
                interbuffer[i + j * w] =
-
 
187
                    *get_field_at(&conn->screenbuffer,
193
        return (ssize_t) rc;
188
                    x + i, y + j);
-
 
189
            }
194
    }
190
        }
195
 
191
 
-
 
192
        rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
-
 
193
            x, y, w, h);
-
 
194
    } else {
-
 
195
        rc = ENOTSUP;
-
 
196
    }
-
 
197
 
-
 
198
    if (rc != 0) {
-
 
199
        attrs = &conn->screenbuffer.attrs;
-
 
200
 
-
 
201
        for (j = 0; j < h; j++) {
-
 
202
            for (i = 0; i < w; i++) {
-
 
203
                field = get_field_at(&conn->screenbuffer,
-
 
204
                    x + i, y + j);
-
 
205
                if (!attrs_same(*attrs, field->attrs))
196
    async_wait_for(req, &rc);
206
                    set_attrs(&field->attrs);
197
    async_serialize_end();
207
                attrs = &field->attrs;
198
 
208
 
199
    if (rc == EOK)
-
 
200
        return (ssize_t) IPC_GET_ARG1(answer);
209
                fb_putchar(field->character, y + j, x + i);
201
    else
210
            }
202
        return -1;
211
        }
-
 
212
    }
203
}
213
}
204
 
214
 
205
/** Flush buffered characters to FB. */
215
/** Flush pending cells to FB. */
206
static void fb_buf_flush(void)
216
static void fb_pending_flush(void)
207
{
217
{
208
    screenbuffer_t *scr;
218
    screenbuffer_t *scr;
209
    int i;
-
 
210
 
219
 
211
    scr = &(connections[fb_console].screenbuffer);
220
    scr = &(connections[active_console].screenbuffer);
212
 
221
 
213
    if (fb_bi > 0) {
222
    if (fb_pending.n > 0) {
214
        if (fb_write(fb_buf, fb_bi, fb_buf_row, fb_buf_col) < 0) {
-
 
215
            /* Try falling back to char-by-char. */
-
 
216
            for (i = 0; i < fb_bi; i++) {
-
 
217
                async_msg_3(fb_info.phone, FB_PUTCHAR, fb_buf[i],
223
        fb_update_area(&connections[active_console], fb_pending.col,
218
                    fb_buf_row, fb_buf_col + i);
224
            fb_pending.row, fb_pending.n, 1);
219
            }
-
 
220
        }
-
 
221
        fb_bi = 0;
225
        fb_pending.n = 0;
222
    }
226
    }
223
}
227
}
224
 
228
 
225
/** Print a character to the active VC with buffering. */
229
/** Mark a character cell as changed.
-
 
230
 *
-
 
231
 * This adds the cell to the pending rowspan if possible. Otherwise
-
 
232
 * the old span is flushed first.
-
 
233
 */
226
static void prtchr(char c, int row, int col)
234
static void cell_mark_changed(int row, int col)
227
{
235
{
228
    if (fb_bi >= FB_BUF_SIZE)
236
    if (fb_pending.n != 0) {
-
 
237
        if (row != fb_pending.row ||
-
 
238
            col != fb_pending.col + fb_pending.n) {
229
        fb_buf_flush();
239
            fb_pending_flush();
-
 
240
        }
-
 
241
    }
230
 
242
 
231
    if (fb_bi == 0) {
243
    if (fb_pending.n == 0) {
232
        fb_buf_row = row;
244
        fb_pending.row = row;
233
        fb_buf_col = col;
245
        fb_pending.col = col;
234
        fb_console = active_console;
-
 
235
    }
246
    }
236
 
247
 
237
    fb_buf[fb_bi++] = c;
248
    ++fb_pending.n;
238
}
249
}
239
 
250
 
-
 
251
 
240
/** Check key and process special keys.
252
/** Print a character to the active VC with buffering. */
-
 
253
static void fb_putchar(char c, int row, int col)
241
 *
254
{
-
 
255
    async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
242
 *
256
}
243
 */
257
 
-
 
258
/** Process a character from the client (TTY emulation). */
244
static void write_char(int console, char key)
259
static void write_char(int console, char key)
245
{
260
{
246
    bool flush_cursor = false;
261
    bool flush_cursor = false;
247
    screenbuffer_t *scr = &(connections[console].screenbuffer);
262
    screenbuffer_t *scr = &(connections[console].screenbuffer);
248
 
263
 
249
    switch (key) {
264
    switch (key) {
250
    case '\n':
265
    case '\n':
251
        fb_buf_flush();
266
        fb_pending_flush();
252
        flush_cursor = true;
267
        flush_cursor = true;
253
        scr->position_y++;
268
        scr->position_y++;
254
        scr->position_x = 0;
269
        scr->position_x = 0;
255
        break;
270
        break;
256
    case '\r':
271
    case '\r':
257
        fb_buf_flush();
-
 
258
        break;
272
        break;
259
    case '\t':
273
    case '\t':
260
        fb_buf_flush();
-
 
261
        scr->position_x += 8;
274
        scr->position_x += 8;
262
        scr->position_x -= scr->position_x % 8;
275
        scr->position_x -= scr->position_x % 8;
263
        break;
276
        break;
264
    case '\b':
277
    case '\b':
265
        fb_buf_flush();
-
 
266
        if (scr->position_x == 0)
278
        if (scr->position_x == 0)
267
            break;
279
            break;
268
        scr->position_x--;
280
        scr->position_x--;
269
        if (console == active_console)
281
        if (console == active_console)
270
            prtchr(' ', scr->position_y, scr->position_x);
282
            cell_mark_changed(scr->position_y, scr->position_x);
271
        screenbuffer_putchar(scr, ' ');
283
        screenbuffer_putchar(scr, ' ');
272
        break;
284
        break;
273
    default:   
285
    default:   
274
        if (console == active_console)
286
        if (console == active_console)
275
            prtchr(key, scr->position_y, scr->position_x);
287
            cell_mark_changed(scr->position_y, scr->position_x);
276
 
288
 
277
        screenbuffer_putchar(scr, key);
289
        screenbuffer_putchar(scr, key);
278
        scr->position_x++;
290
        scr->position_x++;
279
    }
291
    }
280
 
292
 
281
    if (scr->position_x >= scr->size_x) {
293
    if (scr->position_x >= scr->size_x) {
282
        fb_buf_flush();
-
 
283
        flush_cursor = true;
294
        flush_cursor = true;
284
        scr->position_y++;
295
        scr->position_y++;
285
    }
296
    }
286
   
297
   
287
    if (scr->position_y >= scr->size_y) {
298
    if (scr->position_y >= scr->size_y) {
-
 
299
        fb_pending_flush();
288
        scr->position_y = scr->size_y - 1;
300
        scr->position_y = scr->size_y - 1;
289
        screenbuffer_clear_line(scr, scr->top_line);
301
        screenbuffer_clear_line(scr, scr->top_line);
290
        scr->top_line = (scr->top_line + 1) % scr->size_y;
302
        scr->top_line = (scr->top_line + 1) % scr->size_y;
291
        if (console == active_console)
303
        if (console == active_console)
292
            async_msg_1(fb_info.phone, FB_SCROLL, 1);
304
            async_msg_1(fb_info.phone, FB_SCROLL, 1);
Line 307... Line 319...
307
    attrs_t *attrs;
319
    attrs_t *attrs;
308
   
320
   
309
    if (newcons == active_console)
321
    if (newcons == active_console)
310
        return;
322
        return;
311
 
323
 
312
    fb_buf_flush();
324
    fb_pending_flush();
313
 
325
 
314
    if (newcons == KERNEL_CONSOLE) {
326
    if (newcons == KERNEL_CONSOLE) {
315
        async_serialize_start();
327
        async_serialize_start();
316
        curs_hide_sync();
328
        curs_hide_sync();
317
        gcons_in_kernel();
329
        gcons_in_kernel();
Line 335... Line 347...
335
        conn = &connections[active_console];
347
        conn = &connections[active_console];
336
       
348
       
337
        set_attrs(&conn->screenbuffer.attrs);
349
        set_attrs(&conn->screenbuffer.attrs);
338
        curs_visibility(false);
350
        curs_visibility(false);
339
        if (interbuffer) {
351
        if (interbuffer) {
340
            for (i = 0; i < conn->screenbuffer.size_x; i++)
352
            for (j = 0; j < conn->screenbuffer.size_y; j++) {
341
                for (j = 0; j < conn->screenbuffer.size_y; j++) {
353
                for (i = 0; i < conn->screenbuffer.size_x; i++) {
342
                    unsigned int size_x;
354
                    unsigned int size_x;
343
                   
355
                   
344
                    size_x = conn->screenbuffer.size_x;
356
                    size_x = conn->screenbuffer.size_x;
345
                    interbuffer[i + j * size_x] =
357
                    interbuffer[j * size_x + i] =
346
                        *get_field_at(&conn->screenbuffer, i, j);
358
                        *get_field_at(&conn->screenbuffer, i, j);
347
                }
359
                }
-
 
360
            }
348
            /* This call can preempt, but we are already at the end */
361
            /* This call can preempt, but we are already at the end */
349
            rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA);
362
            rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
-
 
363
                0, 0, conn->screenbuffer.size_x,
-
 
364
                conn->screenbuffer.size_y);
350
        }
365
        }
351
       
366
       
352
        if ((!interbuffer) || (rc != 0)) {
367
        if ((!interbuffer) || (rc != 0)) {
353
            set_attrs(&conn->screenbuffer.attrs);
368
            set_attrs(&conn->screenbuffer.attrs);
354
            clrscr();
369
            clrscr();
Line 363... Line 378...
363
                    if ((field->character == ' ') &&
378
                    if ((field->character == ' ') &&
364
                        (attrs_same(field->attrs,
379
                        (attrs_same(field->attrs,
365
                        conn->screenbuffer.attrs)))
380
                        conn->screenbuffer.attrs)))
366
                        continue;
381
                        continue;
367
 
382
 
368
                    prtchr(field->character, j, i);
383
                    fb_putchar(field->character, j, i);
369
                }
384
                }
370
        }
385
        }
371
       
386
       
372
        curs_goto(conn->screenbuffer.position_y,
387
        curs_goto(conn->screenbuffer.position_y,
373
            conn->screenbuffer.position_x);
388
            conn->screenbuffer.position_x);
Line 476... Line 491...
476
    ipc_callid_t callid;
491
    ipc_callid_t callid;
477
    ipc_call_t call;
492
    ipc_call_t call;
478
    int consnum;
493
    int consnum;
479
    ipcarg_t arg1, arg2, arg3, arg4;
494
    ipcarg_t arg1, arg2, arg3, arg4;
480
    connection_t *conn;
495
    connection_t *conn;
-
 
496
    screenbuffer_t *scr;
481
   
497
   
482
    if ((consnum = find_free_connection()) == -1) {
498
    if ((consnum = find_free_connection()) == -1) {
483
        ipc_answer_0(iid, ELIMIT);
499
        ipc_answer_0(iid, ELIMIT);
484
        return;
500
        return;
485
    }
501
    }
Line 532... Line 548...
532
           
548
           
533
            screenbuffer_clear(&conn->screenbuffer);
549
            screenbuffer_clear(&conn->screenbuffer);
534
           
550
           
535
            break;
551
            break;
536
        case CONSOLE_GOTO:
552
        case CONSOLE_GOTO:
537
            fb_buf_flush();
-
 
538
            screenbuffer_goto(&conn->screenbuffer,
553
            screenbuffer_goto(&conn->screenbuffer,
539
                IPC_GET_ARG2(call), IPC_GET_ARG1(call));
554
                IPC_GET_ARG2(call), IPC_GET_ARG1(call));
540
            if (consnum == active_console)
555
            if (consnum == active_console)
541
                curs_goto(IPC_GET_ARG1(call),
556
                curs_goto(IPC_GET_ARG1(call),
542
                    IPC_GET_ARG2(call));
557
                    IPC_GET_ARG2(call));
Line 544... Line 559...
544
        case CONSOLE_GETSIZE:
559
        case CONSOLE_GETSIZE:
545
            arg1 = fb_info.rows;
560
            arg1 = fb_info.rows;
546
            arg2 = fb_info.cols;
561
            arg2 = fb_info.cols;
547
            break;
562
            break;
548
        case CONSOLE_FLUSH:
563
        case CONSOLE_FLUSH:
549
            fb_buf_flush();
564
            fb_pending_flush();
550
            if (consnum == active_console)
565
            if (consnum == active_console) {
551
                async_req_0_0(fb_info.phone, FB_FLUSH);
566
                async_req_0_0(fb_info.phone, FB_FLUSH);
-
 
567
 
-
 
568
                scr = &(connections[consnum].screenbuffer);
-
 
569
                curs_goto(scr->position_y, scr->position_x);
-
 
570
            }
552
            break;
571
            break;
553
        case CONSOLE_SET_STYLE:
572
        case CONSOLE_SET_STYLE:
554
            fb_buf_flush();
573
            fb_pending_flush();
555
            arg1 = IPC_GET_ARG1(call);
574
            arg1 = IPC_GET_ARG1(call);
556
            screenbuffer_set_style(&conn->screenbuffer, arg1);
575
            screenbuffer_set_style(&conn->screenbuffer, arg1);
557
            if (consnum == active_console)
576
            if (consnum == active_console)
558
                set_style(arg1);
577
                set_style(arg1);
559
            break;
578
            break;
560
        case CONSOLE_SET_COLOR:
579
        case CONSOLE_SET_COLOR:
561
            fb_buf_flush();
580
            fb_pending_flush();
562
            arg1 = IPC_GET_ARG1(call);
581
            arg1 = IPC_GET_ARG1(call);
563
            arg2 = IPC_GET_ARG2(call);
582
            arg2 = IPC_GET_ARG2(call);
564
            arg3 = IPC_GET_ARG3(call);
583
            arg3 = IPC_GET_ARG3(call);
565
            screenbuffer_set_color(&conn->screenbuffer, arg1,
584
            screenbuffer_set_color(&conn->screenbuffer, arg1,
566
                arg2, arg3);
585
                arg2, arg3);
567
            if (consnum == active_console)
586
            if (consnum == active_console)
568
                set_color(arg1, arg2, arg3);
587
                set_color(arg1, arg2, arg3);
569
            break;
588
            break;
570
        case CONSOLE_SET_RGB_COLOR:
589
        case CONSOLE_SET_RGB_COLOR:
571
            fb_buf_flush();
590
            fb_pending_flush();
572
            arg1 = IPC_GET_ARG1(call);
591
            arg1 = IPC_GET_ARG1(call);
573
            arg2 = IPC_GET_ARG2(call);
592
            arg2 = IPC_GET_ARG2(call);
574
            screenbuffer_set_rgb_color(&conn->screenbuffer, arg1,
593
            screenbuffer_set_rgb_color(&conn->screenbuffer, arg1,
575
                arg2);
594
                arg2);
576
            if (consnum == active_console)
595
            if (consnum == active_console)
577
                set_rgb_color(arg1, arg2);
596
                set_rgb_color(arg1, arg2);
578
            break;
597
            break;
579
        case CONSOLE_CURSOR_VISIBILITY:
598
        case CONSOLE_CURSOR_VISIBILITY:
580
            fb_buf_flush();
599
            fb_pending_flush();
581
            arg1 = IPC_GET_ARG1(call);
600
            arg1 = IPC_GET_ARG1(call);
582
            conn->screenbuffer.is_cursor_visible = arg1;
601
            conn->screenbuffer.is_cursor_visible = arg1;
583
            if (consnum == active_console)
602
            if (consnum == active_console)
584
                curs_visibility(arg1);
603
                curs_visibility(arg1);
585
            break;
604
            break;
Line 681... Line 700...
681
 
700
 
682
    /* Set up shared memory buffer. */
701
    /* Set up shared memory buffer. */
683
    ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
702
    ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
684
    interbuffer = as_get_mappable_page(ib_size);
703
    interbuffer = as_get_mappable_page(ib_size);
685
 
704
 
-
 
705
    fb_pending.n = 0;
-
 
706
 
686
    if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
707
    if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
687
        AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) {
708
        AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) {
688
        interbuffer = NULL;
709
        interbuffer = NULL;
689
    }
710
    }
690
 
711