]> git.vomp.tv Git - vompclient.git/blob - osdvector.h
Add static icons in menu
[vompclient.git] / osdvector.h
1 /*
2     Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef OSDVECTOR_H
22 #define OSDVECTOR_H
23 #include "osd.h"
24 #include "mutex.h"
25 #include "colour.h"
26 #include <set>
27 #include <list>
28 #include <map>
29 #include <queue>
30 #include <string>
31 #include "tvmedia.h"
32 #include "vdr.h"
33
34 #include "teletextdecodervbiebu.h"
35
36 enum SVGCommandInstr {
37         DrawNoop,
38         DrawPath,
39         DrawGlyph,
40         DrawImage,
41         DrawTTchar,
42         DrawClipping,
43         DrawImageLoading
44 };
45 enum PathIndex {
46         HorzLine,
47         VertLine,
48         Rectangle,
49         Point
50 };
51
52 enum Corner{
53         TopLeft,
54         TopRight,
55         BottomLeft,
56         BottomRight,
57         TopMiddle,
58         BottomMiddle,
59         TopLeftLimited
60 };
61
62 typedef  unsigned int ImageIndex;
63 typedef unsigned long long LoadIndex;
64
65 class SVGCommand
66 {
67 public:
68         SVGCommand()
69     {
70                 instr=DrawNoop;
71                 x=y=w=h=reference=0;
72     };
73
74         static SVGCommand PaintPath(float ix, float iy,float iw,float ih,PathIndex path,unsigned int ref)
75         {
76                 SVGCommand nc;
77                 nc.instr=DrawPath;
78                 nc.x=ix;
79                 nc.y=iy;
80                 nc.w=iw;
81                 nc.h=ih;
82                 nc.target.path_index=path;
83                 nc.reference=ref;
84                 return nc;
85         };
86
87         static SVGCommand PaintImageLoading(LoadIndex load_in,float ix, float iy,float iw,float ih,unsigned int ref, Corner corner=TopLeft)
88         {
89                 SVGCommand nc;
90                 nc.instr=DrawImageLoading;
91                 nc.x=ix;
92                 nc.y=iy;
93                 nc.w=iw;
94                 nc.h=ih;
95                 nc.target.loadindex=load_in;
96                 nc.reference=ref;
97                 nc.corner=corner;
98                 return nc;
99         };
100
101         static SVGCommand PaintImage(float ix, float iy,float iw,float ih,ImageIndex image_in,unsigned int ref, Corner corner=TopLeft)
102         {
103                 SVGCommand nc;
104                 nc.instr=DrawImage;
105                 nc.x=ix;
106                 nc.y=iy;
107                 nc.w=iw;
108                 nc.h=ih;
109                 nc.target.image=image_in;
110                 nc.reference=ref;
111                 nc.corner=corner;
112                 return nc;
113         };
114
115
116
117         static SVGCommand PaintTTchar(float ix, float iy,float iw,float ih,unsigned int ttchar_in)
118         {
119                 SVGCommand nc;
120                 nc.instr=DrawTTchar;
121                 nc.x=ix;
122                 nc.y=iy;
123                 nc.w=iw;
124                 nc.h=ih;
125                 nc.reference=0;
126                 nc.target.ttchar=ttchar_in;
127                 nc.corner=TopLeft;
128                 return nc;
129         };
130         static SVGCommand PaintClipping(float ix, float iy,float iw,float ih)
131         {
132                 SVGCommand nc;
133                 nc.instr=DrawClipping;
134                 nc.x=ix;
135                 nc.y=iy;
136                 nc.w=iw;
137                 nc.h=ih;
138                 nc.reference=0;
139                 nc.target.ttchar=0;
140                 return nc;
141         };
142
143
144         static SVGCommand PaintGlyph(float ix, float iy,wchar_t char_in,unsigned int ref)
145         {
146                 SVGCommand nc;
147                 nc.instr=DrawGlyph;
148                 nc.x=ix;
149                 nc.y=iy;
150                 nc.w=0;
151                 nc.h=0;
152                 nc.reference=ref;
153                 nc.target.textchar=char_in;
154                 return nc;
155         };
156
157         bool Test(float tx,float ty,float tw, float th)
158         {
159                 return (x>=tx) && (y>=ty) && ((x+w)<=(tx+tw)) && ((y+h)<=(ty+th));
160         }
161         bool TTTest(float tox,float toy,float tx, float ty)
162         {
163                 return (x==tox) && (toy==y) && (w==tx) && (h==ty);
164         }
165         bool Outside(float tx,float ty,float tw, float th)
166         {
167                 return ((x+w)<tx) || ((y+h)<ty) || ((tx+tw) < x) || ((ty+th) < y);
168         }
169
170         unsigned int getRef(){return reference;};
171         ImageIndex getImageIndex() {
172                 if (instr!=DrawImage) return 0;
173                 else return target.image;
174         };
175         LoadIndex getLoadIndex() {
176                 if (instr!=DrawImageLoading) return 0;
177                 else return target.loadindex;
178         };
179
180         SVGCommandInstr instr;
181         float x,y,w,h;
182         unsigned int reference;
183         union {
184                 PathIndex path_index; //path_index
185                 wchar_t textchar;
186                 ImageIndex image;
187                 unsigned int ttchar;
188                 LoadIndex loadindex;
189         } target;
190         Corner corner;
191
192 };
193
194 class SurfaceVector;
195 class VDR_ResponsePacket;
196
197 struct SurfaceCommands{
198         const SurfaceVector* surf;
199         list<SVGCommand> commands;
200         float x,y,w,h;
201 };
202
203
204 class OsdVector : public Osd
205 {
206   public:
207     OsdVector();
208     virtual ~OsdVector();
209
210
211     int restore();
212
213     int getFD();
214
215     void screenShot(const char* fileName);
216     virtual bool screenShot(void *buffer, int width, int height, bool osd /*include osd*/)=0;
217
218     Surface * createNewSurface();
219         void BeginPainting();
220         void EndPainting();
221
222         void Blank();
223
224         void updateOrAddSurface(const SurfaceVector *surf,float x,float y,float height,float width,
225                         list<SVGCommand>& commands);
226         void removeSurface(const SurfaceVector *surf);
227
228         virtual float getFontHeight()=0;
229         virtual float getCharWidth(wchar_t c)=0;
230
231         //virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);
232         virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia,ImageIndex& image);
233         virtual ImageIndex getMonoBitmapRef(void *base,int width,int height);
234         virtual ImageIndex getImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data);
235         virtual void imageUploadLine(ImageIndex index,unsigned int j,unsigned int width,void *data)=0;
236
237
238         virtual bool getStaticImageData(unsigned int static_id, UCHAR **userdata, ULONG *length)=0;
239
240         void removeImageRef(const ImageIndex ref);
241         void removeLoadIndexRef(const LoadIndex ref);
242         unsigned int getColorRef(const Colour &c); //internally this is the same as getStyleRef
243         unsigned int getStyleRef(const DrawStyle &c);
244         virtual void removeStyleRef(unsigned int ref);
245         virtual void getScreenSize(int &width, int &height)=0;
246         virtual void getRealScreenSize(int &width, int &height)=0;
247
248         // should be only called from command thread
249         void informPicture(LoadIndex index, ImageIndex i_index);
250
251
252
253
254     int charSet() {return 2;}; //UTF-8
255
256
257     class PictureDecoder;
258     struct PictureInfo
259     {
260         enum PictType {
261                 RGBAMemBlock,
262                 EGLImage
263         };
264         PictType type;
265         ULONG width;
266         ULONG height;
267         LoadIndex lindex;
268     union {
269         const void * image;
270         unsigned int handle;
271     };
272         void *reference;
273         PictureDecoder* decoder;
274     };
275
276
277     class PictureReader;
278
279     class PictureDecoder
280     {
281     public:
282         PictureDecoder(PictureReader * treader) {reader=treader;};
283         virtual ~PictureDecoder() {};
284
285         // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
286         virtual unsigned char * decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem=true)=0;
287
288         virtual bool getDecodedPicture(struct PictureInfo& pict_inf)=0;
289         virtual void freeReference(void * ref)=0;
290
291         virtual void init() {};
292         virtual void shutdown() {};
293
294     protected:
295         PictureReader * reader;
296     };
297
298     class PictureReader: public Thread_TYPE {
299     public:
300
301         ~PictureReader();
302
303         void init();
304         void addDecoder(PictureDecoder*);
305         void removeDecoder(PictureDecoder*);
306
307         void shutdown();
308
309
310         bool processReceivedPictures();
311
312         // should be called from command thread
313         void receivePicture(VDR_ResponsePacket *vresp);
314
315         void addStaticImage(unsigned int id);
316
317         void invalidateLoadIndex(LoadIndex index);
318
319
320
321
322     protected:
323
324         void threadMethod();
325         void threadPostStopCleanup();
326
327         Mutex pict_lock_incoming; //locks
328         Mutex decoders_lock;
329         std::queue<VDR_ResponsePacket*> pict_incoming;
330         std::queue<unsigned int> pict_incoming_static;
331         std::list<PictureDecoder*> decoders;
332         set<LoadIndex> invalid_loadindex;
333
334         bool picture_update;
335
336     };
337
338     PictureReader *getPictReader() { return &reader;};
339
340
341
342 protected:
343
344     PictureReader reader;
345
346         void incImageRef(ImageIndex index);
347         int getImageRef(ImageIndex index);
348         virtual void destroyImageRef(ImageIndex index)=0;
349         void incLoadIndexRef(LoadIndex index);
350         int getLoadIndexRef(LoadIndex index);
351
352
353         //virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
354         virtual ImageIndex createMonoBitmap(void *base,int width,int height)=0;
355         virtual ImageIndex createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)=0;
356         virtual void createPicture(struct PictureInfo& pict_inf)=0;
357
358         virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
359
360
361
362         map<ImageIndex,int> images_ref;
363         map<void *,ImageIndex> monobitmaps;
364         //map<string,ImageIndex> jpegs;
365         map<TVMediaInfo,ImageIndex> tvmedias;
366         list<ImageIndex> palettepics;
367
368
369
370
371
372
373
374         map<LoadIndex,int> loadindex_ref;
375         map<TVMediaInfo,LoadIndex> tvmedias_load;
376         map<LoadIndex,TVMediaInfo> tvmedias_load_inv;
377         map<LoadIndex,ImageIndex> tvmedias_loaded;
378
379
380
381         void incStyleRef(unsigned int index);
382         int getStyleRef(ImageIndex index);
383         virtual void destroyStyleRef(unsigned int index)=0;
384         map<pair<Colour*,unsigned int>,unsigned int> styles;
385         map<unsigned int,int> styles_ref;
386         virtual unsigned int createStyleRef(const DrawStyle &c)=0;
387         virtual unsigned int createColorRef(const Colour &c)=0;
388
389         void dereferenceSVGCommand(list<SVGCommand>& commands );
390         void referenceSVGCommand(list<SVGCommand>& commands );
391         void cleanupOrphanedRefs();
392
393
394
395         virtual void drawSetTrans(SurfaceCommands & sc)=0;
396         virtual void executeDrawCommand(SVGCommand & command)=0;
397
398
399
400
401         list<SurfaceCommands> scommands;
402
403         Mutex surfaces_mutex;
404
405         void drawSurfaces();
406 };
407
408
409
410
411 #endif