📄 fbvideo.c
字号:
tty0_fd = open("/dev/tty", O_RDWR, 0); if ( tty0_fd >= 0 ) { ioctl(tty0_fd, TIOCNOTTY, 0); close(tty0_fd); } } } } if ( keyboard_fd < 0 ) { /* Last resort, maybe our tty is a usable VT */ current_vt = 0; keyboard_fd = open("/dev/tty", O_RDWR); }#ifdef DEBUG_KEYBOARD fprintf(stderr, "Current VT: %d\n", current_vt);#endif /* Make sure that our input is a console terminal */ { int dummy; if ( ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0 ) { close(keyboard_fd); keyboard_fd = -1; GAL_SetError("Unable to open a console terminal"); } } }#endif return(keyboard_fd);}static int FB_VideoInit(_THIS, GAL_PixelFormat *vformat){ struct fb_fix_screeninfo finfo; struct fb_var_screeninfo vinfo; int i, j; int current_index; unsigned int current_w; unsigned int current_h; const char *GAL_fbdev; /* Initialize the library */ GAL_fbdev = getenv("FRAMEBUFFER"); if ( GAL_fbdev == NULL ) { GAL_fbdev = "/dev/fb0"; } console_fd = open(GAL_fbdev, O_RDWR, 0); if ( console_fd < 0 ) { GAL_SetError("Unable to open %s", GAL_fbdev); return(-1); } /* Get the type of video hardware */ if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { GAL_SetError("Couldn't get console hardware info"); FB_VideoQuit(this); return(-1); } switch (finfo.type) { case FB_TYPE_PACKED_PIXELS: /* Supported, no worries.. */ break;#ifdef VGA16_FBCON_SUPPORT case FB_TYPE_VGA_PLANES: /* VGA16 is supported, but that's it */ if ( finfo.type_aux == FB_AUX_VGA_PLANES_VGA4 ) { if ( ioperm(0x3b4, 0x3df - 0x3b4 + 1, 1) < 0 ) { GAL_SetError("No I/O port permissions"); FB_VideoQuit(this); return(-1); } this->SetVideoMode = FB_SetVGA16Mode; break; } /* Fall through to unsupported case */#endif /* VGA16_FBCON_SUPPORT */ default: GAL_SetError("Unsupported console hardware"); FB_VideoQuit(this); return(-1); } switch (finfo.visual) { case FB_VISUAL_TRUECOLOR: case FB_VISUAL_PSEUDOCOLOR: case FB_VISUAL_STATIC_PSEUDOCOLOR: case FB_VISUAL_DIRECTCOLOR: break; default: GAL_SetError("Unsupported console hardware"); FB_VideoQuit(this); return(-1); }#if 0 /* Check if the user wants to disable hardware acceleration */ { const char *fb_accel; fb_accel = getenv("GAL_FBACCEL"); if ( fb_accel ) { finfo.accel = atoi(fb_accel); } }#endif /* Memory map the device, compensating for buggy PPC mmap() */ mapped_offset = (((long)finfo.smem_start) - (((long)finfo.smem_start)&~(PAGE_SIZE-1))); mapped_memlen = finfo.smem_len+mapped_offset; mapped_mem = mmap(NULL, mapped_memlen, PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0); if ( mapped_mem == (char *)-1 ) { GAL_SetError("Unable to memory map the video hardware"); mapped_mem = NULL; FB_VideoQuit(this); return(-1); } /* Determine the current screen depth */ if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { GAL_SetError("Couldn't get console pixel format"); FB_VideoQuit(this); return(-1); } vformat->BitsPerPixel = vinfo.bits_per_pixel; if ( vformat->BitsPerPixel < 8 ) { /* Assuming VGA16, we handle this via a shadow framebuffer */ vformat->BitsPerPixel = 8; } for ( i=0; i<vinfo.red.length; ++i ) { vformat->Rmask <<= 1; vformat->Rmask |= (0x00000001<<vinfo.red.offset); } for ( i=0; i<vinfo.green.length; ++i ) { vformat->Gmask <<= 1; vformat->Gmask |= (0x00000001<<vinfo.green.offset); } for ( i=0; i<vinfo.blue.length; ++i ) { vformat->Bmask <<= 1; vformat->Bmask |= (0x00000001<<vinfo.blue.offset); } saved_vinfo = vinfo; /* Save hardware palette, if needed */ FB_SavePalette(this, &finfo, &vinfo); /* If the I/O registers are available, memory map them so we can take advantage of any supported hardware acceleration. */ vinfo.accel_flags = 0; /* Temporarily reserve registers */ ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo); if ( finfo.accel && finfo.mmio_len ) { mapped_iolen = finfo.mmio_len; mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, mapped_memlen); if ( mapped_io == (char *)-1 ) { /* Hmm, failed to memory map I/O registers */ mapped_io = NULL; } }#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) if (mgIsServer) {#endif /* Query for the list of available video modes */ current_w = vinfo.xres; current_h = vinfo.yres; current_index = ((vinfo.bits_per_pixel+7)/8)-1; for ( i=0; i<NUM_MODELISTS; ++i ) { GAL_nummodes[i] = 0; GAL_modelist[i] = NULL; for ( j=0; j<(sizeof(checkres)/sizeof(checkres[0])); ++j ) { unsigned int w, h; /* See if we are querying for the current mode */ w = checkres[j].w; h = checkres[j].h; if ( i == current_index ) { if ( (current_w > w) || (current_h > h) ) { /* Only check once */ FB_AddMode(this, i, current_w, current_h); current_index = -1; } } if ( FB_CheckMode(this, &vinfo, i, &w, &h) ) { FB_AddMode(this, i, w, h); } } }#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) }#endif /* Fill in our hardware acceleration capabilities */ this->info.hw_available = 1; this->info.video_mem = finfo.smem_len/1024; if ( mapped_io ) { switch (finfo.accel) { case FB_ACCEL_MATROX_MGA2064W: case FB_ACCEL_MATROX_MGA1064SG: case FB_ACCEL_MATROX_MGA2164W: case FB_ACCEL_MATROX_MGA2164W_AGP: case FB_ACCEL_MATROX_MGAG100: /*case FB_ACCEL_MATROX_MGAG200: G200 acceleration broken! */ case FB_ACCEL_MATROX_MGAG400:#ifdef FBACCEL_DEBUG fprintf(stderr, "Matrox hardware accelerator!\n");#endif FB_MatroxAccel(this, finfo.accel); break; case FB_ACCEL_3DFX_BANSHEE:#ifdef FBACCEL_DEBUG fprintf(stderr, "3DFX hardware accelerator!\n");#endif FB_3DfxAccel (this, finfo.accel); break;#ifdef FB_ACCEL_NEOMAGIC_NM2070 case FB_ACCEL_NEOMAGIC_NM2200: case FB_ACCEL_NEOMAGIC_NM2230: case FB_ACCEL_NEOMAGIC_NM2360: case FB_ACCEL_NEOMAGIC_NM2380:#ifdef FBACCEL_DEBUG fprintf(stderr, "NeoMagic hardware accelerator!\n");#endif FB_NeoMagicAccel (this, finfo.accel);#endif break; default:#ifdef FBACCEL_DEBUG fprintf(stderr, "Unknown hardware accelerator!\n");#endif break; } } if (FB_OpenKeyboard(this) < 0) { FB_VideoQuit(this); return(-1); } /* We're done! */ return(0);}static GAL_Rect **FB_ListModes(_THIS, GAL_PixelFormat *format, Uint32 flags){ return(GAL_modelist[((format->BitsPerPixel+7)/8)-1]);}/* Various screen update functions available */#if 0static void FB_DirectUpdate(_THIS, int numrects, GAL_Rect *rects);#endif#ifdef VGA16_FBCON_SUPPORTstatic void FB_VGA16Update(_THIS, int numrects, GAL_Rect *rects);#endif#ifdef FBCON_DEBUGstatic void print_vinfo(struct fb_var_screeninfo *vinfo){ fprintf(stderr, "Printing vinfo:\n"); fprintf(stderr, "txres: %d\n", vinfo->xres); fprintf(stderr, "tyres: %d\n", vinfo->yres); fprintf(stderr, "txres_virtual: %d\n", vinfo->xres_virtual); fprintf(stderr, "tyres_virtual: %d\n", vinfo->yres_virtual); fprintf(stderr, "txoffset: %d\n", vinfo->xoffset); fprintf(stderr, "tyoffset: %d\n", vinfo->yoffset); fprintf(stderr, "tbits_per_pixel: %d\n", vinfo->bits_per_pixel); fprintf(stderr, "tgrayscale: %d\n", vinfo->grayscale); fprintf(stderr, "tnonstd: %d\n", vinfo->nonstd); fprintf(stderr, "tactivate: %d\n", vinfo->activate); fprintf(stderr, "theight: %d\n", vinfo->height); fprintf(stderr, "twidth: %d\n", vinfo->width); fprintf(stderr, "taccel_flags: %d\n", vinfo->accel_flags); fprintf(stderr, "tpixclock: %d\n", vinfo->pixclock); fprintf(stderr, "tleft_margin: %d\n", vinfo->left_margin); fprintf(stderr, "tright_margin: %d\n", vinfo->right_margin); fprintf(stderr, "tupper_margin: %d\n", vinfo->upper_margin); fprintf(stderr, "tlower_margin: %d\n", vinfo->lower_margin); fprintf(stderr, "thsync_len: %d\n", vinfo->hsync_len); fprintf(stderr, "tvsync_len: %d\n", vinfo->vsync_len); fprintf(stderr, "tsync: %d\n", vinfo->sync); fprintf(stderr, "tvmode: %d\n", vinfo->vmode); fprintf(stderr, "tred: %d/%d\n", vinfo->red.length, vinfo->red.offset); fprintf(stderr, "tgreen: %d/%d\n", vinfo->green.length, vinfo->green.offset); fprintf(stderr, "tblue: %d/%d\n", vinfo->blue.length, vinfo->blue.offset); fprintf(stderr, "talpha: %d/%d\n", vinfo->transp.length, vinfo->transp.offset);}static void print_finfo(struct fb_fix_screeninfo *finfo){ fprintf(stderr, "Printing finfo:\n"); fprintf(stderr, "tsmem_start = %p\n", (char *)finfo->smem_start); fprintf(stderr, "tsmem_len = %d\n", finfo->smem_len); fprintf(stderr, "ttype = %d\n", finfo->type); fprintf(stderr, "ttype_aux = %d\n", finfo->type_aux); fprintf(stderr, "tvisual = %d\n", finfo->visual); fprintf(stderr, "txpanstep = %d\n", finfo->xpanstep); fprintf(stderr, "typanstep = %d\n", finfo->ypanstep); fprintf(stderr, "tywrapstep = %d\n", finfo->ywrapstep); fprintf(stderr, "tline_length = %d\n", finfo->line_length); fprintf(stderr, "tmmio_start = %p\n", (char *)finfo->mmio_start); fprintf(stderr, "tmmio_len = %d\n", finfo->mmio_len); fprintf(stderr, "taccel = %d\n", finfo->accel);}#endifstatic int choose_fbmodes_mode(struct fb_var_screeninfo *vinfo){ /* FIXME */ return 0;#if 0 int matched; FILE *fbmodes; matched = 0; fbmodes = fopen("/etc/fb.modes", "r"); if ( fbmodes ) { /* FIXME: Parse the mode definition file */ fclose(fbmodes); } return(matched);#endif}static int choose_vesa_mode(struct fb_var_screeninfo *vinfo){ int matched; int i; /* Check for VESA timings */ matched = 0; for ( i=0; i<(sizeof(vesa_timings)/sizeof(vesa_timings[0])); ++i ) { if ( (vinfo->xres == vesa_timings[i].xres) && (vinfo->yres == vesa_timings[i].yres) ) {#ifdef FBCON_DEBUG fprintf(stderr, "Using VESA timings for %dx%d\n", vinfo->xres, vinfo->yres);#endif if ( vesa_timings[i].pixclock ) { vinfo->pixclock = vesa_timings[i].pixclock; } vinfo->left_margin = vesa_timings[i].left; vinfo->right_margin = vesa_timings[i].right; vinfo->upper_margin = vesa_timings[i].upper; vinfo->lower_margin = vesa_timings[i].lower; vinfo->hsync_len = vesa_timings[i].hslen; vinfo->vsync_len = vesa_timings[i].vslen; vinfo->sync = vesa_timings[i].sync; vinfo->vmode = vesa_timings[i].vmode; matched = 1; break; } } return(matched);}#ifdef VGA16_FBCON_SUPPORTstatic GAL_Surface *FB_SetVGA16Mode(_THIS, GAL_Surface *current, int width, int height, int bpp, Uint32 flags){ struct fb_fix_screeninfo finfo; struct fb_var_screeninfo vinfo; /* Set the terminal into graphics mode */ if ( FB_EnterGraphicsMode(this) < 0 ) { return(NULL); } /* Restore the original palette */ FB_RestorePalette(this); /* Set the video mode and get the final screen format */ if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { GAL_SetError("Couldn't get console screen info"); return(NULL); } cache_vinfo = vinfo;#ifdef FBCON_DEBUG fprintf(stderr, "Printing actual vinfo:\n"); print_vinfo(&vinfo);#endif if ( ! GAL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { return(NULL); } current->format->palette->ncolors = 16; /* Get the fixed information about the console hardware. This is necessary since finfo.line_length changes. */ if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { GAL_SetError("Couldn't get console hardware info"); return(NULL); }#ifdef FBCON_DEBUG fprintf(stderr, "Printing actual finfo:\n"); print_finfo(&finfo);#endif /* Save hardware palette, if needed */ FB_SavePalette(this, &finfo, &vinfo); /* Set up the new mode framebuffer */ current->flags = GAL_FULLSCREEN; current->w = vinfo.xres; current->h = vinfo.yres; current->pitch = current->w; current->pixels = malloc(current->h*current->pitch); /* Set the update rectangle function */ this->UpdateRects = FB_VGA16Update; /* We're done */ return(current);}#endif /* VGA16_FBCON_SUPPORT */static GAL_Surface *FB_SetVideoMode(_THIS, GAL_Surface *current, int width, int height, int bpp, Uint32 flags){ struct fb_fix_screeninfo finfo; struct fb_var_screeninfo vinfo; int i; Uint32 Rmask; Uint32 Gmask; Uint32 Bmask; char *surfaces_mem; int surfaces_len; /* Set the terminal into graphics mode */ if (FB_EnterGraphicsMode(this) < 0) { return(NULL); } /* Restore the original palette */ FB_RestorePalette (this); /* Set the video mode and get the final screen format */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -