6265b07529aca091e13734841dc43d74e1f31ac9
[mesa.git] / src / egl / main / eglglobals.c
1 #include <stdio.h>
2 #include "eglglobals.h"
3
4
5 struct _egl_global _eglGlobal = { EGL_FALSE };
6
7
8 /**
9 * Init the fields in the _eglGlobal struct
10 * May be safely called more than once.
11 */
12 void
13 _eglInitGlobals(void)
14 {
15 if (!_eglGlobal.Initialized) {
16 _eglGlobal.Displays = _eglNewHashTable();
17 _eglGlobal.Contexts = _eglNewHashTable();
18 _eglGlobal.Surfaces = _eglNewHashTable();
19 _eglGlobal.FreeScreenHandle = 1;
20 _eglGlobal.CurrentContext = EGL_NO_CONTEXT;
21 _eglGlobal.LastError = EGL_SUCCESS;
22 _eglGlobal.Initialized = EGL_TRUE;
23 }
24 }
25
26
27 /**
28 * Should call this via an atexit handler.
29 */
30 void
31 _eglDestroyGlobals(void)
32 {
33 /* XXX TODO walk over table entries, deleting each */
34 _eglDeleteHashTable(_eglGlobal.Displays);
35 _eglDeleteHashTable(_eglGlobal.Contexts);
36 _eglDeleteHashTable(_eglGlobal.Surfaces);
37 }
38
39
40
41 /**
42 * Record EGL error code.
43 */
44 void
45 _eglError(EGLint errCode, const char *msg)
46 {
47 if (_eglGlobal.LastError == EGL_SUCCESS) {
48 _eglGlobal.LastError = errCode;
49 /* XXX temporary */
50 fprintf(stderr, "EGL Error 0x%x in %s\n", errCode, msg);
51 }
52 }
53
54
55 /**
56 * Return a new screen handle/ID.
57 * NOTE: we never reuse these!
58 */
59 EGLScreenMESA
60 _eglAllocScreenHandle(void)
61 {
62 EGLScreenMESA s = _eglGlobal.FreeScreenHandle;
63 _eglGlobal.FreeScreenHandle++;
64 return s;
65 }