Skip to content

Commit 093739e

Browse files
committed
refactor egl config selection
two helper functions for choosing EGL configs: - one for choosing a config for GBM window surfaces (that match the exact GBM pixel format) - one for choosing a config for pbuffer surfaces, which have no EGL_NATIVE_VISUAL_ID, so you can only try to match the r,g,b,a bit size. require EGL_NO_CONFIG_KHR, the workaround if it's not supported was untested anyways, and it doesn't really work with offscreen render surfaces.
1 parent beab7b5 commit 093739e

7 files changed

+167
-238
lines changed

src/egl_gbm_render_surface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static int egl_gbm_render_surface_init(
180180
/// TODO: Think about allowing different tilings / modifiers here
181181
if (egl_config == EGL_NO_CONFIG_KHR) {
182182
// choose a config
183-
egl_config = gl_renderer_choose_config_direct(renderer, pixel_format);
183+
egl_config = gl_renderer_choose_gbm_window_config(renderer, pixel_format);
184184
if (egl_config == EGL_NO_CONFIG_KHR) {
185185
LOG_ERROR(
186186
"EGL doesn't supported the specified pixel format %s. Try a different one (ARGB8888 should always work).\n",

src/egl_offscreen_render_surface.c

Lines changed: 27 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct egl_offscreen_render_surface {
3838
uuid_t uuid;
3939
#endif
4040

41-
enum pixfmt pixel_format;
4241
EGLDisplay egl_display;
4342
EGLSurface egl_surface;
4443
EGLConfig egl_config;
@@ -67,57 +66,35 @@ ATTR_PURE struct egl_offscreen_render_surface *__checked_cast_egl_offscreen_rend
6766

6867
void egl_offscreen_render_surface_deinit(struct surface *s);
6968
static int egl_offscreen_render_surface_present_kms(struct surface *s, const struct fl_layer_props *props, struct kms_req_builder *builder);
70-
static int egl_offscreen_render_surface_present_fbdev(struct surface *s, const struct fl_layer_props *props, struct fbdev_commit_builder *builder);
69+
static int
70+
egl_offscreen_render_surface_present_fbdev(struct surface *s, const struct fl_layer_props *props, struct fbdev_commit_builder *builder);
7171
static int egl_offscreen_render_surface_fill(struct render_surface *s, FlutterBackingStore *fl_store);
7272
static int egl_offscreen_render_surface_queue_present(struct render_surface *s, const FlutterBackingStore *fl_store);
7373

7474
static int egl_offscreen_render_surface_init(
7575
struct egl_offscreen_render_surface *s,
7676
struct tracer *tracer,
7777
struct vec2i size,
78-
struct gl_renderer *renderer,
79-
enum pixfmt pixel_format,
80-
EGLConfig egl_config
78+
struct gl_renderer *renderer
8179
) {
8280
EGLDisplay egl_display;
8381
EGLSurface egl_surface;
8482
EGLBoolean egl_ok;
83+
EGLConfig egl_config;
8584
int ok;
8685

8786
ASSERT_NOT_NULL(renderer);
88-
ASSUME_PIXFMT_VALID(pixel_format);
8987
egl_display = gl_renderer_get_egl_display(renderer);
9088
ASSERT_NOT_NULL(egl_display);
9189

92-
#ifdef DEBUG
93-
if (egl_config != EGL_NO_CONFIG_KHR) {
94-
EGLint value = 0;
95-
96-
egl_ok = eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &value);
97-
if (egl_ok == EGL_FALSE) {
98-
LOG_EGL_ERROR(eglGetError(), "Couldn't query pixel format of EGL framebuffer config. eglGetConfigAttrib");
99-
return EIO;
100-
}
101-
102-
ASSERT_EQUALS_MSG(
103-
value,
104-
get_pixfmt_info(pixel_format)->gbm_format,
105-
"EGL framebuffer config pixel format doesn't match the argument pixel format."
106-
);
107-
}
108-
#endif
109-
11090
/// TODO: Think about allowing different tilings / modifiers here
91+
// choose a config
92+
egl_config = gl_renderer_choose_pbuffer_config(renderer, 8, 8, 8, 8);
11193
if (egl_config == EGL_NO_CONFIG_KHR) {
112-
// choose a config
113-
egl_config = gl_renderer_choose_config_direct(renderer, pixel_format);
114-
if (egl_config == EGL_NO_CONFIG_KHR) {
115-
LOG_ERROR(
116-
"EGL doesn't supported the specified pixel format %s. Try a different one (ARGB8888 should always work).\n",
117-
get_pixfmt_info(pixel_format)->name
118-
);
119-
return EINVAL;
120-
}
94+
LOG_ERROR(
95+
"EGL doesn't supported the hardcoded software rendering pixel format ARGB8888.\n"
96+
);
97+
return EINVAL;
12198
}
12299

123100
// EGLAttribKHR is defined by EGL_KHR_cl_event2.
@@ -160,7 +137,6 @@ static int egl_offscreen_render_surface_init(
160137
#ifdef DEBUG
161138
uuid_copy(&s->uuid, uuid);
162139
#endif
163-
s->pixel_format = pixel_format;
164140
s->egl_display = egl_display;
165141
s->egl_surface = egl_surface;
166142
s->egl_config = egl_config;
@@ -179,19 +155,12 @@ static int egl_offscreen_render_surface_init(
179155
* @param compositor The compositor that this surface will be registered to when calling surface_register.
180156
* @param size The size of the surface.
181157
* @param renderer The EGL/OpenGL used to create any GL surfaces.
182-
* @param pixel_format The pixel format to be used by the framebuffers of the surface.
183-
* @param egl_config The EGLConfig used for creating the EGLSurface.
184-
* @param allowed_modifiers The list of modifiers that gbm_surface_create_with_modifiers can choose from.
185-
* NULL if not specified. (In that case, gbm_surface_create will be used)
186-
* @param n_allowed_modifiers The number of modifiers in @param allowed_modifiers.
187158
* @return struct egl_offscreen_render_surface*
188159
*/
189-
struct egl_offscreen_render_surface *egl_offscreen_render_surface_new_with_egl_config(
160+
struct egl_offscreen_render_surface *egl_offscreen_render_surface_new(
190161
struct tracer *tracer,
191162
struct vec2i size,
192-
struct gl_renderer *renderer,
193-
enum pixfmt pixel_format,
194-
EGLConfig egl_config
163+
struct gl_renderer *renderer
195164
) {
196165
struct egl_offscreen_render_surface *surface;
197166
int ok;
@@ -201,14 +170,7 @@ struct egl_offscreen_render_surface *egl_offscreen_render_surface_new_with_egl_c
201170
goto fail_return_null;
202171
}
203172

204-
ok = egl_offscreen_render_surface_init(
205-
surface,
206-
tracer,
207-
size,
208-
renderer,
209-
pixel_format,
210-
egl_config
211-
);
173+
ok = egl_offscreen_render_surface_init(surface, tracer, size, renderer);
212174
if (ok != 0) {
213175
goto fail_free_surface;
214176
}
@@ -222,25 +184,6 @@ struct egl_offscreen_render_surface *egl_offscreen_render_surface_new_with_egl_c
222184
return NULL;
223185
}
224186

225-
/**
226-
* @brief Create a new gbm_surface based render surface.
227-
*
228-
* @param compositor The compositor that this surface will be registered to when calling surface_register.
229-
* @param size The size of the surface.
230-
* @param device The GBM device used to allocate the surface.
231-
* @param renderer The EGL/OpenGL used to create any GL surfaces.
232-
* @param pixel_format The pixel format to be used by the framebuffers of the surface.
233-
* @return struct egl_offscreen_render_surface*
234-
*/
235-
struct egl_offscreen_render_surface *egl_offscreen_render_surface_new(
236-
struct tracer *tracer,
237-
struct vec2i size,
238-
struct gl_renderer *renderer,
239-
enum pixfmt pixel_format
240-
) {
241-
return egl_offscreen_render_surface_new_with_egl_config(tracer, size, renderer, pixel_format, EGL_NO_CONFIG_KHR);
242-
}
243-
244187
void egl_offscreen_render_surface_deinit(struct surface *s) {
245188
struct egl_offscreen_render_surface *egl_surface;
246189

@@ -279,30 +222,33 @@ egl_offscreen_render_surface_present_fbdev(struct surface *s, const struct fl_la
279222

280223
static int egl_offscreen_render_surface_fill(struct render_surface *s, FlutterBackingStore *fl_store) {
281224
fl_store->type = kFlutterBackingStoreTypeOpenGL;
282-
fl_store->open_gl = (FlutterOpenGLBackingStore
283-
){ .type = kFlutterOpenGLTargetTypeFramebuffer,
284-
.framebuffer = { /* for some reason flutter wants this to be GL_BGRA8_EXT, contrary to what the docs say */
285-
.target = GL_BGRA8_EXT,
225+
fl_store->open_gl = (FlutterOpenGLBackingStore) {
226+
.type = kFlutterOpenGLTargetTypeFramebuffer,
227+
.framebuffer = {
228+
/* for some reason flutter wants this to be GL_BGRA8_EXT, contrary to what the docs say */
229+
.target = GL_BGRA8_EXT,
286230

287-
/* 0 refers to the window surface, instead of to an FBO */
288-
.name = 0,
231+
/* 0 refers to the window surface, instead of to an FBO */
232+
.name = 0,
289233

290-
/*
234+
/*
291235
* even though the compositor will call surface_ref too to fill the FlutterBackingStore.user_data,
292236
* we need to ref two times because flutter will call both this destruction callback and the
293237
* compositor collect callback
294238
*/
295-
.user_data = surface_ref(CAST_SURFACE_UNCHECKED(s)),
296-
.destruction_callback = surface_unref_void } };
239+
.user_data = surface_ref(CAST_SURFACE_UNCHECKED(s)),
240+
.destruction_callback = surface_unref_void,
241+
},
242+
};
297243
return 0;
298244
}
299245

300246
static int egl_offscreen_render_surface_queue_present(struct render_surface *s, const FlutterBackingStore *fl_store) {
301247
(void) s;
302248
(void) fl_store;
303-
249+
304250
// nothing to do here
305-
251+
306252
return 0;
307253
}
308254

src/egl_offscreen_render_surface.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,10 @@ ATTR_PURE struct egl_offscreen_render_surface *__checked_cast_egl_offscreen_rend
2424
#define CAST_EGL_OFFSCREEN_RENDER_SURFACE(ptr) CAST_EGL_OFFSCREEN_RENDER_SURFACE_UNCHECKED(ptr)
2525
#endif
2626

27-
struct egl_offscreen_render_surface *egl_offscreen_render_surface_new_with_egl_config(
28-
struct tracer *tracer,
29-
struct vec2i size,
30-
struct gl_renderer *renderer,
31-
enum pixfmt pixel_format,
32-
EGLConfig egl_config
33-
);
34-
3527
struct egl_offscreen_render_surface *egl_offscreen_render_surface_new(
3628
struct tracer *tracer,
3729
struct vec2i size,
38-
struct gl_renderer *renderer,
39-
enum pixfmt pixel_format
30+
struct gl_renderer *renderer
4031
);
4132

4233
ATTR_PURE EGLSurface egl_offscreen_render_surface_get_egl_surface(struct egl_offscreen_render_surface *s);

src/flutter-pi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,14 +2482,14 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {
24822482
vk_renderer = NULL;
24832483

24842484
if (gbm_device != NULL) {
2485-
gl_renderer = gl_renderer_new_from_gbm_device(tracer, gbm_device, cmd_args.has_pixel_format, cmd_args.pixel_format);
2485+
gl_renderer = gl_renderer_new_from_gbm_device(tracer, gbm_device);
24862486
if (gl_renderer == NULL) {
24872487
LOG_ERROR("Couldn't create EGL/OpenGL renderer.\n");
24882488
ok = EIO;
24892489
goto fail_unref_scheduler;
24902490
}
24912491
} else {
2492-
gl_renderer = gl_renderer_new_surfaceless(tracer, cmd_args.has_pixel_format, cmd_args.pixel_format);
2492+
gl_renderer = gl_renderer_new_surfaceless(tracer);
24932493
if (gl_renderer == NULL) {
24942494
LOG_ERROR("Couldn't create EGL/OpenGL renderer.\n");
24952495
ok = EIO;

0 commit comments

Comments
 (0)