allow access to gfbdc from python to set resolution
[enigma2.git] / lib / gdi / grc.h
1 #ifndef __grc_h
2 #define __grc_h
3
4 /*
5         gPainter ist die high-level version. die highlevel daten werden zu low level opcodes ueber
6         die gRC-queue geschickt und landen beim gDC der hardwarespezifisch ist, meist aber auf einen
7         gPixmap aufsetzt (und damit unbeschleunigt ist).
8 */
9
10 // for debugging use:
11 //#define SYNC_PAINT
12 #undef SYNC_PAINT
13
14 #include <pthread.h>
15 #include <stack>
16 #include <list>
17
18 #include <string>
19 #include <lib/base/elock.h>
20 #include <lib/base/message.h>
21 #include <lib/gdi/erect.h>
22 #include <lib/gdi/gpixmap.h>
23 #include <lib/gdi/region.h>
24 #include <lib/gdi/gfont.h>
25
26 #ifndef SWIG
27 class eTextPara;
28
29 class gDC;
30 struct gOpcode
31 {
32         enum Opcode
33         {
34                 renderText,
35                 renderPara,
36                 setFont,
37                 
38                 fill, fillRegion, clear,
39                 blit,
40
41                 setPalette,
42                 mergePalette,
43                 
44                 line,
45                 
46                 setBackgroundColor,
47                 setForegroundColor,
48                 
49                 setBackgroundColorRGB,
50                 setForegroundColorRGB,
51                 
52                 setOffset,
53                 
54                 setClip, addClip, popClip,
55                 
56                 flush,
57                 
58                 waitVSync,
59                 flip,
60                 notify,
61                 
62                 enableSpinner, disableSpinner, incrementSpinner,
63                 
64                 shutdown
65         } opcode;
66
67         gDC *dc;
68         union para
69         {
70                 struct pfillRect
71                 {
72                         eRect area;
73                 } *fill;
74
75                 struct pfillRegion
76                 {
77                         gRegion region;
78                 } *fillRegion;
79
80                 struct prenderText
81                 {
82                         eRect area;
83                         char *text;
84                         int flags;
85                 } *renderText;
86
87                 struct prenderPara
88                 {
89                         ePoint offset;
90                         eTextPara *textpara;
91                 } *renderPara;
92                 
93                 struct psetFont
94                 {
95                         gFont *font;
96                 } *setFont;
97
98                 struct psetPalette
99                 {
100                         gPalette *palette;
101                 } *setPalette;
102                 
103                 struct pblit
104                 {
105                         gPixmap *pixmap;
106                         ePoint position;
107                         int flags;
108                         eRect clip;
109                 } *blit;
110
111                 struct pmergePalette
112                 {
113                         gPixmap *target;
114                 } *mergePalette;
115                 
116                 struct pline
117                 {
118                         ePoint start, end;
119                 } *line;
120
121                 struct psetClip
122                 {
123                         gRegion region;
124                 } *clip;
125                 
126                 struct psetColor
127                 {
128                         gColor color;
129                 } *setColor;
130                 
131                 struct psetColorRGB
132                 {
133                         gRGB color;
134                 } *setColorRGB;
135                 
136                 struct psetOffset
137                 {
138                         ePoint value;
139                         int rel;
140                 } *setOffset;
141         } parm;
142 };
143
144 #define MAXSIZE 2048
145
146                 /* gRC is the singleton which controls the fifo and dispatches commands */
147 class gRC: public iObject, public Object
148 {
149 DECLARE_REF(gRC);
150 private:
151         friend class gPainter;
152         static gRC *instance;
153
154 #ifndef SYNC_PAINT
155         static void *thread_wrapper(void *ptr);
156         pthread_t the_thread;
157         pthread_mutex_t mutex;
158         pthread_cond_t cond;
159 #endif
160         void *thread();
161
162         gOpcode queue[MAXSIZE];
163         int rp, wp;
164
165         eFixedMessagePump<int> m_notify_pump;
166         void recv_notify(const int &i);
167
168         ePtr<gDC> m_spinner_dc;
169         int m_spinner_enabled;
170         
171         void enableSpinner();
172         void disableSpinner();
173
174 public:
175         gRC();
176         virtual ~gRC();
177
178         void submit(const gOpcode &o);
179
180         Signal0<void> notify;
181         
182         void setSpinnerDC(gDC *dc) { m_spinner_dc = dc; }
183         
184         static gRC *getInstance();
185 };
186
187         /* gPainter is the user frontend, which in turn sends commands through gRC */
188 class gPainter
189 {
190         ePtr<gDC> m_dc;
191         ePtr<gRC> m_rc;
192         friend class gRC;
193
194         gOpcode *beginptr;
195         void begin(const eRect &rect);
196         void end();
197 public:
198         gPainter(gDC *dc, eRect rect=eRect());
199         virtual ~gPainter();
200         
201         void setBackgroundColor(const gColor &color);
202         void setForegroundColor(const gColor &color);
203
204         void setBackgroundColor(const gRGB &color);
205         void setForegroundColor(const gRGB &color);
206
207         void setFont(gFont *font);
208                 /* flags only THESE: */
209         enum
210         {
211                         // todo, make mask. you cannot align both right AND center AND block ;)
212                 RT_HALIGN_LEFT = 0,  /* default */
213                 RT_HALIGN_RIGHT = 1,
214                 RT_HALIGN_CENTER = 2,
215                 RT_HALIGN_BLOCK = 4,
216                 
217                 RT_VALIGN_TOP = 0,  /* default */
218                 RT_VALIGN_CENTER = 8,
219                 RT_VALIGN_BOTTOM = 16,
220                 
221                 RT_WRAP = 32
222         };
223         void renderText(const eRect &position, const std::string &string, int flags=0);
224         
225         void renderPara(eTextPara *para, ePoint offset=ePoint(0, 0));
226
227         void fill(const eRect &area);
228         void fill(const gRegion &area);
229         
230         void clear();
231
232         enum
233         {
234                 BT_ALPHATEST = 1
235         };
236
237         void blit(gPixmap *pixmap, ePoint pos, const eRect &what=eRect(), int flags=0);
238
239         void setPalette(gRGB *colors, int start=0, int len=256);
240         void setPalette(gPixmap *source);
241         void mergePalette(gPixmap *target);
242         
243         void line(ePoint start, ePoint end);
244
245         void setOffset(ePoint abs);
246         void moveOffset(ePoint rel);
247         void resetOffset();
248         
249         void resetClip(const gRegion &clip);
250         void clip(const gRegion &clip);
251         void clippop();
252
253         void flush();
254         
255         void waitVSync();
256         void flip();
257         void notify();
258 };
259 #endif
260
261 class gDC: public iObject
262 {
263 DECLARE_REF(gDC);
264 #ifndef SWIG
265 protected:
266         ePtr<gPixmap> m_pixmap;
267
268         gColor m_foreground_color, m_background_color;
269         gRGB m_foreground_color_rgb, m_background_color_rgb;
270         ePtr<gFont> m_current_font;
271         ePoint m_current_offset;
272         
273         std::stack<gRegion> m_clip_stack;
274         gRegion m_current_clip;
275         
276         ePtr<gPixmap> m_spinner_saved, m_spinner_temp;
277         ePtr<gPixmap> *m_spinner_pic;
278         eRect m_spinner_pos;
279         int m_spinner_num, m_spinner_i;
280 public:
281         virtual void exec(gOpcode *opcode);
282 #else
283 public:
284 #endif
285         gDC(gPixmap *pixmap);
286         gDC();
287         virtual ~gDC();
288         gRegion &getClip() { return m_current_clip; }
289         int getPixmap(ePtr<gPixmap> &pm) { pm = m_pixmap; return 0; }
290         gRGB getRGB(gColor col);
291         virtual eSize size() { return m_pixmap->size(); }
292         virtual int islocked() { return 0; }
293         
294         void enableSpinner();
295         void disableSpinner();
296         void incrementSpinner();
297         void setSpinner(eRect pos, ePtr<gPixmap> *pic, int len);
298 };
299
300 #endif