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