diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2015-03-04 08:36:51 +0100 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2015-07-22 17:05:14 +0200 |
commit | 0a2f2166b4d233c1f3c69d37885243d4ffe13e0d (patch) | |
tree | a2f22b845b7396cb82566783e6df4c1a7f3e2114 | |
parent | 73c76a4f3cf138bd7cbfd376d0022b3a38084401 (diff) |
egldevice: use _EGLDevice struct and keep a list of them in globals
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@collabora.co.uk>
-rw-r--r-- | src/egl/main/Makefile.sources | 2 | ||||
-rw-r--r-- | src/egl/main/egldevice.c | 92 | ||||
-rw-r--r-- | src/egl/main/egldevice.h | 47 | ||||
-rw-r--r-- | src/egl/main/eglglobals.c | 7 | ||||
-rw-r--r-- | src/egl/main/eglglobals.h | 2 | ||||
-rw-r--r-- | src/egl/main/egltypedefs.h | 2 |
6 files changed, 150 insertions, 2 deletions
diff --git a/src/egl/main/Makefile.sources b/src/egl/main/Makefile.sources index e39a80f14a..5c14bbfe24 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 0000000000..c5c8e9433d --- /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 0000000000..f8f3824623 --- /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 2fd6ac0849..e2d118eed5 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 ae1b75b454..03de632735 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 7facdb47f8..5fb2b00e51 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; |