]> git.vomp.tv Git - vompclient.git/blob - osdvector.h
Fix text corruption on channel list when returning from live TV
[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 = VECTOR_HANDLE_INIT;
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         virtual void updateBackgroundColor(DrawStyle bg) {};
224
225         void updateOrAddSurface(const SurfaceVector *surf,float x,float y,float height,float width,
226                         std::vector<SVGCommand>& commands);
227         void removeSurface(const SurfaceVector *surf);
228
229         virtual float getFontHeight()=0;
230         virtual float getCharWidth(wchar_t c)=0;
231         float *getCharWidthArray() {return byte_char_width;};
232
233         //virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);
234         virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia,ImageIndex& image);
235         virtual ImageIndex getMonoBitmapRef(void *base,int width,int height);
236         virtual ImageIndex getImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data);
237
238
239         virtual bool getStaticImageData(unsigned int static_id, UCHAR **userdata, ULONG *length)=0;
240
241         void removeImageRef(const ImageIndex ref);
242         void removeLoadIndexRef(const LoadIndex ref);
243         VectorHandle getStyleRef(const DrawStyle &c);
244         virtual void removeStyleRef(VectorHandle 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                         D2DBitmap
264         };
265         PictType type;
266         ULONG width;
267         ULONG height;
268         LoadIndex lindex;
269     union {
270         const void * image;
271         unsigned int handle;
272     };
273         void *reference;
274         PictureDecoder* decoder;
275     };
276
277
278     class PictureReader;
279
280     class PictureDecoder
281     {
282     public:
283         PictureDecoder(PictureReader * treader) {reader=treader;};
284         virtual ~PictureDecoder() {};
285
286         // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
287         virtual unsigned char * decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem=true)=0;
288
289         virtual bool getDecodedPicture(struct PictureInfo& pict_inf)=0;
290         virtual void freeReference(void * ref)=0;
291
292         virtual void init() {};
293         virtual void shutdown() {};
294
295     protected:
296         PictureReader * reader;
297     };
298
299     class PictureReader: public Thread_TYPE {
300     public:
301
302         ~PictureReader();
303
304         void init();
305         void addDecoder(PictureDecoder*);
306         void removeDecoder(PictureDecoder*);
307
308         void shutdown();
309
310
311         bool processReceivedPictures();
312
313         // should be called from command thread
314         void receivePicture(VDR_ResponsePacket *vresp);
315
316         void addStaticImage(unsigned int id);
317
318         void invalidateLoadIndex(LoadIndex index);
319
320         void informFallback(LoadIndex index, int fallback);
321
322
323
324
325     protected:
326
327         void threadMethod();
328         void threadPostStopCleanup();
329
330         Mutex pict_lock_incoming; //locks
331         Mutex decoders_lock;
332         std::queue<VDR_ResponsePacket*> pict_incoming;
333         std::queue<unsigned int> pict_incoming_static;
334         std::list<PictureDecoder*> decoders;
335         std::map<LoadIndex,int> inform_fallback;
336         set<LoadIndex> invalid_loadindex;
337
338         bool picture_update;
339
340     };
341
342     PictureReader *getPictReader() { return &reader;};
343
344
345
346 protected:
347
348     PictureReader reader;
349
350         void incImageRef(ImageIndex index);
351         int getImageRef(ImageIndex index);
352         virtual void destroyImageRef(ImageIndex index)=0;
353         void incLoadIndexRef(LoadIndex index);
354         int getLoadIndexRef(LoadIndex index);
355
356
357         //virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
358         virtual ImageIndex createMonoBitmap(void *base,int width,int height)=0;
359         virtual ImageIndex createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)=0;
360         virtual void createPicture(struct PictureInfo& pict_inf)=0;
361
362         virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
363
364
365
366         map<ImageIndex,int> images_ref;
367         map<void *,ImageIndex> monobitmaps;
368         //map<string,ImageIndex> jpegs;
369         map<TVMediaInfo,ImageIndex> tvmedias;
370         list<ImageIndex> palettepics;
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(VectorHandle index);
382         int getStyleRef(VectorHandle index);
383         virtual void destroyStyleRef(VectorHandle index) = 0;
384
385
386         map<DrawStyle, VectorHandle> styles;
387         map<VectorHandle, int> styles_ref;
388         map<DrawStyle, VectorHandle>::iterator styles_lastit;
389         bool styles_lastit_valid;
390         map<VectorHandle, int>::iterator styles_ref_lastit;
391         bool styles_ref_lastit_valid;
392
393         virtual VectorHandle createStyleRef(const DrawStyle &c) = 0;
394
395         void dereferenceSVGCommand(std::vector<SVGCommand>& commands );
396         void referenceSVGCommand(std::vector<SVGCommand>& commands );
397         void cleanupOrphanedRefs();
398
399
400
401         virtual void drawSetTrans(SurfaceCommands & sc)=0;
402         virtual void executeDrawCommand(SVGCommand & command)=0;
403
404
405
406
407         std::list<SurfaceCommands> scommands;
408
409         Mutex surfaces_mutex;
410
411         float byte_char_width[256];
412
413         void drawSurfaces();
414 };
415
416
417
418
419 #endif