tests: Add initial support for adding new devices to EGL_dummy.

Added a new function to the EGL dummy vendor called DummySetDeviceCount, which
will change the number of devices that it hands back for eglQueryDevicesEXT.

Also added a new dummy extension function, eglTestReturnDevice, which will
dispatch based on an EGLDisplay and return an EGLDeviceEXT handle. This is
used to test the new __EGLapiExports::setVendorForDevice function.
This commit is contained in:
Kyle Brenneman 2021-02-11 11:39:57 -07:00
parent eaffa7bc12
commit 6d43e9bac5
2 changed files with 69 additions and 11 deletions

View File

@ -38,6 +38,7 @@ enum
DI_eglTestDispatchDisplay,
DI_eglTestDispatchDevice,
DI_eglTestDispatchCurrent,
DI_eglTestReturnDevice,
DI_COUNT,
};
@ -82,6 +83,11 @@ static EGLint failNextMakeCurrentError = EGL_NONE;
static EGLDEBUGPROCKHR debugCallbackFunc = NULL;
static EGLBoolean debugCallbackEnabled = EGL_TRUE;
// The EGLDeviceEXT handle values have to be pointers, so just use the
// address of an array element for each EGLDeviceEXT handle.
static const char EGL_DEVICE_HANDLES[DUMMY_EGL_MAX_DEVICE_COUNT];
static EGLint deviceCount = DUMMY_EGL_DEVICE_COUNT;
static DummyThreadState *GetThreadState(void)
{
DummyThreadState *thr = (DummyThreadState *)
@ -144,18 +150,14 @@ static DummyEGLDisplay *LookupEGLDisplay(EGLDisplay dpy)
static EGLDeviceEXT GetEGLDevice(EGLint index)
{
// The EGLDeviceEXT handle values have to be pointers, so just use the
// address of an array element for each EGLDeviceEXT handle.
static const char EGL_DEVICE_HANDLES[DUMMY_EGL_DEVICE_COUNT];
assert(index >= 0 && index < DUMMY_EGL_DEVICE_COUNT);
assert(index >= 0 && index < DUMMY_EGL_MAX_DEVICE_COUNT);
return (EGLDeviceEXT) (EGL_DEVICE_HANDLES + index);
}
static EGLBoolean IsEGLDeviceValid(EGLDeviceEXT dev)
{
int i;
for (i=0; i<DUMMY_EGL_DEVICE_COUNT; i++) {
for (i=0; i<deviceCount; i++) {
if (dev == GetEGLDevice(i)) {
return EGL_TRUE;
}
@ -504,17 +506,17 @@ static EGLBoolean EGLAPIENTRY dummy_eglQueryDevicesEXT(EGLint max_devices, EGLDe
CommonEntrypoint();
if (devices != NULL) {
EGLint i;
if (max_devices != DUMMY_EGL_DEVICE_COUNT) {
if (max_devices != deviceCount) {
// libEGL should only every query the full list of devices.
printf("Wrong max_devices in eglQueryDevicesEXT: %d\n", max_devices);
abort();
}
*num_devices = DUMMY_EGL_DEVICE_COUNT;
*num_devices = deviceCount;
for (i=0; i<*num_devices; i++) {
devices[i] = GetEGLDevice(i);
}
} else {
*num_devices = DUMMY_EGL_DEVICE_COUNT;
*num_devices = deviceCount;
}
return EGL_TRUE;
}
@ -612,9 +614,16 @@ static void *dummy_eglTestDispatchCurrent(EGLint command, EGLAttrib param)
return CommonTestDispatch("eglTestDispatchCurrent", EGL_NO_DISPLAY, EGL_NO_DEVICE_EXT, command, param);
}
static EGLDeviceEXT dummy_eglTestReturnDevice(EGLDisplay dpy, EGLint index)
{
assert(index >= 0 && index < deviceCount);
return GetEGLDevice(index);
}
static void *dispatch_eglTestDispatchDisplay(EGLDisplay dpy, EGLint command, EGLAttrib param);
static void *dispatch_eglTestDispatchDevice(EGLDeviceEXT dpy, EGLint command, EGLAttrib param);
static void *dispatch_eglTestDispatchCurrent(EGLint command, EGLAttrib param);
static EGLDeviceEXT dispatch_eglTestReturnDevice(EGLDisplay dpy, EGLint index);
static struct {
const char *name;
@ -626,6 +635,7 @@ static struct {
PROC_ENTRY(eglTestDispatchDisplay),
PROC_ENTRY(eglTestDispatchDevice),
PROC_ENTRY(eglTestDispatchCurrent),
PROC_ENTRY(eglTestReturnDevice),
#undef PROC_ENTRY
};
@ -697,6 +707,24 @@ static void *dispatch_eglTestDispatchCurrent(EGLint command, EGLAttrib param)
}
}
static EGLDeviceEXT dispatch_eglTestReturnDevice(EGLDisplay dpy, EGLint index)
{
__EGLvendorInfo *vendor;
pfn_eglTestReturnDevice func;
EGLDeviceEXT ret;
apiExports->threadInit();
vendor = apiExports->getVendorFromDisplay(dpy);
func = (pfn_eglTestReturnDevice) FetchVendorFunc(vendor, DI_eglTestReturnDevice, EGL_BAD_DISPLAY);
if (func != NULL) {
ret = func(dpy, index);
} else {
ret = NULL;
}
apiExports->setVendorForDevice(ret, vendor);
return ret;
}
static const struct {
const char *name;
@ -791,6 +819,12 @@ static EGLBoolean dummyGetSupportsAPI(EGLenum api)
}
}
PUBLIC void DummySetDeviceCount(EGLint count)
{
assert(count >= 0 && count <= DUMMY_EGL_MAX_DEVICE_COUNT);
deviceCount = count;
}
PUBLIC EGLBoolean
__egl_Main(uint32_t version, const __EGLapiExports *exports,
__EGLvendorInfo *vendor, __EGLapiImports *imports)

View File

@ -56,11 +56,20 @@
#define DUMMY_VENDOR_NAME_1 "dummy1"
/**
* The number of devices that each dummy vendor library exposes. This is used
* to figure out which vendor library should be behind each device.
* The number of devices that each dummy vendor library exposes by default.
* This is used to figure out which vendor library should be behind each
* device.
*/
#define DUMMY_EGL_DEVICE_COUNT 2
/**
* The maximum number of devices that each dummy vendor library can expose.
*
* This is used to test adding a device after the initial eglQueryDevicesEXT
* call.
*/
#define DUMMY_EGL_MAX_DEVICE_COUNT 3
/**
* A platform enum to select a vendor library by name.
* The native display should be a pointer to a string with the vendor name.
@ -111,4 +120,19 @@ typedef void * (* pfn_eglTestDispatchDevice) (EGLDeviceEXT dev, EGLint command,
*/
typedef void * (* pfn_eglTestDispatchCurrent) (EGLint command, EGLAttrib param);
/**
* Returns an EGLDeviceEXT handle from the vendor library.
*
* This is used to test returning a device that wasn't listed in a call to
* eglQueryDevicesEXT.
*/
typedef EGLDeviceEXT (* pfn_eglTestReturnDevice) (EGLDisplay dpy, EGLint index);
/**
* Changes the number of EGLDeviceEXT handles that the dummy library exposes.
*
* This function has to be looked up using dlsym, not eglGetProcAddress.
*/
typedef void (* pfn_DummySetDeviceCount) (EGLint count);
#endif // EGL_DUMMY_H