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 *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 struct __DriverContextConfig ctx_config
;
307 ctx_config
.major_version
= 1;
308 ctx_config
.minor_version
= 0;
309 ctx_config
.flags
= 0;
310 ctx_config
.attribute_mask
= 0;
311 ctx_config
.priority
= __DRI_CTX_PRIORITY_MEDIUM
;
313 assert((num_attribs
== 0) || (attribs
!= NULL
));
315 if (!(screen
->api_mask
& (1 << api
))) {
316 *error
= __DRI_CTX_ERROR_BAD_API
;
321 case __DRI_API_OPENGL
:
322 mesa_api
= API_OPENGL_COMPAT
;
325 mesa_api
= API_OPENGLES
;
327 case __DRI_API_GLES2
:
328 case __DRI_API_GLES3
:
329 mesa_api
= API_OPENGLES2
;
331 case __DRI_API_OPENGL_CORE
:
332 mesa_api
= API_OPENGL_CORE
;
335 *error
= __DRI_CTX_ERROR_BAD_API
;
339 for (unsigned i
= 0; i
< num_attribs
; i
++) {
340 switch (attribs
[i
* 2]) {
341 case __DRI_CTX_ATTRIB_MAJOR_VERSION
:
342 ctx_config
.major_version
= attribs
[i
* 2 + 1];
344 case __DRI_CTX_ATTRIB_MINOR_VERSION
:
345 ctx_config
.minor_version
= attribs
[i
* 2 + 1];
347 case __DRI_CTX_ATTRIB_FLAGS
:
348 ctx_config
.flags
= attribs
[i
* 2 + 1];
350 case __DRI_CTX_ATTRIB_RESET_STRATEGY
:
351 if (attribs
[i
* 2 + 1] != __DRI_CTX_RESET_NO_NOTIFICATION
) {
352 ctx_config
.attribute_mask
|=
353 __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY
;
354 ctx_config
.reset_strategy
= attribs
[i
* 2 + 1];
356 ctx_config
.attribute_mask
&=
357 ~__DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY
;
360 case __DRI_CTX_ATTRIB_PRIORITY
:
361 ctx_config
.attribute_mask
|= __DRIVER_CONTEXT_ATTRIB_PRIORITY
;
362 ctx_config
.priority
= attribs
[i
* 2 + 1];
365 /* We can't create a context that satisfies the requirements of an
366 * attribute that we don't understand. Return failure.
368 assert(!"Should not get here.");
369 *error
= __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
;
374 /* Mesa does not support the GL_ARB_compatibilty extension or the
375 * compatibility profile. This means that we treat a API_OPENGL_COMPAT 3.1 as
376 * API_OPENGL_CORE and reject API_OPENGL_COMPAT 3.2+.
378 if (mesa_api
== API_OPENGL_COMPAT
&&
379 ctx_config
.major_version
== 3 && ctx_config
.minor_version
== 1)
380 mesa_api
= API_OPENGL_CORE
;
382 if (mesa_api
== API_OPENGL_COMPAT
383 && ((ctx_config
.major_version
> 3)
384 || (ctx_config
.major_version
== 3 &&
385 ctx_config
.minor_version
>= 2))) {
386 *error
= __DRI_CTX_ERROR_BAD_API
;
390 /* The latest version of EGL_KHR_create_context spec says:
392 * "If the EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR flag bit is set in
393 * EGL_CONTEXT_FLAGS_KHR, then a <debug context> will be created.
394 * [...] This bit is supported for OpenGL and OpenGL ES contexts.
396 * No other EGL_CONTEXT_OPENGL_*_BIT is legal for an ES context.
398 * However, Mesa's EGL layer translates the context attribute
399 * EGL_CONTEXT_OPENGL_ROBUST_ACCESS into the context flag
400 * __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS. That attribute is legal for ES
401 * (with EGL 1.5 or EGL_EXT_create_context_robustness) and GL (only with
404 * From the EGL_EXT_create_context_robustness spec:
406 * This extension is written against the OpenGL ES 2.0 Specification
407 * but can apply to OpenGL ES 1.1 and up.
409 * From the EGL 1.5 (2014.08.27) spec, p55:
411 * If the EGL_CONTEXT_OPENGL_ROBUST_ACCESS attribute is set to
412 * EGL_TRUE, a context supporting robust buffer access will be created.
413 * OpenGL contexts must support the GL_ARB_robustness extension, or
414 * equivalent core API functional- ity. OpenGL ES contexts must support
415 * the GL_EXT_robustness extension, or equivalent core API
418 if (mesa_api
!= API_OPENGL_COMPAT
419 && mesa_api
!= API_OPENGL_CORE
420 && (ctx_config
.flags
& ~(__DRI_CTX_FLAG_DEBUG
|
421 __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
|
422 __DRI_CTX_FLAG_NO_ERROR
))) {
423 *error
= __DRI_CTX_ERROR_BAD_FLAG
;
427 /* There are no forward-compatible contexts before OpenGL 3.0. The
428 * GLX_ARB_create_context spec says:
430 * "Forward-compatible contexts are defined only for OpenGL versions
433 * Forward-looking contexts are supported by silently converting the
434 * requested API to API_OPENGL_CORE.
436 * In Mesa, a debug context is the same as a regular context.
438 if ((ctx_config
.flags
& __DRI_CTX_FLAG_FORWARD_COMPATIBLE
) != 0) {
439 mesa_api
= API_OPENGL_CORE
;
442 const uint32_t allowed_flags
= (__DRI_CTX_FLAG_DEBUG
443 | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
444 | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
445 | __DRI_CTX_FLAG_NO_ERROR
);
446 if (ctx_config
.flags
& ~allowed_flags
) {
447 *error
= __DRI_CTX_ERROR_UNKNOWN_FLAG
;
451 if (!validate_context_version(screen
, mesa_api
,
452 ctx_config
.major_version
,
453 ctx_config
.minor_version
,
457 context
= calloc(1, sizeof *context
);
459 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
463 context
->loaderPrivate
= data
;
465 context
->driScreenPriv
= screen
;
466 context
->driDrawablePriv
= NULL
;
467 context
->driReadablePriv
= NULL
;
469 if (!screen
->driver
->CreateContext(mesa_api
, modes
, context
,
470 &ctx_config
, error
, shareCtx
)) {
475 *error
= __DRI_CTX_ERROR_SUCCESS
;
480 driContextSetFlags(struct gl_context
*ctx
, uint32_t flags
)
482 if ((flags
& __DRI_CTX_FLAG_FORWARD_COMPATIBLE
) != 0)
483 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
;
484 if ((flags
& __DRI_CTX_FLAG_DEBUG
) != 0) {
485 _mesa_set_debug_state_int(ctx
, GL_DEBUG_OUTPUT
, GL_TRUE
);
486 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_DEBUG_BIT
;
488 if ((flags
& __DRI_CTX_FLAG_NO_ERROR
) != 0)
489 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
;
492 static __DRIcontext
*
493 driCreateNewContextForAPI(__DRIscreen
*screen
, int api
,
494 const __DRIconfig
*config
,
495 __DRIcontext
*shared
, void *data
)
499 return driCreateContextAttribs(screen
, api
, config
, shared
, 0, NULL
,
503 static __DRIcontext
*
504 driCreateNewContext(__DRIscreen
*screen
, const __DRIconfig
*config
,
505 __DRIcontext
*shared
, void *data
)
507 return driCreateNewContextForAPI(screen
, __DRI_API_OPENGL
,
508 config
, shared
, data
);
512 * Destroy the per-context private information.
515 * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
516 * drmDestroyContext(), and finally frees \p contextPrivate.
519 driDestroyContext(__DRIcontext
*pcp
)
522 pcp
->driScreenPriv
->driver
->DestroyContext(pcp
);
528 driCopyContext(__DRIcontext
*dest
, __DRIcontext
*src
, unsigned long mask
)
539 /*****************************************************************/
540 /** \name Context (un)binding functions */
541 /*****************************************************************/
544 static void dri_get_drawable(__DRIdrawable
*pdp
);
545 static void dri_put_drawable(__DRIdrawable
*pdp
);
548 * This function takes both a read buffer and a draw buffer. This is needed
549 * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent
552 static int driBindContext(__DRIcontext
*pcp
,
557 ** Assume error checking is done properly in glXMakeCurrent before
558 ** calling driUnbindContext.
564 /* Bind the drawable to the context */
565 pcp
->driDrawablePriv
= pdp
;
566 pcp
->driReadablePriv
= prp
;
568 pdp
->driContextPriv
= pcp
;
569 dri_get_drawable(pdp
);
571 if (prp
&& pdp
!= prp
) {
572 dri_get_drawable(prp
);
575 return pcp
->driScreenPriv
->driver
->MakeCurrent(pcp
, pdp
, prp
);
581 * \param scrn the screen.
584 * \return \c GL_TRUE on success, or \c GL_FALSE on failure.
587 * This function calls __DriverAPIRec::UnbindContext, and then decrements
588 * __DRIdrawableRec::refcount which must be non-zero for a successful
591 * While casting the opaque private pointers associated with the parameters
592 * into their respective real types it also assures they are not \c NULL.
594 static int driUnbindContext(__DRIcontext
*pcp
)
600 ** Assume error checking is done properly in glXMakeCurrent before
601 ** calling driUnbindContext.
608 ** Call driUnbindContext before checking for valid drawables
609 ** to handle surfaceless contexts properly.
611 pcp
->driScreenPriv
->driver
->UnbindContext(pcp
);
613 pdp
= pcp
->driDrawablePriv
;
614 prp
= pcp
->driReadablePriv
;
616 /* already unbound */
621 if (pdp
->refcount
== 0) {
626 dri_put_drawable(pdp
);
629 if (prp
->refcount
== 0) {
634 dri_put_drawable(prp
);
637 pcp
->driDrawablePriv
= NULL
;
638 pcp
->driReadablePriv
= NULL
;
646 static void dri_get_drawable(__DRIdrawable
*pdp
)
651 static void dri_put_drawable(__DRIdrawable
*pdp
)
658 pdp
->driScreenPriv
->driver
->DestroyBuffer(pdp
);
663 static __DRIdrawable
*
664 driCreateNewDrawable(__DRIscreen
*screen
,
665 const __DRIconfig
*config
,
668 __DRIdrawable
*pdraw
;
670 assert(data
!= NULL
);
672 pdraw
= malloc(sizeof *pdraw
);
676 pdraw
->loaderPrivate
= data
;
678 pdraw
->driScreenPriv
= screen
;
679 pdraw
->driContextPriv
= NULL
;
681 pdraw
->lastStamp
= 0;
685 dri_get_drawable(pdraw
);
687 if (!screen
->driver
->CreateBuffer(screen
, pdraw
, &config
->modes
,
693 pdraw
->dri2
.stamp
= pdraw
->lastStamp
+ 1;
699 driDestroyDrawable(__DRIdrawable
*pdp
)
702 * The loader's data structures are going away, even if pdp itself stays
703 * around for the time being because it is currently bound. This happens
704 * when a currently bound GLX pixmap is destroyed.
706 * Clear out the pointer back into the loader's data structures to avoid
707 * accessing an outdated pointer.
709 pdp
->loaderPrivate
= NULL
;
711 dri_put_drawable(pdp
);
715 dri2AllocateBuffer(__DRIscreen
*screen
,
716 unsigned int attachment
, unsigned int format
,
717 int width
, int height
)
719 return screen
->driver
->AllocateBuffer(screen
, attachment
, format
,
724 dri2ReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
726 screen
->driver
->ReleaseBuffer(screen
, buffer
);
731 dri2ConfigQueryb(__DRIscreen
*screen
, const char *var
, unsigned char *val
)
733 if (!driCheckOption(&screen
->optionCache
, var
, DRI_BOOL
))
736 *val
= driQueryOptionb(&screen
->optionCache
, var
);
742 dri2ConfigQueryi(__DRIscreen
*screen
, const char *var
, int *val
)
744 if (!driCheckOption(&screen
->optionCache
, var
, DRI_INT
) &&
745 !driCheckOption(&screen
->optionCache
, var
, DRI_ENUM
))
748 *val
= driQueryOptioni(&screen
->optionCache
, var
);
754 dri2ConfigQueryf(__DRIscreen
*screen
, const char *var
, float *val
)
756 if (!driCheckOption(&screen
->optionCache
, var
, DRI_FLOAT
))
759 *val
= driQueryOptionf(&screen
->optionCache
, var
);
765 driGetAPIMask(__DRIscreen
*screen
)
767 return screen
->api_mask
;
771 * swrast swapbuffers entrypoint.
773 * DRI2 implements this inside the loader with only flushes handled by the
777 driSwapBuffers(__DRIdrawable
*pdp
)
779 assert(pdp
->driScreenPriv
->swrast_loader
);
781 pdp
->driScreenPriv
->driver
->SwapBuffers(pdp
);
784 /** Core interface */
785 const __DRIcoreExtension driCoreExtension
= {
786 .base
= { __DRI_CORE
, 2 },
788 .createNewScreen
= NULL
,
789 .destroyScreen
= driDestroyScreen
,
790 .getExtensions
= driGetExtensions
,
791 .getConfigAttrib
= driGetConfigAttrib
,
792 .indexConfigAttrib
= driIndexConfigAttrib
,
793 .createNewDrawable
= NULL
,
794 .destroyDrawable
= driDestroyDrawable
,
795 .swapBuffers
= driSwapBuffers
, /* swrast */
796 .createNewContext
= driCreateNewContext
, /* swrast */
797 .copyContext
= driCopyContext
,
798 .destroyContext
= driDestroyContext
,
799 .bindContext
= driBindContext
,
800 .unbindContext
= driUnbindContext
803 /** DRI2 interface */
804 const __DRIdri2Extension driDRI2Extension
= {
805 .base
= { __DRI_DRI2
, 4 },
807 .createNewScreen
= dri2CreateNewScreen
,
808 .createNewDrawable
= driCreateNewDrawable
,
809 .createNewContext
= driCreateNewContext
,
810 .getAPIMask
= driGetAPIMask
,
811 .createNewContextForAPI
= driCreateNewContextForAPI
,
812 .allocateBuffer
= dri2AllocateBuffer
,
813 .releaseBuffer
= dri2ReleaseBuffer
,
814 .createContextAttribs
= driCreateContextAttribs
,
815 .createNewScreen2
= driCreateNewScreen2
,
818 const __DRIswrastExtension driSWRastExtension
= {
819 .base
= { __DRI_SWRAST
, 4 },
821 .createNewScreen
= driSWRastCreateNewScreen
,
822 .createNewDrawable
= driCreateNewDrawable
,
823 .createNewContextForAPI
= driCreateNewContextForAPI
,
824 .createContextAttribs
= driCreateContextAttribs
,
825 .createNewScreen2
= driSWRastCreateNewScreen2
,
828 const __DRI2configQueryExtension dri2ConfigQueryExtension
= {
829 .base
= { __DRI2_CONFIG_QUERY
, 1 },
831 .configQueryb
= dri2ConfigQueryb
,
832 .configQueryi
= dri2ConfigQueryi
,
833 .configQueryf
= dri2ConfigQueryf
,
837 dri2InvalidateDrawable(__DRIdrawable
*drawable
)
839 drawable
->dri2
.stamp
++;
843 * Check that the gl_framebuffer associated with dPriv is the right size.
844 * Resize the gl_framebuffer if needed.
845 * It's expected that the dPriv->driverPrivate member points to a
846 * gl_framebuffer object.
849 driUpdateFramebufferSize(struct gl_context
*ctx
, const __DRIdrawable
*dPriv
)
851 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) dPriv
->driverPrivate
;
852 if (fb
&& (dPriv
->w
!= fb
->Width
|| dPriv
->h
!= fb
->Height
)) {
853 _mesa_resize_framebuffer(ctx
, fb
, dPriv
->w
, dPriv
->h
);
854 /* if the driver needs the hw lock for ResizeBuffers, the drawable
855 might have changed again by now */
856 assert(fb
->Width
== dPriv
->w
);
857 assert(fb
->Height
== dPriv
->h
);
862 driGLFormatToImageFormat(mesa_format format
)
865 case MESA_FORMAT_B5G6R5_UNORM
:
866 return __DRI_IMAGE_FORMAT_RGB565
;
867 case MESA_FORMAT_B5G5R5A1_UNORM
:
868 return __DRI_IMAGE_FORMAT_ARGB1555
;
869 case MESA_FORMAT_B8G8R8X8_UNORM
:
870 return __DRI_IMAGE_FORMAT_XRGB8888
;
871 case MESA_FORMAT_B10G10R10A2_UNORM
:
872 return __DRI_IMAGE_FORMAT_ARGB2101010
;
873 case MESA_FORMAT_B10G10R10X2_UNORM
:
874 return __DRI_IMAGE_FORMAT_XRGB2101010
;
875 case MESA_FORMAT_B8G8R8A8_UNORM
:
876 return __DRI_IMAGE_FORMAT_ARGB8888
;
877 case MESA_FORMAT_R8G8B8A8_UNORM
:
878 return __DRI_IMAGE_FORMAT_ABGR8888
;
879 case MESA_FORMAT_R8G8B8X8_UNORM
:
880 return __DRI_IMAGE_FORMAT_XBGR8888
;
881 case MESA_FORMAT_L_UNORM8
:
882 case MESA_FORMAT_R_UNORM8
:
883 return __DRI_IMAGE_FORMAT_R8
;
884 case MESA_FORMAT_L8A8_UNORM
:
885 case MESA_FORMAT_R8G8_UNORM
:
886 return __DRI_IMAGE_FORMAT_GR88
;
887 case MESA_FORMAT_NONE
:
888 return __DRI_IMAGE_FORMAT_NONE
;
889 case MESA_FORMAT_B8G8R8A8_SRGB
:
890 return __DRI_IMAGE_FORMAT_SARGB8
;
897 driImageFormatToGLFormat(uint32_t image_format
)
899 switch (image_format
) {
900 case __DRI_IMAGE_FORMAT_RGB565
:
901 return MESA_FORMAT_B5G6R5_UNORM
;
902 case __DRI_IMAGE_FORMAT_ARGB1555
:
903 return MESA_FORMAT_B5G5R5A1_UNORM
;
904 case __DRI_IMAGE_FORMAT_XRGB8888
:
905 return MESA_FORMAT_B8G8R8X8_UNORM
;
906 case __DRI_IMAGE_FORMAT_ARGB2101010
:
907 return MESA_FORMAT_B10G10R10A2_UNORM
;
908 case __DRI_IMAGE_FORMAT_XRGB2101010
:
909 return MESA_FORMAT_B10G10R10X2_UNORM
;
910 case __DRI_IMAGE_FORMAT_ARGB8888
:
911 return MESA_FORMAT_B8G8R8A8_UNORM
;
912 case __DRI_IMAGE_FORMAT_ABGR8888
:
913 return MESA_FORMAT_R8G8B8A8_UNORM
;
914 case __DRI_IMAGE_FORMAT_XBGR8888
:
915 return MESA_FORMAT_R8G8B8X8_UNORM
;
916 case __DRI_IMAGE_FORMAT_R8
:
917 return MESA_FORMAT_R_UNORM8
;
918 case __DRI_IMAGE_FORMAT_R16
:
919 return MESA_FORMAT_R_UNORM16
;
920 case __DRI_IMAGE_FORMAT_GR88
:
921 return MESA_FORMAT_R8G8_UNORM
;
922 case __DRI_IMAGE_FORMAT_GR1616
:
923 return MESA_FORMAT_R16G16_UNORM
;
924 case __DRI_IMAGE_FORMAT_SARGB8
:
925 return MESA_FORMAT_B8G8R8A8_SRGB
;
926 case __DRI_IMAGE_FORMAT_NONE
:
927 return MESA_FORMAT_NONE
;
929 return MESA_FORMAT_NONE
;
933 /** Image driver interface */
934 const __DRIimageDriverExtension driImageDriverExtension
= {
935 .base
= { __DRI_IMAGE_DRIVER
, 1 },
937 .createNewScreen2
= driCreateNewScreen2
,
938 .createNewDrawable
= driCreateNewDrawable
,
939 .getAPIMask
= driGetAPIMask
,
940 .createContextAttribs
= driCreateContextAttribs
,
943 /* swrast copy sub buffer entrypoint. */
944 static void driCopySubBuffer(__DRIdrawable
*pdp
, int x
, int y
,
947 assert(pdp
->driScreenPriv
->swrast_loader
);
949 pdp
->driScreenPriv
->driver
->CopySubBuffer(pdp
, x
, y
, w
, h
);
952 /* for swrast only */
953 const __DRIcopySubBufferExtension driCopySubBufferExtension
= {
954 .base
= { __DRI_COPY_SUB_BUFFER
, 1 },
956 .copySubBuffer
= driCopySubBuffer
,
959 const __DRInoErrorExtension dri2NoErrorExtension
= {
960 .base
= { __DRI2_NO_ERROR
, 1 },