10 #include <lib/gdi/fb.h>
12 #ifndef FBIO_WAITFORVSYNC
13 #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
17 #define FBIO_SET_MANUAL_BLIT _IOW('F', 0x21, __u8)
18 #define FBIO_BLIT 0x22
21 fbClass *fbClass::instance;
23 fbClass *fbClass::getInstance()
28 fbClass::fbClass(const char *fb)
31 fb_fix_screeninfo fix;
45 else if (ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo)<0)
46 perror("FBIOGET_VSCREENINFO");
47 else if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
48 perror("FBIOGET_FSCREENINFO");
51 memcpy(&oldscreen, &screeninfo, sizeof(screeninfo));
52 available=fix.smem_len;
53 lfb=(unsigned char*)mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
60 stride=fix.line_length;
66 int fbClass::showConsole(int state)
68 int fd=open("/dev/vc/0", O_RDWR);
71 if(ioctl(fd, KDSETMODE, state?KD_TEXT:KD_GRAPHICS)<0)
73 eDebug("setting /dev/vc/0 status failed.");
80 int fbClass::SetMode(unsigned int nxRes, unsigned int nyRes, unsigned int nbpp)
82 screeninfo.xres_virtual=screeninfo.xres=nxRes;
83 screeninfo.yres_virtual=(screeninfo.yres=nyRes)*2;
86 screeninfo.xoffset=screeninfo.yoffset=0;
87 screeninfo.bits_per_pixel=nbpp;
90 munmap(lfb, available);
94 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
96 // try single buffering
97 screeninfo.yres_virtual=screeninfo.yres=nyRes;
99 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
101 perror("FBIOPUT_VSCREENINFO");
102 printf("fb failed\n");
105 eDebug(" - double buffering not available.");
107 eDebug(" - double buffering available!");
109 m_number_of_pages = screeninfo.yres_virtual / nyRes;
111 ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo);
113 if ((screeninfo.xres!=nxRes) && (screeninfo.yres!=nyRes) && (screeninfo.bits_per_pixel!=nbpp))
115 eDebug("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
117 screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel);
119 xRes=screeninfo.xres;
120 yRes=screeninfo.yres;
121 bpp=screeninfo.bits_per_pixel;
123 fb_fix_screeninfo fix;
124 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
126 perror("FBIOGET_FSCREENINFO");
127 printf("fb failed\n");
131 available=fix.smem_len;
132 eDebug("%dk video mem", available/1024);
133 lfb=(unsigned char*)mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
140 stride=fix.line_length;
145 eFatal("framebuffer no more ready after SetMode(%d, %d, %d)", nxRes, nyRes, nbpp);
149 int fbClass::setOffset(int off)
151 screeninfo.xoffset = 0;
152 screeninfo.yoffset = off;
153 return ioctl(fd, FBIOPAN_DISPLAY, &screeninfo);
156 int fbClass::waitVSync()
159 return ioctl(fd, FBIO_WAITFORVSYNC, &c);
164 if (m_manual_blit == 1) {
165 if (ioctl(fd, FBIO_BLIT) < 0)
173 ioctl(fd, FBIOPUT_VSCREENINFO, &oldscreen);
175 munmap(lfb, available);
180 int fbClass::PutCMAP()
182 return ioctl(fd, FBIOPUTCMAP, &cmap);
189 if (m_manual_blit == 1)
199 void fbClass::unlock()
203 if (locked == 2) // re-enable manualBlit
206 SetMode(xRes, yRes, bpp);
210 void fbClass::enableManualBlit()
212 unsigned char tmp = 1;
213 if (ioctl(fd,FBIO_SET_MANUAL_BLIT, &tmp)<0)
214 perror("FBIO_SET_MANUAL_BLIT");
219 void fbClass::disableManualBlit()
221 unsigned char tmp = 0;
222 if (ioctl(fd,FBIO_SET_MANUAL_BLIT, &tmp)<0)
223 perror("FBIO_SET_MANUAL_BLIT");