]> git.vomp.tv Git - vompclient.git/blob - osdvector.h
Extended recordings menu, including artwork from tvscraper
[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 int 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         ImageIndex 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         void removeImageRef(const ImageIndex ref);
235         void removeLoadIndexRef(const LoadIndex ref);
236         unsigned int getColorRef(const Colour &c); //internally this is the same as getStyleRef
237         unsigned int getStyleRef(const DrawStyle &c);
238         virtual void removeStyleRef(unsigned int ref);
239         virtual void getScreenSize(int &width, int &height)=0;
240
241         // should be only called from command thread
242         void informPicture(LoadIndex index, ImageIndex i_index);
243
244
245
246
247     int charSet() {return 2;}; //UTF-8
248
249
250     class PictureDecoder;
251     struct PictureInfo
252     {
253         enum PictType {
254                 RGBAMemBlock,
255                 EGLImage
256         };
257         PictType type;
258         ULONG width;
259         ULONG height;
260         LoadIndex lindex;
261     union {
262         const void * image;
263         unsigned int handle;
264     };
265         void *reference;
266         PictureDecoder* decoder;
267     };
268
269
270     class PictureReader;
271
272     class PictureDecoder
273     {
274     public:
275         PictureDecoder(PictureReader * treader) {reader=treader;};
276         virtual ~PictureDecoder() {};
277
278         // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
279         virtual bool decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length)=0;
280
281         virtual bool getDecodedPicture(struct PictureInfo& pict_inf)=0;
282         virtual void freeReference(void * ref)=0;
283
284         virtual void init() {};
285         virtual void shutdown() {};
286
287     protected:
288         PictureReader * reader;
289     };
290
291     class PictureReader: public Thread_TYPE {
292     public:
293
294         ~PictureReader();
295
296         void init();
297         void addDecoder(PictureDecoder*);
298         void removeDecoder(PictureDecoder*);
299
300         void shutdown();
301
302
303         bool processReceivedPictures();
304
305         // should be called from command thread
306         void receivePicture(VDR_ResponsePacket *vresp);
307
308         void invalidateLoadIndex(LoadIndex index);
309
310
311
312
313     protected:
314
315         void threadMethod();
316         void threadPostStopCleanup();
317
318         Mutex pict_lock_incoming; //locks
319         Mutex decoders_lock;
320         std::queue<VDR_ResponsePacket*> pict_incoming;
321         std::list<PictureDecoder*> decoders;
322         set<LoadIndex> invalid_loadindex;
323
324         bool picture_update;
325
326     };
327
328     PictureReader *getPictReader() { return &reader;};
329
330
331
332 protected:
333
334     PictureReader reader;
335
336         void incImageRef(ImageIndex index);
337         int getImageRef(ImageIndex index);
338         virtual void destroyImageRef(ImageIndex index)=0;
339         void incLoadIndexRef(LoadIndex index);
340         int getLoadIndexRef(LoadIndex index);
341
342
343         virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
344         virtual ImageIndex createMonoBitmap(void *base,int width,int height)=0;
345         virtual ImageIndex createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)=0;
346         virtual void createPicture(struct PictureInfo& pict_inf)=0;
347
348         virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
349
350
351
352         map<ImageIndex,int> images_ref;
353         map<void *,ImageIndex> monobitmaps;
354         map<string,ImageIndex> jpegs;
355         map<TVMediaInfo,ImageIndex> tvmedias;
356
357
358
359
360
361
362
363         map<LoadIndex,int> loadindex_ref;
364         map<TVMediaInfo,LoadIndex> tvmedias_load;
365         map<LoadIndex,TVMediaInfo> tvmedias_load_inv;
366         map<LoadIndex,ImageIndex> tvmedias_loaded;
367
368
369
370         void incStyleRef(unsigned int index);
371         int getStyleRef(ImageIndex index);
372         virtual void destroyStyleRef(unsigned int index)=0;
373         map<pair<Colour*,unsigned int>,unsigned int> styles;
374         map<unsigned int,int> styles_ref;
375         virtual unsigned int createStyleRef(const DrawStyle &c)=0;
376         virtual unsigned int createColorRef(const Colour &c)=0;
377
378         void dereferenceSVGCommand(list<SVGCommand>& commands );
379         void referenceSVGCommand(list<SVGCommand>& commands );
380         void cleanupOrphanedRefs();
381
382
383
384         virtual void drawSetTrans(SurfaceCommands & sc)=0;
385         virtual void executeDrawCommand(SVGCommand & command)=0;
386
387
388
389
390         list<SurfaceCommands> scommands;
391
392         Mutex surfaces_mutex;
393
394         void drawSurfaces();
395 };
396
397
398
399
400 #endif