]> git.vomp.tv Git - vompclient.git/blob - osdopenvg.h
36 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 <condition_variable>
27
28 #include <EGL/egl.h>
29 #include <EGL/eglext.h>
30 #include <VG/openvg.h>
31 #include <VG/vgu.h>
32
33 #include "defines.h"
34 #include "osdvector.h"
35 #include "log.h"
36 #include "threadp.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 OpenVGCommand
62 {
63   enum OpenVGTask task;
64   const void* data;
65   const void* data2;
66   unsigned int param1, param2, param3;
67   unsigned int id; //only set an id if you are waiting
68 };
69
70 struct OpenVGResponse
71 {
72   unsigned int id;
73   unsigned int result;
74 };
75
76 class OsdOpenVG : public OsdVector, public Thread_TYPE
77 #ifdef PICTURE_DECODER_OMX
78   , public EGLPictureCreator
79 #endif
80 {
81   public:
82     OsdOpenVG();
83     virtual ~OsdOpenVG();
84
85     int init();
86     int shutdown();
87     int stopUpdate();
88
89     bool screenShot(void* buffer, int width, int height, bool osd /*include osd*/);
90
91     float getFontHeight();
92     float getCharWidth(wchar_t c);
93
94     int getFontNames(const char***  names, const char***  names_keys);
95
96     virtual void setFont(const char* fontname);
97
98     virtual float getPixelAspect() {return aspect_correction;};
99
100     bool getEGLPicture(struct OsdVector::PictureInfo& info, EGLDisplay* display);
101
102     void updateBackgroundColor(DrawStyle bg);
103
104   protected:
105     /*osd vector implementation*/
106     void destroyImageRef(ImageIndex index);
107     // ImageIndex createJpeg(const char* fileName, int *width,int *height);
108     ImageIndex createMonoBitmap(void* base, int width, int height);
109     ImageIndex createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data);
110     void createPicture(struct PictureInfo& pict_inf);
111     void destroyDrawStyleHandle(VectorHandle index);
112     VectorHandle createDrawStyleHandle(const DrawStyle& c);
113     bool getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length);
114
115     void drawSetTrans(SurfaceInfo& sc);
116     void executeDrawCommand(SVGCommand& command);
117
118     void initPaths();
119     void destroyPaths();
120     VGPath std_paths[PIPoint + 1];
121     long long  lastrendertime;
122     void InternalRendering();
123     void getScreenSize(int& width, int& height);
124     void getRealScreenSize(int& width, int& height);
125
126     std::mutex vgmutex;
127     std::mutex taskmutex;
128     std::mutex vgTaskSignalMutex;
129     std::condition_variable vgTaskSignal;
130
131     std::deque<OpenVGCommand> vgcommands;
132     std::deque<OpenVGResponse> vgresponses;
133     bool processTasks();
134     bool haveOpenVGResponse(unsigned int id, unsigned int* resp);
135     unsigned int putOpenVGCommand(OpenVGCommand& comm, bool wait);
136     unsigned int handleTask(OpenVGCommand& command);
137     //void purgeAllReferences();
138     unsigned int wait_id{1};
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     void threadMethod();
158
159     /* BCM specific */
160
161     uint32_t display_height{};
162     uint32_t display_width{};
163     DISPMANX_DISPLAY_HANDLE_T bcm_display;
164     DISPMANX_ELEMENT_HANDLE_T bcm_element;
165     DISPMANX_ELEMENT_HANDLE_T bcm_background;
166     DISPMANX_RESOURCE_HANDLE_T bcm_backres{};
167
168     uint32_t mode{};
169
170     EGLDisplay egl_display;
171     EGLSurface egl_surface;
172     EGLContext egl_context;
173     EGLConfig egl_ourconfig;
174     float font_height;
175     float aspect_correction{1.};
176     bool freetype_inited{};
177
178     uint8_t* static_artwork_begin[sa_MAX];
179     uint8_t* static_artwork_end[sa_MAX];
180
181 #ifdef PICTURE_DECODER_OMX
182     ImageOMX* imageomx;
183 #endif
184
185 };
186
187 #endif