2 * (C) Copyright IBM Corporation 2002, 2004
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:
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
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.
27 * DRI utility functions.
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
34 * Basically, these utility functions take care of some of the dirty details of
35 * screen initialization, context creation, context binding, DRM setup, etc.
37 * These functions are compiled into each DRI driver so libGL.so knows nothing
45 #include "util/xmlpool.h"
46 #include "main/mtypes.h"
47 #include "main/framebuffer.h"
48 #include "main/version.h"
49 #include "main/debug_output.h"
50 #include "main/errors.h"
51 #include "main/macros.h"
53 const char __dri2ConfigOptions
[] =
55 DRI_CONF_SECTION_PERFORMANCE
56 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1
)
60 /*****************************************************************/
61 /** \name Screen handling functions */
62 /*****************************************************************/
66 setupLoaderExtensions(__DRIscreen
*psp
,
67 const __DRIextension
**extensions
)
71 for (i
= 0; extensions
[i
]; i
++) {
72 if (strcmp(extensions
[i
]->name
, __DRI_DRI2_LOADER
) == 0)
73 psp
->dri2
.loader
= (__DRIdri2LoaderExtension
*) extensions
[i
];
74 if (strcmp(extensions
[i
]->name
, __DRI_IMAGE_LOOKUP
) == 0)
75 psp
->dri2
.image
= (__DRIimageLookupExtension
*) extensions
[i
];
76 if (strcmp(extensions
[i
]->name
, __DRI_USE_INVALIDATE
) == 0)
77 psp
->dri2
.useInvalidate
= (__DRIuseInvalidateExtension
*) extensions
[i
];
78 if (strcmp(extensions
[i
]->name
, __DRI_BACKGROUND_CALLABLE
) == 0)
79 psp
->dri2
.backgroundCallable
= (__DRIbackgroundCallableExtension
*) extensions
[i
];
80 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST_LOADER
) == 0)
81 psp
->swrast_loader
= (__DRIswrastLoaderExtension
*) extensions
[i
];
82 if (strcmp(extensions
[i
]->name
, __DRI_IMAGE_LOADER
) == 0)
83 psp
->image
.loader
= (__DRIimageLoaderExtension
*) extensions
[i
];
88 * This pointer determines which driver API we'll use in the case of the
89 * loader not passing us an explicit driver extensions list (that would,
90 * itself, contain a pointer to a driver API.)
92 * A driver's driDriverGetExtensions_drivername() can update this pointer to
93 * what it's returning, and a loader that is ignorant of createNewScreen2()
94 * will get the correct driver screen created, as long as no other
95 * driDriverGetExtensions() happened in between the first one and the
98 * This allows the X Server to not require the significant dri_interface.h
99 * updates for doing createNewScreen2(), which would discourage backporting of
100 * the X Server patches to support the new loader interface.
102 const struct __DriverAPIRec
*globalDriverAPI
= &driDriverAPI
;
105 * This is the first entrypoint in the driver called by the DRI driver loader
106 * after dlopen()ing it.
108 * It's used to create global state for the driver across contexts on the same
112 driCreateNewScreen2(int scrn
, int fd
,
113 const __DRIextension
**extensions
,
114 const __DRIextension
**driver_extensions
,
115 const __DRIconfig
***driver_configs
, void *data
)
117 static const __DRIextension
*emptyExtensionList
[] = { NULL
};
120 psp
= calloc(1, sizeof(*psp
));
124 /* By default, use the global driDriverAPI symbol (non-megadrivers). */
125 psp
->driver
= globalDriverAPI
;
127 /* If the driver exposes its vtable through its extensions list
128 * (megadrivers), use that instead.
130 if (driver_extensions
) {
131 for (int i
= 0; driver_extensions
[i
]; i
++) {
132 if (strcmp(driver_extensions
[i
]->name
, __DRI_DRIVER_VTABLE
) == 0) {
134 ((__DRIDriverVtableExtension
*)driver_extensions
[i
])->vtable
;
139 setupLoaderExtensions(psp
, extensions
);
141 psp
->loaderPrivate
= data
;
143 psp
->extensions
= emptyExtensionList
;
147 /* Option parsing before ->InitScreen(), as some options apply there. */
148 driParseOptionInfo(&psp
->optionInfo
, __dri2ConfigOptions
);
149 driParseConfigFiles(&psp
->optionCache
, &psp
->optionInfo
, psp
->myNum
, "dri2");
151 *driver_configs
= psp
->driver
->InitScreen(psp
);
152 if (*driver_configs
== NULL
) {
157 struct gl_constants consts
= { 0 };
162 if (_mesa_override_gl_version_contextless(&consts
, &api
, &version
))
163 psp
->max_gl_es2_version
= version
;
165 api
= API_OPENGL_COMPAT
;
166 if (_mesa_override_gl_version_contextless(&consts
, &api
, &version
)) {
167 psp
->max_gl_core_version
= version
;
168 if (api
== API_OPENGL_COMPAT
)
169 psp
->max_gl_compat_version
= version
;
173 if (psp
->max_gl_compat_version
> 0)
174 psp
->api_mask
|= (1 << __DRI_API_OPENGL
);
175 if (psp
->max_gl_core_version
> 0)
176 psp
->api_mask
|= (1 << __DRI_API_OPENGL_CORE
);
177 if (psp
->max_gl_es1_version
> 0)
178 psp
->api_mask
|= (1 << __DRI_API_GLES
);
179 if (psp
->max_gl_es2_version
> 0)
180 psp
->api_mask
|= (1 << __DRI_API_GLES2
);
181 if (psp
->max_gl_es2_version
>= 30)
182 psp
->api_mask
|= (1 << __DRI_API_GLES3
);
188 dri2CreateNewScreen(int scrn
, int fd
,
189 const __DRIextension
**extensions
,
190 const __DRIconfig
***driver_configs
, void *data
)
192 return driCreateNewScreen2(scrn
, fd
, extensions
, NULL
,
193 driver_configs
, data
);
196 /** swrast driver createNewScreen entrypoint. */
198 driSWRastCreateNewScreen(int scrn
, const __DRIextension
**extensions
,
199 const __DRIconfig
***driver_configs
, void *data
)
201 return driCreateNewScreen2(scrn
, -1, extensions
, NULL
,
202 driver_configs
, data
);
206 driSWRastCreateNewScreen2(int scrn
, const __DRIextension
**extensions
,
207 const __DRIextension
**driver_extensions
,
208 const __DRIconfig
***driver_configs
, void *data
)
210 return driCreateNewScreen2(scrn
, -1, extensions
, driver_extensions
,
211 driver_configs
, data
);
215 * Destroy the per-screen private information.
218 * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
219 * drmClose(), and finally frees \p screenPrivate.
221 static void driDestroyScreen(__DRIscreen
*psp
)
224 /* No interaction with the X-server is possible at this point. This
225 * routine is called after XCloseDisplay, so there is no protocol
226 * stream open to the X-server anymore.
229 psp
->driver
->DestroyScreen(psp
);
231 driDestroyOptionCache(&psp
->optionCache
);
232 driDestroyOptionInfo(&psp
->optionInfo
);
238 static const __DRIextension
**driGetExtensions(__DRIscreen
*psp
)
240 return psp
->extensions
;
247 validate_context_version(__DRIscreen
*screen
,
249 unsigned major_version
,
250 unsigned minor_version
,
251 unsigned *dri_ctx_error
)
253 unsigned req_version
= 10 * major_version
+ minor_version
;
254 unsigned max_version
= 0;
257 case API_OPENGL_COMPAT
:
258 max_version
= screen
->max_gl_compat_version
;
260 case API_OPENGL_CORE
:
261 max_version
= screen
->max_gl_core_version
;
264 max_version
= screen
->max_gl_es1_version
;
267 max_version
= screen
->max_gl_es2_version
;
274 if (max_version
== 0) {
275 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_API
;
277 } else if (req_version
> max_version
) {
278 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_VERSION
;
285 /*****************************************************************/
286 /** \name Context handling functions */
287 /*****************************************************************/
290 static __DRIcontext
*
291 driCreateContextAttribs(__DRIscreen
*screen
, int api
,
292 const __DRIconfig
*config
,
293 __DRIcontext
*shared
,
294 unsigned num_attribs
,
295 const uint32_t *attribs
,
299 __DRIcontext
*context
;
300 const struct gl_config
*modes
= (config
!= NULL
) ? &config
->modes
: NULL
;
301 void *shareCtx
= (shared
!= NULL
) ? shared
->driverPrivate
: NULL
;
303 struct __DriverContextConfig ctx_config
;
305 ctx_config
.major_version
= 1;
306 ctx_config
.minor_version
= 0;
307 ctx_config
.flags
= 0;
308 ctx_config
.attribute_mask
= 0;
309 ctx_config
.priority
= __DRI_CTX_PRIORITY_MEDIUM
;
311 assert((num_attribs
== 0) || (attribs
!= NULL
));
313 if (!(screen
->api_mask
& (1 << api
))) {
314 *error
= __DRI_CTX_ERROR_BAD_API
;
319 case __DRI_API_OPENGL
:
320 mesa_api
= API_OPENGL_COMPAT
;
323 mesa_api
= API_OPENGLES
;
325 case __DRI_API_GLES2
:
326 case __DRI_API_GLES3
:
327 mesa_api
= API_OPENGLES2
;
329 case __DRI_API_OPENGL_CORE
:
330 mesa_api
= API_OPENGL_CORE
;
333 *error
= __DRI_CTX_ERROR_BAD_API
;
337 for (unsigned i
= 0; i
< num_attribs
; i
++) {
338 switch (attribs
[i
* 2]) {
339 case __DRI_CTX_ATTRIB_MAJOR_VERSION
:
340 ctx_config
.major_version
= attribs
[i
* 2 + 1];
342 case __DRI_CTX_ATTRIB_MINOR_VERSION
:
343 ctx_config
.minor_version
= attribs
[i
* 2 + 1];
345 case __DRI_CTX_ATTRIB_FLAGS
:
346 ctx_config
.flags
= attribs
[i
* 2 + 1];
348 case __DRI_CTX_ATTRIB_RESET_STRATEGY
:
349 if (attribs
[i
* 2 + 1] != __DRI_CTX_RESET_NO_NOTIFICATION
) {
350 ctx_config
.attribute_mask
|=
351 __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY
;
352 ctx_config
.reset_strategy
= attribs
[i
* 2 + 1];
354 ctx_config
.attribute_mask
&=
355 ~__DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY
;
358 case __DRI_CTX_ATTRIB_PRIORITY
:
359 ctx_config
.attribute_mask
|= __DRIVER_CONTEXT_ATTRIB_PRIORITY
;
360 ctx_config
.priority
= attribs
[i
* 2 + 1];
362 case __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
:
363 if (attribs
[i
* 2 + 1] != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
364 ctx_config
.attribute_mask
|=
365 __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR
;
366 ctx_config
.release_behavior
= attribs
[i
* 2 + 1];
368 ctx_config
.attribute_mask
&=
369 ~__DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR
;
373 /* We can't create a context that satisfies the requirements of an
374 * attribute that we don't understand. Return failure.
376 assert(!"Should not get here.");
377 *error
= __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
;
382 /* The specific Mesa driver may not support the GL_ARB_compatibilty
383 * extension or the compatibility profile. In that case, we treat an
384 * API_OPENGL_COMPAT 3.1 as API_OPENGL_CORE. We reject API_OPENGL_COMPAT
387 if (mesa_api
== API_OPENGL_COMPAT
&&
388 ctx_config
.major_version
== 3 && ctx_config
.minor_version
== 1 &&
389 screen
->max_gl_compat_version
< 31)
390 mesa_api
= API_OPENGL_CORE
;
392 if (mesa_api
== API_OPENGL_COMPAT
393 && ((ctx_config
.major_version
> 3)
394 || (ctx_config
.major_version
== 3 &&
395 ctx_config
.minor_version
>= 2))) {
396 *error
= __DRI_CTX_ERROR_BAD_API
;
400 /* The latest version of EGL_KHR_create_context spec says:
402 * "If the EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR flag bit is set in
403 * EGL_CONTEXT_FLAGS_KHR, then a <debug context> will be created.
404 * [...] This bit is supported for OpenGL and OpenGL ES contexts.
406 * No other EGL_CONTEXT_OPENGL_*_BIT is legal for an ES context.
408 * However, Mesa's EGL layer translates the context attribute
409 * EGL_CONTEXT_OPENGL_ROBUST_ACCESS into the context flag
410 * __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS. That attribute is legal for ES
411 * (with EGL 1.5 or EGL_EXT_create_context_robustness) and GL (only with
414 * From the EGL_EXT_create_context_robustness spec:
416 * This extension is written against the OpenGL ES 2.0 Specification
417 * but can apply to OpenGL ES 1.1 and up.
419 * From the EGL 1.5 (2014.08.27) spec, p55:
421 * If the EGL_CONTEXT_OPENGL_ROBUST_ACCESS attribute is set to
422 * EGL_TRUE, a context supporting robust buffer access will be created.
423 * OpenGL contexts must support the GL_ARB_robustness extension, or
424 * equivalent core API functional- ity. OpenGL ES contexts must support
425 * the GL_EXT_robustness extension, or equivalent core API
428 if (mesa_api
!= API_OPENGL_COMPAT
429 && mesa_api
!= API_OPENGL_CORE
430 && (ctx_config
.flags
& ~(__DRI_CTX_FLAG_DEBUG
|
431 __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
|
432 __DRI_CTX_FLAG_NO_ERROR
))) {
433 *error
= __DRI_CTX_ERROR_BAD_FLAG
;
437 /* There are no forward-compatible contexts before OpenGL 3.0. The
438 * GLX_ARB_create_context spec says:
440 * "Forward-compatible contexts are defined only for OpenGL versions
443 * Forward-looking contexts are supported by silently converting the
444 * requested API to API_OPENGL_CORE.
446 * In Mesa, a debug context is the same as a regular context.
448 if ((ctx_config
.flags
& __DRI_CTX_FLAG_FORWARD_COMPATIBLE
) != 0) {
449 mesa_api
= API_OPENGL_CORE
;
452 const uint32_t allowed_flags
= (__DRI_CTX_FLAG_DEBUG
453 | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
454 | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
455 | __DRI_CTX_FLAG_NO_ERROR
);
456 if (ctx_config
.flags
& ~allowed_flags
) {
457 *error
= __DRI_CTX_ERROR_UNKNOWN_FLAG
;
461 if (!validate_context_version(screen
, mesa_api
,
462 ctx_config
.major_version
,
463 ctx_config
.minor_version
,
467 context
= calloc(1, sizeof *context
);
469 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
473 context
->loaderPrivate
= data
;
475 context
->driScreenPriv
= screen
;
476 context
->driDrawablePriv
= NULL
;
477 context
->driReadablePriv
= NULL
;
479 if (!screen
->driver
->CreateContext(mesa_api
, modes
, context
,
480 &ctx_config
, error
, shareCtx
)) {
485 *error
= __DRI_CTX_ERROR_SUCCESS
;
490 driContextSetFlags(struct gl_context
*ctx
, uint32_t flags
)
492 if ((flags
& __DRI_CTX_FLAG_FORWARD_COMPATIBLE
) != 0)
493 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
494 if ((flags
& __DRI_CTX_FLAG_DEBUG
) != 0) {
495 _mesa_set_debug_state_int(ctx
, GL_DEBUG_OUTPUT
, GL_TRUE
);
496 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_DEBUG_BIT
;
498 if ((flags
& __DRI_CTX_FLAG_NO_ERROR
) != 0)
499 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
;
502 static __DRIcontext
*
503 driCreateNewContextForAPI(__DRIscreen
*screen
, int api
,
504 const __DRIconfig
*config
,
505 __DRIcontext
*shared
, void *data
)
509 return driCreateContextAttribs(screen
, api
, config
, shared
, 0, NULL
,
513 static __DRIcontext
*
514 driCreateNewContext(__DRIscreen
*screen
, const __DRIconfig
*config
,
515 __DRIcontext
*shared
, void *data
)
517 return driCreateNewContextForAPI(screen
, __DRI_API_OPENGL
,
518 config
, shared
, data
);
522 * Destroy the per-context private information.
525 * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
526 * drmDestroyContext(), and finally frees \p contextPrivate.
529 driDestroyContext(__DRIcontext
*pcp
)
532 pcp
->driScreenPriv
->driver
->DestroyContext(pcp
);
538 driCopyContext(__DRIcontext
*dest
, __DRIcontext
*src
, unsigned long mask
)
549 /*****************************************************************/
550 /** \name Context (un)binding functions */
551 /*****************************************************************/
554 static void dri_get_drawable(__DRIdrawable
*pdp
);
555 static void dri_put_drawable(__DRIdrawable
*pdp
);
558 * This function takes both a read buffer and a draw buffer. This is needed
559 * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
562 static int driBindContext(__DRIcontext
*pcp
,
567 ** Assume error checking is done properly in glXMakeCurrent before
568 ** calling driUnbindContext.
574 /* Bind the drawable to the context */
575 pcp
->driDrawablePriv
= pdp
;
576 pcp
->driReadablePriv
= prp
;
578 pdp
->driContextPriv
= pcp
;
579 dri_get_drawable(pdp
);
581 if (prp
&& pdp
!= prp
) {
582 dri_get_drawable(prp
);
585 return pcp
->driScreenPriv
->driver
->MakeCurrent(pcp
, pdp
, prp
);
591 * \param scrn the screen.
594 * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
597 * This function calls __DriverAPIRec::UnbindContext, and then decrements
598 * __DRIdrawableRec::refcount which must be non-zero for a successful
601 * While casting the opaque private pointers associated with the parameters
602 * into their respective real types it also assures they are not \c NULL.
604 static int driUnbindContext(__DRIcontext
*pcp
)
610 ** Assume error checking is done properly in glXMakeCurrent before
611 ** calling driUnbindContext.
618 ** Call driUnbindContext before checking for valid drawables
619 ** to handle surfaceless contexts properly.
621 pcp
->driScreenPriv
->driver
->UnbindContext(pcp
);
623 pdp
= pcp
->driDrawablePriv
;
624 prp
= pcp
->driReadablePriv
;
626 /* already unbound */
631 if (pdp
->refcount
== 0) {
636 dri_put_drawable(pdp
);
639 if (prp
->refcount
== 0) {
644 dri_put_drawable(prp
);
647 pcp
->driDrawablePriv
= NULL
;
648 pcp
->driReadablePriv
= NULL
;
656 static void dri_get_drawable(__DRIdrawable
*pdp
)
661 static void dri_put_drawable(__DRIdrawable
*pdp
)
668 pdp
->driScreenPriv
->driver
->DestroyBuffer(pdp
);
673 static __DRIdrawable
*
674 driCreateNewDrawable(__DRIscreen
*screen
,
675 const __DRIconfig
*config
,
678 __DRIdrawable
*pdraw
;
680 assert(data
!= NULL
);
682 pdraw
= malloc(sizeof *pdraw
);
686 pdraw
->loaderPrivate
= data
;
688 pdraw
->driScreenPriv
= screen
;
689 pdraw
->driContextPriv
= NULL
;
691 pdraw
->lastStamp
= 0;
695 dri_get_drawable(pdraw
);
697 if (!screen
->driver
->CreateBuffer(screen
, pdraw
, &config
->modes
,
703 pdraw
->dri2
.stamp
= pdraw
->lastStamp
+ 1;
709 driDestroyDrawable(__DRIdrawable
*pdp
)
712 * The loader's data structures are going away, even if pdp itself stays
713 * around for the time being because it is currently bound. This happens
714 * when a currently bound GLX pixmap is destroyed.
716 * Clear out the pointer back into the loader's data structures to avoid
717 * accessing an outdated pointer.
719 pdp
->loaderPrivate
= NULL
;
721 dri_put_drawable(pdp
);
725 dri2AllocateBuffer(__DRIscreen
*screen
,
726 unsigned int attachment
, unsigned int format
,
727 int width
, int height
)
729 return screen
->driver
->AllocateBuffer(screen
, attachment
, format
,
734 dri2ReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
736 screen
->driver
->ReleaseBuffer(screen
, buffer
);
741 dri2ConfigQueryb(__DRIscreen
*screen
, const char *var
, unsigned char *val
)
743 if (!driCheckOption(&screen
->optionCache
, var
, DRI_BOOL
))
746 *val
= driQueryOptionb(&screen
->optionCache
, var
);
752 dri2ConfigQueryi(__DRIscreen
*screen
, const char *var
, int *val
)
754 if (!driCheckOption(&screen
->optionCache
, var
, DRI_INT
) &&
755 !driCheckOption(&screen
->optionCache
, var
, DRI_ENUM
))
758 *val
= driQueryOptioni(&screen
->optionCache
, var
);
764 dri2ConfigQueryf(__DRIscreen
*screen
, const char *var
, float *val
)
766 if (!driCheckOption(&screen
->optionCache
, var
, DRI_FLOAT
))
769 *val
= driQueryOptionf(&screen
->optionCache
, var
);
775 driGetAPIMask(__DRIscreen
*screen
)
777 return screen
->api_mask
;
781 * swrast swapbuffers entrypoint.
783 * DRI2 implements this inside the loader with only flushes handled by the
787 driSwapBuffers(__DRIdrawable
*pdp
)
789 assert(pdp
->driScreenPriv
->swrast_loader
);
791 pdp
->driScreenPriv
->driver
->SwapBuffers(pdp
);
794 /** Core interface */
795 const __DRIcoreExtension driCoreExtension
= {
796 .base
= { __DRI_CORE
, 2 },
798 .createNewScreen
= NULL
,
799 .destroyScreen
= driDestroyScreen
,
800 .getExtensions
= driGetExtensions
,
801 .getConfigAttrib
= driGetConfigAttrib
,
802 .indexConfigAttrib
= driIndexConfigAttrib
,
803 .createNewDrawable
= NULL
,
804 .destroyDrawable
= driDestroyDrawable
,
805 .swapBuffers
= driSwapBuffers
, /* swrast */
806 .createNewContext
= driCreateNewContext
, /* swrast */
807 .copyContext
= driCopyContext
,
808 .destroyContext
= driDestroyContext
,
809 .bindContext
= driBindContext
,
810 .unbindContext
= driUnbindContext
813 /** DRI2 interface */
814 const __DRIdri2Extension driDRI2Extension
= {
815 .base
= { __DRI_DRI2
, 4 },
817 .createNewScreen
= dri2CreateNewScreen
,
818 .createNewDrawable
= driCreateNewDrawable
,
819 .createNewContext
= driCreateNewContext
,
820 .getAPIMask
= driGetAPIMask
,
821 .createNewContextForAPI
= driCreateNewContextForAPI
,
822 .allocateBuffer
= dri2AllocateBuffer
,
823 .releaseBuffer
= dri2ReleaseBuffer
,
824 .createContextAttribs
= driCreateContextAttribs
,
825 .createNewScreen2
= driCreateNewScreen2
,
828 const __DRIswrastExtension driSWRastExtension
= {
829 .base
= { __DRI_SWRAST
, 4 },
831 .createNewScreen
= driSWRastCreateNewScreen
,
832 .createNewDrawable
= driCreateNewDrawable
,
833 .createNewContextForAPI
= driCreateNewContextForAPI
,
834 .createContextAttribs
= driCreateContextAttribs
,
835 .createNewScreen2
= driSWRastCreateNewScreen2
,
838 const __DRI2configQueryExtension dri2ConfigQueryExtension
= {
839 .base
= { __DRI2_CONFIG_QUERY
, 1 },
841 .configQueryb
= dri2ConfigQueryb
,
842 .configQueryi
= dri2ConfigQueryi
,
843 .configQueryf
= dri2ConfigQueryf
,
846 const __DRI2flushControlExtension dri2FlushControlExtension
= {
847 .base
= { __DRI2_FLUSH_CONTROL
, 1 }
851 dri2InvalidateDrawable(__DRIdrawable
*drawable
)
853 drawable
->dri2
.stamp
++;
857 * Check that the gl_framebuffer associated with dPriv is the right size.
858 * Resize the gl_framebuffer if needed.
859 * It's expected that the dPriv->driverPrivate member points to a
860 * gl_framebuffer object.
863 driUpdateFramebufferSize(struct gl_context
*ctx
, const __DRIdrawable
*dPriv
)
865 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) dPriv
->driverPrivate
;
866 if (fb
&& (dPriv
->w
!= fb
->Width
|| dPriv
->h
!= fb
->Height
)) {
867 _mesa_resize_framebuffer(ctx
, fb
, dPriv
->w
, dPriv
->h
);
868 /* if the driver needs the hw lock for ResizeBuffers, the drawable
869 might have changed again by now */
870 assert(fb
->Width
== dPriv
->w
);
871 assert(fb
->Height
== dPriv
->h
);
876 driGLFormatToImageFormat(mesa_format format
)
879 case MESA_FORMAT_B5G6R5_UNORM
:
880 return __DRI_IMAGE_FORMAT_RGB565
;
881 case MESA_FORMAT_B5G5R5A1_UNORM
:
882 return __DRI_IMAGE_FORMAT_ARGB1555
;
883 case MESA_FORMAT_B8G8R8X8_UNORM
:
884 return __DRI_IMAGE_FORMAT_XRGB8888
;
885 case MESA_FORMAT_B10G10R10A2_UNORM
:
886 return __DRI_IMAGE_FORMAT_ARGB2101010
;
887 case MESA_FORMAT_B10G10R10X2_UNORM
:
888 return __DRI_IMAGE_FORMAT_XRGB2101010
;
889 case MESA_FORMAT_B8G8R8A8_UNORM
:
890 return __DRI_IMAGE_FORMAT_ARGB8888
;
891 case MESA_FORMAT_R8G8B8A8_UNORM
:
892 return __DRI_IMAGE_FORMAT_ABGR8888
;
893 case MESA_FORMAT_R8G8B8X8_UNORM
:
894 return __DRI_IMAGE_FORMAT_XBGR8888
;
895 case MESA_FORMAT_L_UNORM8
:
896 case MESA_FORMAT_R_UNORM8
:
897 return __DRI_IMAGE_FORMAT_R8
;
898 case MESA_FORMAT_L8A8_UNORM
:
899 case MESA_FORMAT_R8G8_UNORM
:
900 return __DRI_IMAGE_FORMAT_GR88
;
901 case MESA_FORMAT_NONE
:
902 return __DRI_IMAGE_FORMAT_NONE
;
903 case MESA_FORMAT_R8G8B8A8_SRGB
:
904 return __DRI_IMAGE_FORMAT_SABGR8
;
905 case MESA_FORMAT_B8G8R8A8_SRGB
:
906 return __DRI_IMAGE_FORMAT_SARGB8
;
913 driImageFormatToGLFormat(uint32_t image_format
)
915 switch (image_format
) {
916 case __DRI_IMAGE_FORMAT_RGB565
:
917 return MESA_FORMAT_B5G6R5_UNORM
;
918 case __DRI_IMAGE_FORMAT_ARGB1555
:
919 return MESA_FORMAT_B5G5R5A1_UNORM
;
920 case __DRI_IMAGE_FORMAT_XRGB8888
:
921 return MESA_FORMAT_B8G8R8X8_UNORM
;
922 case __DRI_IMAGE_FORMAT_ARGB2101010
:
923 return MESA_FORMAT_B10G10R10A2_UNORM
;
924 case __DRI_IMAGE_FORMAT_XRGB2101010
:
925 return MESA_FORMAT_B10G10R10X2_UNORM
;
926 case __DRI_IMAGE_FORMAT_ARGB8888
:
927 return MESA_FORMAT_B8G8R8A8_UNORM
;
928 case __DRI_IMAGE_FORMAT_ABGR8888
:
929 return MESA_FORMAT_R8G8B8A8_UNORM
;
930 case __DRI_IMAGE_FORMAT_XBGR8888
:
931 return MESA_FORMAT_R8G8B8X8_UNORM
;
932 case __DRI_IMAGE_FORMAT_R8
:
933 return MESA_FORMAT_R_UNORM8
;
934 case __DRI_IMAGE_FORMAT_R16
:
935 return MESA_FORMAT_R_UNORM16
;
936 case __DRI_IMAGE_FORMAT_GR88
:
937 return MESA_FORMAT_R8G8_UNORM
;
938 case __DRI_IMAGE_FORMAT_GR1616
:
939 return MESA_FORMAT_R16G16_UNORM
;
940 case __DRI_IMAGE_FORMAT_SARGB8
:
941 return MESA_FORMAT_B8G8R8A8_SRGB
;
942 case __DRI_IMAGE_FORMAT_SABGR8
:
943 return MESA_FORMAT_R8G8B8A8_SRGB
;
944 case __DRI_IMAGE_FORMAT_NONE
:
945 return MESA_FORMAT_NONE
;
947 return MESA_FORMAT_NONE
;
951 /** Image driver interface */
952 const __DRIimageDriverExtension driImageDriverExtension
= {
953 .base
= { __DRI_IMAGE_DRIVER
, 1 },
955 .createNewScreen2
= driCreateNewScreen2
,
956 .createNewDrawable
= driCreateNewDrawable
,
957 .getAPIMask
= driGetAPIMask
,
958 .createContextAttribs
= driCreateContextAttribs
,
961 /* swrast copy sub buffer entrypoint. */
962 static void driCopySubBuffer(__DRIdrawable
*pdp
, int x
, int y
,
965 assert(pdp
->driScreenPriv
->swrast_loader
);
967 pdp
->driScreenPriv
->driver
->CopySubBuffer(pdp
, x
, y
, w
, h
);
970 /* for swrast only */
971 const __DRIcopySubBufferExtension driCopySubBufferExtension
= {
972 .base
= { __DRI_COPY_SUB_BUFFER
, 1 },
974 .copySubBuffer
= driCopySubBuffer
,
977 const __DRInoErrorExtension dri2NoErrorExtension
= {
978 .base
= { __DRI2_NO_ERROR
, 1 },