[7497] | 1 | #ifndef FB_H |
---|
| 2 | #define FB_H |
---|
| 3 | |
---|
[40590] | 4 | #ifdef CONFIG_ION |
---|
[40591] | 5 | #define ION_HEAP_TYPE_BMEM (ION_HEAP_TYPE_CUSTOM + 1) |
---|
| 6 | #define ION_HEAP_ID_MASK (1 << ION_HEAP_TYPE_BMEM) |
---|
| 7 | #define ACCEL_MEM_SIZE (32*1024*1024) |
---|
| 8 | int m_accel_fd; |
---|
[40590] | 9 | #endif |
---|
[40589] | 10 | |
---|
[40591] | 11 | |
---|
| 12 | |
---|
| 13 | |
---|
[7497] | 14 | struct fb* getfb(char *name) |
---|
| 15 | { |
---|
| 16 | struct fb *node = fb; |
---|
| 17 | |
---|
| 18 | while(node != NULL) |
---|
| 19 | { |
---|
[16471] | 20 | if(ostrstr(node->name, name) != NULL) |
---|
[7497] | 21 | return node; |
---|
| 22 | |
---|
| 23 | node = node->next; |
---|
| 24 | } |
---|
[26549] | 25 | debug(444, "framebuffer not found (%s)", name); |
---|
[7497] | 26 | return NULL; |
---|
| 27 | } |
---|
| 28 | |
---|
[7694] | 29 | long getfbsize(int dev) |
---|
[7497] | 30 | { |
---|
| 31 | struct fb* node = fb; |
---|
| 32 | unsigned long fbmemcount = 0; |
---|
| 33 | struct fb_fix_screeninfo fix_screeninfo; |
---|
| 34 | |
---|
| 35 | if(fb == NULL) |
---|
| 36 | { |
---|
[23267] | 37 | err("NULL dedect"); |
---|
[7497] | 38 | return 0; |
---|
| 39 | } |
---|
| 40 | |
---|
[9579] | 41 | #ifndef NOFB |
---|
[7497] | 42 | if(ioctl(fb->fd, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) |
---|
| 43 | { |
---|
| 44 | perr("ioctl FBIOGET_FSCREENINFO failed"); |
---|
| 45 | return 0; |
---|
| 46 | } |
---|
| 47 | #else |
---|
| 48 | fix_screeninfo.smem_len = 16*1024*1024; |
---|
| 49 | #endif |
---|
| 50 | |
---|
| 51 | while(node != NULL) |
---|
| 52 | { |
---|
[7694] | 53 | if(node->dev == dev) |
---|
| 54 | fbmemcount = fbmemcount + node->varfbsize; |
---|
[7497] | 55 | node = node->next; |
---|
| 56 | } |
---|
[26464] | 57 | |
---|
[7497] | 58 | return fix_screeninfo.smem_len - fbmemcount; |
---|
| 59 | } |
---|
| 60 | |
---|
[45014] | 61 | int getfbxres() |
---|
| 62 | { |
---|
| 63 | struct fb_var_screeninfo var_screeninfo; |
---|
| 64 | int fd = -1; |
---|
| 65 | char *fbdev = getconfig("fbdev", NULL); |
---|
| 66 | |
---|
| 67 | if(fbdev == NULL) |
---|
| 68 | { |
---|
| 69 | err("failed to find fbdev in config file"); |
---|
| 70 | return -1; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | fd = open(fbdev, O_RDWR); |
---|
| 74 | if(fd == -1) |
---|
| 75 | { |
---|
| 76 | perr("failed to open %s", fbdev); |
---|
| 77 | return -1; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | if(ioctl(fd, FBIOGET_VSCREENINFO, &var_screeninfo) < 0) |
---|
| 81 | { |
---|
| 82 | err("failed to read VSCREENINFO"); |
---|
| 83 | close(fd); |
---|
| 84 | return -1; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | close(fd); |
---|
| 88 | return var_screeninfo.xres; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | int getfbyres() |
---|
| 92 | { |
---|
| 93 | struct fb_var_screeninfo var_screeninfo; |
---|
| 94 | int fd = -1; |
---|
| 95 | char *fbdev = getconfig("fbdev", NULL); |
---|
| 96 | |
---|
| 97 | if(fbdev == NULL) |
---|
| 98 | { |
---|
| 99 | err("failed to find fbdev in config file"); |
---|
| 100 | return -1; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | fd = open(fbdev, O_RDWR); |
---|
| 104 | if(fd == -1) |
---|
| 105 | { |
---|
| 106 | perr("failed to open %s", fbdev); |
---|
| 107 | return -1; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | if(ioctl(fd, FBIOGET_VSCREENINFO, &var_screeninfo) < 0) |
---|
| 111 | { |
---|
| 112 | err("failed to read VSCREENINFO"); |
---|
| 113 | close(fd); |
---|
| 114 | return -1; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | close(fd); |
---|
| 118 | return var_screeninfo.yres; |
---|
| 119 | } |
---|
| 120 | |
---|
[36560] | 121 | struct fb* addfb(char *fbname, int dev, int width, int height, int colbytes, int fd, unsigned char* mmapfb, unsigned long fixfbsize, unsigned long data_phys) |
---|
[7497] | 122 | { |
---|
| 123 | struct fb *newnode = NULL, *node = fb; |
---|
| 124 | char *name = NULL; |
---|
| 125 | long ret = 0; |
---|
| 126 | |
---|
[16286] | 127 | name = ostrcat(fbname, NULL, 0, 0); |
---|
[7497] | 128 | if(name == NULL) |
---|
| 129 | { |
---|
| 130 | err("no memory"); |
---|
| 131 | return NULL; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | newnode = (struct fb*)malloc(sizeof(struct fb)); |
---|
| 135 | if(newnode == NULL) |
---|
| 136 | { |
---|
| 137 | err("no memory"); |
---|
| 138 | free(name); |
---|
| 139 | return NULL; |
---|
| 140 | } |
---|
[36614] | 141 | |
---|
[7497] | 142 | memset(newnode, 0, sizeof(struct fb)); |
---|
| 143 | newnode->name = name; |
---|
[7694] | 144 | newnode->dev = dev; |
---|
[7497] | 145 | newnode->width = width; |
---|
| 146 | newnode->height = height; |
---|
[9590] | 147 | newnode->colbytes = colbytes; |
---|
[8590] | 148 | newnode->pitch = newnode->width * newnode->colbytes; |
---|
[11076] | 149 | newnode->fb = mmapfb; |
---|
| 150 | newnode->fblong = (unsigned long*)newnode->fb; |
---|
| 151 | newnode->fd = fd; |
---|
| 152 | newnode->fixfbsize = fixfbsize; |
---|
[36560] | 153 | newnode->data_phys = data_phys; |
---|
[15169] | 154 | |
---|
[7497] | 155 | if(ostrcmp(name, FB) == 0) |
---|
[15296] | 156 | setfbvarsize(newnode); |
---|
[7694] | 157 | else if(ostrcmp(name, FB1) == 0) |
---|
[36614] | 158 | #ifdef MIPSEL |
---|
| 159 | newnode->varfbsize = width * height * newnode->colbytes; |
---|
| 160 | #else |
---|
[7694] | 161 | newnode->varfbsize = 720 * 576 * newnode->colbytes; |
---|
[36614] | 162 | #endif |
---|
[7497] | 163 | else |
---|
| 164 | newnode->varfbsize = width * height * newnode->colbytes; |
---|
[13190] | 165 | |
---|
[7497] | 166 | if(node != NULL) |
---|
| 167 | { |
---|
| 168 | while(node->next != NULL) |
---|
| 169 | node = node->next; |
---|
| 170 | node->next = newnode; |
---|
| 171 | } |
---|
| 172 | else |
---|
| 173 | fb = newnode; |
---|
[15344] | 174 | |
---|
| 175 | /*eigener Buffer zB fuer LCD*/ |
---|
| 176 | if(dev == 999) |
---|
| 177 | return newnode; |
---|
[40624] | 178 | #ifdef CONFIG_ION |
---|
| 179 | if(ostrcmp(name, FB) == 0) |
---|
| 180 | ret = getfbsize(dev); |
---|
| 181 | #else |
---|
[7694] | 182 | ret = getfbsize(dev); |
---|
[40624] | 183 | #endif |
---|
[7497] | 184 | if(ret < 0) |
---|
| 185 | { |
---|
| 186 | err("framebuffermem (%s) to small, needed = %ld", name, ret * -1); |
---|
[15344] | 187 | free(name); |
---|
[7497] | 188 | free(newnode); |
---|
| 189 | if(newnode == fb) fb = NULL; |
---|
| 190 | return NULL; |
---|
| 191 | } |
---|
| 192 | |
---|
[40612] | 193 | debug(444, "fbname=%s, fbwidth=%d, fbheight=%d, fbcol=%d, fbsize=%ld, phys_addr=%lu", newnode->name, newnode->width, newnode->height, newnode->colbytes, newnode->varfbsize, newnode->data_phys); |
---|
[7497] | 194 | return newnode; |
---|
| 195 | } |
---|
| 196 | |
---|
[14732] | 197 | void fb2png_thread() |
---|
| 198 | { |
---|
| 199 | while (writeFBfile.buf1 != NULL || writeFBfile.buf2 != NULL) { |
---|
| 200 | if(writeFBfile.buf1 != NULL) { |
---|
| 201 | writeFBfile.ActBuf = writeFBfile.buf1; |
---|
| 202 | fb2png(writeFBfile.buf1, 320, 240, "/tmp/titanlcd.png"); |
---|
| 203 | free(writeFBfile.buf1); writeFBfile.buf1 = NULL; |
---|
[14758] | 204 | if(writeFBfile.buf2 != NULL) |
---|
| 205 | usleep(500000); |
---|
[14732] | 206 | } |
---|
[14738] | 207 | if(writeFBfile.buf2 != NULL) { |
---|
[14732] | 208 | writeFBfile.ActBuf = writeFBfile.buf2; |
---|
| 209 | fb2png(writeFBfile.buf2, 320, 240, "/tmp/titanlcd.png"); |
---|
| 210 | free(writeFBfile.buf2); writeFBfile.buf2 = NULL; |
---|
[14758] | 211 | if(writeFBfile.buf1 != NULL) |
---|
| 212 | usleep(500000); |
---|
[14732] | 213 | } |
---|
| 214 | } |
---|
| 215 | writeFBfile.ActBuf = NULL; |
---|
| 216 | } |
---|
| 217 | |
---|
[7497] | 218 | void delfb(char *name) |
---|
| 219 | { |
---|
| 220 | struct fb *node = fb, *prev = fb; |
---|
| 221 | |
---|
| 222 | while(node != NULL) |
---|
| 223 | { |
---|
| 224 | if(ostrcmp(node->name, name) == 0) |
---|
| 225 | { |
---|
| 226 | if(node == fb) |
---|
| 227 | fb = node->next; |
---|
| 228 | else |
---|
| 229 | prev->next = node->next; |
---|
| 230 | |
---|
| 231 | free(node->name); |
---|
| 232 | node->name = NULL; |
---|
| 233 | |
---|
| 234 | free(node); |
---|
| 235 | node = NULL; |
---|
| 236 | break; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | prev = node; |
---|
| 240 | node = node->next; |
---|
| 241 | } |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | void freefb() |
---|
| 245 | { |
---|
| 246 | struct fb *node = fb, *prev = fb; |
---|
| 247 | |
---|
| 248 | while(node != NULL) |
---|
| 249 | { |
---|
| 250 | prev = node; |
---|
| 251 | node = node->next; |
---|
| 252 | if(prev != NULL) |
---|
| 253 | delfb(prev->name); |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | |
---|
[7694] | 257 | struct fb* openfb(char *fbdev, int devnr) |
---|
[7497] | 258 | { |
---|
| 259 | int fd = -1; |
---|
| 260 | unsigned char *mmapfb = NULL; |
---|
| 261 | struct fb_var_screeninfo var_screeninfo; |
---|
| 262 | struct fb_fix_screeninfo fix_screeninfo; |
---|
[7694] | 263 | struct fb* node = NULL; |
---|
[7497] | 264 | |
---|
| 265 | if(fbdev == NULL) |
---|
| 266 | { |
---|
| 267 | err("failed to find fbdev in config file"); |
---|
| 268 | return NULL; |
---|
| 269 | } |
---|
| 270 | |
---|
[40580] | 271 | #ifdef CONFIG_ION |
---|
| 272 | int ion; |
---|
| 273 | #endif |
---|
| 274 | |
---|
[9579] | 275 | #ifndef NOFB |
---|
[7497] | 276 | fd = open(fbdev, O_RDWR); |
---|
[26434] | 277 | |
---|
[26495] | 278 | // blinking work start |
---|
[26549] | 279 | #ifdef MIPSEL |
---|
[26495] | 280 | if (fd < 0) |
---|
[26434] | 281 | { |
---|
[40671] | 282 | err(fbdev); |
---|
| 283 | goto nolfb; |
---|
| 284 | } |
---|
[26495] | 285 | #endif |
---|
| 286 | // blinking work end |
---|
[26434] | 287 | |
---|
[7497] | 288 | if(fd == -1) |
---|
| 289 | { |
---|
| 290 | perr("failed to open %s", fbdev); |
---|
| 291 | return NULL; |
---|
| 292 | } |
---|
[8375] | 293 | closeonexec(fd); |
---|
[26464] | 294 | |
---|
[44177] | 295 | //workarounnd |
---|
| 296 | if(checkchipset("HI3798MV200") == 1) |
---|
| 297 | { |
---|
| 298 | printf("---> setframebuffer(1280, 720, 1280, 2880, 32)\n"); |
---|
| 299 | setframebuffer(1280, 720, 1280, 2880, 32); |
---|
| 300 | } |
---|
[44330] | 301 | if(frameb1 == 1) |
---|
| 302 | { |
---|
[44347] | 303 | printf("---> setframebuffer(1920, 1080, 1920, 2160, 32);\n"); |
---|
| 304 | setframebuffer(1920, 1080, 1920, 2160, 32); |
---|
[44330] | 305 | } |
---|
[44177] | 306 | |
---|
[44330] | 307 | |
---|
[7497] | 308 | if(ioctl(fd, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) |
---|
| 309 | { |
---|
| 310 | perr("ioctl FBIOGET_VSCREENINFO failed"); |
---|
| 311 | close(fd); |
---|
| 312 | return NULL; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | if(ioctl(fd, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) |
---|
| 316 | { |
---|
| 317 | perr("ioctl FBIOGET_FSCREENINFO failed"); |
---|
| 318 | close(fd); |
---|
| 319 | return NULL; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | if(!(mmapfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0))) |
---|
| 323 | { |
---|
| 324 | perr("mmap framebuffer"); |
---|
| 325 | close(fd); |
---|
| 326 | return NULL; |
---|
| 327 | } |
---|
| 328 | |
---|
[26549] | 329 | debug(444, "%dk video mem", fix_screeninfo.smem_len/1024); |
---|
[40672] | 330 | unsigned long data_phys = 0; |
---|
[26549] | 331 | #ifdef MIPSEL |
---|
[40672] | 332 | data_phys = fix_screeninfo.smem_start; |
---|
[40589] | 333 | #ifdef CONFIG_ION |
---|
| 334 | /* allocate accel memory here... its independent from the framebuffer */ |
---|
| 335 | ion = open("/dev/ion", O_RDWR | O_CLOEXEC); |
---|
| 336 | if (ion >= 0) |
---|
| 337 | { |
---|
| 338 | struct ion_allocation_data alloc_data; |
---|
| 339 | struct ion_fd_data share_data; |
---|
| 340 | struct ion_handle_data free_data; |
---|
| 341 | struct ion_phys_data phys_data; |
---|
| 342 | int ret; |
---|
[40591] | 343 | |
---|
[40589] | 344 | debug(444,"Using ION allocator"); |
---|
| 345 | |
---|
| 346 | memset(&alloc_data, 0, sizeof(alloc_data)); |
---|
| 347 | alloc_data.len = ACCEL_MEM_SIZE; |
---|
| 348 | alloc_data.align = 4096; // 4k aligned |
---|
| 349 | alloc_data.heap_id_mask = ION_HEAP_ID_MASK; |
---|
| 350 | ret = ioctl(ion, ION_IOC_ALLOC, &alloc_data); |
---|
| 351 | if (ret < 0) |
---|
| 352 | { |
---|
| 353 | err("ION_IOC_ALLOC failed"); |
---|
| 354 | err("failed to allocate accel memory!!!"); |
---|
[40598] | 355 | return NULL; |
---|
[40589] | 356 | } |
---|
| 357 | |
---|
| 358 | memset(&phys_data, 0, sizeof(phys_data)); |
---|
| 359 | phys_data.handle = alloc_data.handle; |
---|
| 360 | ret = ioctl(ion, ION_IOC_PHYS, &phys_data); |
---|
| 361 | if (ret < 0) |
---|
| 362 | { |
---|
| 363 | err("ION_IOC_PHYS failed"); |
---|
| 364 | goto err_ioc_free; |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | memset(&share_data, 0, sizeof(share_data)); |
---|
| 368 | share_data.handle = alloc_data.handle; |
---|
| 369 | ret = ioctl(ion, ION_IOC_SHARE, &share_data); |
---|
| 370 | if (ret < 0) |
---|
| 371 | { |
---|
| 372 | err("ION_IOC_SHARE failed"); |
---|
| 373 | goto err_ioc_free; |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | memset(&free_data, 0, sizeof(free_data)); |
---|
| 377 | free_data.handle = alloc_data.handle; |
---|
| 378 | if (ioctl(ion, ION_IOC_FREE, &free_data) < 0) |
---|
| 379 | err("ION_IOC_FREE failed"); |
---|
| 380 | |
---|
| 381 | m_accel_fd = share_data.fd; |
---|
| 382 | lfb=(unsigned char*)mmap(0, ACCEL_MEM_SIZE, PROT_WRITE|PROT_READ, MAP_SHARED, share_data.fd, 0); |
---|
| 383 | |
---|
| 384 | if (lfb) |
---|
| 385 | { |
---|
| 386 | debug(444,"%dkB available for acceleration surfaces (via ION).", ACCEL_MEM_SIZE); |
---|
[40619] | 387 | |
---|
[40622] | 388 | node = addfb(FB, devnr, var_screeninfo.xres, var_screeninfo.yres, var_screeninfo.bits_per_pixel / 8, fd, mmapfb, fix_screeninfo.smem_len, data_phys); |
---|
[40613] | 389 | skinfb = addfb(SKINFB, 0, getconfigint("skinfbwidth", NULL), getconfigint("skinfbheight", NULL), 4, share_data.fd, lfb, ACCEL_MEM_SIZE, phys_data.addr); |
---|
[40619] | 390 | accelfb = addfb(ACCELFB, 0, (ACCEL_MEM_SIZE-(skinfb->width*skinfb->height*4)) / 4, 1, 4, share_data.fd, skinfb->fb + skinfb->varfbsize, ACCEL_MEM_SIZE, skinfb->data_phys + skinfb->varfbsize); |
---|
[40589] | 391 | } |
---|
| 392 | else |
---|
| 393 | { |
---|
| 394 | close(m_accel_fd); |
---|
[40600] | 395 | err("mmap lfb failed"); |
---|
[40589] | 396 | err_ioc_free: |
---|
| 397 | err("failed to allocate accel memory via ION!!!"); |
---|
| 398 | m_accel_fd = -1; |
---|
| 399 | memset(&free_data, 0, sizeof(free_data)); |
---|
| 400 | free_data.handle = alloc_data.handle; |
---|
| 401 | if (ioctl(ion, ION_IOC_FREE, &free_data) < 0) |
---|
| 402 | err("ION_IOC_FREE"); |
---|
| 403 | } |
---|
| 404 | close(ion); |
---|
| 405 | } |
---|
| 406 | else |
---|
| 407 | { |
---|
| 408 | err("failed to open ION device node! no allocate accel memory available !!"); |
---|
| 409 | m_accel_fd = -1; |
---|
| 410 | } |
---|
| 411 | if (!lfb) |
---|
| 412 | { |
---|
| 413 | err("mmap"); |
---|
| 414 | goto nolfb; |
---|
| 415 | } |
---|
| 416 | #else |
---|
[26471] | 417 | lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0); |
---|
| 418 | if (!lfb) |
---|
| 419 | { |
---|
[40589] | 420 | err("mmap"); |
---|
[26471] | 421 | goto nolfb; |
---|
| 422 | } |
---|
| 423 | |
---|
[26495] | 424 | if (var_screeninfo.bits_per_pixel != 32) |
---|
[26471] | 425 | { |
---|
[26549] | 426 | debug(444, "Only 32 bit per pixel supported. Framebuffer currently use %d", var_screeninfo.bits_per_pixel); |
---|
[26471] | 427 | closefb(); |
---|
| 428 | return 0; |
---|
| 429 | } |
---|
[40589] | 430 | #endif |
---|
[40671] | 431 | #endif |
---|
[40589] | 432 | #ifndef CONFIG_ION |
---|
[7694] | 433 | if(devnr == 0) |
---|
[36560] | 434 | node = addfb(FB, devnr, var_screeninfo.xres, var_screeninfo.yres, var_screeninfo.bits_per_pixel / 8, fd, mmapfb, fix_screeninfo.smem_len, data_phys); |
---|
[7694] | 435 | if(devnr == 1) |
---|
[36560] | 436 | node = addfb(FB1, devnr, var_screeninfo.xres, var_screeninfo.yres, var_screeninfo.bits_per_pixel / 8, fd, mmapfb, fix_screeninfo.smem_len, data_phys); |
---|
[40671] | 437 | |
---|
[40589] | 438 | #endif |
---|
[7694] | 439 | |
---|
[7497] | 440 | #else |
---|
| 441 | mmapfb = malloc(16 * 1024 * 1024); |
---|
[7694] | 442 | if(devnr == 0) |
---|
[36560] | 443 | node = addfb(FB, devnr, getconfigint("skinfbwidth", NULL), getconfigint("skinfbheight", NULL), 4, -1, mmapfb, 16*1024*1024, 0); |
---|
[7694] | 444 | if(devnr == 1) |
---|
[36560] | 445 | node = addfb(FB1, devnr, getconfigint("skinfbwidth", NULL), getconfigint("skinfbheight", NULL), 4, -1, mmapfb, 16*1024*1024, 0); |
---|
[7694] | 446 | |
---|
[7497] | 447 | #endif |
---|
[7694] | 448 | |
---|
| 449 | return node; |
---|
[26434] | 450 | |
---|
[26549] | 451 | #ifdef MIPSEL |
---|
[26434] | 452 | nolfb: |
---|
[26464] | 453 | if (fd >= 0) |
---|
[26434] | 454 | { |
---|
[26464] | 455 | close(fd); |
---|
| 456 | fd = -1; |
---|
[26434] | 457 | } |
---|
[26464] | 458 | |
---|
[26549] | 459 | debug(444, "framebuffer not available."); |
---|
| 460 | #endif |
---|
[26434] | 461 | return 0; |
---|
| 462 | // blinking work end |
---|
[7497] | 463 | } |
---|
| 464 | |
---|
| 465 | void closefb() |
---|
| 466 | { |
---|
[26495] | 467 | |
---|
[26549] | 468 | #ifdef MIPSEL |
---|
[26495] | 469 | if(lfb) |
---|
[26464] | 470 | { |
---|
[26549] | 471 | debug(444, "ms_sync"); |
---|
[26495] | 472 | msync(lfb, fix_screeninfo.smem_len, MS_SYNC); |
---|
| 473 | munmap(lfb, fix_screeninfo.smem_len); |
---|
[26464] | 474 | } |
---|
[26495] | 475 | if(fb->fd >= 0) |
---|
| 476 | { |
---|
[26549] | 477 | debug(444, "close"); |
---|
[26495] | 478 | disablemanualblit(); |
---|
| 479 | close(fb->fd); |
---|
| 480 | fb->fd = -1; |
---|
| 481 | } |
---|
| 482 | #endif |
---|
[26464] | 483 | |
---|
[7497] | 484 | if(fb != NULL) |
---|
| 485 | { |
---|
| 486 | if(fb->fb != NULL) |
---|
| 487 | munmap(fb->fb, fb->fixfbsize); |
---|
| 488 | if(fb->fd != -1) |
---|
| 489 | close(fb->fd); |
---|
[9594] | 490 | #ifdef NOFB |
---|
[15342] | 491 | free(fb->fb); |
---|
[7497] | 492 | #endif |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | |
---|
[9592] | 496 | void clearfball() |
---|
| 497 | { |
---|
[15342] | 498 | if(fb != NULL && fb->fb != NULL) |
---|
[9592] | 499 | memset(fb->fb, 0, fb->fixfbsize); |
---|
| 500 | } |
---|
| 501 | |
---|
[7497] | 502 | void clearfb(struct fb *node) |
---|
| 503 | { |
---|
| 504 | if(node != NULL) |
---|
| 505 | memset(node->fb, 0, node->varfbsize); |
---|
| 506 | } |
---|
| 507 | |
---|
[14636] | 508 | void blitfb(int flag) |
---|
| 509 | { |
---|
| 510 | blitfb2(skinfb, flag); |
---|
| 511 | } |
---|
| 512 | |
---|
[24090] | 513 | void blitfb1() |
---|
| 514 | { |
---|
| 515 | blitfb2(skinfb, 0); |
---|
| 516 | } |
---|
| 517 | |
---|
[20751] | 518 | //flag 0: del skinfb |
---|
| 519 | //flag 1: don't del skinfb |
---|
| 520 | void changefbresolution(char *value, int flag) |
---|
[7497] | 521 | { |
---|
[26549] | 522 | debug(444, "fb->colbytes: %d", fb->colbytes); |
---|
| 523 | #ifdef MIPSEL |
---|
[43066] | 524 | return; |
---|
[26495] | 525 | #endif |
---|
[43650] | 526 | |
---|
[7497] | 527 | if(ostrcmp("pal", value) == 0) |
---|
| 528 | { |
---|
| 529 | fb->width = 720; |
---|
| 530 | fb->height = 576; |
---|
[26471] | 531 | fb->pitch = fb->width * fb->colbytes; |
---|
[7497] | 532 | } |
---|
| 533 | else if(ostrncmp("576", value, 3) == 0) |
---|
| 534 | { |
---|
| 535 | fb->width = 720; |
---|
| 536 | fb->height = 576; |
---|
[26471] | 537 | fb->pitch = fb->width * fb->colbytes; |
---|
[7497] | 538 | } |
---|
| 539 | else if(ostrncmp("720", value, 3) == 0) |
---|
| 540 | { |
---|
| 541 | fb->width = 1280; |
---|
| 542 | fb->height = 720; |
---|
[26471] | 543 | fb->pitch = fb->width * fb->colbytes; |
---|
[7497] | 544 | } |
---|
| 545 | else if(ostrncmp("1080", value, 4) == 0) |
---|
| 546 | { |
---|
| 547 | fb->width = 1920; |
---|
| 548 | fb->height = 1080; |
---|
[26471] | 549 | fb->pitch = fb->width * fb->colbytes; |
---|
[7497] | 550 | } |
---|
[8451] | 551 | if(skinfb == fb) |
---|
| 552 | { |
---|
| 553 | skin->width = skinfb->width; |
---|
| 554 | skin->height = skinfb->height; |
---|
| 555 | skin->iwidth = skinfb->width; |
---|
| 556 | skin->iheight = skinfb->height; |
---|
| 557 | skin->rwidth = skinfb->width; |
---|
| 558 | skin->rheight = skinfb->height; |
---|
| 559 | } |
---|
| 560 | clearfb(fb); |
---|
[20751] | 561 | if(flag == 0) clearfb(skinfb); |
---|
[7497] | 562 | } |
---|
| 563 | |
---|
[14364] | 564 | static void write_PNG(unsigned char *outbuffer, char *filename, |
---|
| 565 | int width, int height, int interlace) |
---|
| 566 | { |
---|
| 567 | int i; |
---|
| 568 | int bit_depth=0, color_type; |
---|
| 569 | png_bytep row_pointers[height]; |
---|
| 570 | png_structp png_ptr; |
---|
| 571 | png_infop info_ptr; |
---|
| 572 | FILE *outfile = fopen(filename, "wb"); |
---|
| 573 | |
---|
| 574 | for (i=0; i<height; i++) |
---|
| 575 | row_pointers[i] = outbuffer + i * 4 * width; |
---|
| 576 | |
---|
| 577 | if (!outfile) |
---|
| 578 | { |
---|
| 579 | fprintf (stderr, "Error: Couldn't fopen %s.\n", filename); |
---|
| 580 | exit(EXIT_FAILURE); |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, |
---|
| 584 | (png_voidp) NULL, (png_error_ptr) NULL, (png_error_ptr) NULL); |
---|
| 585 | |
---|
| 586 | if (!png_ptr) |
---|
| 587 | err("Error: Couldn't create PNG write struct."); |
---|
| 588 | |
---|
| 589 | info_ptr = png_create_info_struct(png_ptr); |
---|
| 590 | if (!info_ptr) |
---|
| 591 | { |
---|
| 592 | png_destroy_write_struct(&png_ptr, (png_infopp) NULL); |
---|
| 593 | err("Error: Couldn't create PNG info struct."); |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | png_init_io(png_ptr, outfile); |
---|
| 597 | |
---|
| 598 | png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); |
---|
| 599 | |
---|
| 600 | bit_depth = 8; |
---|
| 601 | color_type = PNG_COLOR_TYPE_RGB_ALPHA; |
---|
| 602 | //color_type = PNG_COLOR_TYPE_RGB; |
---|
| 603 | png_set_invert_alpha(png_ptr); |
---|
| 604 | png_set_bgr(png_ptr); |
---|
| 605 | |
---|
| 606 | png_set_IHDR(png_ptr, info_ptr, width, height, |
---|
| 607 | bit_depth, color_type, interlace, |
---|
| 608 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
---|
| 609 | |
---|
| 610 | png_write_info(png_ptr, info_ptr); |
---|
| 611 | |
---|
| 612 | printf ("Now writing PNG file\n"); |
---|
| 613 | |
---|
| 614 | png_write_image(png_ptr, row_pointers); |
---|
| 615 | |
---|
| 616 | png_write_end(png_ptr, info_ptr); |
---|
| 617 | /* puh, done, now freeing memory... */ |
---|
| 618 | png_destroy_write_struct(&png_ptr, &info_ptr); |
---|
| 619 | |
---|
| 620 | if (outfile != NULL) |
---|
| 621 | (void) fclose(outfile); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | static void convert_and_write(unsigned char *inbuffer, char *filename, |
---|
| 625 | int width, int height, int bits, int interlace) |
---|
| 626 | { |
---|
| 627 | size_t bufsize = (size_t) width * height * 4; |
---|
| 628 | |
---|
| 629 | unsigned char *outbuffer = malloc(bufsize); |
---|
| 630 | |
---|
| 631 | if (outbuffer == NULL) |
---|
| 632 | err("Not enough memory"); |
---|
| 633 | |
---|
| 634 | memset(outbuffer, 0, bufsize); |
---|
| 635 | write_PNG(inbuffer, filename, width, height, interlace); |
---|
| 636 | (void) free(outbuffer); |
---|
| 637 | } |
---|
| 638 | |
---|
[14709] | 639 | int fb2png(unsigned char *buf_p, int width, int height, char *outfile) |
---|
[14364] | 640 | { |
---|
| 641 | int interlace = PNG_INTERLACE_ADAM7; |
---|
| 642 | int bitdepth = 32; |
---|
| 643 | |
---|
| 644 | size_t help = 0; |
---|
| 645 | while(help <= (width * height * 4)) |
---|
| 646 | { |
---|
| 647 | buf_p[help+3] = 0x00; |
---|
| 648 | help = help + 4; |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | convert_and_write(buf_p, outfile, width, height, bitdepth, interlace); |
---|
| 652 | |
---|
[16809] | 653 | return 0; |
---|
[14364] | 654 | } |
---|
| 655 | |
---|
[16809] | 656 | void pngforlcd(unsigned char *fbuffer, int width, int height) |
---|
[12751] | 657 | { |
---|
[16747] | 658 | fb2png(fbuffer, width, height, "/tmp/titanlcd.png"); |
---|
[12751] | 659 | } |
---|
| 660 | |
---|
[14672] | 661 | void write_FB_to_JPEG_file(unsigned char *inbuffer, int image_width, int image_height, char * filename, int quality) |
---|
[24696] | 662 | { |
---|
[14672] | 663 | size_t helpb = 0; |
---|
| 664 | size_t help = 0; |
---|
| 665 | unsigned char *helpbuffer = malloc(image_width*image_height*3); |
---|
| 666 | |
---|
| 667 | //delete alpha byte |
---|
| 668 | while(help <= (image_width*image_height*4)) |
---|
| 669 | { |
---|
[16924] | 670 | helpbuffer[helpb+0] = inbuffer[help+2]; |
---|
[14672] | 671 | helpbuffer[helpb+1] = inbuffer[help+1]; |
---|
[16924] | 672 | helpbuffer[helpb+2] = inbuffer[help+0]; |
---|
[14672] | 673 | help = help + 4; |
---|
| 674 | helpb = helpb + 3; |
---|
| 675 | } |
---|
| 676 | |
---|
| 677 | JSAMPLE *image_buffer = helpbuffer; |
---|
| 678 | struct jpeg_compress_struct cinfo; |
---|
| 679 | struct jpeg_error_mgr jerr; |
---|
| 680 | FILE * outfile; |
---|
| 681 | |
---|
| 682 | JSAMPROW row_pointer[1]; |
---|
| 683 | int row_stride; |
---|
| 684 | |
---|
| 685 | cinfo.err = jpeg_std_error(&jerr); |
---|
| 686 | jpeg_create_compress(&cinfo); |
---|
| 687 | if ((outfile = fopen(filename, "wb")) == NULL) { |
---|
| 688 | fprintf(stderr, "can't open %s\n", filename); |
---|
| 689 | exit(1); |
---|
| 690 | } |
---|
| 691 | jpeg_stdio_dest(&cinfo, outfile); |
---|
| 692 | cinfo.image_width = image_width; /* image width and height, in pixels */ |
---|
| 693 | cinfo.image_height = image_height; |
---|
| 694 | cinfo.input_components = 3; /* # of color components per pixel */ |
---|
| 695 | cinfo.in_color_space = JCS_RGB; |
---|
| 696 | |
---|
| 697 | jpeg_set_defaults(&cinfo); |
---|
| 698 | jpeg_set_quality(&cinfo, quality, TRUE); |
---|
| 699 | |
---|
| 700 | jpeg_start_compress(&cinfo, TRUE); |
---|
| 701 | row_stride = image_width * 3; |
---|
| 702 | |
---|
| 703 | while (cinfo.next_scanline < cinfo.image_height) { |
---|
| 704 | row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; |
---|
| 705 | (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | jpeg_finish_compress(&cinfo); |
---|
| 709 | fclose(outfile); |
---|
| 710 | jpeg_destroy_compress(&cinfo); |
---|
| 711 | |
---|
| 712 | free(helpbuffer); |
---|
| 713 | } |
---|
| 714 | |
---|
[43661] | 715 | int setframebuffer(int width, int height, int vwidth, int vheight, int bits) |
---|
| 716 | { |
---|
| 717 | struct fb_var_screeninfo var_screeninfo; |
---|
| 718 | int fd = -1; |
---|
| 719 | char *fbdev = getconfig("fbdev", NULL); |
---|
| 720 | |
---|
| 721 | if(fbdev == NULL) |
---|
| 722 | { |
---|
| 723 | err("failed to find fbdev in config file"); |
---|
| 724 | return -1; |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | fd = open(fbdev, O_RDWR); |
---|
| 728 | if(fd == -1) |
---|
| 729 | { |
---|
| 730 | perr("failed to open %s", fbdev); |
---|
| 731 | return -1; |
---|
| 732 | } |
---|
| 733 | |
---|
| 734 | if(ioctl(fd, FBIOGET_VSCREENINFO, &var_screeninfo) < 0) |
---|
| 735 | { |
---|
| 736 | err("failed to read VSCREENINFO"); |
---|
| 737 | close(fd); |
---|
| 738 | return -1; |
---|
| 739 | } |
---|
| 740 | |
---|
| 741 | var_screeninfo.xres = width; |
---|
| 742 | var_screeninfo.yres = height; |
---|
| 743 | var_screeninfo.xres_virtual = vwidth; |
---|
| 744 | var_screeninfo.yres_virtual = vheight; |
---|
| 745 | var_screeninfo.bits_per_pixel = bits; |
---|
| 746 | |
---|
| 747 | if(ioctl(fd, FBIOPUT_VSCREENINFO, &var_screeninfo) < 0) |
---|
| 748 | { |
---|
| 749 | err("failed to put VSCREENINFO"); |
---|
| 750 | close(fd); |
---|
| 751 | return -1; |
---|
| 752 | } |
---|
[44174] | 753 | |
---|
| 754 | printf("---> FBIOPUT_VSCREENINFO endet\n"); |
---|
| 755 | system("fbset"); |
---|
| 756 | |
---|
[43661] | 757 | close(fd); |
---|
| 758 | return 0; |
---|
| 759 | } |
---|
| 760 | |
---|
[43671] | 761 | #ifdef OEBUILD |
---|
| 762 | int saveframebuffer() |
---|
| 763 | { |
---|
| 764 | int fd = -1; |
---|
| 765 | char *fbdev = getconfig("fbdev", NULL); |
---|
| 766 | |
---|
| 767 | if(fbdev == NULL) |
---|
| 768 | { |
---|
| 769 | err("failed to find fbdev in config file"); |
---|
| 770 | return -1; |
---|
| 771 | } |
---|
| 772 | |
---|
| 773 | fd = open(fbdev, O_RDWR); |
---|
| 774 | if(fd == -1) |
---|
| 775 | { |
---|
| 776 | perr("failed to open %s", fbdev); |
---|
| 777 | return -1; |
---|
| 778 | } |
---|
[44177] | 779 | //workaround |
---|
| 780 | if(checkchipset("HI3798MV200") == 1) |
---|
| 781 | { |
---|
| 782 | printf("---> setframebuffer(1280, 720, 1280, 2880, 32)\n"); |
---|
| 783 | setframebuffer(1280, 720, 1280, 2880, 32); |
---|
| 784 | } |
---|
[44330] | 785 | if(frameb1 == 1) |
---|
| 786 | { |
---|
[44347] | 787 | printf("---> setframebuffer(1920, 1080, 1920, 2160, 32)\n"); |
---|
| 788 | setframebuffer(1920, 1080, 1920, 2160, 32); |
---|
[44330] | 789 | } |
---|
[43671] | 790 | |
---|
| 791 | if(ioctl(fd, FBIOGET_VSCREENINFO, &save_var_screeninfo) < 0) |
---|
| 792 | { |
---|
| 793 | err("failed to read VSCREENINFO"); |
---|
| 794 | close(fd); |
---|
| 795 | return -1; |
---|
| 796 | } |
---|
| 797 | |
---|
| 798 | close(fd); |
---|
| 799 | return 0; |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | int restoreframebuffer() |
---|
| 803 | { |
---|
| 804 | int fd = -1; |
---|
| 805 | char *fbdev = getconfig("fbdev", NULL); |
---|
| 806 | |
---|
| 807 | if(fbdev == NULL) |
---|
| 808 | { |
---|
| 809 | err("failed to find fbdev in config file"); |
---|
| 810 | return -1; |
---|
| 811 | } |
---|
| 812 | |
---|
| 813 | fd = open(fbdev, O_RDWR); |
---|
| 814 | if(fd == -1) |
---|
| 815 | { |
---|
| 816 | perr("failed to open %s", fbdev); |
---|
| 817 | return -1; |
---|
| 818 | } |
---|
| 819 | |
---|
| 820 | if(ioctl(fd, FBIOPUT_VSCREENINFO, &save_var_screeninfo) < 0) |
---|
| 821 | { |
---|
| 822 | err("failed to write VSCREENINFO"); |
---|
| 823 | close(fd); |
---|
| 824 | return -1; |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | close(fd); |
---|
| 828 | return 0; |
---|
| 829 | } |
---|
[7497] | 830 | #endif |
---|
[43671] | 831 | |
---|
| 832 | |
---|
| 833 | #endif |
---|