Check that the framebuffer image matches expectations

This commit is contained in:
John Lorentzson 2025-04-09 15:11:18 +02:00
parent d562f588cf
commit 4003931ed9

View file

@ -31,6 +31,14 @@ static bool CheckShm() {
return exists;
}
bool checkImageOK(XImage* image) {
bool ok = true;
ok &= (image->width == screenWidth);
ok &= (image->bytes_per_line == screenWidth * 4);
ok &= (image->depth == 24 || image->depth == 32);
return ok;
}
void createFramebuffer() {
gc = DefaultGC(xDisplay, DefaultScreen(xDisplay));
@ -83,10 +91,15 @@ bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen
XSetWMProtocols(xDisplay, window, &WM_DELETE_WINDOW, 1);
createFramebuffer();
if(checkImageOK(framebufferImage) == false) {
Backend_PrintError("Something's off with the framebuffer.\n");
return false;
}
if(framebufferImage == 0) {
return false;
}
framebufferPitch = screen_width * 4;
return true;
}