51 // version to version without notice, or even be removed. |
51 // version to version without notice, or even be removed. |
52 // |
52 // |
53 // We mean it. |
53 // We mean it. |
54 // |
54 // |
55 |
55 |
56 #include <QtCore/qsize.h> |
|
57 #include <QtGui/qimage.h> |
|
58 |
|
59 #include <private/qeglproperties_p.h> |
|
60 |
|
61 QT_BEGIN_INCLUDE_NAMESPACE |
56 QT_BEGIN_INCLUDE_NAMESPACE |
62 |
57 |
|
58 #ifndef QT_NO_EGL |
|
59 #if defined(QT_OPENGL_ES_2) |
|
60 # include <GLES2/gl2.h> |
|
61 #endif |
|
62 |
|
63 #if defined(QT_GLES_EGL) |
|
64 # include <GLES/egl.h> |
|
65 #else |
|
66 # include <EGL/egl.h> |
|
67 #endif |
|
68 #else |
|
69 |
|
70 //types from egltypes.h for compiling stub without EGL headers |
|
71 typedef int EGLBoolean; |
|
72 typedef int EGLint; |
|
73 typedef int EGLenum; |
|
74 typedef int NativeDisplayType; |
|
75 typedef void* NativeWindowType; |
|
76 typedef void* NativePixmapType; |
|
77 typedef int EGLDisplay; |
|
78 typedef int EGLConfig; |
|
79 typedef int EGLSurface; |
|
80 typedef int EGLContext; |
|
81 typedef int EGLClientBuffer; |
|
82 #define EGL_NONE 0x3038 /* Attrib list terminator */ |
|
83 |
|
84 #endif |
|
85 |
|
86 #if defined(Q_WS_X11) |
|
87 // If <EGL/egl.h> included <X11/Xlib.h>, then the global namespace |
|
88 // may have been polluted with X #define's. The following makes sure |
|
89 // the X11 headers were included properly and then cleans things up. |
|
90 #include <X11/Xlib.h> |
|
91 #include <X11/Xutil.h> |
|
92 #undef Bool |
|
93 #undef Status |
|
94 #undef None |
|
95 #undef KeyPress |
|
96 #undef KeyRelease |
|
97 #undef FocusIn |
|
98 #undef FocusOut |
|
99 #undef Type |
|
100 #undef FontChange |
|
101 #undef CursorShape |
|
102 #undef Unsorted |
|
103 #undef GrayScale |
|
104 #endif |
|
105 |
|
106 // Internally we use the EGL-prefixed native types which are used in EGL >= 1.3. |
|
107 // For older versions of EGL, we have to define these types ourselves here: |
63 #if !defined(EGL_VERSION_1_3) && !defined(QEGL_NATIVE_TYPES_DEFINED) |
108 #if !defined(EGL_VERSION_1_3) && !defined(QEGL_NATIVE_TYPES_DEFINED) |
64 #undef EGLNativeWindowType |
109 #undef EGLNativeWindowType |
65 #undef EGLNativePixmapType |
110 #undef EGLNativePixmapType |
66 #undef EGLNativeDisplayType |
111 #undef EGLNativeDisplayType |
67 typedef NativeWindowType EGLNativeWindowType; |
112 typedef NativeWindowType EGLNativeWindowType; |
68 typedef NativePixmapType EGLNativePixmapType; |
113 typedef NativePixmapType EGLNativePixmapType; |
69 typedef NativeDisplayType EGLNativeDisplayType; |
114 typedef NativeDisplayType EGLNativeDisplayType; |
70 #define QEGL_NATIVE_TYPES_DEFINED 1 |
115 #define QEGL_NATIVE_TYPES_DEFINED 1 |
71 #endif |
116 #endif |
|
117 |
72 QT_END_INCLUDE_NAMESPACE |
118 QT_END_INCLUDE_NAMESPACE |
73 |
119 |
|
120 #include <QtGui/qpaintdevice.h> |
|
121 #include <QFlags> |
|
122 |
74 QT_BEGIN_NAMESPACE |
123 QT_BEGIN_NAMESPACE |
75 |
124 |
76 class Q_GUI_EXPORT QEglContext |
125 #define QEGL_NO_CONFIG ((EGLConfig)-1) |
77 { |
126 |
78 public: |
127 #ifndef EGLAPIENTRY |
79 QEglContext(); |
128 #define EGLAPIENTRY |
80 ~QEglContext(); |
129 #endif |
81 |
130 |
82 bool isValid() const; |
131 // Try to get some info to debug the symbian build failues: |
83 bool isCurrent() const; |
132 #ifdef Q_OS_SYMBIAN |
84 bool isSharing() const { return sharing; } |
133 |
85 |
134 #ifdef EGL_KHR_image |
86 QEgl::API api() const { return apiType; } |
135 #warning "EGL_KHR_image is defined" |
87 void setApi(QEgl::API api) { apiType = api; } |
136 #else |
88 |
137 #warning "EGL_KHR_image is NOT defined" |
89 bool chooseConfig(const QEglProperties& properties, QEgl::PixelFormatMatch match = QEgl::ExactPixelFormat); |
138 #endif |
90 bool createContext(QEglContext *shareContext = 0, const QEglProperties *properties = 0); |
139 |
91 void destroyContext(); |
140 #ifdef EGL_KHR_image_base |
92 EGLSurface createSurface(QPaintDevice *device, const QEglProperties *properties = 0); |
141 #warning "EGL_KHR_image_base is defined" |
93 void destroySurface(EGLSurface surface); |
142 #else |
94 |
143 #warning "EGL_KHR_image_base is NOT defined" |
95 bool makeCurrent(EGLSurface surface); |
144 #endif |
96 bool doneCurrent(); |
145 |
97 bool lazyDoneCurrent(); |
146 #ifdef EGL_EGLEXT_PROTOTYPES |
98 bool swapBuffers(EGLSurface surface); |
147 #warning "EGL_EGLEXT_PROTOTYPES is defined" |
99 |
148 #else |
100 void waitNative(); |
149 #warning "EGL_EGLEXT_PROTOTYPES NOT not defined" |
101 void waitClient(); |
150 #endif |
102 |
151 |
103 bool configAttrib(int name, EGLint *value) const; |
152 #endif |
104 |
153 |
105 static void clearError(); |
154 |
106 static EGLint error(); |
155 // Declare/define the bits of EGL_KHR_image_base we need: |
107 static QString errorString(EGLint code); |
156 #if !defined(EGL_KHR_image) && !defined(EGL_KHR_image_base) |
108 |
157 #ifdef Q_OS_SYMBIAN |
109 static EGLDisplay display(); |
158 //symbian version of eglext.h differs from the khronos reference |
110 |
159 typedef int EGLImageKHR; |
111 EGLContext context() const { return ctx; } |
160 #else |
112 void setContext(EGLContext context) { ctx = context; ownsContext = false;} |
161 typedef void *EGLImageKHR; |
113 |
162 #endif |
114 EGLConfig config() const { return cfg; } |
163 |
115 void setConfig(EGLConfig config) { cfg = config; } |
164 #define EGL_NO_IMAGE_KHR ((EGLImageKHR)0) |
116 |
165 #define EGL_IMAGE_PRESERVED_KHR 0x30D2 |
117 QEglProperties configProperties(EGLConfig cfg = 0) const; |
166 #define EGL_KHR_image_base |
118 |
167 #endif |
119 void dumpAllConfigs(); |
168 |
120 |
169 #if !defined(EGL_KHR_image) && !defined(EGL_KHR_image_pixmap) |
121 static QString extensions(); |
170 #define EGL_NATIVE_PIXMAP_KHR 0x30B0 |
122 static bool hasExtension(const char* extensionName); |
171 #define EGL_KHR_image_pixmap |
123 |
172 #endif |
124 private: |
173 |
125 QEgl::API apiType; |
174 |
126 EGLContext ctx; |
175 class QEglProperties; |
127 EGLConfig cfg; |
176 |
128 EGLSurface currentSurface; |
177 namespace QEgl { |
129 bool current; |
178 enum API |
130 bool ownsContext; |
179 { |
131 bool sharing; |
180 OpenGL, |
132 |
181 OpenVG |
133 static EGLDisplay dpy; |
182 }; |
134 static EGLNativeDisplayType nativeDisplay(); |
183 |
135 |
184 enum PixelFormatMatch |
136 static QEglContext *currentContext(QEgl::API api); |
185 { |
137 static void setCurrentContext(QEgl::API api, QEglContext *context); |
186 ExactPixelFormat, |
138 }; |
187 BestPixelFormat |
|
188 }; |
|
189 |
|
190 enum ConfigOption |
|
191 { |
|
192 NoOptions = 0, |
|
193 Translucent = 0x01, |
|
194 Renderable = 0x02 // Config will be compatable with the paint engines (VG or GL) |
|
195 }; |
|
196 Q_DECLARE_FLAGS(ConfigOptions, ConfigOption) |
|
197 |
|
198 // Most of the time we use the same config for things like widgets & pixmaps, so rather than |
|
199 // go through the eglChooseConfig loop every time, we use defaultConfig, which will return |
|
200 // the config for a particular device/api/option combo. This function assumes that once a |
|
201 // config is chosen for a particular combo, it's safe to always use that combo. |
|
202 Q_GUI_EXPORT EGLConfig defaultConfig(int devType, API api, ConfigOptions options); |
|
203 |
|
204 Q_GUI_EXPORT EGLConfig chooseConfig(const QEglProperties* configAttribs, QEgl::PixelFormatMatch match = QEgl::ExactPixelFormat); |
|
205 Q_GUI_EXPORT EGLSurface createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *surfaceAttribs = 0); |
|
206 |
|
207 Q_GUI_EXPORT void dumpAllConfigs(); |
|
208 |
|
209 #ifdef QT_NO_EGL |
|
210 Q_GUI_EXPORT QString errorString(EGLint code = 0); |
|
211 #else |
|
212 Q_GUI_EXPORT QString errorString(EGLint code = eglGetError()); |
|
213 #endif |
|
214 |
|
215 Q_GUI_EXPORT QString extensions(); |
|
216 Q_GUI_EXPORT bool hasExtension(const char* extensionName); |
|
217 |
|
218 Q_GUI_EXPORT EGLDisplay display(); |
|
219 |
|
220 Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay(); |
|
221 Q_GUI_EXPORT EGLNativeWindowType nativeWindow(QWidget*); |
|
222 Q_GUI_EXPORT EGLNativePixmapType nativePixmap(QPixmap*); |
|
223 |
|
224 // Extension functions |
|
225 Q_GUI_EXPORT EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); |
|
226 Q_GUI_EXPORT EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img); |
|
227 |
|
228 #ifdef Q_WS_X11 |
|
229 Q_GUI_EXPORT VisualID getCompatibleVisualId(EGLConfig config); |
|
230 #endif |
|
231 } |
|
232 |
|
233 Q_DECLARE_OPERATORS_FOR_FLAGS(QEgl::ConfigOptions) |
139 |
234 |
140 QT_END_NAMESPACE |
235 QT_END_NAMESPACE |
141 |
236 |
142 #endif // QEGL_P_H |
237 #endif //QEGL_P_H |