/**************************************************************************1*2* Copyright 2008 VMware, Inc.3* Copyright 2009-2010 Chia-I Wu <[email protected]>4* Copyright 2010-2011 LunarG, Inc.5* All Rights Reserved.6*7* Permission is hereby granted, free of charge, to any person obtaining a8* copy of this software and associated documentation files (the9* "Software"), to deal in the Software without restriction, including10* without limitation the rights to use, copy, modify, merge, publish,11* distribute, sub license, and/or sell copies of the Software, and to12* permit persons to whom the Software is furnished to do so, subject to13* the following conditions:14*15* The above copyright notice and this permission notice (including the16* next paragraph) shall be included in all copies or substantial portions17* of the Software.18*19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR20* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,21* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL22* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER23* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING24* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER25* DEALINGS IN THE SOFTWARE.26*27**************************************************************************/282930#ifndef EGLCONTEXT_INCLUDED31#define EGLCONTEXT_INCLUDED3233#include "c99_compat.h"3435#include "egltypedefs.h"36#include "egldisplay.h"373839#ifdef __cplusplus40extern "C" {41#endif4243/**44* "Base" class for device driver contexts.45*/46struct _egl_context47{48/* A context is a display resource */49_EGLResource Resource;5051/* The bound status of the context */52_EGLThreadInfo *Binding;53_EGLSurface *DrawSurface;54_EGLSurface *ReadSurface;5556_EGLConfig *Config;5758EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */59EGLint ClientMajorVersion;60EGLint ClientMinorVersion;61EGLint Flags;62EGLint Profile;63EGLint ResetNotificationStrategy;64EGLint ContextPriority;65EGLBoolean NoError;66EGLint ReleaseBehavior;67};686970extern EGLBoolean71_eglInitContext(_EGLContext *ctx, _EGLDisplay *disp,72_EGLConfig *config, const EGLint *attrib_list);737475extern EGLBoolean76_eglQueryContext(_EGLContext *ctx, EGLint attribute, EGLint *value);777879extern EGLBoolean80_eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,81_EGLContext **old_ctx,82_EGLSurface **old_draw, _EGLSurface **old_read);8384extern _EGLContext *85_eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t);868788/**89* Increment reference count for the context.90*/91static inline _EGLContext *92_eglGetContext(_EGLContext *ctx)93{94if (ctx)95_eglGetResource(&ctx->Resource);96return ctx;97}9899100/**101* Decrement reference count for the context.102*/103static inline EGLBoolean104_eglPutContext(_EGLContext *ctx)105{106return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE;107}108109110/**111* Link a context to its display and return the handle of the link.112* The handle can be passed to client directly.113*/114static inline EGLContext115_eglLinkContext(_EGLContext *ctx)116{117_eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);118return (EGLContext) ctx;119}120121122/**123* Unlink a linked context from its display.124* Accessing an unlinked context should generate EGL_BAD_CONTEXT error.125*/126static inline void127_eglUnlinkContext(_EGLContext *ctx)128{129_eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);130}131132133/**134* Lookup a handle to find the linked context.135* Return NULL if the handle has no corresponding linked context.136*/137static inline _EGLContext *138_eglLookupContext(EGLContext context, _EGLDisplay *disp)139{140_EGLContext *ctx = (_EGLContext *) context;141if (!disp || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, disp))142ctx = NULL;143return ctx;144}145146147/**148* Return the handle of a linked context, or EGL_NO_CONTEXT.149*/150static inline EGLContext151_eglGetContextHandle(_EGLContext *ctx)152{153_EGLResource *res = (_EGLResource *) ctx;154return (res && _eglIsResourceLinked(res)) ?155(EGLContext) ctx : EGL_NO_CONTEXT;156}157158159#ifdef __cplusplus160}161#endif162163#endif /* EGLCONTEXT_INCLUDED */164165166