2 * Functions related to EGLDisplay.
8 #include "eglcontext.h"
9 #include "eglsurface.h"
10 #include "egldisplay.h"
11 #include "egldriver.h"
12 #include "eglglobals.h"
13 #include "eglstring.h"
19 * Finish display management.
24 _EGLDisplay
*dpyList
, *dpy
;
26 /* atexit function is called with global mutex locked */
27 dpyList
= _eglGlobal
.DisplayList
;
33 dpyList
= dpyList
->Next
;
35 for (i
= 0; i
< _EGL_NUM_RESOURCES
; i
++) {
36 if (dpy
->ResourceLists
[i
]) {
37 _eglLog(_EGL_DEBUG
, "Display %p is destroyed with resources", dpy
);
44 _eglGlobal
.DisplayList
= NULL
;
49 * Allocate a new _EGLDisplay object for the given nativeDisplay handle.
50 * We'll also try to determine the device driver name at this time.
52 * Note that nativeDisplay may be an X Display ptr, or a string.
55 _eglNewDisplay(NativeDisplayType nativeDisplay
)
57 _EGLDisplay
*dpy
= (_EGLDisplay
*) calloc(1, sizeof(_EGLDisplay
));
59 dpy
->NativeDisplay
= nativeDisplay
;
66 * Link a display to itself and return the handle of the link.
67 * The handle can be passed to client directly.
70 _eglLinkDisplay(_EGLDisplay
*dpy
)
72 _eglLockMutex(_eglGlobal
.Mutex
);
74 dpy
->Next
= _eglGlobal
.DisplayList
;
75 _eglGlobal
.DisplayList
= dpy
;
77 _eglUnlockMutex(_eglGlobal
.Mutex
);
79 return (EGLDisplay
) dpy
;
84 * Unlink a linked display from itself.
85 * Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
88 _eglUnlinkDisplay(_EGLDisplay
*dpy
)
92 _eglLockMutex(_eglGlobal
.Mutex
);
94 prev
= _eglGlobal
.DisplayList
;
97 if (prev
->Next
== dpy
)
102 prev
->Next
= dpy
->Next
;
105 _eglGlobal
.DisplayList
= dpy
->Next
;
108 _eglUnlockMutex(_eglGlobal
.Mutex
);
113 * Find the display corresponding to the specified native display id in all
117 _eglFindDisplay(NativeDisplayType nativeDisplay
)
121 _eglLockMutex(_eglGlobal
.Mutex
);
123 dpy
= _eglGlobal
.DisplayList
;
125 if (dpy
->NativeDisplay
== nativeDisplay
) {
126 _eglUnlockMutex(_eglGlobal
.Mutex
);
132 _eglUnlockMutex(_eglGlobal
.Mutex
);
139 * Destroy the contexts and surfaces that are linked to the display.
142 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
146 list
= display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
];
148 _EGLContext
*ctx
= (_EGLContext
*) list
;
151 _eglUnlinkContext(ctx
);
152 drv
->API
.DestroyContext(drv
, display
, ctx
);
154 assert(!display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
]);
156 list
= display
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
158 _EGLSurface
*surf
= (_EGLSurface
*) list
;
161 _eglUnlinkSurface(surf
);
162 drv
->API
.DestroySurface(drv
, display
, surf
);
164 assert(!display
->ResourceLists
[_EGL_RESOURCE_SURFACE
]);
169 * Free all the data hanging of an _EGLDisplay object, but not
173 _eglCleanupDisplay(_EGLDisplay
*disp
)
178 for (i
= 0; i
< disp
->NumConfigs
; i
++)
179 free(disp
->Configs
[i
]);
181 disp
->Configs
= NULL
;
182 disp
->NumConfigs
= 0;
189 #ifndef _EGL_SKIP_HANDLE_CHECK
193 * Return EGL_TRUE if the given handle is a valid handle to a display.
196 _eglCheckDisplayHandle(EGLDisplay dpy
)
200 _eglLockMutex(_eglGlobal
.Mutex
);
201 cur
= _eglGlobal
.DisplayList
;
203 if (cur
== (_EGLDisplay
*) dpy
)
207 _eglUnlockMutex(_eglGlobal
.Mutex
);
208 return (cur
!= NULL
);
213 * Return EGL_TRUE if the given resource is valid. That is, the display does
217 _eglCheckResource(void *res
, _EGLResourceType type
, _EGLDisplay
*dpy
)
219 _EGLResource
*list
= dpy
->ResourceLists
[type
];
225 if (res
== (void *) list
) {
226 assert(list
->Display
== dpy
);
232 return (list
!= NULL
);
236 #endif /* !_EGL_SKIP_HANDLE_CHECK */
240 * Link a resource to a display.
243 _eglLinkResource(_EGLResource
*res
, _EGLResourceType type
, _EGLDisplay
*dpy
)
246 res
->Next
= dpy
->ResourceLists
[type
];
247 dpy
->ResourceLists
[type
] = res
;
252 * Unlink a linked resource from its display.
255 _eglUnlinkResource(_EGLResource
*res
, _EGLResourceType type
)
259 prev
= res
->Display
->ResourceLists
[type
];
262 if (prev
->Next
== res
)
267 prev
->Next
= res
->Next
;
270 res
->Display
->ResourceLists
[type
] = res
->Next
;