]> git.vomp.tv Git - vompclient.git/blob - src/osdopenvg.h
Type change: UCHAR -> u1
[vompclient.git] / src / 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 "videoomx.h"
37 #include "messagequeue.h"
38 #include "staticartwork.h"
39 #ifdef PICTURE_DECODER_OMX
40   //#include "imageomx.h"
41   #include "imageomx2.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   u4 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 ImageOMX2;
80
81 #include "eglpicturecreator.h"
82
83 class OsdImageOpenVG : public OsdImageBase
84 {
85   friend class OsdOpenVG;
86   private:
87     OsdImageOpenVG(VGImage vgi)
88     : vgimage(vgi) {}
89
90     VGImage getVGImage() { return vgimage; }
91
92     VGImage vgimage;
93 };
94
95 class OsdOpenVG : public OsdVector, public MessageReceiver
96 #ifdef PICTURE_DECODER_OMX
97   , public EGLPictureCreator
98 #endif
99 {
100   public:
101     OsdOpenVG();
102     virtual ~OsdOpenVG();
103
104     int init();
105     int shutdown();
106     int stopUpdate();
107
108     bool screenShotInternal(void* buffer, int width, int height, bool includeOSD);
109
110     float getFontHeight();
111     float getCharWidth(wchar_t c);
112
113     int getFontNames(const char***  names, const char***  names_keys);
114
115     virtual void setFont(const char* fontname);
116
117     virtual float getPixelAspect() {return aspect_correction;};
118
119     bool getEGLPicture(struct PictureInfo& info, EGLDisplay* display);
120
121     void updateBackgroundColor(DrawStyle bg);
122
123     void createPicture(struct PictureInfo& pict_inf);
124
125     void processMessage(Message* m);
126
127     void garbageCollectOsdImages();
128
129   protected:
130
131     // OSDOVG-ROD-EXPERIMENT
132     void doRender();
133
134     /*osd vector implementation*/
135     void destroyImageRef(VectorHandleImage handle);
136     // VectorHandleImage createJpeg(const char* fileName, int *width,int *height);
137     VectorHandleImage createMonoBitmap(void* base, int width, int height);
138     VectorHandleImage createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data);
139     void destroyDrawStyleHandle(VectorHandle index);
140     VectorHandle createDrawStyleHandle(const DrawStyle& c);
141     bool getStaticImageData(unsigned int static_id, u1** userdata, u4* length);
142
143     void drawSetTrans(SurfaceInfo& sc);
144     void executeDrawCommand(SVGCommand& command);
145
146     void initPaths();
147     void destroyPaths();
148     VGPath std_paths[PIPoint + 1];
149     long long  lastrendertime;
150     void InternalRendering();
151     void getScreenSize(int& width, int& height);
152     void getRealScreenSize(int& width, int& height);
153
154     std::mutex vgmutex;
155     std::mutex taskmutex;
156
157     std::deque<OpenVGCommand> vgcommands;
158     bool processOpenVGCommands();
159     unsigned int putOpenVGCommand(OpenVGCommand& comm, bool wait);
160     unsigned int handleOpenVGCommand(OpenVGCommand& command);
161     //void purgeAllReferences();
162
163     FT_Library  ft_library;
164     FT_Face     ft_face;
165     VGFont vgfont;
166     VGFont vgttfont;
167     VGPaint vgttpaint;
168     int loadFont(bool fontchange);
169     std::map<unsigned int, float> font_exp_x;
170     std::vector<char*> fontnames;
171     std::vector<char*> fontnames_keys;
172     char* cur_fontname;
173
174     int clip_shift_x;
175     int clip_shift_y;
176
177     unsigned int loadTTchar(cTeletextChar c);
178     std::map<unsigned int, int> tt_font_chars;
179
180     std::thread renderThread;
181     std::mutex renderThreadMutex; // used for start-protect, go-around signal, quit signal
182     std::condition_variable renderThreadCond;
183     int renderThreadReq; // 1 - do update, 2 - stop
184     void renderLoop();
185     void renderThreadStop();
186
187     /* BCM specific */
188
189     int32_t display_height{};
190     int32_t display_width{};
191     DISPMANX_DISPLAY_HANDLE_T bcm_display;
192     DISPMANX_ELEMENT_HANDLE_T bcm_element;
193     DISPMANX_ELEMENT_HANDLE_T bcm_background;
194     DISPMANX_RESOURCE_HANDLE_T bcm_backres{};
195
196     uint32_t mode{};
197
198     EGLDisplay egl_display;
199     EGLSurface egl_surface;
200     EGLContext egl_context;
201     EGLConfig egl_ourconfig;
202     float font_height;
203     float aspect_correction{1.};
204     bool freetype_inited{};
205
206     uint8_t* static_artwork_begin[sa_MAX];
207     uint8_t* static_artwork_end[sa_MAX];
208
209 #ifdef PICTURE_DECODER_OMX
210     ImageOMX2* imageomx2;
211 #endif
212 };
213
214 #endif