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;
98 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
100 // try single buffering
101 screeninfo.yres_virtual=screeninfo.yres=nyRes;
103 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
105 perror("FBIOPUT_VSCREENINFO");
106 printf("fb failed\n");
109 eDebug(" - double buffering not available.");
111 eDebug(" - double buffering available!");
113 m_number_of_pages = screeninfo.yres_virtual / nyRes;
115 if ((screeninfo.xres!=nxRes) && (screeninfo.yres!=nyRes) && (screeninfo.bits_per_pixel!=nbpp))
117 eDebug("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
119 screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel);
121 xRes=screeninfo.xres;
122 yRes=screeninfo.yres;
123 bpp=screeninfo.bits_per_pixel;
124 fb_fix_screeninfo fix;
125 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
127 perror("FBIOGET_FSCREENINFO");
128 printf("fb failed\n");
130 stride=fix.line_length;
131 memset(lfb, 0, stride*yRes);
135 int fbClass::setOffset(int off)
137 screeninfo.xoffset = 0;
138 screeninfo.yoffset = off;
139 return ioctl(fd, FBIOPAN_DISPLAY, &screeninfo);
142 int fbClass::waitVSync()
145 return ioctl(fd, FBIO_WAITFORVSYNC, &c);
151 ioctl(fd, FBIOPUT_VSCREENINFO, &oldscreen);
153 munmap(lfb, available);
157 int fbClass::PutCMAP()
159 return ioctl(fd, FBIOPUTCMAP, &cmap);
170 void fbClass::unlock()
175 SetMode(xRes, yRes, bpp);