static htsmsg_t * hts_settings_load_one(const char *filename) { ssize_t n; char *mem; fb_file *fp; htsmsg_t *r = NULL; /* Open */ if (!(fp = fb_open(filename, 1, 0))) return NULL; /* Load data */ mem = malloc(fb_size(fp)+1); n = fb_read(fp, mem, fb_size(fp)); if (n >= 0) mem[n] = 0; /* Decode */ if(n == fb_size(fp)) r = htsmsg_json_deserialize(mem); /* Close */ fb_close(fp); free(mem); return r; }
static int fb_open(struct FbInfo *fb, const char* fbfilename) { fb->fd = open(fbfilename, O_RDWR); if (fb->fd < 0) { return -1; } if (ioctl(fb->fd, FBIOGET_FSCREENINFO, &fb->fix) < 0) goto fail; if (ioctl(fb->fd, FBIOGET_VSCREENINFO, &fb->var) < 0) goto fail; fb->var.xoffset = 0; fb->var.yoffset = 0; ioctl (fb->fd, FBIOPAN_DISPLAY, &(fb->var)); ftk_logi("FbInfo: %s\n", fbfilename); ftk_logi("FbInfo: xres=%d yres=%d bits_per_pixel=%d mem_size=%d\n", fb->var.xres, fb->var.yres, fb->var.bits_per_pixel, fb_size(fb)); ftk_logi("FbInfo: red(%d %d) green(%d %d) blue(%d %d)\n", fb->var.red.offset, fb->var.red.length, fb->var.green.offset, fb->var.green.length, fb->var.blue.offset, fb->var.blue.length); #ifdef FTK_FB_NOMMAP //uclinux doesn't support MAP_SHARED or MAP_PRIVATE with PROT_WRITE, so no mmap at all is simpler fb->bits = fb->fix.smem_start; #else fb->bits = mmap(0, fb_size(fb), PROT_READ | PROT_WRITE, MAP_SHARED, fb->fd, 0); #endif if (fb->bits == MAP_FAILED) { ftk_logi("map framebuffer failed.\n"); goto fail; } memset(fb->bits, 0xff, fb_size(fb)); ftk_logi("xres_virtual =%d yres_virtual=%d xpanstep=%d ywrapstep=%d\n", fb->var.xres_virtual, fb->var.yres_virtual, fb->fix.xpanstep, fb->fix.ywrapstep); return 0; fail: ftk_logi("%s is not a framebuffer.\n", fbfilename); close(fb->fd); return -1; }
FrameBuffer* framebuffer_create(const char* file_name) { FrameBuffer* fb = (FrameBuffer*)calloc(1, sizeof(FrameBuffer)); do { if((fb->fd = open(file_name, O_RDWR)) < 0) break; if(ioctl(fb->fd, FBIOGET_FSCREENINFO, &fb->fix) < 0) break; if(ioctl(fb->fd, FBIOGET_VSCREENINFO, &fb->var) < 0) break; fb->buffer = mmap(0, fb_size(fb), PROT_READ | PROT_WRITE, MAP_SHARED, fb->fd, 0); if(fb->buffer == MAP_FAILED) break; printf("%s: width=%d height=%d\n", file_name, fb_width(fb), fb_height(fb)); return fb; }while(0); if(fb != NULL) { if(fb->fd > 0) { close(fb->fd); } free(fb); } return NULL; }
void drm_copy_data_to_fb(drm_overlay_fb *fb, uint8_t *data, int swap) { if (!format_planar(fb->format)) { copy_plane_data(fb->bo_mmap, data, fb->width, fb->height, fb->pitch, fb_pitch(fb->format, fb->width)); return; } copy_plane_data(fb->bo_y_mmap, data, fb->width, fb->height, fb->pitch_y, fb_pitch(fb->format, fb->width)); data += fb_size(fb->format, fb->width, fb->height); copy_plane_data(swap ? fb->bo_cb_mmap : fb->bo_cr_mmap, data, fb_width_c(fb->format, fb->width), fb_height_c(fb->format, fb->height), swap ? fb->pitch_cb : fb->pitch_cr, fb_pitch_c(fb->format, fb->width)); data += fb_size_c(fb->format, fb->width, fb->height); copy_plane_data(swap ? fb->bo_cr_mmap : fb->bo_cb_mmap, data, fb_width_c(fb->format, fb->width), fb_height_c(fb->format, fb->height), swap ? fb->pitch_cr : fb->pitch_cb, fb_pitch_c(fb->format, fb->width)); }
int fih_dump_framebuffer(char *filename) { struct fb_info *info = NULL; struct file *filp = NULL; unsigned char *bits = NULL; int count = 0, err = 0; mm_segment_t old_fs = get_fs(); set_fs (get_ds()); printk(KERN_INFO "[DISPLAY] %s\n", __func__); info = registered_fb[0]; if (!info) { printk(KERN_WARNING "%s: Can not access framebuffer\n", __func__); return -ENODEV; } bits = (unsigned char *)(info->screen_base); filp = filp_open(filename, O_RDWR | O_CREAT, 0644); if (IS_ERR(filp)) { printk(KERN_WARNING "%s: Can not open %s\n", __func__, filename); err = -ENOENT; goto error1; } #ifdef CONFIG_FB_MSM_TRIPLE_BUFFER count = 3*fb_size(info); #else count = 2*fb_size(info); #endif if (filp->f_op->write(filp, bits, count, &filp->f_pos) < 0) { printk(KERN_WARNING "%s: write file error?\n", __func__); err = -EIO; } filp_close(filp, NULL); error1: set_fs(old_fs); return err; }
void framebuffer_destroy(FrameBuffer* fb) { if(fb != NULL) { munmap(fb->buffer, fb_size(fb)); close(fb->fd); free(fb); } return; }
static void fb_close(struct FbInfo *fb) { if(fb != NULL) { munmap(fb->bits, fb_size(fb)); close(fb->fd); FTK_FREE(fb); } return; }
static int fb_open(struct FB *fb) { fb->fd = open("/dev/graphics/fb0", O_RDWR); if (fb->fd < 0) return -1; if (ioctl(fb->fd, FBIOGET_FSCREENINFO, &fb->fi) < 0) goto fail; if (ioctl(fb->fd, FBIOGET_VSCREENINFO, &fb->vi) < 0) goto fail; fb->bits = mmap(0, fb_size(fb), PROT_READ | PROT_WRITE, MAP_SHARED, fb->fd, 0); if (fb->bits == MAP_FAILED) goto fail; return 0; fail: close(fb->fd); return -1; }
static void fb_close(struct FB *fb) { munmap(fb->bits, fb_size(fb)); close(fb->fd); }
/* 565RLE image format: [count(2 bytes), rle(2 bytes)] */ int load_565rle_image(char *filename) { struct fb_info *info; int fd, err = 0; unsigned count, max, width, stride, line_pos = 0; unsigned short *data, *ptr; unsigned char *bits; info = registered_fb[0]; if (!info) { printk(KERN_WARNING "%s: Can not access framebuffer\n", __func__); return -ENODEV; } fd = sys_open(filename, O_RDONLY, 0); if (fd < 0) { printk(KERN_WARNING "%s: Can not open %s\n", __func__, filename); return -ENOENT; } count = sys_lseek(fd, (off_t)0, 2); if (count <= 0) { err = -EIO; goto err_logo_close_file; } sys_lseek(fd, (off_t)0, 0); data = kmalloc(count, GFP_KERNEL); if (!data) { printk(KERN_WARNING "%s: Can not alloc data\n", __func__); err = -ENOMEM; goto err_logo_close_file; } if (sys_read(fd, (char *)data, count) != count) { err = -EIO; goto err_logo_free_data; } width = fb_width(info); stride = fb_linewidth(info); max = width * fb_height(info); ptr = data; bits = (unsigned char *)(info->screen_base); while (count > 3) { int n = ptr[0]; if (n > max) break; max -= n; while (n > 0) { unsigned int j = (line_pos + n > width ? width-line_pos : n); if (fb_depth(info) == 2) memset16(bits, swab16(ptr[1]), j << 1); else { unsigned int widepixel = ptr[1]; /* * Format is RGBA, but fb is big * endian so we should make widepixel * as ABGR. */ widepixel = /* red : f800 -> 000000f8 */ (widepixel & 0xf800) >> 8 | /* green : 07e0 -> 0000fc00 */ (widepixel & 0x07e0) << 5 | /* blue : 001f -> 00f80000 */ (widepixel & 0x001f) << 19; memset32(bits, widepixel, j << 2); } bits += j * fb_depth(info); line_pos += j; n -= j; if (line_pos == width) { bits += (stride-width) * fb_depth(info); line_pos = 0; } } ptr += 2; count -= 4; } dmac_flush_range(info->screen_base, info->screen_base + fb_size(info)); err_logo_free_data: kfree(data); err_logo_close_file: sys_close(fd); return err; }