Changeset 00bb6965 in mainline for uspace/fb/fb.c
- Timestamp:
- 2006-12-11T23:17:58Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- df496c5
- Parents:
- dff0a94
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/fb/fb.c
rdff0a94 r00bb6965 162 162 static void bgr_byte0888(void *dst, int rgb) 163 163 { 164 *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | RED(rgb, 8); 164 *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | 165 RED(rgb, 8); 165 166 } 166 167 … … 168 169 { 169 170 int color = *(uint32_t *)(src); 170 return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | ((color >> 16) & 0xff); 171 return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | ((color 172 >> 16) & 0xff); 171 173 } 172 174 … … 199 201 { 200 202 /* 5-bit, 5-bits, 5-bits */ 201 *((uint16_t *)(dst)) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5); 203 *((uint16_t *)(dst)) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | 204 BLUE(rgb, 5); 202 205 } 203 206 … … 206 209 { 207 210 int color = *(uint16_t *)(src); 208 return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); 211 return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) << 212 (8 + 3)) | ((color & 0x1f) << 3); 209 213 } 210 214 … … 213 217 { 214 218 /* 5-bit, 6-bits, 5-bits */ 215 *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5); 219 *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | 220 BLUE(rgb, 5); 216 221 } 217 222 … … 220 225 { 221 226 int color = *(uint16_t *)(src); 222 return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); 227 return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << 228 (8 + 2)) | ((color & 0x1f) << 3); 223 229 } 224 230 … … 233 239 { 234 240 int color = *(uint8_t *)src; 235 return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); 241 return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << 242 (8 + 6)) | ((color & 0x7) << 5); 236 243 } 237 244 … … 243 250 * @param color RGB color 244 251 */ 245 static void putpixel(viewport_t *vport, unsigned int x, unsigned int y, int color) 252 static void putpixel(viewport_t *vport, unsigned int x, unsigned int y, int 253 color) 246 254 { 247 255 int dx = vport->x + x; … … 267 275 } 268 276 269 static inline void putpixel_mem(char *mem, unsigned int x, unsigned int y, 270 intcolor)277 static inline void putpixel_mem(char *mem, unsigned int x, unsigned int y, int 278 color) 271 279 { 272 280 (*screen.rgb2scr)(&mem[POINTPOS(x,y)], COLOR(color)); … … 274 282 275 283 static void draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy, 276 unsigned int width, unsigned int height, 277 int color) 284 unsigned int width, unsigned int height, int color) 278 285 { 279 286 unsigned int x, y; … … 297 304 } 298 305 if (vport->dbdata) { 299 for (y =sy;y < sy+height; y++) {306 for (y = sy; y < sy + height; y++) { 300 307 int rline = (y + vport->dboffset) % vport->height; 301 int rpos = (rline * vport->width + sx) * screen.pixelbytes; 302 memcpy(&vport->dbdata[rpos], tmpline, screen.pixelbytes * width); 308 int rpos = (rline * vport->width + sx) * 309 screen.pixelbytes; 310 memcpy(&vport->dbdata[rpos], tmpline, 311 screen.pixelbytes * width); 303 312 } 304 313 } … … 309 318 static void clear_port(viewport_t *vport) 310 319 { 311 draw_rectangle(vport, 0, 0, vport->width, vport->height, vport->style.bg_color); 320 draw_rectangle(vport, 0, 0, vport->width, vport->height, 321 vport->style.bg_color); 312 322 } 313 323 … … 322 332 323 333 if (lines > 0) { 324 for (y =vport->y; y < vport->y+vport->height - lines; y++)334 for (y = vport->y; y < vport->y+vport->height - lines; y++) 325 335 memcpy(&screen.fbaddress[POINTPOS(vport->x,y)], 326 336 &screen.fbaddress[POINTPOS(vport->x,y + lines)], 327 337 screen.pixelbytes * vport->width); 328 draw_rectangle(vport, 0, vport->height - lines, 329 vport->width,lines, vport->style.bg_color);338 draw_rectangle(vport, 0, vport->height - lines, vport->width, 339 lines, vport->style.bg_color); 330 340 } else if (lines < 0) { 331 341 lines = -lines; 332 for (y=vport->y + vport->height-1; y >= vport->y + lines; y--) 342 for (y = vport->y + vport->height-1; y >= vport->y + lines; 343 y--) 333 344 memcpy(&screen.fbaddress[POINTPOS(vport->x,y)], 334 345 &screen.fbaddress[POINTPOS(vport->x,y - lines)], 335 346 screen.pixelbytes * vport->width); 336 draw_rectangle(vport, 0, 0, vport->width, lines, vport->style.bg_color); 347 draw_rectangle(vport, 0, 0, vport->width, lines, 348 vport->style.bg_color); 337 349 } 338 350 } … … 408 420 * @param transparent If false, print background color 409 421 */ 410 static void draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx, unsigned int sy,411 422 static void draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx, 423 unsigned int sy, style_t style, int transparent) 412 424 { 413 425 int i; … … 419 431 for (i = 0; i < 8; i++) { 420 432 if (glline & (1 << (7 - i))) 421 putpixel(vport, sx + i, sy + y, style.fg_color); 433 putpixel(vport, sx + i, sy + y, 434 style.fg_color); 422 435 else if (!transparent) 423 putpixel(vport, sx + i, sy + y, style.bg_color); 436 putpixel(vport, sx + i, sy + y, 437 style.bg_color); 424 438 } 425 439 } … … 434 448 for (x = 0; x < COL_WIDTH; x++) 435 449 for (y = 0; y < FONT_SCANLINES; y++) 436 invert_pixel(vport, col * COL_WIDTH + x, row * FONT_SCANLINES + y); 450 invert_pixel(vport, col * COL_WIDTH + x, row * 451 FONT_SCANLINES + y); 437 452 } 438 453 … … 446 461 */ 447 462 static int viewport_create(unsigned int x, unsigned int y,unsigned int width, 448 463 unsigned int height) 449 464 { 450 465 int i; … … 488 503 * 489 504 */ 490 static bool screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int scan, unsigned int visual, bool invert_colors) 505 static bool screen_init(void *addr, unsigned int xres, unsigned int yres, 506 unsigned int scan, unsigned int visual, bool invert_colors) 491 507 { 492 508 switch (visual) { … … 578 594 * @param transparent If false, print background color with character 579 595 */ 580 static void draw_char(viewport_t *vport, char c, unsigned int row, unsigned int col,581 596 static void draw_char(viewport_t *vport, char c, unsigned int row, unsigned int 597 col, style_t style, int transparent) 582 598 { 583 599 /* Optimize - do not hide cursor if we are going to overwrite it */ … … 586 602 invert_char(vport, vport->cur_row, vport->cur_col); 587 603 588 draw_glyph(vport, c, col * COL_WIDTH, row * FONT_SCANLINES, style, transparent); 604 draw_glyph(vport, c, col * COL_WIDTH, row * FONT_SCANLINES, style, 605 transparent); 589 606 590 607 vport->cur_col = col; … … 592 609 593 610 vport->cur_col++; 594 if (vport->cur_col >= vport->cols) {611 if (vport->cur_col >= vport->cols) { 595 612 vport->cur_col = 0; 596 613 vport->cur_row++; … … 612 629 613 630 clear_port(vport); 614 for (i=0; i < vport->cols * vport->rows; i++) { 615 if (data[i].character == ' ' && style_same(data[i].style,vport->style)) 631 for (i = 0; i < vport->cols * vport->rows; i++) { 632 if (data[i].character == ' ' && style_same(data[i].style, 633 vport->style)) 616 634 continue; 617 635 col = i % vport->cols; 618 636 row = i / vport->cols; 619 draw_glyph(vport, data[i].character, col * COL_WIDTH, row * FONT_SCANLINES, 620 data[i].style, style_same(data[i].style,vport->style)); 637 draw_glyph(vport, data[i].character, col * COL_WIDTH, row * 638 FONT_SCANLINES, data[i].style, 639 style_same(data[i].style,vport->style)); 621 640 } 622 641 cursor_print(vport); … … 671 690 * Protocol for drawing pixmaps: 672 691 * - FB_PREPARE_SHM(client shm identification) 673 * - IPC_M_ SEND_AS_AREA692 * - IPC_M_AS_AREA_SEND 674 693 * - FB_DRAW_PPM(startx,starty) 675 694 * - FB_DROP_SHM 676 695 * 677 696 * Protocol for text drawing 678 * - IPC_M_ SEND_AS_AREA697 * - IPC_M_AS_AREA_SEND 679 698 * - FB_DRAW_TEXT_DATA 680 699 * … … 755 774 } 756 775 757 ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call), 758 vport->width - x, vport->height - y, (putpixel_cb_t)putpixel, vport); 776 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); 759 779 break; 760 780 case FB_DRAW_TEXT_DATA: … … 763 783 break; 764 784 } 765 if (intersize < vport->cols*vport->rows*sizeof(*interbuffer)) { 785 if (intersize < vport->cols * vport->rows * 786 sizeof(*interbuffer)) { 766 787 retval = EINVAL; 767 788 break; … … 793 814 rowsize = width * screen.pixelbytes; 794 815 795 for (y=0;y < height; y++) { 796 tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; 797 memcpy(pmap->data + rowsize*y, screen.fbaddress + tmp, rowsize); 816 for (y = 0; y < height; y++) { 817 tmp = (vport->y + y) * screen.scanline + vport->x * 818 screen.pixelbytes; 819 memcpy(pmap->data + rowsize * y, screen.fbaddress + tmp, 820 rowsize); 798 821 } 799 822 } … … 852 875 853 876 for (y=0; y < realheight; y++) { 854 tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; 855 memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize, realrowsize); 877 tmp = (vport->y + y) * screen.scanline + vport->x * 878 screen.pixelbytes; 879 memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize, 880 realrowsize); 856 881 } 857 882 return 0; … … 865 890 866 891 /* Limit redrawing */ 867 counts = (counts +1) % 8;892 counts = (counts + 1) % 8; 868 893 if (counts) 869 894 return; 870 895 871 896 for (i=0; i < MAX_ANIMATIONS; i++) { 872 if (!animations[i].animlen || !animations[i].initialized || !animations[i].enabled) 897 if (!animations[i].animlen || !animations[i].initialized || 898 !animations[i].enabled) 873 899 continue; 874 draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]); 875 animations[i].pos = (animations[i].pos+1) % animations[i].animlen; 900 draw_pixmap(animations[i].vp, 901 animations[i].pixmaps[animations[i].pos]); 902 animations[i].pos = (animations[i].pos + 1) % 903 animations[i].animlen; 876 904 } 877 905 } … … 895 923 /* Save image under the cursor */ 896 924 if (pointer_vport == -1) { 897 pointer_vport = viewport_create(pointer_x, pointer_y, pointer_width, pointer_height); 925 pointer_vport = viewport_create(pointer_x, pointer_y, 926 pointer_width, pointer_height); 898 927 if (pointer_vport < 0) 899 928 return; … … 906 935 pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]); 907 936 else 908 copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]); 937 copy_vp_to_pixmap(&viewports[pointer_vport], 938 &pixmaps[pointer_pixmap]); 909 939 910 940 /* Draw cursor */ 911 for (i=0; i < pointer_height; i++) 912 for (j=0;j < pointer_width; j++) { 913 bytepos = i*((pointer_width-1)/8+1) + j/8; 914 visibility = pointer_mask_bits[bytepos] & (1 << (j % 8)); 941 for (i = 0; i < pointer_height; i++) 942 for (j = 0; j < pointer_width; j++) { 943 bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8; 944 visibility = pointer_mask_bits[bytepos] & (1 << (j % 945 8)); 915 946 if (visibility) { 916 color = pointer_bits[bytepos] & (1 << (j % 8)) ? 0 : 0xffffff; 917 if (pointer_x+j < screen.xres && pointer_y+i < screen.yres) 918 putpixel(&viewports[0], pointer_x+j, pointer_y+i, color); 947 color = pointer_bits[bytepos] & (1 << (j % 8)) 948 ? 0 : 0xffffff; 949 if (pointer_x + j < screen.xres && pointer_y + 950 i < screen.yres) 951 putpixel(&viewports[0], pointer_x + j, 952 pointer_y+i, color); 919 953 } 920 954 } … … 951 985 if (nvp == -1) 952 986 nvp = vp; 953 if (nvp >= MAX_VIEWPORTS || nvp < 0 || !viewports[nvp].initialized) { 954 retval = EINVAL; 955 break; 956 } 957 for (i=0; i < MAX_ANIMATIONS; i++) { 958 if (! animations[i].initialized) 987 if (nvp >= MAX_VIEWPORTS || nvp < 0 || 988 !viewports[nvp].initialized) { 989 retval = EINVAL; 990 break; 991 } 992 for (i = 0; i < MAX_ANIMATIONS; i++) { 993 if (!animations[i].initialized) 959 994 break; 960 995 } … … 980 1015 case FB_ANIM_ADDPIXMAP: 981 1016 i = IPC_GET_ARG1(*call); 982 if (i >= MAX_ANIMATIONS || i < 0 || !animations[i].initialized) { 1017 if (i >= MAX_ANIMATIONS || i < 0 || 1018 !animations[i].initialized) { 983 1019 retval = EINVAL; 984 1020 break; … … 989 1025 } 990 1026 newval = IPC_GET_ARG2(*call); 991 if (newval < 0 || newval > MAX_PIXMAPS || !pixmaps[newval].data) { 1027 if (newval < 0 || newval > MAX_PIXMAPS || 1028 !pixmaps[newval].data) { 992 1029 retval = EINVAL; 993 1030 break; … … 1004 1041 if (nvp == -1) 1005 1042 nvp = vp; 1006 if (nvp >= MAX_VIEWPORTS || nvp < 0 || !viewports[nvp].initialized) { 1043 if (nvp >= MAX_VIEWPORTS || nvp < 0 || 1044 !viewports[nvp].initialized) { 1007 1045 retval = EINVAL; 1008 1046 break; … … 1043 1081 if (nvp == -1) 1044 1082 nvp = vp; 1045 if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized) { 1083 if (nvp < 0 || nvp >= MAX_VIEWPORTS || 1084 !viewports[nvp].initialized) { 1046 1085 retval = EINVAL; 1047 1086 break; … … 1054 1093 if (nvp == -1) 1055 1094 nvp = vp; 1056 if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized) 1095 if (nvp < 0 || nvp >= MAX_VIEWPORTS || 1096 !viewports[nvp].initialized) 1057 1097 retval = EINVAL; 1058 1098 else … … 1126 1166 client_connected = 0; 1127 1167 /* cleanup other viewports */ 1128 for (i =1; i < MAX_VIEWPORTS; i++)1168 for (i = 1; i < MAX_VIEWPORTS; i++) 1129 1169 vport->initialized = 0; 1130 1170 return; /* Exit thread */ … … 1141 1181 ipc_answer_fast(callid,0,0,0); 1142 1182 1143 draw_char(vport, c, row, col, vport->style, IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR); 1183 draw_char(vport, c, row, col, vport->style, 1184 IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR); 1144 1185 continue; /* msg already answered */ 1145 1186 case FB_CLEAR: … … 1196 1237 viewports[i].dboffset = 0; 1197 1238 if (IPC_GET_ARG2(call) == 1 && !viewports[i].dbdata) 1198 viewports[i].dbdata = malloc(screen.pixelbytes*viewports[i].width * viewports[i].height); 1199 else if (IPC_GET_ARG2(call) == 0 && viewports[i].dbdata) { 1239 viewports[i].dbdata = malloc(screen.pixelbytes 1240 * viewports[i].width * 1241 viewports[i].height); 1242 else if (IPC_GET_ARG2(call) == 0 && 1243 viewports[i].dbdata) { 1200 1244 free(viewports[i].dbdata); 1201 1245 viewports[i].dbdata = NULL; … … 1221 1265 case FB_VIEWPORT_CREATE: 1222 1266 retval = viewport_create(IPC_GET_ARG1(call) >> 16, 1223 IPC_GET_ARG1(call) & 0xffff, 1224 IPC_GET_ARG2(call) >> 16, 1225 IPC_GET_ARG2(call) & 0xffff); 1267 IPC_GET_ARG1(call) & 0xffff, IPC_GET_ARG2(call) 1268 >> 16, IPC_GET_ARG2(call) & 0xffff); 1226 1269 break; 1227 1270 case FB_VIEWPORT_DELETE: … … 1284 1327 1285 1328 asz = fb_scanline * fb_height; 1286 fb_addr = as_get_mappable_page(asz, (int) sysinfo_value("fb.address.color")); 1287 1288 physmem_map(fb_ph_addr, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >> PAGE_WIDTH, 1289 AS_AREA_READ | AS_AREA_WRITE); 1329 fb_addr = as_get_mappable_page(asz, (int) 1330 sysinfo_value("fb.address.color")); 1331 1332 physmem_map(fb_ph_addr, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >> 1333 PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE); 1290 1334 1291 1335 if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual,
Note:
See TracChangeset
for help on using the changeset viewer.