mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-30 11:40:32 +00:00
(SDL) Clean sdl_gfx.c up a bit
This commit is contained in:
parent
314389e4f7
commit
260abc0861
@ -53,8 +53,6 @@ typedef struct sdl_video
|
||||
uint8_t font_b;
|
||||
|
||||
struct scaler_ctx scaler;
|
||||
unsigned last_width;
|
||||
unsigned last_height;
|
||||
|
||||
sdl_menu_frame_t menu;
|
||||
} sdl_video_t;
|
||||
@ -78,6 +76,30 @@ static void sdl_gfx_free(void *data)
|
||||
free(vid);
|
||||
}
|
||||
|
||||
static void sdl_update_scaler(SDL_Surface *surf, struct scaler_ctx *scaler,
|
||||
enum scaler_pix_fmt format, unsigned width,
|
||||
unsigned height, unsigned pitch)
|
||||
{
|
||||
if (
|
||||
width != scaler->in_width
|
||||
|| height != scaler->in_height
|
||||
|| format != scaler->in_fmt
|
||||
|| pitch != scaler->in_stride
|
||||
)
|
||||
{
|
||||
scaler->in_fmt = format;
|
||||
scaler->in_width = width;
|
||||
scaler->in_height = height;
|
||||
scaler->in_stride = pitch;
|
||||
|
||||
scaler->out_width = surf->w;
|
||||
scaler->out_height = surf->h;
|
||||
scaler->out_stride = surf->pitch;
|
||||
|
||||
scaler_ctx_gen_filter(scaler);
|
||||
}
|
||||
}
|
||||
|
||||
static void sdl_init_font(sdl_video_t *vid, const char *font_path, unsigned font_size)
|
||||
{
|
||||
if (!g_settings.video.font_enable)
|
||||
@ -100,7 +122,7 @@ static void sdl_init_font(sdl_video_t *vid, const char *font_path, unsigned font
|
||||
vid->font_b = b;
|
||||
}
|
||||
else
|
||||
RARCH_LOG("Could not initialize fonts.\n");
|
||||
RARCH_LOG("[SDL]: Could not initialize fonts.\n");
|
||||
}
|
||||
|
||||
static void sdl_render_msg(sdl_video_t *vid, SDL_Surface *buffer,
|
||||
@ -220,8 +242,11 @@ static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
XInitThreads();
|
||||
#endif
|
||||
|
||||
if (SDL_WasInit(0) == 0 && SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
return NULL;
|
||||
if (SDL_WasInit(0) == 0)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
return NULL;
|
||||
}
|
||||
else if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
||||
return NULL;
|
||||
|
||||
@ -233,12 +258,10 @@ static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
rarch_assert(video_info);
|
||||
unsigned full_x = video_info->current_w;
|
||||
unsigned full_y = video_info->current_h;
|
||||
RARCH_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y);
|
||||
|
||||
void *sdl_input = NULL;
|
||||
RARCH_LOG("[SDL]: Detecting desktop resolution %ux%u.\n", full_x, full_y);
|
||||
|
||||
if (!video->fullscreen)
|
||||
RARCH_LOG("Creating window @ %ux%u\n", video->width, video->height);
|
||||
RARCH_LOG("[SDL]: Creating window @ %ux%u\n", video->width, video->height);
|
||||
|
||||
vid->screen = SDL_SetVideoMode(video->width, video->height, 32,
|
||||
SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | (video->fullscreen ? SDL_FULLSCREEN : 0));
|
||||
@ -248,7 +271,7 @@ static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
|
||||
if (!vid->screen)
|
||||
{
|
||||
RARCH_ERR("Failed to init SDL surface: %s\n", SDL_GetError());
|
||||
RARCH_ERR("[SDL]: Failed to init SDL surface: %s\n", SDL_GetError());
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -259,7 +282,7 @@ static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
|
||||
if (input && input_data)
|
||||
{
|
||||
sdl_input = input_sdl.init();
|
||||
void *sdl_input = input_sdl.init();
|
||||
if (sdl_input)
|
||||
{
|
||||
*input = &input_sdl;
|
||||
@ -285,7 +308,7 @@ static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
|
||||
if (!vid->menu.frame)
|
||||
{
|
||||
RARCH_ERR("Failed to init menu surface: %s\n", SDL_GetError());
|
||||
RARCH_ERR("[SDL]: Failed to init menu surface: %s\n", SDL_GetError());
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -311,28 +334,15 @@ static void check_window(sdl_video_t *vid)
|
||||
}
|
||||
}
|
||||
|
||||
static bool sdl_gfx_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
|
||||
static bool sdl_gfx_frame(void *data, const void *frame, unsigned width,
|
||||
unsigned height, unsigned pitch, const char *msg)
|
||||
{
|
||||
if (!frame)
|
||||
return true;
|
||||
|
||||
sdl_video_t *vid = (sdl_video_t*)data;
|
||||
|
||||
vid->scaler.in_stride = pitch;
|
||||
if (width != vid->last_width || height != vid->last_height)
|
||||
{
|
||||
vid->scaler.in_width = width;
|
||||
vid->scaler.in_height = height;
|
||||
|
||||
vid->scaler.out_width = vid->screen->w;
|
||||
vid->scaler.out_height = vid->screen->h;
|
||||
vid->scaler.out_stride = vid->screen->pitch;
|
||||
|
||||
scaler_ctx_gen_filter(&vid->scaler);
|
||||
|
||||
vid->last_width = width;
|
||||
vid->last_height = height;
|
||||
}
|
||||
sdl_update_scaler(vid->screen, &vid->scaler, vid->scaler.in_fmt, width, height, pitch);
|
||||
|
||||
if (SDL_MUSTLOCK(vid->screen))
|
||||
SDL_LockSurface(vid->screen);
|
||||
@ -401,7 +411,8 @@ static void sdl_set_aspect_ratio(void *data, unsigned aspectratio_index)
|
||||
switch (aspectratio_index)
|
||||
{
|
||||
case ASPECT_RATIO_SQUARE:
|
||||
gfx_set_square_pixel_viewport(g_extern.system.av_info.geometry.base_width, g_extern.system.av_info.geometry.base_height);
|
||||
gfx_set_square_pixel_viewport(g_extern.system.av_info.geometry.base_width,
|
||||
g_extern.system.av_info.geometry.base_height);
|
||||
break;
|
||||
|
||||
case ASPECT_RATIO_CORE:
|
||||
@ -432,24 +443,8 @@ static void sdl_set_texture_frame(void *data, const void *frame, bool rgb32,
|
||||
|
||||
enum scaler_pix_fmt format = rgb32 ? SCALER_FMT_ARGB8888 : SCALER_FMT_RGBA4444;
|
||||
|
||||
vid->menu.scaler.in_stride = width * (rgb32 ? sizeof(uint32_t) : sizeof(uint16_t));
|
||||
|
||||
if (
|
||||
width != vid->menu.scaler.in_width
|
||||
|| height != vid->menu.scaler.in_height
|
||||
|| format != vid->menu.scaler.in_fmt
|
||||
)
|
||||
{
|
||||
vid->menu.scaler.in_fmt = format;
|
||||
vid->menu.scaler.in_width = width;
|
||||
vid->menu.scaler.in_height = height;
|
||||
|
||||
vid->menu.scaler.out_width = vid->screen->w;
|
||||
vid->menu.scaler.out_height = vid->screen->h;
|
||||
vid->menu.scaler.out_stride = vid->screen->pitch;
|
||||
|
||||
scaler_ctx_gen_filter(&vid->menu.scaler);
|
||||
}
|
||||
sdl_update_scaler(vid->menu.frame, &vid->menu.scaler, format, width, height,
|
||||
width * (rgb32 ? sizeof(uint32_t) : sizeof(uint16_t)));
|
||||
|
||||
scaler_ctx_scale(&vid->menu.scaler, vid->menu.frame->pixels, frame);
|
||||
SDL_SetAlpha(vid->menu.frame, SDL_SRCALPHA, 255.0 * alpha);
|
||||
|
Loading…
Reference in New Issue
Block a user