From 2b988b01c6bf9476fd17eb774ec3f46e4f814909 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Nov 2017 22:31:55 +0530 Subject: [PATCH] Get rid of the needs_render tracking as it was too fragile. --- kitty/child-monitor.c | 37 +++++++++++++++---------------------- kitty/screen.h | 4 +--- kitty/shaders.c | 32 ++++++-------------------------- kitty/state.h | 3 +-- 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 9a97a7764..15ce45151 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -497,13 +497,12 @@ simple_render_screen(PyObject UNUSED *self, PyObject *args) { ssize_t vao_idx, gvao_idx; float xstart, ystart, dx, dy; if (!PyArg_ParseTuple(args, "O!nnffff", &Screen_Type, &screen, &vao_idx, &gvao_idx, &xstart, &ystart, &dx, &dy)) return NULL; - PyObject *ret = draw_cells(vao_idx, gvao_idx, xstart, ystart, dx, dy, screen, current_os_window()) ? Py_True : Py_False; - Py_INCREF(ret); return ret; + draw_cells(vao_idx, gvao_idx, xstart, ystart, dx, dy, screen, current_os_window()); + Py_RETURN_NONE; } -static inline bool +static inline void render_os_window(OSWindow *os_window, double now, unsigned int *active_window_id) { - bool dirtied = false; if (OPT(mouse_hide_wait) > 0 && now - os_window->last_mouse_activity_at > OPT(mouse_hide_wait)) hide_mouse(os_window); Tab *tab = os_window->tabs + os_window->active_tab; for (unsigned int i = 0; i < tab->num_windows; i++) { @@ -521,14 +520,12 @@ render_os_window(OSWindow *os_window, double now, unsigned int *active_window_id bool is_active_window = i == tab->active_window; if (is_active_window) { *active_window_id = w->id; - collect_cursor_info(&WD.screen->current_cursor_render_info, w, now, os_window); - if (update_window_title(w, os_window)) dirtied = true; - } else WD.screen->current_cursor_render_info.is_visible = false; - if (draw_cells(WD.vao_idx, WD.gvao_idx, WD.xstart, WD.ystart, WD.dx, WD.dy, WD.screen, os_window)) { - if (is_active_window && WD.screen->current_cursor_render_info.is_visible && WD.screen->current_cursor_render_info.shape != CURSOR_BLOCK) { - draw_cursor(&WD.screen->current_cursor_render_info, os_window == global_state.focused_os_window); - } - dirtied = true; + collect_cursor_info(&WD.screen->cursor_render_info, w, now, os_window); + update_window_title(w, os_window); + } else WD.screen->cursor_render_info.is_visible = false; + draw_cells(WD.vao_idx, WD.gvao_idx, WD.xstart, WD.ystart, WD.dx, WD.dy, WD.screen, os_window); + if (is_active_window && WD.screen->cursor_render_info.is_visible && WD.screen->cursor_render_info.shape != CURSOR_BLOCK) { + draw_cursor(&WD.screen->cursor_render_info, os_window == global_state.focused_os_window); } if (WD.screen->start_visual_bell_at != 0) { double bell_left = global_state.opts.visual_bell_duration - (now - WD.screen->start_visual_bell_at); @@ -537,7 +534,6 @@ render_os_window(OSWindow *os_window, double now, unsigned int *active_window_id } } #undef WD - return dirtied; } static inline void @@ -557,17 +553,14 @@ render(double now) { w->viewport_size_dirty = false; } unsigned int active_window_id = 0; - bool window_rendered = render_os_window(w, now, &active_window_id); - bool tab_bar_changed = w->num_tabs > 1 && (w->last_active_tab != w->active_tab || w->last_num_tabs != w->num_tabs); + render_os_window(w, now, &active_window_id); Tab *active_tab = w->tabs + w->active_tab; BorderRects *br = &active_tab->border_rects; - if (window_rendered || tab_bar_changed || br->is_dirty || active_window_id != w->last_active_window_id) { - draw_borders(br->vao_idx, br->num_border_rects, br->rect_buf, br->is_dirty, w->viewport_width, w->viewport_height); - if (TD.screen && w->num_tabs > 1) draw_cells(TD.vao_idx, 0, TD.xstart, TD.ystart, TD.dx, TD.dy, TD.screen, w); - swap_window_buffers(w); - w->last_active_tab = w->active_tab; w->last_num_tabs = w->num_tabs; w->last_active_window_id = active_window_id; - br->is_dirty = false; - } + draw_borders(br->vao_idx, br->num_border_rects, br->rect_buf, br->is_dirty, w->viewport_width, w->viewport_height); + if (TD.screen && w->num_tabs > 1) draw_cells(TD.vao_idx, 0, TD.xstart, TD.ystart, TD.dx, TD.dy, TD.screen, w); + swap_window_buffers(w); + w->last_active_tab = w->active_tab; w->last_num_tabs = w->num_tabs; w->last_active_window_id = active_window_id; + br->is_dirty = false; } last_render_at = now; #undef TD diff --git a/kitty/screen.h b/kitty/screen.h index 47af2921c..e2b8a73bd 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -56,9 +56,7 @@ typedef struct { size_t read_buf_sz, write_buf_sz, write_buf_used; pthread_mutex_t read_buf_lock, write_buf_lock; - CursorRenderInfo last_cursor_render_info, current_cursor_render_info; - bool colors_inverted_at_last_render; - float last_render_x_start, last_render_y_start; + CursorRenderInfo cursor_render_info; } Screen; diff --git a/kitty/shaders.c b/kitty/shaders.c index a163df7b3..6b0c8bce0 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -239,12 +239,11 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G unmap_vao_buffer(vao_idx, uniform_buffer); rd = NULL; } -static inline bool +static inline void cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloat xstart, GLfloat ystart, GLfloat dx, GLfloat dy) { size_t sz; CELL_BUFFERS; void *address; - bool needs_render = false; ensure_sprite_map(); @@ -253,7 +252,6 @@ cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloa address = alloc_and_map_vao_buffer(vao_idx, sz, cell_data_buffer, GL_STREAM_DRAW, GL_WRITE_ONLY); screen_update_cell_data(screen, address, sz); unmap_vao_buffer(vao_idx, cell_data_buffer); address = NULL; - needs_render = true; } if (screen_is_selection_dirty(screen)) { @@ -261,7 +259,6 @@ cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloa address = alloc_and_map_vao_buffer(vao_idx, sz, selection_buffer, GL_STREAM_DRAW, GL_WRITE_ONLY); screen_apply_selection(screen, address, sz); unmap_vao_buffer(vao_idx, selection_buffer); address = NULL; - needs_render = true; } if (gvao_idx && grman_update_layers(screen->grman, screen->scrolled_by, xstart, ystart, dx, dy, screen->columns, screen->lines)) { @@ -269,28 +266,13 @@ cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloa GLfloat *a = alloc_and_map_vao_buffer(gvao_idx, sz, 0, GL_STREAM_DRAW, GL_WRITE_ONLY); for (size_t i = 0; i < screen->grman->count; i++, a += 16) memcpy(a, screen->grman->render_data[i].vertices, sizeof(screen->grman->render_data[0].vertices)); unmap_vao_buffer(gvao_idx, 0); a = NULL; - needs_render = true; } bool inverted = screen_invert_colors(screen); - if (inverted != screen->colors_inverted_at_last_render) needs_render = true; - if (!needs_render && (screen->last_render_x_start != xstart || screen->last_render_y_start != ystart)) needs_render = true; -#define CC(attr) (screen->last_cursor_render_info.attr != screen->current_cursor_render_info.attr) - if (!needs_render && (CC(is_visible) || CC(shape) || CC(x) || CC(y) || CC(color))) needs_render = true; -#undef CC + cell_update_uniform_block(vao_idx, screen, uniform_buffer, xstart, ystart, dx, dy, &screen->cursor_render_info, inverted); - if (needs_render) { - cell_update_uniform_block(vao_idx, screen, uniform_buffer, xstart, ystart, dx, dy, &screen->current_cursor_render_info, inverted); - - bind_vao_uniform_buffer(vao_idx, uniform_buffer, cell_program_layouts[CELL_PROGRAM].render_data.index); - bind_vertex_array(vao_idx); - screen->colors_inverted_at_last_render = inverted; - screen->last_render_x_start = xstart; screen->last_render_y_start = ystart; -#define CC(attr) screen->last_cursor_render_info.attr = screen->current_cursor_render_info.attr - CC(is_visible); CC(shape); CC(x); CC(y); CC(color); -#undef CC - } - return needs_render; + bind_vao_uniform_buffer(vao_idx, uniform_buffer, cell_program_layouts[CELL_PROGRAM].render_data.index); + bind_vertex_array(vao_idx); } static void @@ -348,10 +330,9 @@ draw_cells_interleaved(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen) { if (screen->grman->num_of_positive_refs) draw_graphics(vao_idx, gvao_idx, screen->grman->render_data, screen->grman->num_of_negative_refs, screen->grman->num_of_positive_refs); } -bool +void draw_cells(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat ystart, GLfloat dx, GLfloat dy, Screen *screen, OSWindow *os_window) { - bool needs_render = cell_prepare_to_render(vao_idx, gvao_idx, screen, xstart, ystart, dx, dy); - if (!needs_render) return false; + cell_prepare_to_render(vao_idx, gvao_idx, screen, xstart, ystart, dx, dy); GLfloat h = (GLfloat)screen->lines * dy; #define SCALE(w, x) ((GLfloat)(os_window->viewport_##w) * (GLfloat)(x)) glScissor( @@ -363,7 +344,6 @@ draw_cells(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat ystart, GL #undef SCALE if (screen->grman->num_of_negative_refs) draw_cells_interleaved(vao_idx, gvao_idx, screen); else draw_all_cells(vao_idx, gvao_idx, screen); - return true; } // }}} diff --git a/kitty/state.h b/kitty/state.h index 8576f3176..793709d5d 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -98,7 +98,6 @@ typedef struct { PyObject *window_title; bool is_key_pressed[MAX_KEY_COUNT]; bool viewport_size_dirty; - bool needs_render; } OSWindow; @@ -147,7 +146,7 @@ void draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *re ssize_t create_cell_vao(); ssize_t create_graphics_vao(); ssize_t create_border_vao(); -bool draw_cells(ssize_t, ssize_t, float, float, float, float, Screen *, OSWindow *); +void draw_cells(ssize_t, ssize_t, float, float, float, float, Screen *, OSWindow *); void draw_cursor(CursorRenderInfo *, bool); void update_surface_size(int, int); void free_texture(uint32_t*);