01f67f6e4702fceb321e530d58c48ae5c9a6bf10
[mesa.git] / src / egl / main / egldisplay.c
1
2 /**
3 * Functions related to EGLDisplay.
4 */
5
6 #include <assert.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include "eglcontext.h"
10 #include "egldisplay.h"
11 #include "egldriver.h"
12 #include "eglglobals.h"
13 #include "eglhash.h"
14 #include "eglstring.h"
15
16
17 /**
18 * Allocate a new _EGLDisplay object for the given nativeDisplay handle.
19 * We'll also try to determine the device driver name at this time.
20 *
21 * Note that nativeDisplay may be an X Display ptr, or a string.
22 */
23 _EGLDisplay *
24 _eglNewDisplay(NativeDisplayType nativeDisplay)
25 {
26 _EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay));
27 if (dpy) {
28 EGLuint key = _eglHashGenKey(_eglGlobal.Displays);
29
30 dpy->Handle = (EGLDisplay) key;
31 _eglHashInsert(_eglGlobal.Displays, key, dpy);
32
33 dpy->NativeDisplay = nativeDisplay;
34 #if defined(_EGL_PLATFORM_X)
35 dpy->Xdpy = (Display *) nativeDisplay;
36 #endif
37
38 dpy->DriverName = _eglChooseDriver(dpy);
39 if (!dpy->DriverName) {
40 free(dpy);
41 return NULL;
42 }
43 }
44 return dpy;
45 }
46
47
48 /**
49 * Return the public handle for an internal _EGLDisplay.
50 * This is the inverse of _eglLookupDisplay().
51 */
52 EGLDisplay
53 _eglGetDisplayHandle(_EGLDisplay *display)
54 {
55 if (display)
56 return display->Handle;
57 else
58 return EGL_NO_DISPLAY;
59 }
60
61
62 /**
63 * Return the _EGLDisplay object that corresponds to the given public/
64 * opaque display handle.
65 * This is the inverse of _eglGetDisplayHandle().
66 */
67 _EGLDisplay *
68 _eglLookupDisplay(EGLDisplay dpy)
69 {
70 EGLuint key = (EGLuint) dpy;
71 if (!_eglGlobal.Displays)
72 return NULL;
73 return (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, key);
74 }
75
76
77 void
78 _eglSaveDisplay(_EGLDisplay *dpy)
79 {
80 EGLuint key = _eglHashGenKey(_eglGlobal.Displays);
81 assert(dpy);
82 assert(!dpy->Handle);
83 dpy->Handle = (EGLDisplay) key;
84 assert(dpy->Handle);
85 _eglHashInsert(_eglGlobal.Displays, key, dpy);
86 }
87
88
89 /**
90 * Free all the data hanging of an _EGLDisplay object, but not
91 * the object itself.
92 */
93 void
94 _eglCleanupDisplay(_EGLDisplay *disp)
95 {
96 EGLint i;
97
98 for (i = 0; i < disp->NumConfigs; i++) {
99 free(disp->Configs[i]);
100 }
101 free(disp->Configs);
102 disp->Configs = NULL;
103
104 /* XXX incomplete */
105
106 free((void *) disp->DriverName);
107 disp->DriverName = NULL;
108
109 /* driver deletes the _EGLDisplay object */
110 }