10 #include <lib/system/econfig.h>
11 #include <lib/gdi/fb.h>
12 #include <lib/gdi/grc.h>
15 #if HAVE_DVB_API_VERSION >= 3
19 fbClass
*fbClass::instance
;
21 fbClass
*fbClass::getInstance()
26 fbClass::fbClass(const char *fb
)
39 eConfig::getInstance()->getKey("/ezap/osd/showConsoleOnFB", state
);
47 if (ioctl(fd
, FBIOGET_VSCREENINFO
, &screeninfo
)<0)
49 perror("FBIOGET_VSCREENINFO");
53 memcpy(&oldscreen
, &screeninfo
, sizeof(screeninfo
));
55 fb_fix_screeninfo fix
;
56 if (ioctl(fd
, FBIOGET_FSCREENINFO
, &fix
)<0)
58 perror("FBIOGET_FSCREENINFO");
62 available
=fix
.smem_len
;
63 eDebug("%dk video mem", available
/1024);
64 lfb
=(unsigned char*)mmap(0, available
, PROT_WRITE
|PROT_READ
, MAP_SHARED
, fd
, 0);
75 printf("framebuffer not available.\n");
79 int fbClass::showConsole(int state
)
81 int fd
=open("/dev/vc/0", O_RDWR
);
84 if(ioctl(fd
, KDSETMODE
, state
?KD_TEXT
:KD_GRAPHICS
)<0)
86 eDebug("setting /dev/vc/0 status failed.");
93 int fbClass::SetMode(unsigned int nxRes
, unsigned int nyRes
, unsigned int nbpp
)
95 screeninfo
.xres_virtual
=screeninfo
.xres
=nxRes
;
96 screeninfo
.yres_virtual
=screeninfo
.yres
=nyRes
;
99 screeninfo
.xoffset
=screeninfo
.yoffset
=0;
100 screeninfo
.bits_per_pixel
=nbpp
;
101 if (ioctl(fd
, FBIOPUT_VSCREENINFO
, &screeninfo
)<0)
103 perror("FBIOPUT_VSCREENINFO");
104 printf("fb failed\n");
107 if ((screeninfo
.xres
!=nxRes
) && (screeninfo
.yres
!=nyRes
) && (screeninfo
.bits_per_pixel
!=nbpp
))
109 eDebug("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
111 screeninfo
.xres
, screeninfo
.yres
, screeninfo
.bits_per_pixel
);
113 xRes
=screeninfo
.xres
;
114 yRes
=screeninfo
.yres
;
115 bpp
=screeninfo
.bits_per_pixel
;
116 fb_fix_screeninfo fix
;
117 if (ioctl(fd
, FBIOGET_FSCREENINFO
, &fix
)<0)
119 perror("FBIOGET_FSCREENINFO");
120 printf("fb failed\n");
122 stride
=fix
.line_length
;
123 memset(lfb
, 0, stride
*yRes
);
130 ioctl(fd
, FBIOPUT_VSCREENINFO
, &oldscreen
);
132 munmap(lfb
, available
);
135 int fbClass::PutCMAP()
137 return ioctl(fd
, FBIOPUTCMAP
, &cmap
);
140 void fbClass::Box(int x
, int y
, int width
, int height
, int color
, int backcolor
)
142 if (width
<=2 || locked
)
144 int offset
=y
*stride
+x
/2;
145 int first
=0xF0|((color
&0xF0)>>4);
146 int last
= 0xF0|((backcolor
&0xF0)>>4);
147 color
=(color
&0xF)*0x11;
148 int halfwidth
=width
/2;
149 for (int ay
=y
; ay
<(y
+height
); ay
++)
152 memset(lfb
+offset
+1, color
, halfwidth
-2);
153 lfb
[offset
+halfwidth
-1]=last
;
158 void fbClass::NBox(int x
, int y
, int width
, int height
, int color
)
162 int offset
=y
*stride
+x
/2;
163 int halfwidth
=width
/2;
164 for (int ay
=y
; ay
<(y
+height
); ay
++)
166 memset(lfb
+offset
, color
, halfwidth
);
171 void fbClass::VLine(int x
, int y
, int sy
, int color
)
175 int offset
=y
*stride
+x
/2;
187 while (gRC::getInstance().mustDraw())
193 void fbClass::unlock()
198 SetMode(xRes
, yRes
, bpp
);
202 void fbClass::paletteSet(struct fb_cmap
*map
)
210 ioctl(fd
, FBIOPUTCMAP
, map
);
213 #if HAVE_DVB_API_VERSION >= 3
214 void fbClass::setTransparency(int tr
)
219 int val
= (tr
<< 8) | tr
;
220 if (ioctl(fd
, AVIA_GT_GV_SET_BLEV
, val
))
221 perror("AVIA_GT_GV_SET_BLEV");