Merge remote branch 'origin/master' into pipe-video
[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 _EGLContext *
38 _eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list);
39
40
41 extern EGLBoolean
42 _eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx);
43
44
45 extern EGLBoolean
46 _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
47
48
49 PUBLIC EGLBoolean
50 _eglBindContext(_EGLContext **ctx, _EGLSurface **draw, _EGLSurface **read);
51
52
53 extern EGLBoolean
54 _eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx);
55
56
57 extern EGLBoolean
58 _eglCopyContextMESA(_EGLDriver *drv, EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask);
59
60
61 /**
62 * Return true if the context is bound to a thread.
63 *
64 * The binding is considered a reference to the context. Drivers should not
65 * destroy a context when it is bound.
66 */
67 static INLINE EGLBoolean
68 _eglIsContextBound(_EGLContext *ctx)
69 {
70 return (ctx->Binding != NULL);
71 }
72
73
74 /**
75 * Link a context to a display and return the handle of the link.
76 * The handle can be passed to client directly.
77 */
78 static INLINE EGLContext
79 _eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy)
80 {
81 _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT, dpy);
82 return (EGLContext) ctx;
83 }
84
85
86 /**
87 * Unlink a linked context from its display.
88 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
89 */
90 static INLINE void
91 _eglUnlinkContext(_EGLContext *ctx)
92 {
93 _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
94 }
95
96
97 /**
98 * Lookup a handle to find the linked context.
99 * Return NULL if the handle has no corresponding linked context.
100 */
101 static INLINE _EGLContext *
102 _eglLookupContext(EGLContext context, _EGLDisplay *dpy)
103 {
104 _EGLContext *ctx = (_EGLContext *) context;
105 if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy))
106 ctx = NULL;
107 return ctx;
108 }
109
110
111 /**
112 * Return the handle of a linked context, or EGL_NO_CONTEXT.
113 */
114 static INLINE EGLContext
115 _eglGetContextHandle(_EGLContext *ctx)
116 {
117 _EGLResource *res = (_EGLResource *) ctx;
118 return (res && _eglIsResourceLinked(res)) ?
119 (EGLContext) ctx : EGL_NO_CONTEXT;
120 }
121
122
123 /**
124 * Return true if the context is linked to a display.
125 *
126 * The link is considered a reference to the context (the display is owning the
127 * context). Drivers should not destroy a context when it is linked.
128 */
129 static INLINE EGLBoolean
130 _eglIsContextLinked(_EGLContext *ctx)
131 {
132 _EGLResource *res = (_EGLResource *) ctx;
133 return (res && _eglIsResourceLinked(res));
134 }
135
136
137 #endif /* EGLCONTEXT_INCLUDED */