dri: Add a flush control extension
[mesa.git] / src / mesa / drivers / dri / common / dri_util.h
1 /*
2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file dri_util.h
28 * DRI utility functions definitions.
29 *
30 * This module acts as glue between GLX and the actual hardware driver. A DRI
31 * driver doesn't really \e have to use any of this - it's optional. But, some
32 * useful stuff is done here that otherwise would have to be duplicated in most
33 * drivers.
34 *
35 * Basically, these utility functions take care of some of the dirty details of
36 * screen initialization, context creation, context binding, DRM setup, etc.
37 *
38 * These functions are compiled into each DRI driver so libGL.so knows nothing
39 * about them.
40 *
41 * \sa dri_util.c.
42 *
43 * \author Kevin E. Martin <kevin@precisioninsight.com>
44 * \author Brian Paul <brian@precisioninsight.com>
45 */
46
47 /**
48 * The following structs are shared between DRISW and DRI2, the DRISW structs
49 * are essentially base classes of the DRI2 structs. DRISW needs to compile on
50 * platforms without DRM, so keep the structs opaque to DRM.
51 */
52
53 #ifndef _DRI_UTIL_H_
54 #define _DRI_UTIL_H_
55
56 #include <GL/gl.h>
57 #include <GL/internal/dri_interface.h>
58 #include "main/mtypes.h"
59 #include "util/xmlconfig.h"
60 #include <stdbool.h>
61
62 /**
63 * Extensions.
64 */
65 extern const __DRIcoreExtension driCoreExtension;
66 extern const __DRIswrastExtension driSWRastExtension;
67 extern const __DRIdri2Extension driDRI2Extension;
68 extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
69 extern const __DRIcopySubBufferExtension driCopySubBufferExtension;
70 extern const __DRI2flushControlExtension dri2FlushControlExtension;
71
72 /**
73 * Description of the attributes used to create a config.
74 *
75 * This is passed as the context_config parameter to CreateContext. The idea
76 * with this struct is that it can be extended without having to modify all of
77 * the drivers. The first three members (major/minor_version and flags) are
78 * always valid, but the remaining members are only valid if the corresponding
79 * flag is set for the attribute. If the flag is not set then the default
80 * value should be assumed. That way the driver can quickly check if any
81 * attributes were set that it doesn't understand and report an error.
82 */
83 struct __DriverContextConfig {
84 /* These members are always valid */
85 unsigned major_version;
86 unsigned minor_version;
87 uint32_t flags;
88
89 /* Flags describing which of the remaining members are valid */
90 uint32_t attribute_mask;
91
92 /* Only valid if __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY is set */
93 int reset_strategy;
94
95 /* Only valid if __DRIVER_CONTEXT_PRIORITY is set */
96 unsigned priority;
97
98 /* Only valid if __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR is set */
99 int release_behavior;
100 };
101
102 #define __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY (1 << 0)
103 #define __DRIVER_CONTEXT_ATTRIB_PRIORITY (1 << 1)
104 #define __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR (1 << 2)
105
106 /**
107 * Driver callback functions.
108 *
109 * Each DRI driver must have one of these structures with all the pointers set
110 * to appropriate functions within the driver.
111 *
112 * When glXCreateContext() is called, for example, it'll call a helper function
113 * dri_util.c which in turn will jump through the \a CreateContext pointer in
114 * this structure.
115 */
116 struct __DriverAPIRec {
117 const __DRIconfig **(*InitScreen) (__DRIscreen * priv);
118
119 void (*DestroyScreen)(__DRIscreen *driScrnPriv);
120
121 GLboolean (*CreateContext)(gl_api api,
122 const struct gl_config *glVis,
123 __DRIcontext *driContextPriv,
124 const struct __DriverContextConfig *ctx_config,
125 unsigned *error,
126 void *sharedContextPrivate);
127
128 void (*DestroyContext)(__DRIcontext *driContextPriv);
129
130 GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv,
131 __DRIdrawable *driDrawPriv,
132 const struct gl_config *glVis,
133 GLboolean pixmapBuffer);
134
135 void (*DestroyBuffer)(__DRIdrawable *driDrawPriv);
136
137 void (*SwapBuffers)(__DRIdrawable *driDrawPriv);
138
139 GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv,
140 __DRIdrawable *driDrawPriv,
141 __DRIdrawable *driReadPriv);
142
143 GLboolean (*UnbindContext)(__DRIcontext *driContextPriv);
144
145 __DRIbuffer *(*AllocateBuffer) (__DRIscreen *screenPrivate,
146 unsigned int attachment,
147 unsigned int format,
148 int width, int height);
149
150 void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
151
152 void (*CopySubBuffer)(__DRIdrawable *driDrawPriv, int x, int y,
153 int w, int h);
154 };
155
156 extern const struct __DriverAPIRec driDriverAPI;
157 extern const struct __DriverAPIRec *globalDriverAPI;
158
159 /**
160 * Per-screen private driver information.
161 */
162 struct __DRIscreenRec {
163 /**
164 * Driver-specific entrypoints provided by the driver's
165 * __DRIDriverVtableExtensionRec.
166 */
167 const struct __DriverAPIRec *driver;
168
169 /**
170 * Current screen's number
171 */
172 int myNum;
173
174 /**
175 * File descriptor returned when the kernel device driver is opened.
176 *
177 * Used to:
178 * - authenticate client to kernel
179 * - map the frame buffer, SAREA, etc.
180 * - close the kernel device driver
181 */
182 int fd;
183
184 /**
185 * Device-dependent private information (not stored in the SAREA).
186 *
187 * This pointer is never touched by the DRI layer.
188 */
189 void *driverPrivate;
190
191 void *loaderPrivate;
192
193 int max_gl_core_version;
194 int max_gl_compat_version;
195 int max_gl_es1_version;
196 int max_gl_es2_version;
197
198 const __DRIextension **extensions;
199
200 const __DRIswrastLoaderExtension *swrast_loader;
201
202 struct {
203 /* Flag to indicate that this is a DRI2 screen. Many of the above
204 * fields will not be valid or initializaed in that case. */
205 const __DRIdri2LoaderExtension *loader;
206 const __DRIimageLookupExtension *image;
207 const __DRIuseInvalidateExtension *useInvalidate;
208 const __DRIbackgroundCallableExtension *backgroundCallable;
209 } dri2;
210
211 struct {
212 const __DRIimageLoaderExtension *loader;
213 } image;
214
215 driOptionCache optionInfo;
216 driOptionCache optionCache;
217
218 unsigned int api_mask;
219 };
220
221 /**
222 * Per-context private driver information.
223 */
224 struct __DRIcontextRec {
225 /**
226 * Device driver's private context data. This structure is opaque.
227 */
228 void *driverPrivate;
229
230 /**
231 * The loaders's private context data. This structure is opaque.
232 */
233 void *loaderPrivate;
234
235 /**
236 * Pointer to drawable currently bound to this context for drawing.
237 */
238 __DRIdrawable *driDrawablePriv;
239
240 /**
241 * Pointer to drawable currently bound to this context for reading.
242 */
243 __DRIdrawable *driReadablePriv;
244
245 /**
246 * Pointer to screen on which this context was created.
247 */
248 __DRIscreen *driScreenPriv;
249
250 struct {
251 int draw_stamp;
252 int read_stamp;
253 } dri2;
254 };
255
256 /**
257 * Per-drawable private DRI driver information.
258 */
259 struct __DRIdrawableRec {
260 /**
261 * Driver's private drawable information.
262 *
263 * This structure is opaque.
264 */
265 void *driverPrivate;
266
267 /**
268 * Private data from the loader. We just hold on to it and pass
269 * it back when calling into loader provided functions.
270 */
271 void *loaderPrivate;
272
273 /**
274 * Pointer to context to which this drawable is currently bound.
275 */
276 __DRIcontext *driContextPriv;
277
278 /**
279 * Pointer to screen on which this drawable was created.
280 */
281 __DRIscreen *driScreenPriv;
282
283 /**
284 * Reference count for number of context's currently bound to this
285 * drawable.
286 *
287 * Once it reaches zero, the drawable can be destroyed.
288 *
289 * \note This behavior will change with GLX 1.3.
290 */
291 int refcount;
292
293 /**
294 * Last value of the stamp.
295 *
296 * If this differs from the value stored at __DRIdrawable::dri2.stamp,
297 * then the drawable information has been modified by the X server, and the
298 * drawable information (below) should be retrieved from the X server.
299 */
300 unsigned int lastStamp;
301
302 int w, h;
303
304 /**
305 * Drawable timestamp. Increased when the loader calls invalidate.
306 */
307 struct {
308 unsigned int stamp;
309 } dri2;
310 };
311
312 extern uint32_t
313 driGLFormatToImageFormat(mesa_format format);
314
315 extern mesa_format
316 driImageFormatToGLFormat(uint32_t image_format);
317
318 extern void
319 dri2InvalidateDrawable(__DRIdrawable *drawable);
320
321 extern void
322 driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv);
323
324 extern void
325 driContextSetFlags(struct gl_context *ctx, uint32_t flags);
326
327 extern const __DRIimageDriverExtension driImageDriverExtension;
328
329 extern const __DRInoErrorExtension dri2NoErrorExtension;
330
331 #endif /* _DRI_UTIL_H_ */