Double buffering causes system to freeze
Posted: Mon Jan 10, 2022 12:16 pm
Hey, I am currently working on implementing double buffering for my GOP driver. But after copying over the memory from the backbuffer to the framebuffer, it freezes.
Setting up the back buffer:
Drawing to the back buffer:
Copying from the back buffer to frame buffer:
memcpy function:
The drawing:
Not sure if I need to post any more information but I can if that's needed
Setting up the back buffer:
Code: Select all
BackBuffer = malloc(framebuffer->Width * framebuffer->Height * 4);
Code: Select all
void Graphics::draw_pixel(int x, int y, int color)
{
*(unsigned int*)((unsigned int*)BackBuffer + x + (y * buffer->PixelsPerScanLine)) = color;
}
void Graphics::draw_rect(int x, int y, int w, int h, int color)
{
for (int Y = y; Y < y + h; Y++)
{
for (int X = x; X < x + w; X++)
{
draw_pixel(X, Y, color);
}
}
}
Code: Select all
memcpy((uint64_t*)buffer->BaseAddress, (uint64_t*)BackBuffer, buffer->Width * buffer->Height * 4);
Code: Select all
void* memcpy(uint64_t* dest, uint64_t* source, int count)
{
for (int i = 0; i < count; i++)
{
dest[i] = source[i];
}
return dest;
}
Code: Select all
g.draw_rect(0, 0, 50, 50, 0xFFFFFF);
g.update(); // Draws white square successfully but then freezes the system
// This doesn't draw!
g.draw_rect(0, 0, 50, 50, 0xFF0000);
g.update();