Reputation: 328
I am currently booting my system into a 640x480x32b VESA mode with a linear frame buffer.
Using the following code, I flash red and green on the screen:
void clear(Color color) {
u8* cursor = frame_buffer;
int L = VIDEO_HEIGHT * VIDEO_WIDTH;
for (int i = 0; i < L; i++) {
*(cursor) = color.b;
*(cursor + 1) = color.g;
*(cursor + 2) = color.r;
cursor = cursor + 4;
}
}
void update_screen() {
int L = VIDEO_HEIGHT * VIDEO_WIDTH * 4;
for (int i = 0; i < L; i++) {
*(LFB + i) = *(frame_buffer + i);
}
}
Where LFB
is the linear frame buffer used for rendering and frame_buffer
is a secondary buffer.
void main() {
init_video();
while (1) {
clear((Color) {255, 0, 0});
update_screen();
clear((Color) {0, 255, 0});
update_screen();
}
}
This works very well in QEMU, updating the entire screen nigh-instantly. However, when ran on real hardware, it takes nearly half a second, i.e. at least 10x slower than QEMU (probably much more than 10x, although I don't have an accurate way to measure this).
Any reason for why update_screen
is so slow on the real hardware?
Upvotes: 2
Views: 66