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
);
24 conf
= _eglLookupConfig(drv
, dpy
, config
);
26 _eglError(EGL_BAD_CONFIG
, "_eglInitContext");
30 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
31 switch (attrib_list
[i
]) {
32 case EGL_CONTEXT_CLIENT_VERSION
:
36 _eglError(EGL_BAD_ATTRIBUTE
, "_eglInitContext");
41 memset(ctx
, 0, sizeof(_EGLContext
));
42 ctx
->Display
= display
;
44 ctx
->DrawSurface
= EGL_NO_SURFACE
;
45 ctx
->ReadSurface
= EGL_NO_SURFACE
;
52 * Save a new _EGLContext into the hash table.
55 _eglSaveContext(_EGLContext
*ctx
)
58 * Public EGLContext handle and private _EGLContext are the same.
64 * Remove the given _EGLContext object from the hash table.
67 _eglRemoveContext(_EGLContext
*ctx
)
70 * Public EGLContext handle and private _EGLContext are the same.
76 * Return the public handle for the given private context ptr.
77 * This is the inverse of _eglLookupContext().
80 _eglGetContextHandle(_EGLContext
*ctx
)
83 return (EGLContext
) ctx
;
88 * Return the _EGLContext object that corresponds to the given
90 * This is the inverse of _eglGetContextHandle().
93 _eglLookupContext(EGLContext ctx
)
95 /* just a cast since EGLContext is just a void ptr */
96 return (_EGLContext
*) ctx
;
101 * Return the currently bound _EGLContext object, or NULL.
104 _eglGetCurrentContext(void)
106 _EGLThreadInfo
*t
= _eglGetCurrentThread();
107 return t
->CurrentContext
;
112 * Just a placeholder/demo function. Real driver will never use this!
115 _eglCreateContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
116 EGLContext share_list
, const EGLint
*attrib_list
)
118 #if 0 /* example code */
119 _EGLContext
*context
;
121 context
= (_EGLContext
*) calloc(1, sizeof(_EGLContext
));
123 return EGL_NO_CONTEXT
;
125 if (!_eglInitContext(drv
, dpy
, context
, config
, attrib_list
)) {
127 return EGL_NO_CONTEXT
;
130 _eglSaveContext(context
);
131 return (EGLContext
) context
;
133 return EGL_NO_CONTEXT
;
138 * Default fallback routine - drivers should usually override this.
141 _eglDestroyContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext ctx
)
143 _EGLContext
*context
= _eglLookupContext(ctx
);
145 if (context
->IsBound
) {
146 context
->DeletePending
= EGL_TRUE
;
154 _eglError(EGL_BAD_CONTEXT
, "eglDestroyContext");
161 _eglQueryContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext ctx
,
162 EGLint attribute
, EGLint
*value
)
164 _EGLContext
*c
= _eglLookupContext(ctx
);
170 _eglError(EGL_BAD_CONTEXT
, "eglQueryContext");
176 *value
= GET_CONFIG_ATTRIB(c
->Config
, EGL_CONFIG_ID
);
178 #ifdef EGL_VERSION_1_2
179 case EGL_CONTEXT_CLIENT_TYPE
:
180 *value
= c
->ClientAPI
;
182 #endif /* EGL_VERSION_1_2 */
184 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryContext");
191 * Drivers will typically call this to do the error checking and
192 * update the various IsBound and DeletePending flags.
193 * Then, the driver will do its device-dependent Make-Current stuff.
196 _eglMakeCurrent(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface d
,
197 EGLSurface r
, EGLContext context
)
199 _EGLThreadInfo
*t
= _eglGetCurrentThread();
200 _EGLContext
*ctx
= _eglLookupContext(context
);
201 _EGLSurface
*draw
= _eglLookupSurface(d
);
202 _EGLSurface
*read
= _eglLookupSurface(r
);
204 _EGLContext
*oldContext
= _eglGetCurrentContext();
205 _EGLSurface
*oldDrawSurface
= _eglGetCurrentSurface(EGL_DRAW
);
206 _EGLSurface
*oldReadSurface
= _eglGetCurrentSurface(EGL_READ
);
210 if (draw
== NULL
|| read
== NULL
) {
211 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
214 if (draw
->Config
!= ctx
->Config
) {
215 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
218 if (read
->Config
!= ctx
->Config
) {
219 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
225 * check if the old context or surfaces need to be deleted
227 if (oldDrawSurface
!= NULL
) {
228 oldDrawSurface
->IsBound
= EGL_FALSE
;
229 if (oldDrawSurface
->DeletePending
) {
230 /* make sure we don't try to rebind a deleted surface */
231 if (draw
== oldDrawSurface
|| draw
== oldReadSurface
) {
234 /* really delete surface now */
235 drv
->API
.DestroySurface(drv
, dpy
, oldDrawSurface
->Handle
);
238 if (oldReadSurface
!= NULL
&& oldReadSurface
!= oldDrawSurface
) {
239 oldReadSurface
->IsBound
= EGL_FALSE
;
240 if (oldReadSurface
->DeletePending
) {
241 /* make sure we don't try to rebind a deleted surface */
242 if (read
== oldDrawSurface
|| read
== oldReadSurface
) {
245 /* really delete surface now */
246 drv
->API
.DestroySurface(drv
, dpy
, oldReadSurface
->Handle
);
249 if (oldContext
!= NULL
) {
250 oldContext
->IsBound
= EGL_FALSE
;
251 if (oldContext
->DeletePending
) {
252 /* make sure we don't try to rebind a deleted context */
253 if (ctx
== oldContext
) {
256 /* really delete context now */
257 drv
->API
.DestroyContext(drv
, dpy
, _eglGetContextHandle(oldContext
));
262 /* check read/draw again, in case we deleted them above */
263 if (draw
== NULL
|| read
== NULL
) {
264 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
267 ctx
->DrawSurface
= draw
;
268 ctx
->ReadSurface
= read
;
269 ctx
->IsBound
= EGL_TRUE
;
270 draw
->IsBound
= EGL_TRUE
;
271 read
->IsBound
= EGL_TRUE
;
274 t
->CurrentContext
= ctx
;
281 * This is defined by the EGL_MESA_copy_context extension.
284 _eglCopyContextMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext source
,
285 EGLContext dest
, EGLint mask
)
287 /* This function will always have to be overridden/implemented in the
288 * device driver. If the driver is based on Mesa, use _mesa_copy_context().