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