diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c index 7940faf2b9..377b678cde 100644 --- a/video/out/opengl/context.c +++ b/video/out/opengl/context.c @@ -223,6 +223,17 @@ int ra_gl_ctx_color_depth(struct ra_swapchain *sw) bool ra_gl_ctx_start_frame(struct ra_swapchain *sw, struct ra_fbo *out_fbo) { struct priv *p = sw->priv; + + bool visible = true; + if (p->params.check_visible) + visible = p->params.check_visible(sw->ctx); + if (!visible) + return false; + + // If out_fbo is NULL, this was called from vo_gpu_next. Bail out. + if (out_fbo == NULL || !visible) + return visible; + if (!out_fbo) return true; *out_fbo = (struct ra_fbo) { diff --git a/video/out/opengl/context.h b/video/out/opengl/context.h index 222661ad83..19521ff54b 100644 --- a/video/out/opengl/context.h +++ b/video/out/opengl/context.h @@ -21,6 +21,10 @@ enum gles_mode ra_gl_ctx_get_glesmode(struct ra_ctx *ctx); // clean them up) struct ra_gl_ctx_params { + // For special contexts (i.e. wayland) that want to check visibility + // before drawing a frame. + bool (*check_visible)(struct ra_ctx *ctx); + // Set to the platform-specific function to swap buffers, like // glXSwapBuffers, eglSwapBuffers etc. This will be called by // ra_gl_ctx_swap_buffers. Required unless you either never call that diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index a7a8f4f3b4..98d702c386 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -54,19 +54,13 @@ static void resize(struct ra_ctx *ctx) wl->vo->dheight = height; } -static bool wayland_egl_start_frame(struct ra_swapchain *sw, struct ra_fbo *out_fbo) +static bool wayland_egl_check_visible(struct ra_ctx *ctx) { - struct ra_ctx *ctx = sw->ctx; - struct vo_wayland_state *wl = ctx->vo->wl; - bool render = !wl->hidden || wl->opts->disable_vsync; - wl->frame_wait = true; - - return render ? ra_gl_ctx_start_frame(sw, out_fbo) : false; + return vo_wayland_check_visible(ctx->vo); } -static void wayland_egl_swap_buffers(struct ra_swapchain *sw) +static void wayland_egl_swap_buffers(struct ra_ctx *ctx) { - struct ra_ctx *ctx = sw->ctx; struct priv *p = ctx->priv; struct vo_wayland_state *wl = ctx->vo->wl; @@ -79,11 +73,6 @@ static void wayland_egl_swap_buffers(struct ra_swapchain *sw) vo_wayland_sync_swap(wl); } -static const struct ra_swapchain_fns wayland_egl_swapchain = { - .start_frame = wayland_egl_start_frame, - .swap_buffers = wayland_egl_swap_buffers, -}; - static void wayland_egl_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info) { struct vo_wayland_state *wl = ctx->vo->wl; @@ -116,8 +105,9 @@ static bool egl_create_context(struct ra_ctx *ctx) mpegl_load_functions(&p->gl, wl->log); struct ra_gl_ctx_params params = { - .external_swapchain = &wayland_egl_swapchain, - .get_vsync = &wayland_egl_get_vsync, + .check_visible = wayland_egl_check_visible, + .swap_buffers = wayland_egl_swap_buffers, + .get_vsync = wayland_egl_get_vsync, }; if (!ra_gl_ctx_init(ctx, &p->gl, params)) diff --git a/video/out/vo_wlshm.c b/video/out/vo_wlshm.c index 4744e505f3..76abb9c6a0 100644 --- a/video/out/vo_wlshm.c +++ b/video/out/vo_wlshm.c @@ -218,9 +218,8 @@ static void draw_image(struct vo *vo, struct mp_image *src) struct priv *p = vo->priv; struct vo_wayland_state *wl = vo->wl; struct buffer *buf; - bool render = !wl->hidden || wl->opts->disable_vsync; - wl->frame_wait = true; + bool render = vo_wayland_check_visible(vo); if (!render) return; diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c index 0770004b4c..ab54789890 100644 --- a/video/out/vulkan/context_wayland.c +++ b/video/out/vulkan/context_wayland.c @@ -28,11 +28,7 @@ struct priv { static bool wayland_vk_check_visible(struct ra_ctx *ctx) { - struct vo_wayland_state *wl = ctx->vo->wl; - bool render = !wl->hidden || wl->opts->disable_vsync; - wl->frame_wait = true; - - return render; + return vo_wayland_check_visible(ctx->vo); } static void wayland_vk_swap_buffers(struct ra_ctx *ctx) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index ee6b3e885d..eddaae952d 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -1562,6 +1562,14 @@ static void vo_wayland_dispatch_events(struct vo_wayland_state *wl, int nfds, in } /* Non-static */ +bool vo_wayland_check_visible(struct vo *vo) +{ + struct vo_wayland_state *wl = vo->wl; + bool render = !wl->hidden || wl->opts->disable_vsync; + wl->frame_wait = true; + return render; +} + int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) { struct vo_wayland_state *wl = vo->wl; diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index 14b5fdce09..faca1cd19b 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -125,6 +125,8 @@ struct vo_wayland_state { uint32_t pointer_id; }; +bool vo_wayland_check_visible(struct vo *vo); + int vo_wayland_control(struct vo *vo, int *events, int request, void *arg); int vo_wayland_init(struct vo *vo); int vo_wayland_reconfig(struct vo *vo);