2 Copyright 2004-2005,2021 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 "osdvectortypes.h"
38 #include "imageloader.h"
39 #include "teletextdecodervbiebu.h"
66 inline static SVGCommand PaintPath(float ix, float iy, float iw, float ih, PathIndex path, VectorHandle ref)
74 nc.target.path_index = path;
75 nc.handle = ref; // always a valid DrawStyle handle
79 inline static SVGCommand PaintImageLoading(Image& image, float ix, float iy, float iw, float ih, Corner corner = TopLeft)
82 nc.instr = DrawImageLoading;
87 nc.handle = 0; // not valid for PaintImageLoading
95 inline static SVGCommand PaintBitmap(float ix, float iy, float iw, float ih,
96 VectorHandleImage handle, VectorHandle ref, Corner corner = TopLeft)
99 nc.instr = DrawBitmap;
104 nc.target.bitmap = handle;
105 nc.handle = ref; // can be 0 (no handle) or can be an Drawstyle nandle
110 inline static SVGCommand PaintImage(float ix, float iy, float iw, float ih,
111 Image& image, Corner corner = TopLeft)
114 nc.instr = DrawImage;
124 inline static SVGCommand PaintTTchar(float ix, float iy, float iw, float ih, unsigned int ttchar_in)
127 nc.instr = DrawTTchar;
132 nc.handle = 0; // not valid for PaintTTchar
133 nc.target.ttchar = ttchar_in;
138 inline static SVGCommand PaintClipping(float ix, float iy, float iw, float ih)
141 nc.instr = DrawClipping;
146 nc.handle = 0; // not valid for PaintClipping
147 nc.target.ttchar = 0;
151 inline static void PaintGlyph(SVGCommand& nc, float ix, float iy, wchar_t char_in, VectorHandle ref)
153 nc.instr = DrawGlyph;
158 nc.handle = ref; // always a valid DrawStyle handle
159 nc.target.textchar = char_in;
162 bool Test(float tx, float ty, float tw, float th)
164 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);
172 bool Outside(float tx, float ty, float tw, float th)
174 return ((x + w) < tx) || ((y + h) < ty) || ((tx + tw) < x) || ((ty + th) < y);
177 VectorHandle getHandle() // Is this DrawStyle references?
182 VectorHandleImage getImageHandle()
184 if (instr != DrawBitmap) return 0;
185 else return target.bitmap;
188 SVGCommandInstr instr{DrawNoop};
190 float x{}, y{}, w{}, h{};
191 VectorHandle handle{VECTOR_HANDLE_INIT};
194 PathIndex path_index;
196 VectorHandleImage bitmap;
200 Image image; // This would be in the union but it's a non-trivial type
204 class VDR_ResponsePacket;
208 const SurfaceVector* surface;
209 std::vector<SVGCommand> commands;
213 class OsdVector : public Osd
219 virtual ~OsdVector();
221 // FIXME switch to bool
222 virtual int init(); // Derived classes overriding init() must call this base init()
226 bool screenShot(const char* fileName);
227 virtual bool screenShotInternal(void* buffer, int width, int height, bool osd /*include osd*/) = 0;
229 Surface* createNewSurface();
232 virtual void updateBackgroundColor(DrawStyle /* bg */) {};
234 void updateOrAddSurface(const SurfaceVector* surf, float x, float y, float height, float width,
235 std::vector<SVGCommand>& commands);
236 void removeSurface(const SurfaceVector* surf);
238 virtual float getFontHeight() = 0;
239 virtual float getCharWidth(wchar_t c) = 0;
240 float* getCharWidthArray() {return byte_char_width;};
241 virtual void getScreenSize(int& width, int& height) = 0;
242 virtual void getRealScreenSize(int& width, int& height) = 0;
244 virtual bool getStaticImageData(unsigned int static_id, u1** userdata, u4* length) = 0;
246 // Used only by OsdVector and SurfaceVector
247 void removeImageRef(const VectorHandleImage ref);
248 VectorHandle getDrawStyleHandle(const DrawStyle& c);
249 void decrementDrawStyleHandleRefCount(VectorHandle ref);
250 //virtual VectorHandleImage getJpegRef(const char* fileName, int *width,int *height);
251 virtual VectorHandleImage getMonoBitmapRef(void* base, int width, int height);
252 virtual VectorHandleImage getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data);
254 int charSet() {return 2;}; //UTF-8
256 virtual void createPicture(struct PictureInfo& pict_inf) = 0;
257 virtual void destroyImageRef(VectorHandleImage handle) = 0;
262 float byte_char_width[256]{};
264 //virtual VectorHandleImage createJpeg(const char* fileName, int *width,int *height)=0;
265 virtual VectorHandleImage createMonoBitmap(void* base, int width, int height) = 0;
266 virtual VectorHandleImage createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data) = 0;
267 virtual VectorHandle createDrawStyleHandle(const DrawStyle& c) = 0;
268 virtual void destroyDrawStyleHandle(VectorHandle index) = 0;
269 virtual void drawSetTrans(SurfaceInfo& sc) = 0;
270 virtual void executeDrawCommand(SVGCommand& command) = 0;
279 // Methods that only seem to be called internally
280 void incImageRef(VectorHandleImage handle);
281 void decrementAllRefCounts(std::vector<SVGCommand>& commands);
282 void incrementAllRefCounts(std::vector<SVGCommand>& commands);
283 void cleanupOrphanedRefs();
284 void incrementDrawStyleHandleRefCount(VectorHandle index);
286 // All the below are data structures only touched by this base class OsdVector
288 std::map<void*, VectorHandleImage> monobitmaps;
289 //map<string,VectorHandleImage> jpegs;
290 std::list<VectorHandleImage> palettepics;
291 std::map<VectorHandleImage, int> vhi_refcounts; // This appears to cover all 3 (4) of the above types
293 std::map<DrawStyle, VectorHandle> drawstyleHandles;
294 std::map<DrawStyle, VectorHandle>::iterator drawstyleHandles_lastit;
295 bool drawstyleHandles_lastit_valid{};
297 std::map<VectorHandle, int> drawstyleHandlesRefCounts;
298 std::map<VectorHandle, int>::iterator drawstyleHandlesRefCounts_lastit;
299 bool drawstyleHandlesRefCounts_lastit_valid{};
301 std::list<SurfaceInfo> surfaces;
302 using SurfacesIterator = std::list<SurfaceInfo>::iterator;
303 std::mutex surfaces_mutex;