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