egl_manager.h 4.7 KB

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