Commit graph

63 commits

Author SHA1 Message Date
Dylan Baker 8ee0213413 meson: use meson.override_dependency when possible
Which allows libglvnd to be consumed as a meson subproject.
2022-07-06 14:15:28 -07:00
Aidan Foster 9f59259dc6 Moving setspecific to before DestroyThreadState 2022-03-15 17:53:15 +00:00
Aidan Foster 1f2bfbb6f0 Update src/EGL/libeglcurrent.c 2022-03-14 20:38:20 +00:00
Aidan Foster 4834bd26e7 Set current thread state to NULL in teardown
In the EGL destructor, DestroyThreadState gets called by
__eglCurrentTeardown to free the threadState, but the threadState does
not get changed to NULL when this happens.

The function eglReleaseThread calls __eglDestroyCurrentThreadAPIState,
which does set the threadState to NULL, right before calling
DestroyThreadState. Both eglReleaseThread and
__eglDestroyCurrentThreadAPIState check to make sure the threadState is
NULL before continuing.

If eglReleaseThread gets externally called after destruction, the
threadState is not NULL, so DestroyThreadState will be called to free
the threadState that was already freed by the destructor, causing a
double free.

This change is to add the same setting threadState to NULL in
__eglCurrentTeardown as which already __eglDestroyCurrentThreadAPIState,
to prevent this double free situation.
2022-03-14 18:51:37 +00:00
Kyle Brenneman db5ca3370c EGL: Add support for eglQueryDisplayAttribKHR and NV.
There are KHR, EXT, and NV versions of eglQueryDisplayAttrib, so add
support for all of them.

Define separate eglQueryDisplayAttribEXT, eglQueryDisplayAttribKHR, and
eglQueryDisplayAttribNV functions. They all call into the same common
function, with the only difference being the name passed to an error
callback.

When loading a vendor library, check for the vendor's
eglQueryDisplayAttrib using all three suffixes, and use whichever one is
available.
2021-11-29 07:26:39 -07:00
Kyle Brenneman eaffa7bc12 EGL: Add a dispatch stub for eglQueryDisplayAttribEXT.
Add a dispatch stub for eglQueryDisplayAttribEXT, which updates the device
hashtable if the application queries EGL_DEVICE_EXT.

It's possible that eglQueryDisplayAttribEXT could return an EGLDeviceEXT handle
that wasn't returned by eglQueryDevicesEXT, so the dispatch stub needs to add
the handle to the device hashtable.
2021-11-25 09:51:20 -07:00
Kyle Brenneman 26d15a9f13 EGL: Allow vendor's dispatch stubs to update the EGL device map.
Export a new __EGLapiExports::setVendorForDevice function, which allows
dispatch stubs to update the device hashtable when something returns an
EGLDeviceEXT handle.

Bumped the ABI version number to 1.2.
2021-11-25 09:51:20 -07:00
Kyle Brenneman 2747fcd3fc EGL: Allow adding EGLDeviceEXT handles
It's possible for new devices to become available while a program is running,
so eglQueryDevicesEXT might need to return a different list.

Change the EGLDeviceEXT hashtable so that each entry is allocated and added
separately, rathat than allocating every entry in a single malloc.

Added a new __eglAddDevice function, which adds an entry to the device
hashtable.

When the application calls eglQueryDevicesEXT, always call through to each
vendor library, and add (or update) each EGLDeviceEXT to the hashtable.

There's still no provision for removing an entry from the device hashtable. The
semantics of hot-unplugging a device aren't defined yet, and there's no way to
ensure that libglvnd's mapping will get updated if a device disappears
asynchonously, so it's up to the vendor library to deal with the old handle.
2021-11-25 09:51:20 -07:00
Kyle Brenneman fa9ef3971f Replace USE_X11 macro with ENABLE_EGL_X11.
If x11 support is enabled, then the meson and configure scripts will set
a macro named ENABLE_EGL_X11 instead of USE_X11.

USE_X11 will also select the Xlib typedef of EGLNativeDisplayType in
eglplatform.h, and libglvnd does not need or want those.

Enabling or disabling X11 support for EGL only affects platform
detection in eglGetDisplay. The rest of libEGL is supposed to treat
EGLNativeDisplayType as an opaque void* pointer.
2021-10-27 12:27:47 -06:00
Alex Richardson 396c10bdd7 Add x11_headers dependency to all targets that use it
This fixes the build for me since I have libX11 installed to a custom
prefix, so the default include path does not include libX11. This fixes
lots of instances of the following error:
../../libglvnd/include/EGL/eglplatform.h:109:10: fatal error: 'X11/Xlib.h' file not found

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-10-04 10:58:08 +01:00
Kyle Brenneman a7bb6f4d19 Remove extra paragraph from license text.
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
2021-09-30 09:21:34 -06:00
Simon McVittie a22477ba28 EGL: Interpret relative ICD paths as relative to the JSON manifest
Previously, relative ICD paths were treated as being relative to the
current working directory, but this doesn't seem useful in practice:
EGL vendors cannot predict what the current working directory of EGL
applications is going to be.

Instead, interpret the path as being relative to the realpath() of the
JSON manifest describing the ICD.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/190
2021-08-04 14:32:22 +01:00
Ronan Pigott a527411da7 egl: use device dispatch if at least one vendor suceeds
Currently, in InitDeviceListInternal if any egl vendor fails to list
its devices for any reason the construction of the device list is
abandoned. That means that even if we have one vendor successfully
serving the application, the failure of another vendor library will
break any api calls related to egl devices.

Instead, if a vendor fails queryDevicesEXT the device mapping logic
should proceed as if it listed no devices. If the relevant device
belongs to the failed vendor then the dispatch will still fail with
EGL_BAD_DEVICE.
2020-11-18 15:46:53 -07:00
Eric Engestrom 214450d18a egl: import eglFunctionList directly instead of passing it in the command line
`imp` is deprecated, and there's no reason to do things this complicated
when it's the only possibility.
2019-12-12 23:18:53 +00:00
Dylan Baker b308a876d3 autotools: Include meson.build and meson_options.txt in dist 2019-12-05 12:01:36 -08:00
Dylan Baker 16dc32352d Add meson build system
Theres a couple of things that this meson build system does differently
than autotools. It doesn't use a config.h file, it just puts #defines on
the command line with -D. It also does all of the code generation in the
generated folder, simply because it's simpler to do that.

On my 2 core / 4 thread KBL system:

autotools (no ccache):
sh -c "./autogen.sh&& ./configure && make -j6 check"  44.74s user 6.70s system 145% cpu 35.269 total

autotools (warm ccache):
sh -c "./autogen.sh&& ./configure && make -j6 check"  32.86s user 4.22s system 129% cpu 28.580 total

meson (no ccache):
sh -c "meson build; ninja -C build test"  23.48s user 3.71s system 236% cpu 11.487 total

meson (warm ccache)
sh -c "meson build; ninja -C build test"  16.06s user 2.31s system 210% cpu 8.727 total
2019-12-05 12:01:36 -08:00
Dylan Baker 3a7aed009c tests: Add symbol check tests
These use the symbol-check.py script from mesa, and should help to
ensure that glvnd doesn't start exposing/hiding new symbols. It's also
useful to double check that meson and autotools are doing the same
thing.
2019-12-04 10:02:00 -08:00
Simon McVittie 58e0fda487 Document EGL vendor ICD search paths
The behaviour of a relative `library_path` is deliberately left
unspecified here. As an implementation detail, it's currently
passed directly to `dlopen()`, so in practice it will be interpreted as
relative to the process's current working directory, but that doesn't
seem practically useful. Vulkan treats relative paths as being relative
to the JSON file in which they were found, which seems more likely to
be a helpful behaviour.

Otherwise this documents the current behaviour, without any of the
possible changes suggested on #187. If any of those changes are made,
then this document should be updated at the same time.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-09-19 18:06:57 +01:00
Kyle Brenneman 69b8c323d0 EGL: Use EGL_FALSE instead of False.
Fix InternalMakeCurrentDispatch to use the constant EGL_FALSE instead of the
Xlib-specific False.
2019-09-13 15:31:45 -06:00
Kyle Brenneman e49caa311f Use the pkg-config variables for X11 and Xext.
In the makefiles, use the CFLAGS and LIBS variables set by the
PKG_CHECK_MODULES macros for X11 and Xext.
2019-09-12 10:15:33 -06:00
Kyle Brenneman a5a74957d8 Make X11 support optional.
Add a new configure option, --disable-x11. That option will disable GLX, and
will #ifdef out the X11 platform detection in EGL, but also remove the
dependency on the X11 libraries and headers.

In addition, only check for the xext and glproto packages if GLX is enabled,
since that's the only component that needs them.
2019-09-12 10:02:37 -06:00
Kyle Brenneman 0dfaea2bcb Add pkg-config files for EGL, GL, GLES, and GLX.
This preserves the names from Mesa's gl, glesv1_cm, glesv2, and egl pkgconfig
data, and for compatibility with that, gl.pc gives you libGL.

Also added glx.pc and opengl.pc for libglvnd's libGLX and libOpenGL libraries.
If newer applications want to explicitly depend on libGLX and the appropriate
rendering API they can ask for the new pkgconfig names.

Note that the version numbers in each file are the API versions that each
library exposes, not the libglvnd package version.
2019-09-03 09:22:52 -06:00
Kyle Brenneman 58c8c4a402 Check if dirent.d_type is available in the configure script.
Add a check in the configure script to check if the dirent struct has a d_type
member, since that's not available on all systems.
2019-04-26 11:10:14 -06:00
Kyle Brenneman 55fad54ac7 Make Python optional when building from the make dist tarball.
When you run "make dist", the resulting tarball includes all of the generated
files. When building from that, we don't need to generate anything.
2018-08-17 07:17:56 -06:00
Kyle Brenneman 56450264b8 EGL: Fix typo in the makefile.
The $(VM_V_GEN) variable should be $(AM_V_GEN).
2018-08-17 07:17:53 -06:00
Mathieu Bridon 90f973f74d build: Find Python the Autotools way
An added advantage to this is that it makes it really easy to build with
Python 3, the same way other Autotools projects support it:

    $ export PYTHON=/usr/bin/python3
    $ ./configure
2018-08-16 13:57:27 +02:00
Kyle Brenneman 638ef33fc7 EGL: Remove a few unused functions in egldispatchstubs.c.
Remove FindProcIndex, __eglSetDispatchIndex, and
__eglDispatchFindDispatchFunction from egldispatchstubs.c.

The dispatch indices are allocated and assigned during initialization, so none
of those functions are ever called.
2018-06-06 08:42:41 -06:00
Kyle Brenneman 652909fbff Some fixes for "make dist"
Don't point nonst_HEADERS or EXTRA_DIST at entire directories. That causes
"make dist" to include files that it shouldn't, such as configured makefiles
and .pyc files.

Also added a few generated header files to noinst_HEADERS.
2018-04-13 16:15:37 -06:00
Kyle Brenneman dfaf0fd2b9 Add a (void*) cast for the last parameter when calling mincore.
The third parameter to mincore(2) can be a pointer to char or unsigned char,
depending on what system it's building on. To build in either case, just cast
that argument to a (void *).
2018-03-26 14:41:07 -06:00
Kyle Brenneman 0177ade402 configure: Check if linking against libdl is necessary.
Add an AC_CHECK_FUNC call to check whether dlopen is available without any
additional libraries. Some systems provide dlopen as part of libc, in which
case we can't (and don't need to) link against libdl.so.
2018-03-26 14:41:01 -06:00
Christopher James Halse Rogers 45d92a4b6d
Handle dlsym succeeding with info.dli_sname == NULL.
When dlsym is handed an address in a shared object that doesn't match a symbol
in that shared object (such as a C++ vtable) it returns success but sets
dli_sname to null.

Handle this case rather than crashing.
2018-03-05 10:15:02 +01:00
Kyle Brenneman 28e05b9349 Always return an error from eglMakeCurrent if the EGLDispaly is invalid
In eglMakeCurrent, check to make sure the EGLDisplay is valid, even if the
context is NULL.

Fixes https://github.com/NVIDIA/libglvnd/issues/151
2018-02-22 11:33:43 -07:00
Kyle Brenneman 1b74e819e1 Bump the version numbers in the library filenames.
If libglvnd is installed onto a system that already has non-libglvnd versions
of any of the OpenGL libraries installed, then ldconfig can get confused about
which files to create symlinks to. At worst, you could end up with a mix of the
libglvnd libraries and leftover non-libglvnd libraries.

To avoid that, bump the version numbers in these filenames:
- libGL.so.1.0.0 -> libGL.so.1.7.0
- libGLESv1_CM.so.1.0.0 -> libGLESv1_CM.so.1.2.0
- libGLESv2.so.2.0.0 -> libGLESv2.so.2.1.0
- libEGL.so.1.0.0 -> libEGL.so.1.1.0

Fixes https://github.com/NVIDIA/libglvnd/issues/147
2018-01-30 11:04:18 -07:00
Gabríel Arthúr Pétursson e3ab0a24cf Cleanup winsys dispatch index list on EGL mapping teardown
This fixes a memory leak reported by both Valgrind and LeakSanitizer
when libEGL is dlopen()-ed and dlclose()-ed afterwards.
2017-10-07 01:15:20 +00:00
Gabríel Arthúr Pétursson c2f81ca7ce Fix memory leak in LoadVendorsFromConfigDir
The individual entries allocated by scandir need to be freed too.
2017-10-06 22:39:20 +00:00
Kyle Brenneman a14972089e EGL: Fix handling a malloc failure in eglQueryString.
In GetClientExtensionString, if it runs into a malloc failure, then return NULL
instead of trying to dereference the result.
2017-07-25 08:50:10 -06:00
Kyle Brenneman 71226b013c EGL: Allow vendor libraries to identify platforms for eglGetDisplay. (#124)
EGL: Allow vendor libraries to identify platforms for eglGetDisplay.

Add a new optional function __EGLapiImports::findNativeDisplayPlatform. Vendor
libraries can provide that function to identify the platform for the native
display passed to eglGetDisplay.

Reviewed-by: Emil Velikov emil.velikov@collabora.com
2017-06-20 12:50:40 -06:00
Emil Velikov 94691a3ee2 EGL: honour eglGetPlatformDisplay's attrib_list
Currently we simply drop them on the floor.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2017-06-07 17:43:56 +01:00
Emil Velikov f6c14fabfa EGL: alias "drm" to gbm when using EGL_PLATFORM
Since the inseption of EGL/GBM the unofficial way to force
the platform was via EGL_PLATFORM="drm".

Strictly speaking one could remove the gbm one, but it should have no
side effects. Plus it's more consistent with other platforms.

In either case, one should not be using eglGetDisplay but the Platform
version of the API.

Signed-off-by: Emil Velikov <emil.velikov@gmail.com>
2017-06-07 17:43:56 +01:00
Emil Velikov a6120e6ec5 EGL: add platform gbm detection in eglGetDisplay
Without it any applications that depend on the platform will fail to
run.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2017-06-07 17:43:56 +01:00
Emil Velikov b559273fbd EGL: detect platform gbm vendor capability
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2017-06-07 17:43:56 +01:00
Kyle Brenneman 480046fa04 Merge pull request #111 from kbrenneman/libegl-platform-detection
Better X11 and Wayland platform detection
2016-12-13 11:42:38 -07:00
Kyle Brenneman 839a33ef43 Merge pull request #110 from kbrenneman/fix-issue-103-eglfini
Remove the remaining calls to the vendor library from __eglFini and __glXFini.
2016-11-09 10:51:45 -07:00
Kyle Brenneman 7fb2537acf EGL: Fix the python command line.
Fix the python command lines so that they use the correct variable name for the
python executable.
2016-10-31 14:56:58 -06:00
Kyle Brenneman c9378ea943 EGL: Fix an unitialized variable in IsX11Display. 2016-10-27 13:43:39 -06:00
Kyle Brenneman 31d0c31610 EGL: Add display detection for X11.
In eglGetDisplay, try to identify an X11 display based on a known function
pointer.

This is based on a patch by ajax@redhat.com:
https://github.com/NVIDIA/libglvnd/pull/102
2016-10-26 18:07:28 -06:00
Adam Jackson 10a4095b33 EGL: Better wayland detection in eglGetDisplay
The problem with using dlsym to look for wl_display_interface is that
variables by that name are emitted into other client libraries besides
libwayland-client. libSDL2 has this property, at least. Instead of that,
use dladdr() to look up the name of the symbol pointed to, and accept
any symbol with the right name as being wayland enough.

Signed-off-by: Adam Jackson <ajax@redhat.com>

v2: Minor formatting change.
2016-10-26 18:07:00 -06:00
Kyle Brenneman 8146a979d8 EGL: Don't call into the vendor library from __eglFini.
In __eglFini, check for a fork, but don't call __glDispatchCheckMultithreaded.

If a vendor has patched the OpenGL entrypoints, then
__glDispatchCheckMultithreaded will try to call the vendor's thread attach
callback, but the vendor library may have already been unloaded.

Fixes https://github.com/NVIDIA/libglvnd/issues/103
2016-10-25 17:40:53 -06:00
Kyle Brenneman 61bd107cc6 Fix a crash in process termination when EGL and GLX are both loaded.
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
2016-10-24 14:52:27 -06:00
Kyle Brenneman 1cd6a43122 Factor out some common extension string functions.
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.
2016-10-13 13:22:13 -06:00