Skip to content

Commit 3821405

Browse files
committed
Progress
1 parent 71ebd37 commit 3821405

File tree

9 files changed

+33
-35
lines changed

9 files changed

+33
-35
lines changed

kitty/child-monitor.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,11 @@ static inline void
617617
render_os_window(OSWindow *os_window, double now, unsigned int active_window_id, color_type active_window_bg, unsigned int num_visible_windows) {
618618
static bool first_time = true;
619619
if (first_time) {
620-
setup_scroll(os_window->viewport_width, os_window->viewport_height);
620+
setup_scroll(os_window);
621621
first_time = false;
622622
}
623623
// ensure all pixels are cleared to background color at least once in every buffer
624-
if (os_window->clear_count++ < 3) blank_os_window(os_window);
624+
if (os_window->clear_count++ < 2) blank_os_window(os_window);
625625
Tab *tab = os_window->tabs + os_window->active_tab;
626626
BorderRects *br = &tab->border_rects;
627627
bool static_live_resize_in_progress = os_window->live_resize.in_progress && OPT(resize_draw_strategy) == RESIZE_DRAW_STATIC;
@@ -644,8 +644,7 @@ render_os_window(OSWindow *os_window, double now, unsigned int active_window_id,
644644
double bell_left = global_state.opts.visual_bell_duration - (now - WD.screen->start_visual_bell_at);
645645
set_maximum_wait(bell_left);
646646
}
647-
double pixels = get_scrolled_by_pixels(WD.screen);
648-
after_render(pixels / os_window->viewport_height * 2);
647+
after_render(os_window, (WD.screen->scrolled_by_pixels * 2.0) / os_window->viewport_height);
649648
w->cursor_visible_at_last_render = WD.screen->cursor_render_info.is_visible; w->last_cursor_x = WD.screen->cursor_render_info.x; w->last_cursor_y = WD.screen->cursor_render_info.y; w->last_cursor_shape = WD.screen->cursor_render_info.shape;
650649
}
651650
}
@@ -711,7 +710,7 @@ render(double now) {
711710
bool needs_render = w->is_damaged || w->live_resize.in_progress;
712711
if (w->viewport_size_dirty) {
713712
w->clear_count = 0;
714-
update_surface_size(w->viewport_width, w->viewport_height, w->offscreen_texture_id);
713+
update_surface_size(w->viewport_width, w->viewport_height, w->offscreen_texture_id, w->scroll_texture_id);
715714
w->viewport_size_dirty = false;
716715
needs_render = true;
717716
}

kitty/gl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ gl_init() {
6767
}
6868

6969
void
70-
update_surface_size(int w, int h, GLuint offscreen_texture_id) {
70+
update_surface_size(int w, int h, GLuint offscreen_texture_id, GLuint scroll_texture_id) {
7171
glViewport(0, 0, w, h);
72+
if (scroll_texture_id) {
73+
glBindTexture(GL_TEXTURE_2D, scroll_texture_id);
74+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
75+
}
7276
if (offscreen_texture_id) {
7377
glBindTexture(GL_TEXTURE_2D, offscreen_texture_id);
7478
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

kitty/glfw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ framebuffer_size_callback(GLFWwindow *w, int width, int height) {
160160
window->live_resize.width = MAX(0, width); window->live_resize.height = MAX(0, height);
161161
window->live_resize.num_of_resize_events++;
162162
make_os_window_context_current(window);
163-
update_surface_size(width, height, window->offscreen_texture_id);
163+
update_surface_size(width, height, window->offscreen_texture_id, window->scroll_texture_id);
164164
request_tick_callback();
165165
} else log_error("Ignoring resize request for tiny size: %dx%d", width, height);
166166
global_state.callback_os_window = NULL;

kitty/mouse.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,9 @@ scroll_event(double UNUSED xoffset, double yoffset, int flags) {
602602

603603
if (is_high_resolution) {
604604
yoffset *= OPT(touch_scroll_multiplier);
605-
double pixels = global_state.callback_os_window->pending_scroll_pixels + yoffset;
605+
double pixels = screen->pending_scroll_pixels + yoffset;
606606
s = (int)round(pixels) / (int)global_state.callback_os_window->fonts_data->cell_height;
607-
global_state.callback_os_window->pending_scroll_pixels = pixels - s * (int) global_state.callback_os_window->fonts_data->cell_height;
607+
screen->pending_scroll_pixels = pixels - s * (int) global_state.callback_os_window->fonts_data->cell_height;
608608
} else {
609609
if (screen->linebuf == screen->main_linebuf || !screen->modes.mouse_tracking_mode) {
610610
// Only use wheel_scroll_multiplier if we are scrolling kitty scrollback or in mouse
@@ -621,8 +621,8 @@ scroll_event(double UNUSED xoffset, double yoffset, int flags) {
621621
if (s == 0 && yoffset != 0) s = yoffset > 0 ? 1 : -1;
622622
}
623623
bool upwards = s > 0;
624-
int pixels = global_state.callback_os_window->pending_scroll_pixels;
625-
//printf("asdf %f\n", pixels);
624+
int pixels = screen->pending_scroll_pixels;
625+
printf("asdf %d\n", pixels);
626626
if (screen->linebuf == screen->main_linebuf) {
627627
screen_history_scroll(screen, abs(s), upwards);
628628
if (screen->scrolled_by != 0) {

kitty/screen.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,11 +1516,6 @@ screen_update_cell_data(Screen *self, void *address, FONTS_DATA_HANDLE fonts_dat
15161516
}
15171517
}
15181518

1519-
double get_scrolled_by_pixels(Screen *self) {
1520-
return self->scrolled_by_pixels;
1521-
}
1522-
1523-
15241519
static inline bool
15251520
is_selection_empty(Screen *self, unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y) {
15261521
return (start_x >= self->columns || start_y >= self->lines || end_x >= self->columns || end_y >= self->lines || (start_x == end_x && start_y == end_y)) ? true : false;
@@ -2046,7 +2041,8 @@ screen_selection_range_for_word(Screen *self, index_type x, index_type *y1, inde
20462041
#undef is_ok
20472042
}
20482043

2049-
void pixel_scroll(Screen *self, double amt) {
2044+
void pixel_scroll(Screen *self, int amt) {
2045+
printf("pixel_scroll(%d)\n", amt);
20502046
self->scrolled_by_pixels = amt;
20512047
self->pixel_scroll_changed = true;
20522048
}

kitty/screen.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ typedef struct {
6666
6767
unsigned int columns, lines, margin_top, margin_bottom, charset, scrolled_by, last_selection_scrolled_by;
6868
unsigned int last_rendered_cursor_x, last_rendered_cursor_y;
69-
double scrolled_by_pixels;
69+
int scrolled_by_pixels;
70+
double pending_scroll_pixels;
7071
CellPixelSize cell_size;
7172
OverlayLine overlay_line;
7273
id_type window_id;
@@ -180,13 +181,12 @@ bool screen_is_selection_dirty(Screen *self);
180181
bool screen_has_selection(Screen*);
181182
bool screen_invert_colors(Screen *self);
182183
void screen_update_cell_data(Screen *self, void *address, FONTS_DATA_HANDLE, bool cursor_has_moved);
183-
double get_scrolled_by_pixels(Screen *self);
184184
bool screen_is_cursor_visible(Screen *self);
185185
bool screen_selection_range_for_line(Screen *self, index_type y, index_type *start, index_type *end);
186186
bool screen_selection_range_for_word(Screen *self, index_type x, index_type *, index_type *, index_type *start, index_type *end, bool);
187187
void screen_start_selection(Screen *self, index_type x, index_type y, bool, SelectionExtendMode);
188188
void screen_update_selection(Screen *self, index_type x, index_type y, bool ended);
189-
void pixel_scroll(Screen *self, double amt);
189+
void pixel_scroll(Screen *self, int amt);
190190
bool screen_history_scroll(Screen *self, int amt, bool upwards);
191191
Line* screen_visual_line(Screen *self, index_type y);
192192
unsigned long screen_current_char_width(Screen *self);

kitty/shaders.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ typedef struct {
155155
static CellProgramLayout cell_program_layouts[NUM_PROGRAMS];
156156
static GLuint offscreen_framebuffer = 0;
157157
static GLuint scroll_framebuffer = 0;
158-
static unsigned int scroll_texture = 0;
159158
static unsigned int quadVAO, quadVBO;
160159
static ssize_t blit_vertex_array;
161160

@@ -179,18 +178,18 @@ init_cell_program(void) {
179178
blit_vertex_array = create_vao();
180179
}
181180

182-
void setup_scroll(int UNUSED width, int UNUSED height) {
181+
void setup_scroll(OSWindow *os_window) {
183182
glGenFramebuffers(1, &scroll_framebuffer);
184183
glBindFramebuffer(GL_FRAMEBUFFER, scroll_framebuffer);
185-
glGenTextures(1, &scroll_texture);
186-
glBindTexture(GL_TEXTURE_2D, scroll_texture);
187-
printf("%d %d\n", width, height);
188-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
189-
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 640, 400, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
184+
glGenTextures(1, &os_window->scroll_texture_id);
185+
glBindTexture(GL_TEXTURE_2D, os_window->scroll_texture_id);
186+
printf("%d %d\n", os_window->viewport_width, os_window->viewport_height);
187+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, os_window->viewport_width, os_window->viewport_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
188+
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 640, 400, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
190189
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
191190
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
192191
glBindTexture(GL_TEXTURE_2D, 0);
193-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, scroll_texture, 0);
192+
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, os_window->scroll_texture_id, 0);
194193

195194
float quadVertices[] = { // vertex attributes for a quad that fills the entire screen in Normalized Device Coordinates.
196195
// positions // texCoords
@@ -221,7 +220,7 @@ void before_render() {
221220
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // we're not using the stencil buffer now
222221
}
223222

224-
void after_render(double pixels) {
223+
void after_render(OSWindow *os_window, double pixels) {
225224
// second pass
226225
glBindFramebuffer(GL_FRAMEBUFFER, 0); // back to default
227226
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
@@ -231,7 +230,7 @@ void after_render(double pixels) {
231230
bind_program(SCROLL_PROGRAM);
232231
glUniform1f(glGetUniformLocation(program_id(SCROLL_PROGRAM), "offset"), pixels);
233232
glBindVertexArray(quadVAO);
234-
glBindTexture(GL_TEXTURE_2D, scroll_texture);
233+
glBindTexture(GL_TEXTURE_2D, os_window->scroll_texture_id);
235234
glDrawArrays(GL_TRIANGLES, 0, 6);
236235
}
237236

kitty/state.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ destroy_os_window_item(OSWindow *w) {
180180
}
181181
Py_CLEAR(w->window_title); Py_CLEAR(w->tab_bar_render_data.screen);
182182
if (w->offscreen_texture_id) free_texture(&w->offscreen_texture_id);
183+
if (w->scroll_texture_id) free_texture(&w->scroll_texture_id);
183184
remove_vao(w->tab_bar_render_data.vao_idx);
184185
remove_vao(w->gvao_idx);
185186
free(w->tabs); w->tabs = NULL;

kitty/state.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,12 @@ typedef struct {
140140
bool viewport_size_dirty;
141141
LiveResizeInfo live_resize;
142142
bool has_pending_resizes, is_semi_transparent, shown_once, is_damaged;
143-
uint32_t offscreen_texture_id;
143+
uint32_t offscreen_texture_id, scroll_texture_id;
144144
unsigned int clear_count;
145145
color_type last_titlebar_color;
146146
float background_opacity;
147147
FONTS_DATA_HANDLE fonts_data;
148148
id_type temp_font_group_id;
149-
double pending_scroll_pixels;
150149
enum RENDER_STATE render_state;
151150
id_type last_focused_counter;
152151
ssize_t gvao_idx;
@@ -203,17 +202,17 @@ OSWindow* add_os_window(void);
203202
OSWindow* current_os_window(void);
204203
void os_window_regions(OSWindow*, Region *main, Region *tab_bar);
205204
bool drag_scroll(Window *, OSWindow*);
206-
void setup_scroll(int width, int height);
205+
void setup_scroll(OSWindow *os_window);
207206
void before_render();
208-
void after_render(double pixels);
207+
void after_render(OSWindow *os_window, double pixels);
209208
void draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_buf, bool rect_data_is_dirty, uint32_t viewport_width, uint32_t viewport_height, color_type, unsigned int, OSWindow *w);
210209
ssize_t create_cell_vao(void);
211210
ssize_t create_graphics_vao(void);
212211
ssize_t create_border_vao(void);
213212
bool send_cell_data_to_gpu(ssize_t, ssize_t, float, float, float, float, Screen *, OSWindow *);
214213
void draw_cells(ssize_t, ssize_t, float, float, float, float, Screen *, OSWindow *, bool, bool);
215214
void draw_centered_alpha_mask(ssize_t gvao_idx, size_t screen_width, size_t screen_height, size_t width, size_t height, uint8_t *canvas);
216-
void update_surface_size(int, int, uint32_t);
215+
void update_surface_size(int, int, uint32_t, uint32_t);
217216
void free_texture(uint32_t*);
218217
void send_image_to_gpu(uint32_t*, const void*, int32_t, int32_t, bool, bool);
219218
void send_sprite_to_gpu(FONTS_DATA_HANDLE fg, unsigned int, unsigned int, unsigned int, pixel*);

0 commit comments

Comments
 (0)