eglglobals.c revision d63b28c1
13464ebd5Sriastradh/**************************************************************************
23464ebd5Sriastradh *
3af69d88dSmrg * Copyright 2008 VMware, Inc.
43464ebd5Sriastradh * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
53464ebd5Sriastradh * Copyright 2010-2011 LunarG, Inc.
63464ebd5Sriastradh * All Rights Reserved.
73464ebd5Sriastradh *
83464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
93464ebd5Sriastradh * copy of this software and associated documentation files (the
103464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including
113464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish,
123464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to
133464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to
143464ebd5Sriastradh * the following conditions:
153464ebd5Sriastradh *
163464ebd5Sriastradh * The above copyright notice and this permission notice (including the
173464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions
183464ebd5Sriastradh * of the Software.
193464ebd5Sriastradh *
203464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
213464ebd5Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
223464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
233464ebd5Sriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243464ebd5Sriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
253464ebd5Sriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
263464ebd5Sriastradh * DEALINGS IN THE SOFTWARE.
273464ebd5Sriastradh *
283464ebd5Sriastradh **************************************************************************/
293464ebd5Sriastradh
303464ebd5Sriastradh
314a49301eSmrg#include <stdlib.h>
324a49301eSmrg#include <assert.h>
334a49301eSmrg#include "eglglobals.h"
34cdc920a0Smrg#include "egldisplay.h"
354a49301eSmrg#include "egldriver.h"
364a49301eSmrg#include "eglmutex.h"
374a49301eSmrg
384a49301eSmrg
39af69d88dSmrgstatic _EGLMutex _eglGlobalMutex = _EGL_MUTEX_INITIALIZER;
40af69d88dSmrg
414a49301eSmrgstruct _egl_global _eglGlobal =
424a49301eSmrg{
434a49301eSmrg   &_eglGlobalMutex,       /* Mutex */
444a49301eSmrg   NULL,                   /* DisplayList */
454a49301eSmrg   2,                      /* NumAtExitCalls */
464a49301eSmrg   {
474a49301eSmrg      /* default AtExitCalls, called in reverse order */
484a49301eSmrg      _eglUnloadDrivers, /* always called last */
494a49301eSmrg      _eglFiniDisplay
504a49301eSmrg   },
51af69d88dSmrg
52af69d88dSmrg   /* ClientExtensions */
53af69d88dSmrg   {
54af69d88dSmrg      true, /* EGL_EXT_client_extensions */
55af69d88dSmrg      true, /* EGL_EXT_platform_base */
56af69d88dSmrg      true, /* EGL_EXT_platform_x11 */
57af69d88dSmrg      true, /* EGL_EXT_platform_wayland */
58af69d88dSmrg      true  /* EGL_MESA_platform_gbm */
59af69d88dSmrg   },
60af69d88dSmrg
61af69d88dSmrg   /* ClientExtensionsString */
62af69d88dSmrg   "EGL_EXT_client_extensions"
63af69d88dSmrg   " EGL_EXT_platform_base"
64af69d88dSmrg   " EGL_EXT_platform_x11"
65af69d88dSmrg   " EGL_EXT_platform_wayland"
66af69d88dSmrg   " EGL_MESA_platform_gbm"
674a49301eSmrg};
684a49301eSmrg
69d63b28c1Smartinstatic EGLBoolean registered = EGL_FALSE;
704a49301eSmrg
71d63b28c1Smartinstatic void __attribute__((__destructor__))
724a49301eSmrg_eglAtExit(void)
734a49301eSmrg{
744a49301eSmrg   EGLint i;
75d63b28c1Smartin
76d63b28c1Smartin   if (!registered)
77d63b28c1Smartin     return;
78d63b28c1Smartin
794a49301eSmrg   for (i = _eglGlobal.NumAtExitCalls - 1; i >= 0; i--)
804a49301eSmrg      _eglGlobal.AtExitCalls[i]();
814a49301eSmrg}
824a49301eSmrg
834a49301eSmrg
844a49301eSmrgvoid
854a49301eSmrg_eglAddAtExitCall(void (*func)(void))
864a49301eSmrg{
874a49301eSmrg   if (func) {
884a49301eSmrg
894a49301eSmrg      _eglLockMutex(_eglGlobal.Mutex);
904a49301eSmrg
91d63b28c1Smartin      registered = EGL_TRUE;
924a49301eSmrg
934a49301eSmrg      assert(_eglGlobal.NumAtExitCalls < ARRAY_SIZE(_eglGlobal.AtExitCalls));
944a49301eSmrg      _eglGlobal.AtExitCalls[_eglGlobal.NumAtExitCalls++] = func;
954a49301eSmrg
964a49301eSmrg      _eglUnlockMutex(_eglGlobal.Mutex);
974a49301eSmrg   }
984a49301eSmrg}
99