void fb_switch(int n_sig) { static int switching=0; signal(SIGUSR2, fb_switch); /* reset signal handler */ if(switching && (n_sig == SIGUSR2)) return; if(switching == 0) switching = 1; if(FB_visible) { b_store = (char*)malloc(visiblesize); if(b_store == NULL) fprintf(stderr,"FBlib:cannot use backing store for VT switch"); else memcpy(b_store, fbp, visiblesize); fb_unmap(); fbp = b_store; FB_visible = 0; if(ioctl(TTY,VT_RELDISP,1) < 0) { fprintf(stderr,"FBlib:ioctl VT_RELDISP failed: %s \n",strerror(errno)); fb_map(); free(b_store); FB_visible=1; } } else { if(ioctl(TTY,VT_RELDISP,VT_ACKACQ) < 0) { fprintf(stderr,"FBlib:ioctl VT_RELDISP failed: %s (FATAL error)\n",strerror(errno)); FB_exit(); exit(1); } fb_map(); memcpy(fbp, b_store, visiblesize); free(b_store); b_store=NULL; FB_visible=1; } switching=0; return; }
void fb_init(void) { Debug("fb_init()\n"); fb_open(); fb_get_var(); memcpy(&saved_var, &fb_var, sizeof(struct fb_var_screeninfo)); //saved_var = fb_var; if (fb_var.xoffset || fb_var.yoffset || fb_var.accel_flags) { fb_var.xoffset = 0; fb_var.yoffset = 0; fb_var.accel_flags = 0; fb_set_var(); } fb_get_fix(); var_fix_validate(); memcpy(&saved_fix, &fb_fix, sizeof(struct fb_var_screeninfo)); //saved_fix = fb_fix; switch (fb_fix.visual) { case FB_VISUAL_MONO01: case FB_VISUAL_MONO10: case FB_VISUAL_TRUECOLOR: /* no colormap */ break; case FB_VISUAL_PSEUDOCOLOR: case FB_VISUAL_STATIC_PSEUDOCOLOR: cmap_init(1<<fb_var.bits_per_pixel); break; case FB_VISUAL_DIRECTCOLOR: cmap_init(1<<(max(max(fb_var.red.length, fb_var.green.length), max(fb_var.blue.length, fb_var.transp.length)))); break; } if (fb_cmap.len) { fb_get_cmap(); saved_cmap = fb_cmap; ALLOC_AND_SAVE_COMPONENT(red); ALLOC_AND_SAVE_COMPONENT(green); ALLOC_AND_SAVE_COMPONENT(blue); if (fb_cmap.transp) ALLOC_AND_SAVE_COMPONENT(transp); } fb_map(); fb_save(); fb_clear(); }
int fb_device_open(hw_module_t const *module, const char *name, hw_device_t **device) { alloc_device_t *gralloc_device; int err; err = gralloc_open(module, &gralloc_device); if (err < 0) return err; /* Initialize our state here */ fb_context_t *dev = (fb_context_t *)malloc(sizeof *dev); memset(dev, 0, sizeof *dev); /* Initialize the procs */ dev->device.common.tag = HARDWARE_DEVICE_TAG; dev->device.common.version = 0; dev->device.common.module = const_cast<hw_module_t *>(module); dev->device.common.close = fb_close; dev->device.setSwapInterval = fb_setSwapInterval; dev->device.post = fb_post; dev->device.setUpdateRect = 0; private_module_t *m = (private_module_t*)module; err = fb_map(m); if (err < 0) return err; const_cast<uint32_t&>(dev->device.flags) = 0; const_cast<uint32_t&>(dev->device.width) = m->mode->hdisplay; const_cast<uint32_t&>(dev->device.height) = m->mode->vdisplay; const_cast<int&>(dev->device.stride) = m->stride; const_cast<int&>(dev->device.format) = HAL_PIXEL_FORMAT_RGB_565; const_cast<float&>(dev->device.xdpi) = m->xdpi; const_cast<float&>(dev->device.ydpi) = m->ydpi; const_cast<float&>(dev->device.fps) = m->fps; const_cast<int&>(dev->device.minSwapInterval) = 1; const_cast<int&>(dev->device.maxSwapInterval) = 1; *device = &dev->device.common; return 0; }
int FB_initlib(char *dev) { int ioctl_err; char *errstr; struct vt_mode vtmode; if(!strcmp(dev, "")) dev = "/dev/fb0"; fbufd = open(dev, O_RDWR); /* Open framebuffer device */ if(fbufd < 0) { errstr = strerror(errno); fprintf(stderr, "FBlib:open %s failed: %s \n", dev, errstr); return -1; } ioctl_err = ioctl(fbufd,FBIOGET_FSCREENINFO,&fb_fix_info); /* Get fixed informations */ if(ioctl_err < 0) { errstr = strerror(errno); fprintf(stderr,"FBlib:ioctl FBIOGET_FSCREENINFO failed: %s \n",errstr); return IOCTL_ERR; } /* Get backup variable infos */ ioctl_err = ioctl(fbufd,FBIOGET_VSCREENINFO,&backup_var_info); /* Get changeable variable infos */ ioctl_err = ioctl(fbufd,FBIOGET_VSCREENINFO,&work_var_info); if(ioctl_err < 0) { errstr=strerror(errno); fprintf(stderr,"FBlib:ioctl FBIOGET_VSCREENINFO failed: %s \n",errstr); return IOCTL_ERR; } work_var_info.xoffset = 0; work_var_info.yoffset = 0; ioctl_err = ioctl(fbufd,FBIOPUT_VSCREENINFO,&work_var_info); if(ioctl_err < 0) { errstr = strerror(errno); fprintf(stderr,"FBlib:ioctl FBIOPUT_VSCREENINFO failed: %s \n",errstr); return IOCTL_ERR; } screensize = fb_fix_info.smem_len; /* size in bytes of the virtual screen */ visiblesize = work_var_info.xres * work_var_info.yres * (work_var_info.bits_per_pixel/8); ioctl_err = ioctl(TTY, VT_GETMODE, &vtmode); if(ioctl_err < 0) { errstr = strerror(errno); fprintf(stderr,"FBlib:ioctl VT_GETMODE failed: %s \n",errstr); return IOCTL_ERR; } vtmode.mode = VT_PROCESS; vtmode.relsig = SIGUSR2; vtmode.acqsig = SIGUSR2; signal(SIGUSR2, fb_switch); ioctl_err = ioctl(TTY, VT_SETMODE, &vtmode); if(ioctl_err < 0) { errstr = strerror(errno); fprintf(stderr,"FBlib:ioctl VT_SETMODE failed: %s \n",errstr); return IOCTL_ERR; } ioctl_err = fb_map(); if(ioctl_err < 0) return ioctl_err; FB_change_font(DEFAULT_FONT); inc_x = work_var_info.bits_per_pixel/8; inc_y = fb_fix_info.line_length; return OK; }