]> git.vomp.tv Git - vompclient.git/blob - osdvector.h
Added Vector based OSD for windows (Vista and later)
[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
22 #ifndef OSDVECTOR_H
23 #define OSDVECTOR_H
24 #include "osd.h"
25 #include "mutex.h"
26 #include "colour.h"
27 #include <set>
28 #include <list>
29 #include <vector>
30 #include <map>
31 #include <queue>
32 #include <string>
33 #include "tvmedia.h"
34 #include "vdr.h"
35
36 #include "teletextdecodervbiebu.h"
37
38 enum SVGCommandInstr {
39         DrawNoop,
40         DrawPath,
41         DrawGlyph,
42         DrawImage,
43         DrawTTchar,
44         DrawClipping,
45         DrawImageLoading
46 };
47 enum PathIndex {
48         PIHorzLine,
49         PIVertLine,
50         PIRectangle,
51         PIPoint
52 };
53
54 enum Corner{
55         TopLeft,
56         TopRight,
57         BottomLeft,
58         BottomRight,
59         TopMiddle,
60         BottomMiddle,
61         TopLeftLimited
62 };
63
64 typedef  VectorHandle ImageIndex;
65 typedef unsigned long long LoadIndex;
66
67 class SVGCommand
68 {
69 public:
70         SVGCommand()
71     {
72                 instr=DrawNoop;
73                 x=y=w=h=0;
74                 reference = NULL;
75     };
76
77         inline static SVGCommand PaintPath(float ix, float iy, float iw, float ih, PathIndex path, VectorHandle ref)
78         {
79                 SVGCommand nc;
80                 nc.instr=DrawPath;
81                 nc.x=ix;
82                 nc.y=iy;
83                 nc.w=iw;
84                 nc.h=ih;
85                 nc.target.path_index=path;
86                 nc.reference=ref;
87                 return nc;
88         };
89
90         inline static SVGCommand PaintImageLoading(LoadIndex load_in, float ix, float iy, float iw, float ih, VectorHandle ref, Corner corner = TopLeft)
91         {
92                 SVGCommand nc;
93                 nc.instr=DrawImageLoading;
94                 nc.x=ix;
95                 nc.y=iy;
96                 nc.w=iw;
97                 nc.h=ih;
98                 nc.target.loadindex=load_in;
99                 nc.reference=ref;
100                 nc.corner=corner;
101                 return nc;
102         };
103
104         inline static SVGCommand PaintImage(float ix, float iy, float iw, float ih, ImageIndex image_in, VectorHandle ref, Corner corner = TopLeft)
105         {
106                 SVGCommand nc;
107                 nc.instr=DrawImage;
108                 nc.x=ix;
109                 nc.y=iy;
110                 nc.w=iw;
111                 nc.h=ih;
112                 nc.target.image=image_in;
113                 nc.reference=ref;
114                 nc.corner=corner;
115                 return nc;
116         };
117
118
119
120         inline static SVGCommand PaintTTchar(float ix, float iy,float iw,float ih,unsigned int ttchar_in)
121         {
122                 SVGCommand nc;
123                 nc.instr=DrawTTchar;
124                 nc.x=ix;
125                 nc.y=iy;
126                 nc.w=iw;
127                 nc.h=ih;
128                 nc.reference=0;
129                 nc.target.ttchar=ttchar_in;
130                 nc.corner=TopLeft;
131                 return nc;
132         };
133         inline static SVGCommand PaintClipping(float ix, float iy,float iw,float ih)
134         {
135                 SVGCommand nc;
136                 nc.instr=DrawClipping;
137                 nc.x=ix;
138                 nc.y=iy;
139                 nc.w=iw;
140                 nc.h=ih;
141                 nc.reference=0;
142                 nc.target.ttchar=0;
143                 return nc;
144         };
145
146
147         inline static void PaintGlyph(SVGCommand& nc, float ix, float iy, wchar_t char_in, VectorHandle ref)
148         {
149                 nc.instr=DrawGlyph;
150                 nc.x=ix;
151                 nc.y=iy;
152                 nc.w=0;
153                 nc.h=0;
154                 nc.reference=ref;
155                 nc.target.textchar=char_in;
156         };
157
158         bool Test(float tx,float ty,float tw, float th)
159         {
160                 return (x>=tx) && (y>=ty) && ((x+w)<=(tx+tw)) && ((y+h)<=(ty+th));
161         }
162         bool TTTest(float tox,float toy,float tx, float ty)
163         {
164                 return (x==tox) && (toy==y) && (w==tx) && (h==ty);
165         }
166         bool Outside(float tx,float ty,float tw, float th)
167         {
168                 return ((x+w)<tx) || ((y+h)<ty) || ((tx+tw) < x) || ((ty+th) < y);
169         }
170
171         VectorHandle getRef(){ return reference; };
172         ImageIndex getImageIndex() {
173                 if (instr!=DrawImage) return 0;
174                 else return target.image;
175         };
176         LoadIndex getLoadIndex() {
177                 if (instr!=DrawImageLoading) return 0;
178                 else return target.loadindex;
179         };
180
181         SVGCommandInstr instr;
182         Corner corner;
183         float x,y,w,h;
184         VectorHandle reference;
185         union {
186                 PathIndex path_index; //path_index
187                 wchar_t textchar;
188                 ImageIndex image;
189                 unsigned int ttchar;
190                 LoadIndex loadindex;
191         } target;
192
193
194 };
195
196 class SurfaceVector;
197 class VDR_ResponsePacket;
198
199 struct SurfaceCommands{
200         const SurfaceVector* surf;
201         vector<SVGCommand> commands;
202         float x,y,w,h;
203 };
204
205
206 class OsdVector : public Osd
207 {
208   public:
209     OsdVector();
210     virtual ~OsdVector();
211
212
213     int restore();
214
215     int getFD();
216
217     void screenShot(const char* fileName);
218     virtual bool screenShot(void *buffer, int width, int height, bool osd /*include osd*/)=0;
219
220     Surface * createNewSurface();
221
222         void Blank();
223
224         void updateOrAddSurface(const SurfaceVector *surf,float x,float y,float height,float width,
225                         std::vector<SVGCommand>& commands);
226         void removeSurface(const SurfaceVector *surf);
227
228         virtual float getFontHeight()=0;
229         virtual float getCharWidth(wchar_t c)=0;
230         float *getCharWidthArray() {return byte_char_width;};
231
232         //virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);
233         virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia,ImageIndex& image);
234         virtual ImageIndex getMonoBitmapRef(void *base,int width,int height);
235         virtual ImageIndex getImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data);
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         VectorHandle getStyleRef(const DrawStyle &c);
243         virtual void removeStyleRef(VectorHandle ref);
244         virtual void getScreenSize(int &width, int &height)=0;
245         virtual void getRealScreenSize(int &width, int &height)=0;
246
247         // should be only called from command thread
248         void informPicture(LoadIndex index, ImageIndex i_index);
249
250
251
252
253     int charSet() {return 2;}; //UTF-8
254
255
256     class PictureDecoder;
257     struct PictureInfo
258     {
259         enum PictType {
260                 RGBAMemBlock,
261                 EGLImage,
262                         D2DBitmap
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         void informFallback(LoadIndex index, int fallback);
320
321
322
323
324     protected:
325
326         void threadMethod();
327         void threadPostStopCleanup();
328
329         Mutex pict_lock_incoming; //locks
330         Mutex decoders_lock;
331         std::queue<VDR_ResponsePacket*> pict_incoming;
332         std::queue<unsigned int> pict_incoming_static;
333         std::list<PictureDecoder*> decoders;
334         std::map<LoadIndex,int> inform_fallback;
335         set<LoadIndex> invalid_loadindex;
336
337         bool picture_update;
338
339     };
340
341     PictureReader *getPictReader() { return &reader;};
342
343
344
345 protected:
346
347     PictureReader reader;
348
349         void incImageRef(ImageIndex index);
350         int getImageRef(ImageIndex index);
351         virtual void destroyImageRef(ImageIndex index)=0;
352         void incLoadIndexRef(LoadIndex index);
353         int getLoadIndexRef(LoadIndex index);
354
355
356         //virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
357         virtual ImageIndex createMonoBitmap(void *base,int width,int height)=0;
358         virtual ImageIndex createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)=0;
359         virtual void createPicture(struct PictureInfo& pict_inf)=0;
360
361         virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
362
363
364
365         map<ImageIndex,int> images_ref;
366         map<void *,ImageIndex> monobitmaps;
367         //map<string,ImageIndex> jpegs;
368         map<TVMediaInfo,ImageIndex> tvmedias;
369         list<ImageIndex> palettepics;
370
371
372
373         map<LoadIndex,int> loadindex_ref;
374         map<TVMediaInfo,LoadIndex> tvmedias_load;
375         map<LoadIndex,TVMediaInfo> tvmedias_load_inv;
376         map<LoadIndex,ImageIndex> tvmedias_loaded;
377
378
379
380         void incStyleRef(VectorHandle index);
381         int getStyleRef(VectorHandle index);
382         virtual void destroyStyleRef(VectorHandle index) = 0;
383
384
385         map<DrawStyle, VectorHandle> styles;
386         map<VectorHandle, int> styles_ref;
387         map<DrawStyle, VectorHandle>::iterator styles_lastit;
388         bool styles_lastit_valid;
389         map<VectorHandle, int>::iterator styles_ref_lastit;
390         bool styles_ref_lastit_valid;
391
392         virtual VectorHandle createStyleRef(const DrawStyle &c) = 0;
393
394         void dereferenceSVGCommand(std::vector<SVGCommand>& commands );
395         void referenceSVGCommand(std::vector<SVGCommand>& commands );
396         void cleanupOrphanedRefs();
397
398
399
400         virtual void drawSetTrans(SurfaceCommands & sc)=0;
401         virtual void executeDrawCommand(SVGCommand & command)=0;
402
403
404
405
406         std::list<SurfaceCommands> scommands;
407
408         Mutex surfaces_mutex;
409
410         float byte_char_width[256];
411
412         void drawSurfaces();
413 };
414
415
416
417
418 #endif