From 65c75859bcb7e49b2ce67fb45ad4de2225f5cbde Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 21 Mar 2019 16:54:15 +0530 Subject: [PATCH] Move rendering of resize banner into the tick callback Unifies all rendering in one place. And possibly fixes issues with rendering in a resize callback on sway. --- kitty/child-monitor.c | 23 +++++++++++++++++++++-- kitty/glfw.c | 18 +----------------- kitty/state.h | 1 + 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 058ce28c8..00109396c 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -652,6 +652,18 @@ update_os_window_title(OSWindow *os_window) { } } +static void +draw_resizing_text(OSWindow *w) { + char text[32] = {0}; + unsigned int width = w->live_resize.width, height = w->live_resize.height; + snprintf(text, sizeof(text), "%u x %u cells", width / w->fonts_data->cell_width, height / w->fonts_data->cell_height); + StringCanvas rendered = render_simple_text(w->fonts_data, text); + if (rendered.canvas) { + draw_centered_alpha_mask(w->gvao_idx, width, height, rendered.width, rendered.height, rendered.canvas); + free(rendered.canvas); + } +} + static inline void render(double now) { double time_since_last_render = now - last_render_at; @@ -663,7 +675,7 @@ render(double now) { for (size_t i = 0; i < global_state.num_os_windows; i++) { OSWindow *w = global_state.os_windows + i; if (!w->num_tabs) continue; - if ((w->live_resize.in_progress && (now - w->live_resize.last_resize_event_at) < 1) || !should_os_window_be_rendered(w)) { + if (!should_os_window_be_rendered(w)) { update_os_window_title(w); continue; } @@ -671,8 +683,15 @@ render(double now) { if (w->render_state == RENDER_FRAME_NOT_REQUESTED) request_frame_render(w); continue; } - bool needs_render = w->is_damaged; make_os_window_context_current(w); + if (w->live_resize.in_progress) { + blank_os_window(w); + draw_resizing_text(w); + swap_window_buffers(w); + if (USE_RENDER_FRAMES) request_frame_render(w); + continue; + } + bool needs_render = w->is_damaged; if (w->viewport_size_dirty) { w->clear_count = 0; update_surface_size(w->viewport_width, w->viewport_height, w->offscreen_texture_id); diff --git a/kitty/glfw.c b/kitty/glfw.c index e763ba769..c302c96ec 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -53,17 +53,6 @@ update_os_window_viewport(OSWindow *window, bool notify_boss) { } } -static void -draw_resizing_text(OSWindow *w, unsigned int width, unsigned int height) { - char text[32] = {0}; - snprintf(text, sizeof(text), "%u x %u cells", width / w->fonts_data->cell_width, height / w->fonts_data->cell_height); - StringCanvas rendered = render_simple_text(w->fonts_data, text); - if (rendered.canvas) { - draw_centered_alpha_mask(w->gvao_idx, width, height, rendered.width, rendered.height, rendered.canvas); - free(rendered.canvas); - } -} - // callbacks {{{ void @@ -161,14 +150,9 @@ framebuffer_size_callback(GLFWwindow *w, int width, int height) { global_state.has_pending_resizes = true; window->live_resize.in_progress = true; window->live_resize.last_resize_event_at = monotonic(); - // render OS window as blank. On cocoa this is needed for semi-transparent windows, - // otherwise you get burn in of the previous frame. On Linux this is needed as otherwise - // you get partially rendered windows. + window->live_resize.width = MAX(0, width); window->live_resize.height = MAX(0, height); make_os_window_context_current(window); update_surface_size(width, height, window->offscreen_texture_id); - blank_os_window(window); - draw_resizing_text(window, MAX(0, width), MAX(0, height)); - swap_window_buffers(window); request_tick_callback(); } else log_error("Ignoring resize request for tiny size: %dx%d", width, height); global_state.callback_os_window = NULL; diff --git a/kitty/state.h b/kitty/state.h index 8d768504b..ff119625d 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -112,6 +112,7 @@ typedef struct { bool in_progress; bool from_os_notification; bool os_says_resize_complete; + unsigned int width, height; } LiveResizeInfo;