egl: Drop dpy argument from the link functions.
[mesa.git] / src / egl / main / eglcontext.h
1 #ifndef EGLCONTEXT_INCLUDED
2 #define EGLCONTEXT_INCLUDED
3
4
5 #include "egltypedefs.h"
6 #include "egldisplay.h"
7
8
9 /**
10 * "Base" class for device driver contexts.
11 */
12 struct _egl_context
13 {
14 /* A context is a display resource */
15 _EGLResource Resource;
16
17 /* The bound status of the context */
18 _EGLThreadInfo *Binding;
19 _EGLSurface *DrawSurface;
20 _EGLSurface *ReadSurface;
21
22 _EGLConfig *Config;
23
24 EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */
25 EGLint ClientVersion; /**< 1 = OpenGLES 1.x, 2 = OpenGLES 2.x */
26
27 /* The real render buffer when a window surface is bound */
28 EGLint WindowRenderBuffer;
29 };
30
31
32 PUBLIC EGLBoolean
33 _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy,
34 _EGLConfig *config, const EGLint *attrib_list);
35
36
37 extern EGLBoolean
38 _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
39
40
41 PUBLIC EGLBoolean
42 _eglBindContext(_EGLContext **ctx, _EGLSurface **draw, _EGLSurface **read);
43
44
45 /**
46 * Return true if the context is bound to a thread.
47 *
48 * The binding is considered a reference to the context. Drivers should not
49 * destroy a context when it is bound.
50 */
51 static INLINE EGLBoolean
52 _eglIsContextBound(_EGLContext *ctx)
53 {
54 return (ctx->Binding != NULL);
55 }
56
57
58 /**
59 * Link a context to its display and return the handle of the link.
60 * The handle can be passed to client directly.
61 */
62 static INLINE EGLContext
63 _eglLinkContext(_EGLContext *ctx)
64 {
65 _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
66 return (EGLContext) ctx;
67 }
68
69
70 /**
71 * Unlink a linked context from its display.
72 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
73 */
74 static INLINE void
75 _eglUnlinkContext(_EGLContext *ctx)
76 {
77 _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
78 }
79
80
81 /**
82 * Lookup a handle to find the linked context.
83 * Return NULL if the handle has no corresponding linked context.
84 */
85 static INLINE _EGLContext *
86 _eglLookupContext(EGLContext context, _EGLDisplay *dpy)
87 {
88 _EGLContext *ctx = (_EGLContext *) context;
89 if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy))
90 ctx = NULL;
91 return ctx;
92 }
93
94
95 /**
96 * Return the handle of a linked context, or EGL_NO_CONTEXT.
97 */
98 static INLINE EGLContext
99 _eglGetContextHandle(_EGLContext *ctx)
100 {
101 _EGLResource *res = (_EGLResource *) ctx;
102 return (res && _eglIsResourceLinked(res)) ?
103 (EGLContext) ctx : EGL_NO_CONTEXT;
104 }
105
106
107 /**
108 * Return true if the context is linked to a display.
109 *
110 * The link is considered a reference to the context (the display is owning the
111 * context). Drivers should not destroy a context when it is linked.
112 */
113 static INLINE EGLBoolean
114 _eglIsContextLinked(_EGLContext *ctx)
115 {
116 _EGLResource *res = (_EGLResource *) ctx;
117 return (res && _eglIsResourceLinked(res));
118 }
119
120
121 #endif /* EGLCONTEXT_INCLUDED */