[Mesa-dev] [PATCH 2/8] egldevice: use _EGLDevice struct and keep a list of them in globals

Jonny Lamb jonny.lamb at collabora.co.uk
Fri Jul 24 07:19:56 PDT 2015


Right now the _EGLDevice struct has nothing of interest apart from a
next pointer but this is what will be opaquely returned to clients in
eglQueryDevicesEXT.

The _EGLDeviceInfo struct is held in _eglGlobal and thanks to atexit()
it is cleaned up appropriately too.

Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
 src/egl/main/Makefile.sources |  2 +
 src/egl/main/egldevice.c      | 92 +++++++++++++++++++++++++++++++++++++++++++
 src/egl/main/egldevice.h      | 47 ++++++++++++++++++++++
 src/egl/main/eglglobals.c     |  7 +++-
 src/egl/main/eglglobals.h     |  2 +
 src/egl/main/egltypedefs.h    |  2 +
 6 files changed, 150 insertions(+), 2 deletions(-)
 create mode 100644 src/egl/main/egldevice.c
 create mode 100644 src/egl/main/egldevice.h

diff --git a/src/egl/main/Makefile.sources b/src/egl/main/Makefile.sources
index e39a80f..5c14bbf 100644
--- a/src/egl/main/Makefile.sources
+++ b/src/egl/main/Makefile.sources
@@ -11,6 +11,8 @@ LIBEGL_C_FILES := \
 	eglcurrent.c \
 	eglcurrent.h \
 	egldefines.h \
+	egldevice.c \
+	egldevice.h \
 	egldisplay.c \
 	egldisplay.h \
 	egldriver.c \
diff --git a/src/egl/main/egldevice.c b/src/egl/main/egldevice.c
new file mode 100644
index 0000000..c5c8e94
--- /dev/null
+++ b/src/egl/main/egldevice.c
@@ -0,0 +1,92 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Collabora
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "egldevice.h"
+#include "eglglobals.h"
+#include "egltypedefs.h"
+
+
+typedef struct {
+   /* device list */
+   _EGLDevice *devices;
+
+} _EGLDeviceInfo;
+
+static _EGLDeviceInfo *
+_eglEnsureDeviceInfo(void)
+{
+   _EGLDeviceInfo *info;
+
+   mtx_lock(_eglGlobal.Mutex);
+
+   info = _eglGlobal.DeviceInfo;
+
+   if (!info) {
+      info = calloc(1, sizeof(_EGLDeviceInfo));
+      if (!info)
+         goto out;
+
+      info->devices = NULL;
+
+      _eglGlobal.DeviceInfo = info;
+   }
+
+out:
+   mtx_unlock(_eglGlobal.Mutex);
+
+   return info;
+}
+
+/**
+ * Finish device management.
+ */
+void
+_eglFiniDeviceInfo(void)
+{
+   _EGLDeviceInfo *info;
+   _EGLDevice *device_list, *device;
+
+   /* atexit function is called with global mutex locked */
+
+   info = _eglGlobal.DeviceInfo;
+
+   if (!info)
+      return;
+
+   device_list = info->devices;
+   while (device_list) {
+      /* pop list head */
+      device = device_list;
+      device_list = device_list->Next;
+
+      free(device);
+   }
+
+   free(info);
+   _eglGlobal.DeviceInfo = NULL;
+}
diff --git a/src/egl/main/egldevice.h b/src/egl/main/egldevice.h
new file mode 100644
index 0000000..f8f3824
--- /dev/null
+++ b/src/egl/main/egldevice.h
@@ -0,0 +1,47 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Collabora
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#ifndef EGLDEVICE_INCLUDED
+#define EGLDEVICE_INCLUDED
+
+
+#include "egltypedefs.h"
+
+
+struct _egl_device {
+   _EGLDevice *Next;
+
+   /* TODO */
+};
+
+
+extern void
+_eglFiniDeviceInfo(void);
+
+
+#endif /* EGLDEVICE_INCLUDED */
diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c
index 2583d86..18cfbb3 100644
--- a/src/egl/main/eglglobals.c
+++ b/src/egl/main/eglglobals.c
@@ -33,6 +33,7 @@
 #include "c11/threads.h"
 
 #include "eglglobals.h"
+#include "egldevice.h"
 #include "egldisplay.h"
 #include "egldriver.h"
 
@@ -43,11 +44,13 @@ struct _egl_global _eglGlobal =
 {
    &_eglGlobalMutex,       /* Mutex */
    NULL,                   /* DisplayList */
-   2,                      /* NumAtExitCalls */
+   NULL,                   /* DeviceInfo */
+   3,                      /* NumAtExitCalls */
    {
       /* default AtExitCalls, called in reverse order */
       _eglUnloadDrivers, /* always called last */
-      _eglFiniDisplay
+      _eglFiniDisplay,
+      _eglFiniDeviceInfo
    },
 
    /* ClientExtensionsString */
diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h
index ae1b75b..03de632 100644
--- a/src/egl/main/eglglobals.h
+++ b/src/egl/main/eglglobals.h
@@ -47,6 +47,8 @@ struct _egl_global
    /* the list of all displays */
    _EGLDisplay *DisplayList;
 
+   void *DeviceInfo;
+
    EGLint NumAtExitCalls;
    void (*AtExitCalls[10])(void);
 
diff --git a/src/egl/main/egltypedefs.h b/src/egl/main/egltypedefs.h
index 7facdb4..5fb2b00 100644
--- a/src/egl/main/egltypedefs.h
+++ b/src/egl/main/egltypedefs.h
@@ -49,6 +49,8 @@ typedef struct _egl_config _EGLConfig;
 
 typedef struct _egl_context _EGLContext;
 
+typedef struct _egl_device _EGLDevice;
+
 typedef struct _egl_display _EGLDisplay;
 
 typedef struct _egl_driver _EGLDriver;
-- 
2.4.6



More information about the mesa-dev mailing list