888b91df58658f52cf44bd407baecfdad80d1c10
[mesa.git] / include / GL / internal / dri_interface.h
1 /*
2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3 * (C) Copyright IBM Corporation 2004
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file dri_interface.h
28 *
29 * This file contains all the types and functions that define the interface
30 * between a DRI driver and driver loader. Currently, the most common driver
31 * loader is the XFree86 libGL.so. However, other loaders do exist, and in
32 * the future the server-side libglx.a will also be a loader.
33 *
34 * \author Kevin E. Martin <kevin@precisioninsight.com>
35 * \author Ian Romanick <idr@us.ibm.com>
36 */
37
38 #ifndef DRI_INTERFACE_H
39 #define DRI_INTERFACE_H
40
41 #include <GL/internal/glcore.h>
42 #include <drm.h>
43
44 /**
45 * \name DRI interface structures
46 *
47 * The following structures define the interface between the GLX client
48 * side library and the DRI (direct rendering infrastructure).
49 */
50 /*@{*/
51 typedef struct __DRIdisplayRec __DRIdisplay;
52 typedef struct __DRIscreenRec __DRIscreen;
53 typedef struct __DRIcontextRec __DRIcontext;
54 typedef struct __DRIdrawableRec __DRIdrawable;
55 typedef struct __DRIdriverRec __DRIdriver;
56 typedef struct __DRIframebufferRec __DRIframebuffer;
57 typedef struct __DRIversionRec __DRIversion;
58 typedef struct __DRIinterfaceMethodsRec __DRIinterfaceMethods;
59
60 typedef struct __DRIextensionRec __DRIextension;
61 typedef struct __DRIcopySubBufferExtensionRec __DRIcopySubBufferExtension;
62 typedef struct __DRIswapControlExtensionRec __DRIswapControlExtension;
63 typedef struct __DRIallocateExtensionRec __DRIallocateExtension;
64 typedef struct __DRIframeTrackingExtensionRec __DRIframeTrackingExtension;
65 typedef struct __DRImediaStreamCounterExtensionRec __DRImediaStreamCounterExtension;
66 typedef struct __DRItexOffsetExtensionRec __DRItexOffsetExtension;
67 typedef struct __DRItexBufferExtensionRec __DRItexBufferExtension;
68 /*@}*/
69
70
71 /**
72 * Extension struct. Drivers 'inherit' from this struct by embedding
73 * it as the first element in the extension struct. The
74 * __DRIscreen::getExtensions entry point will return a list of these
75 * structs and the loader can use the extensions it knows about by
76 * casting it to a more specific extension and optionally advertising
77 * the GLX extension. See below for examples.
78 *
79 * We never break API in for a DRI extension. If we need to change
80 * the way things work in a non-backwards compatible manner, we
81 * introduce a new extension. During a transition period, we can
82 * leave both the old and the new extension in the driver, which
83 * allows us to move to the new interface without having to update the
84 * loader(s) in lock step.
85 *
86 * However, we can add entry points to an extension over time as long
87 * as we don't break the old ones. As we add entry points to an
88 * extension, we increase the version number. The corresponding
89 * #define can be used to guard code that accesses the new entry
90 * points at compile time and the version field in the extension
91 * struct can be used at run-time to determine how to use the
92 * extension.
93 */
94 struct __DRIextensionRec {
95 const char *name;
96 int version;
97 };
98
99 /**
100 * Used by drivers to indicate support for setting the read drawable.
101 */
102 #define __DRI_READ_DRAWABLE "DRI_ReadDrawable"
103 #define __DRI_READ_DRAWABLE_VERSION 1
104
105 /**
106 * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension.
107 */
108 #define __DRI_COPY_SUB_BUFFER "DRI_CopySubBuffer"
109 #define __DRI_COPY_SUB_BUFFER_VERSION 1
110 struct __DRIcopySubBufferExtensionRec {
111 __DRIextension base;
112 void (*copySubBuffer)(__DRIdrawable *drawable, int x, int y, int w, int h);
113 };
114
115 /**
116 * Used by drivers that implement the GLX_SGI_swap_control or
117 * GLX_MESA_swap_control extension.
118 */
119 #define __DRI_SWAP_CONTROL "DRI_SwapControl"
120 #define __DRI_SWAP_CONTROL_VERSION 1
121 struct __DRIswapControlExtensionRec {
122 __DRIextension base;
123 void (*setSwapInterval)(__DRIdrawable *drawable, unsigned int inteval);
124 unsigned int (*getSwapInterval)(__DRIdrawable *drawable);
125 };
126
127 /**
128 * Used by drivers that implement the GLX_MESA_allocate_memory.
129 */
130 #define __DRI_ALLOCATE "DRI_Allocate"
131 #define __DRI_ALLOCATE_VERSION 1
132 struct __DRIallocateExtensionRec {
133 __DRIextension base;
134
135 void *(*allocateMemory)(__DRIscreen *screen, GLsizei size,
136 GLfloat readfreq, GLfloat writefreq,
137 GLfloat priority);
138
139 void (*freeMemory)(__DRIscreen *screen, GLvoid *pointer);
140
141 GLuint (*memoryOffset)(__DRIscreen *screen, const GLvoid *pointer);
142 };
143
144 /**
145 * Used by drivers that implement the GLX_MESA_swap_frame_usage extension.
146 */
147 #define __DRI_FRAME_TRACKING "DRI_FrameTracking"
148 #define __DRI_FRAME_TRACKING_VERSION 1
149 struct __DRIframeTrackingExtensionRec {
150 __DRIextension base;
151
152 /**
153 * Enable or disable frame usage tracking.
154 *
155 * \since Internal API version 20030317.
156 */
157 int (*frameTracking)(__DRIdrawable *drawable, GLboolean enable);
158
159 /**
160 * Retrieve frame usage information.
161 *
162 * \since Internal API version 20030317.
163 */
164 int (*queryFrameTracking)(__DRIdrawable *drawable,
165 int64_t * sbc, int64_t * missedFrames,
166 float * lastMissedUsage, float * usage);
167 };
168
169
170 /**
171 * Used by drivers that implement the GLX_SGI_video_sync extension.
172 */
173 #define __DRI_MEDIA_STREAM_COUNTER "DRI_MediaStreamCounter"
174 #define __DRI_MEDIA_STREAM_COUNTER_VERSION 1
175 struct __DRImediaStreamCounterExtensionRec {
176 __DRIextension base;
177
178 /**
179 * Wait for the MSC to equal target_msc, or, if that has already passed,
180 * the next time (MSC % divisor) is equal to remainder. If divisor is
181 * zero, the function will return as soon as MSC is greater than or equal
182 * to target_msc.
183 */
184 int (*waitForMSC)(__DRIdrawable *drawable,
185 int64_t target_msc, int64_t divisor, int64_t remainder,
186 int64_t * msc, int64_t * sbc);
187
188 /**
189 * Get the number of vertical refreshes since some point in time before
190 * this function was first called (i.e., system start up).
191 */
192 int (*getDrawableMSC)(__DRIscreen *screen, __DRIdrawable *drawable,
193 int64_t *msc);
194 };
195
196
197 #define __DRI_TEX_OFFSET "DRI_TexOffset"
198 #define __DRI_TEX_OFFSET_VERSION 1
199 struct __DRItexOffsetExtensionRec {
200 __DRIextension base;
201
202 /**
203 * Method to override base texture image with a driver specific 'offset'.
204 * The depth passed in allows e.g. to ignore the alpha channel of texture
205 * images where the non-alpha components don't occupy a whole texel.
206 *
207 * For GLX_EXT_texture_from_pixmap with AIGLX.
208 */
209 void (*setTexOffset)(__DRIcontext *pDRICtx, GLint texname,
210 unsigned long long offset, GLint depth, GLuint pitch);
211 };
212
213
214 #define __DRI_TEX_BUFFER "DRI_TexBuffer"
215 #define __DRI_TEX_BUFFER_VERSION 1
216 struct __DRItexBufferExtensionRec {
217 __DRIextension base;
218
219 /**
220 * Method to override base texture image with a DRM memory manager
221 * buffer object. The depth passed in allows e.g. to ignore the
222 * alpha channel of texture images where the non-alpha components
223 * don't occupy a whole texel.
224 *
225 * For GLX_EXT_texture_from_pixmap with AIGLX.
226 */
227 void (*setTexBuffer)(__DRIcontext *pDRICtx,
228 GLint target, unsigned long handle,
229 GLint cpp, GLuint pitch, GLuint height);
230 };
231
232
233 /**
234 * Macros for building symbol and strings. Standard CPP two step...
235 */
236
237 #define __DRI_REAL_STRINGIFY(x) # x
238 #define __DRI_STRINGIFY(x) __DRI_REAL_STRINGIFY(x)
239 #define __DRI_REAL_MAKE_VERSION(name, version) name ## _ ## version
240 #define __DRI_MAKE_VERSION(name, version) __DRI_REAL_MAKE_VERSION(name, version)
241
242 /**
243 * \name Functions and data provided by the driver.
244 */
245 /*@{*/
246
247 #define __DRI_INTERFACE_VERSION 20070105
248
249 typedef void *(CREATENEWSCREENFUNC)(int scr, __DRIscreen *psc,
250 const __DRIversion * ddx_version, const __DRIversion * dri_version,
251 const __DRIversion * drm_version, const __DRIframebuffer * frame_buffer,
252 void * pSAREA, int fd, int internal_api_version,
253 const __DRIinterfaceMethods * interface,
254 __GLcontextModes ** driver_modes);
255 typedef CREATENEWSCREENFUNC* PFNCREATENEWSCREENFUNC;
256
257 #define __DRI_CREATE_NEW_SCREEN \
258 __DRI_MAKE_VERSION(__driCreateNewScreen, __DRI_INTERFACE_VERSION)
259
260 #define __DRI_CREATE_NEW_SCREEN_STRING \
261 __DRI_STRINGIFY(__DRI_CREATE_NEW_SCREEN)
262
263 extern CREATENEWSCREENFUNC __DRI_CREATE_NEW_SCREEN;
264
265
266 /* DRI2 Entry point */
267
268 typedef void *(__DRI2_CREATE_NEW_SCREEN_FUNC)(int scr, __DRIscreen *psc,
269 const __DRIversion * ddx_version, const __DRIversion * dri_version,
270 const __DRIversion * drm_version, int fd,
271 unsigned int sarea_handle,
272 const __DRIinterfaceMethods * interface,
273 __GLcontextModes ** driver_modes);
274 #define __DRI2_CREATE_NEW_SCREEN \
275 __DRI_MAKE_VERSION(__dri2CreateNewScreen, __DRI_INTERFACE_VERSION)
276
277 #define __DRI2_CREATE_NEW_SCREEN_STRING \
278 __DRI_STRINGIFY(__DRI2_CREATE_NEW_SCREEN)
279
280 extern __DRI2_CREATE_NEW_SCREEN_FUNC __DRI2_CREATE_NEW_SCREEN;
281
282
283 /**
284 * XML document describing the configuration options supported by the
285 * driver.
286 */
287 extern const char __driConfigOptions[];
288
289 /*@}*/
290
291
292 /**
293 * Stored version of some component (i.e., server-side DRI module, kernel-side
294 * DRM, etc.).
295 *
296 * \todo
297 * There are several data structures that explicitly store a major version,
298 * minor version, and patch level. These structures should be modified to
299 * have a \c __DRIversionRec instead.
300 */
301 struct __DRIversionRec {
302 int major; /**< Major version number. */
303 int minor; /**< Minor version number. */
304 int patch; /**< Patch-level. */
305 };
306
307
308 typedef void (*__DRIfuncPtr)(void);
309
310 struct __DRIinterfaceMethodsRec {
311 /**
312 * Create a list of \c __GLcontextModes structures.
313 */
314 __GLcontextModes * (*createContextModes)(unsigned count,
315 size_t minimum_bytes_per_struct);
316
317 /**
318 * Destroy a list of \c __GLcontextModes structures.
319 *
320 * \todo
321 * Determine if the drivers actually need to call this.
322 */
323 void (*destroyContextModes)( __GLcontextModes * modes );
324
325
326 /**
327 * \name Client/server protocol functions.
328 *
329 * These functions implement the DRI client/server protocol for
330 * context and drawable operations. Platforms that do not implement
331 * the wire protocol (e.g., EGL) will implement glorified no-op functions.
332 */
333 /*@{*/
334
335 /**
336 * This function is used to get information about the position, size, and
337 * clip rects of a drawable.
338 */
339 GLboolean (* getDrawableInfo) ( __DRIdrawable *drawable,
340 unsigned int * index, unsigned int * stamp,
341 int * x, int * y, int * width, int * height,
342 int * numClipRects, drm_clip_rect_t ** pClipRects,
343 int * backX, int * backY,
344 int * numBackClipRects, drm_clip_rect_t ** pBackClipRects );
345 /*@}*/
346
347
348 /**
349 * \name Timing related functions.
350 */
351 /*@{*/
352 /**
353 * Get the 64-bit unadjusted system time (UST).
354 */
355 int (*getUST)(int64_t * ust);
356
357 /**
358 * Get the media stream counter (MSC) rate.
359 *
360 * Matching the definition in GLX_OML_sync_control, this function returns
361 * the rate of the "media stream counter". In practical terms, this is
362 * the frame refresh rate of the display.
363 */
364 GLboolean (*getMSCRate)(__DRIdrawable *draw,
365 int32_t * numerator, int32_t * denominator);
366 /*@}*/
367
368 /**
369 * Reports areas of the given drawable which have been modified by the
370 * driver.
371 *
372 * \param drawable which the drawing was done to.
373 * \param rects rectangles affected, with the drawable origin as the
374 * origin.
375 * \param x X offset of the drawable within the screen (used in the
376 * front_buffer case)
377 * \param y Y offset of the drawable within the screen.
378 * \param front_buffer boolean flag for whether the drawing to the
379 * drawable was actually done directly to the front buffer (instead
380 * of backing storage, for example)
381 */
382 void (*reportDamage)(__DRIdrawable *draw,
383 int x, int y,
384 drm_clip_rect_t *rects, int num_rects,
385 GLboolean front_buffer);
386
387 /**
388 * Ping the windowing system to get it to reemit info for the
389 * specified drawable in the DRI2 event buffer.
390 *
391 * \param draw the drawable for which to request info
392 */
393 void (*reemitDrawableInfo)(__DRIdrawable *draw);
394
395 };
396
397
398 /**
399 * Framebuffer information record. Used by libGL to communicate information
400 * about the framebuffer to the driver's \c __driCreateNewScreen function.
401 *
402 * In XFree86, most of this information is derrived from data returned by
403 * calling \c XF86DRIGetDeviceInfo.
404 *
405 * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
406 * __driUtilCreateNewScreen CallCreateNewScreen
407 *
408 * \bug This structure could be better named.
409 */
410 struct __DRIframebufferRec {
411 unsigned char *base; /**< Framebuffer base address in the CPU's
412 * address space. This value is calculated by
413 * calling \c drmMap on the framebuffer handle
414 * returned by \c XF86DRIGetDeviceInfo (or a
415 * similar function).
416 */
417 int size; /**< Framebuffer size, in bytes. */
418 int stride; /**< Number of bytes from one line to the next. */
419 int width; /**< Pixel width of the framebuffer. */
420 int height; /**< Pixel height of the framebuffer. */
421 int dev_priv_size; /**< Size of the driver's dev-priv structure. */
422 void *dev_priv; /**< Pointer to the driver's dev-priv structure. */
423 };
424
425
426 /**
427 * Screen dependent methods. This structure is initialized during the
428 * \c __DRIdisplayRec::createScreen call.
429 */
430 struct __DRIscreenRec {
431 /**
432 * Method to destroy the private DRI screen data.
433 */
434 void (*destroyScreen)(__DRIscreen *screen);
435
436 /**
437 * Method to get screen extensions.
438 */
439 const __DRIextension **(*getExtensions)(__DRIscreen *screen);
440
441 /**
442 * Method to create the private DRI drawable data and initialize the
443 * drawable dependent methods.
444 */
445 void *(*createNewDrawable)(__DRIscreen *screen,
446 const __GLcontextModes *modes,
447 __DRIdrawable *pdraw,
448 drm_drawable_t hwDrawable,
449 int renderType, const int *attrs);
450
451 /**
452 * Opaque pointer to private per screen direct rendering data. \c NULL
453 * if direct rendering is not supported on this screen. Never
454 * dereferenced in libGL.
455 */
456 void *private;
457
458 /**
459 * Method to create the private DRI context data and initialize the
460 * context dependent methods.
461 *
462 * \since Internal API version 20031201.
463 */
464 void * (*createNewContext)(__DRIscreen *screen,
465 const __GLcontextModes *modes,
466 int render_type,
467 __DRIcontext *shared,
468 drm_context_t hwContext, __DRIcontext *pctx);
469 };
470
471 /**
472 * Context dependent methods. This structure is initialized during the
473 * \c __DRIscreenRec::createContext call.
474 */
475 struct __DRIcontextRec {
476 /**
477 * Method to destroy the private DRI context data.
478 */
479 void (*destroyContext)(__DRIcontext *context);
480
481 /**
482 * Opaque pointer to private per context direct rendering data.
483 * \c NULL if direct rendering is not supported on the display or
484 * screen used to create this context. Never dereferenced in libGL.
485 */
486 void *private;
487
488 /**
489 * Method to bind a DRI drawable to a DRI graphics context.
490 *
491 * \since Internal API version 20050727.
492 */
493 GLboolean (*bindContext)(__DRIcontext *ctx,
494 __DRIdrawable *pdraw,
495 __DRIdrawable *pread);
496
497 /**
498 * Method to unbind a DRI drawable from a DRI graphics context.
499 *
500 * \since Internal API version 20050727.
501 */
502 GLboolean (*unbindContext)(__DRIcontext *ctx);
503 };
504
505 /**
506 * Drawable dependent methods. This structure is initialized during the
507 * \c __DRIscreenRec::createDrawable call. \c createDrawable is not called
508 * by libGL at this time. It's currently used via the dri_util.c utility code
509 * instead.
510 */
511 struct __DRIdrawableRec {
512 /**
513 * Method to destroy the private DRI drawable data.
514 */
515 void (*destroyDrawable)(__DRIdrawable *drawable);
516
517 /**
518 * Method to swap the front and back buffers.
519 */
520 void (*swapBuffers)(__DRIdrawable *drawable);
521
522 /**
523 * Opaque pointer to private per drawable direct rendering data.
524 * \c NULL if direct rendering is not supported on the display or
525 * screen used to create this drawable. Never dereferenced in libGL.
526 */
527 void *private;
528 };
529
530 #endif