10 #include <lib/gdi/fb.h>
12 #ifndef FBIO_WAITFORVSYNC
13 #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
17 fbClass *fbClass::instance;
19 fbClass *fbClass::getInstance()
24 fbClass::fbClass(const char *fb)
42 if (ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo)<0)
44 perror("FBIOGET_VSCREENINFO");
48 memcpy(&oldscreen, &screeninfo, sizeof(screeninfo));
50 fb_fix_screeninfo fix;
51 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
53 perror("FBIOGET_FSCREENINFO");
57 available=fix.smem_len;
58 eDebug("%dk video mem", available/1024);
59 lfb=(unsigned char*)mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
70 printf("framebuffer not available.\n");
74 int fbClass::showConsole(int state)
76 int fd=open("/dev/vc/0", O_RDWR);
79 if(ioctl(fd, KDSETMODE, state?KD_TEXT:KD_GRAPHICS)<0)
81 eDebug("setting /dev/vc/0 status failed.");
88 int fbClass::SetMode(unsigned int nxRes, unsigned int nyRes, unsigned int nbpp)
90 screeninfo.xres_virtual=screeninfo.xres=nxRes;
91 screeninfo.yres_virtual=(screeninfo.yres=nyRes)*2;
94 screeninfo.xoffset=screeninfo.yoffset=0;
95 screeninfo.bits_per_pixel=nbpp;
97 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
99 // try single buffering
100 screeninfo.yres_virtual=screeninfo.yres=nyRes;
102 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
104 perror("FBIOPUT_VSCREENINFO");
105 printf("fb failed\n");
108 eDebug(" - double buffering not available.");
110 eDebug(" - double buffering available!");
112 m_number_of_pages = screeninfo.yres_virtual / nyRes;
114 if ((screeninfo.xres!=nxRes) && (screeninfo.yres!=nyRes) && (screeninfo.bits_per_pixel!=nbpp))
116 eDebug("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
118 screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel);
120 xRes=screeninfo.xres;
121 yRes=screeninfo.yres;
122 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");
129 stride=fix.line_length;
130 memset(lfb, 0, stride*yRes);
134 int fbClass::setOffset(int off)
136 screeninfo.xoffset = 0;
137 screeninfo.yoffset = off;
138 return ioctl(fd, FBIOPAN_DISPLAY, &screeninfo);
141 int fbClass::waitVSync()
144 return ioctl(fd, FBIO_WAITFORVSYNC, &c);
150 ioctl(fd, FBIOPUT_VSCREENINFO, &oldscreen);
152 munmap(lfb, available);
156 int fbClass::PutCMAP()
158 return ioctl(fd, FBIOPUTCMAP, &cmap);
169 void fbClass::unlock()
174 SetMode(xRes, yRes, bpp);