- add more python stuff
[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 #include <pthread.h>
11 #include <stack>
12 #include <list>
13
14 #include <string>
15 #include <lib/base/ringbuffer.h>
16 #include <lib/base/elock.h>
17 #include <lib/gdi/erect.h>
18 #include <lib/gdi/gpixmap.h>
19 #include <lib/gdi/region.h>
20
21 class eTextPara;
22
23 class gDC;
24 struct gOpcode
25 {
26         enum Opcode
27         {
28                 renderText,
29                 renderPara,
30                 setFont,
31                 
32                 fill, fillRegion, clear,
33                 blit,
34
35                 setPalette,
36                 mergePalette,
37                 
38                 line,
39                 
40                 setBackgroundColor,
41                 setForegroundColor,
42                 
43                 setOffset,
44                 
45                 setClip, addClip, popClip,
46                 
47                 end,shutdown
48         } opcode;
49
50         gDC *dc;
51         union para
52         {
53                 struct pfillRect
54                 {
55                         eRect area;
56                 } *fill;
57
58                 struct pfillRegion
59                 {
60                         gRegion region;
61                 } *fillRegion;
62
63                 struct prenderText
64                 {
65                         eRect area;
66                         std::string text;
67                         int flags;
68                 } *renderText;
69
70                 struct prenderPara
71                 {
72                         ePoint offset;
73                         eTextPara *textpara;
74                 } *renderPara;
75                 
76                 struct psetFont
77                 {
78                         gFont *font;
79                 } *setFont;
80
81                 struct psetPalette
82                 {
83                         gPalette *palette;
84                 } *setPalette;
85                 
86                 struct pblit
87                 {
88                         gPixmap *pixmap;
89                         ePoint position;
90                         int flags;
91                         eRect clip;
92                 } *blit;
93
94                 struct pmergePalette
95                 {
96                         gPixmap *target;
97                 } *mergePalette;
98                 
99                 struct pline
100                 {
101                         ePoint start, end;
102                 } *line;
103
104                 struct psetClip
105                 {
106                         gRegion region;
107                 } *clip;
108                 
109                 struct psetColor
110                 {
111                         gColor color;
112                 } *setColor;
113                 
114                 struct psetOffset
115                 {
116                         ePoint value;
117                         int rel;
118                 } *setOffset;
119         } parm;
120
121         int flags;
122 };
123
124                 /* gRC is the singleton which controls the fifo and dispatches commands */
125 class gRC: public iObject
126 {
127 DECLARE_REF;
128 private:
129         static gRC *instance;
130         
131         static void *thread_wrapper(void *ptr);
132         pthread_t the_thread;
133         void *thread();
134
135         queueRingBuffer<gOpcode> queue;
136 public:
137         eLock queuelock;
138         gRC();
139         virtual ~gRC();
140
141         void submit(const gOpcode &o)
142         {
143                 static int collected=0;
144                 queue.enqueue(o);
145                 collected++;
146 //              if (o.opcode==gOpcode::end||o.opcode==gOpcode::shutdown)
147                 {
148                         queuelock.unlock(collected);
149 #ifdef SYNC_PAINT
150                         thread();
151 #endif
152                         collected=0;
153                 }
154         }
155
156         static gRC *getInstance();
157 };
158
159         /* gPainter is the user frontend, which in turn sends commands through gRC */
160 class gPainter
161 {
162         ePtr<gDC> m_dc;
163         ePtr<gRC> m_rc;
164         friend class gRC;
165
166         gOpcode *beginptr;
167         void begin(const eRect &rect);
168         void end();
169 public:
170         gPainter(gDC *dc, eRect rect=eRect());
171         virtual ~gPainter();
172
173         void setBackgroundColor(const gColor &color);
174         void setForegroundColor(const gColor &color);
175
176         void setFont(gFont *font);
177         void renderText(const eRect &position, const std::string &string, int flags=0);
178         void renderPara(eTextPara *para, ePoint offset=ePoint(0, 0));
179
180         void fill(const eRect &area);
181         void fill(const gRegion &area);
182         
183         void clear();
184         
185         void blit(gPixmap *pixmap, ePoint pos, const eRect &what=eRect(), int flags=0);
186
187         void setPalette(gRGB *colors, int start=0, int len=256);
188         void mergePalette(gPixmap *target);
189         
190         void line(ePoint start, ePoint end);
191
192         void setOffset(ePoint abs);
193         void moveOffset(ePoint rel);
194         void resetOffset();
195         
196         void resetClip(const gRegion &clip);
197         void clip(const gRegion &clip);
198         void clippop();
199
200         void flush();
201 };
202
203 class gDC: public iObject
204 {
205 DECLARE_REF;
206 protected:
207         ePtr<gPixmap> m_pixmap;
208
209         gColor m_foreground_color, m_background_color;
210         ePtr<gFont> m_current_font;
211         ePoint m_current_offset;
212         
213         std::stack<gRegion> m_clip_stack;
214         gRegion m_current_clip;
215         
216 public:
217         virtual void exec(gOpcode *opcode);
218         gDC(gPixmap *pixmap);
219         gDC();
220         virtual ~gDC();
221         gRegion &getClip() { return m_current_clip; }
222         int getPixmap(ePtr<gPixmap> &pm) { pm = m_pixmap; return 0; }
223         gRGB getRGB(gColor col);
224         virtual eSize getSize() { return m_pixmap->getSize(); }
225 };
226
227 #endif