eglcontext.h revision 3464ebd5
1/************************************************************************** 2 * 3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com> 5 * Copyright 2010-2011 LunarG, Inc. 6 * All Rights Reserved. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sub license, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice (including the 17 * next paragraph) shall be included in all copies or substantial portions 18 * of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 * DEALINGS IN THE SOFTWARE. 27 * 28 **************************************************************************/ 29 30 31#ifndef EGLCONTEXT_INCLUDED 32#define EGLCONTEXT_INCLUDED 33 34 35#include "egltypedefs.h" 36#include "egldisplay.h" 37 38 39/** 40 * "Base" class for device driver contexts. 41 */ 42struct _egl_context 43{ 44 /* A context is a display resource */ 45 _EGLResource Resource; 46 47 /* The bound status of the context */ 48 _EGLThreadInfo *Binding; 49 _EGLSurface *DrawSurface; 50 _EGLSurface *ReadSurface; 51 52 _EGLConfig *Config; 53 54 EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */ 55 EGLint ClientVersion; /**< 1 = OpenGLES 1.x, 2 = OpenGLES 2.x */ 56 57 /* The real render buffer when a window surface is bound */ 58 EGLint WindowRenderBuffer; 59}; 60 61 62PUBLIC EGLBoolean 63_eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, 64 _EGLConfig *config, const EGLint *attrib_list); 65 66 67extern EGLBoolean 68_eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value); 69 70 71PUBLIC EGLBoolean 72_eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, 73 _EGLContext **old_ctx, 74 _EGLSurface **old_draw, _EGLSurface **old_read); 75 76 77/** 78 * Increment reference count for the context. 79 */ 80static INLINE _EGLContext * 81_eglGetContext(_EGLContext *ctx) 82{ 83 if (ctx) 84 _eglGetResource(&ctx->Resource); 85 return ctx; 86} 87 88 89/** 90 * Decrement reference count for the context. 91 */ 92static INLINE EGLBoolean 93_eglPutContext(_EGLContext *ctx) 94{ 95 return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE; 96} 97 98 99/** 100 * Link a context to its display and return the handle of the link. 101 * The handle can be passed to client directly. 102 */ 103static INLINE EGLContext 104_eglLinkContext(_EGLContext *ctx) 105{ 106 _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); 107 return (EGLContext) ctx; 108} 109 110 111/** 112 * Unlink a linked context from its display. 113 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. 114 */ 115static INLINE void 116_eglUnlinkContext(_EGLContext *ctx) 117{ 118 _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); 119} 120 121 122/** 123 * Lookup a handle to find the linked context. 124 * Return NULL if the handle has no corresponding linked context. 125 */ 126static INLINE _EGLContext * 127_eglLookupContext(EGLContext context, _EGLDisplay *dpy) 128{ 129 _EGLContext *ctx = (_EGLContext *) context; 130 if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy)) 131 ctx = NULL; 132 return ctx; 133} 134 135 136/** 137 * Return the handle of a linked context, or EGL_NO_CONTEXT. 138 */ 139static INLINE EGLContext 140_eglGetContextHandle(_EGLContext *ctx) 141{ 142 _EGLResource *res = (_EGLResource *) ctx; 143 return (res && _eglIsResourceLinked(res)) ? 144 (EGLContext) ctx : EGL_NO_CONTEXT; 145} 146 147 148#endif /* EGLCONTEXT_INCLUDED */ 149