Changes in kernel/genarch/src/fb/fb.c [eb2187c4:e037cf37] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/fb/fb.c
reb2187c4 re037cf37 45 45 #include <align.h> 46 46 #include <panic.h> 47 #include <mem w.h>47 #include <mem.h> 48 48 #include <config.h> 49 49 #include <bitops.h> … … 81 81 ((glyph) * (instance)->glyphbytes + (y) * (instance)->glyphscanline) 82 82 83 #define TAB_WIDTH 884 85 83 typedef void (*rgb_conv_t)(void *, uint32_t); 86 84 … … 101 99 102 100 /** Number of rows that fit on framebuffer */ 103 unsigned int screen_rows;101 unsigned int rowtrim; 104 102 105 103 unsigned int scanline; … … 123 121 /** Current backbuffer position */ 124 122 unsigned int position; 125 126 /** Partial character between writes */127 mbstate_t mbstate;128 129 unsigned int row;130 unsigned int column;131 123 } fb_instance_t; 132 124 133 static void fb_ write(outdev_t *, const char *, size_t);125 static void fb_putuchar(outdev_t *, char32_t); 134 126 static void fb_redraw(outdev_t *); 135 127 static void fb_scroll_up(outdev_t *); … … 137 129 138 130 static outdev_operations_t fbdev_ops = { 139 .write = fb_ write,131 .write = fb_putuchar, 140 132 .redraw = fb_redraw, 141 133 .scroll_up = fb_scroll_up, … … 255 247 256 248 unsigned int rel_row = row - instance->offset_row; 257 if (rel_row >= instance-> screen_rows)249 if (rel_row >= instance->rowtrim) 258 250 return; 259 251 … … 273 265 { 274 266 if ((!instance->parea.mapped) || (console_override)) { 275 for (unsigned int rel_row = 0; rel_row < instance-> screen_rows; rel_row++) {267 for (unsigned int rel_row = 0; rel_row < instance->rowtrim; rel_row++) { 276 268 unsigned int y = ROW2Y(rel_row); 277 269 unsigned int row = rel_row + instance->offset_row; … … 322 314 static void cursor_put(fb_instance_t *instance) 323 315 { 324 unsigned int col = instance-> column;325 unsigned int row = instance-> row;316 unsigned int col = instance->position % instance->cols; 317 unsigned int row = instance->position / instance->cols; 326 318 327 319 glyph_draw(instance, fb_font_glyph(U_CURSOR), col, row, true); … … 330 322 static void cursor_remove(fb_instance_t *instance) 331 323 { 332 unsigned int col = instance-> column;333 unsigned int row = instance-> row;324 unsigned int col = instance->position % instance->cols; 325 unsigned int row = instance->position / instance->cols; 334 326 335 327 glyph_draw(instance, instance->backbuf[BB_POS(instance, col, row)], … … 381 373 static void fb_redraw_internal(fb_instance_t *instance) 382 374 { 383 for (unsigned int rel_row = 0; rel_row < instance-> screen_rows; rel_row++) {375 for (unsigned int rel_row = 0; rel_row < instance->rowtrim; rel_row++) { 384 376 unsigned int y = ROW2Y(rel_row); 385 377 unsigned int row = rel_row + instance->offset_row; … … 412 404 } 413 405 414 if (ROW2Y(instance-> screen_rows) < instance->yres) {406 if (ROW2Y(instance->rowtrim) < instance->yres) { 415 407 unsigned int y; 416 408 417 for (y = ROW2Y(instance-> screen_rows); y < instance->yres; y++)409 for (y = ROW2Y(instance->rowtrim); y < instance->yres; y++) 418 410 memcpy(&instance->addr[FB_POS(instance, 0, y)], 419 411 instance->bgscan, instance->bgscanbytes); … … 421 413 } 422 414 423 static void _advance_row(fb_instance_t *instance)424 {425 instance->column = 0;426 instance->row++;427 }428 429 static void _advance_column(fb_instance_t *instance)430 {431 instance->column++;432 if (instance->column == instance->cols)433 _advance_row(instance);434 }435 436 415 /** Print character to screen 437 416 * … … 439 418 * 440 419 */ 441 static void _putuchar(fb_instance_t *instance, char32_t ch) 442 { 420 static void fb_putuchar(outdev_t *dev, char32_t ch) 421 { 422 fb_instance_t *instance = (fb_instance_t *) dev->data; 423 spinlock_lock(&instance->lock); 424 443 425 switch (ch) { 444 426 case '\n': 445 _advance_row(instance); 427 cursor_remove(instance); 428 instance->position += instance->cols; 429 instance->position -= instance->position % instance->cols; 446 430 break; 447 431 case '\r': 448 instance->column = 0; 432 cursor_remove(instance); 433 instance->position -= instance->position % instance->cols; 449 434 break; 450 435 case '\b': 451 if (instance->column > 0) 452 instance->column--; 436 cursor_remove(instance); 437 if (instance->position % instance->cols) 438 instance->position--; 453 439 break; 454 440 case '\t': 441 cursor_remove(instance); 455 442 do { 456 443 glyph_draw(instance, fb_font_glyph(' '), 457 instance->column, 458 instance->row, false); 459 _advance_column(instance); 460 } while (instance->column % TAB_WIDTH != 0); 444 instance->position % instance->cols, 445 instance->position / instance->cols, false); 446 instance->position++; 447 } while (((instance->position % instance->cols) % 8 != 0) && 448 (instance->position < instance->cols * instance->rows)); 461 449 break; 462 450 default: 463 451 glyph_draw(instance, fb_font_glyph(ch), 464 instance-> column,465 instance-> row, false);466 _advance_column(instance);467 } 468 469 while (instance->row >=instance->rows) {470 instance-> row--;452 instance->position % instance->cols, 453 instance->position / instance->cols, false); 454 instance->position++; 455 } 456 457 if (instance->position >= instance->cols * instance->rows) { 458 instance->position -= instance->cols; 471 459 screen_scroll(instance); 472 460 } 473 }474 475 static void fb_write(outdev_t *dev, const char *s, size_t n)476 {477 fb_instance_t *instance = (fb_instance_t *) dev->data;478 479 spinlock_lock(&instance->lock);480 cursor_remove(instance);481 482 size_t offset = 0;483 char32_t ch;484 485 while ((ch = str_decode_r(s, &offset, n, U_SPECIAL, &instance->mbstate)))486 _putuchar(instance, ch);487 461 488 462 cursor_put(instance); 463 489 464 spinlock_unlock(&instance->lock); 490 465 } … … 498 473 spinlock_lock(&instance->lock); 499 474 500 if (instance->offset_row >= instance-> screen_rows/ 2)501 instance->offset_row -= instance-> screen_rows/ 2;475 if (instance->offset_row >= instance->rowtrim / 2) 476 instance->offset_row -= instance->rowtrim / 2; 502 477 else 503 478 instance->offset_row = 0; … … 517 492 spinlock_lock(&instance->lock); 518 493 519 if (instance->offset_row + instance-> screen_rows/ 2 <=520 instance->rows - instance-> screen_rows)521 instance->offset_row += instance-> screen_rows/ 2;494 if (instance->offset_row + instance->rowtrim / 2 <= 495 instance->rows - instance->rowtrim) 496 instance->offset_row += instance->rowtrim / 2; 522 497 else 523 instance->offset_row = instance->rows - instance-> screen_rows;498 instance->offset_row = instance->rows - instance->rowtrim; 524 499 525 500 fb_redraw_internal(instance); … … 640 615 instance->scanline = props->scan; 641 616 642 instance-> screen_rows= Y2ROW(instance->yres);617 instance->rowtrim = Y2ROW(instance->yres); 643 618 644 619 instance->cols = X2COL(instance->xres); 645 instance->rows = FB_PAGES * instance-> screen_rows;646 647 instance->start_row = instance->rows - instance-> screen_rows;620 instance->rows = FB_PAGES * instance->rowtrim; 621 622 instance->start_row = instance->rows - instance->rowtrim; 648 623 instance->offset_row = instance->start_row; 649 instance->row = instance->start_row; 650 instance->column = 0; 624 instance->position = instance->start_row * instance->cols; 651 625 652 626 instance->glyphscanline = FONT_WIDTH * instance->pixelbytes; … … 659 633 660 634 instance->addr = (uint8_t *) km_map((uintptr_t) props->addr, fbsize, 661 KM_NATURAL_ALIGNMENT, PAGE_WRITE | PAGE_ WRITE_COMBINE);635 KM_NATURAL_ALIGNMENT, PAGE_WRITE | PAGE_NOT_CACHEABLE); 662 636 if (!instance->addr) { 663 637 LOG("Unable to map framebuffer.");
Note:
See TracChangeset
for help on using the changeset viewer.