1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the plugins of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qmeegoextensions.h"
|
---|
43 | #include <private/qeglcontext_p.h>
|
---|
44 | #include <private/qpixmapdata_gl_p.h>
|
---|
45 |
|
---|
46 | bool QMeeGoExtensions::initialized = false;
|
---|
47 | bool QMeeGoExtensions::hasImageShared = false;
|
---|
48 | bool QMeeGoExtensions::hasSurfaceScaling = false;
|
---|
49 | bool QMeeGoExtensions::hasLockSurface = false;
|
---|
50 | bool QMeeGoExtensions::hasFenceSync = false;
|
---|
51 |
|
---|
52 | /* Extension funcs */
|
---|
53 |
|
---|
54 | typedef EGLBoolean (EGLAPIENTRY *eglQueryImageNOKFunc)(EGLDisplay, EGLImageKHR, EGLint, EGLint*);
|
---|
55 | typedef EGLNativeSharedImageTypeNOK (EGLAPIENTRY *eglCreateSharedImageNOKFunc)(EGLDisplay, EGLImageKHR, EGLint*);
|
---|
56 | typedef EGLBoolean (EGLAPIENTRY *eglDestroySharedImageNOKFunc)(EGLDisplay, EGLNativeSharedImageTypeNOK);
|
---|
57 | typedef EGLBoolean (EGLAPIENTRY *eglSetSurfaceScalingNOKFunc)(EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint);
|
---|
58 | typedef EGLBoolean (EGLAPIENTRY *eglLockSurfaceKHRFunc)(EGLDisplay, EGLSurface, const EGLint*);
|
---|
59 | typedef EGLBoolean (EGLAPIENTRY *eglUnlockSurfaceKHRFunc)(EGLDisplay, EGLSurface);
|
---|
60 | typedef EGLSyncKHR (EGLAPIENTRY *eglCreateSyncKHRFunc)(EGLDisplay, EGLenum, const EGLint*);
|
---|
61 | typedef EGLBoolean (EGLAPIENTRY *eglDestroySyncKHRFunc)(EGLDisplay, EGLSyncKHR);
|
---|
62 | typedef EGLint (EGLAPIENTRY *eglClientWaitSyncKHRFunc)(EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR);
|
---|
63 | typedef EGLBoolean (EGLAPIENTRY *eglGetSyncAttribKHRFunc)(EGLDisplay, EGLSyncKHR, EGLint, EGLint*);
|
---|
64 |
|
---|
65 | static eglQueryImageNOKFunc _eglQueryImageNOK = 0;
|
---|
66 | static eglCreateSharedImageNOKFunc _eglCreateSharedImageNOK = 0;
|
---|
67 | static eglDestroySharedImageNOKFunc _eglDestroySharedImageNOK = 0;
|
---|
68 | static eglSetSurfaceScalingNOKFunc _eglSetSurfaceScalingNOK = 0;
|
---|
69 | static eglLockSurfaceKHRFunc _eglLockSurfaceKHR = 0;
|
---|
70 | static eglUnlockSurfaceKHRFunc _eglUnlockSurfaceKHR = 0;
|
---|
71 | static eglCreateSyncKHRFunc _eglCreateSyncKHR = 0;
|
---|
72 | static eglDestroySyncKHRFunc _eglDestroySyncKHR = 0;
|
---|
73 | static eglClientWaitSyncKHRFunc _eglClientWaitSyncKHR = 0;
|
---|
74 | static eglGetSyncAttribKHRFunc _eglGetSyncAttribKHR = 0;
|
---|
75 |
|
---|
76 | /* Public */
|
---|
77 |
|
---|
78 | void QMeeGoExtensions::ensureInitialized()
|
---|
79 | {
|
---|
80 | if (!initialized)
|
---|
81 | initialize();
|
---|
82 |
|
---|
83 | initialized = true;
|
---|
84 | }
|
---|
85 |
|
---|
86 | EGLNativeSharedImageTypeNOK QMeeGoExtensions::eglCreateSharedImageNOK(EGLDisplay dpy, EGLImageKHR image, EGLint *props)
|
---|
87 | {
|
---|
88 | if (!hasImageShared)
|
---|
89 | qFatal("EGL_NOK_image_shared not found but trying to use capability!");
|
---|
90 |
|
---|
91 | return _eglCreateSharedImageNOK(dpy, image, props);
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool QMeeGoExtensions::eglQueryImageNOK(EGLDisplay dpy, EGLImageKHR image, EGLint prop, EGLint *v)
|
---|
95 | {
|
---|
96 | if (!hasImageShared)
|
---|
97 | qFatal("EGL_NOK_image_shared not found but trying to use capability!");
|
---|
98 |
|
---|
99 | return _eglQueryImageNOK(dpy, image, prop, v);
|
---|
100 | }
|
---|
101 |
|
---|
102 | bool QMeeGoExtensions::eglDestroySharedImageNOK(EGLDisplay dpy, EGLNativeSharedImageTypeNOK img)
|
---|
103 | {
|
---|
104 | if (!hasImageShared)
|
---|
105 | qFatal("EGL_NOK_image_shared not found but trying to use capability!");
|
---|
106 |
|
---|
107 | return _eglDestroySharedImageNOK(dpy, img);
|
---|
108 | }
|
---|
109 |
|
---|
110 | bool QMeeGoExtensions::eglSetSurfaceScalingNOK(EGLDisplay dpy, EGLSurface surface, int x, int y, int width, int height)
|
---|
111 | {
|
---|
112 | if (!hasSurfaceScaling)
|
---|
113 | qFatal("EGL_NOK_surface_scaling not found but trying to use capability!");
|
---|
114 |
|
---|
115 | return _eglSetSurfaceScalingNOK(dpy, surface, x, y, width, height);
|
---|
116 | }
|
---|
117 |
|
---|
118 | bool QMeeGoExtensions::eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list)
|
---|
119 | {
|
---|
120 | if (!hasLockSurface)
|
---|
121 | qFatal("EGL_KHR_lock_surface2 not found but trying to use capability!");
|
---|
122 |
|
---|
123 | return _eglLockSurfaceKHR(display, surface, attrib_list);
|
---|
124 | }
|
---|
125 |
|
---|
126 | bool QMeeGoExtensions::eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface)
|
---|
127 | {
|
---|
128 | if (!hasLockSurface)
|
---|
129 | qFatal("EGL_KHR_lock_surface2 not found but trying to use capability!");
|
---|
130 |
|
---|
131 | return _eglUnlockSurfaceKHR(display, surface);
|
---|
132 | }
|
---|
133 |
|
---|
134 | EGLSyncKHR QMeeGoExtensions::eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
|
---|
135 | {
|
---|
136 | if (!hasFenceSync)
|
---|
137 | qFatal("EGL_KHR_fence_sync not found but trying to use capability!");
|
---|
138 |
|
---|
139 | return _eglCreateSyncKHR(dpy, type, attrib_list);
|
---|
140 | }
|
---|
141 |
|
---|
142 | bool QMeeGoExtensions::eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
|
---|
143 | {
|
---|
144 | if (!hasFenceSync)
|
---|
145 | qFatal("EGL_KHR_fence_sync not found but trying to use capability!");
|
---|
146 |
|
---|
147 | return _eglDestroySyncKHR(dpy, sync);
|
---|
148 | }
|
---|
149 |
|
---|
150 | EGLint QMeeGoExtensions::eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout)
|
---|
151 | {
|
---|
152 | if (!hasFenceSync)
|
---|
153 | qFatal("EGL_KHR_fence_sync not found but trying to use capability!");
|
---|
154 |
|
---|
155 | return _eglClientWaitSyncKHR(dpy, sync, flags, timeout);
|
---|
156 | }
|
---|
157 |
|
---|
158 | EGLBoolean QMeeGoExtensions::eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value)
|
---|
159 | {
|
---|
160 | if (!hasFenceSync)
|
---|
161 | qFatal("EGL_KHR_fence_sync not found but trying to use capability!");
|
---|
162 |
|
---|
163 | return _eglGetSyncAttribKHR(dpy, sync, attribute, value);
|
---|
164 | }
|
---|
165 |
|
---|
166 | /* Private */
|
---|
167 |
|
---|
168 | void QMeeGoExtensions::initialize()
|
---|
169 | {
|
---|
170 | QGLContext *ctx = (QGLContext *) QGLContext::currentContext();
|
---|
171 | qt_resolve_eglimage_gl_extensions(ctx);
|
---|
172 |
|
---|
173 | if (QEgl::hasExtension("EGL_NOK_image_shared")) {
|
---|
174 | qDebug("MeegoGraphics: found EGL_NOK_image_shared");
|
---|
175 | _eglQueryImageNOK = (eglQueryImageNOKFunc) eglGetProcAddress("eglQueryImageNOK");
|
---|
176 | _eglCreateSharedImageNOK = (eglCreateSharedImageNOKFunc) eglGetProcAddress("eglCreateSharedImageNOK");
|
---|
177 | _eglDestroySharedImageNOK = (eglDestroySharedImageNOKFunc) eglGetProcAddress("eglDestroySharedImageNOK");
|
---|
178 | _eglLockSurfaceKHR = (eglLockSurfaceKHRFunc) eglGetProcAddress("eglLockSurfaceKHR");
|
---|
179 | _eglUnlockSurfaceKHR = (eglUnlockSurfaceKHRFunc) eglGetProcAddress("eglUnlockSurfaceKHR");
|
---|
180 |
|
---|
181 | Q_ASSERT(_eglQueryImageNOK && _eglCreateSharedImageNOK && _eglDestroySharedImageNOK);
|
---|
182 | hasImageShared = true;
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (QEgl::hasExtension("EGL_NOK_surface_scaling")) {
|
---|
186 | qDebug("MeegoGraphics: found EGL_NOK_surface_scaling");
|
---|
187 | _eglSetSurfaceScalingNOK = (eglSetSurfaceScalingNOKFunc) eglGetProcAddress("eglSetSurfaceScalingNOK");
|
---|
188 |
|
---|
189 | Q_ASSERT(_eglSetSurfaceScalingNOK);
|
---|
190 | hasSurfaceScaling = true;
|
---|
191 | }
|
---|
192 |
|
---|
193 | if (QEgl::hasExtension("EGL_KHR_lock_surface2")) {
|
---|
194 | qDebug("MeegoGraphics: found EGL_KHR_lock_surface2");
|
---|
195 | _eglLockSurfaceKHR = (eglLockSurfaceKHRFunc) eglGetProcAddress("eglLockSurfaceKHR");
|
---|
196 | _eglUnlockSurfaceKHR = (eglUnlockSurfaceKHRFunc) eglGetProcAddress("eglUnlockSurfaceKHR");
|
---|
197 |
|
---|
198 | Q_ASSERT(_eglLockSurfaceKHR && _eglUnlockSurfaceKHR);
|
---|
199 | hasLockSurface = true;
|
---|
200 | }
|
---|
201 |
|
---|
202 | if (QEgl::hasExtension("EGL_KHR_fence_sync")) {
|
---|
203 | qDebug("MeegoGraphics: found EGL_KHR_fence_sync");
|
---|
204 | _eglCreateSyncKHR = (eglCreateSyncKHRFunc) eglGetProcAddress("eglCreateSyncKHR");
|
---|
205 | _eglDestroySyncKHR = (eglDestroySyncKHRFunc) eglGetProcAddress("eglDestroySyncKHR");
|
---|
206 | _eglClientWaitSyncKHR = (eglClientWaitSyncKHRFunc) eglGetProcAddress("eglClientWaitSyncKHR");
|
---|
207 | _eglGetSyncAttribKHR = (eglGetSyncAttribKHRFunc) eglGetProcAddress("eglGetSyncAttribKHR");
|
---|
208 |
|
---|
209 | Q_ASSERT(_eglCreateSyncKHR && _eglDestroySyncKHR && _eglClientWaitSyncKHR && _eglGetSyncAttribKHR);
|
---|
210 | hasFenceSync = true;
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|