?? fbvideo.c
字號:
FB_NeoMagicAccel (this, finfo.accel);#endif break; default:#ifdef FBACCEL_DEBUG fprintf(stderr, "FBCON NEWGAL Engine: 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_Rect**) -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);}#endif#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("FBCON NEWGAL Engine: Couldn't get console screen info\n"); return(NULL); } cache_vinfo = vinfo;#ifdef FBCON_DEBUG fprintf(stderr, "FBCON NEWGAL Engine: 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("FBCON NEWGAL Engine: Couldn't get console hardware info\n"); return(NULL); }#ifdef FBCON_DEBUG fprintf(stderr, "FBCON NEWGAL Engine: 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;#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) if (mgIsServer)#endif { /* 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("FBCON NEWGAL Engine: Couldn't get console screen info"); return(NULL); }#ifdef FBCON_DEBUG fprintf(stderr, "FBCON NEWGAL Engine: Printing original vinfo:\n"); print_vinfo(&vinfo);#endif#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) if (!mgIsServer) { vinfo.xres = width; vinfo.yres = height; } if ( mgIsServer && ((vinfo.xres != width) || (vinfo.yres != height) || (vinfo.bits_per_pixel != bpp) /* || (flags & GAL_DOUBLEBUF) */) ) {#else if ( ((vinfo.xres != width) || (vinfo.yres != height) || (vinfo.bits_per_pixel != bpp) /* || (flags & GAL_DOUBLEBUF) */) ) {#endif vinfo.activate = FB_ACTIVATE_NOW; vinfo.accel_flags = 0; vinfo.bits_per_pixel = bpp; vinfo.xres = width; vinfo.xres_virtual = width; vinfo.yres = height;#if 0 if ( flags & GAL_DOUBLEBUF ) { vinfo.yres_virtual = height*2; } else { vinfo.yres_virtual = height; }#else vinfo.yres_virtual = height;#endif vinfo.xoffset = 0; vinfo.yoffset = 0; vinfo.red.length = vinfo.red.offset = 0; vinfo.green.length = vinfo.green.offset = 0; vinfo.blue.length = vinfo.blue.offset = 0; vinfo.transp.length = vinfo.transp.offset = 0;#ifdef FBCON_DEBUG fprintf(stderr, "FBCON NEWGAL Engine: Printing wanted vinfo:\n"); print_vinfo(&vinfo);#endif if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) { vinfo.yres_virtual = height; if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) { GAL_SetError("FBCON NEWGAL Engine: Couldn't set console screen info"); return(NULL); } } } else { int maxheight; /* Figure out how much video memory is available */#if 0 if ( flags & GAL_DOUBLEBUF ) { maxheight = height*2; } else { maxheight = height; }#else maxheight = height;#endif if ( vinfo.yres_virtual > maxheight ) { vinfo.yres_virtual = maxheight; } } cache_vinfo = vinfo;#ifdef FBCON_DEBUG fprintf (stderr, "FBCON NEWGAL Engine: Printing actual vinfo:\n"); print_vinfo(&vinfo);#endif Rmask = 0; for ( i=0; i<vinfo.red.length; ++i ) { Rmask <<= 1; Rmask |= (0x00000001<<vinfo.red.offset); } Gmask = 0; for ( i=0; i<vinfo.green.length; ++i ) { Gmask <<= 1; Gmask |= (0x00000001<<vinfo.green.offset); } Bmask = 0; for ( i=0; i<vinfo.blue.length; ++i ) { Bmask <<= 1; Bmask |= (0x00000001<<vinfo.blue.offset); } if (!GAL_ReallocFormat(current, vinfo.bits_per_pixel, Rmask, Gmask, Bmask, 0) ) { return(NULL); } /* 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("FBCON NEWGAL Engine: Couldn't get console hardware info"); return(NULL); } /* Save hardware palette, if needed */ FB_SavePalette(this, &finfo, &vinfo); /* Set up the new mode framebuffer */ current->flags = (GAL_FULLSCREEN|GAL_HWSURFACE); current->w = vinfo.xres; current->h = vinfo.yres; current->pitch = finfo.line_length; current->pixels = mapped_mem+mapped_offset; /* Set up the information for hardware surfaces */ surfaces_mem = (char *)current->pixels + vinfo.yres_virtual*current->pitch; surfaces_len = (mapped_memlen-(surfaces_mem-mapped_mem));#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) if (mgIsServer)#endif { FB_FreeHWSurfaces(this); FB_InitHWSurfaces(this, current, surfaces_mem, surfaces_len); }#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) else { current->hwdata = NULL; }#endif /* Let the application know we have a hardware palette */ switch (finfo.visual) { case FB_VISUAL_PSEUDOCOLOR: current->flags |= GAL_HWPALETTE; break; default: break; }#if 0 /* Update for double-buffering, if we can */ if ( flags & GAL_DOUBLEBUF ) { if ( vinfo.yres_virtual == (height*2) ) { current->flags |= GAL_DOUBLEBUF; flip_page = 0; flip_address[0] = (char *)current->pixels; flip_address[1] = (char *)current->pixels+ current->h*current->pitch; this->screen = current; FB_FlipHWSurface(this, current); this->screen = NULL; } } /* Set the update rectangle function */ this->UpdateRects = FB_DirectUpdate;#endif /* We're done */ return(current);}#ifdef FBCON_DEBUGstatic void FB_DumpHWSurfaces(_THIS){ vidmem_bucket *bucket; fprintf(stderr, "Memory left: %d (%d total)\n", surfaces_memleft, surfaces_memtotal); fprintf(stderr, "\n"); fprintf(stderr, " Base Size\n"); for ( bucket=&surfaces; bucket; bucket=bucket->next ) { fprintf(stderr, "Bucket: %p, %d (%s)\n", bucket->base, bucket->size, bucket->used ? "used" : "free"); if ( bucket->prev ) { if ( bucket->base != bucket->prev->base+bucket->prev->size ) { fprintf(stderr, "Warning, corrupt bucket list! (prev)\n"); } } else { if ( bucket != &surfaces ) { fprintf(stderr, "Warning, corrupt bucket list! (!prev)\n"); } } if ( bucket->next ) { if ( bucket->next->base != bucket->base+bucket->size ) { fprintf(stderr, "Warning, corrupt bucket list! (next)\n"); } } } fprintf(stderr, "\n");}#endifstatic int FB_InitHWSurfaces(_THIS, GAL_Surface *screen, char *base, int size){ vidmem_bucket *bucket; surfaces_memtotal = size; surfaces_memleft = size; if ( surfaces_memleft > 0 ) { bucket = (vidmem_bucket *)malloc(sizeof(*bucket)); if ( bucket == NULL ) { GAL_OutOfMemory(); return(-1); } bucket->prev = &surfaces; bucket->used = 0; bucket->dirty = 0; bucket->base = base; bucket->size = size; bucket->next = NULL; } else { bucket = NULL; } surfaces.prev = NULL; surfaces.used = 1; surfaces.dirty = 0; surfaces.base = screen->pixels; surfaces.size = (unsigned int)((long)base - (long)surfaces.base); surfaces.next = bucket; screen->hwdata = (struct private_hwdata *)&surfaces; return(0);}static void FB_FreeHWSurfaces(_THIS){ vidmem_bucket *bucket, *freeable; bucket = surfaces.next; while ( bucket ) { freeable = bucket; bucket = bucket->next; free(freeable); } surfaces.next = NULL;}static void FB_RequestHWSurface (_THIS, const REQ_HWSURFACE* request, REP_HWSURFACE* reply){ if (request->bucket == NULL) { /* alloc hw surface */ vidmem_bucket *bucket; int size; int extra; reply->bucket = NULL; /* Temporarily, we only allow surfaces the same width as display. Some blitters require the pitch between two hardware surfaces to be the same. Others have interesting alignment restrictions. Until someone who knows these details looks at the code... */ if (request->pitch > GAL_VideoSurface->pitch) { GAL_SetError("FBCON NEWGAL Engine: Surface requested wider than screen\n"); return; } reply->pitch = GAL_VideoSurface->pitch; size = request->h * reply->pitch;#ifdef FBCON_DEBUG fprintf(stderr, "Allocating bucket of %d bytes\n", size);#endif /* Quick check for available mem */ if ( size > surfaces_memleft ) { GAL_SetError("FBCON NEWGAL Engine: Not enough video memory\n"); return; } /* Search for an empty bucket big enough */ for ( bucket=&surfaces; bucket; bucket=bucket->next ) { if ( ! bucket->used && (size <= bucket->size) ) { break; } } if ( bucket == NULL ) { GAL_SetError("FBCON NEWGAL Engine: Video memory too fragmented\n"); return; } /* Create a new bucket for left-over memory */ extra = (bucket->size - size); if ( extra ) { vidmem_bucket *newbucket;#ifdef FBCON_DEBUG fprintf(stderr, "Adding new free bucket of %d bytes\n", extra);#endif newbucket = (vidmem_bucket *)malloc(sizeof(*newbucket)); if ( newbucket == NULL ) { GAL_OutOfMemory(); return; } newbucket->prev = bucket; newbucket->used = 0; newbucket->base = bucket->base + size; newbucket->size = extra; newbucket->next = bucket->next; if ( bucket->next ) { bucket->next->prev = newbucket; } bucket->next = newbucket; } /* Set the current bucket values and return it! */ bucket->used = 1; bucket->size = size; bucket->dirty = 0;#ifdef FBCON_DEBUG fprintf(stderr, "Allocated %d bytes at %p\n", bucket->size, bucket->base);#endif surfaces_memleft -= size; reply->bucket = bucket; reply->offset = bucket->base - mapped_mem; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -