diff --git a/gfx/common/gdi_common.h b/gfx/common/gdi_common.h index 456fe4d7a7..91e745ed47 100644 --- a/gfx/common/gdi_common.h +++ b/gfx/common/gdi_common.h @@ -36,6 +36,19 @@ typedef struct gdi unsigned screen_height; void *ctx_data; const gfx_ctx_driver_t *ctx_driver; + + unsigned menu_width; + unsigned menu_height; + unsigned menu_pitch; + unsigned video_pitch; + unsigned video_bits; + unsigned menu_bits; + bool rgb32; + bool menu_rgb32; + int win_major; + int win_minor; + bool lte_win98; + unsigned short *temp_buf; } gdi_t; typedef struct gdi_texture diff --git a/gfx/drivers/gdi_gfx.c b/gfx/drivers/gdi_gfx.c index f4c53f87a4..f2722b380b 100644 --- a/gfx/drivers/gdi_gfx.c +++ b/gfx/drivers/gdi_gfx.c @@ -40,20 +40,8 @@ #endif static unsigned char *gdi_menu_frame = NULL; -static unsigned gdi_menu_width = 0; -static unsigned gdi_menu_height = 0; -static unsigned gdi_menu_pitch = 0; -static unsigned gdi_video_pitch = 0; -static unsigned gdi_video_bits = 0; -static unsigned gdi_menu_bits = 0; -static bool gdi_rgb32 = false; -static bool gdi_menu_rgb32 = false; -static int gdi_win_major = 0; -static int gdi_win_minor = 0; -static bool gdi_lte_win98 = false; -static unsigned short *gdi_temp_buf = NULL; -static void gdi_gfx_create(void) +static void gdi_gfx_create(gdi_t *gdi) { char os[64] = {0}; @@ -65,13 +53,13 @@ static void gdi_gfx_create(void) return; } - ctx->get_os(os, sizeof(os), &gdi_win_major, &gdi_win_minor); + ctx->get_os(os, sizeof(os), &gdi->win_major, &gdi->win_minor); /* Are we running on Windows 98 or below? */ - if (gdi_win_major < 4 || (gdi_win_major == 4 && gdi_win_minor <= 10)) + if (gdi->win_major < 4 || (gdi->win_major == 4 && gdi->win_minor <= 10)) { RARCH_LOG("[GDI] Win98 or lower detected, using slow frame conversion method for RGB444.\n"); - gdi_lte_win98 = true; + gdi->lte_win98 = true; } } @@ -97,16 +85,16 @@ static void *gdi_gfx_init(const video_info_t *video, gdi->video_width = video->width; gdi->video_height = video->height; - gdi_rgb32 = video->rgb32; + gdi->rgb32 = video->rgb32; - gdi_video_bits = video->rgb32 ? 32 : 16; + gdi->video_bits = video->rgb32 ? 32 : 16; if (video->rgb32) - gdi_video_pitch = video->width * 4; + gdi->video_pitch = video->width * 4; else - gdi_video_pitch = video->width * 2; + gdi->video_pitch = video->width * 2; - gdi_gfx_create(); + gdi_gfx_create(gdi); ctx_driver = video_context_driver_init_first(gdi, settings->arrays.video_context_driver, @@ -199,9 +187,9 @@ static bool gdi_gfx_frame(void *data, const void *frame, const void *frame_to_copy = frame; unsigned width = 0; unsigned height = 0; - unsigned bits = gdi_video_bits; bool draw = true; gdi_t *gdi = (gdi_t*)data; + unsigned bits = gdi->video_bits; HWND hwnd = win32_get_window(); /* FIXME: Force these settings off as they interfere with the rendering */ @@ -217,29 +205,29 @@ static bool gdi_gfx_frame(void *data, const void *frame, if ( gdi->video_width != frame_width || gdi->video_height != frame_height || - gdi_video_pitch != pitch) + gdi->video_pitch != pitch) { if (frame_width > 4 && frame_height > 4) { gdi->video_width = frame_width; gdi->video_height = frame_height; - gdi_video_pitch = pitch; + gdi->video_pitch = pitch; } } if (gdi_menu_frame && video_info->menu_is_alive) { frame_to_copy = gdi_menu_frame; - width = gdi_menu_width; - height = gdi_menu_height; - pitch = gdi_menu_pitch; - bits = gdi_menu_bits; + width = gdi->menu_width; + height = gdi->menu_height; + pitch = gdi->menu_pitch; + bits = gdi->menu_bits; } else { width = gdi->video_width; height = gdi->video_height; - pitch = gdi_video_pitch; + pitch = gdi->video_pitch; if ( frame_width == 4 && frame_height == 4 && @@ -274,18 +262,18 @@ static bool gdi_gfx_frame(void *data, const void *frame, gdi->winDC, gdi->video_width, gdi->video_height); gdi->bmp_old = (HBITMAP)SelectObject(gdi->memDC, gdi->bmp); - if (gdi_lte_win98) + if (gdi->lte_win98) { unsigned short *tmp = NULL; - if (gdi_temp_buf) - free(gdi_temp_buf); + if (gdi->temp_buf) + free(gdi->temp_buf); tmp = (unsigned short*)malloc(width * height * sizeof(unsigned short)); if (tmp) - gdi_temp_buf = tmp; + gdi->temp_buf = tmp; } } @@ -306,7 +294,7 @@ static bool gdi_gfx_frame(void *data, const void *frame, if (bits == 16) { - if (gdi_lte_win98 && gdi_temp_buf) + if (gdi->lte_win98 && gdi->temp_buf) { /* Win98 and below cannot use BI_BITFIELDS with RGB444, * so convert it to RGB555 first. */ @@ -317,11 +305,11 @@ static bool gdi_gfx_frame(void *data, const void *frame, for (x = 0; x < width; x++) { unsigned short pixel = ((unsigned short*)frame_to_copy)[width * y + x]; - gdi_temp_buf[width * y + x] = (pixel & 0xF000) >> 1 | (pixel & 0x0F00) >> 2 | (pixel & 0x00F0) >> 3; + gdi->temp_buf[width * y + x] = (pixel & 0xF000) >> 1 | (pixel & 0x0F00) >> 2 | (pixel & 0x00F0) >> 3; } } - frame_to_copy = gdi_temp_buf; + frame_to_copy = gdi->temp_buf; info->bmiHeader.biCompression = BI_RGB; } else @@ -369,7 +357,9 @@ static bool gdi_gfx_frame(void *data, const void *frame, return true; } -static void gdi_gfx_set_nonblock_state(void *a, bool b, bool c, unsigned d) { } +static void gdi_gfx_set_nonblock_state(void *a, bool b, bool c, unsigned d) +{ +} static bool gdi_gfx_alive(void *data) { @@ -418,21 +408,17 @@ static void gdi_gfx_free(void *data) gdi_t *gdi = (gdi_t*)data; HWND hwnd = win32_get_window(); - if (gdi_menu_frame) - { - free(gdi_menu_frame); - gdi_menu_frame = NULL; - } - - if (gdi_temp_buf) - { - free(gdi_temp_buf); - gdi_temp_buf = NULL; - } - if (!gdi) return; + if (gdi_menu_frame) + free(gdi_menu_frame); + gdi_menu_frame = NULL; + + if (gdi->temp_buf) + free(gdi->temp_buf); + gdi->temp_buf = NULL; + if (gdi->bmp) DeleteObject(gdi->bmp); @@ -472,21 +458,20 @@ static void gdi_set_texture_frame(void *data, const void *frame, bool rgb32, unsigned width, unsigned height, float alpha) { + gdi_t *gdi = (gdi_t*)data; unsigned pitch = width * 2; if (rgb32) pitch = width * 4; if (gdi_menu_frame) - { free(gdi_menu_frame); - gdi_menu_frame = NULL; - } + gdi_menu_frame = NULL; if ( !gdi_menu_frame || - gdi_menu_width != width || - gdi_menu_height != height || - gdi_menu_pitch != pitch) + gdi->menu_width != width || + gdi->menu_height != height || + gdi->menu_pitch != pitch) { if (pitch && height) { @@ -500,10 +485,10 @@ static void gdi_set_texture_frame(void *data, if (gdi_menu_frame && frame && pitch && height) { memcpy(gdi_menu_frame, frame, pitch * height); - gdi_menu_width = width; - gdi_menu_height = height; - gdi_menu_pitch = pitch; - gdi_menu_bits = rgb32 ? 32 : 16; + gdi->menu_width = width; + gdi->menu_height = height; + gdi->menu_pitch = pitch; + gdi->menu_bits = rgb32 ? 32 : 16; } }