(GDI) Get rid of memory allocation per frame

This commit is contained in:
twinaphex 2020-07-09 09:34:06 +02:00
parent f56b6a3a0f
commit 35762e07cb
1 changed files with 23 additions and 18 deletions

View File

@ -297,7 +297,7 @@ static bool gdi_gfx_frame(void *data, const void *frame,
unsigned frame_width, unsigned frame_height, uint64_t frame_count, unsigned frame_width, unsigned frame_height, uint64_t frame_count,
unsigned pitch, const char *msg, video_frame_info_t *video_info) unsigned pitch, const char *msg, video_frame_info_t *video_info)
{ {
BITMAPINFO *info; BITMAPINFO info;
unsigned mode_width = 0; unsigned mode_width = 0;
unsigned mode_height = 0; unsigned mode_height = 0;
const void *frame_to_copy = frame; const void *frame_to_copy = frame;
@ -396,18 +396,25 @@ static bool gdi_gfx_frame(void *data, const void *frame,
gfx_ctx_gdi_get_video_size(&mode_width, &mode_height); gfx_ctx_gdi_get_video_size(&mode_width, &mode_height);
gdi->screen_width = mode_width; gdi->screen_width = mode_width;
gdi->screen_height = mode_height; gdi->screen_height = mode_height;
info = (BITMAPINFO*) info.bmiColors[0].rgbBlue = 0;
calloc(1, sizeof(*info) + (3 * sizeof(RGBQUAD))); info.bmiColors[0].rgbGreen = 0;
info.bmiColors[0].rgbRed = 0;
info.bmiColors[0].rgbReserved = 0;
info->bmiHeader.biBitCount = bits; info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info->bmiHeader.biWidth = pitch / (bits / 8); info.bmiHeader.biWidth = pitch / (bits / 8);
info->bmiHeader.biHeight = -height; info.bmiHeader.biHeight = -height;
info->bmiHeader.biPlanes = 1; info.bmiHeader.biPlanes = 1;
info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); info.bmiHeader.biBitCount = bits;
info->bmiHeader.biSizeImage = 0; info.bmiHeader.biCompression = 0;
info.bmiHeader.biSizeImage = 0;
info.bmiHeader.biXPelsPerMeter= 0;
info.bmiHeader.biYPelsPerMeter= 0;
info.bmiHeader.biClrUsed = 0;
info.bmiHeader.biClrImportant = 0;
if (bits == 16) if (bits == 16)
{ {
@ -427,13 +434,13 @@ static bool gdi_gfx_frame(void *data, const void *frame,
} }
frame_to_copy = gdi->temp_buf; frame_to_copy = gdi->temp_buf;
info->bmiHeader.biCompression = BI_RGB; info.bmiHeader.biCompression = BI_RGB;
} }
else else
{ {
unsigned *masks = (unsigned*)info->bmiColors; unsigned *masks = (unsigned*)info.bmiColors;
info->bmiHeader.biCompression = BI_BITFIELDS; info.bmiHeader.biCompression = BI_BITFIELDS;
/* default 16-bit format on Windows is XRGB1555 */ /* default 16-bit format on Windows is XRGB1555 */
if (frame_to_copy == gdi->menu_frame) if (frame_to_copy == gdi->menu_frame)
@ -453,16 +460,14 @@ static bool gdi_gfx_frame(void *data, const void *frame,
} }
} }
else else
info->bmiHeader.biCompression = BI_RGB; info.bmiHeader.biCompression = BI_RGB;
if (draw) if (draw)
StretchDIBits(gdi->memDC, 0, 0, width, height, 0, 0, width, height, StretchDIBits(gdi->memDC, 0, 0, width, height, 0, 0, width, height,
frame_to_copy, info, DIB_RGB_COLORS, SRCCOPY); frame_to_copy, &info, DIB_RGB_COLORS, SRCCOPY);
SelectObject(gdi->memDC, gdi->bmp_old); SelectObject(gdi->memDC, gdi->bmp_old);
free(info);
if (msg) if (msg)
font_driver_render_msg(gdi, msg, NULL, NULL); font_driver_render_msg(gdi, msg, NULL, NULL);