2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
28 * DRI utility functions definitions.
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
35 * Basically, these utility functions take care of some of the dirty details of
36 * screen initialization, context creation, context binding, DRM setup, etc.
38 * These functions are compiled into each DRI driver so libGL.so knows nothing
43 * \author Kevin E. Martin <kevin@precisioninsight.com>
44 * \author Brian Paul <brian@precisioninsight.com>
52 #include <drm_sarea.h>
54 #include "xmlconfig.h"
55 #include "main/glheader.h"
56 #include "main/mtypes.h"
57 #include "GL/internal/dri_interface.h"
59 #define GLX_BAD_CONTEXT 5
64 extern const __DRIcoreExtension driCoreExtension
;
65 extern const __DRIdri2Extension driDRI2Extension
;
66 extern const __DRI2configQueryExtension dri2ConfigQueryExtension
;
69 * Driver callback functions.
71 * Each DRI driver must have one of these structures with all the pointers set
72 * to appropriate functions within the driver.
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
78 struct __DriverAPIRec
{
79 const __DRIconfig
**(*InitScreen
) (__DRIscreen
* priv
);
82 * Screen destruction callback
84 void (*DestroyScreen
)(__DRIscreen
*driScrnPriv
);
87 * Context creation callback
89 GLboolean (*CreateContext
)(gl_api api
,
90 const struct gl_config
*glVis
,
91 __DRIcontext
*driContextPriv
,
92 void *sharedContextPrivate
);
95 * Context destruction callback
97 void (*DestroyContext
)(__DRIcontext
*driContextPriv
);
100 * Buffer (drawable) creation callback
102 GLboolean (*CreateBuffer
)(__DRIscreen
*driScrnPriv
,
103 __DRIdrawable
*driDrawPriv
,
104 const struct gl_config
*glVis
,
105 GLboolean pixmapBuffer
);
108 * Buffer (drawable) destruction callback
110 void (*DestroyBuffer
)(__DRIdrawable
*driDrawPriv
);
113 * Buffer swapping callback
115 void (*SwapBuffers
)(__DRIdrawable
*driDrawPriv
);
118 * Context activation callback
120 GLboolean (*MakeCurrent
)(__DRIcontext
*driContextPriv
,
121 __DRIdrawable
*driDrawPriv
,
122 __DRIdrawable
*driReadPriv
);
125 * Context unbinding callback
127 GLboolean (*UnbindContext
)(__DRIcontext
*driContextPriv
);
130 * These are required if GLX_OML_sync_control is supported.
133 int (*WaitForMSC
)( __DRIdrawable
*priv
, int64_t target_msc
,
134 int64_t divisor
, int64_t remainder
,
136 int (*WaitForSBC
)( __DRIdrawable
*priv
, int64_t target_sbc
,
137 int64_t * msc
, int64_t * sbc
);
139 int64_t (*SwapBuffersMSC
)( __DRIdrawable
*priv
, int64_t target_msc
,
140 int64_t divisor
, int64_t remainder
);
142 void (*CopySubBuffer
)(__DRIdrawable
*driDrawPriv
,
143 int x
, int y
, int w
, int h
);
146 * New version of GetMSC so we can pass drawable data to the low
147 * level DRM driver (e.g. pipe info). Required if
148 * GLX_SGI_video_sync or GLX_OML_sync_control is supported.
150 int (*GetDrawableMSC
) ( __DRIscreen
* priv
,
151 __DRIdrawable
*drawablePrivate
,
156 /* DRI2 Entry point */
157 const __DRIconfig
**(*InitScreen2
) (__DRIscreen
* priv
);
159 __DRIbuffer
*(*AllocateBuffer
) (__DRIscreen
*screenPrivate
,
160 unsigned int attachment
,
162 int width
, int height
);
163 void (*ReleaseBuffer
) (__DRIscreen
*screenPrivate
, __DRIbuffer
*buffer
);
166 extern const struct __DriverAPIRec driDriverAPI
;
170 * Per-drawable private DRI driver information.
172 struct __DRIdrawableRec
{
174 * Kernel drawable handle
176 drm_drawable_t hHWDrawable
;
179 * Driver's private drawable information.
181 * This structure is opaque.
186 * Private data from the loader. We just hold on to it and pass
187 * it back when calling into loader provided functions.
192 * Reference count for number of context's currently bound to this
195 * Once it reaches zero, the drawable can be destroyed.
197 * \note This behavior will change with GLX 1.3.
202 * Index of this drawable information in the SAREA.
207 * Pointer to the "drawable has changed ID" stamp in the SAREA (or
208 * to dri2.stamp if DRI2 is being used).
210 unsigned int *pStamp
;
213 * Last value of the stamp.
215 * If this differs from the value stored at __DRIdrawable::pStamp,
216 * then the drawable information has been modified by the X server, and the
217 * drawable information (below) should be retrieved from the X server.
219 unsigned int lastStamp
;
224 * \name Vertical blank tracking information
225 * Used for waiting on vertical blank events.
229 unsigned int vblFlags
;
233 * \name Monotonic MSC tracking
235 * Low level driver is responsible for updating msc_base and
236 * vblSeq values so that higher level code can calculate
237 * a new msc value or msc target for a WaitMSC call. The new value
239 * msc = msc_base + get_vblank_count() - vblank_base;
241 * And for waiting on a value, core code will use:
242 * actual_target = target_msc - msc_base + vblank_base;
250 * Pointer to context to which this drawable is currently bound.
252 __DRIcontext
*driContextPriv
;
255 * Pointer to screen on which this drawable was created.
257 __DRIscreen
*driScreenPriv
;
260 * Controls swap interval as used by GLX_SGI_swap_control and
261 * GLX_MESA_swap_control.
263 unsigned int swap_interval
;
271 * Per-context private driver information.
273 struct __DRIcontextRec
{
275 * Kernel context handle used to access the device lock.
277 drm_context_t hHWContext
;
280 * Device driver's private context data. This structure is opaque.
285 * Pointer to drawable currently bound to this context for drawing.
287 __DRIdrawable
*driDrawablePriv
;
290 * Pointer to drawable currently bound to this context for reading.
292 __DRIdrawable
*driReadablePriv
;
295 * Pointer to screen on which this context was created.
297 __DRIscreen
*driScreenPriv
;
300 * The loaders's private context data. This structure is opaque.
311 * Per-screen private driver information.
313 struct __DRIscreenRec
{
315 * Current screen's number
320 * Callback functions into the hardware-specific DRI driver code.
322 struct __DriverAPIRec DriverAPI
;
324 const __DRIextension
**extensions
;
326 * DDX / 2D driver version information.
328 __DRIversion ddx_version
;
331 * DRI X extension version information.
333 __DRIversion dri_version
;
336 * DRM (kernel module) version information.
338 __DRIversion drm_version
;
341 * ID used when the client sets the drawable lock.
343 * The X server uses this value to detect if the client has died while
344 * holding the drawable lock.
349 * File descriptor returned when the kernel device driver is opened.
352 * - authenticate client to kernel
353 * - map the frame buffer, SAREA, etc.
354 * - close the kernel device driver
363 * - the device-independent per-drawable and per-context(?) information
368 * \name Direct frame buffer access information
369 * Used for software fallbacks.
382 * \name Device-dependent private information (stored in the SAREA).
384 * This data is accessed by the client driver only.
392 * Device-dependent private information (not stored in the SAREA).
394 * This pointer is never touched by the DRI layer.
402 /* Extensions provided by the loader. */
403 const __DRIgetDrawableInfoExtension
*getDrawableInfo
;
404 const __DRIsystemTimeExtension
*systemTime
;
405 const __DRIdamageExtension
*damage
;
408 /* Flag to indicate that this is a DRI2 screen. Many of the above
409 * fields will not be valid or initializaed in that case. */
411 __DRIdri2LoaderExtension
*loader
;
412 __DRIimageLookupExtension
*image
;
413 __DRIuseInvalidateExtension
*useInvalidate
;
416 /* The lock actually in use, old sarea or DRI2 */
419 driOptionCache optionInfo
;
420 driOptionCache optionCache
;
421 unsigned int api_mask
;
426 dri2InvalidateDrawable(__DRIdrawable
*drawable
);
428 #endif /* _DRI_UTIL_H_ */