diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2015-07-21 09:28:20 +0200 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2015-07-22 17:05:17 +0200 |
commit | fd12aa36b59cc6dc0f085532e60049775b8e3fed (patch) | |
tree | fc9c48d54450eab746efb0c909964c78f1bb6748 | |
parent | c69b792962bba413875cec3a198ee54ad3c24e51 (diff) |
egldevice: add EGLDevice checking helper function
This is useful to ensure EGLDevices given to functions (such as
eglQueryDeviceAttrib or eglQueryDeviceString) are valid.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | src/egl/main/eglapi.c | 6 | ||||
-rw-r--r-- | src/egl/main/egldevice.c | 26 | ||||
-rw-r--r-- | src/egl/main/egldevice.h | 4 |
3 files changed, 36 insertions, 0 deletions
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 98589d9822..b87bac8e6d 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -157,6 +157,12 @@ #define _EGL_CHECK_SYNC(disp, s, ret, drv) \ _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv) +#define _EGL_CHECK_DEVICE(dev, ret, devptr) \ + do { \ + devptr = _eglLookupDevice(dev); \ + if (!devptr) \ + RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, ret); \ + } while (0) static inline _EGLDriver * _eglCheckDisplay(_EGLDisplay *disp, const char *msg) diff --git a/src/egl/main/egldevice.c b/src/egl/main/egldevice.c index 9307b56e48..33473df620 100644 --- a/src/egl/main/egldevice.c +++ b/src/egl/main/egldevice.c @@ -89,6 +89,32 @@ out: return info; } +/** + * Lookup an existing device in the device list. + * Return NULL if the device pointer doesn't already exist in the device list. + */ +_EGLDevice * +_eglLookupDevice(EGLDeviceEXT device) +{ + _EGLDeviceInfo *info; + _EGLDevice *dev; + + info = _eglEnsureDeviceInfo(EGL_FALSE); + if (!info) + return NULL; + + mtx_lock(_eglGlobal.Mutex); + + for (dev = info->devices; dev; dev = dev->Next) { + if (dev == device) + break; + } + + mtx_unlock(_eglGlobal.Mutex); + + return dev; +} + /* TODO: this is all copied from loader.c. it should probably be put somewhere * common so both there and here can use the same source. also, if it remains * here, it needs a mutex.*/ diff --git a/src/egl/main/egldevice.h b/src/egl/main/egldevice.h index 682f4b1c3c..5ea2df8286 100644 --- a/src/egl/main/egldevice.h +++ b/src/egl/main/egldevice.h @@ -44,6 +44,10 @@ extern void _eglFiniDeviceInfo(void); +_EGLDevice * +_eglLookupDevice(EGLDeviceEXT device); + + EGLBoolean _eglQueryDevicesEXT(EGLint max_devices, _EGLDevice **devices, EGLint *num_devices); |