i965: Build the driver into a shared mesa_dri_drivers.so .
[mesa.git] / src / mesa / drivers / dri / common / dri_util.c
1 /*
2 * (C) Copyright IBM Corporation 2002, 2004
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 "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file dri_util.c
27 * DRI utility functions.
28 *
29 * This module acts as glue between GLX and the actual hardware driver. A DRI
30 * driver doesn't really \e have to use any of this - it's optional. But, some
31 * useful stuff is done here that otherwise would have to be duplicated in most
32 * drivers.
33 *
34 * Basically, these utility functions take care of some of the dirty details of
35 * screen initialization, context creation, context binding, DRM setup, etc.
36 *
37 * These functions are compiled into each DRI driver so libGL.so knows nothing
38 * about them.
39 */
40
41
42 #include <stdbool.h>
43 #ifndef __NOT_HAVE_DRM_H
44 #include <xf86drm.h>
45 #endif
46 #include "dri_util.h"
47 #include "utils.h"
48 #include "xmlpool.h"
49 #include "../glsl/glsl_parser_extras.h"
50 #include "main/mtypes.h"
51 #include "main/version.h"
52 #include "main/macros.h"
53
54 PUBLIC const char __dri2ConfigOptions[] =
55 DRI_CONF_BEGIN
56 DRI_CONF_SECTION_PERFORMANCE
57 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1)
58 DRI_CONF_SECTION_END
59 DRI_CONF_END;
60
61 /*****************************************************************/
62 /** \name Screen handling functions */
63 /*****************************************************************/
64 /*@{*/
65
66 static void
67 setupLoaderExtensions(__DRIscreen *psp,
68 const __DRIextension **extensions)
69 {
70 int i;
71
72 for (i = 0; extensions[i]; i++) {
73 if (strcmp(extensions[i]->name, __DRI_DRI2_LOADER) == 0)
74 psp->dri2.loader = (__DRIdri2LoaderExtension *) extensions[i];
75 if (strcmp(extensions[i]->name, __DRI_IMAGE_LOOKUP) == 0)
76 psp->dri2.image = (__DRIimageLookupExtension *) extensions[i];
77 if (strcmp(extensions[i]->name, __DRI_USE_INVALIDATE) == 0)
78 psp->dri2.useInvalidate = (__DRIuseInvalidateExtension *) extensions[i];
79 if (strcmp(extensions[i]->name, __DRI_SWRAST_LOADER) == 0)
80 psp->swrast_loader = (__DRIswrastLoaderExtension *) extensions[i];
81 }
82 }
83
84 /**
85 * This pointer determines which driver API we'll use in the case of the
86 * loader not passing us an explicit driver extensions list (that would,
87 * itself, contain a pointer to a driver API.)
88 *
89 * A driver's driDriverGetExtensions_drivername() can update this pointer to
90 * what it's returning, and a loader that is ignorant of createNewScreen2()
91 * will get the correct driver screen created, as long as no other
92 * driDriverGetExtensions() happened in between the first one and the
93 * createNewScreen().
94 *
95 * This allows the X Server to not require the significant dri_interface.h
96 * updates for doing createNewScreen2(), which would discourage backporting of
97 * the X Server patches to support the new loader interface.
98 */
99 const struct __DriverAPIRec *globalDriverAPI = &driDriverAPI;
100
101 /**
102 * This is the first entrypoint in the driver called by the DRI driver loader
103 * after dlopen()ing it.
104 *
105 * It's used to create global state for the driver across contexts on the same
106 * Display.
107 */
108 static __DRIscreen *
109 dri2CreateNewScreen2(int scrn, int fd,
110 const __DRIextension **extensions,
111 const __DRIextension **driver_extensions,
112 const __DRIconfig ***driver_configs, void *data)
113 {
114 static const __DRIextension *emptyExtensionList[] = { NULL };
115 __DRIscreen *psp;
116
117 psp = calloc(1, sizeof(*psp));
118 if (!psp)
119 return NULL;
120
121 /* By default, use the global driDriverAPI symbol (non-megadrivers). */
122 psp->driver = globalDriverAPI;
123
124 /* If the driver exposes its vtable through its extensions list
125 * (megadrivers), use that instead.
126 */
127 if (driver_extensions) {
128 for (int i = 0; driver_extensions[i]; i++) {
129 if (strcmp(driver_extensions[i]->name, __DRI_DRIVER_VTABLE) == 0) {
130 psp->driver =
131 ((__DRIDriverVtableExtension *)driver_extensions[i])->vtable;
132 }
133 }
134 }
135
136 setupLoaderExtensions(psp, extensions);
137
138 #ifndef __NOT_HAVE_DRM_H
139 if (fd != -1) {
140 drmVersionPtr version = drmGetVersion(fd);
141 if (version) {
142 psp->drm_version.major = version->version_major;
143 psp->drm_version.minor = version->version_minor;
144 psp->drm_version.patch = version->version_patchlevel;
145 drmFreeVersion(version);
146 }
147 }
148 #endif
149
150 psp->loaderPrivate = data;
151
152 psp->extensions = emptyExtensionList;
153 psp->fd = fd;
154 psp->myNum = scrn;
155
156 *driver_configs = psp->driver->InitScreen(psp);
157 if (*driver_configs == NULL) {
158 free(psp);
159 return NULL;
160 }
161
162 int gl_version_override = _mesa_get_gl_version_override();
163 if (gl_version_override >= 31) {
164 psp->max_gl_core_version = MAX2(psp->max_gl_core_version,
165 gl_version_override);
166 } else {
167 psp->max_gl_compat_version = MAX2(psp->max_gl_compat_version,
168 gl_version_override);
169 }
170
171 psp->api_mask = (1 << __DRI_API_OPENGL);
172 if (psp->max_gl_core_version > 0)
173 psp->api_mask |= (1 << __DRI_API_OPENGL_CORE);
174 if (psp->max_gl_es1_version > 0)
175 psp->api_mask |= (1 << __DRI_API_GLES);
176 if (psp->max_gl_es2_version > 0)
177 psp->api_mask |= (1 << __DRI_API_GLES2);
178 if (psp->max_gl_es2_version >= 30)
179 psp->api_mask |= (1 << __DRI_API_GLES3);
180
181 driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions);
182 driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, "dri2");
183
184
185 return psp;
186 }
187
188 static __DRIscreen *
189 dri2CreateNewScreen(int scrn, int fd,
190 const __DRIextension **extensions,
191 const __DRIconfig ***driver_configs, void *data)
192 {
193 return dri2CreateNewScreen2(scrn, fd, extensions, NULL,
194 driver_configs, data);
195 }
196
197 /** swrast driver createNewScreen entrypoint. */
198 static __DRIscreen *
199 driSWRastCreateNewScreen(int scrn, const __DRIextension **extensions,
200 const __DRIconfig ***driver_configs, void *data)
201 {
202 return dri2CreateNewScreen2(scrn, -1, extensions, NULL,
203 driver_configs, data);
204 }
205
206 static __DRIscreen *
207 driSWRastCreateNewScreen2(int scrn, const __DRIextension **extensions,
208 const __DRIextension **driver_extensions,
209 const __DRIconfig ***driver_configs, void *data)
210 {
211 return dri2CreateNewScreen2(scrn, -1, extensions, driver_extensions,
212 driver_configs, data);
213 }
214
215 /**
216 * Destroy the per-screen private information.
217 *
218 * \internal
219 * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
220 * drmClose(), and finally frees \p screenPrivate.
221 */
222 static void driDestroyScreen(__DRIscreen *psp)
223 {
224 if (psp) {
225 /* No interaction with the X-server is possible at this point. This
226 * routine is called after XCloseDisplay, so there is no protocol
227 * stream open to the X-server anymore.
228 */
229
230 _mesa_destroy_shader_compiler();
231
232 psp->driver->DestroyScreen(psp);
233
234 driDestroyOptionCache(&psp->optionCache);
235 driDestroyOptionInfo(&psp->optionInfo);
236
237 free(psp);
238 }
239 }
240
241 static const __DRIextension **driGetExtensions(__DRIscreen *psp)
242 {
243 return psp->extensions;
244 }
245
246 /*@}*/
247
248
249 static bool
250 validate_context_version(__DRIscreen *screen,
251 int mesa_api,
252 unsigned major_version,
253 unsigned minor_version,
254 unsigned *dri_ctx_error)
255 {
256 unsigned req_version = 10 * major_version + minor_version;
257 unsigned max_version = 0;
258
259 switch (mesa_api) {
260 case API_OPENGL_COMPAT:
261 max_version = screen->max_gl_compat_version;
262 break;
263 case API_OPENGL_CORE:
264 max_version = screen->max_gl_core_version;
265 break;
266 case API_OPENGLES:
267 max_version = screen->max_gl_es1_version;
268 break;
269 case API_OPENGLES2:
270 max_version = screen->max_gl_es2_version;
271 break;
272 default:
273 max_version = 0;
274 break;
275 }
276
277 if (max_version == 0) {
278 *dri_ctx_error = __DRI_CTX_ERROR_BAD_API;
279 return false;
280 } else if (req_version > max_version) {
281 *dri_ctx_error = __DRI_CTX_ERROR_BAD_VERSION;
282 return false;
283 }
284
285 return true;
286 }
287
288 /*****************************************************************/
289 /** \name Context handling functions */
290 /*****************************************************************/
291 /*@{*/
292
293 static __DRIcontext *
294 dri2CreateContextAttribs(__DRIscreen *screen, int api,
295 const __DRIconfig *config,
296 __DRIcontext *shared,
297 unsigned num_attribs,
298 const uint32_t *attribs,
299 unsigned *error,
300 void *data)
301 {
302 __DRIcontext *context;
303 const struct gl_config *modes = (config != NULL) ? &config->modes : NULL;
304 void *shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
305 gl_api mesa_api;
306 unsigned major_version = 1;
307 unsigned minor_version = 0;
308 uint32_t flags = 0;
309
310 assert((num_attribs == 0) || (attribs != NULL));
311
312 if (!(screen->api_mask & (1 << api))) {
313 *error = __DRI_CTX_ERROR_BAD_API;
314 return NULL;
315 }
316
317 switch (api) {
318 case __DRI_API_OPENGL:
319 mesa_api = API_OPENGL_COMPAT;
320 break;
321 case __DRI_API_GLES:
322 mesa_api = API_OPENGLES;
323 break;
324 case __DRI_API_GLES2:
325 case __DRI_API_GLES3:
326 mesa_api = API_OPENGLES2;
327 break;
328 case __DRI_API_OPENGL_CORE:
329 mesa_api = API_OPENGL_CORE;
330 break;
331 default:
332 *error = __DRI_CTX_ERROR_BAD_API;
333 return NULL;
334 }
335
336 for (unsigned i = 0; i < num_attribs; i++) {
337 switch (attribs[i * 2]) {
338 case __DRI_CTX_ATTRIB_MAJOR_VERSION:
339 major_version = attribs[i * 2 + 1];
340 break;
341 case __DRI_CTX_ATTRIB_MINOR_VERSION:
342 minor_version = attribs[i * 2 + 1];
343 break;
344 case __DRI_CTX_ATTRIB_FLAGS:
345 flags = attribs[i * 2 + 1];
346 break;
347 default:
348 /* We can't create a context that satisfies the requirements of an
349 * attribute that we don't understand. Return failure.
350 */
351 assert(!"Should not get here.");
352 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
353 return NULL;
354 }
355 }
356
357 /* Mesa does not support the GL_ARB_compatibilty extension or the
358 * compatibility profile. This means that we treat a API_OPENGL_COMPAT 3.1 as
359 * API_OPENGL_CORE and reject API_OPENGL_COMPAT 3.2+.
360 */
361 if (mesa_api == API_OPENGL_COMPAT && major_version == 3 && minor_version == 1)
362 mesa_api = API_OPENGL_CORE;
363
364 if (mesa_api == API_OPENGL_COMPAT
365 && ((major_version > 3)
366 || (major_version == 3 && minor_version >= 2))) {
367 *error = __DRI_CTX_ERROR_BAD_API;
368 return NULL;
369 }
370
371 /* The EGL_KHR_create_context spec says:
372 *
373 * "Flags are only defined for OpenGL context creation, and specifying
374 * a flags value other than zero for other types of contexts,
375 * including OpenGL ES contexts, will generate an error."
376 *
377 * The GLX_EXT_create_context_es2_profile specification doesn't say
378 * anything specific about this case. However, none of the known flags
379 * have any meaning in an ES context, so this seems safe.
380 */
381 if (mesa_api != API_OPENGL_COMPAT
382 && mesa_api != API_OPENGL_CORE
383 && flags != 0) {
384 *error = __DRI_CTX_ERROR_BAD_FLAG;
385 return NULL;
386 }
387
388 /* There are no forward-compatible contexts before OpenGL 3.0. The
389 * GLX_ARB_create_context spec says:
390 *
391 * "Forward-compatible contexts are defined only for OpenGL versions
392 * 3.0 and later."
393 *
394 * Forward-looking contexts are supported by silently converting the
395 * requested API to API_OPENGL_CORE.
396 *
397 * In Mesa, a debug context is the same as a regular context.
398 */
399 if ((flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
400 mesa_api = API_OPENGL_CORE;
401 }
402
403 if ((flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE))
404 != 0) {
405 *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
406 return NULL;
407 }
408
409 if (!validate_context_version(screen, mesa_api,
410 major_version, minor_version, error))
411 return NULL;
412
413 context = calloc(1, sizeof *context);
414 if (!context) {
415 *error = __DRI_CTX_ERROR_NO_MEMORY;
416 return NULL;
417 }
418
419 context->loaderPrivate = data;
420
421 context->driScreenPriv = screen;
422 context->driDrawablePriv = NULL;
423 context->driReadablePriv = NULL;
424
425 if (!screen->driver->CreateContext(mesa_api, modes, context,
426 major_version, minor_version,
427 flags, error, shareCtx) ) {
428 free(context);
429 return NULL;
430 }
431
432 struct gl_context *ctx = context->driverPrivate;
433 if ((flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0)
434 ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
435 if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) {
436 ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT;
437 ctx->Debug.DebugOutput = GL_TRUE;
438 }
439
440 *error = __DRI_CTX_ERROR_SUCCESS;
441 return context;
442 }
443
444 static __DRIcontext *
445 dri2CreateNewContextForAPI(__DRIscreen *screen, int api,
446 const __DRIconfig *config,
447 __DRIcontext *shared, void *data)
448 {
449 unsigned error;
450
451 return dri2CreateContextAttribs(screen, api, config, shared, 0, NULL,
452 &error, data);
453 }
454
455 static __DRIcontext *
456 dri2CreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
457 __DRIcontext *shared, void *data)
458 {
459 return dri2CreateNewContextForAPI(screen, __DRI_API_OPENGL,
460 config, shared, data);
461 }
462
463 /**
464 * Destroy the per-context private information.
465 *
466 * \internal
467 * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
468 * drmDestroyContext(), and finally frees \p contextPrivate.
469 */
470 static void
471 driDestroyContext(__DRIcontext *pcp)
472 {
473 if (pcp) {
474 pcp->driScreenPriv->driver->DestroyContext(pcp);
475 free(pcp);
476 }
477 }
478
479 static int
480 driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask)
481 {
482 (void) dest;
483 (void) src;
484 (void) mask;
485 return GL_FALSE;
486 }
487
488 /*@}*/
489
490
491 /*****************************************************************/
492 /** \name Context (un)binding functions */
493 /*****************************************************************/
494 /*@{*/
495
496 static void dri_get_drawable(__DRIdrawable *pdp);
497 static void dri_put_drawable(__DRIdrawable *pdp);
498
499 /**
500 * This function takes both a read buffer and a draw buffer. This is needed
501 * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
502 * function.
503 */
504 static int driBindContext(__DRIcontext *pcp,
505 __DRIdrawable *pdp,
506 __DRIdrawable *prp)
507 {
508 /*
509 ** Assume error checking is done properly in glXMakeCurrent before
510 ** calling driUnbindContext.
511 */
512
513 if (!pcp)
514 return GL_FALSE;
515
516 /* Bind the drawable to the context */
517 pcp->driDrawablePriv = pdp;
518 pcp->driReadablePriv = prp;
519 if (pdp) {
520 pdp->driContextPriv = pcp;
521 dri_get_drawable(pdp);
522 }
523 if (prp && pdp != prp) {
524 dri_get_drawable(prp);
525 }
526
527 return pcp->driScreenPriv->driver->MakeCurrent(pcp, pdp, prp);
528 }
529
530 /**
531 * Unbind context.
532 *
533 * \param scrn the screen.
534 * \param gc context.
535 *
536 * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
537 *
538 * \internal
539 * This function calls __DriverAPIRec::UnbindContext, and then decrements
540 * __DRIdrawableRec::refcount which must be non-zero for a successful
541 * return.
542 *
543 * While casting the opaque private pointers associated with the parameters
544 * into their respective real types it also assures they are not \c NULL.
545 */
546 static int driUnbindContext(__DRIcontext *pcp)
547 {
548 __DRIdrawable *pdp;
549 __DRIdrawable *prp;
550
551 /*
552 ** Assume error checking is done properly in glXMakeCurrent before
553 ** calling driUnbindContext.
554 */
555
556 if (pcp == NULL)
557 return GL_FALSE;
558
559 pdp = pcp->driDrawablePriv;
560 prp = pcp->driReadablePriv;
561
562 /* already unbound */
563 if (!pdp && !prp)
564 return GL_TRUE;
565
566 pcp->driScreenPriv->driver->UnbindContext(pcp);
567
568 assert(pdp);
569 if (pdp->refcount == 0) {
570 /* ERROR!!! */
571 return GL_FALSE;
572 }
573
574 dri_put_drawable(pdp);
575
576 if (prp != pdp) {
577 if (prp->refcount == 0) {
578 /* ERROR!!! */
579 return GL_FALSE;
580 }
581
582 dri_put_drawable(prp);
583 }
584
585 pcp->driDrawablePriv = NULL;
586 pcp->driReadablePriv = NULL;
587
588 return GL_TRUE;
589 }
590
591 /*@}*/
592
593
594 static void dri_get_drawable(__DRIdrawable *pdp)
595 {
596 pdp->refcount++;
597 }
598
599 static void dri_put_drawable(__DRIdrawable *pdp)
600 {
601 if (pdp) {
602 pdp->refcount--;
603 if (pdp->refcount)
604 return;
605
606 pdp->driScreenPriv->driver->DestroyBuffer(pdp);
607 free(pdp);
608 }
609 }
610
611 static __DRIdrawable *
612 dri2CreateNewDrawable(__DRIscreen *screen,
613 const __DRIconfig *config,
614 void *data)
615 {
616 __DRIdrawable *pdraw;
617
618 pdraw = malloc(sizeof *pdraw);
619 if (!pdraw)
620 return NULL;
621
622 pdraw->loaderPrivate = data;
623
624 pdraw->driScreenPriv = screen;
625 pdraw->driContextPriv = NULL;
626 pdraw->refcount = 0;
627 pdraw->lastStamp = 0;
628 pdraw->w = 0;
629 pdraw->h = 0;
630
631 dri_get_drawable(pdraw);
632
633 if (!screen->driver->CreateBuffer(screen, pdraw, &config->modes,
634 GL_FALSE)) {
635 free(pdraw);
636 return NULL;
637 }
638
639 pdraw->dri2.stamp = pdraw->lastStamp + 1;
640
641 return pdraw;
642 }
643
644 static void
645 driDestroyDrawable(__DRIdrawable *pdp)
646 {
647 dri_put_drawable(pdp);
648 }
649
650 static __DRIbuffer *
651 dri2AllocateBuffer(__DRIscreen *screen,
652 unsigned int attachment, unsigned int format,
653 int width, int height)
654 {
655 return screen->driver->AllocateBuffer(screen, attachment, format,
656 width, height);
657 }
658
659 static void
660 dri2ReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
661 {
662 screen->driver->ReleaseBuffer(screen, buffer);
663 }
664
665
666 static int
667 dri2ConfigQueryb(__DRIscreen *screen, const char *var, GLboolean *val)
668 {
669 if (!driCheckOption(&screen->optionCache, var, DRI_BOOL))
670 return -1;
671
672 *val = driQueryOptionb(&screen->optionCache, var);
673
674 return 0;
675 }
676
677 static int
678 dri2ConfigQueryi(__DRIscreen *screen, const char *var, GLint *val)
679 {
680 if (!driCheckOption(&screen->optionCache, var, DRI_INT) &&
681 !driCheckOption(&screen->optionCache, var, DRI_ENUM))
682 return -1;
683
684 *val = driQueryOptioni(&screen->optionCache, var);
685
686 return 0;
687 }
688
689 static int
690 dri2ConfigQueryf(__DRIscreen *screen, const char *var, GLfloat *val)
691 {
692 if (!driCheckOption(&screen->optionCache, var, DRI_FLOAT))
693 return -1;
694
695 *val = driQueryOptionf(&screen->optionCache, var);
696
697 return 0;
698 }
699
700 static unsigned int
701 dri2GetAPIMask(__DRIscreen *screen)
702 {
703 return screen->api_mask;
704 }
705
706 /**
707 * swrast swapbuffers entrypoint.
708 *
709 * DRI2 implements this inside the loader with only flushes handled by the
710 * driver.
711 */
712 static void
713 driSwapBuffers(__DRIdrawable *pdp)
714 {
715 assert(pdp->driScreenPriv->swrast_loader);
716
717 pdp->driScreenPriv->driver->SwapBuffers(pdp);
718 }
719
720 /** Core interface */
721 const __DRIcoreExtension driCoreExtension = {
722 .base = { __DRI_CORE, __DRI_CORE_VERSION },
723
724 .createNewScreen = NULL,
725 .destroyScreen = driDestroyScreen,
726 .getExtensions = driGetExtensions,
727 .getConfigAttrib = driGetConfigAttrib,
728 .indexConfigAttrib = driIndexConfigAttrib,
729 .createNewDrawable = NULL,
730 .destroyDrawable = driDestroyDrawable,
731 .swapBuffers = driSwapBuffers, /* swrast */
732 .createNewContext = dri2CreateNewContext, /* swrast */
733 .copyContext = driCopyContext,
734 .destroyContext = driDestroyContext,
735 .bindContext = driBindContext,
736 .unbindContext = driUnbindContext
737 };
738
739 /** DRI2 interface */
740 const __DRIdri2Extension driDRI2Extension = {
741 .base = { __DRI_DRI2, 4 },
742
743 .createNewScreen = dri2CreateNewScreen,
744 .createNewDrawable = dri2CreateNewDrawable,
745 .createNewContext = dri2CreateNewContext,
746 .getAPIMask = dri2GetAPIMask,
747 .createNewContextForAPI = dri2CreateNewContextForAPI,
748 .allocateBuffer = dri2AllocateBuffer,
749 .releaseBuffer = dri2ReleaseBuffer,
750 .createContextAttribs = dri2CreateContextAttribs,
751 .createNewScreen2 = dri2CreateNewScreen2,
752 };
753
754 const __DRIswrastExtension driSWRastExtension = {
755 { __DRI_SWRAST, 4 },
756 driSWRastCreateNewScreen,
757 dri2CreateNewDrawable,
758 dri2CreateNewContextForAPI,
759 dri2CreateContextAttribs,
760 driSWRastCreateNewScreen2,
761 };
762
763 const __DRI2configQueryExtension dri2ConfigQueryExtension = {
764 .base = { __DRI2_CONFIG_QUERY, __DRI2_CONFIG_QUERY_VERSION },
765
766 .configQueryb = dri2ConfigQueryb,
767 .configQueryi = dri2ConfigQueryi,
768 .configQueryf = dri2ConfigQueryf,
769 };
770
771 void
772 dri2InvalidateDrawable(__DRIdrawable *drawable)
773 {
774 drawable->dri2.stamp++;
775 }
776
777 /**
778 * Check that the gl_framebuffer associated with dPriv is the right size.
779 * Resize the gl_framebuffer if needed.
780 * It's expected that the dPriv->driverPrivate member points to a
781 * gl_framebuffer object.
782 */
783 void
784 driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv)
785 {
786 struct gl_framebuffer *fb = (struct gl_framebuffer *) dPriv->driverPrivate;
787 if (fb && (dPriv->w != fb->Width || dPriv->h != fb->Height)) {
788 ctx->Driver.ResizeBuffers(ctx, fb, dPriv->w, dPriv->h);
789 /* if the driver needs the hw lock for ResizeBuffers, the drawable
790 might have changed again by now */
791 assert(fb->Width == dPriv->w);
792 assert(fb->Height == dPriv->h);
793 }
794 }