OSDN Git Service

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