10 #include <lib/base/econfig.h>
11 #include <lib/gdi/fb.h>
13 #ifndef FBIO_WAITFORVSYNC
14 #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
18 fbClass *fbClass::instance;
20 fbClass *fbClass::getInstance()
25 fbClass::fbClass(const char *fb)
43 if (ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo)<0)
45 perror("FBIOGET_VSCREENINFO");
49 memcpy(&oldscreen, &screeninfo, sizeof(screeninfo));
51 fb_fix_screeninfo fix;
52 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
54 perror("FBIOGET_FSCREENINFO");
58 available=fix.smem_len;
59 eDebug("%dk video mem", available/1024);
60 lfb=(unsigned char*)mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
71 printf("framebuffer not available.\n");
75 int fbClass::showConsole(int state)
77 int fd=open("/dev/vc/0", O_RDWR);
80 if(ioctl(fd, KDSETMODE, state?KD_TEXT:KD_GRAPHICS)<0)
82 eDebug("setting /dev/vc/0 status failed.");
89 int fbClass::SetMode(unsigned int nxRes, unsigned int nyRes, unsigned int nbpp)
91 screeninfo.xres_virtual=screeninfo.xres=nxRes;
92 screeninfo.yres_virtual=(screeninfo.yres=nyRes)*2;
95 screeninfo.xoffset=screeninfo.yoffset=0;
96 screeninfo.bits_per_pixel=nbpp;
97 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
99 perror("FBIOPUT_VSCREENINFO");
100 printf("fb failed\n");
103 if ((screeninfo.xres!=nxRes) && (screeninfo.yres!=nyRes) && (screeninfo.bits_per_pixel!=nbpp))
105 eDebug("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
107 screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel);
109 xRes=screeninfo.xres;
110 yRes=screeninfo.yres;
111 bpp=screeninfo.bits_per_pixel;
112 fb_fix_screeninfo fix;
113 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
115 perror("FBIOGET_FSCREENINFO");
116 printf("fb failed\n");
118 stride=fix.line_length;
119 memset(lfb, 0, stride*yRes);
123 int fbClass::setOffset(int off)
125 screeninfo.xoffset = 0;
126 screeninfo.yoffset = off;
127 return ioctl(fd, FBIOPAN_DISPLAY, &screeninfo);
130 int fbClass::waitVSync()
133 return ioctl(fd, FBIO_WAITFORVSYNC, &c);
139 ioctl(fd, FBIOPUT_VSCREENINFO, &oldscreen);
141 munmap(lfb, available);
145 int fbClass::PutCMAP()
147 return ioctl(fd, FBIOPUTCMAP, &cmap);
158 void fbClass::unlock()
163 SetMode(xRes, yRes, bpp);