⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fbvideo.c

📁 libminigui-1.3.0.tar.gz。 miniGUI的库函数源代码!
💻 C
📖 第 1 页 / 共 4 页
字号:
        }    } else {        if ( FB_IsSurfaceBusy(surface) ) {            FB_WaitBusySurfaces(this);        }    }    return(0);}static void FB_UnlockHWSurface(_THIS, GAL_Surface *surface){    if ( surface == this->screen ) {        GAL_mutexV(hw_lock);    }}static int FB_FlipHWSurface(_THIS, GAL_Surface *surface){    /* Wait for vertical retrace and then flip display */    cache_vinfo.yoffset = flip_page*surface->h;    if ( FB_IsSurfaceBusy(this->screen) ) {        FB_WaitBusySurfaces(this);    }    wait_vbl(this);    if ( ioctl(console_fd, FBIOPAN_DISPLAY, &cache_vinfo) < 0 ) {        GAL_SetError("ioctl(FBIOPAN_DISPLAY) failed");        return(-1);    }    flip_page = !flip_page;    surface->pixels = flip_address[flip_page];    return(0);}static void FB_DirectUpdate(_THIS, int numrects, GAL_Rect *rects){    /* The application is already updating the visible video memory */    return;}#endifstatic void FB_WaitVBL(_THIS){#ifdef FBIOWAITRETRACE /* Heheh, this didn't make it into the main kernel */    ioctl(console_fd, FBIOWAITRETRACE, 0);#endif    return;}static void FB_WaitIdle(_THIS){    return;}#ifdef VGA16_FBCON_SUPPORT/* Code adapted with thanks from the XFree86 VGA16 driver! :) */#define writeGr(index, value)   \outb(index, 0x3CE);             \outb(value, 0x3CF);#define writeSeq(index, value)  \outb(index, 0x3C4);             \outb(value, 0x3C5);static void FB_VGA16Update(_THIS, int numrects, GAL_Rect *rects){    GAL_Surface *screen;    int width, height, FBPitch, left, i, j, SRCPitch, phase;    register Uint32 m;    Uint8  s1, s2, s3, s4;    Uint32 *src, *srcPtr;    Uint8  *dst, *dstPtr;    screen = this->screen;    FBPitch = screen->w >> 3;    SRCPitch = screen->pitch >> 2;    writeGr(0x03, 0x00);    writeGr(0x05, 0x00);    writeGr(0x01, 0x00);    writeGr(0x08, 0xFF);    while(numrects--) {    left = rects->x & ~7;        width = (rects->w + 7) >> 3;        height = rects->h;        src = (Uint32*)screen->pixels + (rects->y * SRCPitch) + (left >> 2);         dst = (Uint8*)mapped_mem + (rects->y * FBPitch) + (left >> 3);    if((phase = (long)dst & 3L)) {        phase = 4 - phase;        if(phase > width) phase = width;        width -= phase;    }        while(height--) {        writeSeq(0x02, 1 << 0);        dstPtr = dst;        srcPtr = src;        i = width;        j = phase;        while(j--) {        m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4);         *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);        srcPtr += 2;        }        while(i >= 4) {        m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4);         s1 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);        m = (srcPtr[3] & 0x01010101) | ((srcPtr[2] & 0x01010101) << 4);         s2 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);        m = (srcPtr[5] & 0x01010101) | ((srcPtr[4] & 0x01010101) << 4);         s3 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);        m = (srcPtr[7] & 0x01010101) | ((srcPtr[6] & 0x01010101) << 4);         s4 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);        *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);        srcPtr += 8;        dstPtr += 4;        i -= 4;        }        while(i--) {        m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4);         *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);        srcPtr += 2;        }        writeSeq(0x02, 1 << 1);        dstPtr = dst;        srcPtr = src;        i = width;        j = phase;        while(j--) {        m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4);         *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);        srcPtr += 2;        }        while(i >= 4) {        m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4);         s1 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);        m = (srcPtr[3] & 0x02020202) | ((srcPtr[2] & 0x02020202) << 4);         s2 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);        m = (srcPtr[5] & 0x02020202) | ((srcPtr[4] & 0x02020202) << 4);         s3 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);        m = (srcPtr[7] & 0x02020202) | ((srcPtr[6] & 0x02020202) << 4);         s4 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);        *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);        srcPtr += 8;        dstPtr += 4;        i -= 4;        }        while(i--) {        m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4);         *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);        srcPtr += 2;        }        writeSeq(0x02, 1 << 2);        dstPtr = dst;        srcPtr = src;        i = width;        j = phase;        while(j--) {        m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4);         *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);        srcPtr += 2;        }        while(i >= 4) {        m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4);         s1 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);        m = (srcPtr[3] & 0x04040404) | ((srcPtr[2] & 0x04040404) << 4);         s2 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);        m = (srcPtr[5] & 0x04040404) | ((srcPtr[4] & 0x04040404) << 4);         s3 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);        m = (srcPtr[7] & 0x04040404) | ((srcPtr[6] & 0x04040404) << 4);         s4 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);        *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);        srcPtr += 8;        dstPtr += 4;        i -= 4;        }        while(i--) {        m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4);         *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);        srcPtr += 2;        }                writeSeq(0x02, 1 << 3);        dstPtr = dst;        srcPtr = src;        i = width;        j = phase;        while(j--) {        m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4);         *dstPtr++ = (m >> 27) | (m >> 18) | (m >> 9) | m;        srcPtr += 2;        }        while(i >= 4) {        m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4);         s1 = (m >> 27) | (m >> 18) | (m >> 9) | m;        m = (srcPtr[3] & 0x08080808) | ((srcPtr[2] & 0x08080808) << 4);         s2 = (m >> 27) | (m >> 18) | (m >> 9) | m;        m = (srcPtr[5] & 0x08080808) | ((srcPtr[4] & 0x08080808) << 4);         s3 = (m >> 27) | (m >> 18) | (m >> 9) | m;        m = (srcPtr[7] & 0x08080808) | ((srcPtr[6] & 0x08080808) << 4);         s4 = (m >> 27) | (m >> 18) | (m >> 9) | m;        *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);        srcPtr += 8;        dstPtr += 4;        i -= 4;        }        while(i--) {        m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4);         *dstPtr++ = (m >> 27) | (m >> 18) | (m >> 9) | m;        srcPtr += 2;        }            dst += FBPitch;            src += SRCPitch;        }        rects++;    }}#endif /* VGA16_FBCON_SUPPORT */void FB_SavePaletteTo(_THIS, int palette_len, __u16 *area){    struct fb_cmap cmap;    cmap.start = 0;    cmap.len = palette_len;    cmap.red = &area[0*palette_len];    cmap.green = &area[1*palette_len];    cmap.blue = &area[2*palette_len];    cmap.transp = NULL;    ioctl(console_fd, FBIOGETCMAP, &cmap);}void FB_RestorePaletteFrom(_THIS, int palette_len, __u16 *area){    struct fb_cmap cmap;    cmap.start = 0;    cmap.len = palette_len;    cmap.red = &area[0*palette_len];    cmap.green = &area[1*palette_len];    cmap.blue = &area[2*palette_len];    cmap.transp = NULL;    ioctl(console_fd, FBIOPUTCMAP, &cmap);}static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo,                                  struct fb_var_screeninfo *vinfo){    int i;    /* Save hardware palette, if needed */    if ( finfo->visual == FB_VISUAL_PSEUDOCOLOR ) {        saved_cmaplen = 1<<vinfo->bits_per_pixel;        saved_cmap=(__u16 *)malloc(3*saved_cmaplen*sizeof(*saved_cmap));        if ( saved_cmap != NULL ) {            FB_SavePaletteTo(this, saved_cmaplen, saved_cmap);        }    }    /* Added support for FB_VISUAL_DIRECTCOLOR.       With this mode pixel information is passed through the palette...       Neat fading and gamma correction effects can be had by simply       fooling around with the palette instead of changing the pixel       values themselves... Very neat!       Adam Meyerowitz 1/19/2000       ameyerow@optonline.com    */    if ( finfo->visual == FB_VISUAL_DIRECTCOLOR ) {        __u16 new_entries[3*256];        /* Save the colormap */        saved_cmaplen = 256;        saved_cmap=(__u16 *)malloc(3*saved_cmaplen*sizeof(*saved_cmap));        if ( saved_cmap != NULL ) {            FB_SavePaletteTo(this, saved_cmaplen, saved_cmap);        }        /* Allocate new identity colormap */        for ( i=0; i<256; ++i ) {                  new_entries[(0*256)+i] =            new_entries[(1*256)+i] =            new_entries[(2*256)+i] = (i<<8)|i;        }        FB_RestorePaletteFrom(this, 256, new_entries);    }}static void FB_RestorePalette(_THIS){    /* Restore the original palette */    if ( saved_cmap ) {        FB_RestorePaletteFrom(this, saved_cmaplen, saved_cmap);        free(saved_cmap);        saved_cmap = NULL;    }}static int FB_SetColors(_THIS, int firstcolor, int ncolors, GAL_Color *colors){    int i;    __u16 r[256];    __u16 g[256];    __u16 b[256];    struct fb_cmap cmap;    /* Set up the colormap */    for (i = 0; i < ncolors; i++) {        r[i] = colors[i].r << 8;        g[i] = colors[i].g << 8;        b[i] = colors[i].b << 8;    }    cmap.start = firstcolor;    cmap.len = ncolors;    cmap.red = r;    cmap.green = g;    cmap.blue = b;    cmap.transp = NULL;    if( (ioctl(console_fd, FBIOPUTCMAP, &cmap) < 0) ||        !(this->screen->flags & GAL_HWPALETTE) ) {            colors = this->screen->format->palette->colors;        ncolors = this->screen->format->palette->ncolors;        cmap.start = 0;        cmap.len = ncolors;        memset(r, 0, sizeof(r));        memset(g, 0, sizeof(g));        memset(b, 0, sizeof(b));        if ( ioctl(console_fd, FBIOGETCMAP, &cmap) == 0 ) {            for ( i=ncolors-1; i>=0; --i ) {                colors[i].r = (r[i]>>8);                colors[i].g = (g[i]>>8);                colors[i].b = (b[i]>>8);            }        }        return(0);    }    return(1);}/* Note:  If we are terminated, this could be called in the middle of   another SDL video routine -- notably UpdateRects.*/static void FB_VideoQuit(_THIS){    int i, j;#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)    if ( mgIsServer && this->screen ) {#else    if ( this->screen ) {#endif        /* Clear screen and tell SDL not to free the pixels */        if ( this->screen->pixels ) {#ifdef __powerpc__    /* SIGBUS when using memset() ?? */            Uint8 *rowp = (Uint8 *)this->screen->pixels;            int left = this->screen->pitch*this->screen->h;            while ( left-- ) { *rowp++ = 0; }#else            memset(this->screen->pixels,0,this->screen->h*this->screen->pitch);#endif        }        /* This test fails when using the VGA16 shadow memory */        if ( ((char *)this->screen->pixels >= mapped_mem) &&             ((char *)this->screen->pixels < (mapped_mem+mapped_memlen)) ) {            this->screen->pixels = NULL;        }    }    /* Clear the lock mutex */#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)    if ( mgIsServer && hw_lock ) {#else    if ( hw_lock ) {#endif        GAL_DestroyMutex(hw_lock);        hw_lock = NULL;    }#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)    if (mgIsServer) {#endif    /* Clean up defined video modes */        for ( i=0; i<NUM_MODELISTS; ++i ) {            if ( GAL_modelist[i] != NULL ) {                for ( j=0; GAL_modelist[i][j]; ++j ) {                    free(GAL_modelist[i][j]);                }                free(GAL_modelist[i]);                GAL_modelist[i] = NULL;            }        }#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)    }#endif    /* Clean up the memory bucket list */#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)    if (mgIsServer)#endif    {        FB_FreeHWSurfaces(this);    }    /* Close console and input file descriptors */    if ( console_fd > 0 ) {        /* Unmap the video framebuffer and I/O registers */        if ( mapped_mem ) {            munmap(mapped_mem, mapped_memlen);            mapped_mem = NULL;        }        if ( mapped_io ) {            munmap(mapped_io, mapped_iolen);            mapped_io = NULL;        }        /* Restore the original video mode and palette */        if (ttyfd >= 0) {            FB_RestorePalette(this);            ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo);        }        FB_LeaveGraphicsMode (this);        /* We're all done with the framebuffer */        close(console_fd);        console_fd = -1;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -