eglcontext.h revision d69242be55091e53b0ae2cfa6282790ce1862f29
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 */ 64static INLINE EGLBoolean 65_eglIsContextBound(_EGLContext *ctx) 66{ 67 return (ctx->Binding != NULL); 68} 69 70 71/** 72 * Link a context to a display and return the handle of the link. 73 * The handle can be passed to client directly. 74 */ 75static INLINE EGLContext 76_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy) 77{ 78 _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT, dpy); 79 return (EGLContext) ctx; 80} 81 82 83/** 84 * Unlink a linked context from its display. 85 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. 86 */ 87static INLINE void 88_eglUnlinkContext(_EGLContext *ctx) 89{ 90 _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); 91} 92 93 94/** 95 * Lookup a handle to find the linked context. 96 * Return NULL if the handle has no corresponding linked context. 97 */ 98static INLINE _EGLContext * 99_eglLookupContext(EGLContext context, _EGLDisplay *dpy) 100{ 101 _EGLContext *ctx = (_EGLContext *) context; 102 if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy)) 103 ctx = NULL; 104 return ctx; 105} 106 107 108/** 109 * Return the handle of a linked context, or EGL_NO_CONTEXT. 110 */ 111static INLINE EGLContext 112_eglGetContextHandle(_EGLContext *ctx) 113{ 114 _EGLResource *res = (_EGLResource *) ctx; 115 return (res && _eglIsResourceLinked(res)) ? 116 (EGLContext) ctx : EGL_NO_CONTEXT; 117} 118 119 120/** 121 * Return true if the context is linked to a display. 122 */ 123static INLINE EGLBoolean 124_eglIsContextLinked(_EGLContext *ctx) 125{ 126 _EGLResource *res = (_EGLResource *) ctx; 127 return (res && _eglIsResourceLinked(res)); 128} 129 130 131#endif /* EGLCONTEXT_INCLUDED */ 132