fix spaces
[enigma2.git] / lib / gdi / gfbdc.cpp
index 83ffed2b9280439a6c1eb4c3117752c85bce8c31..ee2227cfabcbef1b4b80ed3d460ca73f7cd7d91a 100644 (file)
@@ -4,6 +4,10 @@
 #include <lib/base/init_num.h>
 #include <lib/base/econfig.h>
 
+#include <lib/gdi/accel.h>
+
+#include <time.h>
+
 gFBDC *gFBDC::instance;
 
 gFBDC::gFBDC()
@@ -14,7 +18,7 @@ gFBDC::gFBDC()
        if (!fb->Available())
                eFatal("no framebuffer available");
 
-       fb->SetMode(720, 576, 8);
+       fb->SetMode(720, 576, 32);
 
        for (int y=0; y<576; y++)                                                                                                                                                // make whole screen transparent
                memset(fb->lfb+y*fb->Stride(), 0x00, fb->Stride());
@@ -22,12 +26,42 @@ gFBDC::gFBDC()
        surface.type = 0;
        surface.x = 720;
        surface.y = 576;
-       surface.bpp = 8;
-       surface.bypp = 1;
+       surface.bpp = 32;
+       surface.bypp = 4;
        surface.stride = fb->Stride();
        surface.data = fb->lfb;
-       surface.clut.colors=256;
-       surface.clut.data=new gRGB[surface.clut.colors];
+       surface.offset = 0;
+       
+       surface.data_phys = 50*1024*1024; // FIXME
+       
+       int fb_size = surface.stride * surface.y;
+
+       if (fb->getNumPages() > 1)
+       {
+               m_enable_double_buffering = 1;
+               surface_back.type = 0;
+               surface_back.x = 720;
+               surface_back.y = 576;
+               surface_back.bpp = 32;
+               surface_back.bypp = 4;
+               surface_back.stride = fb->Stride();
+               surface_back.offset = surface.y;
+               surface_back.data = fb->lfb + fb_size;
+               surface_back.data_phys = surface.data_phys + fb_size;
+       
+               fb_size *= 2;
+       } else
+               m_enable_double_buffering = 0;
+       
+       eDebug("%dkB available for acceleration surfaces.", (fb->Available() - fb_size)/1024);
+       
+       if (gAccel::getInstance())
+               gAccel::getInstance()->setAccelMemorySpace(fb->lfb + fb_size, surface.data_phys + fb_size, fb->Available() - fb_size);
+       
+       surface.clut.colors = 256;
+       surface.clut.data = new gRGB[surface.clut.colors];
+       
+       surface_back.clut = surface.clut;
        
        m_pixmap = new gPixmap(&surface);
        
@@ -38,6 +72,8 @@ gFBDC::gFBDC()
 gFBDC::~gFBDC()
 {
        delete fb;
+       
+       delete[] surface.clut.data;
        instance=0;
 }
 
@@ -91,8 +127,6 @@ void gFBDC::setPalette()
                fb->CMAP()->green[i]=ramp[surface.clut.data[i].g]<<8;
                fb->CMAP()->blue[i]=ramp[surface.clut.data[i].b]<<8;
                fb->CMAP()->transp[i]=rampalpha[surface.clut.data[i].a]<<8;
-               if (!fb->CMAP()->red[i])
-                       fb->CMAP()->red[i]=0x100;
        }
        fb->PutCMAP();
 }
@@ -107,6 +141,39 @@ void gFBDC::exec(gOpcode *o)
                setPalette();
                break;
        }
+       case gOpcode::flip:
+       {
+               if (m_enable_double_buffering)
+               {
+                       gSurface s(surface);
+                       surface = surface_back;
+                       surface_back = s;
+               
+                       fb->setOffset(surface_back.offset);
+               }
+               break;
+       }
+       case gOpcode::waitVSync:
+       {
+               static timeval l;
+               static int t;
+               timeval now;
+               
+               if (t == 1000)
+               {
+                       gettimeofday(&now, 0);
+               
+                       int diff = (now.tv_sec - l.tv_sec) * 1000 + (now.tv_usec - l.tv_usec) / 1000;
+                       eDebug("%d ms latency (%d fps)", diff, t * 1000 / (diff ? diff : 1));
+                       l = now;
+                       t = 0;
+               }
+               
+               ++t;
+               
+               fb->waitVSync();
+               break;
+       }
        default:
                gDC::exec(o);
                break;
@@ -158,3 +225,6 @@ void gFBDC::reloadSettings()
 }
 
 // eAutoInitPtr<gFBDC> init_gFBDC(eAutoInitNumbers::graphic-1, "GFBDC");
+#ifndef SDLDC
+eAutoInitPtr<gFBDC> init_gFBDC(eAutoInitNumbers::graphic-1, "GFBDC");
+#endif