Skip to content

Commit adb56c9

Browse files
committed
compositor, window: add ..._has_egl_surface()
Can be used to check if an EGL surface has already been created for this window. In the future, might be used by flutter-pi to make a surfaceless context current if not surface was created yet.
1 parent 17a25b0 commit adb56c9

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

src/compositor_ng.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ struct surface *compositor_get_view_by_id_locked(struct compositor *compositor,
459459
}
460460

461461
#ifdef HAVE_EGL_GLES2
462+
bool compositor_has_egl_surface(struct compositor *compositor) {
463+
return window_has_egl_surface(compositor->main_window);
464+
}
465+
462466
EGLSurface compositor_get_egl_surface(struct compositor *compositor) {
463467
return window_get_egl_surface(compositor->main_window);
464468
}

src/flutter-pi.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,26 @@ static bool on_make_current(void *userdata) {
283283
flutterpi = userdata;
284284
ASSERT_NOT_NULL(flutterpi->gl_renderer);
285285

286+
// Ideally we don't make a surface current here at all.
287+
// But that doesn't work right now.
288+
// if (compositor_has_egl_surface(flutterpi->compositor)) {
289+
// surface = compositor_get_egl_surface(flutterpi->compositor);
290+
// if (surface == EGL_NO_SURFACE) {
291+
// /// TODO: Get a fake EGL Surface just for initialization.
292+
// LOG_ERROR("Couldn't get an EGL surface from the compositor.\n");
293+
// return false;
294+
// }
295+
// ok = gl_renderer_make_flutter_rendering_context_current(flutterpi->gl_renderer, surface);
296+
// if (ok != 0) {
297+
// return false;
298+
// }
299+
// } else {
300+
// ok = gl_renderer_make_flutter_setup_context_current(flutterpi->gl_renderer);
301+
// if (ok != 0) {
302+
// return false;
303+
// }
304+
// }
305+
286306
surface = compositor_get_egl_surface(flutterpi->compositor);
287307
if (surface == EGL_NO_SURFACE) {
288308
/// TODO: Get a fake EGL Surface just for initialization.

src/window.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ struct window {
224224
struct render_surface *(*get_render_surface)(struct window *window, struct vec2i size);
225225

226226
#ifdef HAVE_EGL_GLES2
227+
bool (*has_egl_surface)(struct window *window);
227228
EGLSurface (*get_egl_surface)(struct window *window);
228229
#endif
229230

@@ -401,14 +402,12 @@ static int window_init(
401402
window->gl_renderer = NULL;
402403
window->vk_renderer = NULL;
403404
window->render_surface = NULL;
404-
#ifdef HAVE_EGL_GLES2
405-
window->egl_surface = NULL;
406-
#endif
407405
window->cursor_enabled = false;
408406
window->cursor_pos = VEC2I(0, 0);
409407
window->push_composition = NULL;
410408
window->get_render_surface = NULL;
411409
#ifdef HAVE_EGL_GLES2
410+
window->has_egl_surface = NULL;
412411
window->get_egl_surface = NULL;
413412
#endif
414413
window->set_cursor_locked = NULL;
@@ -477,6 +476,10 @@ int window_get_next_vblank(struct window *window, uint64_t *next_vblank_ns_out)
477476
}
478477

479478
#ifdef HAVE_EGL_GLES2
479+
bool window_has_egl_surface(struct window *window) {
480+
return window->egl_surface;
481+
}
482+
480483
EGLSurface window_get_egl_surface(struct window *window) {
481484
ASSERT_NOT_NULL(window);
482485
ASSERT_NOT_NULL(window->get_egl_surface);
@@ -863,6 +866,7 @@ static int kms_window_push_composition(struct window *window, struct fl_layer_co
863866
static struct render_surface *kms_window_get_render_surface(struct window *window, struct vec2i size);
864867

865868
#ifdef HAVE_EGL_GLES2
869+
static bool kms_window_has_egl_surface(struct window *window);
866870
static EGLSurface kms_window_get_egl_surface(struct window *window);
867871
#endif
868872

@@ -1007,6 +1011,7 @@ MUST_CHECK struct window *kms_window_new(
10071011
window->push_composition = kms_window_push_composition;
10081012
window->get_render_surface = kms_window_get_render_surface;
10091013
#ifdef HAVE_EGL_GLES2
1014+
window->has_egl_surface = kms_window_has_egl_surface;
10101015
window->get_egl_surface = kms_window_get_egl_surface;
10111016
#endif
10121017
window->deinit = kms_window_deinit;
@@ -1486,6 +1491,14 @@ static struct render_surface *kms_window_get_render_surface(struct window *windo
14861491
}
14871492

14881493
#ifdef HAVE_EGL_GLES2
1494+
static bool kms_window_has_egl_surface(struct window *window) {
1495+
if (window->renderer_type == kOpenGL_RendererType) {
1496+
return window->render_surface != NULL;
1497+
} else {
1498+
return false;
1499+
}
1500+
}
1501+
14891502
static EGLSurface kms_window_get_egl_surface(struct window *window) {
14901503
if (window->renderer_type == kOpenGL_RendererType) {
14911504
struct render_surface *render_surface = kms_window_get_render_surface_internal(window, false, VEC2I(0, 0));

src/window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ ATTR_PURE double window_get_refresh_rate(struct window *window);
102102
*/
103103
int window_get_next_vblank(struct window *window, uint64_t *next_vblank_ns_out);
104104

105+
#ifdef HAVE_EGL_GLES2
105106
bool window_has_egl_surface(struct window *window);
106107

107-
#ifdef HAVE_EGL_GLES2
108108
EGLSurface window_get_egl_surface(struct window *window);
109109
#endif
110110

0 commit comments

Comments
 (0)