Debian Codegraph @

drivers/egl/egl_manager.h

raw symbols SCIP
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
31 #pragma once
32
33 #ifdef EGL_ENABLED
34
35 // These must come first to avoid windows.h mess.
36 #include "platform_gl.h"
37
38 #include "core/templates/local_vector.h"
39 #include "servers/display/display_server.h"
40
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
48 EGLDisplay egl_display = EGL_NO_DISPLAY;
49 EGLContext egl_context = EGL_NO_CONTEXT;
50 EGLConfig egl_config = nullptr;
51
52 #ifdef WINDOWS_ENABLED
53 bool has_EGL_ANGLE_surface_orientation = false;
54 #endif
55 };
56
57 // EGL specific window data.
58 struct GLWindow {
59 bool initialized = false;
60 #ifdef WINDOWS_ENABLED
61 bool flipped_y = false;
62 #endif
63
64 // An handle to the GLDisplay associated with this window.
65 int gldisplay_id = -1;
66
67 EGLSurface egl_surface = EGL_NO_SURFACE;
68 };
69
70 LocalVector<GLDisplay> displays;
71 LocalVector<GLWindow> windows;
72
73 GLWindow *current_window = nullptr;
74
75 // On EGL the default swap interval is 1 and thus vsync is on by default.
76 bool use_vsync = true;
77
78 virtual const char *_get_platform_extension_name() const = 0;
79 virtual EGLenum _get_platform_extension_enum() const = 0;
80 virtual EGLenum _get_platform_api_enum() const = 0;
81 virtual Vector<EGLAttrib> _get_platform_display_attributes() const = 0;
82 virtual Vector<EGLint> _get_platform_context_attribs() const = 0;
83
84 #ifdef EGL_ANDROID_blob_cache
85 static String shader_cache_dir;
86
87 static void _set_cache(const void *p_key, EGLsizeiANDROID p_key_size, const void *p_value, EGLsizeiANDROID p_value_size);
88 static EGLsizeiANDROID _get_cache(const void *p_key, EGLsizeiANDROID p_key_size, void *p_value, EGLsizeiANDROID p_value_size);
89 #endif
90
91 int _get_gldisplay_id(void *p_display);
92 Error _gldisplay_create_context(GLDisplay &p_gldisplay);
93
94 public:
95 int display_get_native_visual_id(void *p_display);
96
97 Error open_display(void *p_display);
98 Error window_create(DisplayServer::WindowID p_window_id, void *p_display, void *p_native_window, int p_width, int p_height);
99
100 void window_destroy(DisplayServer::WindowID p_window_id);
101
102 void release_current();
103 void swap_buffers();
104
105 void window_make_current(DisplayServer::WindowID p_window_id);
106
107 void set_use_vsync(bool p_use);
108 bool is_using_vsync() const;
109
110 EGLContext get_context(DisplayServer::WindowID p_window_id);
111 EGLDisplay get_display(DisplayServer::WindowID p_window_id);
112 EGLConfig get_config(DisplayServer::WindowID p_window_id);
113
114 Error initialize(void *p_native_display = nullptr);
115
116 EGLManager();
117 virtual ~EGLManager();
118 };
119
120 #endif // EGL_ENABLED