[Mesa-dev] [PATCH 5/8] egldevice: add EGLDevice checking helper function
Jonny Lamb
jonny.lamb at collabora.co.uk
Fri Jul 24 07:19:59 PDT 2015
This is useful to ensure EGLDevices given to functions (such as
eglQueryDeviceAttrib or eglQueryDeviceString) are valid.
Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
src/egl/main/eglapi.c | 6 ++++++
src/egl/main/egldevice.c | 26 ++++++++++++++++++++++++++
src/egl/main/egldevice.h | 4 ++++
3 files changed, 36 insertions(+)
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 222d3ff..0b826d4 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 56fa73c..5fb3a1a 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 682f4b1..5ea2df8 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);
--
2.4.6
More information about the mesa-dev
mailing list