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 eDebug("%dk video mem", available/1024);
66 lfb=(unsigned char*)mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
79 printf("framebuffer not available.\n");
83 int fbClass::showConsole(int state)
85 int fd=open("/dev/vc/0", O_RDWR);
88 if(ioctl(fd, KDSETMODE, state?KD_TEXT:KD_GRAPHICS)<0)
90 eDebug("setting /dev/vc/0 status failed.");
97 int fbClass::SetMode(unsigned int nxRes, unsigned int nyRes, unsigned int nbpp)
99 screeninfo.xres_virtual=screeninfo.xres=nxRes;
100 screeninfo.yres_virtual=(screeninfo.yres=nyRes)*2;
103 screeninfo.xoffset=screeninfo.yoffset=0;
104 screeninfo.bits_per_pixel=nbpp;
106 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
108 // try single buffering
109 screeninfo.yres_virtual=screeninfo.yres=nyRes;
111 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
113 perror("FBIOPUT_VSCREENINFO");
114 printf("fb failed\n");
117 eDebug(" - double buffering not available.");
119 eDebug(" - double buffering available!");
121 m_number_of_pages = screeninfo.yres_virtual / nyRes;
123 ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo);
125 if ((screeninfo.xres!=nxRes) && (screeninfo.yres!=nyRes) && (screeninfo.bits_per_pixel!=nbpp))
127 eDebug("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
129 screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel);
131 xRes=screeninfo.xres;
132 yRes=screeninfo.yres;
133 bpp=screeninfo.bits_per_pixel;
134 fb_fix_screeninfo fix;
135 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
137 perror("FBIOGET_FSCREENINFO");
138 printf("fb failed\n");
140 stride=fix.line_length;
141 memset(lfb, 0, stride*yRes);
145 int fbClass::setOffset(int off)
147 screeninfo.xoffset = 0;
148 screeninfo.yoffset = off;
149 return ioctl(fd, FBIOPAN_DISPLAY, &screeninfo);
152 int fbClass::waitVSync()
155 return ioctl(fd, FBIO_WAITFORVSYNC, &c);
160 if (m_manual_blit == 1) {
161 if (ioctl(fd, FBIO_BLIT) < 0)
169 ioctl(fd, FBIOPUT_VSCREENINFO, &oldscreen);
171 munmap(lfb, available);
176 int fbClass::PutCMAP()
178 return ioctl(fd, FBIOPUTCMAP, &cmap);
185 if (m_manual_blit == 1)
195 void fbClass::unlock()
199 if (locked == 2) // re-enable manualBlit
202 SetMode(xRes, yRes, bpp);
206 void fbClass::enableManualBlit()
208 unsigned char tmp = 1;
209 if (ioctl(fd,FBIO_SET_MANUAL_BLIT, &tmp)<0)
210 perror("FBIO_SET_MANUAL_BLIT");
215 void fbClass::disableManualBlit()
217 unsigned char tmp = 0;
218 if (ioctl(fd,FBIO_SET_MANUAL_BLIT, &tmp)<0)
219 perror("FBIO_SET_MANUAL_BLIT");