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 * Return the native platform by parsing EGL_PLATFORM.
20 static _EGLPlatformType
21 _eglGetNativePlatformFromEnv(void)
23 /* map --with-egl-platforms names to platform types */
25 _EGLPlatformType platform
;
27 } egl_platforms
[_EGL_NUM_PLATFORMS
] = {
28 { _EGL_PLATFORM_WINDOWS
, "gdi" },
29 { _EGL_PLATFORM_X11
, "x11" },
30 { _EGL_PLATFORM_DRM
, "drm" },
31 { _EGL_PLATFORM_FBDEV
, "fbdev" }
33 _EGLPlatformType plat
= _EGL_INVALID_PLATFORM
;
34 const char *plat_name
;
37 plat_name
= getenv("EGL_PLATFORM");
38 /* try deprecated env variable */
39 if (!plat_name
|| !plat_name
[0])
40 plat_name
= getenv("EGL_DISPLAY");
41 if (!plat_name
|| !plat_name
[0])
42 return _EGL_INVALID_PLATFORM
;
44 for (i
= 0; i
< _EGL_NUM_PLATFORMS
; i
++) {
45 if (strcmp(egl_platforms
[i
].name
, plat_name
) == 0) {
46 plat
= egl_platforms
[i
].platform
;
56 * Return the native platform. It is the platform of the EGL native types.
59 _eglGetNativePlatform(void)
61 static _EGLPlatformType native_platform
= _EGL_INVALID_PLATFORM
;
63 if (native_platform
== _EGL_INVALID_PLATFORM
) {
64 native_platform
= _eglGetNativePlatformFromEnv();
65 if (native_platform
== _EGL_INVALID_PLATFORM
)
66 native_platform
= _EGL_NATIVE_PLATFORM
;
69 return native_platform
;
74 * Finish display management.
79 _EGLDisplay
*dpyList
, *dpy
;
81 /* atexit function is called with global mutex locked */
82 dpyList
= _eglGlobal
.DisplayList
;
88 dpyList
= dpyList
->Next
;
90 for (i
= 0; i
< _EGL_NUM_RESOURCES
; i
++) {
91 if (dpy
->ResourceLists
[i
]) {
92 _eglLog(_EGL_DEBUG
, "Display %p is destroyed with resources", dpy
);
99 _eglGlobal
.DisplayList
= NULL
;
104 * Find the display corresponding to the specified native display, or create a
108 _eglFindDisplay(_EGLPlatformType plat
, void *plat_dpy
)
112 if (plat
== _EGL_INVALID_PLATFORM
)
115 _eglLockMutex(_eglGlobal
.Mutex
);
117 /* search the display list first */
118 dpy
= _eglGlobal
.DisplayList
;
120 if (dpy
->Platform
== plat
&& dpy
->PlatformDisplay
== plat_dpy
)
125 /* create a new display */
127 dpy
= (_EGLDisplay
*) calloc(1, sizeof(_EGLDisplay
));
129 _eglInitMutex(&dpy
->Mutex
);
130 dpy
->Platform
= plat
;
131 dpy
->PlatformDisplay
= plat_dpy
;
133 /* add to the display list */
134 dpy
->Next
= _eglGlobal
.DisplayList
;
135 _eglGlobal
.DisplayList
= dpy
;
139 _eglUnlockMutex(_eglGlobal
.Mutex
);
146 * Destroy the contexts and surfaces that are linked to the display.
149 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
153 list
= display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
];
155 _EGLContext
*ctx
= (_EGLContext
*) list
;
158 _eglUnlinkContext(ctx
);
159 drv
->API
.DestroyContext(drv
, display
, ctx
);
161 assert(!display
->ResourceLists
[_EGL_RESOURCE_CONTEXT
]);
163 list
= display
->ResourceLists
[_EGL_RESOURCE_SURFACE
];
165 _EGLSurface
*surf
= (_EGLSurface
*) list
;
168 _eglUnlinkSurface(surf
);
169 drv
->API
.DestroySurface(drv
, display
, surf
);
171 assert(!display
->ResourceLists
[_EGL_RESOURCE_SURFACE
]);
176 * Free all the data hanging of an _EGLDisplay object, but not
180 _eglCleanupDisplay(_EGLDisplay
*disp
)
183 _eglDestroyArray(disp
->Configs
, free
);
184 disp
->Configs
= NULL
;
192 * Return EGL_TRUE if the given handle is a valid handle to a display.
195 _eglCheckDisplayHandle(EGLDisplay dpy
)
199 _eglLockMutex(_eglGlobal
.Mutex
);
200 cur
= _eglGlobal
.DisplayList
;
202 if (cur
== (_EGLDisplay
*) dpy
)
206 _eglUnlockMutex(_eglGlobal
.Mutex
);
207 return (cur
!= NULL
);
212 * Return EGL_TRUE if the given resource is valid. That is, the display does
216 _eglCheckResource(void *res
, _EGLResourceType type
, _EGLDisplay
*dpy
)
218 _EGLResource
*list
= dpy
->ResourceLists
[type
];
224 if (res
== (void *) list
) {
225 assert(list
->Display
== dpy
);
231 return (list
!= NULL
);
236 * Link a resource to a display.
239 _eglLinkResource(_EGLResource
*res
, _EGLResourceType type
, _EGLDisplay
*dpy
)
241 assert(!res
->Display
|| res
->Display
== dpy
);
244 res
->IsLinked
= EGL_TRUE
;
245 res
->Next
= dpy
->ResourceLists
[type
];
246 dpy
->ResourceLists
[type
] = res
;
251 * Unlink a linked resource from its display.
254 _eglUnlinkResource(_EGLResource
*res
, _EGLResourceType type
)
258 prev
= res
->Display
->ResourceLists
[type
];
261 if (prev
->Next
== res
)
266 prev
->Next
= res
->Next
;
269 res
->Display
->ResourceLists
[type
] = res
->Next
;
273 /* do not reset res->Display */
274 res
->IsLinked
= EGL_FALSE
;