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
, _EGLContext
*ctx
,
18 _EGLConfig
*conf
, const EGLint
*attrib_list
)
21 const EGLenum api
= eglQueryAPI();
23 if (api
== EGL_NONE
) {
24 _eglError(EGL_BAD_MATCH
, "eglCreateContext(no client API)");
29 _eglError(EGL_BAD_CONFIG
, "_eglInitContext");
33 memset(ctx
, 0, sizeof(_EGLContext
));
35 ctx
->ClientVersion
= 1; /* the default, per EGL spec */
37 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
38 switch (attrib_list
[i
]) {
39 case EGL_CONTEXT_CLIENT_VERSION
:
41 ctx
->ClientVersion
= attrib_list
[i
];
44 _eglError(EGL_BAD_ATTRIBUTE
, "_eglInitContext");
50 ctx
->DrawSurface
= EGL_NO_SURFACE
;
51 ctx
->ReadSurface
= EGL_NO_SURFACE
;
59 * Just a placeholder/demo function. Real driver will never use this!
62 _eglCreateContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
63 EGLContext share_list
, const EGLint
*attrib_list
)
65 #if 0 /* example code */
69 conf
= _eglLookupConfig(drv
, dpy
, config
);
71 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
72 return EGL_NO_CONTEXT
;
75 context
= (_EGLContext
*) calloc(1, sizeof(_EGLContext
));
77 return EGL_NO_CONTEXT
;
79 if (!_eglInitContext(drv
, context
, conf
, attrib_list
)) {
81 return EGL_NO_CONTEXT
;
84 return _eglLinkContext(context
, _eglLookupDisplay(dpy
));
86 return EGL_NO_CONTEXT
;
91 * Default fallback routine - drivers should usually override this.
94 _eglDestroyContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext ctx
)
96 _EGLContext
*context
= _eglLookupContext(ctx
);
98 _eglUnlinkContext(context
);
99 if (context
->IsBound
) {
100 context
->DeletePending
= EGL_TRUE
;
108 _eglError(EGL_BAD_CONTEXT
, "eglDestroyContext");
115 _eglQueryContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext ctx
,
116 EGLint attribute
, EGLint
*value
)
118 _EGLContext
*c
= _eglLookupContext(ctx
);
124 _eglError(EGL_BAD_CONTEXT
, "eglQueryContext");
130 *value
= GET_CONFIG_ATTRIB(c
->Config
, EGL_CONFIG_ID
);
132 #ifdef EGL_VERSION_1_2
133 case EGL_CONTEXT_CLIENT_TYPE
:
134 *value
= c
->ClientAPI
;
136 #endif /* EGL_VERSION_1_2 */
137 case EGL_CONTEXT_CLIENT_VERSION
:
138 *value
= c
->ClientVersion
;
141 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryContext");
148 * Drivers will typically call this to do the error checking and
149 * update the various IsBound and DeletePending flags.
150 * Then, the driver will do its device-dependent Make-Current stuff.
153 _eglMakeCurrent(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface d
,
154 EGLSurface r
, EGLContext context
)
156 _EGLThreadInfo
*t
= _eglGetCurrentThread();
157 _EGLContext
*ctx
= _eglLookupContext(context
);
158 _EGLSurface
*draw
= _eglLookupSurface(d
);
159 _EGLSurface
*read
= _eglLookupSurface(r
);
160 _EGLContext
*oldContext
= NULL
;
161 _EGLSurface
*oldDrawSurface
= NULL
;
162 _EGLSurface
*oldReadSurface
= NULL
;
165 if (_eglIsCurrentThreadDummy())
166 return _eglError(EGL_BAD_ALLOC
, "eglMakeCurrent");
170 if (draw
== NULL
|| read
== NULL
) {
171 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
174 if (draw
->Config
!= ctx
->Config
) {
175 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
178 if (read
->Config
!= ctx
->Config
) {
179 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
183 #ifdef EGL_VERSION_1_4
184 /* OpenGL and OpenGL ES are conflicting */
185 switch (ctx
->ClientAPI
) {
186 case EGL_OPENGL_ES_API
:
187 if (t
->CurrentContexts
[_eglConvertApiToIndex(EGL_OPENGL_API
)])
188 return _eglError(EGL_BAD_ACCESS
, "eglMakeCurrent");
191 if (t
->CurrentContexts
[_eglConvertApiToIndex(EGL_OPENGL_ES_API
)])
192 return _eglError(EGL_BAD_ACCESS
, "eglMakeCurrent");
198 apiIndex
= _eglConvertApiToIndex(ctx
->ClientAPI
);
201 apiIndex
= t
->CurrentAPIIndex
;
204 oldContext
= t
->CurrentContexts
[apiIndex
];
206 oldDrawSurface
= oldContext
->DrawSurface
;
207 oldReadSurface
= oldContext
->ReadSurface
;
211 * check if the old context or surfaces need to be deleted
213 if (oldDrawSurface
!= NULL
) {
214 oldDrawSurface
->IsBound
= EGL_FALSE
;
215 if (oldDrawSurface
->DeletePending
) {
216 /* make sure we don't try to rebind a deleted surface */
217 if (draw
== oldDrawSurface
|| draw
== oldReadSurface
) {
220 /* really delete surface now */
221 drv
->API
.DestroySurface(drv
, dpy
, oldDrawSurface
->Handle
);
224 if (oldReadSurface
!= NULL
&& oldReadSurface
!= oldDrawSurface
) {
225 oldReadSurface
->IsBound
= EGL_FALSE
;
226 if (oldReadSurface
->DeletePending
) {
227 /* make sure we don't try to rebind a deleted surface */
228 if (read
== oldDrawSurface
|| read
== oldReadSurface
) {
231 /* really delete surface now */
232 drv
->API
.DestroySurface(drv
, dpy
, oldReadSurface
->Handle
);
235 if (oldContext
!= NULL
) {
236 oldContext
->IsBound
= EGL_FALSE
;
237 if (oldContext
->DeletePending
) {
238 /* make sure we don't try to rebind a deleted context */
239 if (ctx
== oldContext
) {
242 /* really delete context now */
243 drv
->API
.DestroyContext(drv
, dpy
, _eglGetContextHandle(oldContext
));
248 /* check read/draw again, in case we deleted them above */
249 if (draw
== NULL
|| read
== NULL
) {
250 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
253 ctx
->DrawSurface
= draw
;
254 ctx
->ReadSurface
= read
;
255 ctx
->IsBound
= EGL_TRUE
;
256 draw
->IsBound
= EGL_TRUE
;
257 read
->IsBound
= EGL_TRUE
;
258 t
->CurrentContexts
[apiIndex
] = ctx
;
261 t
->CurrentContexts
[apiIndex
] = NULL
;
269 * This is defined by the EGL_MESA_copy_context extension.
272 _eglCopyContextMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext source
,
273 EGLContext dest
, EGLint mask
)
275 /* This function will always have to be overridden/implemented in the
276 * device driver. If the driver is based on Mesa, use _mesa_copy_context().