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 "messagequeue.h"
33 #include "threadsystem.h"
38 #include "teletextdecodervbiebu.h"
72 typedef VectorHandle ImageIndex;
73 typedef unsigned long long LoadIndex;
78 inline static SVGCommand PaintPath(float ix, float iy, float iw, float ih, PathIndex path, VectorHandle ref)
86 nc.target.path_index = path;
87 nc.handle = ref; // always a valid DrawStyle handle
91 inline static SVGCommand PaintImageLoading(LoadIndex load_in, float ix, float iy, float iw, float ih, Corner corner = TopLeft)
94 nc.instr = DrawImageLoading;
99 nc.target.loadindex = load_in;
100 nc.handle = 0; // not valid for PaintImageLoading
105 inline static SVGCommand PaintImage(float ix, float iy, float iw, float ih, ImageIndex image_in, VectorHandle ref, Corner corner = TopLeft)
108 nc.instr = DrawImage;
113 nc.target.image = image_in;
114 nc.handle = ref; // can be 0 (no handle) or can be an Drawstyle nandle
119 inline static SVGCommand PaintTTchar(float ix, float iy, float iw, float ih, unsigned int ttchar_in)
122 nc.instr = DrawTTchar;
127 nc.handle = 0; // not valid for PaintTTchar
128 nc.target.ttchar = ttchar_in;
133 inline static SVGCommand PaintClipping(float ix, float iy, float iw, float ih)
136 nc.instr = DrawClipping;
141 nc.handle = 0; // not valid for PaintClipping
142 nc.target.ttchar = 0;
146 inline static void PaintGlyph(SVGCommand& nc, float ix, float iy, wchar_t char_in, VectorHandle ref)
148 nc.instr = DrawGlyph;
153 nc.handle = ref; // always a valid DrawStyle handle
154 nc.target.textchar = char_in;
157 bool Test(float tx, float ty, float tw, float th)
159 return (x >= tx) && (y >= ty) && ((x + w) <= (tx + tw)) && ((y + h) <= (ty + th));
162 bool TTTest(float tox, float toy, float tx, float ty)
164 return (x == tox) && (toy == y) && (w == tx) && (h == ty);
167 bool Outside(float tx, float ty, float tw, float th)
169 return ((x + w) < tx) || ((y + h) < ty) || ((tx + tw) < x) || ((ty + th) < y);
172 VectorHandle getHandle()
177 ImageIndex getImageIndex()
179 if (instr != DrawImage) return 0;
180 else return target.image;
183 LoadIndex getLoadIndex()
185 if (instr != DrawImageLoading) return 0;
186 else return target.loadindex;
189 SVGCommandInstr instr{DrawNoop};
191 float x{}, y{}, w{}, h{};
192 VectorHandle handle{VECTOR_HANDLE_INIT};
195 PathIndex path_index;
204 class VDR_ResponsePacket;
208 const SurfaceVector* surface;
209 std::vector<SVGCommand> commands;
213 class OsdVector : public Osd, public MessageReceiver
217 virtual ~OsdVector();
221 bool screenShot(const char* fileName);
222 virtual bool screenShotInternal(void* buffer, int width, int height, bool osd /*include osd*/) = 0;
224 Surface* createNewSurface();
227 virtual void updateBackgroundColor(DrawStyle /* bg */) {};
229 void updateOrAddSurface(const SurfaceVector* surf, float x, float y, float height, float width,
230 std::vector<SVGCommand>& commands);
231 void removeSurface(const SurfaceVector* surf);
233 virtual float getFontHeight() = 0;
234 virtual float getCharWidth(wchar_t c) = 0;
235 float* getCharWidthArray() {return byte_char_width;};
237 //virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);
238 virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia, ImageIndex& image);
239 virtual ImageIndex getMonoBitmapRef(void* base, int width, int height);
240 virtual ImageIndex getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data);
243 virtual bool getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length) = 0;
245 void removeImageRef(const ImageIndex ref);
246 void removeLoadIndexRef(const LoadIndex ref);
247 VectorHandle getDrawStyleHandle(const DrawStyle& c);
248 virtual void decrementDrawStyleHandleRefCount(VectorHandle ref);
249 virtual void getScreenSize(int& width, int& height) = 0;
250 virtual void getRealScreenSize(int& width, int& height) = 0;
252 // should be only called from control thread
253 void informPicture(LoadIndex index, ImageIndex i_index);
254 void processMessage(Message* m);
257 int charSet() {return 2;}; //UTF-8
260 class PictureDecoder;
279 PictureDecoder* decoder;
288 PictureDecoder(PictureReader* treader) {reader = treader;};
289 virtual ~PictureDecoder() {};
291 // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
292 virtual unsigned char* decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem = true) = 0;
294 virtual bool getDecodedPicture(struct PictureInfo& pict_inf) = 0;
295 virtual void freeReference(void* ref) = 0;
297 virtual void init() {};
298 virtual void shutdown() {};
301 PictureReader* reader;
304 class PictureReader: public Thread_TYPE
309 void addDecoder(PictureDecoder*);
310 void removeDecoder(PictureDecoder*);
312 bool processReceivedPictures();
314 // should be called from control thread
315 void receivePicture(VDR_ResponsePacket* vresp);
317 void addStaticImage(unsigned int id);
318 void invalidateLoadIndex(LoadIndex index);
319 void informFallback(LoadIndex index, int fallback);
325 std::mutex pict_lock_incoming; //locks
326 std::mutex decoders_lock;
327 std::queue<VDR_ResponsePacket*> pict_incoming;
328 std::queue<unsigned int> pict_incoming_static;
329 std::list<PictureDecoder*> decoders;
330 std::map<LoadIndex, int> inform_fallback;
331 std::set<LoadIndex> invalid_loadindex;
336 PictureReader* getPictReader() { return &reader; };
341 PictureReader reader;
343 std::map<ImageIndex, int> images_ref;
344 std::map<void*, ImageIndex> monobitmaps;
345 //map<string,ImageIndex> jpegs;
346 std::map<TVMediaInfo, ImageIndex> tvmedias;
347 std::list<ImageIndex> palettepics;
348 std::map<LoadIndex, int> loadindex_ref;
349 std::map<TVMediaInfo, LoadIndex> tvmedias_load;
350 std::map<LoadIndex, TVMediaInfo> tvmedias_load_inv;
351 std::map<LoadIndex, ImageIndex> tvmedias_loaded;
353 std::map<DrawStyle, VectorHandle> drawstyleHandles;
354 std::map<DrawStyle, VectorHandle>::iterator drawstyleHandles_lastit;
355 bool drawstyleHandles_lastit_valid{};
357 std::map<VectorHandle, int> drawstyleHandlesRefCounts;
358 std::map<VectorHandle, int>::iterator drawstyleHandlesRefCounts_lastit;
359 bool drawstyleHandlesRefCounts_lastit_valid{};
361 std::list<SurfaceInfo> surfaces;
362 using SurfacesIterator = std::list<SurfaceInfo>::iterator;
364 std::mutex surfaces_mutex;
366 float byte_char_width[256]{};
368 void incImageRef(ImageIndex index);
369 int getImageRef(ImageIndex index);
370 virtual void destroyImageRef(ImageIndex index) = 0;
371 void incLoadIndexRef(LoadIndex index);
372 int getLoadIndexRef(LoadIndex index);
374 //virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
375 virtual ImageIndex createMonoBitmap(void* base, int width, int height) = 0;
376 virtual ImageIndex createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data) = 0;
377 virtual void createPicture(struct PictureInfo& pict_inf) = 0;
379 virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
381 virtual VectorHandle createDrawStyleHandle(const DrawStyle& c) = 0;
382 void incrementDrawStyleHandleRefCount(VectorHandle index);
383 virtual void destroyDrawStyleHandle(VectorHandle index) = 0;
386 void decrementAllRefCounts(std::vector<SVGCommand>& commands);
387 void incrementAllRefCounts(std::vector<SVGCommand>& commands);
388 void cleanupOrphanedRefs();
390 virtual void drawSetTrans(SurfaceInfo& sc) = 0;
391 virtual void executeDrawCommand(SVGCommand& command) = 0;