5 #include "eglcontext.h"
6 #include "egldisplay.h"
8 #include "eglglobals.h"
9 #include "eglsurface.h"
13 * Initialize the given _EGLContext object to defaults and/or the values
17 _eglInitContext(_EGLDriver
*drv
, EGLDisplay dpy
, _EGLContext
*ctx
,
18 EGLConfig config
, const EGLint
*attrib_list
)
21 _EGLDisplay
*display
= _eglLookupDisplay(dpy
);
23 const EGLenum api
= eglQueryAPI();
25 if (api
== EGL_NONE
) {
26 _eglError(EGL_BAD_MATCH
, "eglCreateContext(no client API)");
30 conf
= _eglLookupConfig(drv
, dpy
, config
);
32 _eglError(EGL_BAD_CONFIG
, "_eglInitContext");
36 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
37 switch (attrib_list
[i
]) {
38 case EGL_CONTEXT_CLIENT_VERSION
:
40 ctx
->ClientVersion
= attrib_list
[i
];
43 _eglError(EGL_BAD_ATTRIBUTE
, "_eglInitContext");
48 memset(ctx
, 0, sizeof(_EGLContext
));
49 ctx
->Display
= display
;
51 ctx
->DrawSurface
= EGL_NO_SURFACE
;
52 ctx
->ReadSurface
= EGL_NO_SURFACE
;
60 * Save a new _EGLContext into the hash table.
63 _eglSaveContext(_EGLContext
*ctx
)
66 * Public EGLContext handle and private _EGLContext are the same.
72 * Remove the given _EGLContext object from the hash table.
75 _eglRemoveContext(_EGLContext
*ctx
)
78 * Public EGLContext handle and private _EGLContext are the same.
84 * Return the public handle for the given private context ptr.
85 * This is the inverse of _eglLookupContext().
88 _eglGetContextHandle(_EGLContext
*ctx
)
91 return (EGLContext
) ctx
;
96 * Return the _EGLContext object that corresponds to the given
98 * This is the inverse of _eglGetContextHandle().
101 _eglLookupContext(EGLContext ctx
)
103 /* just a cast since EGLContext is just a void ptr */
104 return (_EGLContext
*) ctx
;
109 * Return the currently bound _EGLContext object, or NULL.
112 _eglGetCurrentContext(void)
114 _EGLThreadInfo
*t
= _eglGetCurrentThread();
115 return t
->CurrentContext
;
120 * Just a placeholder/demo function. Real driver will never use this!
123 _eglCreateContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
124 EGLContext share_list
, const EGLint
*attrib_list
)
126 #if 0 /* example code */
127 _EGLContext
*context
;
129 context
= (_EGLContext
*) calloc(1, sizeof(_EGLContext
));
131 return EGL_NO_CONTEXT
;
133 if (!_eglInitContext(drv
, dpy
, context
, config
, attrib_list
)) {
135 return EGL_NO_CONTEXT
;
138 _eglSaveContext(context
);
139 return (EGLContext
) context
;
141 return EGL_NO_CONTEXT
;
146 * Default fallback routine - drivers should usually override this.
149 _eglDestroyContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext ctx
)
151 _EGLContext
*context
= _eglLookupContext(ctx
);
153 if (context
->IsBound
) {
154 context
->DeletePending
= EGL_TRUE
;
162 _eglError(EGL_BAD_CONTEXT
, "eglDestroyContext");
169 _eglQueryContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext ctx
,
170 EGLint attribute
, EGLint
*value
)
172 _EGLContext
*c
= _eglLookupContext(ctx
);
178 _eglError(EGL_BAD_CONTEXT
, "eglQueryContext");
184 *value
= GET_CONFIG_ATTRIB(c
->Config
, EGL_CONFIG_ID
);
186 #ifdef EGL_VERSION_1_2
187 case EGL_CONTEXT_CLIENT_TYPE
:
188 *value
= c
->ClientAPI
;
190 #endif /* EGL_VERSION_1_2 */
192 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryContext");
199 * Drivers will typically call this to do the error checking and
200 * update the various IsBound and DeletePending flags.
201 * Then, the driver will do its device-dependent Make-Current stuff.
204 _eglMakeCurrent(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface d
,
205 EGLSurface r
, EGLContext context
)
207 _EGLThreadInfo
*t
= _eglGetCurrentThread();
208 _EGLContext
*ctx
= _eglLookupContext(context
);
209 _EGLSurface
*draw
= _eglLookupSurface(d
);
210 _EGLSurface
*read
= _eglLookupSurface(r
);
212 _EGLContext
*oldContext
= _eglGetCurrentContext();
213 _EGLSurface
*oldDrawSurface
= _eglGetCurrentSurface(EGL_DRAW
);
214 _EGLSurface
*oldReadSurface
= _eglGetCurrentSurface(EGL_READ
);
218 if (draw
== NULL
|| read
== NULL
) {
219 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
222 if (draw
->Config
!= ctx
->Config
) {
223 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
226 if (read
->Config
!= ctx
->Config
) {
227 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
233 * check if the old context or surfaces need to be deleted
235 if (oldDrawSurface
!= NULL
) {
236 oldDrawSurface
->IsBound
= EGL_FALSE
;
237 if (oldDrawSurface
->DeletePending
) {
238 /* make sure we don't try to rebind a deleted surface */
239 if (draw
== oldDrawSurface
|| draw
== oldReadSurface
) {
242 /* really delete surface now */
243 drv
->API
.DestroySurface(drv
, dpy
, oldDrawSurface
->Handle
);
246 if (oldReadSurface
!= NULL
&& oldReadSurface
!= oldDrawSurface
) {
247 oldReadSurface
->IsBound
= EGL_FALSE
;
248 if (oldReadSurface
->DeletePending
) {
249 /* make sure we don't try to rebind a deleted surface */
250 if (read
== oldDrawSurface
|| read
== oldReadSurface
) {
253 /* really delete surface now */
254 drv
->API
.DestroySurface(drv
, dpy
, oldReadSurface
->Handle
);
257 if (oldContext
!= NULL
) {
258 oldContext
->IsBound
= EGL_FALSE
;
259 if (oldContext
->DeletePending
) {
260 /* make sure we don't try to rebind a deleted context */
261 if (ctx
== oldContext
) {
264 /* really delete context now */
265 drv
->API
.DestroyContext(drv
, dpy
, _eglGetContextHandle(oldContext
));
270 /* check read/draw again, in case we deleted them above */
271 if (draw
== NULL
|| read
== NULL
) {
272 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
275 ctx
->DrawSurface
= draw
;
276 ctx
->ReadSurface
= read
;
277 ctx
->IsBound
= EGL_TRUE
;
278 draw
->IsBound
= EGL_TRUE
;
279 read
->IsBound
= EGL_TRUE
;
282 t
->CurrentContext
= ctx
;
289 * This is defined by the EGL_MESA_copy_context extension.
292 _eglCopyContextMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext source
,
293 EGLContext dest
, EGLint mask
)
295 /* This function will always have to be overridden/implemented in the
296 * device driver. If the driver is based on Mesa, use _mesa_copy_context().