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