egl_manager.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**************************************************************************/
  2. /* egl_manager.h */
  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. #ifndef EGL_MANAGER_H
  31. #define EGL_MANAGER_H
  32. #ifdef EGL_ENABLED
  33. // These must come first to avoid windows.h mess.
  34. #include "platform_gl.h"
  35. #include "core/config/project_settings.h"
  36. #include "core/crypto/crypto_core.h"
  37. #include "core/io/dir_access.h"
  38. #include "core/io/file_access.h"
  39. #include "core/templates/local_vector.h"
  40. #include "servers/display_server.h"
  41. class EGLManager {
  42. private:
  43. // An EGL-side representation of a display with its own rendering
  44. // context.
  45. struct GLDisplay {
  46. void *display = nullptr;
  47. EGLDisplay egl_display = EGL_NO_DISPLAY;
  48. EGLContext egl_context = EGL_NO_CONTEXT;
  49. EGLConfig egl_config = nullptr;
  50. };
  51. // EGL specific window data.
  52. struct GLWindow {
  53. bool initialized = false;
  54. // An handle to the GLDisplay associated with this window.
  55. int gldisplay_id = -1;
  56. EGLSurface egl_surface = EGL_NO_SURFACE;
  57. };
  58. LocalVector<GLDisplay> displays;
  59. LocalVector<GLWindow> windows;
  60. GLWindow *current_window = nullptr;
  61. // On EGL the default swap interval is 1 and thus vsync is on by default.
  62. bool use_vsync = true;
  63. virtual const char *_get_platform_extension_name() const = 0;
  64. virtual EGLenum _get_platform_extension_enum() const = 0;
  65. virtual EGLenum _get_platform_api_enum() const = 0;
  66. virtual Vector<EGLAttrib> _get_platform_display_attributes() const = 0;
  67. virtual Vector<EGLint> _get_platform_context_attribs() const = 0;
  68. #ifdef EGL_ANDROID_blob_cache
  69. static String shader_cache_dir;
  70. static void _set_cache(const void *p_key, EGLsizeiANDROID p_key_size, const void *p_value, EGLsizeiANDROID p_value_size);
  71. static EGLsizeiANDROID _get_cache(const void *p_key, EGLsizeiANDROID p_key_size, void *p_value, EGLsizeiANDROID p_value_size);
  72. #endif
  73. int _get_gldisplay_id(void *p_display);
  74. Error _gldisplay_create_context(GLDisplay &p_gldisplay);
  75. public:
  76. int display_get_native_visual_id(void *p_display);
  77. Error open_display(void *p_display);
  78. Error window_create(DisplayServer::WindowID p_window_id, void *p_display, void *p_native_window, int p_width, int p_height);
  79. void window_destroy(DisplayServer::WindowID p_window_id);
  80. void release_current();
  81. void swap_buffers();
  82. void window_make_current(DisplayServer::WindowID p_window_id);
  83. void set_use_vsync(bool p_use);
  84. bool is_using_vsync() const;
  85. EGLContext get_context(DisplayServer::WindowID p_window_id);
  86. Error initialize(void *p_native_display = nullptr);
  87. EGLManager();
  88. virtual ~EGLManager();
  89. };
  90. #endif // EGL_ENABLED
  91. #endif // EGL_MANAGER_H