1 #ifndef EGLCONTEXT_INCLUDED
2 #define EGLCONTEXT_INCLUDED
5 #include "egltypedefs.h"
6 #include "egldisplay.h"
10 * "Base" class for device driver contexts.
14 /* A context is a display resource */
15 _EGLResource Resource
;
17 /* The bound status of the context */
18 _EGLThreadInfo
*Binding
;
19 _EGLSurface
*DrawSurface
;
20 _EGLSurface
*ReadSurface
;
24 EGLint ClientAPI
; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */
25 EGLint ClientVersion
; /**< 1 = OpenGLES 1.x, 2 = OpenGLES 2.x */
27 /* The real render buffer when a window surface is bound */
28 EGLint WindowRenderBuffer
;
33 _eglInitContext(_EGLContext
*ctx
, _EGLDisplay
*dpy
,
34 _EGLConfig
*config
, const EGLint
*attrib_list
);
38 _eglQueryContext(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
, EGLint attribute
, EGLint
*value
);
42 _eglBindContext(_EGLContext
**ctx
, _EGLSurface
**draw
, _EGLSurface
**read
);
46 * Increment reference count for the context.
48 static INLINE _EGLContext
*
49 _eglGetContext(_EGLContext
*ctx
)
52 _eglGetResource(&ctx
->Resource
);
58 * Decrement reference count for the context.
60 static INLINE EGLBoolean
61 _eglPutContext(_EGLContext
*ctx
)
63 return (ctx
) ? _eglPutResource(&ctx
->Resource
) : EGL_FALSE
;
68 * Return true if the context is bound to a thread.
70 * The binding is considered a reference to the context. Drivers should not
71 * destroy a context when it is bound.
73 static INLINE EGLBoolean
74 _eglIsContextBound(_EGLContext
*ctx
)
76 return (ctx
->Binding
!= NULL
);
81 * Link a context to its display and return the handle of the link.
82 * The handle can be passed to client directly.
84 static INLINE EGLContext
85 _eglLinkContext(_EGLContext
*ctx
)
87 _eglLinkResource(&ctx
->Resource
, _EGL_RESOURCE_CONTEXT
);
88 return (EGLContext
) ctx
;
93 * Unlink a linked context from its display.
94 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
97 _eglUnlinkContext(_EGLContext
*ctx
)
99 _eglUnlinkResource(&ctx
->Resource
, _EGL_RESOURCE_CONTEXT
);
104 * Lookup a handle to find the linked context.
105 * Return NULL if the handle has no corresponding linked context.
107 static INLINE _EGLContext
*
108 _eglLookupContext(EGLContext context
, _EGLDisplay
*dpy
)
110 _EGLContext
*ctx
= (_EGLContext
*) context
;
111 if (!dpy
|| !_eglCheckResource((void *) ctx
, _EGL_RESOURCE_CONTEXT
, dpy
))
118 * Return the handle of a linked context, or EGL_NO_CONTEXT.
120 static INLINE EGLContext
121 _eglGetContextHandle(_EGLContext
*ctx
)
123 _EGLResource
*res
= (_EGLResource
*) ctx
;
124 return (res
&& _eglIsResourceLinked(res
)) ?
125 (EGLContext
) ctx
: EGL_NO_CONTEXT
;
130 * Return true if the context is linked to a display.
132 * The link is considered a reference to the context (the display is owning the
133 * context). Drivers should not destroy a context when it is linked.
135 static INLINE EGLBoolean
136 _eglIsContextLinked(_EGLContext
*ctx
)
138 _EGLResource
*res
= (_EGLResource
*) ctx
;
139 return (res
&& _eglIsResourceLinked(res
));
143 #endif /* EGLCONTEXT_INCLUDED */