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
Older versions of glxproto.h contained a typo where "Attribs" was misspelled.
The typo was fixed in the xorgproto version of glxproto.h, breaking the API.
Fixes#149.
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.
libGL.so now looks up the GLX core functions using a simple table, so that it
doesn't have the overhead of looking them up by name every time it's loaded.
Removed the (mutex != NULL) checks from __glXGLLoadGLXFunction, since it's no
longer called without a mutex.
Removed __glXWrapperInit, since it doesn't do anything anymore. Also removed the header file libgl.h, which only contained the declaration for __glXWrapperInit.
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.
In glXMakeCurrent, make sure to add the new display to libGLX's tracking, so
that it gets a callback if the display is closed.
This fixes a dangling pointer to the display in the __GLXThreadState struct if
the application closes the display while it's still current.
In __glXAPITeardown, use pthread_mutex_trylock to take the context hash mutex,
and just skip freeing the context data if the mutex isn't available.
In some cases, such as a multi-threaded program that hits an X11 I/O error,
another thread could be blocked in a glXMakeCurrent call, and so trying to take
the context list mutex would deadlock.
In addition, fix the current context bookkeeping in fork recovery. After a
fork, the contexts should still exist, but none of them will be current
anymore.
In cacheProcAddress, check if the function is already in the hashtable before
trying to add it. It's possible that another thread might have already called
glXGetProcAddress for the same function.
In addition, allocate each cache entry with a single malloc instead of a malloc
and a strdup.
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
In MergeExtensionStrings currentString was read after it was realloc'ed
to make space for the extra extensions.
This patch makes the function read the realloc'ed memory instead. To
allow that to work 'buf' has to be null terminated on after every
extra extension is written.
If glXDestroyContext is called with NULL for the GLXContext, then it will now
report an error using glvndAppErrorCheckReportError but it won't generate a
GLXBadContext error.
Some existing drivers (NVIDIA, Mesa, and possibly others) will just silently
return in that case, and some applications depend on that behavior.
By the time __glXFini is called, the destructors in the vendor libraries may
have already been called, so it's not safe to call any functions in the vendor
library.
__glXFini will now check for a fork and go through fork recovery, but it won't
call __glDispatchCheckMultithreaded. If there was a current context, then
__glDispatchCheckMultithreaded might call the vendor's thread attach callback.
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.
Rename __GLdispatchAPIState to __GLdispatchThreadState, to make it clearer that
the structure contains thread-specific data.
Updated some out-of-date comments.
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.
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.
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.
Fix a duplicate typedef of __GLXcontextInfo in libglx.c and libglxcurrent.h.
That causes an error with some compilers.
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.
KDE calls glXGetClientString with a NULL dpy argument, which crashes in the call
to XScreenCount(dpy). Work around it by explicitly checking for this and
returning some static strings.
Note that one oddity is that querying the GLX_VERSION with a NULL dpy will
return the maximum version supported by libglvnd, but specifying a display will
return the maximum supported by any vendor on the display (up to libglvnd's
supported maximum).
Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
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.
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.
Change the current context hash to use a recursive mutex instead of an rwlock.
In __glXLookupDisplay, don't take the lock until after InitDisplayInfoEntry
returns, so that it doesn't try to make any X calls while holding the lock.
If an X error occurs while holding a non-recursive lock, then the error handler
may call exit, which would in turn call __glXFini. That can cause a deadlock if
__glXFini tries to take the same lock.
In CommonMakeCurrent, if the new context is NULL and the drawables are not
None, then it should always generate a BadMatch error. But, if the old context
was NULL, then it would return before checking for the BadMatch error.
In MergeVersionStrings, deal with a zero return value from glvnd_asprintf. Zero
is technically a successful return value from glvnd_asprintf, even though none
of the format strings could produce it.
Remove a bit of dead code from AtomicDecrementClampAtZero. The only way for the
if(newVal < 0) branch to be taken is if (oldVal <= 0), which it can't be at
that point.
Added a new script to generate the GLX entrypoints in libGL. The new script
uses Khronos's glx.xml file for a function list.
Checked in a copy of Khronos's glx.xml, from revision 32184.
Added dispatch functions to libGLX for glXImportContextEXT and
glXFreeContextEXT, since both of them are difficult to implement as a dispatch
function from a vendor library.
Since glXImportContextEXT doesn't take any parameters that directly specify a
screen, it will query the server manually to figure out a screen number.
libGLX will now report any X errors that it generates directly, instead of
relying on a vendor library to report them.
For simply reporting errors, the notifyError callback in every vendor library
is functionally identical, so there's no reason to require every vendor to
implement it.
As a notification, it falls apart in glXMakeContextCurrent, which could have
two different vendor libraries if the drawables are on different screens. In
that case, libGLX has to arbitrarily pick one vendor to notify.
Add a __glXSendError function to libglx.c (based on the same function from
Mesa) to report X errors.
The __GLXapiImports::notifyError callback no longer has to report the X error.
It's mostly a notificaiton, although it returns a boolean value to tell libGLX
whether to report or ignore the error.
In glXMakeCurrent/glXMakeContextCurrent, it will report an error to whatever
vendor library owns the current context (if any), instead of the vendor
libraries for the two drawables. The rest of the function looks to the context
to select a vendor, and the old context is the only one that's valid in this
case.
libGLX will now call XQueryExtension to check the GLX extension the first time
it sees a display.
Add the GLX opcode and error base to __GLXdisplayInfo.
libGLX only gets a callback at thread termination if it has a current context.
If there isn't a current context, then it will leave the thread's __GLXAPIState
in the hashtable until teardown.
Now, libGLX will only keep a __GLXAPIState when it has a current
context. When glXMakeCurrent is called to release the current context, it will
free the __GLXAPIState.
Removed the hashtable for keeping track of the __GLXAPIStates and replaced it
with a linked list.
Removed the __GLX14EntryPoints structure from the vendor library ABI. Instead,
libGLX will use the getProcAddress callback to look up each function after
loading the library.
Moved the contents of __GLXvendorCallbacks into __GLXapiImports.
Changed __GLXdispatchTableStatic to be a separate struct from __GLXapiImports.
It now contains all of the GLX 1.4 function pointers, replacing __GLX14EntryPoints.