another compile fix for bug #411
[vuplus_dvbapp] / 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 #include <lib/gdi/compositing.h>
26
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                 
66                 setCompositing,
67         } opcode;
68
69         gDC *dc;
70         union para
71         {
72                 struct pfillRect
73                 {
74                         eRect area;
75                 } *fill;
76
77                 struct pfillRegion
78                 {
79                         gRegion region;
80                 } *fillRegion;
81
82                 struct prenderText
83                 {
84                         eRect area;
85                         char *text;
86                         int flags;
87                 } *renderText;
88
89                 struct prenderPara
90                 {
91                         ePoint offset;
92                         eTextPara *textpara;
93                 } *renderPara;
94                 
95                 struct psetFont
96                 {
97                         gFont *font;
98                 } *setFont;
99
100                 struct psetPalette
101                 {
102                         gPalette *palette;
103                 } *setPalette;
104                 
105                 struct pblit
106                 {
107                         gPixmap *pixmap;
108                         int flags;
109                         eRect position;
110                         eRect clip;
111                 } *blit;
112
113                 struct pmergePalette
114                 {
115                         gPixmap *target;
116                 } *mergePalette;
117                 
118                 struct pline
119                 {
120                         ePoint start, end;
121                 } *line;
122
123                 struct psetClip
124                 {
125                         gRegion region;
126                 } *clip;
127                 
128                 struct psetColor
129                 {
130                         gColor color;
131                 } *setColor;
132                 
133                 struct psetColorRGB
134                 {
135                         gRGB color;
136                 } *setColorRGB;
137                 
138                 struct psetOffset
139                 {
140                         ePoint value;
141                         int rel;
142                 } *setOffset;
143                 
144                 gCompositingData *setCompositing;
145         } parm;
146 };
147
148 #define MAXSIZE 2048
149
150                 /* gRC is the singleton which controls the fifo and dispatches commands */
151 class gRC: public iObject, public Object
152 {
153         DECLARE_REF(gRC);
154         friend class gPainter;
155         static gRC *instance;
156
157 #ifndef SYNC_PAINT
158         static void *thread_wrapper(void *ptr);
159         pthread_t the_thread;
160         pthread_mutex_t mutex;
161         pthread_cond_t cond;
162 #endif
163         void *thread();
164
165         gOpcode queue[MAXSIZE];
166         int rp, wp;
167
168         eFixedMessagePump<int> m_notify_pump;
169         void recv_notify(const int &i);
170
171         ePtr<gDC> m_spinner_dc;
172         int m_spinner_enabled;
173         
174         void enableSpinner();
175         void disableSpinner();
176         
177         ePtr<gCompositingData> m_compositing;
178
179 public:
180         gRC();
181         virtual ~gRC();
182
183         void submit(const gOpcode &o);
184
185         Signal0<void> notify;
186         
187         void setSpinnerDC(gDC *dc) { m_spinner_dc = dc; }
188         
189         static gRC *getInstance();
190 };
191
192         /* gPainter is the user frontend, which in turn sends commands through gRC */
193 class gPainter
194 {
195         ePtr<gDC> m_dc;
196         ePtr<gRC> m_rc;
197         friend class gRC;
198
199         gOpcode *beginptr;
200         void begin(const eRect &rect);
201         void end();
202 public:
203         gPainter(gDC *dc, eRect rect=eRect());
204         virtual ~gPainter();
205         
206         void setBackgroundColor(const gColor &color);
207         void setForegroundColor(const gColor &color);
208
209         void setBackgroundColor(const gRGB &color);
210         void setForegroundColor(const gRGB &color);
211
212         void setFont(gFont *font);
213                 /* flags only THESE: */
214         enum
215         {
216                         // todo, make mask. you cannot align both right AND center AND block ;)
217                 RT_HALIGN_LEFT = 0,  /* default */
218                 RT_HALIGN_RIGHT = 1,
219                 RT_HALIGN_CENTER = 2,
220                 RT_HALIGN_BLOCK = 4,
221                 
222                 RT_VALIGN_TOP = 0,  /* default */
223                 RT_VALIGN_CENTER = 8,
224                 RT_VALIGN_BOTTOM = 16,
225                 
226                 RT_WRAP = 32
227         };
228         void renderText(const eRect &position, const std::string &string, int flags=0);
229         
230         void renderPara(eTextPara *para, ePoint offset=ePoint(0, 0));
231
232         void fill(const eRect &area);
233         void fill(const gRegion &area);
234         
235         void clear();
236
237         enum
238         {
239                 BT_ALPHATEST = 1,
240                 BT_ALPHABLEND = 2,
241                 BT_SCALE = 4 /* will be automatically set by blitScale */
242         };
243
244         void blit(gPixmap *pixmap, ePoint pos, const eRect &clip=eRect(), int flags=0);
245         void blitScale(gPixmap *pixmap, const eRect &pos, const eRect &clip=eRect(), int flags=0, int aflags = BT_SCALE);
246
247         void setPalette(gRGB *colors, int start=0, int len=256);
248         void setPalette(gPixmap *source);
249         void mergePalette(gPixmap *target);
250         
251         void line(ePoint start, ePoint end);
252
253         void setOffset(ePoint abs);
254         void moveOffset(ePoint rel);
255         void resetOffset();
256         
257         void resetClip(const gRegion &clip);
258         void clip(const gRegion &clip);
259         void clippop();
260
261         void waitVSync();
262         void flip();
263         void notify();
264         void setCompositing(gCompositingData *comp);
265         
266         void flush();
267 };
268
269 class gDC: public iObject
270 {
271         DECLARE_REF(gDC);
272 protected:
273         ePtr<gPixmap> m_pixmap;
274
275         gColor m_foreground_color, m_background_color;
276         gRGB m_foreground_color_rgb, m_background_color_rgb;
277         ePtr<gFont> m_current_font;
278         ePoint m_current_offset;
279         
280         std::stack<gRegion> m_clip_stack;
281         gRegion m_current_clip;
282         
283         ePtr<gPixmap> m_spinner_saved, m_spinner_temp;
284         ePtr<gPixmap> *m_spinner_pic;
285         eRect m_spinner_pos;
286         int m_spinner_num, m_spinner_i;
287 public:
288         virtual void exec(gOpcode *opcode);
289         gDC(gPixmap *pixmap);
290         gDC();
291         virtual ~gDC();
292         gRegion &getClip() { return m_current_clip; }
293         int getPixmap(ePtr<gPixmap> &pm) { pm = m_pixmap; return 0; }
294         gRGB getRGB(gColor col);
295         virtual eSize size() { return m_pixmap->size(); }
296         virtual int islocked() { return 0; }
297         
298         void enableSpinner();
299         void disableSpinner();
300         void incrementSpinner();
301         void setSpinner(eRect pos, ePtr<gPixmap> *pic, int len);
302 };
303
304 #endif