1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2008 VMware, Inc. 4848b8605Smrg * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com> 5848b8605Smrg * Copyright 2010-2011 LunarG, Inc. 6848b8605Smrg * All Rights Reserved. 7848b8605Smrg * 8848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 9848b8605Smrg * copy of this software and associated documentation files (the 10848b8605Smrg * "Software"), to deal in the Software without restriction, including 11848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 12848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 13848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 14848b8605Smrg * the following conditions: 15848b8605Smrg * 16848b8605Smrg * The above copyright notice and this permission notice (including the 17848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 18848b8605Smrg * of the Software. 19848b8605Smrg * 20848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25848b8605Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26848b8605Smrg * DEALINGS IN THE SOFTWARE. 27848b8605Smrg * 28848b8605Smrg **************************************************************************/ 29848b8605Smrg 30848b8605Smrg 31848b8605Smrg#ifndef EGLCONTEXT_INCLUDED 32848b8605Smrg#define EGLCONTEXT_INCLUDED 33848b8605Smrg 34b8e80941Smrg#include "c99_compat.h" 35848b8605Smrg 36848b8605Smrg#include "egltypedefs.h" 37848b8605Smrg#include "egldisplay.h" 38848b8605Smrg 39848b8605Smrg 40b8e80941Smrg#ifdef __cplusplus 41b8e80941Smrgextern "C" { 42b8e80941Smrg#endif 43b8e80941Smrg 44848b8605Smrg/** 45848b8605Smrg * "Base" class for device driver contexts. 46848b8605Smrg */ 47848b8605Smrgstruct _egl_context 48848b8605Smrg{ 49848b8605Smrg /* A context is a display resource */ 50848b8605Smrg _EGLResource Resource; 51848b8605Smrg 52848b8605Smrg /* The bound status of the context */ 53848b8605Smrg _EGLThreadInfo *Binding; 54848b8605Smrg _EGLSurface *DrawSurface; 55848b8605Smrg _EGLSurface *ReadSurface; 56848b8605Smrg 57848b8605Smrg _EGLConfig *Config; 58848b8605Smrg 59848b8605Smrg EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */ 60848b8605Smrg EGLint ClientMajorVersion; 61848b8605Smrg EGLint ClientMinorVersion; 62848b8605Smrg EGLint Flags; 63848b8605Smrg EGLint Profile; 64848b8605Smrg EGLint ResetNotificationStrategy; 65b8e80941Smrg EGLint ContextPriority; 66b8e80941Smrg EGLBoolean NoError; 67b8e80941Smrg EGLint ReleaseBehavior; 68848b8605Smrg}; 69848b8605Smrg 70848b8605Smrg 71b8e80941Smrgextern EGLBoolean 72b8e80941Smrg_eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, 73848b8605Smrg _EGLConfig *config, const EGLint *attrib_list); 74848b8605Smrg 75848b8605Smrg 76848b8605Smrgextern EGLBoolean 77b8e80941Smrg_eglQueryContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx, EGLint attribute, EGLint *value); 78848b8605Smrg 79848b8605Smrg 80b8e80941Smrgextern EGLBoolean 81848b8605Smrg_eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, 82848b8605Smrg _EGLContext **old_ctx, 83848b8605Smrg _EGLSurface **old_draw, _EGLSurface **old_read); 84848b8605Smrg 85b8e80941Smrgextern _EGLContext * 86b8e80941Smrg_eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t); 87b8e80941Smrg 88848b8605Smrg 89848b8605Smrg/** 90848b8605Smrg * Increment reference count for the context. 91848b8605Smrg */ 92b8e80941Smrgstatic inline _EGLContext * 93848b8605Smrg_eglGetContext(_EGLContext *ctx) 94848b8605Smrg{ 95848b8605Smrg if (ctx) 96848b8605Smrg _eglGetResource(&ctx->Resource); 97848b8605Smrg return ctx; 98848b8605Smrg} 99848b8605Smrg 100848b8605Smrg 101848b8605Smrg/** 102848b8605Smrg * Decrement reference count for the context. 103848b8605Smrg */ 104b8e80941Smrgstatic inline EGLBoolean 105848b8605Smrg_eglPutContext(_EGLContext *ctx) 106848b8605Smrg{ 107848b8605Smrg return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE; 108848b8605Smrg} 109848b8605Smrg 110848b8605Smrg 111848b8605Smrg/** 112848b8605Smrg * Link a context to its display and return the handle of the link. 113848b8605Smrg * The handle can be passed to client directly. 114848b8605Smrg */ 115b8e80941Smrgstatic inline EGLContext 116848b8605Smrg_eglLinkContext(_EGLContext *ctx) 117848b8605Smrg{ 118848b8605Smrg _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); 119848b8605Smrg return (EGLContext) ctx; 120848b8605Smrg} 121848b8605Smrg 122848b8605Smrg 123848b8605Smrg/** 124848b8605Smrg * Unlink a linked context from its display. 125848b8605Smrg * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. 126848b8605Smrg */ 127b8e80941Smrgstatic inline void 128848b8605Smrg_eglUnlinkContext(_EGLContext *ctx) 129848b8605Smrg{ 130848b8605Smrg _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); 131848b8605Smrg} 132848b8605Smrg 133848b8605Smrg 134848b8605Smrg/** 135848b8605Smrg * Lookup a handle to find the linked context. 136848b8605Smrg * Return NULL if the handle has no corresponding linked context. 137848b8605Smrg */ 138b8e80941Smrgstatic inline _EGLContext * 139b8e80941Smrg_eglLookupContext(EGLContext context, _EGLDisplay *disp) 140848b8605Smrg{ 141848b8605Smrg _EGLContext *ctx = (_EGLContext *) context; 142b8e80941Smrg if (!disp || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, disp)) 143848b8605Smrg ctx = NULL; 144848b8605Smrg return ctx; 145848b8605Smrg} 146848b8605Smrg 147848b8605Smrg 148848b8605Smrg/** 149848b8605Smrg * Return the handle of a linked context, or EGL_NO_CONTEXT. 150848b8605Smrg */ 151b8e80941Smrgstatic inline EGLContext 152848b8605Smrg_eglGetContextHandle(_EGLContext *ctx) 153848b8605Smrg{ 154848b8605Smrg _EGLResource *res = (_EGLResource *) ctx; 155848b8605Smrg return (res && _eglIsResourceLinked(res)) ? 156848b8605Smrg (EGLContext) ctx : EGL_NO_CONTEXT; 157848b8605Smrg} 158848b8605Smrg 159848b8605Smrg 160b8e80941Smrg#ifdef __cplusplus 161b8e80941Smrg} 162b8e80941Smrg#endif 163b8e80941Smrg 164848b8605Smrg#endif /* EGLCONTEXT_INCLUDED */ 165