]> git.vomp.tv Git - vompclient.git/blob - osdopenvg.h
Fix VRecording showing graphic at bottom left when it shouldn't
[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 "videoomx.h"
37 #include "staticartwork.h"
38 #ifdef PICTURE_DECODER_OMX
39   #include "imageomx.h"
40 #endif
41
42 #include <ft2build.h>
43 #include FT_FREETYPE_H
44
45 enum OpenVGTask
46 {
47   OVGdestroyImageRef,
48   OVGdestroyPaint,
49   OVGcreateImagePalette,
50   OVGcreateMonoBitmap,
51   OVGcreateColorRef,
52   OVGimageUploadLine,
53   //OVGcreateImageFile,
54   OVGreplacefont,
55   OVGcreateImageMemory,
56   OVGcreateEGLImage,
57   OVGreadyEGLImage
58 };
59
60 struct OpenVGResponse
61 {
62   bool done{};
63   UINT result;
64   std::condition_variable doneCond;
65 };
66
67 struct OpenVGCommand
68 {
69   enum OpenVGTask task;
70   const void* data;
71   const void* data2;
72   unsigned int param1, param2, param3;
73
74   struct OpenVGResponse* response{}; // If !NULL, a thread is waiting
75 };
76
77 class OsdOpenVG : public OsdVector
78 #ifdef PICTURE_DECODER_OMX
79   , public EGLPictureCreator
80 #endif
81 {
82   public:
83     OsdOpenVG();
84     virtual ~OsdOpenVG();
85
86     int init();
87     int shutdown();
88     int stopUpdate();
89
90     bool screenShotInternal(void* buffer, int width, int height, bool includeOSD);
91
92     float getFontHeight();
93     float getCharWidth(wchar_t c);
94
95     int getFontNames(const char***  names, const char***  names_keys);
96
97     virtual void setFont(const char* fontname);
98
99     virtual float getPixelAspect() {return aspect_correction;};
100
101     bool getEGLPicture(struct OsdVector::PictureInfo& info, EGLDisplay* display);
102
103     void updateBackgroundColor(DrawStyle bg);
104
105   protected:
106
107     // OSDOVG-ROD-EXPERIMENT
108     void doRender();
109
110     /*osd vector implementation*/
111     void destroyImageRef(ImageIndex index);
112     // ImageIndex createJpeg(const char* fileName, int *width,int *height);
113     ImageIndex createMonoBitmap(void* base, int width, int height);
114     ImageIndex createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data);
115     void createPicture(struct PictureInfo& pict_inf);
116     void destroyDrawStyleHandle(VectorHandle index);
117     VectorHandle createDrawStyleHandle(const DrawStyle& c);
118     bool getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length);
119
120     void drawSetTrans(SurfaceInfo& sc);
121     void executeDrawCommand(SVGCommand& command);
122
123     void initPaths();
124     void destroyPaths();
125     VGPath std_paths[PIPoint + 1];
126     long long  lastrendertime;
127     void InternalRendering();
128     void getScreenSize(int& width, int& height);
129     void getRealScreenSize(int& width, int& height);
130
131     std::mutex vgmutex;
132     std::mutex taskmutex;
133
134     std::deque<OpenVGCommand> vgcommands;
135     bool processOpenVGCommands();
136     unsigned int putOpenVGCommand(OpenVGCommand& comm, bool wait);
137     unsigned int handleOpenVGCommand(OpenVGCommand& command);
138     //void purgeAllReferences();
139
140     FT_Library  ft_library;
141     FT_Face     ft_face;
142     VGFont vgfont;
143     VGFont vgttfont;
144     VGPaint vgttpaint;
145     int loadFont(bool fontchange);
146     std::map<unsigned int, float> font_exp_x;
147     std::vector<char*> fontnames;
148     std::vector<char*> fontnames_keys;
149     char* cur_fontname;
150
151     int clip_shift_x;
152     int clip_shift_y;
153
154     unsigned int loadTTchar(cTeletextChar c);
155     std::map<unsigned int, int> tt_font_chars;
156
157     std::thread renderThread;
158     std::mutex renderThreadMutex; // used for start-protect, go-around signal, quit signal
159     std::condition_variable renderThreadCond;
160     int renderThreadReq; // 1 - do update, 2 - stop
161     void renderLoop();
162     void renderThreadStop();
163
164     /* BCM specific */
165
166     int32_t display_height{};
167     int32_t display_width{};
168     DISPMANX_DISPLAY_HANDLE_T bcm_display;
169     DISPMANX_ELEMENT_HANDLE_T bcm_element;
170     DISPMANX_ELEMENT_HANDLE_T bcm_background;
171     DISPMANX_RESOURCE_HANDLE_T bcm_backres{};
172
173     uint32_t mode{};
174
175     EGLDisplay egl_display;
176     EGLSurface egl_surface;
177     EGLContext egl_context;
178     EGLConfig egl_ourconfig;
179     float font_height;
180     float aspect_correction{1.};
181     bool freetype_inited{};
182
183     uint8_t* static_artwork_begin[sa_MAX];
184     uint8_t* static_artwork_end[sa_MAX];
185
186 #ifdef PICTURE_DECODER_OMX
187     ImageOMX* imageomx;
188 #endif
189 };
190
191 #endif