Rev 3709 | Rev 3733 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3709 | Rev 3710 | ||
|---|---|---|---|
| Line 32... | Line 32... | ||
| 32 | */ |
32 | */ |
| 33 | /** @file |
33 | /** @file |
| 34 | */ |
34 | */ |
| 35 | 35 | ||
| 36 | #include <genarch/fb/font-8x16.h> |
36 | #include <genarch/fb/font-8x16.h> |
| - | 37 | #include <genarch/fb/logo-196x66.h> |
|
| 37 | #include <genarch/fb/visuals.h> |
38 | #include <genarch/fb/visuals.h> |
| 38 | #include <genarch/fb/fb.h> |
39 | #include <genarch/fb/fb.h> |
| 39 | #include <console/chardev.h> |
40 | #include <console/chardev.h> |
| 40 | #include <console/console.h> |
41 | #include <console/console.h> |
| 41 | #include <sysinfo/sysinfo.h> |
42 | #include <sysinfo/sysinfo.h> |
| Line 55... | Line 56... | ||
| 55 | static parea_t fb_parea; |
56 | static parea_t fb_parea; |
| 56 | 57 | ||
| 57 | static uint8_t *fb_addr; |
58 | static uint8_t *fb_addr; |
| 58 | static uint8_t *backbuf; |
59 | static uint8_t *backbuf; |
| 59 | static uint8_t *glyphs; |
60 | static uint8_t *glyphs; |
| 60 | - | ||
| 61 | static void *bgpixel; |
61 | static uint8_t *bgscan; |
| 62 | 62 | ||
| 63 | static unsigned int xres; |
63 | static unsigned int xres; |
| 64 | static unsigned int yres; |
64 | static unsigned int yres; |
| 65 | 65 | ||
| - | 66 | static unsigned int ylogo; |
|
| - | 67 | static unsigned int ytrim; |
|
| - | 68 | static unsigned int rowtrim; |
|
| - | 69 | ||
| 66 | static unsigned int scanline; |
70 | static unsigned int scanline; |
| 67 | static unsigned int glyphscanline; |
71 | static unsigned int glyphscanline; |
| 68 | 72 | ||
| 69 | static unsigned int pixelbytes; |
73 | static unsigned int pixelbytes; |
| 70 | static unsigned int glyphbytes; |
74 | static unsigned int glyphbytes; |
| - | 75 | static unsigned int bgscanbytes; |
|
| 71 | 76 | ||
| 72 | static unsigned int cols; |
77 | static unsigned int cols; |
| 73 | static unsigned int rows; |
78 | static unsigned int rows; |
| 74 | static unsigned int position = 0; |
79 | static unsigned int position = 0; |
| 75 | 80 | ||
| Line 119... | Line 124... | ||
| 119 | * |
124 | * |
| 120 | */ |
125 | */ |
| 121 | static void rgb_888(void *dst, uint32_t rgb) |
126 | static void rgb_888(void *dst, uint32_t rgb) |
| 122 | { |
127 | { |
| 123 | #if defined(FB_INVERT_ENDIAN) |
128 | #if defined(FB_INVERT_ENDIAN) |
| 124 | *((uint32_t *) dst) |
129 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
| 125 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8) |
130 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
| 126 | | (*((uint32_t *) dst) & 0xff0000); |
131 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
| 127 | #else |
132 | #else |
| 128 | *((uint32_t *) dst) |
133 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
| - | 134 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
|
| 129 | = (rgb & 0xffffff) | (*((uint32_t *) dst) & 0xff0000); |
135 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
| 130 | #endif |
136 | #endif |
| 131 | } |
137 | } |
| 132 | 138 | ||
| 133 | 139 | ||
| 134 | /** RGB 5:5:5 conversion |
140 | /** RGB 5:5:5 conversion |
| Line 173... | Line 179... | ||
| 173 | *((uint8_t *) dst) |
179 | *((uint8_t *) dst) |
| 174 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
180 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
| 175 | } |
181 | } |
| 176 | 182 | ||
| 177 | 183 | ||
| - | 184 | /** Hide logo and refresh screen |
|
| - | 185 | * |
|
| - | 186 | */ |
|
| - | 187 | static void logo_hide(void) |
|
| - | 188 | { |
|
| - | 189 | ylogo = 0; |
|
| - | 190 | ytrim = yres; |
|
| - | 191 | rowtrim = rows; |
|
| - | 192 | fb_redraw(); |
|
| - | 193 | } |
|
| - | 194 | ||
| - | 195 | ||
| 178 | /** Draw character at given position |
196 | /** Draw character at given position |
| 179 | * |
197 | * |
| 180 | */ |
198 | */ |
| 181 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
199 | static void glyph_draw(uint8_t glyph, unsigned int col, unsigned int row) |
| 182 | { |
200 | { |
| 183 | unsigned int x = COL2X(col); |
201 | unsigned int x = COL2X(col); |
| 184 | unsigned int y = ROW2Y(row); |
202 | unsigned int y = ROW2Y(row); |
| 185 | unsigned int yd; |
203 | unsigned int yd; |
| 186 | 204 | ||
| - | 205 | if (y >= ytrim) |
|
| - | 206 | logo_hide(); |
|
| - | 207 | ||
| 187 | backbuf[BB_POS(col, row)] = glyph; |
208 | backbuf[BB_POS(col, row)] = glyph; |
| 188 | 209 | ||
| 189 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
210 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
| 190 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
211 | memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)], |
| 191 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
212 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
| 192 | } |
213 | } |
| 193 | 214 | ||
| 194 | 215 | ||
| 195 | /** Scroll screen down by one row |
216 | /** Scroll screen down by one row |
| 196 | * |
217 | * |
| 197 | * |
218 | * |
| 198 | */ |
219 | */ |
| 199 | static void scroll_screen(void) |
220 | static void screen_scroll(void) |
| 200 | { |
221 | { |
| - | 222 | if (ylogo > 0) |
|
| - | 223 | logo_hide(); |
|
| - | 224 | ||
| 201 | unsigned int row; |
225 | unsigned int row; |
| 202 | 226 | ||
| 203 | for (row = 0; row < rows; row++) { |
227 | for (row = 0; row < rows; row++) { |
| 204 | unsigned int y = ROW2Y(row); |
228 | unsigned int y = ROW2Y(row); |
| 205 | unsigned int yd; |
229 | unsigned int yd; |
| Line 230... | Line 254... | ||
| 230 | } |
254 | } |
| 231 | 255 | ||
| 232 | 256 | ||
| 233 | static void cursor_put(void) |
257 | static void cursor_put(void) |
| 234 | { |
258 | { |
| 235 | draw_glyph(CURSOR, position % cols, position / cols); |
259 | glyph_draw(CURSOR, position % cols, position / cols); |
| 236 | } |
260 | } |
| 237 | 261 | ||
| 238 | 262 | ||
| 239 | static void cursor_remove(void) |
263 | static void cursor_remove(void) |
| 240 | { |
264 | { |
| 241 | draw_glyph(0, position % cols, position / cols); |
265 | glyph_draw(0, position % cols, position / cols); |
| 242 | } |
266 | } |
| 243 | 267 | ||
| 244 | 268 | ||
| 245 | /** Print character to screen |
269 | /** Print character to screen |
| 246 | * |
270 | * |
| Line 267... | Line 291... | ||
| 267 | position--; |
291 | position--; |
| 268 | break; |
292 | break; |
| 269 | case '\t': |
293 | case '\t': |
| 270 | cursor_remove(); |
294 | cursor_remove(); |
| 271 | do { |
295 | do { |
| 272 | draw_glyph((uint8_t) ' ', position % cols, position / cols); |
296 | glyph_draw((uint8_t) ' ', position % cols, position / cols); |
| 273 | position++; |
297 | position++; |
| 274 | } while ((position % 8) && (position < cols * rows)); |
298 | } while ((position % 8) && (position < cols * rows)); |
| 275 | break; |
299 | break; |
| 276 | default: |
300 | default: |
| 277 | draw_glyph((uint8_t) ch, position % cols, position / cols); |
301 | glyph_draw((uint8_t) ch, position % cols, position / cols); |
| 278 | position++; |
302 | position++; |
| 279 | } |
303 | } |
| 280 | 304 | ||
| 281 | if (position >= cols * rows) { |
305 | if (position >= cols * rows) { |
| 282 | position -= cols; |
306 | position -= cols; |
| 283 | scroll_screen(); |
307 | screen_scroll(); |
| 284 | } |
308 | } |
| 285 | 309 | ||
| 286 | cursor_put(); |
310 | cursor_put(); |
| 287 | 311 | ||
| 288 | spinlock_unlock(&fb_lock); |
312 | spinlock_unlock(&fb_lock); |
| Line 298... | Line 322... | ||
| 298 | * |
322 | * |
| 299 | * Convert glyphs from device independent font |
323 | * Convert glyphs from device independent font |
| 300 | * description to current visual representation. |
324 | * description to current visual representation. |
| 301 | * |
325 | * |
| 302 | */ |
326 | */ |
| 303 | static void render_glyphs(void) |
327 | static void glyphs_render(void) |
| 304 | { |
328 | { |
| - | 329 | /* Prerender glyphs */ |
|
| 305 | unsigned int glyph; |
330 | unsigned int glyph; |
| 306 | 331 | ||
| 307 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
332 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
| 308 | unsigned int y; |
333 | unsigned int y; |
| 309 | 334 | ||
| 310 | for (y = 0; y < FONT_SCANLINES; y++) { |
335 | for (y = 0; y < FONT_SCANLINES; y++) { |
| 311 | unsigned int x; |
336 | unsigned int x; |
| 312 | 337 | ||
| 313 | for (x = 0; x < FONT_WIDTH; x++) |
338 | for (x = 0; x < FONT_WIDTH; x++) |
| 314 | rgb_conv(&glyphs[GLYPH_POS(glyph, y) + x * pixelbytes], |
339 | rgb_conv(&glyphs[GLYPH_POS(glyph, y) + x * pixelbytes], |
| 315 | (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) ? FG_COLOR : BG_COLOR); |
340 | (fb_font[ROW2Y(glyph) + y] & (1 << (7 - x))) ? FG_COLOR : BG_COLOR); |
| 316 | } |
341 | } |
| 317 | } |
342 | } |
| 318 | 343 | ||
| - | 344 | /* Prerender background scanline */ |
|
| - | 345 | unsigned int x; |
|
| - | 346 | ||
| - | 347 | for (x = 0; x < xres; x++) |
|
| 319 | rgb_conv(bgpixel, BG_COLOR); |
348 | rgb_conv(&bgscan[x * pixelbytes], BG_COLOR); |
| 320 | } |
349 | } |
| 321 | 350 | ||
| 322 | 351 | ||
| 323 | /** Refresh the screen |
352 | /** Refresh the screen |
| 324 | * |
353 | * |
| 325 | */ |
354 | */ |
| 326 | void fb_redraw(void) |
355 | void fb_redraw(void) |
| 327 | { |
356 | { |
| - | 357 | if (ylogo > 0) { |
|
| - | 358 | unsigned int y; |
|
| - | 359 | ||
| - | 360 | for (y = 0; y < LOGO_HEIGHT; y++) { |
|
| - | 361 | unsigned int x; |
|
| - | 362 | ||
| - | 363 | for (x = 0; x < xres; x++) |
|
| - | 364 | rgb_conv(&fb_addr[FB_POS(x, y)], |
|
| - | 365 | (x < LOGO_WIDTH) ? fb_logo[y * LOGO_WIDTH + x] : LOGO_COLOR); |
|
| - | 366 | } |
|
| - | 367 | } |
|
| - | 368 | ||
| 328 | unsigned int row; |
369 | unsigned int row; |
| 329 | 370 | ||
| 330 | for (row = 0; row < rows; row++) { |
371 | for (row = 0; row < rowtrim; row++) { |
| 331 | unsigned int y = ROW2Y(row); |
372 | unsigned int y = ylogo + ROW2Y(row); |
| 332 | unsigned int yd; |
373 | unsigned int yd; |
| 333 | 374 | ||
| 334 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
375 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
| 335 | unsigned int x; |
376 | unsigned int x; |
| 336 | unsigned int col; |
377 | unsigned int col; |
| Line 342... | Line 383... | ||
| 342 | } |
383 | } |
| 343 | } |
384 | } |
| 344 | 385 | ||
| 345 | if (COL2X(cols) < xres) { |
386 | if (COL2X(cols) < xres) { |
| 346 | unsigned int y; |
387 | unsigned int y; |
| - | 388 | unsigned int size = (xres - COL2X(cols)) * pixelbytes; |
|
| 347 | 389 | ||
| 348 | for (y = 0; y < yres; y++) { |
390 | for (y = ylogo; y < yres; y++) |
| 349 | unsigned int x; |
- | |
| 350 | - | ||
| 351 | for (x = COL2X(cols); x < xres; x++) |
- | |
| 352 | memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes); |
391 | memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size); |
| 353 | } |
- | |
| 354 | } |
392 | } |
| 355 | 393 | ||
| 356 | if (ROW2Y(rows) < yres) { |
394 | if (ROW2Y(rowtrim) < yres) { |
| 357 | unsigned int y; |
395 | unsigned int y; |
| 358 | 396 | ||
| 359 | for (y = ROW2Y(rows); y < yres; y++) { |
397 | for (y = ROW2Y(rowtrim); y < yres; y++) |
| 360 | unsigned int x; |
- | |
| 361 | - | ||
| 362 | for (x = 0; x < xres; x++) |
- | |
| 363 | memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes); |
398 | memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes); |
| 364 | } |
- | |
| 365 | } |
399 | } |
| 366 | } |
400 | } |
| 367 | 401 | ||
| 368 | 402 | ||
| 369 | /** Initialize framebuffer as a chardev output device |
403 | /** Initialize framebuffer as a chardev output device |
| Line 412... | Line 446... | ||
| 412 | 446 | ||
| 413 | xres = props->x; |
447 | xres = props->x; |
| 414 | yres = props->y; |
448 | yres = props->y; |
| 415 | scanline = props->scan; |
449 | scanline = props->scan; |
| 416 | 450 | ||
| 417 | cols = xres / FONT_WIDTH; |
451 | cols = X2COL(xres); |
| - | 452 | rows = Y2ROW(yres); |
|
| - | 453 | ||
| - | 454 | if (yres > ylogo) { |
|
| - | 455 | ylogo = LOGO_HEIGHT; |
|
| - | 456 | rowtrim = rows - Y2ROW(ylogo); |
|
| 418 | rows = yres / FONT_SCANLINES; |
457 | if (ylogo % FONT_SCANLINES > 0) |
| - | 458 | rowtrim--; |
|
| - | 459 | ytrim = ROW2Y(rowtrim); |
|
| - | 460 | } else { |
|
| - | 461 | ylogo = 0; |
|
| - | 462 | ytrim = yres; |
|
| - | 463 | rowtrim = rows; |
|
| - | 464 | } |
|
| 419 | 465 | ||
| 420 | glyphscanline = FONT_WIDTH * pixelbytes; |
466 | glyphscanline = FONT_WIDTH * pixelbytes; |
| 421 | glyphbytes = glyphscanline * FONT_SCANLINES; |
467 | glyphbytes = ROW2Y(glyphscanline); |
| - | 468 | bgscanbytes = xres * pixelbytes; |
|
| 422 | 469 | ||
| 423 | unsigned int fbsize = scanline * yres; |
470 | unsigned int fbsize = scanline * yres; |
| 424 | unsigned int bbsize = cols * rows; |
471 | unsigned int bbsize = cols * rows; |
| 425 | unsigned int glyphsize = FONT_GLYPHS * glyphbytes; |
472 | unsigned int glyphsize = FONT_GLYPHS * glyphbytes; |
| 426 | 473 | ||
| Line 430... | Line 477... | ||
| 430 | 477 | ||
| 431 | glyphs = (uint8_t *) malloc(glyphsize, 0); |
478 | glyphs = (uint8_t *) malloc(glyphsize, 0); |
| 432 | if (!glyphs) |
479 | if (!glyphs) |
| 433 | panic("Unable to allocate glyphs.\n"); |
480 | panic("Unable to allocate glyphs.\n"); |
| 434 | 481 | ||
| 435 | bgpixel = malloc(pixelbytes, 0); |
482 | bgscan = malloc(bgscanbytes, 0); |
| 436 | if (!bgpixel) |
483 | if (!bgscan) |
| 437 | panic("Unable to allocate background pixel.\n"); |
484 | panic("Unable to allocate background pixel.\n"); |
| 438 | 485 | ||
| 439 | memsetb(backbuf, bbsize, 0); |
486 | memsetb(backbuf, bbsize, 0); |
| 440 | memsetb(glyphs, glyphsize, 0); |
- | |
| 441 | memsetb(bgpixel, pixelbytes, 0); |
- | |
| 442 | 487 | ||
| 443 | render_glyphs(); |
488 | glyphs_render(); |
| 444 | 489 | ||
| 445 | fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
490 | fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
| 446 | 491 | ||
| 447 | fb_parea.pbase = (uintptr_t) props->addr + props->offset; |
492 | fb_parea.pbase = (uintptr_t) props->addr + props->offset; |
| 448 | fb_parea.vbase = (uintptr_t) fb_addr; |
493 | fb_parea.vbase = (uintptr_t) fb_addr; |