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