Skip to content

Commit f8e0b8b

Browse files
use a dirty flag to prevent unneccessary buffer flips of unchanged backbuffers
1 parent bb13980 commit f8e0b8b

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/drawing.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <kernel.h>
22

3+
extern bool video_dirty;
4+
35
void swap(int64_t* first, int64_t* second)
46
{
57
*first += *second;
@@ -20,11 +22,6 @@ void clamp_range(int64_t* coordinate, coordinate_range_type_t type)
2022

2123
void draw_line(int64_t from_x, int64_t from_y, int64_t to_x, int64_t to_y, uint32_t colour)
2224
{
23-
/*if (from_y == to_y) {
24-
draw_horizontal_line(from_x, to_x, from_y, colour);
25-
return;
26-
}*/
27-
2825
int64_t dx = labs(from_x - to_x);
2926
int64_t sx = from_x < to_x ? 1 : -1;
3027
int64_t dy = -(labs(from_y - to_y));
@@ -61,6 +58,7 @@ void draw_horizontal_line(int64_t from_x, int64_t to_x, int64_t y, uint32_t colo
6158
*addr = colour;
6259
addr++;
6360
}
61+
video_dirty = true;
6462
}
6563

6664
void draw_horizontal_rectangle(int64_t from_x, int64_t from_y, int64_t to_x, int64_t to_y, uint32_t colour)
@@ -146,6 +144,7 @@ void draw_triangle(int64_t x1, int64_t y1, int64_t x2, int64_t y2, int64_t x3, i
146144
}
147145
}
148146
}
147+
video_dirty = true;
149148
}
150149

151150

src/net/ip.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ void ip_frag_gc(void) {
9898
uint64_t ticks = get_ticks();
9999

100100
interrupts_off();
101+
if (!frag_map) {
102+
interrupts_on();
103+
return;
104+
}
101105
while (hashmap_iter(frag_map, &i, &item)) {
102106
ip_fragmented_packet_parts_t *frag = item;
103107

@@ -548,5 +552,5 @@ void ip_init()
548552
ethernet_register_iee802_number(ETHERNET_TYPE_IP, (ethernet_protocol_t)ip_handle_packet);
549553
ethernet_register_iee802_number(ETHERNET_TYPE_IP6, (ethernet_protocol_t)ip6_handle_packet);
550554
proc_register_idle(ip_idle, IDLE_BACKGROUND);
551-
proc_register_idle(ip_foreground, IDLE_BACKGROUND);
555+
proc_register_idle(ip_foreground, IDLE_FOREGROUND);
552556
}

src/video.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ static int64_t screen_x = 0, screen_y = 0, current_x = 0, current_y = 0, screen_
66
static console first_console;
77
bool wait_state = false;
88
bool video_flip_is_auto = true;
9+
bool video_dirty = true;
910
console* current_console = NULL;
1011

1112
extern volatile struct limine_module_request module_request;
@@ -65,6 +66,7 @@ void ft_write(struct flanterm_context *ctx, const char *buf, size_t count) {
6566
return;
6667
}
6768
flanterm_write(ctx, buf, count);
69+
video_dirty = true;
6870
}
6971

7072
void screenonly(console* c, const char* s)
@@ -86,12 +88,14 @@ void gotoxy(uint64_t x, uint64_t y)
8688
char cursor_command[32];
8789
snprintf(cursor_command, 32, "\033[%d;%dH", y % (get_text_height() + 1), x % (get_text_width() + 1));
8890
screenonly(current_console, cursor_command);
91+
video_dirty = true;
8992
}
9093

9194
void putpixel(int64_t x, int64_t y, uint32_t rgb)
9295
{
9396
volatile uint32_t* addr = (volatile uint32_t*)(framebuffer_address() + pixel_address(x, y));
9497
*addr = rgb;
98+
video_dirty = true;
9599
}
96100

97101
uint32_t getpixel(int64_t x, int64_t y)
@@ -102,8 +106,9 @@ uint32_t getpixel(int64_t x, int64_t y)
102106
/* Clear the screen - note this does not send the ansi to the debug console */
103107
void clearscreen(console* c)
104108
{
105-
draw_horizontal_rectangle(0, 0, screen_get_width() - 1, screen_get_height() - 1, 0x000000);
109+
memset(rr_fb_front, 0, rr_fb_bytes);
106110
screenonly(c, "\033[2J\033[0;0H");
111+
video_dirty = true;
107112
}
108113

109114
void dput(const char n)
@@ -329,5 +334,8 @@ void set_video_auto_flip(bool flip) {
329334
}
330335

331336
void rr_flip(void) {
332-
memcpy(rr_fb_front, rr_fb_back, rr_fb_bytes);
337+
if (video_dirty) {
338+
memcpy(rr_fb_front, rr_fb_back, rr_fb_bytes);
339+
video_dirty = false;
340+
}
333341
}

0 commit comments

Comments
 (0)