1 /*
2 * Copyright © 2019 Collabora, Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #ifndef GL_RENDERER_INTERNAL_H
27 #define GL_RENDERER_INTERNAL_H
28
29 #include <GLES2/gl2.h>
30 #include <GLES2/gl2ext.h>
31 #include "shared/simple_gbm.h"
32 #include "shared/weston-egl-ext.h" /* for PFN* stuff */
33 #include "gl-renderer.h"
34
35 struct gl_shader {
36 GLuint program;
37 GLuint vertex_shader, fragment_shader;
38 GLint proj_uniform;
39 GLint tex_uniforms[3];
40 GLint alpha_uniform;
41 GLint color_uniform;
42 const char *vertex_source, *fragment_source;
43 };
44
45 struct gl_fbo {
46 EGLImageKHR image;
47 GLuint tex;
48 GLuint fbo;
49 };
50
51 struct gl_renderer {
52 struct weston_renderer base;
53 bool fragment_shader_debug;
54 bool fan_debug;
55 struct weston_binding *fragment_binding;
56 struct weston_binding *fan_binding;
57
58 EGLenum platform;
59 EGLDisplay egl_display;
60 EGLContext egl_context;
61 EGLConfig egl_config;
62
63 EGLSurface dummy_surface;
64
65 uint32_t gl_version;
66
67 struct wl_array vertices;
68 struct wl_array vtxcnt;
69
70 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
71 PFNEGLCREATEIMAGEKHRPROC create_image;
72 PFNEGLDESTROYIMAGEKHRPROC destroy_image;
73 PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage;
74
75 PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display;
76 PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC create_platform_window;
77 bool has_platform_base;
78
79 bool has_unpack_subimage;
80
81 PFNEGLBINDWAYLANDDISPLAYWL bind_display;
82 PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
83 PFNEGLQUERYWAYLANDBUFFERWL query_buffer;
84 bool has_bind_display;
85
86 bool has_context_priority;
87
88 bool has_egl_image_external;
89
90 bool has_egl_buffer_age;
91 bool has_egl_partial_update;
92 PFNEGLSETDAMAGEREGIONKHRPROC set_damage_region;
93
94 bool has_configless_context;
95
96 bool has_surfaceless_context;
97
98 bool has_dmabuf_import;
99 struct wl_list dmabuf_images;
100 struct wl_list dmabuf_formats;
101
102 bool has_gl_texture_rg;
103
104 struct gl_shader texture_shader_rgba;
105 struct gl_shader texture_shader_rgbx;
106 struct gl_shader texture_shader_egl_external;
107 struct gl_shader texture_shader_y_uv;
108 struct gl_shader texture_shader_y_u_v;
109 struct gl_shader texture_shader_y_xuxv;
110 struct gl_shader texture_shader_xyuv;
111 struct gl_shader invert_color_shader;
112 struct gl_shader solid_shader;
113 struct gl_shader *current_shader;
114
115 struct wl_signal destroy_signal;
116
117 struct wl_listener output_destroy_listener;
118
119 bool has_dmabuf_import_modifiers;
120 PFNEGLQUERYDMABUFFORMATSEXTPROC query_dmabuf_formats;
121 PFNEGLQUERYDMABUFMODIFIERSEXTPROC query_dmabuf_modifiers;
122
123 bool has_native_fence_sync;
124 PFNEGLCREATESYNCKHRPROC create_sync;
125 PFNEGLDESTROYSYNCKHRPROC destroy_sync;
126 PFNEGLDUPNATIVEFENCEFDANDROIDPROC dup_native_fence_fd;
127
128 bool has_wait_sync;
129 PFNEGLWAITSYNCKHRPROC wait_sync;
130 int gbm_fd;
131 struct gbm_device *device;
132 };
133
134 static inline struct gl_renderer *
get_renderer(struct weston_compositor * ec)135 get_renderer(struct weston_compositor *ec)
136 {
137 return (struct gl_renderer *)ec->gpu_renderer;
138 }
139
140 void
141 gl_renderer_print_egl_error_state(void);
142
143 void
144 gl_renderer_log_extensions(const char *name, const char *extensions);
145
146 void
147 log_egl_config_info(EGLDisplay egldpy, EGLConfig eglconfig);
148
149 EGLConfig
150 gl_renderer_get_egl_config(struct gl_renderer *gr,
151 EGLint egl_surface_type,
152 const uint32_t *drm_formats,
153 unsigned drm_formats_count);
154
155 int
156 gl_renderer_setup_egl_display(struct gl_renderer *gr, void *native_display);
157
158 int
159 gl_renderer_setup_egl_client_extensions(struct gl_renderer *gr);
160
161 int
162 gl_renderer_setup_egl_extensions(struct weston_compositor *ec);
163
164 #endif /* GL_RENDERER_INTERNAL_H */
165