1 /**************************************************************************
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.
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:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
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.
28 **************************************************************************/
31 #ifndef EGLCONTEXT_INCLUDED
32 #define EGLCONTEXT_INCLUDED
35 #include "egltypedefs.h"
36 #include "egldisplay.h"
40 * "Base" class for device driver contexts.
44 /* A context is a display resource */
45 _EGLResource Resource;
47 /* The bound status of the context */
48 _EGLThreadInfo *Binding;
49 _EGLSurface *DrawSurface;
50 _EGLSurface *ReadSurface;
54 EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */
55 EGLint ClientMajorVersion;
56 EGLint ClientMinorVersion;
58 /* The real render buffer when a window surface is bound */
59 EGLint WindowRenderBuffer;
64 _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy,
65 _EGLConfig *config, const EGLint *attrib_list);
69 _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
73 _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
74 _EGLContext **old_ctx,
75 _EGLSurface **old_draw, _EGLSurface **old_read);
79 * Increment reference count for the context.
81 static INLINE _EGLContext *
82 _eglGetContext(_EGLContext *ctx)
85 _eglGetResource(&ctx->Resource);
91 * Decrement reference count for the context.
93 static INLINE EGLBoolean
94 _eglPutContext(_EGLContext *ctx)
96 return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE;
101 * Link a context to its display and return the handle of the link.
102 * The handle can be passed to client directly.
104 static INLINE EGLContext
105 _eglLinkContext(_EGLContext *ctx)
107 _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
108 return (EGLContext) ctx;
113 * Unlink a linked context from its display.
114 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
117 _eglUnlinkContext(_EGLContext *ctx)
119 _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
124 * Lookup a handle to find the linked context.
125 * Return NULL if the handle has no corresponding linked context.
127 static INLINE _EGLContext *
128 _eglLookupContext(EGLContext context, _EGLDisplay *dpy)
130 _EGLContext *ctx = (_EGLContext *) context;
131 if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy))
138 * Return the handle of a linked context, or EGL_NO_CONTEXT.
140 static INLINE EGLContext
141 _eglGetContextHandle(_EGLContext *ctx)
143 _EGLResource *res = (_EGLResource *) ctx;
144 return (res && _eglIsResourceLinked(res)) ?
145 (EGLContext) ctx : EGL_NO_CONTEXT;
149 #endif /* EGLCONTEXT_INCLUDED */