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