eglcontext.h revision ecb3b3102a3022e31cf9d75ae099eddbe298517f
1 2#ifndef EGLCONTEXT_INCLUDED 3#define EGLCONTEXT_INCLUDED 4 5 6#include "egltypedefs.h" 7#include "egldisplay.h" 8 9 10/** 11 * "Base" class for device driver contexts. 12 */ 13struct _egl_context 14{ 15 /* A context is a display resource */ 16 _EGLResource Resource; 17 18 /* The bound status of the context */ 19 _EGLThreadInfo *Binding; 20 _EGLSurface *DrawSurface; 21 _EGLSurface *ReadSurface; 22 23 _EGLConfig *Config; 24 25 EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */ 26 EGLint ClientVersion; /**< 1 = OpenGLES 1.x, 2 = OpenGLES 2.x */ 27 28 /* The real render buffer when a window surface is bound */ 29 EGLint WindowRenderBuffer; 30}; 31 32 33PUBLIC EGLBoolean 34_eglInitContext(_EGLDriver *drv, _EGLContext *ctx, 35 _EGLConfig *config, const EGLint *attrib_list); 36 37 38extern _EGLContext * 39_eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list); 40 41 42extern EGLBoolean 43_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx); 44 45 46extern EGLBoolean 47_eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value); 48 49 50PUBLIC EGLBoolean 51_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx); 52 53 54extern EGLBoolean 55_eglCopyContextMESA(_EGLDriver *drv, EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask); 56 57 58/** 59 * Return true if the context is bound to a thread. 60 */ 61static INLINE EGLBoolean 62_eglIsContextBound(_EGLContext *ctx) 63{ 64 return (ctx->Binding != NULL); 65} 66 67 68/** 69 * Link a context to a display and return the handle of the link. 70 * The handle can be passed to client directly. 71 */ 72static INLINE EGLContext 73_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy) 74{ 75 _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT, dpy); 76 return (EGLContext) ctx; 77} 78 79 80/** 81 * Unlink a linked context from its display. 82 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. 83 */ 84static INLINE void 85_eglUnlinkContext(_EGLContext *ctx) 86{ 87 _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); 88} 89 90 91/** 92 * Lookup a handle to find the linked context. 93 * Return NULL if the handle has no corresponding linked context. 94 */ 95static INLINE _EGLContext * 96_eglLookupContext(EGLContext context, _EGLDisplay *dpy) 97{ 98 _EGLResource *res = (_EGLResource *) context; 99 _EGLContext *ctx = (_EGLContext *) context; 100 if (!res || !dpy || !_eglCheckResource(res, _EGL_RESOURCE_CONTEXT, dpy)) 101 ctx = NULL; 102 return ctx; 103} 104 105 106/** 107 * Return the handle of a linked context, or EGL_NO_CONTEXT. 108 */ 109static INLINE EGLContext 110_eglGetContextHandle(_EGLContext *ctx) 111{ 112 _EGLResource *res = (_EGLResource *) ctx; 113 return (res && _eglIsResourceLinked(res)) ? 114 (EGLContext) ctx : EGL_NO_CONTEXT; 115} 116 117 118/** 119 * Return true if the context is linked to a display. 120 */ 121static INLINE EGLBoolean 122_eglIsContextLinked(_EGLContext *ctx) 123{ 124 _EGLResource *res = (_EGLResource *) ctx; 125 return (res && _eglIsResourceLinked(res)); 126} 127 128 129#endif /* EGLCONTEXT_INCLUDED */ 130