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)
49 if (ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo)<0)
51 perror("FBIOGET_VSCREENINFO");
55 memcpy(&oldscreen, &screeninfo, sizeof(screeninfo));
57 fb_fix_screeninfo fix;
58 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
60 perror("FBIOGET_FSCREENINFO");
64 available=fix.smem_len;
65 m_phys_mem = fix.smem_start;
66 eDebug("%dk video mem", available/1024);
67 lfb=(unsigned char*)mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
80 printf("framebuffer not available.\n");
84 int fbClass::showConsole(int state)
86 int fd=open("/dev/vc/0", O_RDWR);
89 if(ioctl(fd, KDSETMODE, state?KD_TEXT:KD_GRAPHICS)<0)
91 eDebug("setting /dev/vc/0 status failed.");
98 int fbClass::SetMode(unsigned int nxRes, unsigned int nyRes, unsigned int nbpp)
100 screeninfo.xres_virtual=screeninfo.xres=nxRes;
101 screeninfo.yres_virtual=(screeninfo.yres=nyRes)*2;
104 screeninfo.xoffset=screeninfo.yoffset=0;
105 screeninfo.bits_per_pixel=nbpp;
110 screeninfo.transp.offset = 15;
111 screeninfo.transp.length = 1;
112 screeninfo.red.offset = 10;
113 screeninfo.red.length = 5;
114 screeninfo.green.offset = 5;
115 screeninfo.green.length = 5;
116 screeninfo.blue.offset = 0;
117 screeninfo.blue.length = 5;
121 screeninfo.transp.offset = 24;
122 screeninfo.transp.length = 8;
123 screeninfo.red.offset = 16;
124 screeninfo.red.length = 8;
125 screeninfo.green.offset = 8;
126 screeninfo.green.length = 8;
127 screeninfo.blue.offset = 0;
128 screeninfo.blue.length = 8;
132 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
134 // try single buffering
135 screeninfo.yres_virtual=screeninfo.yres=nyRes;
137 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
139 perror("FBIOPUT_VSCREENINFO");
140 printf("fb failed\n");
143 eDebug(" - double buffering not available.");
145 eDebug(" - double buffering available!");
147 m_number_of_pages = screeninfo.yres_virtual / nyRes;
149 ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo);
151 if ((screeninfo.xres!=nxRes) && (screeninfo.yres!=nyRes) && (screeninfo.bits_per_pixel!=nbpp))
153 eDebug("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
155 screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel);
157 xRes=screeninfo.xres;
158 yRes=screeninfo.yres;
159 bpp=screeninfo.bits_per_pixel;
160 fb_fix_screeninfo fix;
161 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
163 perror("FBIOGET_FSCREENINFO");
164 printf("fb failed\n");
166 stride=fix.line_length;
167 memset(lfb, 0, stride*yRes);
171 int fbClass::setOffset(int off)
173 screeninfo.xoffset = 0;
174 screeninfo.yoffset = off;
175 return ioctl(fd, FBIOPAN_DISPLAY, &screeninfo);
178 int fbClass::waitVSync()
181 return ioctl(fd, FBIO_WAITFORVSYNC, &c);
186 if (m_manual_blit == 1) {
187 if (ioctl(fd, FBIO_BLIT) < 0)
195 ioctl(fd, FBIOPUT_VSCREENINFO, &oldscreen);
197 munmap(lfb, available);
202 int fbClass::PutCMAP()
204 return ioctl(fd, FBIOPUTCMAP, &cmap);
211 if (m_manual_blit == 1)
221 void fbClass::unlock()
225 if (locked == 2) // re-enable manualBlit
228 SetMode(xRes, yRes, bpp);
232 void fbClass::enableManualBlit()
234 unsigned char tmp = 1;
235 if (ioctl(fd,FBIO_SET_MANUAL_BLIT, &tmp)<0)
236 perror("FBIO_SET_MANUAL_BLIT");
241 void fbClass::disableManualBlit()
243 unsigned char tmp = 0;
244 if (ioctl(fd,FBIO_SET_MANUAL_BLIT, &tmp)<0)
245 perror("FBIO_SET_MANUAL_BLIT");