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"
69 typedef VectorHandle ImageIndex;
70 typedef unsigned long long LoadIndex;
79 reference = VECTOR_HANDLE_INIT;
82 inline static SVGCommand PaintPath(float ix, float iy, float iw, float ih, PathIndex path, VectorHandle ref)
90 nc.target.path_index = path;
95 inline static SVGCommand PaintImageLoading(LoadIndex load_in, float ix, float iy, float iw, float ih, VectorHandle ref, Corner corner = TopLeft)
98 nc.instr = DrawImageLoading;
103 nc.target.loadindex = load_in;
109 inline static SVGCommand PaintImage(float ix, float iy, float iw, float ih, ImageIndex image_in, VectorHandle ref, Corner corner = TopLeft)
112 nc.instr = DrawImage;
117 nc.target.image = image_in;
125 inline static SVGCommand PaintTTchar(float ix, float iy, float iw, float ih, unsigned int ttchar_in)
128 nc.instr = DrawTTchar;
134 nc.target.ttchar = ttchar_in;
138 inline static SVGCommand PaintClipping(float ix, float iy, float iw, float ih)
141 nc.instr = DrawClipping;
147 nc.target.ttchar = 0;
152 inline static void PaintGlyph(SVGCommand& nc, float ix, float iy, wchar_t char_in, VectorHandle ref)
154 nc.instr = DrawGlyph;
160 nc.target.textchar = char_in;
163 bool Test(float tx, float ty, float tw, float th)
165 return (x >= tx) && (y >= ty) && ((x + w) <= (tx + tw)) && ((y + h) <= (ty + th));
167 bool TTTest(float tox, float toy, float tx, float ty)
169 return (x == tox) && (toy == y) && (w == tx) && (h == ty);
171 bool Outside(float tx, float ty, float tw, float th)
173 return ((x + w) < tx) || ((y + h) < ty) || ((tx + tw) < x) || ((ty + th) < y);
176 VectorHandle getRef() { return reference; };
177 ImageIndex getImageIndex()
179 if (instr != DrawImage) return 0;
180 else return target.image;
182 LoadIndex getLoadIndex()
184 if (instr != DrawImageLoading) return 0;
185 else return target.loadindex;
188 SVGCommandInstr instr;
191 VectorHandle reference;
194 PathIndex path_index; //path_index
205 class VDR_ResponsePacket;
209 const SurfaceVector* surface;
210 std::vector<SVGCommand> commands;
215 class OsdVector : public Osd
222 void screenShot(const char* fileName);
223 virtual bool screenShot(void* buffer, int width, int height, bool osd /*include osd*/) = 0;
225 Surface* createNewSurface();
228 virtual void updateBackgroundColor(DrawStyle /* bg */) {};
230 void updateOrAddSurface(const SurfaceVector* surf, float x, float y, float height, float width,
231 std::vector<SVGCommand>& commands);
232 void removeSurface(const SurfaceVector* surf);
234 virtual float getFontHeight() = 0;
235 virtual float getCharWidth(wchar_t c) = 0;
236 float* getCharWidthArray() {return byte_char_width;};
238 //virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);
239 virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia, ImageIndex& image);
240 virtual ImageIndex getMonoBitmapRef(void* base, int width, int height);
241 virtual ImageIndex getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data);
244 virtual bool getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length) = 0;
246 void removeImageRef(const ImageIndex ref);
247 void removeLoadIndexRef(const LoadIndex ref);
248 VectorHandle getStyleRef(const DrawStyle& c);
249 virtual void decrementStyleRefCount(VectorHandle ref);
250 virtual void getScreenSize(int& width, int& height) = 0;
251 virtual void getRealScreenSize(int& width, int& height) = 0;
253 // should be only called from control thread
254 void informPicture(LoadIndex index, ImageIndex i_index);
259 int charSet() {return 2;}; //UTF-8
262 class PictureDecoder;
281 PictureDecoder* decoder;
290 PictureDecoder(PictureReader* treader) {reader = treader;};
291 virtual ~PictureDecoder() {};
293 // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
294 virtual unsigned char* decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem = true) = 0;
296 virtual bool getDecodedPicture(struct PictureInfo& pict_inf) = 0;
297 virtual void freeReference(void* ref) = 0;
299 virtual void init() {};
300 virtual void shutdown() {};
303 PictureReader* reader;
306 class PictureReader: public Thread_TYPE
313 void addDecoder(PictureDecoder*);
314 void removeDecoder(PictureDecoder*);
319 bool processReceivedPictures();
321 // should be called from control thread
322 void receivePicture(VDR_ResponsePacket* vresp);
324 void addStaticImage(unsigned int id);
326 void invalidateLoadIndex(LoadIndex index);
328 void informFallback(LoadIndex index, int fallback);
337 std::mutex pict_lock_incoming; //locks
338 std::mutex decoders_lock;
339 std::queue<VDR_ResponsePacket*> pict_incoming;
340 std::queue<unsigned int> pict_incoming_static;
341 std::list<PictureDecoder*> decoders;
342 std::map<LoadIndex, int> inform_fallback;
343 std::set<LoadIndex> invalid_loadindex;
349 PictureReader* getPictReader() { return &reader;};
355 PictureReader reader;
357 void incImageRef(ImageIndex index);
358 int getImageRef(ImageIndex index);
359 virtual void destroyImageRef(ImageIndex index) = 0;
360 void incLoadIndexRef(LoadIndex index);
361 int getLoadIndexRef(LoadIndex index);
364 //virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
365 virtual ImageIndex createMonoBitmap(void* base, int width, int height) = 0;
366 virtual ImageIndex createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data) = 0;
367 virtual void createPicture(struct PictureInfo& pict_inf) = 0;
369 virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
373 std::map<ImageIndex, int> images_ref;
374 std::map<void*, ImageIndex> monobitmaps;
375 //map<string,ImageIndex> jpegs;
376 std::map<TVMediaInfo, ImageIndex> tvmedias;
377 std::list<ImageIndex> palettepics;
381 std::map<LoadIndex, int> loadindex_ref;
382 std::map<TVMediaInfo, LoadIndex> tvmedias_load;
383 std::map<LoadIndex, TVMediaInfo> tvmedias_load_inv;
384 std::map<LoadIndex, ImageIndex> tvmedias_loaded;
388 void incrementStyleRefCount(VectorHandle index);
389 virtual void destroyStyleRef(VectorHandle index) = 0;
392 std::map<DrawStyle, VectorHandle> styles;
393 std::map<VectorHandle, int> styles_ref;
394 std::map<DrawStyle, VectorHandle>::iterator styles_lastit;
395 bool styles_lastit_valid{};
396 std::map<VectorHandle, int>::iterator styles_ref_lastit;
397 bool styles_ref_lastit_valid{};
399 virtual VectorHandle createStyleRef(const DrawStyle& c) = 0;
401 void decrementAllRefCounts(std::vector<SVGCommand>& commands);
402 void incrementAllRefCounts(std::vector<SVGCommand>& commands);
403 void cleanupOrphanedRefs();
407 virtual void drawSetTrans(SurfaceInfo& sc) = 0;
408 virtual void executeDrawCommand(SVGCommand& command) = 0;
411 std::list<SurfaceInfo> surfaces;
412 using SurfacesIterator = std::list<SurfaceInfo>::iterator;
414 std::mutex surfaces_mutex;
416 float byte_char_width[256];