Changeset d7baee6 in mainline for uspace/fb/fb.c
- Timestamp:
- 2007-01-17T13:03:08Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- df4ed85
- Parents:
- c738d65
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/fb/fb.c
rc738d65 rd7baee6 150 150 151 151 /* Conversion routines between different color representations */ 152 static void rgb_byte0888(void *dst, int rgb) 152 static void 153 rgb_byte0888(void *dst, int rgb) 153 154 { 154 155 *(int *)dst = rgb; 155 156 } 156 157 157 static int byte0888_rgb(void *src) 158 static int 159 byte0888_rgb(void *src) 158 160 { 159 161 return (*(int *)src) & 0xffffff; 160 162 } 161 163 162 static void bgr_byte0888(void *dst, int rgb) 164 static void 165 bgr_byte0888(void *dst, int rgb) 163 166 { 164 167 *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | … … 166 169 } 167 170 168 static int byte0888_bgr(void *src) 171 static int 172 byte0888_bgr(void *src) 169 173 { 170 174 int color = *(uint32_t *)(src); 171 return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | ((color 172 >> 16) & 0xff); 173 } 174 175 static void rgb_byte888(void *dst, int rgb) 175 return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | 176 ((color >> 16) & 0xff); 177 } 178 179 static void 180 rgb_byte888(void *dst, int rgb) 176 181 { 177 182 uint8_t *scr = dst; … … 187 192 } 188 193 189 static int byte888_rgb(void *src) 194 static int 195 byte888_rgb(void *src) 190 196 { 191 197 uint8_t *scr = src; … … 198 204 199 205 /** 16-bit depth (5:5:5) */ 200 static void rgb_byte555(void *dst, int rgb) 206 static void 207 rgb_byte555(void *dst, int rgb) 201 208 { 202 209 /* 5-bit, 5-bits, 5-bits */ … … 206 213 207 214 /** 16-bit depth (5:5:5) */ 208 static int byte555_rgb(void *src) 215 static int 216 byte555_rgb(void *src) 209 217 { 210 218 int color = *(uint16_t *)(src); 211 return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) <<212 ( 8 + 3)) | ((color & 0x1f) << 3);219 return (((color >> 10) & 0x1f) << (16 + 3)) | 220 (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); 213 221 } 214 222 215 223 /** 16-bit depth (5:6:5) */ 216 static void rgb_byte565(void *dst, int rgb) 224 static void 225 rgb_byte565(void *dst, int rgb) 217 226 { 218 227 /* 5-bit, 6-bits, 5-bits */ … … 222 231 223 232 /** 16-bit depth (5:6:5) */ 224 static int byte565_rgb(void *src) 233 static int 234 byte565_rgb(void *src) 225 235 { 226 236 int color = *(uint16_t *)(src); 227 return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) <<228 ( 8 + 2)) | ((color & 0x1f) << 3);237 return (((color >> 11) & 0x1f) << (16 + 3)) | 238 (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); 229 239 } 230 240 231 241 /** Put pixel - 8-bit depth (3:2:3) */ 232 static void rgb_byte8(void *dst, int rgb) 242 static void 243 rgb_byte8(void *dst, int rgb) 233 244 { 234 245 *(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3); … … 236 247 237 248 /** Return pixel color - 8-bit depth (3:2:3) */ 238 static int byte8_rgb(void *src) 249 static int 250 byte8_rgb(void *src) 239 251 { 240 252 int color = *(uint8_t *)src; 241 return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) <<242 ( 8 + 6)) | ((color & 0x7) << 5);253 return (((color >> 5) & 0x7) << (16 + 5)) | 254 (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); 243 255 } 244 256 … … 250 262 * @param color RGB color 251 263 */ 252 static void putpixel(viewport_t *vport, unsigned int x, unsigned int y, int253 264 static void 265 putpixel(viewport_t *vport, unsigned int x, unsigned int y, int color) 254 266 { 255 267 int dx = vport->x + x; … … 257 269 258 270 if (! (vport->paused && vport->dbdata)) 259 (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)], COLOR(color)); 271 (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)], 272 COLOR(color)); 260 273 261 274 if (vport->dbdata) { … … 267 280 268 281 /** Get pixel from viewport */ 269 static int getpixel(viewport_t *vport, unsigned int x, unsigned int y) 282 static int 283 getpixel(viewport_t *vport, unsigned int x, unsigned int y) 270 284 { 271 285 int dx = vport->x + x; 272 286 int dy = vport->y + y; 273 287 274 return COLOR((*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx, dy)]));275 } 276 277 static inline void putpixel_mem(char *mem, unsigned int x, unsigned int y, int278 288 return COLOR((*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx, dy)])); 289 } 290 291 static inline void 292 putpixel_mem(char *mem, unsigned int x, unsigned int y, int color) 279 293 { 280 294 (*screen.rgb2scr)(&mem[POINTPOS(x,y)], COLOR(color)); 281 295 } 282 296 283 static void draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy, 297 static void 298 draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy, 284 299 unsigned int width, unsigned int height, int color) 285 300 { … … 316 331 317 332 /** Fill viewport with background color */ 318 static void clear_port(viewport_t *vport) 333 static void 334 clear_port(viewport_t *vport) 319 335 { 320 336 draw_rectangle(vport, 0, 0, vport->width, vport->height, … … 327 343 * @param lines Positive number - scroll up, negative - scroll down 328 344 */ 329 static void scroll_port_nodb(viewport_t *vport, int lines) 345 static void 346 scroll_port_nodb(viewport_t *vport, int lines) 330 347 { 331 348 int y; … … 351 368 352 369 /** Refresh given viewport from double buffer */ 353 static void refresh_viewport_db(viewport_t *vport) 370 static void 371 refresh_viewport_db(viewport_t *vport) 354 372 { 355 373 unsigned int y, srcy, srcoff, dsty, dstx; … … 369 387 370 388 /** Scroll viewport that has double buffering enabled */ 371 static void scroll_port_db(viewport_t *vport, int lines) 389 static void 390 scroll_port_db(viewport_t *vport, int lines) 372 391 { 373 392 ++vport->paused; … … 394 413 395 414 /** Scrolls viewport given number of lines */ 396 static void scroll_port(viewport_t *vport, int lines) 415 static void 416 scroll_port(viewport_t *vport, int lines) 397 417 { 398 418 if (vport->dbdata) … … 403 423 } 404 424 405 static void invert_pixel(viewport_t *vport, unsigned int x, unsigned int y) 425 static void 426 invert_pixel(viewport_t *vport, unsigned int x, unsigned int y) 406 427 { 407 428 putpixel(vport, x, y, ~getpixel(vport, x, y)); … … 420 441 * @param transparent If false, print background color 421 442 */ 422 static void draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx, 443 static void 444 draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx, 423 445 unsigned int sy, style_t style, int transparent) 424 446 { … … 441 463 442 464 /** Invert character at given position */ 443 static void invert_char(viewport_t *vport,unsigned int row, unsigned int col) 465 static void 466 invert_char(viewport_t *vport,unsigned int row, unsigned int col) 444 467 { 445 468 unsigned int x; … … 460 483 * @return New viewport number 461 484 */ 462 static int viewport_create(unsigned int x, unsigned int y,unsigned int width, 485 static int 486 viewport_create(unsigned int x, unsigned int y,unsigned int width, 463 487 unsigned int height) 464 488 { 465 489 int i; 466 490 467 for (i =0; i < MAX_VIEWPORTS; i++) {491 for (i = 0; i < MAX_VIEWPORTS; i++) { 468 492 if (!viewports[i].initialized) 469 493 break; … … 491 515 return i; 492 516 } 493 494 517 495 518 /** Initialize framebuffer as a chardev output device … … 503 526 * 504 527 */ 505 static bool screen_init(void *addr, unsigned int xres, unsigned int yres, 528 static bool 529 screen_init(void *addr, unsigned int xres, unsigned int yres, 506 530 unsigned int scan, unsigned int visual, bool invert_colors) 507 531 { … … 559 583 560 584 /** Hide cursor if it is shown */ 561 static void cursor_hide(viewport_t *vport) 585 static void 586 cursor_hide(viewport_t *vport) 562 587 { 563 588 if (vport->cursor_active && vport->cursor_shown) { … … 568 593 569 594 /** Show cursor if cursor showing is enabled */ 570 static void cursor_print(viewport_t *vport) 595 static void 596 cursor_print(viewport_t *vport) 571 597 { 572 598 /* Do not check for cursor_shown */ … … 578 604 579 605 /** Invert cursor, if it is enabled */ 580 static void cursor_blink(viewport_t *vport) 606 static void 607 cursor_blink(viewport_t *vport) 581 608 { 582 609 if (vport->cursor_shown) … … 594 621 * @param transparent If false, print background color with character 595 622 */ 596 static void draw_char(viewport_t *vport, char c, unsigned int row, unsigned int 597 col, style_t style, int transparent) 623 static void 624 draw_char(viewport_t *vport, char c, unsigned int row, unsigned int col, 625 style_t style, int transparent) 598 626 { 599 627 /* Optimize - do not hide cursor if we are going to overwrite it */ … … 623 651 * @param data Text data fitting exactly into viewport 624 652 */ 625 static void draw_text_data(viewport_t *vport, keyfield_t *data) 653 static void 654 draw_text_data(viewport_t *vport, keyfield_t *data) 626 655 { 627 656 int i; … … 642 671 } 643 672 644 645 673 /** Return first free pixmap */ 646 static int find_free_pixmap(void) 674 static int 675 find_free_pixmap(void) 647 676 { 648 677 int i; 649 678 650 for (i =0;i < MAX_PIXMAPS;i++)679 for (i = 0;i < MAX_PIXMAPS;i++) 651 680 if (!pixmaps[i].data) 652 681 return i; … … 654 683 } 655 684 656 static void putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color) 685 static void 686 putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color) 657 687 { 658 688 pixmap_t *pmap = &pixmaps[pm]; … … 663 693 664 694 /** Create a new pixmap and return appropriate ID */ 665 static int shm2pixmap(unsigned char *shm, size_t size) 695 static int 696 shm2pixmap(unsigned char *shm, size_t size) 666 697 { 667 698 int pm; … … 706 737 * to redefine static variables with __thread 707 738 */ 708 static int shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 739 static int 740 shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 709 741 { 710 742 static keyfield_t *interbuffer = NULL; … … 718 750 int retval = 0; 719 751 viewport_t *vport = &viewports[vp]; 720 unsigned int x, y;752 unsigned int x, y; 721 753 722 754 switch (IPC_GET_METHOD(*call)) { … … 775 807 776 808 ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), 777 IPC_GET_ARG2(*call), vport->width - x, vport->height -778 y, (putpixel_cb_t)putpixel, vport);809 IPC_GET_ARG2(*call), vport->width - x, 810 vport->height - y, (putpixel_cb_t)putpixel, vport); 779 811 break; 780 812 case FB_DRAW_TEXT_DATA: … … 799 831 } 800 832 801 static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) 833 static void 834 copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) 802 835 { 803 836 int y; … … 815 848 816 849 for (y = 0; y < height; y++) { 817 tmp = (vport->y + y) * screen.scanline + vport->x *818 screen.pixelbytes;850 tmp = (vport->y + y) * screen.scanline + 851 vport->x * screen.pixelbytes; 819 852 memcpy(pmap->data + rowsize * y, screen.fbaddress + tmp, 820 853 rowsize); … … 823 856 824 857 /** Save viewport to pixmap */ 825 static int save_vp_to_pixmap(viewport_t *vport) 858 static int 859 save_vp_to_pixmap(viewport_t *vport) 826 860 { 827 861 int pm; … … 874 908 realrowsize = realwidth * screen.pixelbytes; 875 909 876 for (y =0; y < realheight; y++) {877 tmp = (vport->y + y) * screen.scanline + vport->x *878 screen.pixelbytes;910 for (y = 0; y < realheight; y++) { 911 tmp = (vport->y + y) * screen.scanline + 912 vport->x * screen.pixelbytes; 879 913 memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize, 880 914 realrowsize); … … 884 918 885 919 /** Tick animation one step forward */ 886 static void anims_tick(void) 920 static void 921 anims_tick(void) 887 922 { 888 923 int i; … … 894 929 return; 895 930 896 for (i =0; i < MAX_ANIMATIONS; i++) {931 for (i = 0; i < MAX_ANIMATIONS; i++) { 897 932 if (!animations[i].animlen || !animations[i].initialized || 898 933 !animations[i].enabled) … … 911 946 static int pointer_pixmap = -1; 912 947 913 static void mouse_show(void) 914 { 915 int i,j; 948 static void 949 mouse_show(void) 950 { 951 int i, j; 916 952 int visibility; 917 953 int color; … … 942 978 for (j = 0; j < pointer_width; j++) { 943 979 bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8; 944 visibility = pointer_mask_bits[bytepos] & (1 << (j %945 8));980 visibility = pointer_mask_bits[bytepos] & 981 (1 << (j % 8)); 946 982 if (visibility) { 947 983 color = pointer_bits[bytepos] & (1 << (j % 8)) … … 950 986 i < screen.yres) 951 987 putpixel(&viewports[0], pointer_x + j, 952 pointer_y+i, color);988 pointer_y + i, color); 953 989 } 954 990 } … … 956 992 } 957 993 958 static void mouse_hide(void) 994 static void 995 mouse_hide(void) 959 996 { 960 997 /* Restore image under the cursor */ … … 965 1002 } 966 1003 967 static void mouse_move(unsigned int x, unsigned int y) 1004 static void 1005 mouse_move(unsigned int x, unsigned int y) 968 1006 { 969 1007 mouse_hide(); … … 973 1011 } 974 1012 975 static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 1013 static int 1014 anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 976 1015 { 977 1016 int handled = 1; … … 1070 1109 1071 1110 /** Handler for messages concerning pixmap handling */ 1072 static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 1111 static int 1112 pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) 1073 1113 { 1074 1114 int handled = 1; … … 1123 1163 * 1124 1164 */ 1125 static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) 1165 static void 1166 fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) 1126 1167 { 1127 1168 ipc_callid_t callid; … … 1144 1185 while (1) { 1145 1186 if (vport->cursor_active || anims_enabled) 1146 callid = async_get_call_timeout(&call, 250000);1187 callid = async_get_call_timeout(&call, 250000); 1147 1188 else 1148 1189 callid = async_get_call(&call); … … 1179 1220 break; 1180 1221 } 1181 ipc_answer_fast(callid, 0,0,0);1222 ipc_answer_fast(callid, 0, 0, 0); 1182 1223 1183 1224 draw_char(vport, c, row, col, vport->style, … … 1265 1306 case FB_VIEWPORT_CREATE: 1266 1307 retval = viewport_create(IPC_GET_ARG1(call) >> 16, 1267 IPC_GET_ARG1(call) & 0xffff, IPC_GET_ARG2(call) 1268 >> 16, IPC_GET_ARG2(call) & 0xffff); 1308 IPC_GET_ARG1(call) & 0xffff, 1309 IPC_GET_ARG2(call) >> 16, 1310 IPC_GET_ARG2(call) & 0xffff); 1269 1311 break; 1270 1312 case FB_VIEWPORT_DELETE: … … 1301 1343 retval = ENOENT; 1302 1344 } 1303 ipc_answer_fast(callid,retval, 0,0);1345 ipc_answer_fast(callid,retval, 0, 0); 1304 1346 } 1305 1347 } 1306 1348 1307 1349 /** Initialization of framebuffer */ 1308 int fb_init(void) 1350 int 1351 fb_init(void) 1309 1352 { 1310 1353 void *fb_ph_addr;
Note:
See TracChangeset
for help on using the changeset viewer.