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
43 #ifndef __NOT_HAVE_DRM_H
49 #include "../glsl/glsl_parser_extras.h"
50 #include "main/mtypes.h"
51 #include "main/version.h"
52 #include "main/errors.h"
53 #include "main/macros.h"
55 const char __dri2ConfigOptions
[] =
57 DRI_CONF_SECTION_PERFORMANCE
58 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1
)
62 /*****************************************************************/
63 /** \name Screen handling functions */
64 /*****************************************************************/
68 setupLoaderExtensions(__DRIscreen
*psp
,
69 const __DRIextension
**extensions
)
73 for (i
= 0; extensions
[i
]; i
++) {
74 if (strcmp(extensions
[i
]->name
, __DRI_DRI2_LOADER
) == 0)
75 psp
->dri2
.loader
= (__DRIdri2LoaderExtension
*) extensions
[i
];
76 if (strcmp(extensions
[i
]->name
, __DRI_IMAGE_LOOKUP
) == 0)
77 psp
->dri2
.image
= (__DRIimageLookupExtension
*) extensions
[i
];
78 if (strcmp(extensions
[i
]->name
, __DRI_USE_INVALIDATE
) == 0)
79 psp
->dri2
.useInvalidate
= (__DRIuseInvalidateExtension
*) 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 #ifndef __NOT_HAVE_DRM_H
143 drmVersionPtr version
= drmGetVersion(fd
);
145 psp
->drm_version
.major
= version
->version_major
;
146 psp
->drm_version
.minor
= version
->version_minor
;
147 psp
->drm_version
.patch
= version
->version_patchlevel
;
148 drmFreeVersion(version
);
153 psp
->loaderPrivate
= data
;
155 psp
->extensions
= emptyExtensionList
;
159 *driver_configs
= psp
->driver
->InitScreen(psp
);
160 if (*driver_configs
== NULL
) {
165 int gl_version_override
= _mesa_get_gl_version_override();
166 if (gl_version_override
>= 31) {
167 psp
->max_gl_core_version
= MAX2(psp
->max_gl_core_version
,
168 gl_version_override
);
170 psp
->max_gl_compat_version
= MAX2(psp
->max_gl_compat_version
,
171 gl_version_override
);
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
);
184 driParseOptionInfo(&psp
->optionInfo
, __dri2ConfigOptions
);
185 driParseConfigFiles(&psp
->optionCache
, &psp
->optionInfo
, psp
->myNum
, "dri2");
192 dri2CreateNewScreen(int scrn
, int fd
,
193 const __DRIextension
**extensions
,
194 const __DRIconfig
***driver_configs
, void *data
)
196 return driCreateNewScreen2(scrn
, fd
, extensions
, NULL
,
197 driver_configs
, data
);
200 /** swrast driver createNewScreen entrypoint. */
202 driSWRastCreateNewScreen(int scrn
, const __DRIextension
**extensions
,
203 const __DRIconfig
***driver_configs
, void *data
)
205 return driCreateNewScreen2(scrn
, -1, extensions
, NULL
,
206 driver_configs
, data
);
210 driSWRastCreateNewScreen2(int scrn
, const __DRIextension
**extensions
,
211 const __DRIextension
**driver_extensions
,
212 const __DRIconfig
***driver_configs
, void *data
)
214 return driCreateNewScreen2(scrn
, -1, extensions
, driver_extensions
,
215 driver_configs
, data
);
219 * Destroy the per-screen private information.
222 * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
223 * drmClose(), and finally frees \p screenPrivate.
225 static void driDestroyScreen(__DRIscreen
*psp
)
228 /* No interaction with the X-server is possible at this point. This
229 * routine is called after XCloseDisplay, so there is no protocol
230 * stream open to the X-server anymore.
233 _mesa_destroy_shader_compiler();
235 psp
->driver
->DestroyScreen(psp
);
237 driDestroyOptionCache(&psp
->optionCache
);
238 driDestroyOptionInfo(&psp
->optionInfo
);
244 static const __DRIextension
**driGetExtensions(__DRIscreen
*psp
)
246 return psp
->extensions
;
253 validate_context_version(__DRIscreen
*screen
,
255 unsigned major_version
,
256 unsigned minor_version
,
257 unsigned *dri_ctx_error
)
259 unsigned req_version
= 10 * major_version
+ minor_version
;
260 unsigned max_version
= 0;
263 case API_OPENGL_COMPAT
:
264 max_version
= screen
->max_gl_compat_version
;
266 case API_OPENGL_CORE
:
267 max_version
= screen
->max_gl_core_version
;
270 max_version
= screen
->max_gl_es1_version
;
273 max_version
= screen
->max_gl_es2_version
;
280 if (max_version
== 0) {
281 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_API
;
283 } else if (req_version
> max_version
) {
284 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_VERSION
;
291 /*****************************************************************/
292 /** \name Context handling functions */
293 /*****************************************************************/
296 static __DRIcontext
*
297 driCreateContextAttribs(__DRIscreen
*screen
, int api
,
298 const __DRIconfig
*config
,
299 __DRIcontext
*shared
,
300 unsigned num_attribs
,
301 const uint32_t *attribs
,
305 __DRIcontext
*context
;
306 const struct gl_config
*modes
= (config
!= NULL
) ? &config
->modes
: NULL
;
307 void *shareCtx
= (shared
!= NULL
) ? shared
->driverPrivate
: NULL
;
309 unsigned major_version
= 1;
310 unsigned minor_version
= 0;
312 bool notify_reset
= false;
314 assert((num_attribs
== 0) || (attribs
!= NULL
));
316 if (!(screen
->api_mask
& (1 << api
))) {
317 *error
= __DRI_CTX_ERROR_BAD_API
;
322 case __DRI_API_OPENGL
:
323 mesa_api
= API_OPENGL_COMPAT
;
326 mesa_api
= API_OPENGLES
;
328 case __DRI_API_GLES2
:
329 case __DRI_API_GLES3
:
330 mesa_api
= API_OPENGLES2
;
332 case __DRI_API_OPENGL_CORE
:
333 mesa_api
= API_OPENGL_CORE
;
336 *error
= __DRI_CTX_ERROR_BAD_API
;
340 for (unsigned i
= 0; i
< num_attribs
; i
++) {
341 switch (attribs
[i
* 2]) {
342 case __DRI_CTX_ATTRIB_MAJOR_VERSION
:
343 major_version
= attribs
[i
* 2 + 1];
345 case __DRI_CTX_ATTRIB_MINOR_VERSION
:
346 minor_version
= attribs
[i
* 2 + 1];
348 case __DRI_CTX_ATTRIB_FLAGS
:
349 flags
= attribs
[i
* 2 + 1];
351 case __DRI_CTX_ATTRIB_RESET_STRATEGY
:
352 notify_reset
= (attribs
[i
* 2 + 1]
353 != __DRI_CTX_RESET_NO_NOTIFICATION
);
356 /* We can't create a context that satisfies the requirements of an
357 * attribute that we don't understand. Return failure.
359 assert(!"Should not get here.");
360 *error
= __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
;
365 /* Mesa does not support the GL_ARB_compatibilty extension or the
366 * compatibility profile. This means that we treat a API_OPENGL_COMPAT 3.1 as
367 * API_OPENGL_CORE and reject API_OPENGL_COMPAT 3.2+.
369 if (mesa_api
== API_OPENGL_COMPAT
&& major_version
== 3 && minor_version
== 1)
370 mesa_api
= API_OPENGL_CORE
;
372 if (mesa_api
== API_OPENGL_COMPAT
373 && ((major_version
> 3)
374 || (major_version
== 3 && minor_version
>= 2))) {
375 *error
= __DRI_CTX_ERROR_BAD_API
;
379 /* The EGL_KHR_create_context spec says:
381 * "Flags are only defined for OpenGL context creation, and specifying
382 * a flags value other than zero for other types of contexts,
383 * including OpenGL ES contexts, will generate an error."
385 * The GLX_EXT_create_context_es2_profile specification doesn't say
386 * anything specific about this case. However, none of the known flags
387 * have any meaning in an ES context, so this seems safe.
389 if (mesa_api
!= API_OPENGL_COMPAT
390 && mesa_api
!= API_OPENGL_CORE
392 *error
= __DRI_CTX_ERROR_BAD_FLAG
;
396 /* There are no forward-compatible contexts before OpenGL 3.0. The
397 * GLX_ARB_create_context spec says:
399 * "Forward-compatible contexts are defined only for OpenGL versions
402 * Forward-looking contexts are supported by silently converting the
403 * requested API to API_OPENGL_CORE.
405 * In Mesa, a debug context is the same as a regular context.
407 if ((flags
& __DRI_CTX_FLAG_FORWARD_COMPATIBLE
) != 0) {
408 mesa_api
= API_OPENGL_CORE
;
411 const uint32_t allowed_flags
= (__DRI_CTX_FLAG_DEBUG
412 | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
413 | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
);
414 if (flags
& ~allowed_flags
) {
415 *error
= __DRI_CTX_ERROR_UNKNOWN_FLAG
;
419 if (!validate_context_version(screen
, mesa_api
,
420 major_version
, minor_version
, error
))
423 context
= calloc(1, sizeof *context
);
425 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
429 context
->loaderPrivate
= data
;
431 context
->driScreenPriv
= screen
;
432 context
->driDrawablePriv
= NULL
;
433 context
->driReadablePriv
= NULL
;
435 if (!screen
->driver
->CreateContext(mesa_api
, modes
, context
,
436 major_version
, minor_version
,
437 flags
, notify_reset
, error
, shareCtx
)) {
442 *error
= __DRI_CTX_ERROR_SUCCESS
;
447 driContextSetFlags(struct gl_context
*ctx
, uint32_t flags
)
449 if ((flags
& __DRI_CTX_FLAG_FORWARD_COMPATIBLE
) != 0)
450 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
451 if ((flags
& __DRI_CTX_FLAG_DEBUG
) != 0) {
452 _mesa_set_debug_state_int(ctx
, GL_DEBUG_OUTPUT
, GL_TRUE
);
453 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_DEBUG_BIT
;
457 static __DRIcontext
*
458 driCreateNewContextForAPI(__DRIscreen
*screen
, int api
,
459 const __DRIconfig
*config
,
460 __DRIcontext
*shared
, void *data
)
464 return driCreateContextAttribs(screen
, api
, config
, shared
, 0, NULL
,
468 static __DRIcontext
*
469 driCreateNewContext(__DRIscreen
*screen
, const __DRIconfig
*config
,
470 __DRIcontext
*shared
, void *data
)
472 return driCreateNewContextForAPI(screen
, __DRI_API_OPENGL
,
473 config
, shared
, data
);
477 * Destroy the per-context private information.
480 * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
481 * drmDestroyContext(), and finally frees \p contextPrivate.
484 driDestroyContext(__DRIcontext
*pcp
)
487 pcp
->driScreenPriv
->driver
->DestroyContext(pcp
);
493 driCopyContext(__DRIcontext
*dest
, __DRIcontext
*src
, unsigned long mask
)
504 /*****************************************************************/
505 /** \name Context (un)binding functions */
506 /*****************************************************************/
509 static void dri_get_drawable(__DRIdrawable
*pdp
);
510 static void dri_put_drawable(__DRIdrawable
*pdp
);
513 * This function takes both a read buffer and a draw buffer. This is needed
514 * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
517 static int driBindContext(__DRIcontext
*pcp
,
522 ** Assume error checking is done properly in glXMakeCurrent before
523 ** calling driUnbindContext.
529 /* Bind the drawable to the context */
530 pcp
->driDrawablePriv
= pdp
;
531 pcp
->driReadablePriv
= prp
;
533 pdp
->driContextPriv
= pcp
;
534 dri_get_drawable(pdp
);
536 if (prp
&& pdp
!= prp
) {
537 dri_get_drawable(prp
);
540 return pcp
->driScreenPriv
->driver
->MakeCurrent(pcp
, pdp
, prp
);
546 * \param scrn the screen.
549 * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
552 * This function calls __DriverAPIRec::UnbindContext, and then decrements
553 * __DRIdrawableRec::refcount which must be non-zero for a successful
556 * While casting the opaque private pointers associated with the parameters
557 * into their respective real types it also assures they are not \c NULL.
559 static int driUnbindContext(__DRIcontext
*pcp
)
565 ** Assume error checking is done properly in glXMakeCurrent before
566 ** calling driUnbindContext.
572 pdp
= pcp
->driDrawablePriv
;
573 prp
= pcp
->driReadablePriv
;
575 /* already unbound */
579 pcp
->driScreenPriv
->driver
->UnbindContext(pcp
);
582 if (pdp
->refcount
== 0) {
587 dri_put_drawable(pdp
);
590 if (prp
->refcount
== 0) {
595 dri_put_drawable(prp
);
598 pcp
->driDrawablePriv
= NULL
;
599 pcp
->driReadablePriv
= NULL
;
607 static void dri_get_drawable(__DRIdrawable
*pdp
)
612 static void dri_put_drawable(__DRIdrawable
*pdp
)
619 pdp
->driScreenPriv
->driver
->DestroyBuffer(pdp
);
624 static __DRIdrawable
*
625 driCreateNewDrawable(__DRIscreen
*screen
,
626 const __DRIconfig
*config
,
629 __DRIdrawable
*pdraw
;
631 pdraw
= malloc(sizeof *pdraw
);
635 pdraw
->loaderPrivate
= data
;
637 pdraw
->driScreenPriv
= screen
;
638 pdraw
->driContextPriv
= NULL
;
640 pdraw
->lastStamp
= 0;
644 dri_get_drawable(pdraw
);
646 if (!screen
->driver
->CreateBuffer(screen
, pdraw
, &config
->modes
,
652 pdraw
->dri2
.stamp
= pdraw
->lastStamp
+ 1;
658 driDestroyDrawable(__DRIdrawable
*pdp
)
660 dri_put_drawable(pdp
);
664 dri2AllocateBuffer(__DRIscreen
*screen
,
665 unsigned int attachment
, unsigned int format
,
666 int width
, int height
)
668 return screen
->driver
->AllocateBuffer(screen
, attachment
, format
,
673 dri2ReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
675 screen
->driver
->ReleaseBuffer(screen
, buffer
);
680 dri2ConfigQueryb(__DRIscreen
*screen
, const char *var
, unsigned char *val
)
682 if (!driCheckOption(&screen
->optionCache
, var
, DRI_BOOL
))
685 *val
= driQueryOptionb(&screen
->optionCache
, var
);
691 dri2ConfigQueryi(__DRIscreen
*screen
, const char *var
, int *val
)
693 if (!driCheckOption(&screen
->optionCache
, var
, DRI_INT
) &&
694 !driCheckOption(&screen
->optionCache
, var
, DRI_ENUM
))
697 *val
= driQueryOptioni(&screen
->optionCache
, var
);
703 dri2ConfigQueryf(__DRIscreen
*screen
, const char *var
, float *val
)
705 if (!driCheckOption(&screen
->optionCache
, var
, DRI_FLOAT
))
708 *val
= driQueryOptionf(&screen
->optionCache
, var
);
714 driGetAPIMask(__DRIscreen
*screen
)
716 return screen
->api_mask
;
720 * swrast swapbuffers entrypoint.
722 * DRI2 implements this inside the loader with only flushes handled by the
726 driSwapBuffers(__DRIdrawable
*pdp
)
728 assert(pdp
->driScreenPriv
->swrast_loader
);
730 pdp
->driScreenPriv
->driver
->SwapBuffers(pdp
);
733 /** Core interface */
734 const __DRIcoreExtension driCoreExtension
= {
735 .base
= { __DRI_CORE
, 1 },
737 .createNewScreen
= NULL
,
738 .destroyScreen
= driDestroyScreen
,
739 .getExtensions
= driGetExtensions
,
740 .getConfigAttrib
= driGetConfigAttrib
,
741 .indexConfigAttrib
= driIndexConfigAttrib
,
742 .createNewDrawable
= NULL
,
743 .destroyDrawable
= driDestroyDrawable
,
744 .swapBuffers
= driSwapBuffers
, /* swrast */
745 .createNewContext
= driCreateNewContext
, /* swrast */
746 .copyContext
= driCopyContext
,
747 .destroyContext
= driDestroyContext
,
748 .bindContext
= driBindContext
,
749 .unbindContext
= driUnbindContext
752 /** DRI2 interface */
753 const __DRIdri2Extension driDRI2Extension
= {
754 .base
= { __DRI_DRI2
, 4 },
756 .createNewScreen
= dri2CreateNewScreen
,
757 .createNewDrawable
= driCreateNewDrawable
,
758 .createNewContext
= driCreateNewContext
,
759 .getAPIMask
= driGetAPIMask
,
760 .createNewContextForAPI
= driCreateNewContextForAPI
,
761 .allocateBuffer
= dri2AllocateBuffer
,
762 .releaseBuffer
= dri2ReleaseBuffer
,
763 .createContextAttribs
= driCreateContextAttribs
,
764 .createNewScreen2
= driCreateNewScreen2
,
767 const __DRIswrastExtension driSWRastExtension
= {
768 .base
= { __DRI_SWRAST
, 4 },
770 .createNewScreen
= driSWRastCreateNewScreen
,
771 .createNewDrawable
= driCreateNewDrawable
,
772 .createNewContextForAPI
= driCreateNewContextForAPI
,
773 .createContextAttribs
= driCreateContextAttribs
,
774 .createNewScreen2
= driSWRastCreateNewScreen2
,
777 const __DRI2configQueryExtension dri2ConfigQueryExtension
= {
778 .base
= { __DRI2_CONFIG_QUERY
, 1 },
780 .configQueryb
= dri2ConfigQueryb
,
781 .configQueryi
= dri2ConfigQueryi
,
782 .configQueryf
= dri2ConfigQueryf
,
786 dri2InvalidateDrawable(__DRIdrawable
*drawable
)
788 drawable
->dri2
.stamp
++;
792 * Check that the gl_framebuffer associated with dPriv is the right size.
793 * Resize the gl_framebuffer if needed.
794 * It's expected that the dPriv->driverPrivate member points to a
795 * gl_framebuffer object.
798 driUpdateFramebufferSize(struct gl_context
*ctx
, const __DRIdrawable
*dPriv
)
800 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) dPriv
->driverPrivate
;
801 if (fb
&& (dPriv
->w
!= fb
->Width
|| dPriv
->h
!= fb
->Height
)) {
802 ctx
->Driver
.ResizeBuffers(ctx
, fb
, dPriv
->w
, dPriv
->h
);
803 /* if the driver needs the hw lock for ResizeBuffers, the drawable
804 might have changed again by now */
805 assert(fb
->Width
== dPriv
->w
);
806 assert(fb
->Height
== dPriv
->h
);
811 driGLFormatToImageFormat(mesa_format format
)
814 case MESA_FORMAT_B5G6R5_UNORM
:
815 return __DRI_IMAGE_FORMAT_RGB565
;
816 case MESA_FORMAT_B8G8R8X8_UNORM
:
817 return __DRI_IMAGE_FORMAT_XRGB8888
;
818 case MESA_FORMAT_B10G10R10A2_UNORM
:
819 return __DRI_IMAGE_FORMAT_ARGB2101010
;
820 case MESA_FORMAT_B10G10R10X2_UNORM
:
821 return __DRI_IMAGE_FORMAT_XRGB2101010
;
822 case MESA_FORMAT_B8G8R8A8_UNORM
:
823 return __DRI_IMAGE_FORMAT_ARGB8888
;
824 case MESA_FORMAT_R8G8B8A8_UNORM
:
825 return __DRI_IMAGE_FORMAT_ABGR8888
;
826 case MESA_FORMAT_R8G8B8X8_UNORM
:
827 return __DRI_IMAGE_FORMAT_XBGR8888
;
828 case MESA_FORMAT_R_UNORM8
:
829 return __DRI_IMAGE_FORMAT_R8
;
830 case MESA_FORMAT_R8G8_UNORM
:
831 return __DRI_IMAGE_FORMAT_GR88
;
832 case MESA_FORMAT_NONE
:
833 return __DRI_IMAGE_FORMAT_NONE
;
834 case MESA_FORMAT_B8G8R8A8_SRGB
:
835 return __DRI_IMAGE_FORMAT_SARGB8
;
842 driImageFormatToGLFormat(uint32_t image_format
)
844 switch (image_format
) {
845 case __DRI_IMAGE_FORMAT_RGB565
:
846 return MESA_FORMAT_B5G6R5_UNORM
;
847 case __DRI_IMAGE_FORMAT_XRGB8888
:
848 return MESA_FORMAT_B8G8R8X8_UNORM
;
849 case __DRI_IMAGE_FORMAT_ARGB2101010
:
850 return MESA_FORMAT_B10G10R10A2_UNORM
;
851 case __DRI_IMAGE_FORMAT_XRGB2101010
:
852 return MESA_FORMAT_B10G10R10X2_UNORM
;
853 case __DRI_IMAGE_FORMAT_ARGB8888
:
854 return MESA_FORMAT_B8G8R8A8_UNORM
;
855 case __DRI_IMAGE_FORMAT_ABGR8888
:
856 return MESA_FORMAT_R8G8B8A8_UNORM
;
857 case __DRI_IMAGE_FORMAT_XBGR8888
:
858 return MESA_FORMAT_R8G8B8X8_UNORM
;
859 case __DRI_IMAGE_FORMAT_R8
:
860 return MESA_FORMAT_R_UNORM8
;
861 case __DRI_IMAGE_FORMAT_GR88
:
862 return MESA_FORMAT_R8G8_UNORM
;
863 case __DRI_IMAGE_FORMAT_SARGB8
:
864 return MESA_FORMAT_B8G8R8A8_SRGB
;
865 case __DRI_IMAGE_FORMAT_NONE
:
866 return MESA_FORMAT_NONE
;
868 return MESA_FORMAT_NONE
;
872 /** Image driver interface */
873 const __DRIimageDriverExtension driImageDriverExtension
= {
874 .base
= { __DRI_IMAGE_DRIVER
, 1 },
876 .createNewScreen2
= driCreateNewScreen2
,
877 .createNewDrawable
= driCreateNewDrawable
,
878 .getAPIMask
= driGetAPIMask
,
879 .createContextAttribs
= driCreateContextAttribs
,
882 /* swrast copy sub buffer entrypoint. */
883 static void driCopySubBuffer(__DRIdrawable
*pdp
, int x
, int y
,
886 assert(pdp
->driScreenPriv
->swrast_loader
);
888 pdp
->driScreenPriv
->driver
->CopySubBuffer(pdp
, x
, y
, w
, h
);
891 /* for swrast only */
892 const __DRIcopySubBufferExtension driCopySubBufferExtension
= {
893 .base
= { __DRI_COPY_SUB_BUFFER
, 1 },
895 .copySubBuffer
= driCopySubBuffer
,