• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "kopper_interface.h"
59 #include "main/formats.h"
60 #include "main/glconfig.h"
61 #include "main/menums.h"
62 #include "util/xmlconfig.h"
63 #include <stdbool.h>
64 
65 struct __DRIconfigRec {
66     struct gl_config modes;
67 };
68 
69 /**
70  * Extensions.
71  */
72 extern const __DRIcoreExtension driCoreExtension;
73 extern const __DRIswrastExtension driSWRastExtension;
74 extern const __DRIdri2Extension driDRI2Extension;
75 extern const __DRIdri2Extension swkmsDRI2Extension;
76 extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
77 extern const __DRI2flushControlExtension dri2FlushControlExtension;
78 
79 /**
80  * Description of the attributes used to create a config.
81  *
82  * This is passed as the context_config parameter to CreateContext. The idea
83  * with this struct is that it can be extended without having to modify all of
84  * the drivers. The first three members (major/minor_version and flags) are
85  * always valid, but the remaining members are only valid if the corresponding
86  * flag is set for the attribute. If the flag is not set then the default
87  * value should be assumed. That way the driver can quickly check if any
88  * attributes were set that it doesn't understand and report an error.
89  */
90 struct __DriverContextConfig {
91     /* These members are always valid */
92     unsigned major_version;
93     unsigned minor_version;
94     uint32_t flags;
95 
96     /* Flags describing which of the remaining members are valid */
97     uint32_t attribute_mask;
98 
99     /* Only valid if __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY is set */
100     int reset_strategy;
101 
102     /* Only valid if __DRIVER_CONTEXT_PRIORITY is set */
103     unsigned priority;
104 
105     /* Only valid if __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR is set */
106     int release_behavior;
107 
108     /* Only valid if __DRIVER_CONTEXT_ATTRIB_NO_ERROR is set */
109     int no_error;
110 };
111 
112 #define __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY   (1 << 0)
113 #define __DRIVER_CONTEXT_ATTRIB_PRIORITY         (1 << 1)
114 #define __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR (1 << 2)
115 #define __DRIVER_CONTEXT_ATTRIB_NO_ERROR         (1 << 3)
116 
117 /**
118  * Driver callback functions.
119  *
120  * Each DRI driver must have one of these structures with all the pointers set
121  * to appropriate functions within the driver.
122  */
123 struct __DriverAPIRec {
124     const __DRIconfig **(*InitScreen) (__DRIscreen * priv);
125 
126     void (*DestroyScreen)(__DRIscreen *driScrnPriv);
127 
128     GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv,
129                               __DRIdrawable *driDrawPriv,
130                               const struct gl_config *glVis,
131                               GLboolean pixmapBuffer);
132 
133     void (*DestroyBuffer)(__DRIdrawable *driDrawPriv);
134 
135     void (*SwapBuffers)(__DRIdrawable *driDrawPriv);
136 
137     __DRIbuffer *(*AllocateBuffer) (__DRIscreen *screenPrivate,
138                                     unsigned int attachment,
139                                     unsigned int format,
140                                     int width, int height);
141 
142     void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
143 
144     void (*CopySubBuffer)(__DRIdrawable *driDrawPriv, int x, int y,
145                           int w, int h);
146 };
147 
148 /**
149  * Per-screen private driver information.
150  */
151 struct __DRIscreenRec {
152     /**
153      * Driver-specific entrypoints provided by the driver's
154      * __DRIDriverVtableExtensionRec.
155      */
156     const struct __DriverAPIRec *driver;
157 
158     /**
159      * Current screen's number
160      */
161     int myNum;
162 
163     /**
164      * File descriptor returned when the kernel device driver is opened.
165      *
166      * Used to:
167      *   - authenticate client to kernel
168      *   - map the frame buffer, SAREA, etc.
169      *   - close the kernel device driver
170      */
171     int fd;
172 
173     /**
174      * Device-dependent private information (not stored in the SAREA).
175      *
176      * This pointer is never touched by the DRI layer.
177      */
178     void *driverPrivate;
179 
180     void *loaderPrivate;
181 
182     int max_gl_core_version;
183     int max_gl_compat_version;
184     int max_gl_es1_version;
185     int max_gl_es2_version;
186 
187     const __DRIextension **extensions;
188 
189     const __DRIswrastLoaderExtension *swrast_loader;
190     const __DRIkopperLoaderExtension *kopper_loader;
191 
192     struct {
193 	/* Flag to indicate that this is a DRI2 screen.  Many of the above
194 	 * fields will not be valid or initializaed in that case. */
195 	const __DRIdri2LoaderExtension *loader;
196 	const __DRIimageLookupExtension *image;
197 	const __DRIuseInvalidateExtension *useInvalidate;
198         const __DRIbackgroundCallableExtension *backgroundCallable;
199     } dri2;
200 
201     struct {
202         const __DRIimageLoaderExtension *loader;
203     } image;
204 
205     struct {
206        const __DRImutableRenderBufferLoaderExtension *loader;
207     } mutableRenderBuffer;
208 
209     driOptionCache optionInfo;
210     driOptionCache optionCache;
211 
212     unsigned int api_mask;
213 };
214 
215 /**
216  * Per-context private driver information.
217  */
218 struct __DRIcontextRec {
219     /**
220      * Device driver's private context data.  This structure is opaque.
221      */
222     void *driverPrivate;
223 
224     /**
225      * The loaders's private context data.  This structure is opaque.
226      */
227     void *loaderPrivate;
228 
229     /**
230      * Pointer to drawable currently bound to this context for drawing.
231      */
232     __DRIdrawable *driDrawablePriv;
233 
234     /**
235      * Pointer to drawable currently bound to this context for reading.
236      */
237     __DRIdrawable *driReadablePriv;
238 
239     /**
240      * Pointer to screen on which this context was created.
241      */
242     __DRIscreen *driScreenPriv;
243 
244     struct {
245 	int draw_stamp;
246 	int read_stamp;
247     } dri2;
248 };
249 
250 /**
251  * Per-drawable private DRI driver information.
252  */
253 struct __DRIdrawableRec {
254     /**
255      * Driver's private drawable information.
256      *
257      * This structure is opaque.
258      */
259     void *driverPrivate;
260 
261     /**
262      * Private data from the loader.  We just hold on to it and pass
263      * it back when calling into loader provided functions.
264      */
265     void *loaderPrivate;
266 
267     /**
268      * Pointer to context to which this drawable is currently bound.
269      */
270     __DRIcontext *driContextPriv;
271 
272     /**
273      * Pointer to screen on which this drawable was created.
274      */
275     __DRIscreen *driScreenPriv;
276 
277     /**
278      * Reference count for number of context's currently bound to this
279      * drawable.
280      *
281      * Once it reaches zero, the drawable can be destroyed.
282      *
283      * \note This behavior will change with GLX 1.3.
284      */
285     int refcount;
286 
287     /**
288      * Last value of the stamp.
289      *
290      * If this differs from the value stored at __DRIdrawable::dri2.stamp,
291      * then the drawable information has been modified by the X server, and the
292      * drawable information (below) should be retrieved from the X server.
293      */
294     unsigned int lastStamp;
295 
296     int w, h;
297 
298     /**
299      * Drawable timestamp.  Increased when the loader calls invalidate.
300      */
301     struct {
302 	unsigned int stamp;
303     } dri2;
304 };
305 
306 extern uint32_t
307 driGLFormatToImageFormat(mesa_format format);
308 
309 extern uint32_t
310 driGLFormatToSizedInternalGLFormat(mesa_format format);
311 
312 extern mesa_format
313 driImageFormatToGLFormat(uint32_t image_format);
314 
315 extern const __DRIimageDriverExtension driImageDriverExtension;
316 
317 #endif /* _DRI_UTIL_H_ */
318