dri: Pass in the dlsym()ed driver extension to screen creation.
[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 is the first entrypoint in the driver called by the DRI driver loader
86 * after dlopen()ing it.
87 *
88 * It's used to create global state for the driver across contexts on the same
89 * Display.
90 */
91 static __DRIscreen *
92 dri2CreateNewScreen2(int scrn, int fd,
93 const __DRIextension **extensions,
94 const __DRIextension **driver_extensions,
95 const __DRIconfig ***driver_configs, void *data)
96 {
97 static const __DRIextension *emptyExtensionList[] = { NULL };
98 __DRIscreen *psp;
99
100 psp = calloc(1, sizeof(*psp));
101 if (!psp)
102 return NULL;
103
104 psp->driver = &driDriverAPI;
105
106 setupLoaderExtensions(psp, extensions);
107
108 #ifndef __NOT_HAVE_DRM_H
109 if (fd != -1) {
110 drmVersionPtr version = drmGetVersion(fd);
111 if (version) {
112 psp->drm_version.major = version->version_major;
113 psp->drm_version.minor = version->version_minor;
114 psp->drm_version.patch = version->version_patchlevel;
115 drmFreeVersion(version);
116 }
117 }
118 #endif
119
120 psp->loaderPrivate = data;
121
122 psp->extensions = emptyExtensionList;
123 psp->fd = fd;
124 psp->myNum = scrn;
125
126 *driver_configs = psp->driver->InitScreen(psp);
127 if (*driver_configs == NULL) {
128 free(psp);
129 return NULL;
130 }
131
132 int gl_version_override = _mesa_get_gl_version_override();
133 if (gl_version_override >= 31) {
134 psp->max_gl_core_version = MAX2(psp->max_gl_core_version,
135 gl_version_override);
136 } else {
137 psp->max_gl_compat_version = MAX2(psp->max_gl_compat_version,
138 gl_version_override);
139 }
140
141 psp->api_mask = (1 << __DRI_API_OPENGL);
142 if (psp->max_gl_core_version > 0)
143 psp->api_mask |= (1 << __DRI_API_OPENGL_CORE);
144 if (psp->max_gl_es1_version > 0)
145 psp->api_mask |= (1 << __DRI_API_GLES);
146 if (psp->max_gl_es2_version > 0)
147 psp->api_mask |= (1 << __DRI_API_GLES2);
148 if (psp->max_gl_es2_version >= 30)
149 psp->api_mask |= (1 << __DRI_API_GLES3);
150
151 driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions);
152 driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, "dri2");
153
154
155 return psp;
156 }
157
158 static __DRIscreen *
159 dri2CreateNewScreen(int scrn, int fd,
160 const __DRIextension **extensions,
161 const __DRIconfig ***driver_configs, void *data)
162 {
163 return dri2CreateNewScreen2(scrn, fd, extensions, NULL,
164 driver_configs, data);
165 }
166
167 /** swrast driver createNewScreen entrypoint. */
168 static __DRIscreen *
169 driSWRastCreateNewScreen(int scrn, const __DRIextension **extensions,
170 const __DRIconfig ***driver_configs, void *data)
171 {
172 return dri2CreateNewScreen2(scrn, -1, extensions, NULL,
173 driver_configs, data);
174 }
175
176 static __DRIscreen *
177 driSWRastCreateNewScreen2(int scrn, const __DRIextension **extensions,
178 const __DRIextension **driver_extensions,
179 const __DRIconfig ***driver_configs, void *data)
180 {
181 return dri2CreateNewScreen2(scrn, -1, extensions, driver_extensions,
182 driver_configs, data);
183 }
184
185 /**
186 * Destroy the per-screen private information.
187 *
188 * \internal
189 * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
190 * drmClose(), and finally frees \p screenPrivate.
191 */
192 static void driDestroyScreen(__DRIscreen *psp)
193 {
194 if (psp) {
195 /* No interaction with the X-server is possible at this point. This
196 * routine is called after XCloseDisplay, so there is no protocol
197 * stream open to the X-server anymore.
198 */
199
200 _mesa_destroy_shader_compiler();
201
202 psp->driver->DestroyScreen(psp);
203
204 driDestroyOptionCache(&psp->optionCache);
205 driDestroyOptionInfo(&psp->optionInfo);
206
207 free(psp);
208 }
209 }
210
211 static const __DRIextension **driGetExtensions(__DRIscreen *psp)
212 {
213 return psp->extensions;
214 }
215
216 /*@}*/
217
218
219 static bool
220 validate_context_version(__DRIscreen *screen,
221 int mesa_api,
222 unsigned major_version,
223 unsigned minor_version,
224 unsigned *dri_ctx_error)
225 {
226 unsigned req_version = 10 * major_version + minor_version;
227 unsigned max_version = 0;
228
229 switch (mesa_api) {
230 case API_OPENGL_COMPAT:
231 max_version = screen->max_gl_compat_version;
232 break;
233 case API_OPENGL_CORE:
234 max_version = screen->max_gl_core_version;
235 break;
236 case API_OPENGLES:
237 max_version = screen->max_gl_es1_version;
238 break;
239 case API_OPENGLES2:
240 max_version = screen->max_gl_es2_version;
241 break;
242 default:
243 max_version = 0;
244 break;
245 }
246
247 if (max_version == 0) {
248 *dri_ctx_error = __DRI_CTX_ERROR_BAD_API;
249 return false;
250 } else if (req_version > max_version) {
251 *dri_ctx_error = __DRI_CTX_ERROR_BAD_VERSION;
252 return false;
253 }
254
255 return true;
256 }
257
258 /*****************************************************************/
259 /** \name Context handling functions */
260 /*****************************************************************/
261 /*@{*/
262
263 static __DRIcontext *
264 dri2CreateContextAttribs(__DRIscreen *screen, int api,
265 const __DRIconfig *config,
266 __DRIcontext *shared,
267 unsigned num_attribs,
268 const uint32_t *attribs,
269 unsigned *error,
270 void *data)
271 {
272 __DRIcontext *context;
273 const struct gl_config *modes = (config != NULL) ? &config->modes : NULL;
274 void *shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
275 gl_api mesa_api;
276 unsigned major_version = 1;
277 unsigned minor_version = 0;
278 uint32_t flags = 0;
279
280 assert((num_attribs == 0) || (attribs != NULL));
281
282 if (!(screen->api_mask & (1 << api))) {
283 *error = __DRI_CTX_ERROR_BAD_API;
284 return NULL;
285 }
286
287 switch (api) {
288 case __DRI_API_OPENGL:
289 mesa_api = API_OPENGL_COMPAT;
290 break;
291 case __DRI_API_GLES:
292 mesa_api = API_OPENGLES;
293 break;
294 case __DRI_API_GLES2:
295 case __DRI_API_GLES3:
296 mesa_api = API_OPENGLES2;
297 break;
298 case __DRI_API_OPENGL_CORE:
299 mesa_api = API_OPENGL_CORE;
300 break;
301 default:
302 *error = __DRI_CTX_ERROR_BAD_API;
303 return NULL;
304 }
305
306 for (unsigned i = 0; i < num_attribs; i++) {
307 switch (attribs[i * 2]) {
308 case __DRI_CTX_ATTRIB_MAJOR_VERSION:
309 major_version = attribs[i * 2 + 1];
310 break;
311 case __DRI_CTX_ATTRIB_MINOR_VERSION:
312 minor_version = attribs[i * 2 + 1];
313 break;
314 case __DRI_CTX_ATTRIB_FLAGS:
315 flags = attribs[i * 2 + 1];
316 break;
317 default:
318 /* We can't create a context that satisfies the requirements of an
319 * attribute that we don't understand. Return failure.
320 */
321 assert(!"Should not get here.");
322 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
323 return NULL;
324 }
325 }
326
327 /* Mesa does not support the GL_ARB_compatibilty extension or the
328 * compatibility profile. This means that we treat a API_OPENGL_COMPAT 3.1 as
329 * API_OPENGL_CORE and reject API_OPENGL_COMPAT 3.2+.
330 */
331 if (mesa_api == API_OPENGL_COMPAT && major_version == 3 && minor_version == 1)
332 mesa_api = API_OPENGL_CORE;
333
334 if (mesa_api == API_OPENGL_COMPAT
335 && ((major_version > 3)
336 || (major_version == 3 && minor_version >= 2))) {
337 *error = __DRI_CTX_ERROR_BAD_API;
338 return NULL;
339 }
340
341 /* The EGL_KHR_create_context spec says:
342 *
343 * "Flags are only defined for OpenGL context creation, and specifying
344 * a flags value other than zero for other types of contexts,
345 * including OpenGL ES contexts, will generate an error."
346 *
347 * The GLX_EXT_create_context_es2_profile specification doesn't say
348 * anything specific about this case. However, none of the known flags
349 * have any meaning in an ES context, so this seems safe.
350 */
351 if (mesa_api != API_OPENGL_COMPAT
352 && mesa_api != API_OPENGL_CORE
353 && flags != 0) {
354 *error = __DRI_CTX_ERROR_BAD_FLAG;
355 return NULL;
356 }
357
358 /* There are no forward-compatible contexts before OpenGL 3.0. The
359 * GLX_ARB_create_context spec says:
360 *
361 * "Forward-compatible contexts are defined only for OpenGL versions
362 * 3.0 and later."
363 *
364 * Forward-looking contexts are supported by silently converting the
365 * requested API to API_OPENGL_CORE.
366 *
367 * In Mesa, a debug context is the same as a regular context.
368 */
369 if ((flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
370 mesa_api = API_OPENGL_CORE;
371 }
372
373 if ((flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE))
374 != 0) {
375 *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
376 return NULL;
377 }
378
379 if (!validate_context_version(screen, mesa_api,
380 major_version, minor_version, error))
381 return NULL;
382
383 context = calloc(1, sizeof *context);
384 if (!context) {
385 *error = __DRI_CTX_ERROR_NO_MEMORY;
386 return NULL;
387 }
388
389 context->loaderPrivate = data;
390
391 context->driScreenPriv = screen;
392 context->driDrawablePriv = NULL;
393 context->driReadablePriv = NULL;
394
395 if (!screen->driver->CreateContext(mesa_api, modes, context,
396 major_version, minor_version,
397 flags, error, shareCtx) ) {
398 free(context);
399 return NULL;
400 }
401
402 struct gl_context *ctx = context->driverPrivate;
403 if ((flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0)
404 ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
405 if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) {
406 ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT;
407 ctx->Debug.DebugOutput = GL_TRUE;
408 }
409
410 *error = __DRI_CTX_ERROR_SUCCESS;
411 return context;
412 }
413
414 static __DRIcontext *
415 dri2CreateNewContextForAPI(__DRIscreen *screen, int api,
416 const __DRIconfig *config,
417 __DRIcontext *shared, void *data)
418 {
419 unsigned error;
420
421 return dri2CreateContextAttribs(screen, api, config, shared, 0, NULL,
422 &error, data);
423 }
424
425 static __DRIcontext *
426 dri2CreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
427 __DRIcontext *shared, void *data)
428 {
429 return dri2CreateNewContextForAPI(screen, __DRI_API_OPENGL,
430 config, shared, data);
431 }
432
433 /**
434 * Destroy the per-context private information.
435 *
436 * \internal
437 * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
438 * drmDestroyContext(), and finally frees \p contextPrivate.
439 */
440 static void
441 driDestroyContext(__DRIcontext *pcp)
442 {
443 if (pcp) {
444 pcp->driScreenPriv->driver->DestroyContext(pcp);
445 free(pcp);
446 }
447 }
448
449 static int
450 driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask)
451 {
452 (void) dest;
453 (void) src;
454 (void) mask;
455 return GL_FALSE;
456 }
457
458 /*@}*/
459
460
461 /*****************************************************************/
462 /** \name Context (un)binding functions */
463 /*****************************************************************/
464 /*@{*/
465
466 static void dri_get_drawable(__DRIdrawable *pdp);
467 static void dri_put_drawable(__DRIdrawable *pdp);
468
469 /**
470 * This function takes both a read buffer and a draw buffer. This is needed
471 * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
472 * function.
473 */
474 static int driBindContext(__DRIcontext *pcp,
475 __DRIdrawable *pdp,
476 __DRIdrawable *prp)
477 {
478 /*
479 ** Assume error checking is done properly in glXMakeCurrent before
480 ** calling driUnbindContext.
481 */
482
483 if (!pcp)
484 return GL_FALSE;
485
486 /* Bind the drawable to the context */
487 pcp->driDrawablePriv = pdp;
488 pcp->driReadablePriv = prp;
489 if (pdp) {
490 pdp->driContextPriv = pcp;
491 dri_get_drawable(pdp);
492 }
493 if (prp && pdp != prp) {
494 dri_get_drawable(prp);
495 }
496
497 return pcp->driScreenPriv->driver->MakeCurrent(pcp, pdp, prp);
498 }
499
500 /**
501 * Unbind context.
502 *
503 * \param scrn the screen.
504 * \param gc context.
505 *
506 * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
507 *
508 * \internal
509 * This function calls __DriverAPIRec::UnbindContext, and then decrements
510 * __DRIdrawableRec::refcount which must be non-zero for a successful
511 * return.
512 *
513 * While casting the opaque private pointers associated with the parameters
514 * into their respective real types it also assures they are not \c NULL.
515 */
516 static int driUnbindContext(__DRIcontext *pcp)
517 {
518 __DRIdrawable *pdp;
519 __DRIdrawable *prp;
520
521 /*
522 ** Assume error checking is done properly in glXMakeCurrent before
523 ** calling driUnbindContext.
524 */
525
526 if (pcp == NULL)
527 return GL_FALSE;
528
529 pdp = pcp->driDrawablePriv;
530 prp = pcp->driReadablePriv;
531
532 /* already unbound */
533 if (!pdp && !prp)
534 return GL_TRUE;
535
536 pcp->driScreenPriv->driver->UnbindContext(pcp);
537
538 assert(pdp);
539 if (pdp->refcount == 0) {
540 /* ERROR!!! */
541 return GL_FALSE;
542 }
543
544 dri_put_drawable(pdp);
545
546 if (prp != pdp) {
547 if (prp->refcount == 0) {
548 /* ERROR!!! */
549 return GL_FALSE;
550 }
551
552 dri_put_drawable(prp);
553 }
554
555 pcp->driDrawablePriv = NULL;
556 pcp->driReadablePriv = NULL;
557
558 return GL_TRUE;
559 }
560
561 /*@}*/
562
563
564 static void dri_get_drawable(__DRIdrawable *pdp)
565 {
566 pdp->refcount++;
567 }
568
569 static void dri_put_drawable(__DRIdrawable *pdp)
570 {
571 if (pdp) {
572 pdp->refcount--;
573 if (pdp->refcount)
574 return;
575
576 pdp->driScreenPriv->driver->DestroyBuffer(pdp);
577 free(pdp);
578 }
579 }
580
581 static __DRIdrawable *
582 dri2CreateNewDrawable(__DRIscreen *screen,
583 const __DRIconfig *config,
584 void *data)
585 {
586 __DRIdrawable *pdraw;
587
588 pdraw = malloc(sizeof *pdraw);
589 if (!pdraw)
590 return NULL;
591
592 pdraw->loaderPrivate = data;
593
594 pdraw->driScreenPriv = screen;
595 pdraw->driContextPriv = NULL;
596 pdraw->refcount = 0;
597 pdraw->lastStamp = 0;
598 pdraw->w = 0;
599 pdraw->h = 0;
600
601 dri_get_drawable(pdraw);
602
603 if (!screen->driver->CreateBuffer(screen, pdraw, &config->modes,
604 GL_FALSE)) {
605 free(pdraw);
606 return NULL;
607 }
608
609 pdraw->dri2.stamp = pdraw->lastStamp + 1;
610
611 return pdraw;
612 }
613
614 static void
615 driDestroyDrawable(__DRIdrawable *pdp)
616 {
617 dri_put_drawable(pdp);
618 }
619
620 static __DRIbuffer *
621 dri2AllocateBuffer(__DRIscreen *screen,
622 unsigned int attachment, unsigned int format,
623 int width, int height)
624 {
625 return screen->driver->AllocateBuffer(screen, attachment, format,
626 width, height);
627 }
628
629 static void
630 dri2ReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
631 {
632 screen->driver->ReleaseBuffer(screen, buffer);
633 }
634
635
636 static int
637 dri2ConfigQueryb(__DRIscreen *screen, const char *var, GLboolean *val)
638 {
639 if (!driCheckOption(&screen->optionCache, var, DRI_BOOL))
640 return -1;
641
642 *val = driQueryOptionb(&screen->optionCache, var);
643
644 return 0;
645 }
646
647 static int
648 dri2ConfigQueryi(__DRIscreen *screen, const char *var, GLint *val)
649 {
650 if (!driCheckOption(&screen->optionCache, var, DRI_INT) &&
651 !driCheckOption(&screen->optionCache, var, DRI_ENUM))
652 return -1;
653
654 *val = driQueryOptioni(&screen->optionCache, var);
655
656 return 0;
657 }
658
659 static int
660 dri2ConfigQueryf(__DRIscreen *screen, const char *var, GLfloat *val)
661 {
662 if (!driCheckOption(&screen->optionCache, var, DRI_FLOAT))
663 return -1;
664
665 *val = driQueryOptionf(&screen->optionCache, var);
666
667 return 0;
668 }
669
670 static unsigned int
671 dri2GetAPIMask(__DRIscreen *screen)
672 {
673 return screen->api_mask;
674 }
675
676 /**
677 * swrast swapbuffers entrypoint.
678 *
679 * DRI2 implements this inside the loader with only flushes handled by the
680 * driver.
681 */
682 static void
683 driSwapBuffers(__DRIdrawable *pdp)
684 {
685 assert(pdp->driScreenPriv->swrast_loader);
686
687 pdp->driScreenPriv->driver->SwapBuffers(pdp);
688 }
689
690 /** Core interface */
691 const __DRIcoreExtension driCoreExtension = {
692 .base = { __DRI_CORE, __DRI_CORE_VERSION },
693
694 .createNewScreen = NULL,
695 .destroyScreen = driDestroyScreen,
696 .getExtensions = driGetExtensions,
697 .getConfigAttrib = driGetConfigAttrib,
698 .indexConfigAttrib = driIndexConfigAttrib,
699 .createNewDrawable = NULL,
700 .destroyDrawable = driDestroyDrawable,
701 .swapBuffers = driSwapBuffers, /* swrast */
702 .createNewContext = dri2CreateNewContext, /* swrast */
703 .copyContext = driCopyContext,
704 .destroyContext = driDestroyContext,
705 .bindContext = driBindContext,
706 .unbindContext = driUnbindContext
707 };
708
709 /** DRI2 interface */
710 const __DRIdri2Extension driDRI2Extension = {
711 .base = { __DRI_DRI2, 4 },
712
713 .createNewScreen = dri2CreateNewScreen,
714 .createNewDrawable = dri2CreateNewDrawable,
715 .createNewContext = dri2CreateNewContext,
716 .getAPIMask = dri2GetAPIMask,
717 .createNewContextForAPI = dri2CreateNewContextForAPI,
718 .allocateBuffer = dri2AllocateBuffer,
719 .releaseBuffer = dri2ReleaseBuffer,
720 .createContextAttribs = dri2CreateContextAttribs,
721 .createNewScreen2 = dri2CreateNewScreen2,
722 };
723
724 const __DRIswrastExtension driSWRastExtension = {
725 { __DRI_SWRAST, 4 },
726 driSWRastCreateNewScreen,
727 dri2CreateNewDrawable,
728 dri2CreateNewContextForAPI,
729 dri2CreateContextAttribs,
730 driSWRastCreateNewScreen2,
731 };
732
733 const __DRI2configQueryExtension dri2ConfigQueryExtension = {
734 .base = { __DRI2_CONFIG_QUERY, __DRI2_CONFIG_QUERY_VERSION },
735
736 .configQueryb = dri2ConfigQueryb,
737 .configQueryi = dri2ConfigQueryi,
738 .configQueryf = dri2ConfigQueryf,
739 };
740
741 void
742 dri2InvalidateDrawable(__DRIdrawable *drawable)
743 {
744 drawable->dri2.stamp++;
745 }
746
747 /**
748 * Check that the gl_framebuffer associated with dPriv is the right size.
749 * Resize the gl_framebuffer if needed.
750 * It's expected that the dPriv->driverPrivate member points to a
751 * gl_framebuffer object.
752 */
753 void
754 driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv)
755 {
756 struct gl_framebuffer *fb = (struct gl_framebuffer *) dPriv->driverPrivate;
757 if (fb && (dPriv->w != fb->Width || dPriv->h != fb->Height)) {
758 ctx->Driver.ResizeBuffers(ctx, fb, dPriv->w, dPriv->h);
759 /* if the driver needs the hw lock for ResizeBuffers, the drawable
760 might have changed again by now */
761 assert(fb->Width == dPriv->w);
762 assert(fb->Height == dPriv->h);
763 }
764 }