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)
33 eConfig::getInstance()->getKey("/ezap/osd/showConsoleOnFB", state);
41 if (ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo)<0)
43 perror("FBIOGET_VSCREENINFO");
47 memcpy(&oldscreen, &screeninfo, sizeof(screeninfo));
49 fb_fix_screeninfo fix;
50 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
52 perror("FBIOGET_FSCREENINFO");
56 available=fix.smem_len;
57 eDebug("%dk video mem", available/1024);
58 lfb=(unsigned char*)mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
69 printf("framebuffer not available.\n");
73 int fbClass::showConsole(int state)
75 int fd=open("/dev/vc/0", O_RDWR);
78 if(ioctl(fd, KDSETMODE, state?KD_TEXT:KD_GRAPHICS)<0)
80 eDebug("setting /dev/vc/0 status failed.");
87 int fbClass::SetMode(unsigned int nxRes, unsigned int nyRes, unsigned int nbpp)
89 screeninfo.xres_virtual=screeninfo.xres=nxRes;
90 screeninfo.yres_virtual=screeninfo.yres=nyRes;
91 screeninfo.xoffset=screeninfo.yoffset=0;
92 screeninfo.bits_per_pixel=nbpp;
93 if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0)
95 perror("FBIOPUT_VSCREENINFO");
96 printf("fb failed\n");
99 if ((screeninfo.xres!=nxRes) && (screeninfo.yres!=nyRes) && (screeninfo.bits_per_pixel!=nbpp))
101 eDebug("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
103 screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel);
105 xRes=screeninfo.xres;
106 yRes=screeninfo.yres;
107 bpp=screeninfo.bits_per_pixel;
108 fb_fix_screeninfo fix;
109 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0)
111 perror("FBIOGET_FSCREENINFO");
112 printf("fb failed\n");
114 stride=fix.line_length;
115 memset(lfb, 0, stride*yRes);
122 ioctl(fd, FBIOPUT_VSCREENINFO, &oldscreen);
124 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)
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)
152 int offset=y*stride+x/2;
153 int halfwidth=width/2;
154 for (int ay=y; ay<(y+height); ay++)
156 memset(lfb+offset, color, halfwidth);
161 void fbClass::VLine(int x, int y, int sy, int color)
163 int offset=y*stride+x/2;
179 void fbClass::unlock()
184 SetMode(xRes, yRes, bpp);