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 (!_eglIsContextBound(context
))
104 _eglError(EGL_BAD_CONTEXT
, "eglDestroyContext");
111 _eglQueryContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext ctx
,
112 EGLint attribute
, EGLint
*value
)
114 _EGLContext
*c
= _eglLookupContext(ctx
);
120 _eglError(EGL_BAD_CONTEXT
, "eglQueryContext");
126 *value
= GET_CONFIG_ATTRIB(c
->Config
, EGL_CONFIG_ID
);
128 #ifdef EGL_VERSION_1_2
129 case EGL_CONTEXT_CLIENT_TYPE
:
130 *value
= c
->ClientAPI
;
132 #endif /* EGL_VERSION_1_2 */
133 case EGL_CONTEXT_CLIENT_VERSION
:
134 *value
= c
->ClientVersion
;
137 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryContext");
144 * Drivers will typically call this to do the error checking and
145 * update the various flags.
146 * Then, the driver will do its device-dependent Make-Current stuff.
149 _eglMakeCurrent(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface d
,
150 EGLSurface r
, EGLContext context
)
152 _EGLThreadInfo
*t
= _eglGetCurrentThread();
153 _EGLContext
*ctx
= _eglLookupContext(context
);
154 _EGLSurface
*draw
= _eglLookupSurface(d
);
155 _EGLSurface
*read
= _eglLookupSurface(r
);
156 _EGLContext
*oldContext
= NULL
;
157 _EGLSurface
*oldDrawSurface
= NULL
;
158 _EGLSurface
*oldReadSurface
= NULL
;
161 if (_eglIsCurrentThreadDummy())
162 return _eglError(EGL_BAD_ALLOC
, "eglMakeCurrent");
166 if (draw
== NULL
|| read
== NULL
) {
167 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
170 if (draw
->Config
!= ctx
->Config
) {
171 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
174 if (read
->Config
!= ctx
->Config
) {
175 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
179 #ifdef EGL_VERSION_1_4
180 /* OpenGL and OpenGL ES are conflicting */
181 switch (ctx
->ClientAPI
) {
182 case EGL_OPENGL_ES_API
:
183 if (t
->CurrentContexts
[_eglConvertApiToIndex(EGL_OPENGL_API
)])
184 return _eglError(EGL_BAD_ACCESS
, "eglMakeCurrent");
187 if (t
->CurrentContexts
[_eglConvertApiToIndex(EGL_OPENGL_ES_API
)])
188 return _eglError(EGL_BAD_ACCESS
, "eglMakeCurrent");
194 apiIndex
= _eglConvertApiToIndex(ctx
->ClientAPI
);
197 apiIndex
= t
->CurrentAPIIndex
;
200 oldContext
= t
->CurrentContexts
[apiIndex
];
202 oldDrawSurface
= oldContext
->DrawSurface
;
203 oldReadSurface
= oldContext
->ReadSurface
;
207 * check if the old context or surfaces need to be deleted
209 if (oldDrawSurface
!= NULL
) {
210 oldDrawSurface
->Binding
= NULL
;
211 if (!_eglIsSurfaceLinked(oldDrawSurface
)) {
212 /* make sure we don't try to rebind a deleted surface */
213 if (draw
== oldDrawSurface
|| draw
== oldReadSurface
) {
216 /* really delete surface now */
217 drv
->API
.DestroySurface(drv
, dpy
, oldDrawSurface
->Handle
);
220 if (oldReadSurface
!= NULL
&& oldReadSurface
!= oldDrawSurface
) {
221 oldReadSurface
->Binding
= NULL
;
222 if (!_eglIsSurfaceLinked(oldReadSurface
)) {
223 /* make sure we don't try to rebind a deleted surface */
224 if (read
== oldDrawSurface
|| read
== oldReadSurface
) {
227 /* really delete surface now */
228 drv
->API
.DestroySurface(drv
, dpy
, oldReadSurface
->Handle
);
231 if (oldContext
!= NULL
) {
232 oldContext
->Binding
= NULL
;
233 if (!_eglIsContextLinked(oldContext
)) {
234 /* make sure we don't try to rebind a deleted context */
235 if (ctx
== oldContext
) {
238 /* really delete context now */
239 drv
->API
.DestroyContext(drv
, dpy
, _eglGetContextHandle(oldContext
));
244 /* check read/draw again, in case we deleted them above */
245 if (draw
== NULL
|| read
== NULL
) {
246 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
249 ctx
->DrawSurface
= draw
;
250 ctx
->ReadSurface
= read
;
254 t
->CurrentContexts
[apiIndex
] = ctx
;
257 t
->CurrentContexts
[apiIndex
] = NULL
;
265 * This is defined by the EGL_MESA_copy_context extension.
268 _eglCopyContextMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext source
,
269 EGLContext dest
, EGLint mask
)
271 /* This function will always have to be overridden/implemented in the
272 * device driver. If the driver is based on Mesa, use _mesa_copy_context().