10 #include <lib/base/econfig.h>
11 #include <lib/gdi/fb.h>
13 fbClass *fbClass::instance;
15 fbClass *fbClass::getInstance()
20 fbClass::fbClass(const char *fb)
38 if (ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo)<0)
40 perror("FBIOGET_VSCREENINFO");
44 memcpy(&oldscreen, &screeninfo, sizeof(screeninfo));
46 fb_fix_screeninfo fix;
47 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
49 perror("FBIOGET_FSCREENINFO");
53 available=fix.smem_len;
54 eDebug("%dk video mem", available/1024);
55 lfb=(unsigned char*)mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
66 printf("framebuffer not available.\n");
70 int fbClass::showConsole(int state)
72 int fd=open("/dev/vc/0", O_RDWR);
75 if(ioctl(fd, KDSETMODE, state?KD_TEXT:KD_GRAPHICS)<0)
77 eDebug("setting /dev/vc/0 status failed.");
84 int fbClass::SetMode(unsigned int nxRes, unsigned int nyRes, unsigned int nbpp)
86 /* screeninfo.xres_virtual=screeninfo.xres=nxRes;
87 screeninfo.yres_virtual=screeninfo.yres=nyRes; */
90 screeninfo.xoffset=screeninfo.yoffset=0;
91 screeninfo.bits_per_pixel=nbpp;
92 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
94 perror("FBIOPUT_VSCREENINFO");
95 printf("fb failed\n");
98 if ((screeninfo.xres!=nxRes) && (screeninfo.yres!=nyRes) && (screeninfo.bits_per_pixel!=nbpp))
100 eDebug("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
102 screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel);
104 xRes=screeninfo.xres;
105 yRes=screeninfo.yres;
106 bpp=screeninfo.bits_per_pixel;
107 fb_fix_screeninfo fix;
108 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
110 perror("FBIOGET_FSCREENINFO");
111 printf("fb failed\n");
113 stride=fix.line_length;
114 memset(lfb, 0, stride*yRes);
121 ioctl(fd, FBIOPUT_VSCREENINFO, &oldscreen);
123 munmap(lfb, available);
127 int fbClass::PutCMAP()
129 return ioctl(fd, FBIOPUTCMAP, &cmap);
132 void fbClass::Box(int x, int y, int width, int height, int color, int backcolor)
134 if (width<=2 || locked)
136 int offset=y*stride+x/2;
137 int first=0xF0|((color&0xF0)>>4);
138 int last= 0xF0|((backcolor&0xF0)>>4);
139 color=(color&0xF)*0x11;
140 int halfwidth=width/2;
141 for (int ay=y; ay<(y+height); ay++)
144 memset(lfb+offset+1, color, halfwidth-2);
145 lfb[offset+halfwidth-1]=last;
150 void fbClass::NBox(int x, int y, int width, int height, int color)
154 int offset=y*stride+x/2;
155 int halfwidth=width/2;
156 for (int ay=y; ay<(y+height); ay++)
158 memset(lfb+offset, color, halfwidth);
163 void fbClass::VLine(int x, int y, int sy, int color)
167 int offset=y*stride+x/2;
183 void fbClass::unlock()
188 SetMode(xRes, yRes, bpp);