7a3b0a9b2f5294e6d7b5aec0da19a164e2802495
[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 #ifndef _DRI_UTIL_H_
48 #define _DRI_UTIL_H_
49
50 #include <GL/gl.h>
51 #include <drm.h>
52 #include <drm_sarea.h>
53 #include <xf86drm.h>
54 #include "xmlconfig.h"
55 #include "main/glheader.h"
56 #include "main/mtypes.h"
57 #include "GL/internal/dri_interface.h"
58
59 #define GLX_BAD_CONTEXT 5
60
61 /**
62 * Extensions.
63 */
64 extern const __DRIcoreExtension driCoreExtension;
65 extern const __DRIdri2Extension driDRI2Extension;
66 extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
67
68 /**
69 * Driver callback functions.
70 *
71 * Each DRI driver must have one of these structures with all the pointers set
72 * to appropriate functions within the driver.
73 *
74 * When glXCreateContext() is called, for example, it'll call a helper function
75 * dri_util.c which in turn will jump through the \a CreateContext pointer in
76 * this structure.
77 */
78 struct __DriverAPIRec {
79 /**
80 * Screen destruction callback
81 */
82 void (*DestroyScreen)(__DRIscreen *driScrnPriv);
83
84 /**
85 * Context creation callback
86 */
87 GLboolean (*CreateContext)(gl_api api,
88 const struct gl_config *glVis,
89 __DRIcontext *driContextPriv,
90 void *sharedContextPrivate);
91
92 /**
93 * Context destruction callback
94 */
95 void (*DestroyContext)(__DRIcontext *driContextPriv);
96
97 /**
98 * Buffer (drawable) creation callback
99 */
100 GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv,
101 __DRIdrawable *driDrawPriv,
102 const struct gl_config *glVis,
103 GLboolean pixmapBuffer);
104
105 /**
106 * Buffer (drawable) destruction callback
107 */
108 void (*DestroyBuffer)(__DRIdrawable *driDrawPriv);
109
110 /**
111 * Context activation callback
112 */
113 GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv,
114 __DRIdrawable *driDrawPriv,
115 __DRIdrawable *driReadPriv);
116
117 /**
118 * Context unbinding callback
119 */
120 GLboolean (*UnbindContext)(__DRIcontext *driContextPriv);
121
122 /* DRI2 Entry point */
123 const __DRIconfig **(*InitScreen2) (__DRIscreen * priv);
124
125 __DRIbuffer *(*AllocateBuffer) (__DRIscreen *screenPrivate,
126 unsigned int attachment,
127 unsigned int format,
128 int width, int height);
129 void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
130 };
131
132 extern const struct __DriverAPIRec driDriverAPI;
133
134
135 /**
136 * Per-drawable private DRI driver information.
137 */
138 struct __DRIdrawableRec {
139 /**
140 * Driver's private drawable information.
141 *
142 * This structure is opaque.
143 */
144 void *driverPrivate;
145
146 /**
147 * Private data from the loader. We just hold on to it and pass
148 * it back when calling into loader provided functions.
149 */
150 void *loaderPrivate;
151
152 /**
153 * Reference count for number of context's currently bound to this
154 * drawable.
155 *
156 * Once it reaches zero, the drawable can be destroyed.
157 *
158 * \note This behavior will change with GLX 1.3.
159 */
160 int refcount;
161
162 /**
163 * Last value of the stamp.
164 *
165 * If this differs from the value stored at __DRIdrawable::dri2.stamp,
166 * then the drawable information has been modified by the X server, and the
167 * drawable information (below) should be retrieved from the X server.
168 */
169 unsigned int lastStamp;
170
171 int w, h;
172
173 /**
174 * Pointer to context to which this drawable is currently bound.
175 */
176 __DRIcontext *driContextPriv;
177
178 /**
179 * Pointer to screen on which this drawable was created.
180 */
181 __DRIscreen *driScreenPriv;
182
183 /**
184 * Drawable timestamp. Increased when the loader calls invalidate.
185 */
186 struct {
187 unsigned int stamp;
188 } dri2;
189 };
190
191 /**
192 * Per-context private driver information.
193 */
194 struct __DRIcontextRec {
195 /**
196 * Device driver's private context data. This structure is opaque.
197 */
198 void *driverPrivate;
199
200 /**
201 * Pointer to drawable currently bound to this context for drawing.
202 */
203 __DRIdrawable *driDrawablePriv;
204
205 /**
206 * Pointer to drawable currently bound to this context for reading.
207 */
208 __DRIdrawable *driReadablePriv;
209
210 /**
211 * Pointer to screen on which this context was created.
212 */
213 __DRIscreen *driScreenPriv;
214
215 /**
216 * The loaders's private context data. This structure is opaque.
217 */
218 void *loaderPrivate;
219
220 struct {
221 int draw_stamp;
222 int read_stamp;
223 } dri2;
224 };
225
226 /**
227 * Per-screen private driver information.
228 */
229 struct __DRIscreenRec {
230 /**
231 * Current screen's number
232 */
233 int myNum;
234
235 /**
236 * Callback functions into the hardware-specific DRI driver code.
237 */
238 struct __DriverAPIRec DriverAPI;
239
240 const __DRIextension **extensions;
241
242 /**
243 * DRM (kernel module) version information.
244 */
245 __DRIversion drm_version;
246
247 /**
248 * File descriptor returned when the kernel device driver is opened.
249 *
250 * Used to:
251 * - authenticate client to kernel
252 * - map the frame buffer, SAREA, etc.
253 * - close the kernel device driver
254 */
255 int fd;
256
257 /**
258 * Device-dependent private information (not stored in the SAREA).
259 *
260 * This pointer is never touched by the DRI layer.
261 */
262 #ifdef __cplusplus
263 void *priv;
264 #else
265 void *private;
266 #endif
267
268 struct {
269 /* Flag to indicate that this is a DRI2 screen. Many of the above
270 * fields will not be valid or initializaed in that case. */
271 __DRIdri2LoaderExtension *loader;
272 __DRIimageLookupExtension *image;
273 __DRIuseInvalidateExtension *useInvalidate;
274 } dri2;
275
276 driOptionCache optionInfo;
277 driOptionCache optionCache;
278 unsigned int api_mask;
279 void *loaderPrivate;
280 };
281
282 extern void
283 dri2InvalidateDrawable(__DRIdrawable *drawable);
284
285 extern void
286 driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv);
287
288 #endif /* _DRI_UTIL_H_ */