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"
37 #include "teletextdecodervbiebu.h"
69 typedef VectorHandle ImageIndex;
70 typedef unsigned long long LoadIndex;
75 inline static SVGCommand PaintPath(float ix, float iy, float iw, float ih, PathIndex path, VectorHandle ref)
83 nc.target.path_index = path;
84 nc.handle = ref; // always a valid DrawStyle handle
88 inline static SVGCommand PaintImageLoading(LoadIndex load_in, float ix, float iy, float iw, float ih, Corner corner = TopLeft)
91 nc.instr = DrawImageLoading;
96 nc.target.loadindex = load_in;
97 nc.handle = 0; // not valid for PaintImageLoading
102 inline static SVGCommand PaintImage(float ix, float iy, float iw, float ih, ImageIndex image_in, VectorHandle ref, Corner corner = TopLeft)
105 nc.instr = DrawImage;
110 nc.target.image = image_in;
111 nc.handle = ref; // can be 0 (no handle) or can be an Drawstyle nandle
116 inline static SVGCommand PaintTTchar(float ix, float iy, float iw, float ih, unsigned int ttchar_in)
119 nc.instr = DrawTTchar;
124 nc.handle = 0; // not valid for PaintTTchar
125 nc.target.ttchar = ttchar_in;
130 inline static SVGCommand PaintClipping(float ix, float iy, float iw, float ih)
133 nc.instr = DrawClipping;
138 nc.handle = 0; // not valid for PaintClipping
139 nc.target.ttchar = 0;
143 inline static void PaintGlyph(SVGCommand& nc, float ix, float iy, wchar_t char_in, VectorHandle ref)
145 nc.instr = DrawGlyph;
150 nc.handle = ref; // always a valid DrawStyle handle
151 nc.target.textchar = char_in;
154 bool Test(float tx, float ty, float tw, float th)
156 return (x >= tx) && (y >= ty) && ((x + w) <= (tx + tw)) && ((y + h) <= (ty + th));
159 bool TTTest(float tox, float toy, float tx, float ty)
161 return (x == tox) && (toy == y) && (w == tx) && (h == ty);
164 bool Outside(float tx, float ty, float tw, float th)
166 return ((x + w) < tx) || ((y + h) < ty) || ((tx + tw) < x) || ((ty + th) < y);
169 VectorHandle getHandle()
174 ImageIndex getImageIndex()
176 if (instr != DrawImage) return 0;
177 else return target.image;
180 LoadIndex getLoadIndex()
182 if (instr != DrawImageLoading) return 0;
183 else return target.loadindex;
186 SVGCommandInstr instr{DrawNoop};
188 float x{}, y{}, w{}, h{};
189 VectorHandle handle{VECTOR_HANDLE_INIT};
192 PathIndex path_index;
201 class VDR_ResponsePacket;
205 const SurfaceVector* surface;
206 std::vector<SVGCommand> commands;
210 class OsdVector : public Osd
217 bool screenShot(const char* fileName);
218 virtual bool screenShotInternal(void* buffer, int width, int height, bool osd /*include osd*/) = 0;
220 Surface* createNewSurface();
223 virtual void updateBackgroundColor(DrawStyle /* bg */) {};
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);
229 virtual float getFontHeight() = 0;
230 virtual float getCharWidth(wchar_t c) = 0;
231 float* getCharWidthArray() {return byte_char_width;};
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);
239 virtual bool getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length) = 0;
241 void removeImageRef(const ImageIndex ref);
242 void removeLoadIndexRef(const LoadIndex ref);
243 VectorHandle getDrawStyleHandle(const DrawStyle& c);
244 virtual void decrementDrawStyleHandleRefCount(VectorHandle ref);
245 virtual void getScreenSize(int& width, int& height) = 0;
246 virtual void getRealScreenSize(int& width, int& height) = 0;
248 // should be only called from control thread
249 void informPicture(LoadIndex index, ImageIndex i_index);
252 int charSet() {return 2;}; //UTF-8
255 class PictureDecoder;
274 PictureDecoder* decoder;
283 PictureDecoder(PictureReader* treader) {reader = treader;};
284 virtual ~PictureDecoder() {};
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;
289 virtual bool getDecodedPicture(struct PictureInfo& pict_inf) = 0;
290 virtual void freeReference(void* ref) = 0;
292 virtual void init() {};
293 virtual void shutdown() {};
296 PictureReader* reader;
299 class PictureReader: public Thread_TYPE
304 void addDecoder(PictureDecoder*);
305 void removeDecoder(PictureDecoder*);
307 bool processReceivedPictures();
309 // should be called from control thread
310 void receivePicture(VDR_ResponsePacket* vresp);
312 void addStaticImage(unsigned int id);
313 void invalidateLoadIndex(LoadIndex index);
314 void informFallback(LoadIndex index, int fallback);
320 std::mutex pict_lock_incoming; //locks
321 std::mutex decoders_lock;
322 std::queue<VDR_ResponsePacket*> pict_incoming;
323 std::queue<unsigned int> pict_incoming_static;
324 std::list<PictureDecoder*> decoders;
325 std::map<LoadIndex, int> inform_fallback;
326 std::set<LoadIndex> invalid_loadindex;
331 PictureReader* getPictReader() { return &reader; };
335 PictureReader reader;
337 std::map<ImageIndex, int> images_ref;
338 std::map<void*, ImageIndex> monobitmaps;
339 //map<string,ImageIndex> jpegs;
340 std::map<TVMediaInfo, ImageIndex> tvmedias;
341 std::list<ImageIndex> palettepics;
342 std::map<LoadIndex, int> loadindex_ref;
343 std::map<TVMediaInfo, LoadIndex> tvmedias_load;
344 std::map<LoadIndex, TVMediaInfo> tvmedias_load_inv;
345 std::map<LoadIndex, ImageIndex> tvmedias_loaded;
347 std::map<DrawStyle, VectorHandle> drawstyleHandles;
348 std::map<DrawStyle, VectorHandle>::iterator drawstyleHandles_lastit;
349 bool drawstyleHandles_lastit_valid{};
351 std::map<VectorHandle, int> drawstyleHandlesRefCounts;
352 std::map<VectorHandle, int>::iterator drawstyleHandlesRefCounts_lastit;
353 bool drawstyleHandlesRefCounts_lastit_valid{};
355 std::list<SurfaceInfo> surfaces;
356 using SurfacesIterator = std::list<SurfaceInfo>::iterator;
358 std::mutex surfaces_mutex;
360 float byte_char_width[256]{};
362 void incImageRef(ImageIndex index);
363 int getImageRef(ImageIndex index);
364 virtual void destroyImageRef(ImageIndex index) = 0;
365 void incLoadIndexRef(LoadIndex index);
366 int getLoadIndexRef(LoadIndex index);
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;
373 virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
375 virtual VectorHandle createDrawStyleHandle(const DrawStyle& c) = 0;
376 void incrementDrawStyleHandleRefCount(VectorHandle index);
377 virtual void destroyDrawStyleHandle(VectorHandle index) = 0;
380 void decrementAllRefCounts(std::vector<SVGCommand>& commands);
381 void incrementAllRefCounts(std::vector<SVGCommand>& commands);
382 void cleanupOrphanedRefs();
384 virtual void drawSetTrans(SurfaceInfo& sc) = 0;
385 virtual void executeDrawCommand(SVGCommand& command) = 0;