📄 scr_fb.c
字号:
/* * Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com> * * Microwindows Screen Driver for Linux kernel framebuffers * * Portions used from Ben Pfaff's BOGL <pfaffben@debian.org> * * Note: modify select_fb_driver() to add new framebuffer subdrivers * 2000/10/20 Modified by Song Lixin to be used under MiniGUI. */#define _GNU_SOURCE 1#include <pkgconf/system.h>#ifdef CYGPKG_HAL_ARM#include <assert.h>#include <fcntl.h>#include <limits.h>#include <cyg/hal/drv_api.h>#include <cyg/infra/diag.h>#include <cyg/io/io.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include <cyg/hal/lcd_support.h>#include "native.h"#include "fb.h"/* static variables*/static int status; /* 0=never inited, 1=once inited, 2=inited. *//* init framebuffer*/static PSD fb_open(PSD psd){ PSUBDRIVER subdriver; struct lcd_info li; assert(status < 2); // Initialize LCD screen lcd_init(8); lcd_getinfo(&li); psd->xres = psd->xvirtres = li.width; psd->yres = psd->yvirtres = li.height;// psd->portrait = MWPORTRAIT_NONE; /* set planes from fb type*/ if (1 /*type == FB_TYPE_PACKED_PIXELS*/) psd->planes = 1; /* FIXME */ else psd->planes = 0; /* force error later*/ psd->bpp = li.bpp; psd->ncolors = (psd->bpp >= 24)? (1 << 24): (1 << psd->bpp); /* set linelen to byte length, possibly converted later*/ psd->linelen = li.rlen; psd->size = 0; /* force subdriver init of size*/ psd->flags = PSF_SCREEN | PSF_HAVEBLIT; if (psd->bpp == 16) psd->flags |= PSF_HAVEOP_COPY; /* set pixel format*/ switch (li.type) {#ifdef FB_TRUE_RGB555 case FB_TRUE_RGB555: psd->pixtype = PF_TRUECOLOR555; break;#endif#ifdef FB_TRUE_RGB565 case FB_TRUE_RGB565: psd->pixtype = PF_TRUECOLOR565; break;#endif#ifdef FB_TRUE_RGB332 case FB_TRUE_RGB332: psd->pixtype = PF_TRUECOLOR332; break;#endif default: diag_printf("Unsupported display type: %d\n", li.type); goto fail; } diag_printf("%dx %dx %d linelen %d type %d bpp %d\n", psd->xres, psd->yres,psd->ncolors,psd->linelen,li.type,psd->bpp); /* select a framebuffer subdriver based on planes and bpp*/ subdriver = select_fb_subdriver(psd); if (!subdriver) { diag_printf("No %d bit driver for screen\n", psd->bpp); goto fail; } /* * set and initialize subdriver into screen driver * psd->size is calculated by subdriver init */ if(!set_subdriver(psd, subdriver, TRUE)) { diag_printf("%d bit Driver initialize failed\n", psd->bpp); goto fail; } psd->addr = li.fb; if(psd->addr == NULL || psd->addr == (unsigned char *)-1) { goto fail; } status = 2; psd->gr_mode = MODE_SET; return psd; /* success*/ fail: return NULL;}/* close framebuffer*/static void fb_close(PSD psd){ /* if not opened, return*/ if(status != 2) return; status = 1;}#if 0static int fade = 100;#endifstatic void fb_setpalette(PSD psd,int first, int count, gal_color *palette){ diag_printf("%s - NOT IMPLEMENTED\n", __FUNCTION__); while (1) ;#if 0 int i; unsigned short red[count]; unsigned short green[count]; unsigned short blue[count]; /* convert palette to framebuffer format*/ for(i=0; i < count; i++) { gal_color *p = &palette[i]; /* grayscale computation: * red[i] = green[i] = blue[i] = * (p->r * 77 + p->g * 151 + p->b * 28); */ red[i] = (p->r * fade / 100) << 8; green[i] = (p->g * fade / 100) << 8; blue[i] = (p->b * fade / 100) << 8; } ioctl_setpalette(first, count, red, green, blue);#endif}static void fb_getpalette(PSD psd,int first, int count, gal_color *palette){ diag_printf("%s - NOT IMPLEMENTED\n", __FUNCTION__); while (1) ;#if 0 int i; unsigned short red[count]; unsigned short green[count]; unsigned short blue[count]; ioctl_getpalette(first,count,red,green,blue); for(i=0; i < count; i++) { gal_color *p = &palette[i]; /* grayscale computation: * red[i] = green[i] = blue[i] = * (p->r * 77 + p->g * 151 + p->b * 28); */ p->r = (red[i] >> 8) * 100 / fade; p->g = (green[i] >>8) * 100 / fade; p->b = (blue[i] >>8) * 100 / fade; }#endif}/* get framebuffer palette*/void ioctl_getpalette(int start, int len, short *red, short *green, short *blue){ diag_printf("%s - NOT IMPLEMENTED\n", __FUNCTION__); while (1) ;#if 0 struct fb_cmap cmap; cmap.start = start; cmap.len = len; cmap.red = red; cmap.green = green; cmap.blue = blue; cmap.transp = NULL; ioctl(fb, FBIOGETCMAP, &cmap);#endif}/* set framebuffer palette*/void ioctl_setpalette(int start, int len, short *red, short *green, short *blue){ diag_printf("%s - NOT IMPLEMENTED\n", __FUNCTION__); while (1) ;#if 0 struct fb_cmap cmap; cmap.start = start; cmap.len = len; cmap.red = red; cmap.green = green; cmap.blue = blue; cmap.transp = NULL; ioctl(fb, FBIOPUTCMAP, &cmap);#endif}SCREENDEVICE scrdev = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, fb_open, fb_close, fb_setpalette, fb_getpalette, native_gen_allocatememgc, fb_mapmemgc, native_gen_freememgc, native_gen_clippoint, native_gen_fillrect, NULL, /* DrawPixel subdriver*/ NULL, /* ReadPixel subdriver*/ NULL, /* DrawHLine subdriver*/ NULL, /* PutHLine subdriver*/ NULL, /* GetHLine subdriver*/ NULL, /* DrawVLine subdriver*/ NULL, /* PutVLine subdriver*/ NULL, /* GetVLine subdriver*/ NULL, /* Blit subdriver*/ NULL, /* PutBox subdriver*/ NULL /* CopyBox subdriver*/};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -