Rev 4581 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4581 | Rev 4718 | ||
---|---|---|---|
Line 54... | Line 54... | ||
54 | #include <io/color.h> |
54 | #include <io/color.h> |
55 | #include <io/style.h> |
55 | #include <io/style.h> |
56 | #include <async.h> |
56 | #include <async.h> |
57 | #include <fibril.h> |
57 | #include <fibril.h> |
58 | #include <bool.h> |
58 | #include <bool.h> |
- | 59 | #include <stdio.h> |
|
- | 60 | #include <byteorder.h> |
|
59 | 61 | ||
60 | #include "font-8x16.h" |
62 | #include "font-8x16.h" |
61 | #include "fb.h" |
63 | #include "fb.h" |
62 | #include "main.h" |
64 | #include "main.h" |
63 | #include "../console/screenbuffer.h" |
65 | #include "../console/screenbuffer.h" |
Line 209... | Line 211... | ||
209 | 211 | ||
210 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
212 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
211 | unsigned int row); |
213 | unsigned int row); |
212 | 214 | ||
213 | 215 | ||
214 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
216 | #define RED(x, bits) (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1)) |
215 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
217 | #define GREEN(x, bits) (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1)) |
216 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
218 | #define BLUE(x, bits) (((x) >> (8 - (bits))) & ((1 << (bits)) - 1)) |
217 | 219 | ||
218 | #define COL2X(col) ((col) * FONT_WIDTH) |
220 | #define COL2X(col) ((col) * FONT_WIDTH) |
219 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
221 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
220 | 222 | ||
221 | #define X2COL(x) ((x) / FONT_WIDTH) |
223 | #define X2COL(x) ((x) / FONT_WIDTH) |
Line 223... | Line 225... | ||
223 | 225 | ||
224 | #define FB_POS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
226 | #define FB_POS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
225 | #define BB_POS(vport, col, row) ((row) * vport->cols + (col)) |
227 | #define BB_POS(vport, col, row) ((row) * vport->cols + (col)) |
226 | #define GLYPH_POS(glyph, y, cursor) (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline) |
228 | #define GLYPH_POS(glyph, y, cursor) (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline) |
227 | 229 | ||
228 | 230 | /* |
|
229 | /** ARGB 8:8:8:8 conversion |
231 | * RGB conversion and mask functions. |
230 | * |
232 | * |
- | 233 | * These functions write an RGB value to some memory in some predefined format. |
|
- | 234 | * The naming convention corresponds to the format created by these functions. |
|
- | 235 | * The functions use the so called network order (i.e. big endian) with respect |
|
- | 236 | * to their names. |
|
231 | */ |
237 | */ |
- | 238 | ||
232 | static void rgb_0888(void *dst, uint32_t rgb) |
239 | static void rgb_0888(void *dst, uint32_t rgb) |
233 | { |
240 | { |
234 | *((uint32_t *) dst) = rgb & 0x00ffffff; |
241 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | |
- | 242 | (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8))); |
|
- | 243 | } |
|
- | 244 | ||
- | 245 | static void bgr_0888(void *dst, uint32_t rgb) |
|
- | 246 | { |
|
- | 247 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | |
|
- | 248 | (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8))); |
|
235 | } |
249 | } |
236 | 250 | ||
237 | static void mask_0888(void *dst, bool mask) |
251 | static void mask_0888(void *dst, bool mask) |
238 | { |
252 | { |
239 | *((uint32_t *) dst) = (mask ? 0x00ffffff : 0); |
253 | bgr_0888(dst, mask ? 0xffffff : 0); |
240 | } |
254 | } |
241 | 255 | ||
- | 256 | static void rgb_8880(void *dst, uint32_t rgb) |
|
- | 257 | { |
|
- | 258 | *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) | |
|
- | 259 | (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0); |
|
- | 260 | } |
|
242 | 261 | ||
243 | /** ABGR 8:8:8:8 conversion |
- | |
244 | * |
- | |
245 | */ |
- | |
246 | static void bgr_0888(void *dst, uint32_t rgb) |
262 | static void bgr_8880(void *dst, uint32_t rgb) |
247 | { |
263 | { |
248 | *((uint32_t *) dst) |
264 | *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) | |
249 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
265 | (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0); |
250 | } |
266 | } |
251 | 267 | ||
- | 268 | static void mask_8880(void *dst, bool mask) |
|
- | 269 | { |
|
- | 270 | bgr_8880(dst, mask ? 0xffffff : 0); |
|
- | 271 | } |
|
252 | 272 | ||
253 | /** RGB 8:8:8 conversion |
- | |
254 | * |
- | |
255 | */ |
- | |
256 | static void rgb_888(void *dst, uint32_t rgb) |
273 | static void rgb_888(void *dst, uint32_t rgb) |
257 | { |
274 | { |
- | 275 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
|
- | 276 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
|
- | 277 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
|
- | 278 | } |
|
- | 279 | ||
- | 280 | static void bgr_888(void *dst, uint32_t rgb) |
|
- | 281 | { |
|
258 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
282 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
259 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
283 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
260 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
284 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
261 | } |
285 | } |
262 | 286 | ||
263 | static void mask_888(void *dst, bool mask) |
287 | static void mask_888(void *dst, bool mask) |
264 | { |
288 | { |
265 | if (mask) { |
- | |
266 | ((uint8_t *) dst)[0] = 0xff; |
- | |
267 | ((uint8_t *) dst)[1] = 0xff; |
- | |
268 | ((uint8_t *) dst)[2] = 0xff; |
- | |
269 | } else { |
- | |
270 | ((uint8_t *) dst)[0] = 0; |
- | |
271 | ((uint8_t *) dst)[1] = 0; |
- | |
272 | ((uint8_t *) dst)[2] = 0; |
289 | bgr_888(dst, mask ? 0xffffff : 0); |
273 | } |
- | |
274 | } |
290 | } |
275 | 291 | ||
276 | - | ||
277 | /** BGR 8:8:8 conversion |
- | |
278 | * |
- | |
279 | */ |
- | |
280 | static void bgr_888(void *dst, uint32_t rgb) |
292 | static void rgb_555_be(void *dst, uint32_t rgb) |
281 | { |
293 | { |
282 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
294 | *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 10 | |
283 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
- | |
284 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
295 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5)); |
285 | } |
296 | } |
286 | 297 | ||
287 | - | ||
288 | /** RGB 5:5:5 conversion |
- | |
289 | * |
- | |
290 | */ |
- | |
291 | static void rgb_555(void *dst, uint32_t rgb) |
298 | static void rgb_555_le(void *dst, uint32_t rgb) |
292 | { |
299 | { |
293 | *((uint16_t *) dst) |
300 | *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 10 | |
294 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
301 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5)); |
295 | } |
302 | } |
296 | 303 | ||
297 | static void mask_555(void *dst, bool mask) |
304 | static void rgb_565_be(void *dst, uint32_t rgb) |
298 | { |
305 | { |
299 | *((uint16_t *) dst) = (mask ? 0x7fff : 0); |
306 | *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 11 | |
- | 307 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5)); |
|
300 | } |
308 | } |
301 | 309 | ||
- | 310 | static void rgb_565_le(void *dst, uint32_t rgb) |
|
- | 311 | { |
|
- | 312 | *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 11 | |
|
- | 313 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5)); |
|
- | 314 | } |
|
302 | 315 | ||
303 | /** RGB 5:6:5 conversion |
- | |
304 | * |
- | |
305 | */ |
- | |
306 | static void rgb_565(void *dst, uint32_t rgb) |
316 | static void mask_555(void *dst, bool mask) |
307 | { |
317 | { |
308 | *((uint16_t *) dst) |
- | |
309 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
318 | rgb_555_be(dst, mask ? 0xffffff : 0); |
310 | } |
319 | } |
311 | 320 | ||
312 | static void mask_565(void *dst, bool mask) |
321 | static void mask_565(void *dst, bool mask) |
313 | { |
322 | { |
314 | *((uint16_t *) dst) = (mask ? 0xffff : 0); |
323 | rgb_565_be(dst, mask ? 0xffffff : 0); |
315 | } |
324 | } |
316 | 325 | ||
317 | - | ||
318 | /** RGB 3:2:3 |
- | |
319 | * |
- | |
320 | */ |
- | |
321 | static void rgb_323(void *dst, uint32_t rgb) |
326 | static void bgr_323(void *dst, uint32_t rgb) |
322 | { |
327 | { |
323 | *((uint8_t *) dst) |
328 | *((uint8_t *) dst) |
324 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
329 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
325 | } |
330 | } |
326 | 331 | ||
327 | static void mask_323(void *dst, bool mask) |
332 | static void mask_323(void *dst, bool mask) |
328 | { |
333 | { |
329 | *((uint8_t *) dst) = (mask ? 0xff : 0); |
334 | bgr_323(dst, mask ? 0x0 : ~0x0); |
330 | } |
335 | } |
331 | 336 | ||
332 | /** Draw a filled rectangle. |
337 | /** Draw a filled rectangle. |
333 | * |
338 | * |
334 | * @note Need real implementation that does not access VRAM twice. |
339 | * @note Need real implementation that does not access VRAM twice. |
Line 618... | Line 623... | ||
618 | * |
623 | * |
619 | */ |
624 | */ |
620 | static bool screen_init(void *addr, unsigned int xres, unsigned int yres, |
625 | static bool screen_init(void *addr, unsigned int xres, unsigned int yres, |
621 | unsigned int scan, unsigned int visual) |
626 | unsigned int scan, unsigned int visual) |
622 | { |
627 | { |
623 | - | ||
624 | - | ||
625 | switch (visual) { |
628 | switch (visual) { |
626 | case VISUAL_INDIRECT_8: |
629 | case VISUAL_INDIRECT_8: |
627 | screen.rgb_conv = rgb_323; |
630 | screen.rgb_conv = bgr_323; |
628 | screen.mask_conv = mask_323; |
631 | screen.mask_conv = mask_323; |
629 | screen.pixelbytes = 1; |
632 | screen.pixelbytes = 1; |
630 | break; |
633 | break; |
631 | case VISUAL_RGB_5_5_5: |
634 | case VISUAL_RGB_5_5_5_LE: |
- | 635 | screen.rgb_conv = rgb_555_le; |
|
- | 636 | screen.mask_conv = mask_555; |
|
- | 637 | screen.pixelbytes = 2; |
|
- | 638 | break; |
|
- | 639 | case VISUAL_RGB_5_5_5_BE: |
|
632 | screen.rgb_conv = rgb_555; |
640 | screen.rgb_conv = rgb_555_be; |
633 | screen.mask_conv = mask_555; |
641 | screen.mask_conv = mask_555; |
634 | screen.pixelbytes = 2; |
642 | screen.pixelbytes = 2; |
635 | break; |
643 | break; |
636 | case VISUAL_RGB_5_6_5: |
644 | case VISUAL_RGB_5_6_5_LE: |
- | 645 | screen.rgb_conv = rgb_565_le; |
|
- | 646 | screen.mask_conv = mask_565; |
|
- | 647 | screen.pixelbytes = 2; |
|
- | 648 | break; |
|
- | 649 | case VISUAL_RGB_5_6_5_BE: |
|
637 | screen.rgb_conv = rgb_565; |
650 | screen.rgb_conv = rgb_565_be; |
638 | screen.mask_conv = mask_565; |
651 | screen.mask_conv = mask_565; |
639 | screen.pixelbytes = 2; |
652 | screen.pixelbytes = 2; |
640 | break; |
653 | break; |
641 | case VISUAL_RGB_8_8_8: |
654 | case VISUAL_RGB_8_8_8: |
642 | screen.rgb_conv = rgb_888; |
655 | screen.rgb_conv = rgb_888; |
Line 647... | Line 660... | ||
647 | screen.rgb_conv = bgr_888; |
660 | screen.rgb_conv = bgr_888; |
648 | screen.mask_conv = mask_888; |
661 | screen.mask_conv = mask_888; |
649 | screen.pixelbytes = 3; |
662 | screen.pixelbytes = 3; |
650 | break; |
663 | break; |
651 | case VISUAL_RGB_8_8_8_0: |
664 | case VISUAL_RGB_8_8_8_0: |
652 | screen.rgb_conv = rgb_888; |
665 | screen.rgb_conv = rgb_8880; |
653 | screen.mask_conv = mask_888; |
666 | screen.mask_conv = mask_8880; |
654 | screen.pixelbytes = 4; |
667 | screen.pixelbytes = 4; |
655 | break; |
668 | break; |
656 | case VISUAL_RGB_0_8_8_8: |
669 | case VISUAL_RGB_0_8_8_8: |
657 | screen.rgb_conv = rgb_0888; |
670 | screen.rgb_conv = rgb_0888; |
658 | screen.mask_conv = mask_0888; |
671 | screen.mask_conv = mask_0888; |
Line 661... | Line 674... | ||
661 | case VISUAL_BGR_0_8_8_8: |
674 | case VISUAL_BGR_0_8_8_8: |
662 | screen.rgb_conv = bgr_0888; |
675 | screen.rgb_conv = bgr_0888; |
663 | screen.mask_conv = mask_0888; |
676 | screen.mask_conv = mask_0888; |
664 | screen.pixelbytes = 4; |
677 | screen.pixelbytes = 4; |
665 | break; |
678 | break; |
- | 679 | case VISUAL_BGR_8_8_8_0: |
|
- | 680 | screen.rgb_conv = bgr_8880; |
|
- | 681 | screen.mask_conv = mask_8880; |
|
- | 682 | screen.pixelbytes = 4; |
|
- | 683 | break; |
|
666 | default: |
684 | default: |
667 | return false; |
685 | return false; |
668 | } |
686 | } |
669 | 687 | ||
670 | screen.fb_addr = (unsigned char *) addr; |
688 | screen.fb_addr = (unsigned char *) addr; |
Line 1065... | Line 1083... | ||
1065 | case IPC_M_SHARE_OUT: |
1083 | case IPC_M_SHARE_OUT: |
1066 | /* We accept one area for data interchange */ |
1084 | /* We accept one area for data interchange */ |
1067 | if (IPC_GET_ARG1(*call) == shm_id) { |
1085 | if (IPC_GET_ARG1(*call) == shm_id) { |
1068 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
1086 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
1069 | shm_size = IPC_GET_ARG2(*call); |
1087 | shm_size = IPC_GET_ARG2(*call); |
1070 | if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) |
1088 | if (ipc_answer_1(callid, EOK, (sysarg_t) dest)) { |
1071 | shm = dest; |
- | |
1072 | else |
- | |
1073 | shm_id = 0; |
1089 | shm_id = 0; |
- | 1090 | return false; |
|
- | 1091 | } |
|
- | 1092 | shm = dest; |
|
1074 | 1093 | ||
1075 | if (shm[0] != 'P') |
1094 | if (shm[0] != 'P') |
1076 | return false; |
1095 | return false; |
1077 | 1096 | ||
1078 | return true; |
1097 | return true; |
Line 1643... | Line 1662... | ||
1643 | retval = EOK; |
1662 | retval = EOK; |
1644 | break; |
1663 | break; |
1645 | case FB_GET_CSIZE: |
1664 | case FB_GET_CSIZE: |
1646 | ipc_answer_2(callid, EOK, vport->cols, vport->rows); |
1665 | ipc_answer_2(callid, EOK, vport->cols, vport->rows); |
1647 | continue; |
1666 | continue; |
- | 1667 | case FB_GET_COLOR_CAP: |
|
- | 1668 | ipc_answer_1(callid, EOK, FB_CCAP_RGB); |
|
- | 1669 | continue; |
|
1648 | case FB_SCROLL: |
1670 | case FB_SCROLL: |
1649 | scroll = IPC_GET_ARG1(call); |
1671 | scroll = IPC_GET_ARG1(call); |
1650 | if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) { |
1672 | if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) { |
1651 | retval = EINVAL; |
1673 | retval = EINVAL; |
1652 | break; |
1674 | break; |
Line 1737... | Line 1759... | ||
1737 | unsigned int fb_offset = sysinfo_value("fb.offset"); |
1759 | unsigned int fb_offset = sysinfo_value("fb.offset"); |
1738 | unsigned int fb_width = sysinfo_value("fb.width"); |
1760 | unsigned int fb_width = sysinfo_value("fb.width"); |
1739 | unsigned int fb_height = sysinfo_value("fb.height"); |
1761 | unsigned int fb_height = sysinfo_value("fb.height"); |
1740 | unsigned int fb_scanline = sysinfo_value("fb.scanline"); |
1762 | unsigned int fb_scanline = sysinfo_value("fb.scanline"); |
1741 | unsigned int fb_visual = sysinfo_value("fb.visual"); |
1763 | unsigned int fb_visual = sysinfo_value("fb.visual"); |
1742 | 1764 | ||
1743 | unsigned int fbsize = fb_scanline * fb_height; |
1765 | unsigned int fbsize = fb_scanline * fb_height; |
1744 | void *fb_addr = as_get_mappable_page(fbsize); |
1766 | void *fb_addr = as_get_mappable_page(fbsize); |
1745 | 1767 | ||
1746 | if (physmem_map(fb_ph_addr + fb_offset, fb_addr, |
1768 | if (physmem_map(fb_ph_addr + fb_offset, fb_addr, |
1747 | ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0) |
1769 | ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0) |
1748 | return -1; |
1770 | return -1; |
1749 | 1771 | ||
1750 | if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual)) |
1772 | if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual)) |
1751 | return 0; |
1773 | return 0; |
1752 | 1774 | ||
1753 | return -1; |
1775 | return -1; |
1754 | } |
1776 | } |
1755 | 1777 | ||
1756 | /** |
1778 | /** |
1757 | * @} |
1779 | * @} |