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
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_SWRAST_LOADER) == 0)
79 psp->swrast_loader = (__DRIswrastLoaderExtension *) extensions[i];
80 if (strcmp(extensions[i]->name, __DRI_IMAGE_LOADER) == 0)
81 psp->image.loader = (__DRIimageLoaderExtension *) extensions[i];
86 * This pointer determines which driver API we'll use in the case of the
87 * loader not passing us an explicit driver extensions list (that would,
88 * itself, contain a pointer to a driver API.)
90 * A driver's driDriverGetExtensions_drivername() can update this pointer to
91 * what it's returning, and a loader that is ignorant of createNewScreen2()
92 * will get the correct driver screen created, as long as no other
93 * driDriverGetExtensions() happened in between the first one and the
96 * This allows the X Server to not require the significant dri_interface.h
97 * updates for doing createNewScreen2(), which would discourage backporting of
98 * the X Server patches to support the new loader interface.
100 const struct __DriverAPIRec *globalDriverAPI = &driDriverAPI;
103 * This is the first entrypoint in the driver called by the DRI driver loader
104 * after dlopen()ing it.
106 * It's used to create global state for the driver across contexts on the same
110 driCreateNewScreen2(int scrn, int fd,
111 const __DRIextension **extensions,
112 const __DRIextension **driver_extensions,
113 const __DRIconfig ***driver_configs, void *data)
115 static const __DRIextension *emptyExtensionList[] = { NULL };
118 psp = calloc(1, sizeof(*psp));
122 /* By default, use the global driDriverAPI symbol (non-megadrivers). */
123 psp->driver = globalDriverAPI;
125 /* If the driver exposes its vtable through its extensions list
126 * (megadrivers), use that instead.
128 if (driver_extensions) {
129 for (int i = 0; driver_extensions[i]; i++) {
130 if (strcmp(driver_extensions[i]->name, __DRI_DRIVER_VTABLE) == 0) {
132 ((__DRIDriverVtableExtension *)driver_extensions[i])->vtable;
137 setupLoaderExtensions(psp, extensions);
139 psp->loaderPrivate = data;
141 psp->extensions = emptyExtensionList;
145 *driver_configs = psp->driver->InitScreen(psp);
146 if (*driver_configs == NULL) {
151 struct gl_constants consts = { 0 };
156 if (_mesa_override_gl_version_contextless(&consts, &api, &version))
157 psp->max_gl_es2_version = version;
159 api = API_OPENGL_COMPAT;
160 if (_mesa_override_gl_version_contextless(&consts, &api, &version)) {
161 if (api == API_OPENGL_CORE) {
162 psp->max_gl_core_version = version;
164 psp->max_gl_compat_version = version;
169 if (psp->max_gl_compat_version > 0)
170 psp->api_mask |= (1 << __DRI_API_OPENGL);
171 if (psp->max_gl_core_version > 0)
172 psp->api_mask |= (1 << __DRI_API_OPENGL_CORE);
173 if (psp->max_gl_es1_version > 0)
174 psp->api_mask |= (1 << __DRI_API_GLES);
175 if (psp->max_gl_es2_version > 0)
176 psp->api_mask |= (1 << __DRI_API_GLES2);
177 if (psp->max_gl_es2_version >= 30)
178 psp->api_mask |= (1 << __DRI_API_GLES3);
180 driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions);
181 driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, "dri2");
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 unsigned major_version = 1;
304 unsigned minor_version = 0;
306 bool notify_reset = false;
308 assert((num_attribs == 0) || (attribs != NULL));
310 if (!(screen->api_mask & (1 << api))) {
311 *error = __DRI_CTX_ERROR_BAD_API;
316 case __DRI_API_OPENGL:
317 mesa_api = API_OPENGL_COMPAT;
320 mesa_api = API_OPENGLES;
322 case __DRI_API_GLES2:
323 case __DRI_API_GLES3:
324 mesa_api = API_OPENGLES2;
326 case __DRI_API_OPENGL_CORE:
327 mesa_api = API_OPENGL_CORE;
330 *error = __DRI_CTX_ERROR_BAD_API;
334 for (unsigned i = 0; i < num_attribs; i++) {
335 switch (attribs[i * 2]) {
336 case __DRI_CTX_ATTRIB_MAJOR_VERSION:
337 major_version = attribs[i * 2 + 1];
339 case __DRI_CTX_ATTRIB_MINOR_VERSION:
340 minor_version = attribs[i * 2 + 1];
342 case __DRI_CTX_ATTRIB_FLAGS:
343 flags = attribs[i * 2 + 1];
345 case __DRI_CTX_ATTRIB_RESET_STRATEGY:
346 notify_reset = (attribs[i * 2 + 1]
347 != __DRI_CTX_RESET_NO_NOTIFICATION);
350 /* We can't create a context that satisfies the requirements of an
351 * attribute that we don't understand. Return failure.
353 assert(!"Should not get here.");
354 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
359 /* Mesa does not support the GL_ARB_compatibilty extension or the
360 * compatibility profile. This means that we treat a API_OPENGL_COMPAT 3.1 as
361 * API_OPENGL_CORE and reject API_OPENGL_COMPAT 3.2+.
363 if (mesa_api == API_OPENGL_COMPAT && major_version == 3 && minor_version == 1)
364 mesa_api = API_OPENGL_CORE;
366 if (mesa_api == API_OPENGL_COMPAT
367 && ((major_version > 3)
368 || (major_version == 3 && minor_version >= 2))) {
369 *error = __DRI_CTX_ERROR_BAD_API;
373 /* The latest version of EGL_KHR_create_context spec says:
375 * "If the EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR flag bit is set in
376 * EGL_CONTEXT_FLAGS_KHR, then a <debug context> will be created.
377 * [...] This bit is supported for OpenGL and OpenGL ES contexts.
379 * No other EGL_CONTEXT_OPENGL_*_BIT is legal for an ES context.
381 * However, Mesa's EGL layer translates the context attribute
382 * EGL_CONTEXT_OPENGL_ROBUST_ACCESS into the context flag
383 * __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS. That attribute is legal for ES
384 * (with EGL 1.5 or EGL_EXT_create_context_robustness) and GL (only with
387 * From the EGL_EXT_create_context_robustness spec:
389 * This extension is written against the OpenGL ES 2.0 Specification
390 * but can apply to OpenGL ES 1.1 and up.
392 * From the EGL 1.5 (2014.08.27) spec, p55:
394 * If the EGL_CONTEXT_OPENGL_ROBUST_ACCESS attribute is set to
395 * EGL_TRUE, a context supporting robust buffer access will be created.
396 * OpenGL contexts must support the GL_ARB_robustness extension, or
397 * equivalent core API functional- ity. OpenGL ES contexts must support
398 * the GL_EXT_robustness extension, or equivalent core API
401 if (mesa_api != API_OPENGL_COMPAT
402 && mesa_api != API_OPENGL_CORE
403 && (flags & ~(__DRI_CTX_FLAG_DEBUG |
404 __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS))) {
405 *error = __DRI_CTX_ERROR_BAD_FLAG;
409 /* There are no forward-compatible contexts before OpenGL 3.0. The
410 * GLX_ARB_create_context spec says:
412 * "Forward-compatible contexts are defined only for OpenGL versions
415 * Forward-looking contexts are supported by silently converting the
416 * requested API to API_OPENGL_CORE.
418 * In Mesa, a debug context is the same as a regular context.
420 if ((flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
421 mesa_api = API_OPENGL_CORE;
424 const uint32_t allowed_flags = (__DRI_CTX_FLAG_DEBUG
425 | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
426 | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS);
427 if (flags & ~allowed_flags) {
428 *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
432 if (!validate_context_version(screen, mesa_api,
433 major_version, minor_version, error))
436 context = calloc(1, sizeof *context);
438 *error = __DRI_CTX_ERROR_NO_MEMORY;
442 context->loaderPrivate = data;
444 context->driScreenPriv = screen;
445 context->driDrawablePriv = NULL;
446 context->driReadablePriv = NULL;
448 if (!screen->driver->CreateContext(mesa_api, modes, context,
449 major_version, minor_version,
450 flags, notify_reset, error, shareCtx)) {
455 *error = __DRI_CTX_ERROR_SUCCESS;
460 driContextSetFlags(struct gl_context *ctx, uint32_t flags)
462 if ((flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0)
463 ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
464 if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) {
465 _mesa_set_debug_state_int(ctx, GL_DEBUG_OUTPUT, GL_TRUE);
466 ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT;
470 static __DRIcontext *
471 driCreateNewContextForAPI(__DRIscreen *screen, int api,
472 const __DRIconfig *config,
473 __DRIcontext *shared, void *data)
477 return driCreateContextAttribs(screen, api, config, shared, 0, NULL,
481 static __DRIcontext *
482 driCreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
483 __DRIcontext *shared, void *data)
485 return driCreateNewContextForAPI(screen, __DRI_API_OPENGL,
486 config, shared, data);
490 * Destroy the per-context private information.
493 * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
494 * drmDestroyContext(), and finally frees \p contextPrivate.
497 driDestroyContext(__DRIcontext *pcp)
500 pcp->driScreenPriv->driver->DestroyContext(pcp);
506 driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask)
517 /*****************************************************************/
518 /** \name Context (un)binding functions */
519 /*****************************************************************/
522 static void dri_get_drawable(__DRIdrawable *pdp);
523 static void dri_put_drawable(__DRIdrawable *pdp);
526 * This function takes both a read buffer and a draw buffer. This is needed
527 * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
530 static int driBindContext(__DRIcontext *pcp,
535 ** Assume error checking is done properly in glXMakeCurrent before
536 ** calling driUnbindContext.
542 /* Bind the drawable to the context */
543 pcp->driDrawablePriv = pdp;
544 pcp->driReadablePriv = prp;
546 pdp->driContextPriv = pcp;
547 dri_get_drawable(pdp);
549 if (prp && pdp != prp) {
550 dri_get_drawable(prp);
553 return pcp->driScreenPriv->driver->MakeCurrent(pcp, pdp, prp);
559 * \param scrn the screen.
562 * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
565 * This function calls __DriverAPIRec::UnbindContext, and then decrements
566 * __DRIdrawableRec::refcount which must be non-zero for a successful
569 * While casting the opaque private pointers associated with the parameters
570 * into their respective real types it also assures they are not \c NULL.
572 static int driUnbindContext(__DRIcontext *pcp)
578 ** Assume error checking is done properly in glXMakeCurrent before
579 ** calling driUnbindContext.
586 ** Call driUnbindContext before checking for valid drawables
587 ** to handle surfaceless contexts properly.
589 pcp->driScreenPriv->driver->UnbindContext(pcp);
591 pdp = pcp->driDrawablePriv;
592 prp = pcp->driReadablePriv;
594 /* already unbound */
599 if (pdp->refcount == 0) {
604 dri_put_drawable(pdp);
607 if (prp->refcount == 0) {
612 dri_put_drawable(prp);
615 pcp->driDrawablePriv = NULL;
616 pcp->driReadablePriv = NULL;
624 static void dri_get_drawable(__DRIdrawable *pdp)
629 static void dri_put_drawable(__DRIdrawable *pdp)
636 pdp->driScreenPriv->driver->DestroyBuffer(pdp);
641 static __DRIdrawable *
642 driCreateNewDrawable(__DRIscreen *screen,
643 const __DRIconfig *config,
646 __DRIdrawable *pdraw;
648 assert(data != NULL);
650 pdraw = malloc(sizeof *pdraw);
654 pdraw->loaderPrivate = data;
656 pdraw->driScreenPriv = screen;
657 pdraw->driContextPriv = NULL;
659 pdraw->lastStamp = 0;
663 dri_get_drawable(pdraw);
665 if (!screen->driver->CreateBuffer(screen, pdraw, &config->modes,
671 pdraw->dri2.stamp = pdraw->lastStamp + 1;
677 driDestroyDrawable(__DRIdrawable *pdp)
680 * The loader's data structures are going away, even if pdp itself stays
681 * around for the time being because it is currently bound. This happens
682 * when a currently bound GLX pixmap is destroyed.
684 * Clear out the pointer back into the loader's data structures to avoid
685 * accessing an outdated pointer.
687 pdp->loaderPrivate = NULL;
689 dri_put_drawable(pdp);
693 dri2AllocateBuffer(__DRIscreen *screen,
694 unsigned int attachment, unsigned int format,
695 int width, int height)
697 return screen->driver->AllocateBuffer(screen, attachment, format,
702 dri2ReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
704 screen->driver->ReleaseBuffer(screen, buffer);
709 dri2ConfigQueryb(__DRIscreen *screen, const char *var, unsigned char *val)
711 if (!driCheckOption(&screen->optionCache, var, DRI_BOOL))
714 *val = driQueryOptionb(&screen->optionCache, var);
720 dri2ConfigQueryi(__DRIscreen *screen, const char *var, int *val)
722 if (!driCheckOption(&screen->optionCache, var, DRI_INT) &&
723 !driCheckOption(&screen->optionCache, var, DRI_ENUM))
726 *val = driQueryOptioni(&screen->optionCache, var);
732 dri2ConfigQueryf(__DRIscreen *screen, const char *var, float *val)
734 if (!driCheckOption(&screen->optionCache, var, DRI_FLOAT))
737 *val = driQueryOptionf(&screen->optionCache, var);
743 driGetAPIMask(__DRIscreen *screen)
745 return screen->api_mask;
749 * swrast swapbuffers entrypoint.
751 * DRI2 implements this inside the loader with only flushes handled by the
755 driSwapBuffers(__DRIdrawable *pdp)
757 assert(pdp->driScreenPriv->swrast_loader);
759 pdp->driScreenPriv->driver->SwapBuffers(pdp);
762 /** Core interface */
763 const __DRIcoreExtension driCoreExtension = {
764 .base = { __DRI_CORE, 1 },
766 .createNewScreen = NULL,
767 .destroyScreen = driDestroyScreen,
768 .getExtensions = driGetExtensions,
769 .getConfigAttrib = driGetConfigAttrib,
770 .indexConfigAttrib = driIndexConfigAttrib,
771 .createNewDrawable = NULL,
772 .destroyDrawable = driDestroyDrawable,
773 .swapBuffers = driSwapBuffers, /* swrast */
774 .createNewContext = driCreateNewContext, /* swrast */
775 .copyContext = driCopyContext,
776 .destroyContext = driDestroyContext,
777 .bindContext = driBindContext,
778 .unbindContext = driUnbindContext
781 /** DRI2 interface */
782 const __DRIdri2Extension driDRI2Extension = {
783 .base = { __DRI_DRI2, 4 },
785 .createNewScreen = dri2CreateNewScreen,
786 .createNewDrawable = driCreateNewDrawable,
787 .createNewContext = driCreateNewContext,
788 .getAPIMask = driGetAPIMask,
789 .createNewContextForAPI = driCreateNewContextForAPI,
790 .allocateBuffer = dri2AllocateBuffer,
791 .releaseBuffer = dri2ReleaseBuffer,
792 .createContextAttribs = driCreateContextAttribs,
793 .createNewScreen2 = driCreateNewScreen2,
796 __DRIswrastExtension driSWRastExtension = {
797 .base = { __DRI_SWRAST, __DRI_SWRAST_VERSION },
799 .createNewScreen = driSWRastCreateNewScreen,
800 .createNewDrawable = driCreateNewDrawable,
801 .createNewContextForAPI = driCreateNewContextForAPI,
802 .createContextAttribs = driCreateContextAttribs,
803 .createNewScreen2 = driSWRastCreateNewScreen2,
806 const __DRI2configQueryExtension dri2ConfigQueryExtension = {
807 .base = { __DRI2_CONFIG_QUERY, 1 },
809 .configQueryb = dri2ConfigQueryb,
810 .configQueryi = dri2ConfigQueryi,
811 .configQueryf = dri2ConfigQueryf,
815 dri2InvalidateDrawable(__DRIdrawable *drawable)
817 drawable->dri2.stamp++;
821 * Check that the gl_framebuffer associated with dPriv is the right size.
822 * Resize the gl_framebuffer if needed.
823 * It's expected that the dPriv->driverPrivate member points to a
824 * gl_framebuffer object.
827 driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv)
829 struct gl_framebuffer *fb = (struct gl_framebuffer *) dPriv->driverPrivate;
830 if (fb && (dPriv->w != fb->Width || dPriv->h != fb->Height)) {
831 _mesa_resize_framebuffer(ctx, fb, dPriv->w, dPriv->h);
832 /* if the driver needs the hw lock for ResizeBuffers, the drawable
833 might have changed again by now */
834 assert(fb->Width == dPriv->w);
835 assert(fb->Height == dPriv->h);
840 driGLFormatToImageFormat(mesa_format format)
843 case MESA_FORMAT_B5G6R5_UNORM:
844 return __DRI_IMAGE_FORMAT_RGB565;
845 case MESA_FORMAT_B5G5R5A1_UNORM:
846 return __DRI_IMAGE_FORMAT_ARGB1555;
847 case MESA_FORMAT_B8G8R8X8_UNORM:
848 return __DRI_IMAGE_FORMAT_XRGB8888;
849 case MESA_FORMAT_B10G10R10A2_UNORM:
850 return __DRI_IMAGE_FORMAT_ARGB2101010;
851 case MESA_FORMAT_B10G10R10X2_UNORM:
852 return __DRI_IMAGE_FORMAT_XRGB2101010;
853 case MESA_FORMAT_B8G8R8A8_UNORM:
854 return __DRI_IMAGE_FORMAT_ARGB8888;
855 case MESA_FORMAT_R8G8B8A8_UNORM:
856 return __DRI_IMAGE_FORMAT_ABGR8888;
857 case MESA_FORMAT_R8G8B8X8_UNORM:
858 return __DRI_IMAGE_FORMAT_XBGR8888;
859 case MESA_FORMAT_L_UNORM8:
860 case MESA_FORMAT_R_UNORM8:
861 return __DRI_IMAGE_FORMAT_R8;
862 case MESA_FORMAT_L8A8_UNORM:
863 case MESA_FORMAT_R8G8_UNORM:
864 return __DRI_IMAGE_FORMAT_GR88;
865 case MESA_FORMAT_NONE:
866 return __DRI_IMAGE_FORMAT_NONE;
867 case MESA_FORMAT_B8G8R8A8_SRGB:
868 return __DRI_IMAGE_FORMAT_SARGB8;
875 driImageFormatToGLFormat(uint32_t image_format)
877 switch (image_format) {
878 case __DRI_IMAGE_FORMAT_RGB565:
879 return MESA_FORMAT_B5G6R5_UNORM;
880 case __DRI_IMAGE_FORMAT_ARGB1555:
881 return MESA_FORMAT_B5G5R5A1_UNORM;
882 case __DRI_IMAGE_FORMAT_XRGB8888:
883 return MESA_FORMAT_B8G8R8X8_UNORM;
884 case __DRI_IMAGE_FORMAT_ARGB2101010:
885 return MESA_FORMAT_B10G10R10A2_UNORM;
886 case __DRI_IMAGE_FORMAT_XRGB2101010:
887 return MESA_FORMAT_B10G10R10X2_UNORM;
888 case __DRI_IMAGE_FORMAT_ARGB8888:
889 return MESA_FORMAT_B8G8R8A8_UNORM;
890 case __DRI_IMAGE_FORMAT_ABGR8888:
891 return MESA_FORMAT_R8G8B8A8_UNORM;
892 case __DRI_IMAGE_FORMAT_XBGR8888:
893 return MESA_FORMAT_R8G8B8X8_UNORM;
894 case __DRI_IMAGE_FORMAT_R8:
895 return MESA_FORMAT_R_UNORM8;
896 case __DRI_IMAGE_FORMAT_GR88:
897 return MESA_FORMAT_R8G8_UNORM;
898 case __DRI_IMAGE_FORMAT_SARGB8:
899 return MESA_FORMAT_B8G8R8A8_SRGB;
900 case __DRI_IMAGE_FORMAT_NONE:
901 return MESA_FORMAT_NONE;
903 return MESA_FORMAT_NONE;
907 /** Image driver interface */
908 const __DRIimageDriverExtension driImageDriverExtension = {
909 .base = { __DRI_IMAGE_DRIVER, 1 },
911 .createNewScreen2 = driCreateNewScreen2,
912 .createNewDrawable = driCreateNewDrawable,
913 .getAPIMask = driGetAPIMask,
914 .createContextAttribs = driCreateContextAttribs,
917 /* swrast copy sub buffer entrypoint. */
918 static void driCopySubBuffer(__DRIdrawable *pdp, int x, int y,
921 assert(pdp->driScreenPriv->swrast_loader);
923 pdp->driScreenPriv->driver->CopySubBuffer(pdp, x, y, w, h);
926 /* for swrast only */
927 const __DRIcopySubBufferExtension driCopySubBufferExtension = {
928 .base = { __DRI_COPY_SUB_BUFFER, 1 },
930 .copySubBuffer = driCopySubBuffer,