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 * Find the display corresponding to the specified native display, or create a
52 _eglFindDisplay(EGLNativeDisplayType nativeDisplay
)
56 _eglLockMutex(_eglGlobal
.Mutex
);
58 /* search the display list first */
59 dpy
= _eglGlobal
.DisplayList
;
61 if (dpy
->NativeDisplay
== nativeDisplay
)
66 /* create a new display */
68 dpy
= (_EGLDisplay
*) calloc(1, sizeof(_EGLDisplay
));
70 _eglInitMutex(&dpy
->Mutex
);
71 dpy
->NativeDisplay
= nativeDisplay
;
73 /* add to the display list */
74 dpy
->Next
= _eglGlobal
.DisplayList
;
75 _eglGlobal
.DisplayList
= dpy
;
79 _eglUnlockMutex(_eglGlobal
.Mutex
);
86 * Destroy the contexts and surfaces that are linked to the display.
89 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
93 list
= display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
];
95 _EGLContext
*ctx
= (_EGLContext
*) list
;
98 _eglUnlinkContext(ctx
);
99 drv
->API
.DestroyContext(drv
, display
, ctx
);
101 assert(!display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
]);
103 list
= display
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
105 _EGLSurface
*surf
= (_EGLSurface
*) list
;
108 _eglUnlinkSurface(surf
);
109 drv
->API
.DestroySurface(drv
, display
, surf
);
111 assert(!display
->ResourceLists
[_EGL_RESOURCE_SURFACE
]);
116 * Free all the data hanging of an _EGLDisplay object, but not
120 _eglCleanupDisplay(_EGLDisplay
*disp
)
125 for (i
= 0; i
< disp
->NumConfigs
; i
++)
126 free(disp
->Configs
[i
]);
128 disp
->Configs
= NULL
;
129 disp
->NumConfigs
= 0;
130 disp
->MaxConfigs
= 0;
137 #ifndef _EGL_SKIP_HANDLE_CHECK
141 * Return EGL_TRUE if the given handle is a valid handle to a display.
144 _eglCheckDisplayHandle(EGLDisplay dpy
)
148 _eglLockMutex(_eglGlobal
.Mutex
);
149 cur
= _eglGlobal
.DisplayList
;
151 if (cur
== (_EGLDisplay
*) dpy
)
155 _eglUnlockMutex(_eglGlobal
.Mutex
);
156 return (cur
!= NULL
);
161 * Return EGL_TRUE if the given resource is valid. That is, the display does
165 _eglCheckResource(void *res
, _EGLResourceType type
, _EGLDisplay
*dpy
)
167 _EGLResource
*list
= dpy
->ResourceLists
[type
];
173 if (res
== (void *) list
) {
174 assert(list
->Display
== dpy
);
180 return (list
!= NULL
);
184 #endif /* !_EGL_SKIP_HANDLE_CHECK */
188 * Link a resource to a display.
191 _eglLinkResource(_EGLResource
*res
, _EGLResourceType type
, _EGLDisplay
*dpy
)
193 assert(!res
->Display
|| res
->Display
== dpy
);
196 res
->IsLinked
= EGL_TRUE
;
197 res
->Next
= dpy
->ResourceLists
[type
];
198 dpy
->ResourceLists
[type
] = res
;
203 * Unlink a linked resource from its display.
206 _eglUnlinkResource(_EGLResource
*res
, _EGLResourceType type
)
210 prev
= res
->Display
->ResourceLists
[type
];
213 if (prev
->Next
== res
)
218 prev
->Next
= res
->Next
;
221 res
->Display
->ResourceLists
[type
] = res
->Next
;
225 /* do not reset res->Display */
226 res
->IsLinked
= EGL_FALSE
;