Refactor menu_texture.c - uncouple it from file I/O
This commit is contained in:
parent
cb53153fa1
commit
4b0c2cd7de
|
@ -514,6 +514,7 @@ static void glui_context_destroy(void)
|
||||||
|
|
||||||
static bool glui_load_wallpaper(const char *path)
|
static bool glui_load_wallpaper(const char *path)
|
||||||
{
|
{
|
||||||
|
struct texture_image ti = {0};
|
||||||
glui_handle_t *glui = NULL;
|
glui_handle_t *glui = NULL;
|
||||||
menu_handle_t *menu = menu_driver_resolve();
|
menu_handle_t *menu = menu_driver_resolve();
|
||||||
|
|
||||||
|
@ -530,11 +531,18 @@ static bool glui_load_wallpaper(const char *path)
|
||||||
if (glui->textures.bg.id)
|
if (glui->textures.bg.id)
|
||||||
glDeleteTextures(1, &glui->textures.bg.id);
|
glDeleteTextures(1, &glui->textures.bg.id);
|
||||||
|
|
||||||
|
if (! path_file_exists(path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
texture_image_load(&ti, path);
|
||||||
|
|
||||||
strlcpy(glui->textures.bg.path, path, sizeof(glui->textures.bg.path));
|
strlcpy(glui->textures.bg.path, path, sizeof(glui->textures.bg.path));
|
||||||
|
|
||||||
glui->textures.bg.id = menu_texture_load(glui->textures.bg.path,
|
glui->textures.bg.id = menu_texture_load(&ti,
|
||||||
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
|
|
||||||
|
texture_image_free(&ti);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1393,6 +1393,7 @@ static bool xmb_font_init_first(const gl_font_renderer_t **font_driver,
|
||||||
|
|
||||||
static bool xmb_load_wallpaper(const char *path)
|
static bool xmb_load_wallpaper(const char *path)
|
||||||
{
|
{
|
||||||
|
struct texture_image ti = {0};
|
||||||
xmb_handle_t *xmb = NULL;
|
xmb_handle_t *xmb = NULL;
|
||||||
menu_handle_t *menu = menu_driver_resolve();
|
menu_handle_t *menu = menu_driver_resolve();
|
||||||
|
|
||||||
|
@ -1409,11 +1410,18 @@ static bool xmb_load_wallpaper(const char *path)
|
||||||
if (xmb->textures.bg.id)
|
if (xmb->textures.bg.id)
|
||||||
glDeleteTextures(1, &xmb->textures.bg.id);
|
glDeleteTextures(1, &xmb->textures.bg.id);
|
||||||
|
|
||||||
|
if (! path_file_exists(path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
texture_image_load(&ti, path);
|
||||||
|
|
||||||
strlcpy(xmb->textures.bg.path, path, sizeof(xmb->textures.bg.path));
|
strlcpy(xmb->textures.bg.path, path, sizeof(xmb->textures.bg.path));
|
||||||
|
|
||||||
xmb->textures.bg.id = menu_texture_load(xmb->textures.bg.path,
|
xmb->textures.bg.id = menu_texture_load(&ti,
|
||||||
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
|
|
||||||
|
texture_image_free(&ti);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1425,6 +1433,7 @@ static void xmb_context_reset(void)
|
||||||
fontpath[PATH_MAX_LENGTH], core_id[PATH_MAX_LENGTH], texturepath[PATH_MAX_LENGTH],
|
fontpath[PATH_MAX_LENGTH], core_id[PATH_MAX_LENGTH], texturepath[PATH_MAX_LENGTH],
|
||||||
content_texturepath[PATH_MAX_LENGTH];
|
content_texturepath[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
|
struct texture_image ti = {0};
|
||||||
core_info_t* info = NULL;
|
core_info_t* info = NULL;
|
||||||
core_info_list_t* info_list = NULL;
|
core_info_list_t* info_list = NULL;
|
||||||
gl_t *gl = NULL;
|
gl_t *gl = NULL;
|
||||||
|
@ -1514,9 +1523,19 @@ static void xmb_context_reset(void)
|
||||||
"clock.png", sizeof(xmb->textures.list[XMB_TEXTURE_CLOCK].path));
|
"clock.png", sizeof(xmb->textures.list[XMB_TEXTURE_CLOCK].path));
|
||||||
|
|
||||||
for (k = 0; k < XMB_TEXTURE_LAST; k++)
|
for (k = 0; k < XMB_TEXTURE_LAST; k++)
|
||||||
xmb->textures.list[k].id = menu_texture_load(xmb->textures.list[k].path,
|
{
|
||||||
|
const char *path = xmb->textures.list[k].path;
|
||||||
|
if (! path_file_exists(path))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
texture_image_load(&ti, path);
|
||||||
|
|
||||||
|
xmb->textures.list[k].id = menu_texture_load(&ti,
|
||||||
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
|
|
||||||
|
texture_image_free(&ti);
|
||||||
|
}
|
||||||
|
|
||||||
xmb_load_wallpaper(xmb->textures.bg.path);
|
xmb_load_wallpaper(xmb->textures.bg.path);
|
||||||
|
|
||||||
xmb->settings_node.icon = xmb->textures.list[XMB_TEXTURE_SETTINGS].id;
|
xmb->settings_node.icon = xmb->textures.list[XMB_TEXTURE_SETTINGS].id;
|
||||||
|
@ -1530,6 +1549,7 @@ static void xmb_context_reset(void)
|
||||||
|
|
||||||
for (i = 1; i < menu->categories.size; i++)
|
for (i = 1; i < menu->categories.size; i++)
|
||||||
{
|
{
|
||||||
|
struct texture_image ti = {0};
|
||||||
node = xmb_get_userdata_from_core(xmb, i - 1);
|
node = xmb_get_userdata_from_core(xmb, i - 1);
|
||||||
|
|
||||||
fill_pathname_join(mediapath, g_settings.assets_directory,
|
fill_pathname_join(mediapath, g_settings.assets_directory,
|
||||||
|
@ -1562,11 +1582,20 @@ static void xmb_context_reset(void)
|
||||||
|
|
||||||
node->alpha = 0;
|
node->alpha = 0;
|
||||||
node->zoom = xmb->categories.passive.zoom;
|
node->zoom = xmb->categories.passive.zoom;
|
||||||
node->icon = menu_texture_load(texturepath,
|
|
||||||
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
texture_image_load(&ti, texturepath);
|
||||||
node->content_icon = menu_texture_load(content_texturepath,
|
|
||||||
|
node->icon = menu_texture_load(&ti,
|
||||||
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
|
|
||||||
|
texture_image_free(&ti);
|
||||||
|
|
||||||
|
texture_image_load(&ti, content_texturepath);
|
||||||
|
|
||||||
|
node->content_icon = menu_texture_load(&ti,
|
||||||
|
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
|
|
||||||
|
texture_image_free(&ti);
|
||||||
|
|
||||||
if (i == xmb->categories.active.idx)
|
if (i == xmb->categories.active.idx)
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,22 +38,20 @@ static void menu_texture_png_load_gl(struct texture_image *ti,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static unsigned menu_texture_png_load(const char *path,
|
static unsigned menu_texture_png_load(void *data,
|
||||||
enum texture_backend_type type,
|
enum texture_backend_type type,
|
||||||
enum texture_filter_type filter_type)
|
enum texture_filter_type filter_type)
|
||||||
{
|
{
|
||||||
unsigned id = 0;
|
unsigned id = 0;
|
||||||
struct texture_image ti = {0};
|
|
||||||
if (! path_file_exists(path))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
texture_image_load(&ti, path);
|
if (!data)
|
||||||
|
return 0;
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case TEXTURE_BACKEND_OPENGL:
|
case TEXTURE_BACKEND_OPENGL:
|
||||||
#ifdef HAVE_OPENGL
|
#ifdef HAVE_OPENGL
|
||||||
menu_texture_png_load_gl(&ti, filter_type, &id);
|
menu_texture_png_load_gl((struct texture_image*)data, filter_type, &id);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case TEXTURE_BACKEND_DEFAULT:
|
case TEXTURE_BACKEND_DEFAULT:
|
||||||
|
@ -61,39 +59,28 @@ static unsigned menu_texture_png_load(const char *path,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ti.pixels);
|
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int menu_texture_png_load_wrap(void *data)
|
static int menu_texture_png_load_wrap(void *data)
|
||||||
{
|
{
|
||||||
const char *filename = (const char*)data;
|
return menu_texture_png_load(data, TEXTURE_BACKEND_DEFAULT,
|
||||||
if (!filename)
|
|
||||||
return 0;
|
|
||||||
return menu_texture_png_load(filename, TEXTURE_BACKEND_DEFAULT,
|
|
||||||
TEXTURE_FILTER_LINEAR);
|
TEXTURE_FILTER_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int menu_texture_png_load_wrap_gl_mipmap(void *data)
|
static int menu_texture_png_load_wrap_gl_mipmap(void *data)
|
||||||
{
|
{
|
||||||
const char *filename = (const char*)data;
|
return menu_texture_png_load(data, TEXTURE_BACKEND_OPENGL,
|
||||||
if (!filename)
|
|
||||||
return 0;
|
|
||||||
return menu_texture_png_load(filename, TEXTURE_BACKEND_OPENGL,
|
|
||||||
TEXTURE_FILTER_MIPMAP_LINEAR);
|
TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int menu_texture_png_load_wrap_gl(void *data)
|
static int menu_texture_png_load_wrap_gl(void *data)
|
||||||
{
|
{
|
||||||
const char *filename = (const char*)data;
|
return menu_texture_png_load(data, TEXTURE_BACKEND_OPENGL,
|
||||||
if (!filename)
|
|
||||||
return 0;
|
|
||||||
return menu_texture_png_load(filename, TEXTURE_BACKEND_OPENGL,
|
|
||||||
TEXTURE_FILTER_LINEAR);
|
TEXTURE_FILTER_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned menu_texture_load(const char *path,
|
unsigned menu_texture_load(void *data,
|
||||||
enum texture_backend_type type,
|
enum texture_backend_type type,
|
||||||
enum texture_filter_type filter_type)
|
enum texture_filter_type filter_type)
|
||||||
{
|
{
|
||||||
|
@ -120,7 +107,7 @@ unsigned menu_texture_load(const char *path,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
thr->cmd_data.custom_command.data = (void*)path;
|
thr->cmd_data.custom_command.data = (void*)data;
|
||||||
|
|
||||||
thr->send_cmd_func(thr, CMD_CUSTOM_COMMAND);
|
thr->send_cmd_func(thr, CMD_CUSTOM_COMMAND);
|
||||||
thr->wait_reply_func(thr, CMD_CUSTOM_COMMAND);
|
thr->wait_reply_func(thr, CMD_CUSTOM_COMMAND);
|
||||||
|
@ -128,5 +115,5 @@ unsigned menu_texture_load(const char *path,
|
||||||
return thr->cmd_data.custom_command.return_value;
|
return thr->cmd_data.custom_command.return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return menu_texture_png_load(path, type, filter_type);
|
return menu_texture_png_load(data, type, filter_type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ enum texture_backend_type
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned menu_texture_load(const char *path,
|
unsigned menu_texture_load(void *data,
|
||||||
enum texture_backend_type type,
|
enum texture_backend_type type,
|
||||||
enum texture_filter_type filter_type);
|
enum texture_filter_type filter_type);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue