]> git.vomp.tv Git - vompclient.git/blob - osdopenvg.h
OsdOpenVG: Tighten up sync between putOpenVGCommands and processOpenVGCommands
[vompclient.git] / osdopenvg.h
1 /*
2     Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter
3
4     This file is part of VOMP.
5
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.
10
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.
15
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/>.
18 */
19
20 #ifndef OSDOPENVG_H
21 #define OSDOPENVG_H
22
23 #include <vector>
24 #include <deque>
25 #include <mutex>
26 #include <thread>
27 #include <condition_variable>
28
29 #include <EGL/egl.h>
30 #include <EGL/eglext.h>
31 #include <VG/openvg.h>
32 #include <VG/vgu.h>
33
34 #include "defines.h"
35 #include "osdvector.h"
36 #include "log.h"
37 #include "threadp.h"
38 #include "videoomx.h"
39 #include "staticartwork.h"
40 #ifdef PICTURE_DECODER_OMX
41   #include "imageomx.h"
42 #endif
43
44 #include <ft2build.h>
45 #include FT_FREETYPE_H
46
47 enum OpenVGTask
48 {
49   OVGdestroyImageRef,
50   OVGdestroyPaint,
51   OVGcreateImagePalette,
52   OVGcreateMonoBitmap,
53   OVGcreateColorRef,
54   OVGimageUploadLine,
55   //OVGcreateImageFile,
56   OVGreplacefont,
57   OVGcreateImageMemory,
58   OVGcreateEGLImage,
59   OVGreadyEGLImage
60 };
61
62 struct OpenVGResponse
63 {
64   bool done{};
65   UINT result;
66   std::condition_variable doneCond;
67 };
68
69 struct OpenVGCommand
70 {
71   enum OpenVGTask task;
72   const void* data;
73   const void* data2;
74   unsigned int param1, param2, param3;
75
76   struct OpenVGResponse* response{}; // If !NULL, a thread is waiting
77 };
78
79 class OsdOpenVG : public OsdVector, public Thread_TYPE
80 #ifdef PICTURE_DECODER_OMX
81   , public EGLPictureCreator
82 #endif
83 {
84   public:
85     OsdOpenVG();
86     virtual ~OsdOpenVG();
87
88     int init();
89     int shutdown();
90     int stopUpdate();
91
92     bool screenShot(void* buffer, int width, int height, bool osd /*include osd*/);
93
94     float getFontHeight();
95     float getCharWidth(wchar_t c);
96
97     int getFontNames(const char***  names, const char***  names_keys);
98
99     virtual void setFont(const char* fontname);
100
101     virtual float getPixelAspect() {return aspect_correction;};
102
103     bool getEGLPicture(struct OsdVector::PictureInfo& info, EGLDisplay* display);
104
105     void updateBackgroundColor(DrawStyle bg);
106
107   protected:
108     /*osd vector implementation*/
109     void destroyImageRef(ImageIndex index);
110     // ImageIndex createJpeg(const char* fileName, int *width,int *height);
111     ImageIndex createMonoBitmap(void* base, int width, int height);
112     ImageIndex createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data);
113     void createPicture(struct PictureInfo& pict_inf);
114     void destroyDrawStyleHandle(VectorHandle index);
115     VectorHandle createDrawStyleHandle(const DrawStyle& c);
116     bool getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length);
117
118     void drawSetTrans(SurfaceInfo& sc);
119     void executeDrawCommand(SVGCommand& command);
120
121     void initPaths();
122     void destroyPaths();
123     VGPath std_paths[PIPoint + 1];
124     long long  lastrendertime;
125     void InternalRendering();
126     void getScreenSize(int& width, int& height);
127     void getRealScreenSize(int& width, int& height);
128
129     std::mutex vgmutex;
130     std::mutex taskmutex;
131
132     std::deque<OpenVGCommand> vgcommands;
133     bool processOpenVGCommands();
134     unsigned int putOpenVGCommand(OpenVGCommand& comm, bool wait);
135     unsigned int handleOpenVGCommand(OpenVGCommand& command);
136     //void purgeAllReferences();
137
138     FT_Library  ft_library;
139     FT_Face     ft_face;
140     VGFont vgfont;
141     VGFont vgttfont;
142     VGPaint vgttpaint;
143     int loadFont(bool fontchange);
144     std::map<unsigned int, float> font_exp_x;
145     std::vector<char*> fontnames;
146     std::vector<char*> fontnames_keys;
147     char* cur_fontname;
148
149     int clip_shift_x;
150     int clip_shift_y;
151
152     unsigned int loadTTchar(cTeletextChar c);
153     std::map<unsigned int, int> tt_font_chars;
154
155     void threadMethod();
156
157     /* BCM specific */
158
159     uint32_t display_height{};
160     uint32_t display_width{};
161     DISPMANX_DISPLAY_HANDLE_T bcm_display;
162     DISPMANX_ELEMENT_HANDLE_T bcm_element;
163     DISPMANX_ELEMENT_HANDLE_T bcm_background;
164     DISPMANX_RESOURCE_HANDLE_T bcm_backres{};
165
166     uint32_t mode{};
167
168     EGLDisplay egl_display;
169     EGLSurface egl_surface;
170     EGLContext egl_context;
171     EGLConfig egl_ourconfig;
172     float font_height;
173     float aspect_correction{1.};
174     bool freetype_inited{};
175
176     uint8_t* static_artwork_begin[sa_MAX];
177     uint8_t* static_artwork_end[sa_MAX];
178
179 #ifdef PICTURE_DECODER_OMX
180     ImageOMX* imageomx;
181 #endif
182
183     // future
184     //std::thread renderThread;
185     //std::mutex threadStartProtect;
186
187 };
188
189 #endif