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/>.
31 #include <condition_variable>
34 #include "messagequeue.h"
39 #include "teletextdecodervbiebu.h"
73 typedef VectorHandle VectorHandleImage;
74 typedef unsigned long long LoadIndex;
79 inline static SVGCommand PaintPath(float ix, float iy, float iw, float ih, PathIndex path, VectorHandle ref)
87 nc.target.path_index = path;
88 nc.handle = ref; // always a valid DrawStyle handle
92 inline static SVGCommand PaintImageLoading(LoadIndex load_in, float ix, float iy, float iw, float ih, Corner corner = TopLeft)
95 nc.instr = DrawImageLoading;
100 nc.target.loadindex = load_in;
101 nc.handle = 0; // not valid for PaintImageLoading
106 inline static SVGCommand PaintImage(float ix, float iy, float iw, float ih, VectorHandleImage handle, VectorHandle ref, Corner corner = TopLeft)
109 nc.instr = DrawImage;
114 nc.target.image = handle;
115 nc.handle = ref; // can be 0 (no handle) or can be an Drawstyle nandle
120 inline static SVGCommand PaintTTchar(float ix, float iy, float iw, float ih, unsigned int ttchar_in)
123 nc.instr = DrawTTchar;
128 nc.handle = 0; // not valid for PaintTTchar
129 nc.target.ttchar = ttchar_in;
134 inline static SVGCommand PaintClipping(float ix, float iy, float iw, float ih)
137 nc.instr = DrawClipping;
142 nc.handle = 0; // not valid for PaintClipping
143 nc.target.ttchar = 0;
147 inline static void PaintGlyph(SVGCommand& nc, float ix, float iy, wchar_t char_in, VectorHandle ref)
149 nc.instr = DrawGlyph;
154 nc.handle = ref; // always a valid DrawStyle handle
155 nc.target.textchar = char_in;
158 bool Test(float tx, float ty, float tw, float th)
160 return (x >= tx) && (y >= ty) && ((x + w) <= (tx + tw)) && ((y + h) <= (ty + th));
163 bool TTTest(float tox, float toy, float tx, float ty)
165 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 getHandle()
178 VectorHandleImage getImageHandle()
180 if (instr != DrawImage) return 0;
181 else return target.image;
184 LoadIndex getLoadIndex()
186 if (instr != DrawImageLoading) return 0;
187 else return target.loadindex;
190 SVGCommandInstr instr{DrawNoop};
192 float x{}, y{}, w{}, h{};
193 VectorHandle handle{VECTOR_HANDLE_INIT};
196 PathIndex path_index;
198 VectorHandleImage image;
205 class VDR_ResponsePacket;
209 const SurfaceVector* surface;
210 std::vector<SVGCommand> commands;
214 class OsdVector : public Osd, public MessageReceiver
218 virtual ~OsdVector();
222 bool screenShot(const char* fileName);
223 virtual bool screenShotInternal(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 VectorHandleImage getJpegRef(const char* fileName, int *width,int *height);
239 virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia, VectorHandleImage& handle);
240 virtual VectorHandleImage getMonoBitmapRef(void* base, int width, int height);
241 virtual VectorHandleImage 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 VectorHandleImage ref);
247 void removeLoadIndexRef(const LoadIndex ref);
248 VectorHandle getDrawStyleHandle(const DrawStyle& c);
249 virtual void decrementDrawStyleHandleRefCount(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, VectorHandleImage handle);
255 void processMessage(Message* m);
258 int charSet() {return 2;}; //UTF-8
261 class PictureDecoder;
280 PictureDecoder* decoder;
289 PictureDecoder(PictureReader* treader) {reader = treader;};
290 virtual ~PictureDecoder() {};
292 // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
293 virtual unsigned char* decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem = true) = 0;
295 virtual bool getDecodedPicture(struct PictureInfo& pict_inf) = 0;
296 virtual void freeReference(void* ref) = 0;
298 virtual void init() {};
299 virtual void shutdown() {};
302 PictureReader* reader;
310 void addDecoder(PictureDecoder*);
311 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);
319 void invalidateLoadIndex(LoadIndex index);
320 void informFallback(LoadIndex index, int fallback);
325 std::mutex threadMutex;
326 std::thread readerThread;
327 bool threadReqQuit{};
328 std::condition_variable threadCond;
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;
342 PictureReader* getPictReader() { return &reader; };
347 PictureReader reader;
349 std::map<VectorHandleImage, int> images_ref;
350 std::map<void*, VectorHandleImage> monobitmaps;
351 //map<string,VectorHandleImage> jpegs;
352 std::map<TVMediaInfo, VectorHandleImage> tvmedias;
353 std::list<VectorHandleImage> palettepics;
354 std::map<LoadIndex, int> loadindex_ref;
355 std::map<TVMediaInfo, LoadIndex> tvmedias_load;
356 std::map<LoadIndex, TVMediaInfo> tvmedias_load_inv;
357 std::map<LoadIndex, VectorHandleImage> tvmedias_loaded;
359 std::map<DrawStyle, VectorHandle> drawstyleHandles;
360 std::map<DrawStyle, VectorHandle>::iterator drawstyleHandles_lastit;
361 bool drawstyleHandles_lastit_valid{};
363 std::map<VectorHandle, int> drawstyleHandlesRefCounts;
364 std::map<VectorHandle, int>::iterator drawstyleHandlesRefCounts_lastit;
365 bool drawstyleHandlesRefCounts_lastit_valid{};
367 std::list<SurfaceInfo> surfaces;
368 using SurfacesIterator = std::list<SurfaceInfo>::iterator;
370 std::mutex surfaces_mutex;
372 float byte_char_width[256]{};
374 void incImageRef(VectorHandleImage handle);
375 int getImageRef(VectorHandleImage handle);
376 virtual void destroyImageRef(VectorHandleImage handle) = 0;
377 void incLoadIndexRef(LoadIndex index);
378 int getLoadIndexRef(LoadIndex index);
380 //virtual VectorHandleImage createJpeg(const char* fileName, int *width,int *height)=0;
381 virtual VectorHandleImage createMonoBitmap(void* base, int width, int height) = 0;
382 virtual VectorHandleImage createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data) = 0;
383 virtual void createPicture(struct PictureInfo& pict_inf) = 0;
385 virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
387 virtual VectorHandle createDrawStyleHandle(const DrawStyle& c) = 0;
388 void incrementDrawStyleHandleRefCount(VectorHandle index);
389 virtual void destroyDrawStyleHandle(VectorHandle index) = 0;
392 void decrementAllRefCounts(std::vector<SVGCommand>& commands);
393 void incrementAllRefCounts(std::vector<SVGCommand>& commands);
394 void cleanupOrphanedRefs();
396 virtual void drawSetTrans(SurfaceInfo& sc) = 0;
397 virtual void executeDrawCommand(SVGCommand& command) = 0;