refactor(video/sdl): dedupe scale computation and use calloc for framebuffer
This commit is contained in:
@@ -82,7 +82,7 @@ uint8_t skele_video_init(skele_video_config_t cfg)
|
|||||||
SDL_DisplayID display;
|
SDL_DisplayID display;
|
||||||
SDL_WindowFlags flags = 0;
|
SDL_WindowFlags flags = 0;
|
||||||
const SDL_DisplayMode *mode;
|
const SDL_DisplayMode *mode;
|
||||||
uint16_t window_w, window_h, aw, ah;
|
uint16_t window_w, window_h;
|
||||||
|
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
|
||||||
stk_log(STK_LOG_ERROR, "video: SDL_Init failed: %s",
|
stk_log(STK_LOG_ERROR, "video: SDL_Init failed: %s",
|
||||||
@@ -125,24 +125,17 @@ uint8_t skele_video_init(skele_video_config_t cfg)
|
|||||||
return SKELE_INIT_FAILURE;
|
return SKELE_INIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
aw = (uint16_t)((mode->w * 3) / 4);
|
cur_scale = max_scale(vid_w, vid_h);
|
||||||
ah = (uint16_t)((mode->h * 3) / 4);
|
|
||||||
cur_scale = 1;
|
|
||||||
while ((vid_w * (cur_scale + 1)) <= aw &&
|
|
||||||
(vid_h * (cur_scale + 1)) <= ah)
|
|
||||||
cur_scale++;
|
|
||||||
|
|
||||||
window_w = vid_w * cur_scale;
|
window_w = vid_w * cur_scale;
|
||||||
window_h = vid_h * cur_scale;
|
window_h = vid_h * cur_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
rgba_buf = malloc(vid_total * sizeof(uint32_t));
|
rgba_buf = calloc(vid_total, sizeof(uint32_t));
|
||||||
if (!rgba_buf) {
|
if (!rgba_buf) {
|
||||||
stk_log(STK_LOG_ERROR, "video: out of memory");
|
stk_log(STK_LOG_ERROR, "video: out of memory");
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return SKELE_INIT_FAILURE;
|
return SKELE_INIT_FAILURE;
|
||||||
}
|
}
|
||||||
memset(rgba_buf, 0, vid_total * sizeof(uint32_t));
|
|
||||||
|
|
||||||
window = SDL_CreateWindow("skele", window_w, window_h,
|
window = SDL_CreateWindow("skele", window_w, window_h,
|
||||||
flags | SDL_WINDOW_HIDDEN);
|
flags | SDL_WINDOW_HIDDEN);
|
||||||
|
|||||||
Reference in New Issue
Block a user