Add abstract class gMainDC as an interface for gFBDC and gSDLDC
[vuplus_dvbapp] / lib / gdi / sdl.cpp
1 #include <lib/gdi/sdl.h>
2
3 #include <lib/base/init.h>
4 #include <lib/base/init_num.h>
5
6 #include <SDL.h>
7
8 gSDLDC::gSDLDC()
9 {
10         if (SDL_Init(SDL_INIT_VIDEO) < 0)
11         {
12                 eWarning("Could not initialize SDL: %s", SDL_GetError());
13                 return;
14         }
15
16         setResolution(720, 576);
17
18         CONNECT(m_pump.recv_msg, gSDLDC::pumpEvent);
19
20         m_surface.type = 0;
21         m_surface.clut.colors=256;
22         m_surface.clut.data=new gRGB[m_surface.clut.colors];
23         
24         m_pixmap = new gPixmap(&m_surface);
25         
26         memset(m_surface.clut.data, 0, sizeof(*m_surface.clut.data)*m_surface.clut.colors);
27 }
28
29 gSDLDC::~gSDLDC()
30 {
31         SDL_Quit();
32 }
33
34 void gSDLDC::setPalette()
35 {
36         if (!m_surface.clut.data)
37                 return;
38         
39 /*      for (int i=0; i<256; ++i)
40         {
41                 fb->CMAP()->red[i]=ramp[m_surface.clut.data[i].r]<<8;
42                 fb->CMAP()->green[i]=ramp[m_surface.clut.data[i].g]<<8;
43                 fb->CMAP()->blue[i]=ramp[m_surface.clut.data[i].b]<<8;
44                 fb->CMAP()->transp[i]=rampalpha[m_surface.clut.data[i].a]<<8;
45                 if (!fb->CMAP()->red[i])
46                         fb->CMAP()->red[i]=0x100;
47         }
48         fb->PutCMAP(); */
49 }
50
51 void gSDLDC::exec(const gOpcode *o)
52 {
53         switch (o->opcode)
54         {
55         case gOpcode::setPalette:
56         {
57                 gDC::exec(o);
58                 setPalette();
59                 break;
60         }
61         case gOpcode::flush:
62                 SDL_Flip(m_screen);
63                 eDebug("FLUSH");
64                 break;
65         default:
66                 gDC::exec(o);
67                 break;
68         }
69 }
70
71 void gSDLDC::setResolution(int xres, int yres)
72 {
73         m_screen = SDL_SetVideoMode(xres, yres, 32, SDL_HWSURFACE);
74         if (!m_screen)
75         {
76                 eWarning("Could not create SDL surface: %s", SDL_GetError());
77                 return;
78         }
79
80         m_surface.x = m_screen->w;
81         m_surface.y = m_screen->h;
82         m_surface.bpp = m_screen->format->BitsPerPixel;
83         m_surface.bypp = m_screen->format->BytesPerPixel;
84         m_surface.stride = m_screen->pitch;
85         m_surface.data = m_screen->pixels;
86 }
87
88 eAutoInitPtr<gSDLDC> init_gSDLDC(eAutoInitNumbers::graphic-1, "gSDLDC");