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(_EGLPlatformType plat
, void *plat_dpy
)
56 if (plat
== _EGL_INVALID_PLATFORM
)
59 _eglLockMutex(_eglGlobal
.Mutex
);
61 /* search the display list first */
62 dpy
= _eglGlobal
.DisplayList
;
64 if (dpy
->Platform
== plat
&& dpy
->PlatformDisplay
== plat_dpy
)
69 /* create a new display */
71 dpy
= (_EGLDisplay
*) calloc(1, sizeof(_EGLDisplay
));
73 _eglInitMutex(&dpy
->Mutex
);
75 dpy
->PlatformDisplay
= plat_dpy
;
77 /* add to the display list */
78 dpy
->Next
= _eglGlobal
.DisplayList
;
79 _eglGlobal
.DisplayList
= dpy
;
83 _eglUnlockMutex(_eglGlobal
.Mutex
);
90 * Destroy the contexts and surfaces that are linked to the display.
93 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
97 list
= display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
];
99 _EGLContext
*ctx
= (_EGLContext
*) list
;
102 _eglUnlinkContext(ctx
);
103 drv
->API
.DestroyContext(drv
, display
, ctx
);
105 assert(!display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
]);
107 list
= display
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
109 _EGLSurface
*surf
= (_EGLSurface
*) list
;
112 _eglUnlinkSurface(surf
);
113 drv
->API
.DestroySurface(drv
, display
, surf
);
115 assert(!display
->ResourceLists
[_EGL_RESOURCE_SURFACE
]);
120 * Free all the data hanging of an _EGLDisplay object, but not
124 _eglCleanupDisplay(_EGLDisplay
*disp
)
129 for (i
= 0; i
< disp
->NumConfigs
; i
++)
130 free(disp
->Configs
[i
]);
132 disp
->Configs
= NULL
;
133 disp
->NumConfigs
= 0;
134 disp
->MaxConfigs
= 0;
142 * Return EGL_TRUE if the given handle is a valid handle to a display.
145 _eglCheckDisplayHandle(EGLDisplay dpy
)
149 _eglLockMutex(_eglGlobal
.Mutex
);
150 cur
= _eglGlobal
.DisplayList
;
152 if (cur
== (_EGLDisplay
*) dpy
)
156 _eglUnlockMutex(_eglGlobal
.Mutex
);
157 return (cur
!= NULL
);
162 * Return EGL_TRUE if the given resource is valid. That is, the display does
166 _eglCheckResource(void *res
, _EGLResourceType type
, _EGLDisplay
*dpy
)
168 _EGLResource
*list
= dpy
->ResourceLists
[type
];
174 if (res
== (void *) list
) {
175 assert(list
->Display
== dpy
);
181 return (list
!= NULL
);
186 * Link a resource to a display.
189 _eglLinkResource(_EGLResource
*res
, _EGLResourceType type
, _EGLDisplay
*dpy
)
191 assert(!res
->Display
|| res
->Display
== dpy
);
194 res
->IsLinked
= EGL_TRUE
;
195 res
->Next
= dpy
->ResourceLists
[type
];
196 dpy
->ResourceLists
[type
] = res
;
201 * Unlink a linked resource from its display.
204 _eglUnlinkResource(_EGLResource
*res
, _EGLResourceType type
)
208 prev
= res
->Display
->ResourceLists
[type
];
211 if (prev
->Next
== res
)
216 prev
->Next
= res
->Next
;
219 res
->Display
->ResourceLists
[type
] = res
->Next
;
223 /* do not reset res->Display */
224 res
->IsLinked
= EGL_FALSE
;