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