1 #include <lib/gdi/gfbdc.h>
3 #include <lib/base/init.h>
4 #include <lib/base/init_num.h>
6 #include <lib/gdi/accel.h>
10 gFBDC *gFBDC::instance;
12 ePtr<gFBDC> NewgFBDCPtr(void)
15 gFBDC::getInstance(ptr);
25 eFatal("no framebuffer available");
27 surface.clut.data = 0;
28 setResolution(720, 576); // default res
36 delete[] surface.clut.data;
40 void gFBDC::calcRamp()
43 float fgamma=gamma ? gamma : 1;
46 for (int i=0; i<256; i++)
48 float raw=i/255.0; // IIH, float.
49 float corr=pow(raw, fgamma) * 256.0;
51 int d=corr * (float)(256-brightness) / 256 + brightness;
58 rampalpha[i]=i*alpha/256;
61 for (int i=0; i<256; i++)
65 d=(d-128)*(gamma+64)/(128+64)+128;
66 d+=brightness-128; // brightness correction
73 rampalpha[i]=i*alpha/256;
76 rampalpha[255]=255; // transparent BLEIBT bitte so.
79 void gFBDC::setPalette()
81 if (!surface.clut.data)
84 for (int i=0; i<256; ++i)
86 fb->CMAP()->red[i]=ramp[surface.clut.data[i].r]<<8;
87 fb->CMAP()->green[i]=ramp[surface.clut.data[i].g]<<8;
88 fb->CMAP()->blue[i]=ramp[surface.clut.data[i].b]<<8;
89 fb->CMAP()->transp[i]=rampalpha[surface.clut.data[i].a]<<8;
94 void gFBDC::exec(gOpcode *o)
98 case gOpcode::setPalette:
106 if (m_enable_double_buffering)
109 surface = surface_back;
112 fb->setOffset(surface_back.offset);
116 case gOpcode::waitVSync:
124 gettimeofday(&now, 0);
126 int diff = (now.tv_sec - l.tv_sec) * 1000 + (now.tv_usec - l.tv_usec) / 1000;
127 eDebug("%d ms latency (%d fps)", diff, t * 1000 / (diff ? diff : 1));
146 void gFBDC::setAlpha(int a)
154 void gFBDC::setBrightness(int b)
162 void gFBDC::setGamma(int g)
170 void gFBDC::setResolution(int xres, int yres)
172 if ((m_xres == xres) && (m_yres == yres))
175 m_xres = xres; m_yres = yres;
177 fb->SetMode(m_xres, m_yres, 32);
179 for (int y=0; y<m_yres; y++) // make whole screen transparent
180 memset(fb->lfb+y*fb->Stride(), 0x00, fb->Stride());
187 surface.stride = fb->Stride();
188 surface.data = fb->lfb;
191 surface.data_phys = 50*1024*1024; // FIXME
193 int fb_size = surface.stride * surface.y;
195 if (fb->getNumPages() > 1)
197 m_enable_double_buffering = 1;
198 surface_back.type = 0;
199 surface_back.x = m_xres;
200 surface_back.y = m_yres;
201 surface_back.bpp = 32;
202 surface_back.bypp = 4;
203 surface_back.stride = fb->Stride();
204 surface_back.offset = surface.y;
205 surface_back.data = fb->lfb + fb_size;
206 surface_back.data_phys = surface.data_phys + fb_size;
210 m_enable_double_buffering = 0;
212 eDebug("%dkB available for acceleration surfaces.", (fb->Available() - fb_size)/1024);
213 eDebug("resolution: %d x %d x %d (stride: %d)", surface.x, surface.y, surface.bpp, fb->Stride());
215 if (gAccel::getInstance())
216 gAccel::getInstance()->setAccelMemorySpace(fb->lfb + fb_size, surface.data_phys + fb_size, fb->Available() - fb_size);
218 if (!surface.clut.data)
220 surface.clut.colors = 256;
221 surface.clut.data = new gRGB[surface.clut.colors];
222 memset(surface.clut.data, 0, sizeof(*surface.clut.data)*surface.clut.colors);
225 surface_back.clut = surface.clut;
227 m_pixmap = new gPixmap(&surface);
230 void gFBDC::saveSettings()
234 void gFBDC::reloadSettings()
244 // eAutoInitPtr<gFBDC> init_gFBDC(eAutoInitNumbers::graphic-1, "GFBDC");
246 eAutoInitPtr<gFBDC> init_gFBDC(eAutoInitNumbers::graphic-1, "GFBDC");