Remove the "If only executable code is distributed..." paragraph from
the license text. Everything now uses a normal MIT license.
The only code from Khronos that's included in libglvnd is the EGL/GL
header and XML files, which do not contain that paragraph.
Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/221
When libGLX.so is unloaded, call XESetCloseDisplay to remove the display close
callback for any displays that still exist.
Otherwise, if libGLX.so is loaded using dlopen, and then unloaded while a
display is still open, then XCloseDisplay would try to call the (now dangling)
callback.
In OnDisplayClosed, unlock the __glXDisplayInfoHash lock before locking
glxContextHashLock.
In CommonMakeCurrent, it holds glxContextHashLock while it tries to take the
__glXDisplayInfoHash lock, so if CommonMakeCurrent and OnDisplayClosed run at
the same time, they could deadlock.
To avoid that, OnDisplayClosed will set a new inTeardown flag in the
__GLXdisplayInfoHash, then it will unlock the display hash before calling
__glXDisplayClosed.
After __glXDisplayClosed is finished, OnDisplayClosed will lock
__glXDisplayInfoHash again long enough to remove the display from the
hashtable.
The inTeardown flag tells __glXLookupDisplay to return NULL, since after that
point, nothing should be trying to look up the display. In principle, we could
just remove the display from the hashtable up front, but then if something did
try to look up the display, then __glXLookupDisplay would try to create a new
__GLXdisplayInfo for it.
Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/213
Added a dispatch handler for glXCreateContextAttribsARB. It'll look for a
GLX_SCREEN attribute first if the caller provides one, and then the GLXFBConfig
handle if the caller doesn't.
Added a new function to libGLdispatch, __glDispatchForceUnpatch, which forces
it to unpatch the OpenGL entrypoints before libEGL or libGLX can unload the
vendor library that patched them.
If a vendor patches the OpenGL entrypoints, libGLdispatch doesn't unpatch them
when that vendor's context is no longer current, because that adds too much
overhead to repeated MakeCurrent+LoseCurrent calls. But, that also means that
the patch callbacks end up being dangling pointers after the vendor library is
unloaded.
This mainly shows up at process termination when a process loads both libEGL
and libGLX, because __glxFini and __eglFini will both call the vendor's
threadAttach callback.
Fixes https://github.com/NVIDIA/libglvnd/issues/103
When libGLX.so selects a vendor libray for an X screen, it will look for an
environment variable __GLX_FORCE_VENDOR_LIBRARY_<N>, where <N> is the screen
number.
This is mainly for testing and debugging. It allows unit tests to force
different vendors on different screens, and it allows tests to avoid preloading
the dummy vendor library.
Moved the UnionExtensionStrings and IntersectionExtensionStrings functions from
EGL to utils_misc.c.
Changed libGLX to use the common UnionExtensionStrings and IsTokenInString
functions instead of its own versions of them.
Moved ParseClientVersionString to libglx.c near where it's used, and deleted
libglxstring.c and libglxstring.h.
Added a license+copyright comment to winsys_dispatch.[ch].
Renamed __GLVNDwinsysDispatchIndexHash to __GLVNDwinsysDispatchIndexEntry,
since it's not a hashtable anymore.
In __glXLookupVendorByName, only call __glvndWinsysDispatchGetCount once
instead of on every loop iteration.
Removed the locks for the GLX dispatch index list and the generated GLX
dispatch stubs. Instead, the vendor hashtable's lock is used for all three.
There's enough overlap between when the three locks are taken that using
separte locks has very little benefit and increases the risk of deadlocks.
Some minor cleanup of __glXFetchDispatchEntry.
Handle the various failure cases more directly: If we can't find a name, or if
the vendor library doesn't support a function, then return early.
If we can't allocate a cache entry for the function, then return the dispatch
stub anyway. It can try to store the stub again next time.
The dispatch functions in libGLX are now added to the GLX dispatch list just
like vendor-provided dispatch functions would be.
The function name cache in glXGetProcAddress is no longer required for
correctness, because it can look up a locally-defined dispatch stub in the same
list as the vendor-provided stubs.
In addition to simplifying glXGetProcAddress, this allows vendor libraries to
look up all GLX functions by index. In particular, this would allow a vendor
to look up glXDestroyContext, which would let it recover properly if it fails
to add a new context to the context-to-vendor mapping.
Remove the __GLXdispatchIndexHash table, and use the list in winsys_dispatch.c
to keep track of the function indices, names, and dispatch stubs.
If libGLX generates a GLX dispatch stub, then it will now assign an index to it
when it generates the stub, not when it fills in the stub. That lets it treat
generated stubs the same way regardless of whether they've been filled in or
not.
When assigning an index, it will now call the setDispatchIndex callback for
every vendor library, not just the vendor that provided the dispatch stub.
When loading a vendor library, it will call the new vendor's setDispatchIndex
callback for every existing GLX dispatch function.
Removed the functions __glXGetCurrentDispatch and __glXGetStaticDispatch.
Everything that used either one now looks up the __GLXvendorInfo pointer
instead.
Also removed __glXGetGLDispatch, since it's not used anywhere.
Reviewed-by: aplattner@nvidia.com
Reworked libGLX.so to use the GLX_EXT_libglvnd extension instead of x11glvnd.
In __glXLookupVendorByScreen, use __glXQueryServerString to look up the vendor
name string, and then split it up with strtok_r.
Move the display pointer from __GLXdisplayInfoHash to __GLXdisplayInfo, so that
we don't have to pass around both the Display and __GLXdisplayInfo pointers to
a function that needs both of them.
libGLX will now use XAddExtension and XESetCloseDisplay to register a callback
when a display is closed.
Removed XGLVRegisterCloseDisplayCallback and
XGLVUnregisterCloseDisplayCallbacks from the x11glvnd client library.
This is in preparation for removing the x11glvnd extension.
Added the function pointers for entrypoint rewriting as members of
__GLXapiImports, instead of using a separate __GLdispatchPatchCallbacks
pointer.
Moved the __GLdispatchPatchCallbacks struct to GLdispatch.h.
__glx_Main now takes a pointer to the __GLXapiImports struct and fills it in.
The __GLXapiImports struct is now allocated and zeroed by libGLX. This makes it
possible to add an optional element to the end of the struct without breaking
backward compatibility.
libGLX now allocates its own copy of the __GLXapiImports struct for each vendor
library. This is in preparation for providing an allocated and zeroed struct to
__glx_Main to fill in.
Removed the vendorID and vendorName parameters from the __glx_Main function,
since neither one is useful to a vendor.
Instead, __glx_Main now takes the __GLXvendorInfo pointer as a parameter. We
can use that to look up any additional per-vendor information that might be
added in the future.
Changed vendorFromContext, vendorFromFBConfig, and vendorFromDrawable to return
the vendor pointer as its return value instead of using a pointer.
Returning by pointer was necessary when the functions would also return a
screen number. But, GLX objects are now associated directly with a vendor,
not with any particular screen or display.
Removed addScreenVisualMapping, removeScreenVisualMapping, and vendorFromVisual
from __GLXapiExports.
The XVisualInfo to vendor mapping is a no-op, since it just uses the screen number
to select a vendor.
It might be useful in the future at some point to provide a mechanism for
selecting between multiple vendors on a single X screen, but such an option
would more likely be used with the GLXFBConfig-based functions, not with the
XVisualInfo-based ones.
The addVendorContextMapping, addVendorFBConfigMapping, and
addVendorDrawableMapping functions in __GLXapiExports now return an int to
indicate success or failure.
Updated the various GLX functions so that they will deal with those failures.
In the case of context and drawable creations functions, it will call back into
the vendor library to destroy the object before returning.
Remove the __GLXdispatchTableDynamic struct. Move the hashtable that it
contained to be a member of __GLXvendorInfo instead.
Reviewed-by: Andy Ritger <aritger@nvidia.com>
The __GLXvendorNameHash, __GLXvendorInfo, and vendor name are now allocated in
a single malloc.
Remove some duplicated cleanup code between TeardownVendor and
__glXLookupVendorByName.
Merge TeardownVendor into CleanupVendorNameInto.
In __glXLookupVendorByName, simplify the cleanup path on error. Remove the
local variables that are just copies of the __GLXvendorInfo members.
Remove InitExportsTable and statically initialize the glxExportsTable struct.
Reviewed-by: Andy Ritger <aritger@nvidia.com>
Rework the context tracking in libGLX.so so that it can handle a context that's
current to more than one thread at a time.
There's now a single hashtable to keep track of contexts, which replaces both
the (context -> vendor) map and the current context map.
The new __GLXcontextInfo struct keeps track of the number of threads where the
context is current, and whether the context is marked for deletion.
This also provides a workaround of sorts for some broken applications, which
try (and fail) to make a context current on two threads at the same time, and
aren't prepared to deal with the resulting BadAccess error. Moving the
duplicate context check into the vendor library allows it to preserve that
pre-libglvnd behavior for apps that depend on it.
Reviewed-by: Andy Ritger <aritger@nvidia.com>
The macros in lkdhash.h now just use the __glvndPthreadFuncs table, instead of
taking a GLVNDPthreadFuncs parameter.
Reviewed-by: Andy Ritger <aritger@nvidia.com>
glvnd_pthread.h and glvnd_pthread.c now declare and define a GLVNDPthreadFuncs
struct, instead of having a separate declaration in libGLX and libGLdispatch.
This mostly just simplifies initialization a bit, but it will also make it
easier to have common code that uses pthreads functions.
Reviewed-by: Andy Ritger <aritger@nvidia.com>
__glDispatchCheckMultithreaded will now check if the thread's current dispatch
table is NULL, and if it is, it will plug in the no-op table.
This is a workaround for some broken applications which try to call OpenGL
functions without a current context. As long as the thread calls a GLX function
first, any OpenGL calls it makes later will call a no-op stub instead of just
crashing.
Added calls to __glXThreadInitialize to some of the functions in
__GLXapiExports, so that GLX extension functions will still call
__glXThreadInitialize.
In AddVendorPointerMapping and AddVendorXIDMapping, if there is an existing
mapping, then add an assert that the new vendor library matches the old one.
Handles have to map to at most one vendor, so if we get two different vendors
then there's a bug either in libGLX or in the vendor libraries.
Renamed a bunch of structures and functions to reflect the fact that libGLX
maintains mappings of most objects directly to vendors now, not objects to
screens.
Remove the Display pointer from __GLXscreenPointerMappingHash. It's no longer
needed for anything in libGLX.so. Dispatch functions can find a vendor library
given only the GLXContext handle itself, so functions like glXGetContextIDEXT
don't need the display either.
libGLX now uses a separate hashtable for mapping GLXContext and GLXFBConfig
handles to vendor libraries.
Updated the ABI documentation to define requirements for GLXContext and
GLXFBConfig values, to ensure that there aren't ever any duplicate handles
between vendor libraries.
libGLX now only keeps track of the vendor library for each drawable, not the
screen number.
__glXVendorFromDrawable will now always return -1 for the screen. The screen
parameter will be removed in a later change.
When dispatching a function based on a GLXDrawable, generate an X error if the
drawable is invalid.
Added a helper function CommonDispatchDrawable to handle initialization,
looking up a vendor for a drawable, and reporting an error if it can't find
a vendor.
Removed __glXGetDrawableStaticDispatch, and replaced it with
CommonDispatchDrawable.
Removed the unused function __glXScreenFromDrawable.