2 Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter
4 This file is part of VOMP.
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.
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.
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/>.
32 #include "threadsystem.h"
38 #include "teletextdecodervbiebu.h"
40 enum SVGCommandInstr {
66 typedef VectorHandle ImageIndex;
67 typedef unsigned long long LoadIndex;
76 reference = VECTOR_HANDLE_INIT;
79 inline static SVGCommand PaintPath(float ix, float iy, float iw, float ih, PathIndex path, VectorHandle ref)
87 nc.target.path_index=path;
92 inline static SVGCommand PaintImageLoading(LoadIndex load_in, float ix, float iy, float iw, float ih, VectorHandle ref, Corner corner = TopLeft)
95 nc.instr=DrawImageLoading;
100 nc.target.loadindex=load_in;
106 inline static SVGCommand PaintImage(float ix, float iy, float iw, float ih, ImageIndex image_in, VectorHandle ref, Corner corner = TopLeft)
114 nc.target.image=image_in;
122 inline static SVGCommand PaintTTchar(float ix, float iy,float iw,float ih,unsigned int ttchar_in)
131 nc.target.ttchar=ttchar_in;
135 inline static SVGCommand PaintClipping(float ix, float iy,float iw,float ih)
138 nc.instr=DrawClipping;
149 inline static void PaintGlyph(SVGCommand& nc, float ix, float iy, wchar_t char_in, VectorHandle ref)
157 nc.target.textchar=char_in;
160 bool Test(float tx,float ty,float tw, float th)
162 return (x>=tx) && (y>=ty) && ((x+w)<=(tx+tw)) && ((y+h)<=(ty+th));
164 bool TTTest(float tox,float toy,float tx, float ty)
166 return (x==tox) && (toy==y) && (w==tx) && (h==ty);
168 bool Outside(float tx,float ty,float tw, float th)
170 return ((x+w)<tx) || ((y+h)<ty) || ((tx+tw) < x) || ((ty+th) < y);
173 VectorHandle getRef(){ return reference; };
174 ImageIndex getImageIndex() {
175 if (instr!=DrawImage) return 0;
176 else return target.image;
178 LoadIndex getLoadIndex() {
179 if (instr!=DrawImageLoading) return 0;
180 else return target.loadindex;
183 SVGCommandInstr instr;
186 VectorHandle reference;
188 PathIndex path_index; //path_index
199 class VDR_ResponsePacket;
201 struct SurfaceCommands{
202 const SurfaceVector* surf;
203 std::vector<SVGCommand> commands;
208 class OsdVector : public Osd
212 virtual ~OsdVector();
219 void screenShot(const char* fileName);
220 virtual bool screenShot(void *buffer, int width, int height, bool osd /*include osd*/)=0;
222 Surface * createNewSurface();
225 virtual void updateBackgroundColor(DrawStyle /* bg */) {};
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);
231 virtual float getFontHeight()=0;
232 virtual float getCharWidth(wchar_t c)=0;
233 float *getCharWidthArray() {return byte_char_width;};
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);
241 virtual bool getStaticImageData(unsigned int static_id, UCHAR **userdata, ULONG *length)=0;
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;
250 // should be only called from control thread
251 void informPicture(LoadIndex index, ImageIndex i_index);
256 int charSet() {return 2;}; //UTF-8
259 class PictureDecoder;
276 PictureDecoder* decoder;
285 PictureDecoder(PictureReader * treader) {reader=treader;};
286 virtual ~PictureDecoder() {};
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;
291 virtual bool getDecodedPicture(struct PictureInfo& pict_inf)=0;
292 virtual void freeReference(void * ref)=0;
294 virtual void init() {};
295 virtual void shutdown() {};
298 PictureReader * reader;
301 class PictureReader: public Thread_TYPE {
307 void addDecoder(PictureDecoder*);
308 void removeDecoder(PictureDecoder*);
313 bool processReceivedPictures();
315 // should be called from control thread
316 void receivePicture(VDR_ResponsePacket *vresp);
318 void addStaticImage(unsigned int id);
320 void invalidateLoadIndex(LoadIndex index);
322 void informFallback(LoadIndex index, int fallback);
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;
343 PictureReader *getPictReader() { return &reader;};
349 PictureReader reader;
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);
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;
363 virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
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;
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;
382 void incStyleRef(VectorHandle index);
383 int getStyleRef(VectorHandle index);
384 virtual void destroyStyleRef(VectorHandle index) = 0;
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;
394 virtual VectorHandle createStyleRef(const DrawStyle &c) = 0;
396 void dereferenceSVGCommand(std::vector<SVGCommand>& commands );
397 void referenceSVGCommand(std::vector<SVGCommand>& commands );
398 void cleanupOrphanedRefs();
402 virtual void drawSetTrans(SurfaceCommands & sc)=0;
403 virtual void executeDrawCommand(SVGCommand & command)=0;
406 std::list<SurfaceCommands> scommands;
408 std::mutex surfaces_mutex;
410 float byte_char_width[256];