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