GDI: use custom BITMAPINFO struct to avoid malloc

This commit is contained in:
driver1998 2020-09-07 12:36:43 +08:00
parent 8d82c7b08f
commit 9cf71619d3

View File

@ -43,6 +43,15 @@
static HDC win32_gdi_hdc;
static void *dinput_gdi;
struct bitmap_info {
BITMAPINFOHEADER header;
union {
RGBQUAD colors;
DWORD masks[3];
} u;
};
static void gfx_ctx_gdi_update_title(void)
{
char title[128];
@ -301,7 +310,7 @@ static bool gdi_gfx_frame(void *data, const void *frame,
unsigned frame_width, unsigned frame_height, uint64_t frame_count,
unsigned pitch, const char *msg, video_frame_info_t *video_info)
{
BITMAPINFO* info = NULL;
struct bitmap_info info;
unsigned mode_width = 0;
unsigned mode_height = 0;
const void *frame_to_copy = frame;
@ -410,25 +419,22 @@ static bool gdi_gfx_frame(void *data, const void *frame,
gdi->screen_width = mode_width;
gdi->screen_height = mode_height;
info = malloc(sizeof(BITMAPINFO) + 3 * sizeof(DWORD));
if (!info) return false;
info.u.colors.rgbBlue = 0;
info.u.colors.rgbGreen = 0;
info.u.colors.rgbRed = 0;
info.u.colors.rgbReserved = 0;
info->bmiColors[0].rgbBlue = 0;
info->bmiColors[0].rgbGreen = 0;
info->bmiColors[0].rgbRed = 0;
info->bmiColors[0].rgbReserved = 0;
info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info->bmiHeader.biWidth = pitch / (bits / 8);
info->bmiHeader.biHeight = -height;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biBitCount = bits;
info->bmiHeader.biCompression = 0;
info->bmiHeader.biSizeImage = 0;
info->bmiHeader.biXPelsPerMeter= 0;
info->bmiHeader.biYPelsPerMeter= 0;
info->bmiHeader.biClrUsed = 0;
info->bmiHeader.biClrImportant = 0;
info.header.biSize = sizeof(BITMAPINFOHEADER);
info.header.biWidth = pitch / (bits / 8);
info.header.biHeight = -height;
info.header.biPlanes = 1;
info.header.biBitCount = bits;
info.header.biCompression = 0;
info.header.biSizeImage = 0;
info.header.biXPelsPerMeter= 0;
info.header.biYPelsPerMeter= 0;
info.header.biClrUsed = 0;
info.header.biClrImportant = 0;
if (bits == 16)
{
@ -448,39 +454,36 @@ static bool gdi_gfx_frame(void *data, const void *frame,
}
frame_to_copy = gdi->temp_buf;
info->bmiHeader.biCompression = BI_RGB;
info.header.biCompression = BI_RGB;
}
else
{
DWORD* masks = (DWORD*)info->bmiColors;
info->bmiHeader.biCompression = BI_BITFIELDS;
info.header.biCompression = BI_BITFIELDS;
/* default 16-bit format on Windows is XRGB1555 */
if (frame_to_copy == gdi->menu_frame)
{
/* map RGB444 color bits for RGUI */
masks[0] = 0xF000;
masks[1] = 0x0F00;
masks[2] = 0x00F0;
info.u.masks[0] = 0xF000;
info.u.masks[1] = 0x0F00;
info.u.masks[2] = 0x00F0;
}
else
{
/* map RGB565 color bits for core */
masks[0] = 0xF800;
masks[1] = 0x07E0;
masks[2] = 0x001F;
info.u.masks[0] = 0xF800;
info.u.masks[1] = 0x07E0;
info.u.masks[2] = 0x001F;
}
}
}
else
info->bmiHeader.biCompression = BI_RGB;
info.header.biCompression = BI_RGB;
if (draw)
StretchDIBits(gdi->memDC, 0, 0, width, height, 0, 0, width, height,
frame_to_copy, info, DIB_RGB_COLORS, SRCCOPY);
frame_to_copy, (BITMAPINFO*)&info, DIB_RGB_COLORS, SRCCOPY);
free(info);
SelectObject(gdi->memDC, gdi->bmp_old);
if (msg)