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_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 *driver_configs
= psp
->driver
->InitScreen(psp
);
148 if (*driver_configs
== NULL
) {
153 struct gl_constants consts
= { 0 };
158 if (_mesa_override_gl_version_contextless(&consts
, &api
, &version
))
159 psp
->max_gl_es2_version
= version
;
161 api
= API_OPENGL_COMPAT
;
162 if (_mesa_override_gl_version_contextless(&consts
, &api
, &version
)) {
163 if (api
== API_OPENGL_CORE
) {
164 psp
->max_gl_core_version
= version
;
166 psp
->max_gl_compat_version
= version
;
171 if (psp
->max_gl_compat_version
> 0)
172 psp
->api_mask
|= (1 << __DRI_API_OPENGL
);
173 if (psp
->max_gl_core_version
> 0)
174 psp
->api_mask
|= (1 << __DRI_API_OPENGL_CORE
);
175 if (psp
->max_gl_es1_version
> 0)
176 psp
->api_mask
|= (1 << __DRI_API_GLES
);
177 if (psp
->max_gl_es2_version
> 0)
178 psp
->api_mask
|= (1 << __DRI_API_GLES2
);
179 if (psp
->max_gl_es2_version
>= 30)
180 psp
->api_mask
|= (1 << __DRI_API_GLES3
);
182 driParseOptionInfo(&psp
->optionInfo
, __dri2ConfigOptions
);
183 driParseConfigFiles(&psp
->optionCache
, &psp
->optionInfo
, psp
->myNum
, "dri2");
190 dri2CreateNewScreen(int scrn
, int fd
,
191 const __DRIextension
**extensions
,
192 const __DRIconfig
***driver_configs
, void *data
)
194 return driCreateNewScreen2(scrn
, fd
, extensions
, NULL
,
195 driver_configs
, data
);
198 /** swrast driver createNewScreen entrypoint. */
200 driSWRastCreateNewScreen(int scrn
, const __DRIextension
**extensions
,
201 const __DRIconfig
***driver_configs
, void *data
)
203 return driCreateNewScreen2(scrn
, -1, extensions
, NULL
,
204 driver_configs
, data
);
208 driSWRastCreateNewScreen2(int scrn
, const __DRIextension
**extensions
,
209 const __DRIextension
**driver_extensions
,
210 const __DRIconfig
***driver_configs
, void *data
)
212 return driCreateNewScreen2(scrn
, -1, extensions
, driver_extensions
,
213 driver_configs
, data
);
217 * Destroy the per-screen private information.
220 * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
221 * drmClose(), and finally frees \p screenPrivate.
223 static void driDestroyScreen(__DRIscreen
*psp
)
226 /* No interaction with the X-server is possible at this point. This
227 * routine is called after XCloseDisplay, so there is no protocol
228 * stream open to the X-server anymore.
231 psp
->driver
->DestroyScreen(psp
);
233 driDestroyOptionCache(&psp
->optionCache
);
234 driDestroyOptionInfo(&psp
->optionInfo
);
240 static const __DRIextension
**driGetExtensions(__DRIscreen
*psp
)
242 return psp
->extensions
;
249 validate_context_version(__DRIscreen
*screen
,
251 unsigned major_version
,
252 unsigned minor_version
,
253 unsigned *dri_ctx_error
)
255 unsigned req_version
= 10 * major_version
+ minor_version
;
256 unsigned max_version
= 0;
259 case API_OPENGL_COMPAT
:
260 max_version
= screen
->max_gl_compat_version
;
262 case API_OPENGL_CORE
:
263 max_version
= screen
->max_gl_core_version
;
266 max_version
= screen
->max_gl_es1_version
;
269 max_version
= screen
->max_gl_es2_version
;
276 if (max_version
== 0) {
277 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_API
;
279 } else if (req_version
> max_version
) {
280 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_VERSION
;
287 /*****************************************************************/
288 /** \name Context handling functions */
289 /*****************************************************************/
292 static __DRIcontext
*
293 driCreateContextAttribs(__DRIscreen
*screen
, int api
,
294 const __DRIconfig
*config
,
295 __DRIcontext
*shared
,
296 unsigned num_attribs
,
297 const uint32_t *attribs
,
301 __DRIcontext
*context
;
302 const struct gl_config
*modes
= (config
!= NULL
) ? &config
->modes
: NULL
;
303 void *shareCtx
= (shared
!= NULL
) ? shared
->driverPrivate
: NULL
;
305 unsigned major_version
= 1;
306 unsigned minor_version
= 0;
308 bool notify_reset
= false;
310 assert((num_attribs
== 0) || (attribs
!= NULL
));
312 if (!(screen
->api_mask
& (1 << api
))) {
313 *error
= __DRI_CTX_ERROR_BAD_API
;
318 case __DRI_API_OPENGL
:
319 mesa_api
= API_OPENGL_COMPAT
;
322 mesa_api
= API_OPENGLES
;
324 case __DRI_API_GLES2
:
325 case __DRI_API_GLES3
:
326 mesa_api
= API_OPENGLES2
;
328 case __DRI_API_OPENGL_CORE
:
329 mesa_api
= API_OPENGL_CORE
;
332 *error
= __DRI_CTX_ERROR_BAD_API
;
336 for (unsigned i
= 0; i
< num_attribs
; i
++) {
337 switch (attribs
[i
* 2]) {
338 case __DRI_CTX_ATTRIB_MAJOR_VERSION
:
339 major_version
= attribs
[i
* 2 + 1];
341 case __DRI_CTX_ATTRIB_MINOR_VERSION
:
342 minor_version
= attribs
[i
* 2 + 1];
344 case __DRI_CTX_ATTRIB_FLAGS
:
345 flags
= attribs
[i
* 2 + 1];
347 case __DRI_CTX_ATTRIB_RESET_STRATEGY
:
348 notify_reset
= (attribs
[i
* 2 + 1]
349 != __DRI_CTX_RESET_NO_NOTIFICATION
);
352 /* We can't create a context that satisfies the requirements of an
353 * attribute that we don't understand. Return failure.
355 assert(!"Should not get here.");
356 *error
= __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
;
361 /* Mesa does not support the GL_ARB_compatibilty extension or the
362 * compatibility profile. This means that we treat a API_OPENGL_COMPAT 3.1 as
363 * API_OPENGL_CORE and reject API_OPENGL_COMPAT 3.2+.
365 if (mesa_api
== API_OPENGL_COMPAT
&& major_version
== 3 && minor_version
== 1)
366 mesa_api
= API_OPENGL_CORE
;
368 if (mesa_api
== API_OPENGL_COMPAT
369 && ((major_version
> 3)
370 || (major_version
== 3 && minor_version
>= 2))) {
371 *error
= __DRI_CTX_ERROR_BAD_API
;
375 /* The latest version of EGL_KHR_create_context spec says:
377 * "If the EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR flag bit is set in
378 * EGL_CONTEXT_FLAGS_KHR, then a <debug context> will be created.
379 * [...] This bit is supported for OpenGL and OpenGL ES contexts.
381 * No other EGL_CONTEXT_OPENGL_*_BIT is legal for an ES context.
383 * However, Mesa's EGL layer translates the context attribute
384 * EGL_CONTEXT_OPENGL_ROBUST_ACCESS into the context flag
385 * __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS. That attribute is legal for ES
386 * (with EGL 1.5 or EGL_EXT_create_context_robustness) and GL (only with
389 * From the EGL_EXT_create_context_robustness spec:
391 * This extension is written against the OpenGL ES 2.0 Specification
392 * but can apply to OpenGL ES 1.1 and up.
394 * From the EGL 1.5 (2014.08.27) spec, p55:
396 * If the EGL_CONTEXT_OPENGL_ROBUST_ACCESS attribute is set to
397 * EGL_TRUE, a context supporting robust buffer access will be created.
398 * OpenGL contexts must support the GL_ARB_robustness extension, or
399 * equivalent core API functional- ity. OpenGL ES contexts must support
400 * the GL_EXT_robustness extension, or equivalent core API
403 if (mesa_api
!= API_OPENGL_COMPAT
404 && mesa_api
!= API_OPENGL_CORE
405 && (flags
& ~(__DRI_CTX_FLAG_DEBUG
|
406 __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
|
407 __DRI_CTX_FLAG_NO_ERROR
))) {
408 *error
= __DRI_CTX_ERROR_BAD_FLAG
;
412 /* There are no forward-compatible contexts before OpenGL 3.0. The
413 * GLX_ARB_create_context spec says:
415 * "Forward-compatible contexts are defined only for OpenGL versions
418 * Forward-looking contexts are supported by silently converting the
419 * requested API to API_OPENGL_CORE.
421 * In Mesa, a debug context is the same as a regular context.
423 if ((flags
& __DRI_CTX_FLAG_FORWARD_COMPATIBLE
) != 0) {
424 mesa_api
= API_OPENGL_CORE
;
427 const uint32_t allowed_flags
= (__DRI_CTX_FLAG_DEBUG
428 | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
429 | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
430 | __DRI_CTX_FLAG_NO_ERROR
);
431 if (flags
& ~allowed_flags
) {
432 *error
= __DRI_CTX_ERROR_UNKNOWN_FLAG
;
436 if (!validate_context_version(screen
, mesa_api
,
437 major_version
, minor_version
, error
))
440 context
= calloc(1, sizeof *context
);
442 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
446 context
->loaderPrivate
= data
;
448 context
->driScreenPriv
= screen
;
449 context
->driDrawablePriv
= NULL
;
450 context
->driReadablePriv
= NULL
;
452 if (!screen
->driver
->CreateContext(mesa_api
, modes
, context
,
453 major_version
, minor_version
,
454 flags
, notify_reset
, error
, shareCtx
)) {
459 *error
= __DRI_CTX_ERROR_SUCCESS
;
464 driContextSetFlags(struct gl_context
*ctx
, uint32_t flags
)
466 if ((flags
& __DRI_CTX_FLAG_FORWARD_COMPATIBLE
) != 0)
467 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
468 if ((flags
& __DRI_CTX_FLAG_DEBUG
) != 0) {
469 _mesa_set_debug_state_int(ctx
, GL_DEBUG_OUTPUT
, GL_TRUE
);
470 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_DEBUG_BIT
;
472 if ((flags
& __DRI_CTX_FLAG_NO_ERROR
) != 0)
473 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
;
476 static __DRIcontext
*
477 driCreateNewContextForAPI(__DRIscreen
*screen
, int api
,
478 const __DRIconfig
*config
,
479 __DRIcontext
*shared
, void *data
)
483 return driCreateContextAttribs(screen
, api
, config
, shared
, 0, NULL
,
487 static __DRIcontext
*
488 driCreateNewContext(__DRIscreen
*screen
, const __DRIconfig
*config
,
489 __DRIcontext
*shared
, void *data
)
491 return driCreateNewContextForAPI(screen
, __DRI_API_OPENGL
,
492 config
, shared
, data
);
496 * Destroy the per-context private information.
499 * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
500 * drmDestroyContext(), and finally frees \p contextPrivate.
503 driDestroyContext(__DRIcontext
*pcp
)
506 pcp
->driScreenPriv
->driver
->DestroyContext(pcp
);
512 driCopyContext(__DRIcontext
*dest
, __DRIcontext
*src
, unsigned long mask
)
523 /*****************************************************************/
524 /** \name Context (un)binding functions */
525 /*****************************************************************/
528 static void dri_get_drawable(__DRIdrawable
*pdp
);
529 static void dri_put_drawable(__DRIdrawable
*pdp
);
532 * This function takes both a read buffer and a draw buffer. This is needed
533 * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
536 static int driBindContext(__DRIcontext
*pcp
,
541 ** Assume error checking is done properly in glXMakeCurrent before
542 ** calling driUnbindContext.
548 /* Bind the drawable to the context */
549 pcp
->driDrawablePriv
= pdp
;
550 pcp
->driReadablePriv
= prp
;
552 pdp
->driContextPriv
= pcp
;
553 dri_get_drawable(pdp
);
555 if (prp
&& pdp
!= prp
) {
556 dri_get_drawable(prp
);
559 return pcp
->driScreenPriv
->driver
->MakeCurrent(pcp
, pdp
, prp
);
565 * \param scrn the screen.
568 * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
571 * This function calls __DriverAPIRec::UnbindContext, and then decrements
572 * __DRIdrawableRec::refcount which must be non-zero for a successful
575 * While casting the opaque private pointers associated with the parameters
576 * into their respective real types it also assures they are not \c NULL.
578 static int driUnbindContext(__DRIcontext
*pcp
)
584 ** Assume error checking is done properly in glXMakeCurrent before
585 ** calling driUnbindContext.
592 ** Call driUnbindContext before checking for valid drawables
593 ** to handle surfaceless contexts properly.
595 pcp
->driScreenPriv
->driver
->UnbindContext(pcp
);
597 pdp
= pcp
->driDrawablePriv
;
598 prp
= pcp
->driReadablePriv
;
600 /* already unbound */
605 if (pdp
->refcount
== 0) {
610 dri_put_drawable(pdp
);
613 if (prp
->refcount
== 0) {
618 dri_put_drawable(prp
);
621 pcp
->driDrawablePriv
= NULL
;
622 pcp
->driReadablePriv
= NULL
;
630 static void dri_get_drawable(__DRIdrawable
*pdp
)
635 static void dri_put_drawable(__DRIdrawable
*pdp
)
642 pdp
->driScreenPriv
->driver
->DestroyBuffer(pdp
);
647 static __DRIdrawable
*
648 driCreateNewDrawable(__DRIscreen
*screen
,
649 const __DRIconfig
*config
,
652 __DRIdrawable
*pdraw
;
654 assert(data
!= NULL
);
656 pdraw
= malloc(sizeof *pdraw
);
660 pdraw
->loaderPrivate
= data
;
662 pdraw
->driScreenPriv
= screen
;
663 pdraw
->driContextPriv
= NULL
;
665 pdraw
->lastStamp
= 0;
669 dri_get_drawable(pdraw
);
671 if (!screen
->driver
->CreateBuffer(screen
, pdraw
, &config
->modes
,
677 pdraw
->dri2
.stamp
= pdraw
->lastStamp
+ 1;
683 driDestroyDrawable(__DRIdrawable
*pdp
)
686 * The loader's data structures are going away, even if pdp itself stays
687 * around for the time being because it is currently bound. This happens
688 * when a currently bound GLX pixmap is destroyed.
690 * Clear out the pointer back into the loader's data structures to avoid
691 * accessing an outdated pointer.
693 pdp
->loaderPrivate
= NULL
;
695 dri_put_drawable(pdp
);
699 dri2AllocateBuffer(__DRIscreen
*screen
,
700 unsigned int attachment
, unsigned int format
,
701 int width
, int height
)
703 return screen
->driver
->AllocateBuffer(screen
, attachment
, format
,
708 dri2ReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
710 screen
->driver
->ReleaseBuffer(screen
, buffer
);
715 dri2ConfigQueryb(__DRIscreen
*screen
, const char *var
, unsigned char *val
)
717 if (!driCheckOption(&screen
->optionCache
, var
, DRI_BOOL
))
720 *val
= driQueryOptionb(&screen
->optionCache
, var
);
726 dri2ConfigQueryi(__DRIscreen
*screen
, const char *var
, int *val
)
728 if (!driCheckOption(&screen
->optionCache
, var
, DRI_INT
) &&
729 !driCheckOption(&screen
->optionCache
, var
, DRI_ENUM
))
732 *val
= driQueryOptioni(&screen
->optionCache
, var
);
738 dri2ConfigQueryf(__DRIscreen
*screen
, const char *var
, float *val
)
740 if (!driCheckOption(&screen
->optionCache
, var
, DRI_FLOAT
))
743 *val
= driQueryOptionf(&screen
->optionCache
, var
);
749 driGetAPIMask(__DRIscreen
*screen
)
751 return screen
->api_mask
;
755 * swrast swapbuffers entrypoint.
757 * DRI2 implements this inside the loader with only flushes handled by the
761 driSwapBuffers(__DRIdrawable
*pdp
)
763 assert(pdp
->driScreenPriv
->swrast_loader
);
765 pdp
->driScreenPriv
->driver
->SwapBuffers(pdp
);
768 /** Core interface */
769 const __DRIcoreExtension driCoreExtension
= {
770 .base
= { __DRI_CORE
, 1 },
772 .createNewScreen
= NULL
,
773 .destroyScreen
= driDestroyScreen
,
774 .getExtensions
= driGetExtensions
,
775 .getConfigAttrib
= driGetConfigAttrib
,
776 .indexConfigAttrib
= driIndexConfigAttrib
,
777 .createNewDrawable
= NULL
,
778 .destroyDrawable
= driDestroyDrawable
,
779 .swapBuffers
= driSwapBuffers
, /* swrast */
780 .createNewContext
= driCreateNewContext
, /* swrast */
781 .copyContext
= driCopyContext
,
782 .destroyContext
= driDestroyContext
,
783 .bindContext
= driBindContext
,
784 .unbindContext
= driUnbindContext
787 /** DRI2 interface */
788 const __DRIdri2Extension driDRI2Extension
= {
789 .base
= { __DRI_DRI2
, 4 },
791 .createNewScreen
= dri2CreateNewScreen
,
792 .createNewDrawable
= driCreateNewDrawable
,
793 .createNewContext
= driCreateNewContext
,
794 .getAPIMask
= driGetAPIMask
,
795 .createNewContextForAPI
= driCreateNewContextForAPI
,
796 .allocateBuffer
= dri2AllocateBuffer
,
797 .releaseBuffer
= dri2ReleaseBuffer
,
798 .createContextAttribs
= driCreateContextAttribs
,
799 .createNewScreen2
= driCreateNewScreen2
,
802 const __DRIswrastExtension driSWRastExtension
= {
803 .base
= { __DRI_SWRAST
, 4 },
805 .createNewScreen
= driSWRastCreateNewScreen
,
806 .createNewDrawable
= driCreateNewDrawable
,
807 .createNewContextForAPI
= driCreateNewContextForAPI
,
808 .createContextAttribs
= driCreateContextAttribs
,
809 .createNewScreen2
= driSWRastCreateNewScreen2
,
812 const __DRI2configQueryExtension dri2ConfigQueryExtension
= {
813 .base
= { __DRI2_CONFIG_QUERY
, 1 },
815 .configQueryb
= dri2ConfigQueryb
,
816 .configQueryi
= dri2ConfigQueryi
,
817 .configQueryf
= dri2ConfigQueryf
,
821 dri2InvalidateDrawable(__DRIdrawable
*drawable
)
823 drawable
->dri2
.stamp
++;
827 * Check that the gl_framebuffer associated with dPriv is the right size.
828 * Resize the gl_framebuffer if needed.
829 * It's expected that the dPriv->driverPrivate member points to a
830 * gl_framebuffer object.
833 driUpdateFramebufferSize(struct gl_context
*ctx
, const __DRIdrawable
*dPriv
)
835 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) dPriv
->driverPrivate
;
836 if (fb
&& (dPriv
->w
!= fb
->Width
|| dPriv
->h
!= fb
->Height
)) {
837 _mesa_resize_framebuffer(ctx
, fb
, dPriv
->w
, dPriv
->h
);
838 /* if the driver needs the hw lock for ResizeBuffers, the drawable
839 might have changed again by now */
840 assert(fb
->Width
== dPriv
->w
);
841 assert(fb
->Height
== dPriv
->h
);
846 driGLFormatToImageFormat(mesa_format format
)
849 case MESA_FORMAT_B5G6R5_UNORM
:
850 return __DRI_IMAGE_FORMAT_RGB565
;
851 case MESA_FORMAT_B5G5R5A1_UNORM
:
852 return __DRI_IMAGE_FORMAT_ARGB1555
;
853 case MESA_FORMAT_B8G8R8X8_UNORM
:
854 return __DRI_IMAGE_FORMAT_XRGB8888
;
855 case MESA_FORMAT_B10G10R10A2_UNORM
:
856 return __DRI_IMAGE_FORMAT_ARGB2101010
;
857 case MESA_FORMAT_B10G10R10X2_UNORM
:
858 return __DRI_IMAGE_FORMAT_XRGB2101010
;
859 case MESA_FORMAT_B8G8R8A8_UNORM
:
860 return __DRI_IMAGE_FORMAT_ARGB8888
;
861 case MESA_FORMAT_R8G8B8A8_UNORM
:
862 return __DRI_IMAGE_FORMAT_ABGR8888
;
863 case MESA_FORMAT_R8G8B8X8_UNORM
:
864 return __DRI_IMAGE_FORMAT_XBGR8888
;
865 case MESA_FORMAT_L_UNORM8
:
866 case MESA_FORMAT_R_UNORM8
:
867 return __DRI_IMAGE_FORMAT_R8
;
868 case MESA_FORMAT_L8A8_UNORM
:
869 case MESA_FORMAT_R8G8_UNORM
:
870 return __DRI_IMAGE_FORMAT_GR88
;
871 case MESA_FORMAT_NONE
:
872 return __DRI_IMAGE_FORMAT_NONE
;
873 case MESA_FORMAT_B8G8R8A8_SRGB
:
874 return __DRI_IMAGE_FORMAT_SARGB8
;
881 driImageFormatToGLFormat(uint32_t image_format
)
883 switch (image_format
) {
884 case __DRI_IMAGE_FORMAT_RGB565
:
885 return MESA_FORMAT_B5G6R5_UNORM
;
886 case __DRI_IMAGE_FORMAT_ARGB1555
:
887 return MESA_FORMAT_B5G5R5A1_UNORM
;
888 case __DRI_IMAGE_FORMAT_XRGB8888
:
889 return MESA_FORMAT_B8G8R8X8_UNORM
;
890 case __DRI_IMAGE_FORMAT_ARGB2101010
:
891 return MESA_FORMAT_B10G10R10A2_UNORM
;
892 case __DRI_IMAGE_FORMAT_XRGB2101010
:
893 return MESA_FORMAT_B10G10R10X2_UNORM
;
894 case __DRI_IMAGE_FORMAT_ARGB8888
:
895 return MESA_FORMAT_B8G8R8A8_UNORM
;
896 case __DRI_IMAGE_FORMAT_ABGR8888
:
897 return MESA_FORMAT_R8G8B8A8_UNORM
;
898 case __DRI_IMAGE_FORMAT_XBGR8888
:
899 return MESA_FORMAT_R8G8B8X8_UNORM
;
900 case __DRI_IMAGE_FORMAT_R8
:
901 return MESA_FORMAT_R_UNORM8
;
902 case __DRI_IMAGE_FORMAT_R16
:
903 return MESA_FORMAT_R_UNORM16
;
904 case __DRI_IMAGE_FORMAT_GR88
:
905 return MESA_FORMAT_R8G8_UNORM
;
906 case __DRI_IMAGE_FORMAT_GR1616
:
907 return MESA_FORMAT_R16G16_UNORM
;
908 case __DRI_IMAGE_FORMAT_SARGB8
:
909 return MESA_FORMAT_B8G8R8A8_SRGB
;
910 case __DRI_IMAGE_FORMAT_NONE
:
911 return MESA_FORMAT_NONE
;
913 return MESA_FORMAT_NONE
;
917 /** Image driver interface */
918 const __DRIimageDriverExtension driImageDriverExtension
= {
919 .base
= { __DRI_IMAGE_DRIVER
, 1 },
921 .createNewScreen2
= driCreateNewScreen2
,
922 .createNewDrawable
= driCreateNewDrawable
,
923 .getAPIMask
= driGetAPIMask
,
924 .createContextAttribs
= driCreateContextAttribs
,
927 /* swrast copy sub buffer entrypoint. */
928 static void driCopySubBuffer(__DRIdrawable
*pdp
, int x
, int y
,
931 assert(pdp
->driScreenPriv
->swrast_loader
);
933 pdp
->driScreenPriv
->driver
->CopySubBuffer(pdp
, x
, y
, w
, h
);
936 /* for swrast only */
937 const __DRIcopySubBufferExtension driCopySubBufferExtension
= {
938 .base
= { __DRI_COPY_SUB_BUFFER
, 1 },
940 .copySubBuffer
= driCopySubBuffer
,
943 const __DRInoErrorExtension dri2NoErrorExtension
= {
944 .base
= { __DRI2_NO_ERROR
, 1 },