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>
15 eFatal("no framebuffer available");
17 surface.clut.data = 0;
18 setResolution(720, 576); // default res
26 delete[] surface.clut.data;
29 void gFBDC::calcRamp()
32 float fgamma=gamma ? gamma : 1;
35 for (int i=0; i<256; i++)
37 float raw=i/255.0; // IIH, float.
38 float corr=pow(raw, fgamma) * 256.0;
40 int d=corr * (float)(256-brightness) / 256 + brightness;
47 rampalpha[i]=i*alpha/256;
50 for (int i=0; i<256; i++)
54 d=(d-128)*(gamma+64)/(128+64)+128;
55 d+=brightness-128; // brightness correction
62 rampalpha[i]=i*alpha/256;
65 rampalpha[255]=255; // transparent BLEIBT bitte so.
68 void gFBDC::setPalette()
70 if (!surface.clut.data)
73 for (int i=0; i<256; ++i)
75 fb->CMAP()->red[i]=ramp[surface.clut.data[i].r]<<8;
76 fb->CMAP()->green[i]=ramp[surface.clut.data[i].g]<<8;
77 fb->CMAP()->blue[i]=ramp[surface.clut.data[i].b]<<8;
78 fb->CMAP()->transp[i]=rampalpha[surface.clut.data[i].a]<<8;
83 void gFBDC::exec(const gOpcode *o)
87 case gOpcode::setPalette:
95 if (m_enable_double_buffering)
98 surface = surface_back;
101 fb->setOffset(surface_back.offset);
105 case gOpcode::waitVSync:
113 gettimeofday(&now, 0);
115 int diff = (now.tv_sec - l.tv_sec) * 1000 + (now.tv_usec - l.tv_usec) / 1000;
116 eDebug("%d ms latency (%d fps)", diff, t * 1000 / (diff ? diff : 1));
136 void gFBDC::setAlpha(int a)
144 void gFBDC::setBrightness(int b)
152 void gFBDC::setGamma(int g)
160 void gFBDC::setResolution(int xres, int yres)
162 if ((m_xres == xres) && (m_yres == yres))
165 m_xres = xres; m_yres = yres;
167 fb->SetMode(m_xres, m_yres, 32);
169 for (int y=0; y<m_yres; y++) // make whole screen transparent
170 memset(fb->lfb+y*fb->Stride(), 0x00, fb->Stride());
177 surface.stride = fb->Stride();
178 surface.data = fb->lfb;
181 surface.data_phys = fb->getPhysAddr();
183 int fb_size = surface.stride * surface.y;
185 if (fb->getNumPages() > 1)
187 m_enable_double_buffering = 1;
188 surface_back.type = 0;
189 surface_back.x = m_xres;
190 surface_back.y = m_yres;
191 surface_back.bpp = 32;
192 surface_back.bypp = 4;
193 surface_back.stride = fb->Stride();
194 surface_back.offset = surface.y;
195 surface_back.data = fb->lfb + fb_size;
196 surface_back.data_phys = surface.data_phys + fb_size;
200 m_enable_double_buffering = 0;
202 eDebug("%dkB available for acceleration surfaces.", (fb->Available() - fb_size)/1024);
203 eDebug("resolution: %d x %d x %d (stride: %d)", surface.x, surface.y, surface.bpp, fb->Stride());
205 if (gAccel::getInstance())
206 gAccel::getInstance()->setAccelMemorySpace(fb->lfb + fb_size, surface.data_phys + fb_size, fb->Available() - fb_size);
208 if (!surface.clut.data)
210 surface.clut.colors = 256;
211 surface.clut.data = new gRGB[surface.clut.colors];
212 memset(surface.clut.data, 0, sizeof(*surface.clut.data)*surface.clut.colors);
215 surface_back.clut = surface.clut;
217 m_pixmap = new gPixmap(&surface);
220 void gFBDC::saveSettings()
224 void gFBDC::reloadSettings()
234 eAutoInitPtr<gFBDC> init_gFBDC(eAutoInitNumbers::graphic-1, "GFBDC");