]> git.vomp.tv Git - vompclient.git/blob - osdvector.h
For new raspberry version: fixes, move to new version of libav, use avresample, Bugfi...
[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 };
60
61 typedef  unsigned int ImageIndex;
62 typedef unsigned long long LoadIndex;
63
64 class SVGCommand
65 {
66 public:
67         SVGCommand()
68     {
69                 instr=DrawNoop;
70                 x=y=w=h=reference=0;
71     };
72
73         static SVGCommand PaintPath(float ix, float iy,float iw,float ih,PathIndex path,unsigned int ref)
74         {
75                 SVGCommand nc;
76                 nc.instr=DrawPath;
77                 nc.x=ix;
78                 nc.y=iy;
79                 nc.w=iw;
80                 nc.h=ih;
81                 nc.target.path_index=path;
82                 nc.reference=ref;
83                 return nc;
84         };
85
86         static SVGCommand PaintImageLoading(LoadIndex load_in,float ix, float iy,float iw,float ih,unsigned int ref, Corner corner=TopLeft)
87         {
88                 SVGCommand nc;
89                 nc.instr=DrawImageLoading;
90                 nc.x=ix;
91                 nc.y=iy;
92                 nc.w=iw;
93                 nc.h=ih;
94                 nc.target.loadindex=load_in;
95                 nc.reference=ref;
96                 nc.corner=corner;
97                 return nc;
98         };
99
100         static SVGCommand PaintImage(float ix, float iy,float iw,float ih,ImageIndex image_in,unsigned int ref, Corner corner=TopLeft)
101         {
102                 SVGCommand nc;
103                 nc.instr=DrawImage;
104                 nc.x=ix;
105                 nc.y=iy;
106                 nc.w=iw;
107                 nc.h=ih;
108                 nc.target.image=image_in;
109                 nc.reference=ref;
110                 nc.corner=corner;
111                 return nc;
112         };
113
114
115
116         static SVGCommand PaintTTchar(float ix, float iy,float iw,float ih,unsigned int ttchar_in)
117         {
118                 SVGCommand nc;
119                 nc.instr=DrawTTchar;
120                 nc.x=ix;
121                 nc.y=iy;
122                 nc.w=iw;
123                 nc.h=ih;
124                 nc.reference=0;
125                 nc.target.ttchar=ttchar_in;
126                 nc.corner=TopLeft;
127                 return nc;
128         };
129         static SVGCommand PaintClipping(float ix, float iy,float iw,float ih)
130         {
131                 SVGCommand nc;
132                 nc.instr=DrawClipping;
133                 nc.x=ix;
134                 nc.y=iy;
135                 nc.w=iw;
136                 nc.h=ih;
137                 nc.reference=0;
138                 nc.target.ttchar=0;
139                 return nc;
140         };
141
142
143         static SVGCommand PaintGlyph(float ix, float iy,wchar_t char_in,unsigned int ref)
144         {
145                 SVGCommand nc;
146                 nc.instr=DrawGlyph;
147                 nc.x=ix;
148                 nc.y=iy;
149                 nc.w=0;
150                 nc.h=0;
151                 nc.reference=ref;
152                 nc.target.textchar=char_in;
153                 return nc;
154         };
155
156         bool Test(float tx,float ty,float tw, float th)
157         {
158                 return (x>=tx) && (y>=ty) && ((x+w)<=(tx+tw)) && ((y+h)<=(ty+th));
159         }
160         bool TTTest(float tox,float toy,float tx, float ty)
161         {
162                 return (x==tox) && (toy==y) && (w==tx) && (h==ty);
163         }
164         bool Outside(float tx,float ty,float tw, float th)
165         {
166                 return ((x+w)<tx) || ((y+h)<ty) || ((tx+tw) < x) || ((ty+th) < y);
167         }
168
169         unsigned int getRef(){return reference;};
170         ImageIndex getImageIndex() {
171                 if (instr!=DrawImage) return 0;
172                 else return target.image;
173         };
174         LoadIndex getLoadIndex() {
175                 if (instr!=DrawImageLoading) return 0;
176                 else return target.loadindex;
177         };
178
179         SVGCommandInstr instr;
180         float x,y,w,h;
181         unsigned int reference;
182         union {
183                 PathIndex path_index; //path_index
184                 wchar_t textchar;
185                 ImageIndex image;
186                 unsigned int ttchar;
187                 LoadIndex loadindex;
188         } target;
189         Corner corner;
190
191 };
192
193 class SurfaceVector;
194 class VDR_ResponsePacket;
195
196 struct SurfaceCommands{
197         const SurfaceVector* surf;
198         list<SVGCommand> commands;
199         float x,y,w,h;
200 };
201
202
203 class OsdVector : public Osd
204 {
205   public:
206     OsdVector();
207     virtual ~OsdVector();
208
209
210     int restore();
211
212     int getFD();
213
214     void screenShot(const char* fileName);
215
216     Surface * createNewSurface();
217         void BeginPainting();
218         void EndPainting();
219
220         void Blank();
221
222         void updateOrAddSurface(const SurfaceVector *surf,float x,float y,float height,float width,
223                         list<SVGCommand>& commands);
224         void removeSurface(const SurfaceVector *surf);
225
226         virtual float getFontHeight()=0;
227         virtual float getCharWidth(wchar_t c)=0;
228
229         //virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);
230         virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia,ImageIndex& image);
231         virtual ImageIndex getMonoBitmapRef(void *base,int width,int height);
232         virtual ImageIndex getImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data);
233         virtual void imageUploadLine(ImageIndex index,unsigned int j,unsigned int width,void *data)=0;
234
235
236         virtual bool getStaticImageData(unsigned int static_id, UCHAR **userdata, ULONG *length)=0;
237
238         void removeImageRef(const ImageIndex ref);
239         void removeLoadIndexRef(const LoadIndex ref);
240         unsigned int getColorRef(const Colour &c); //internally this is the same as getStyleRef
241         unsigned int getStyleRef(const DrawStyle &c);
242         virtual void removeStyleRef(unsigned int ref);
243         virtual void getScreenSize(int &width, int &height)=0;
244
245         // should be only called from command thread
246         void informPicture(LoadIndex index, ImageIndex i_index);
247
248
249
250
251     int charSet() {return 2;}; //UTF-8
252
253
254     class PictureDecoder;
255     struct PictureInfo
256     {
257         enum PictType {
258                 RGBAMemBlock,
259                 EGLImage
260         };
261         PictType type;
262         ULONG width;
263         ULONG height;
264         LoadIndex lindex;
265     union {
266         const void * image;
267         unsigned int handle;
268     };
269         void *reference;
270         PictureDecoder* decoder;
271     };
272
273
274     class PictureReader;
275
276     class PictureDecoder
277     {
278     public:
279         PictureDecoder(PictureReader * treader) {reader=treader;};
280         virtual ~PictureDecoder() {};
281
282         // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
283         virtual unsigned char * decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem=true)=0;
284
285         virtual bool getDecodedPicture(struct PictureInfo& pict_inf)=0;
286         virtual void freeReference(void * ref)=0;
287
288         virtual void init() {};
289         virtual void shutdown() {};
290
291     protected:
292         PictureReader * reader;
293     };
294
295     class PictureReader: public Thread_TYPE {
296     public:
297
298         ~PictureReader();
299
300         void init();
301         void addDecoder(PictureDecoder*);
302         void removeDecoder(PictureDecoder*);
303
304         void shutdown();
305
306
307         bool processReceivedPictures();
308
309         // should be called from command thread
310         void receivePicture(VDR_ResponsePacket *vresp);
311
312         void addStaticImage(unsigned int id);
313
314         void invalidateLoadIndex(LoadIndex index);
315
316
317
318
319     protected:
320
321         void threadMethod();
322         void threadPostStopCleanup();
323
324         Mutex pict_lock_incoming; //locks
325         Mutex decoders_lock;
326         std::queue<VDR_ResponsePacket*> pict_incoming;
327         std::queue<unsigned int> pict_incoming_static;
328         std::list<PictureDecoder*> decoders;
329         set<LoadIndex> invalid_loadindex;
330
331         bool picture_update;
332
333     };
334
335     PictureReader *getPictReader() { return &reader;};
336
337
338
339 protected:
340
341     PictureReader reader;
342
343         void incImageRef(ImageIndex index);
344         int getImageRef(ImageIndex index);
345         virtual void destroyImageRef(ImageIndex index)=0;
346         void incLoadIndexRef(LoadIndex index);
347         int getLoadIndexRef(LoadIndex index);
348
349
350         //virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
351         virtual ImageIndex createMonoBitmap(void *base,int width,int height)=0;
352         virtual ImageIndex createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)=0;
353         virtual void createPicture(struct PictureInfo& pict_inf)=0;
354
355         virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
356
357
358
359         map<ImageIndex,int> images_ref;
360         map<void *,ImageIndex> monobitmaps;
361         //map<string,ImageIndex> jpegs;
362         map<TVMediaInfo,ImageIndex> tvmedias;
363         list<ImageIndex> palettepics;
364
365
366
367
368
369
370
371         map<LoadIndex,int> loadindex_ref;
372         map<TVMediaInfo,LoadIndex> tvmedias_load;
373         map<LoadIndex,TVMediaInfo> tvmedias_load_inv;
374         map<LoadIndex,ImageIndex> tvmedias_loaded;
375
376
377
378         void incStyleRef(unsigned int index);
379         int getStyleRef(ImageIndex index);
380         virtual void destroyStyleRef(unsigned int index)=0;
381         map<pair<Colour*,unsigned int>,unsigned int> styles;
382         map<unsigned int,int> styles_ref;
383         virtual unsigned int createStyleRef(const DrawStyle &c)=0;
384         virtual unsigned int createColorRef(const Colour &c)=0;
385
386         void dereferenceSVGCommand(list<SVGCommand>& commands );
387         void referenceSVGCommand(list<SVGCommand>& commands );
388         void cleanupOrphanedRefs();
389
390
391
392         virtual void drawSetTrans(SurfaceCommands & sc)=0;
393         virtual void executeDrawCommand(SVGCommand & command)=0;
394
395
396
397
398         list<SurfaceCommands> scommands;
399
400         Mutex surfaces_mutex;
401
402         void drawSurfaces();
403 };
404
405
406
407
408 #endif