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