egl_manager.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /**************************************************************************/
  2. /* egl_manager.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "egl_manager.h"
  31. #include "core/crypto/crypto_core.h"
  32. #include "core/io/dir_access.h"
  33. #include "drivers/gles3/rasterizer_gles3.h"
  34. #ifdef EGL_ENABLED
  35. #if defined(EGL_STATIC)
  36. #define GLAD_EGL_VERSION_1_5 true
  37. #ifdef EGL_EXT_platform_base
  38. #define GLAD_EGL_EXT_platform_base 1
  39. #endif
  40. #define KHRONOS_STATIC 1
  41. extern "C" EGLAPI void EGLAPIENTRY eglSetBlobCacheFuncsANDROID(EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
  42. extern "C" EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT(EGLenum platform, void *native_display, const EGLint *attrib_list);
  43. #undef KHRONOS_STATIC
  44. #endif // defined(EGL_STATIC)
  45. #ifndef EGL_EXT_platform_base
  46. #define GLAD_EGL_EXT_platform_base 0
  47. #endif
  48. #ifdef WINDOWS_ENABLED
  49. // Unofficial ANGLE extension: EGL_ANGLE_surface_orientation
  50. #ifndef EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE
  51. #define EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE 0x33A7
  52. #define EGL_SURFACE_ORIENTATION_ANGLE 0x33A8
  53. #define EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE 0x0001
  54. #define EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE 0x0002
  55. #endif
  56. #endif
  57. // Creates and caches a GLDisplay. Returns -1 on error.
  58. int EGLManager::_get_gldisplay_id(void *p_display) {
  59. // Look for a cached GLDisplay.
  60. for (unsigned int i = 0; i < displays.size(); i++) {
  61. if (displays[i].display == p_display) {
  62. return i;
  63. }
  64. }
  65. // We didn't find any, so we'll have to create one, along with its own
  66. // EGLDisplay and EGLContext.
  67. GLDisplay new_gldisplay;
  68. new_gldisplay.display = p_display;
  69. if (GLAD_EGL_VERSION_1_5) {
  70. Vector<EGLAttrib> attribs = _get_platform_display_attributes();
  71. new_gldisplay.egl_display = eglGetPlatformDisplay(_get_platform_extension_enum(), new_gldisplay.display, (attribs.size() > 0) ? attribs.ptr() : nullptr);
  72. } else if (GLAD_EGL_EXT_platform_base) {
  73. #ifdef EGL_EXT_platform_base
  74. // eglGetPlatformDisplayEXT wants its attributes as EGLint, so we'll truncate
  75. // what we already have. It's a bit naughty but I'm really not sure what else
  76. // we could do here.
  77. Vector<EGLint> attribs;
  78. for (const EGLAttrib &attrib : _get_platform_display_attributes()) {
  79. attribs.push_back((EGLint)attrib);
  80. }
  81. new_gldisplay.egl_display = eglGetPlatformDisplayEXT(_get_platform_extension_enum(), new_gldisplay.display, (attribs.size() > 0) ? attribs.ptr() : nullptr);
  82. #endif // EGL_EXT_platform_base
  83. } else {
  84. NativeDisplayType *native_display_type = (NativeDisplayType *)new_gldisplay.display;
  85. new_gldisplay.egl_display = eglGetDisplay(*native_display_type);
  86. }
  87. ERR_FAIL_COND_V(eglGetError() != EGL_SUCCESS, -1);
  88. ERR_FAIL_COND_V_MSG(new_gldisplay.egl_display == EGL_NO_DISPLAY, -1, "Can't create an EGL display.");
  89. if (!eglInitialize(new_gldisplay.egl_display, nullptr, nullptr)) {
  90. ERR_FAIL_V_MSG(-1, "Can't initialize an EGL display.");
  91. }
  92. if (!eglBindAPI(_get_platform_api_enum())) {
  93. ERR_FAIL_V_MSG(-1, "OpenGL not supported.");
  94. }
  95. Error err = _gldisplay_create_context(new_gldisplay);
  96. if (err != OK) {
  97. eglTerminate(new_gldisplay.egl_display);
  98. ERR_FAIL_V(-1);
  99. }
  100. #ifdef EGL_ANDROID_blob_cache
  101. #if defined(EGL_STATIC)
  102. bool has_blob_cache = true;
  103. #else
  104. bool has_blob_cache = (eglSetBlobCacheFuncsANDROID != nullptr);
  105. #endif
  106. if (has_blob_cache && !shader_cache_dir.is_empty()) {
  107. eglSetBlobCacheFuncsANDROID(new_gldisplay.egl_display, &EGLManager::_set_cache, &EGLManager::_get_cache);
  108. }
  109. #endif
  110. #ifdef WINDOWS_ENABLED
  111. String client_extensions_string = eglQueryString(new_gldisplay.egl_display, EGL_EXTENSIONS);
  112. if (eglGetError() == EGL_SUCCESS) {
  113. Vector<String> egl_extensions = client_extensions_string.split(" ");
  114. if (egl_extensions.has("EGL_ANGLE_surface_orientation")) {
  115. new_gldisplay.has_EGL_ANGLE_surface_orientation = true;
  116. print_verbose("EGL: EGL_ANGLE_surface_orientation is supported.");
  117. }
  118. }
  119. #endif
  120. displays.push_back(new_gldisplay);
  121. // Return the new GLDisplay's ID.
  122. return displays.size() - 1;
  123. }
  124. #ifdef EGL_ANDROID_blob_cache
  125. String EGLManager::shader_cache_dir;
  126. void EGLManager::_set_cache(const void *p_key, EGLsizeiANDROID p_key_size, const void *p_value, EGLsizeiANDROID p_value_size) {
  127. String name = CryptoCore::b64_encode_str((const uint8_t *)p_key, p_key_size).replace("/", "_");
  128. String path = shader_cache_dir.path_join(name) + ".cache";
  129. Error err = OK;
  130. Ref<FileAccess> file = FileAccess::open(path, FileAccess::WRITE, &err);
  131. if (err != OK) {
  132. return;
  133. }
  134. file->store_buffer((const uint8_t *)p_value, p_value_size);
  135. }
  136. EGLsizeiANDROID EGLManager::_get_cache(const void *p_key, EGLsizeiANDROID p_key_size, void *p_value, EGLsizeiANDROID p_value_size) {
  137. String name = CryptoCore::b64_encode_str((const uint8_t *)p_key, p_key_size).replace("/", "_");
  138. String path = shader_cache_dir.path_join(name) + ".cache";
  139. Error err = OK;
  140. Ref<FileAccess> file = FileAccess::open(path, FileAccess::READ, &err);
  141. if (err != OK) {
  142. return 0;
  143. }
  144. EGLsizeiANDROID len = file->get_length();
  145. if (len <= p_value_size) {
  146. file->get_buffer((uint8_t *)p_value, len);
  147. }
  148. return len;
  149. }
  150. #endif
  151. Error EGLManager::_gldisplay_create_context(GLDisplay &p_gldisplay) {
  152. EGLint attribs[] = {
  153. EGL_RED_SIZE,
  154. 1,
  155. EGL_BLUE_SIZE,
  156. 1,
  157. EGL_GREEN_SIZE,
  158. 1,
  159. EGL_DEPTH_SIZE,
  160. 24,
  161. EGL_NONE,
  162. };
  163. EGLint attribs_layered[] = {
  164. EGL_RED_SIZE,
  165. 8,
  166. EGL_GREEN_SIZE,
  167. 8,
  168. EGL_GREEN_SIZE,
  169. 8,
  170. EGL_ALPHA_SIZE,
  171. 8,
  172. EGL_DEPTH_SIZE,
  173. 24,
  174. EGL_NONE,
  175. };
  176. EGLint config_count = 0;
  177. if (OS::get_singleton()->is_layered_allowed()) {
  178. eglChooseConfig(p_gldisplay.egl_display, attribs_layered, &p_gldisplay.egl_config, 1, &config_count);
  179. } else {
  180. eglChooseConfig(p_gldisplay.egl_display, attribs, &p_gldisplay.egl_config, 1, &config_count);
  181. }
  182. ERR_FAIL_COND_V(eglGetError() != EGL_SUCCESS, ERR_BUG);
  183. ERR_FAIL_COND_V(config_count == 0, ERR_UNCONFIGURED);
  184. Vector<EGLint> context_attribs = _get_platform_context_attribs();
  185. p_gldisplay.egl_context = eglCreateContext(p_gldisplay.egl_display, p_gldisplay.egl_config, EGL_NO_CONTEXT, (context_attribs.size() > 0) ? context_attribs.ptr() : nullptr);
  186. ERR_FAIL_COND_V_MSG(p_gldisplay.egl_context == EGL_NO_CONTEXT, ERR_CANT_CREATE, vformat("Can't create an EGL context. Error code: %d", eglGetError()));
  187. return OK;
  188. }
  189. Error EGLManager::open_display(void *p_display) {
  190. int gldisplay_id = _get_gldisplay_id(p_display);
  191. if (gldisplay_id < 0) {
  192. return ERR_CANT_CREATE;
  193. } else {
  194. return OK;
  195. }
  196. }
  197. int EGLManager::display_get_native_visual_id(void *p_display) {
  198. int gldisplay_id = _get_gldisplay_id(p_display);
  199. ERR_FAIL_COND_V(gldisplay_id < 0, ERR_CANT_CREATE);
  200. GLDisplay gldisplay = displays[gldisplay_id];
  201. EGLint native_visual_id = -1;
  202. if (!eglGetConfigAttrib(gldisplay.egl_display, gldisplay.egl_config, EGL_NATIVE_VISUAL_ID, &native_visual_id)) {
  203. ERR_FAIL_V(-1);
  204. }
  205. return native_visual_id;
  206. }
  207. Error EGLManager::window_create(DisplayServer::WindowID p_window_id, void *p_display, void *p_native_window, int p_width, int p_height) {
  208. int gldisplay_id = _get_gldisplay_id(p_display);
  209. ERR_FAIL_COND_V(gldisplay_id < 0, ERR_CANT_CREATE);
  210. GLDisplay &gldisplay = displays[gldisplay_id];
  211. // In order to ensure a fast lookup, make sure we got enough elements in the
  212. // windows local vector to use the window id as an index.
  213. if (p_window_id >= (int)windows.size()) {
  214. windows.resize(p_window_id + 1);
  215. }
  216. GLWindow &glwindow = windows[p_window_id];
  217. glwindow.gldisplay_id = gldisplay_id;
  218. Vector<EGLAttrib> egl_attribs;
  219. #ifdef WINDOWS_ENABLED
  220. if (gldisplay.has_EGL_ANGLE_surface_orientation) {
  221. EGLint optimal_orientation;
  222. if (eglGetConfigAttrib(gldisplay.egl_display, gldisplay.egl_config, EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE, &optimal_orientation)) {
  223. // We only need to support inverting Y for optimizing ANGLE on D3D11.
  224. if (optimal_orientation & EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE && !(optimal_orientation & EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE)) {
  225. egl_attribs.push_back(EGL_SURFACE_ORIENTATION_ANGLE);
  226. egl_attribs.push_back(EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE);
  227. }
  228. } else {
  229. ERR_PRINT(vformat("Failed to get EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE, error: 0x%08X", eglGetError()));
  230. }
  231. }
  232. if (!egl_attribs.is_empty()) {
  233. egl_attribs.push_back(EGL_NONE);
  234. }
  235. #endif
  236. if (GLAD_EGL_VERSION_1_5) {
  237. glwindow.egl_surface = eglCreatePlatformWindowSurface(gldisplay.egl_display, gldisplay.egl_config, p_native_window, egl_attribs.ptr());
  238. } else {
  239. EGLNativeWindowType *native_window_type = (EGLNativeWindowType *)p_native_window;
  240. glwindow.egl_surface = eglCreateWindowSurface(gldisplay.egl_display, gldisplay.egl_config, *native_window_type, nullptr);
  241. }
  242. if (glwindow.egl_surface == EGL_NO_SURFACE) {
  243. return ERR_CANT_CREATE;
  244. }
  245. glwindow.initialized = true;
  246. #ifdef WINDOWS_ENABLED
  247. if (gldisplay.has_EGL_ANGLE_surface_orientation) {
  248. EGLint orientation;
  249. if (eglQuerySurface(gldisplay.egl_display, glwindow.egl_surface, EGL_SURFACE_ORIENTATION_ANGLE, &orientation)) {
  250. if (orientation & EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE && !(orientation & EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE)) {
  251. glwindow.flipped_y = true;
  252. print_verbose("EGL: Using optimal surface orientation: Invert Y");
  253. }
  254. } else {
  255. ERR_PRINT(vformat("Failed to get EGL_SURFACE_ORIENTATION_ANGLE, error: 0x%08X", eglGetError()));
  256. }
  257. }
  258. #endif
  259. window_make_current(p_window_id);
  260. return OK;
  261. }
  262. void EGLManager::window_destroy(DisplayServer::WindowID p_window_id) {
  263. ERR_FAIL_INDEX(p_window_id, (int)windows.size());
  264. GLWindow &glwindow = windows[p_window_id];
  265. if (!glwindow.initialized) {
  266. return;
  267. }
  268. glwindow.initialized = false;
  269. ERR_FAIL_INDEX(glwindow.gldisplay_id, (int)displays.size());
  270. GLDisplay &gldisplay = displays[glwindow.gldisplay_id];
  271. if (glwindow.egl_surface != EGL_NO_SURFACE) {
  272. eglDestroySurface(gldisplay.egl_display, glwindow.egl_surface);
  273. glwindow.egl_surface = nullptr;
  274. }
  275. }
  276. void EGLManager::release_current() {
  277. if (!current_window) {
  278. return;
  279. }
  280. GLDisplay &current_display = displays[current_window->gldisplay_id];
  281. eglMakeCurrent(current_display.egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  282. }
  283. void EGLManager::swap_buffers() {
  284. if (!current_window) {
  285. return;
  286. }
  287. if (!current_window->initialized) {
  288. WARN_PRINT("Current OpenGL window is uninitialized!");
  289. return;
  290. }
  291. GLDisplay &current_display = displays[current_window->gldisplay_id];
  292. eglSwapBuffers(current_display.egl_display, current_window->egl_surface);
  293. }
  294. void EGLManager::window_make_current(DisplayServer::WindowID p_window_id) {
  295. if (p_window_id == DisplayServer::INVALID_WINDOW_ID) {
  296. return;
  297. }
  298. GLWindow &glwindow = windows[p_window_id];
  299. if (&glwindow == current_window || !glwindow.initialized) {
  300. return;
  301. }
  302. current_window = &glwindow;
  303. GLDisplay &current_display = displays[current_window->gldisplay_id];
  304. eglMakeCurrent(current_display.egl_display, current_window->egl_surface, current_window->egl_surface, current_display.egl_context);
  305. #ifdef WINDOWS_ENABLED
  306. RasterizerGLES3::set_screen_flipped_y(glwindow.flipped_y);
  307. #endif
  308. }
  309. void EGLManager::set_use_vsync(bool p_use) {
  310. // We need an active window to get a display to set the vsync.
  311. if (!current_window) {
  312. return;
  313. }
  314. GLDisplay &disp = displays[current_window->gldisplay_id];
  315. int swap_interval = p_use ? 1 : 0;
  316. if (!eglSwapInterval(disp.egl_display, swap_interval)) {
  317. WARN_PRINT("Could not set V-Sync mode.");
  318. }
  319. use_vsync = p_use;
  320. }
  321. bool EGLManager::is_using_vsync() const {
  322. return use_vsync;
  323. }
  324. EGLContext EGLManager::get_context(DisplayServer::WindowID p_window_id) {
  325. GLWindow &glwindow = windows[p_window_id];
  326. if (!glwindow.initialized) {
  327. return EGL_NO_CONTEXT;
  328. }
  329. GLDisplay &display = displays[glwindow.gldisplay_id];
  330. return display.egl_context;
  331. }
  332. EGLDisplay EGLManager::get_display(DisplayServer::WindowID p_window_id) {
  333. GLWindow &glwindow = windows[p_window_id];
  334. if (!glwindow.initialized) {
  335. return EGL_NO_CONTEXT;
  336. }
  337. GLDisplay &display = displays[glwindow.gldisplay_id];
  338. return display.egl_display;
  339. }
  340. EGLConfig EGLManager::get_config(DisplayServer::WindowID p_window_id) {
  341. GLWindow &glwindow = windows[p_window_id];
  342. if (!glwindow.initialized) {
  343. return nullptr;
  344. }
  345. GLDisplay &display = displays[glwindow.gldisplay_id];
  346. return display.egl_config;
  347. }
  348. Error EGLManager::initialize(void *p_native_display) {
  349. #if defined(GLAD_ENABLED) && !defined(EGL_STATIC)
  350. // Loading EGL with a new display gets us just the bare minimum API. We'll then
  351. // have to temporarily get a proper display and reload EGL once again to
  352. // initialize everything else.
  353. if (!gladLoaderLoadEGL(EGL_NO_DISPLAY)) {
  354. ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Can't load EGL dynamic library.");
  355. }
  356. EGLDisplay tmp_display = EGL_NO_DISPLAY;
  357. if (GLAD_EGL_EXT_platform_base) {
  358. #ifdef EGL_EXT_platform_base
  359. // eglGetPlatformDisplayEXT wants its attributes as EGLint.
  360. Vector<EGLint> attribs;
  361. for (const EGLAttrib &attrib : _get_platform_display_attributes()) {
  362. attribs.push_back((EGLint)attrib);
  363. }
  364. tmp_display = eglGetPlatformDisplayEXT(_get_platform_extension_enum(), p_native_display, attribs.ptr());
  365. #endif // EGL_EXT_platform_base
  366. } else {
  367. WARN_PRINT("EGL: EGL_EXT_platform_base not found during init, using default platform.");
  368. EGLNativeDisplayType *native_display_type = (EGLNativeDisplayType *)p_native_display;
  369. tmp_display = eglGetDisplay(*native_display_type);
  370. }
  371. if (tmp_display == EGL_NO_DISPLAY) {
  372. eglTerminate(tmp_display);
  373. ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Can't get a valid initial EGL display.");
  374. }
  375. eglInitialize(tmp_display, nullptr, nullptr);
  376. int version = gladLoaderLoadEGL(tmp_display);
  377. if (!version) {
  378. eglTerminate(tmp_display);
  379. ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Can't load EGL dynamic library.");
  380. }
  381. int major = GLAD_VERSION_MAJOR(version);
  382. int minor = GLAD_VERSION_MINOR(version);
  383. print_verbose(vformat("Loaded EGL %d.%d", major, minor));
  384. ERR_FAIL_COND_V_MSG(!GLAD_EGL_VERSION_1_4, ERR_UNAVAILABLE, vformat("EGL version is too old! %d.%d < 1.4", major, minor));
  385. eglTerminate(tmp_display);
  386. #endif
  387. #ifdef EGL_ANDROID_blob_cache
  388. shader_cache_dir = Engine::get_singleton()->get_shader_cache_path();
  389. if (shader_cache_dir.is_empty()) {
  390. shader_cache_dir = "user://";
  391. }
  392. Error err = OK;
  393. Ref<DirAccess> da = DirAccess::open(shader_cache_dir);
  394. if (da.is_null()) {
  395. ERR_PRINT("EGL: Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir);
  396. shader_cache_dir = String();
  397. } else {
  398. err = da->change_dir(String("shader_cache").path_join("EGL"));
  399. if (err != OK) {
  400. err = da->make_dir_recursive(String("shader_cache").path_join("EGL"));
  401. }
  402. if (err != OK) {
  403. ERR_PRINT("EGL: Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir);
  404. shader_cache_dir = String();
  405. } else {
  406. shader_cache_dir = shader_cache_dir.path_join(String("shader_cache").path_join("EGL"));
  407. }
  408. }
  409. #endif
  410. String client_extensions_string = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
  411. // If the above method fails, we don't support client extensions, so there's nothing to check.
  412. if (eglGetError() == EGL_SUCCESS) {
  413. const char *platform = _get_platform_extension_name();
  414. if (!client_extensions_string.split(" ").has(platform)) {
  415. ERR_FAIL_V_MSG(ERR_UNAVAILABLE, vformat("EGL platform extension \"%s\" not found.", platform));
  416. }
  417. }
  418. return OK;
  419. }
  420. EGLManager::EGLManager() {
  421. }
  422. EGLManager::~EGLManager() {
  423. for (unsigned int i = 0; i < displays.size(); i++) {
  424. eglTerminate(displays[i].egl_display);
  425. }
  426. }
  427. #endif // EGL_ENABLED