xref: /aosp_15_r20/external/mesa3d/src/egl/main/eglcontext.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2008 VMware, Inc.
4  * Copyright 2009-2010 Chia-I Wu <[email protected]>
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 #ifndef EGLCONTEXT_INCLUDED
31 #define EGLCONTEXT_INCLUDED
32 
33 #include "egldisplay.h"
34 #include "egltypedefs.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /**
41  * "Base" class for device driver contexts.
42  */
43 struct _egl_context {
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 ClientMajorVersion;
56    EGLint ClientMinorVersion;
57    EGLint Flags;
58    EGLint Profile;
59    EGLint ResetNotificationStrategy;
60    EGLint ContextPriority;
61    EGLBoolean NoError;
62    EGLint ReleaseBehavior;
63    EGLBoolean Protected; /* EGL_EXT_protected_content */
64 };
65 
66 extern EGLBoolean
67 _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *config,
68                 _EGLContext *share_list, const EGLint *attrib_list);
69 
70 extern EGLBoolean
71 _eglQueryContext(_EGLContext *ctx, EGLint attribute, EGLint *value);
72 
73 extern EGLBoolean
74 _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
75                 _EGLContext **old_ctx, _EGLSurface **old_draw,
76                 _EGLSurface **old_read);
77 
78 extern _EGLContext *
79 _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t);
80 
81 /**
82  * Increment reference count for the context.
83  */
84 static inline _EGLContext *
_eglGetContext(_EGLContext * ctx)85 _eglGetContext(_EGLContext *ctx)
86 {
87    if (ctx)
88       _eglGetResource(&ctx->Resource);
89    return ctx;
90 }
91 
92 /**
93  * Decrement reference count for the context.
94  */
95 static inline EGLBoolean
_eglPutContext(_EGLContext * ctx)96 _eglPutContext(_EGLContext *ctx)
97 {
98    return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE;
99 }
100 
101 /**
102  * Link a context to its display and return the handle of the link.
103  * The handle can be passed to client directly.
104  */
105 static inline EGLContext
_eglLinkContext(_EGLContext * ctx)106 _eglLinkContext(_EGLContext *ctx)
107 {
108    _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
109    return (EGLContext)ctx;
110 }
111 
112 /**
113  * Unlink a linked context from its display.
114  * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
115  */
116 static inline void
_eglUnlinkContext(_EGLContext * ctx)117 _eglUnlinkContext(_EGLContext *ctx)
118 {
119    _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
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 *
_eglLookupContext(EGLContext context,_EGLDisplay * disp)127 _eglLookupContext(EGLContext context, _EGLDisplay *disp)
128 {
129    _EGLContext *ctx = (_EGLContext *)context;
130    if (!disp || !_eglCheckResource((void *)ctx, _EGL_RESOURCE_CONTEXT, disp))
131       ctx = NULL;
132    return ctx;
133 }
134 
135 /**
136  * Return the handle of a linked context, or EGL_NO_CONTEXT.
137  */
138 static inline EGLContext
_eglGetContextHandle(_EGLContext * ctx)139 _eglGetContextHandle(_EGLContext *ctx)
140 {
141    _EGLResource *res = (_EGLResource *)ctx;
142    return (res && _eglIsResourceLinked(res)) ? (EGLContext)ctx : EGL_NO_CONTEXT;
143 }
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif /* EGLCONTEXT_INCLUDED */
150