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));
147 void gFBDC::setAlpha(int a)
155 void gFBDC::setBrightness(int b)
163 void gFBDC::setGamma(int g)
171 void gFBDC::setResolution(int xres, int yres)
173 if ((m_xres == xres) && (m_yres == yres))
176 m_xres = xres; m_yres = yres;
178 fb->SetMode(m_xres, m_yres, 32);
180 for (int y=0; y<m_yres; y++) // make whole screen transparent
181 memset(fb->lfb+y*fb->Stride(), 0x00, fb->Stride());
188 surface.stride = fb->Stride();
189 surface.data = fb->lfb;
192 surface.data_phys = fb->getPhysAddr();
194 int fb_size = surface.stride * surface.y;
196 if (fb->getNumPages() > 1)
198 m_enable_double_buffering = 1;
199 surface_back.type = 0;
200 surface_back.x = m_xres;
201 surface_back.y = m_yres;
202 surface_back.bpp = 32;
203 surface_back.bypp = 4;
204 surface_back.stride = fb->Stride();
205 surface_back.offset = surface.y;
206 surface_back.data = fb->lfb + fb_size;
207 surface_back.data_phys = surface.data_phys + fb_size;
211 m_enable_double_buffering = 0;
213 eDebug("%dkB available for acceleration surfaces.", (fb->Available() - fb_size)/1024);
214 eDebug("resolution: %d x %d x %d (stride: %d)", surface.x, surface.y, surface.bpp, fb->Stride());
216 if (gAccel::getInstance())
217 gAccel::getInstance()->setAccelMemorySpace(fb->lfb + fb_size, surface.data_phys + fb_size, fb->Available() - fb_size);
219 if (!surface.clut.data)
221 surface.clut.colors = 256;
222 surface.clut.data = new gRGB[surface.clut.colors];
223 memset(surface.clut.data, 0, sizeof(*surface.clut.data)*surface.clut.colors);
226 surface_back.clut = surface.clut;
228 m_pixmap = new gPixmap(&surface);
231 void gFBDC::saveSettings()
235 void gFBDC::reloadSettings()
245 // eAutoInitPtr<gFBDC> init_gFBDC(eAutoInitNumbers::graphic-1, "GFBDC");
247 eAutoInitPtr<gFBDC> init_gFBDC(eAutoInitNumbers::graphic-1, "GFBDC");