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"
18 * Finish display management.
23 _EGLDisplay
*dpyList
, *dpy
;
25 /* atexit function is called with global mutex locked */
26 dpyList
= _eglGlobal
.DisplayList
;
32 dpyList
= dpyList
->Next
;
34 for (i
= 0; i
< _EGL_NUM_RESOURCES
; i
++) {
35 if (dpy
->ResourceLists
[i
]) {
36 _eglLog(_EGL_DEBUG
, "Display %p is destroyed with resources", dpy
);
43 _eglGlobal
.DisplayList
= NULL
;
48 * Allocate a new _EGLDisplay object for the given nativeDisplay handle.
49 * We'll also try to determine the device driver name at this time.
51 * Note that nativeDisplay may be an X Display ptr, or a string.
54 _eglNewDisplay(EGLNativeDisplayType nativeDisplay
)
56 _EGLDisplay
*dpy
= (_EGLDisplay
*) calloc(1, sizeof(_EGLDisplay
));
58 dpy
->NativeDisplay
= nativeDisplay
;
65 * Link a display to itself and return the handle of the link.
66 * The handle can be passed to client directly.
69 _eglLinkDisplay(_EGLDisplay
*dpy
)
71 _eglLockMutex(_eglGlobal
.Mutex
);
73 dpy
->Next
= _eglGlobal
.DisplayList
;
74 _eglGlobal
.DisplayList
= dpy
;
76 _eglUnlockMutex(_eglGlobal
.Mutex
);
78 return (EGLDisplay
) dpy
;
83 * Unlink a linked display from itself.
84 * Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
87 _eglUnlinkDisplay(_EGLDisplay
*dpy
)
91 _eglLockMutex(_eglGlobal
.Mutex
);
93 prev
= _eglGlobal
.DisplayList
;
96 if (prev
->Next
== dpy
)
101 prev
->Next
= dpy
->Next
;
104 _eglGlobal
.DisplayList
= dpy
->Next
;
107 _eglUnlockMutex(_eglGlobal
.Mutex
);
112 * Find the display corresponding to the specified native display id in all
116 _eglFindDisplay(EGLNativeDisplayType nativeDisplay
)
120 _eglLockMutex(_eglGlobal
.Mutex
);
122 dpy
= _eglGlobal
.DisplayList
;
124 if (dpy
->NativeDisplay
== nativeDisplay
) {
125 _eglUnlockMutex(_eglGlobal
.Mutex
);
131 _eglUnlockMutex(_eglGlobal
.Mutex
);
138 * Destroy the contexts and surfaces that are linked to the display.
141 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
145 list
= display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
];
147 _EGLContext
*ctx
= (_EGLContext
*) list
;
150 _eglUnlinkContext(ctx
);
151 drv
->API
.DestroyContext(drv
, display
, ctx
);
153 assert(!display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
]);
155 list
= display
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
157 _EGLSurface
*surf
= (_EGLSurface
*) list
;
160 _eglUnlinkSurface(surf
);
161 drv
->API
.DestroySurface(drv
, display
, surf
);
163 assert(!display
->ResourceLists
[_EGL_RESOURCE_SURFACE
]);
168 * Free all the data hanging of an _EGLDisplay object, but not
172 _eglCleanupDisplay(_EGLDisplay
*disp
)
177 for (i
= 0; i
< disp
->NumConfigs
; i
++)
178 free(disp
->Configs
[i
]);
180 disp
->Configs
= NULL
;
181 disp
->NumConfigs
= 0;
182 disp
->MaxConfigs
= 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
)
245 assert(!res
->Display
|| res
->Display
== dpy
);
248 res
->IsLinked
= EGL_TRUE
;
249 res
->Next
= dpy
->ResourceLists
[type
];
250 dpy
->ResourceLists
[type
] = res
;
255 * Unlink a linked resource from its display.
258 _eglUnlinkResource(_EGLResource
*res
, _EGLResourceType type
)
262 prev
= res
->Display
->ResourceLists
[type
];
265 if (prev
->Next
== res
)
270 prev
->Next
= res
->Next
;
273 res
->Display
->ResourceLists
[type
] = res
->Next
;
277 /* do not reset res->Display */
278 res
->IsLinked
= EGL_FALSE
;