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