xref: /third_party/mesa3d/src/egl/main/eglcontext.h (revision bf215546)
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
39extern "C" {
40#endif
41
42/**
43 * "Base" class for device driver contexts.
44 */
45struct _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
69extern EGLBoolean
70_eglInitContext(_EGLContext *ctx, _EGLDisplay *disp,
71                _EGLConfig *config, const EGLint *attrib_list);
72
73
74extern EGLBoolean
75_eglQueryContext(_EGLContext *ctx, EGLint attribute, EGLint *value);
76
77
78extern EGLBoolean
79_eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
80                _EGLContext **old_ctx,
81                _EGLSurface **old_draw, _EGLSurface **old_read);
82
83extern _EGLContext *
84_eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t);
85
86
87/**
88 * Increment reference count for the context.
89 */
90static inline _EGLContext *
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 */
102static inline EGLBoolean
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 */
113static inline EGLContext
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 */
125static inline void
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 */
136static inline _EGLContext *
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 */
149static inline EGLContext
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