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