1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
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 #include "c99_compat.h"
35
36 #include "egltypedefs.h"
37 #include "egldisplay.h"
38
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /**
45 * "Base" class for device driver contexts.
46 */
47 struct _egl_context
48 {
49 /* A context is a display resource */
50 _EGLResource Resource;
51
52 /* The bound status of the context */
53 _EGLThreadInfo *Binding;
54 _EGLSurface *DrawSurface;
55 _EGLSurface *ReadSurface;
56
57 _EGLConfig *Config;
58
59 EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */
60 EGLint ClientMajorVersion;
61 EGLint ClientMinorVersion;
62 EGLint Flags;
63 EGLint Profile;
64 EGLint ResetNotificationStrategy;
65 EGLint ContextPriority;
66 EGLBoolean NoError;
67 EGLint ReleaseBehavior;
68
69 /* The real render buffer when a window surface is bound */
70 EGLint WindowRenderBuffer;
71 };
72
73
74 extern EGLBoolean
75 _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy,
76 _EGLConfig *config, const EGLint *attrib_list);
77
78
79 extern EGLBoolean
80 _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
81
82
83 extern EGLBoolean
84 _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
85 _EGLContext **old_ctx,
86 _EGLSurface **old_draw, _EGLSurface **old_read);
87
88 extern _EGLContext *
89 _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t);
90
91
92 /**
93 * Increment reference count for the context.
94 */
95 static inline _EGLContext *
_eglGetContext(_EGLContext * ctx)96 _eglGetContext(_EGLContext *ctx)
97 {
98 if (ctx)
99 _eglGetResource(&ctx->Resource);
100 return ctx;
101 }
102
103
104 /**
105 * Decrement reference count for the context.
106 */
107 static inline EGLBoolean
_eglPutContext(_EGLContext * ctx)108 _eglPutContext(_EGLContext *ctx)
109 {
110 return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE;
111 }
112
113
114 /**
115 * Link a context to its display and return the handle of the link.
116 * The handle can be passed to client directly.
117 */
118 static inline EGLContext
_eglLinkContext(_EGLContext * ctx)119 _eglLinkContext(_EGLContext *ctx)
120 {
121 _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
122 return (EGLContext) ctx;
123 }
124
125
126 /**
127 * Unlink a linked context from its display.
128 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
129 */
130 static inline void
_eglUnlinkContext(_EGLContext * ctx)131 _eglUnlinkContext(_EGLContext *ctx)
132 {
133 _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
134 }
135
136
137 /**
138 * Lookup a handle to find the linked context.
139 * Return NULL if the handle has no corresponding linked context.
140 */
141 static inline _EGLContext *
_eglLookupContext(EGLContext context,_EGLDisplay * dpy)142 _eglLookupContext(EGLContext context, _EGLDisplay *dpy)
143 {
144 _EGLContext *ctx = (_EGLContext *) context;
145 if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy))
146 ctx = NULL;
147 return ctx;
148 }
149
150
151 /**
152 * Return the handle of a linked context, or EGL_NO_CONTEXT.
153 */
154 static inline EGLContext
_eglGetContextHandle(_EGLContext * ctx)155 _eglGetContextHandle(_EGLContext *ctx)
156 {
157 _EGLResource *res = (_EGLResource *) ctx;
158 return (res && _eglIsResourceLinked(res)) ?
159 (EGLContext) ctx : EGL_NO_CONTEXT;
160 }
161
162
163 #ifdef __cplusplus
164 }
165 #endif
166
167 #endif /* EGLCONTEXT_INCLUDED */
168