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

📄 fbvideo.c

📁 minigui 1.6.10 8.1开源版
💻 C
📖 第 1 页 / 共 3 页
字号:
        reply->bucket = bucket;        reply->offset = bucket->base - mapped_mem;    }    else {  /* free hw surface */        vidmem_bucket *bucket, *freeable;        /* Look for the bucket in the current list */        for ( bucket=&surfaces; bucket; bucket=bucket->next ) {            if ( bucket == (vidmem_bucket *)request->bucket) {                break;            }        }        if ( bucket && bucket->used ) {        /* Add the memory back to the total */#ifdef FBCON_DEBUG            fprintf(stderr, "NEWGAL>FBCON: Freeing bucket of %d bytes\n", bucket->size);#endif            surfaces_memleft += bucket->size;            /* Can we merge the space with surrounding buckets? */            bucket->used = 0;            if ( bucket->next && ! bucket->next->used ) {#ifdef FBCON_DEBUG                fprintf(stderr, "NEWGAL>FBCON: Merging with next bucket, for %d total bytes\n",                                 bucket->size+bucket->next->size);#endif                freeable = bucket->next;                bucket->size += bucket->next->size;                bucket->next = bucket->next->next;                if ( bucket->next ) {                    bucket->next->prev = bucket;                }                free(freeable);            }            if ( bucket->prev && ! bucket->prev->used ) {#ifdef FBCON_DEBUG                fprintf(stderr, "NEWGAL>FBCON: Merging with previous bucket, for %d total bytes\n",                                 bucket->prev->size+bucket->size);#endif                freeable = bucket;                bucket->prev->size += bucket->size;                bucket->prev->next = bucket->next;                if ( bucket->next ) {                    bucket->next->prev = bucket->prev;                }                free(freeable);            }        }    }}static int FB_AllocHWSurface (_THIS, GAL_Surface *surface){    REQ_HWSURFACE request = {surface->w, surface->h, surface->pitch, 0, NULL};    REP_HWSURFACE reply = {0, 0, NULL};#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)    if (mgIsServer)        FB_RequestHWSurface (this, &request, &reply);    else {        REQUEST req;        req.id = REQID_HWSURFACE;        req.data = &request;        req.len_data = sizeof (REQ_HWSURFACE);        ClientRequest (&req, &reply, sizeof (REP_HWSURFACE));    }#else    FB_RequestHWSurface (this, &request, &reply);#endif    if (reply.bucket == NULL)        return -1;    surface->flags |= GAL_HWSURFACE;    surface->pitch = reply.pitch;    surface->pixels = mapped_mem + reply.offset;    surface->hwdata = (struct private_hwdata *)reply.bucket;    return 0;}static void FB_FreeHWSurface(_THIS, GAL_Surface *surface){    REQ_HWSURFACE request = {surface->w, surface->h, surface->pitch, 0, surface->hwdata};    REP_HWSURFACE reply = {0, 0};    request.offset = (char*)surface->pixels - (char*)mapped_mem;#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)    if (mgIsServer)        FB_RequestHWSurface (this, &request, &reply);    else {        REQUEST req;        if (surface->hwdata == NULL) {            surface->pixels = NULL;            return;        }        request.bucket = surface->hwdata;        req.id = REQID_HWSURFACE;        req.data = &request;        req.len_data = sizeof (REQ_HWSURFACE);        ClientRequest (&req, &reply, sizeof (REP_HWSURFACE));    }#else    FB_RequestHWSurface (this, &request, &reply);#endif    surface->pixels = NULL;    surface->hwdata = NULL;}static 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 GAL video routine -- notably UpdateRects.*/static void FB_VideoQuit(_THIS){#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)    if ( mgIsServer && this->screen ) {#else    if ( this->screen ) {#endif        /* Clear screen and tell GAL 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;        }    }    /* 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;        }#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)        if (mgIsServer)#endif        {            /* 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 + -