Merge branch 'xa_branch'
[mesa.git] / src / egl / main / eglcontext.h
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 */
42 struct _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
62 PUBLIC EGLBoolean
63 _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy,
64 _EGLConfig *config, const EGLint *attrib_list);
65
66
67 extern EGLBoolean
68 _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
69
70
71 PUBLIC 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 */
80 static 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 */
92 static 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 */
103 static 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 */
115 static 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 */
126 static 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 */
139 static 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 */