Fix texture_image_load/free.

This commit is contained in:
Themaister 2014-06-17 17:44:48 +02:00
parent 1c92ea3c5a
commit 15c35d7e44
7 changed files with 19 additions and 45 deletions

View File

@ -465,7 +465,7 @@ static void rmenu_context_reset(void *data)
if (!menu) if (!menu)
return; return;
texture_image_load(driver.video_data, g_extern.menu_texture_path, menu_texture); texture_image_load(menu_texture, g_extern.menu_texture_path);
menu->width = menu_texture->width; menu->width = menu_texture->width;
menu->height = menu_texture->height; menu->height = menu_texture->height;
@ -485,7 +485,7 @@ static void *rmenu_init(void)
static void rmenu_context_destroy(void *data) static void rmenu_context_destroy(void *data)
{ {
texture_image_free(driver.video_data, menu_texture); texture_image_free(menu_texture);
} }
static void rmenu_free(void *data) static void rmenu_free(void *data)

View File

@ -38,22 +38,7 @@ struct texture_image
#endif #endif
}; };
typedef struct image_ctx_driver bool texture_image_load(struct texture_image *img, const char *path);
{ void texture_image_free(struct texture_image *img);
bool (*load)(void*, const char*, void *);
void (*free)(void *, void *);
// Human readable string.
const char *ident;
} image_ctx_driver_t;
#if 0
extern const image_ctx_driver_t image_ctx_xdk1;
extern const image_ctx_driver_t image_ctx_ps3;
extern const image_ctx_driver_t image_ctx_sdl;
extern const image_ctx_driver_t image_ctx_rpng;
#endif
bool texture_image_load(void *data, const char *path, void *img);
void texture_image_free(void *data, void *img);
#endif #endif

View File

@ -304,15 +304,12 @@ error:
return false; return false;
} }
bool texture_image_load(void *data, const char *path, void *image_data) bool texture_image_load(struct texture_image *out_img, const char *path)
{ {
(void)data;
struct texture_image *out_img = (struct texture_image*)image_data;
if (!out_img) if (!out_img)
return false; return false;
if(strstr(path, ".PNG") != NULL || strstr(path, ".png") != NULL) if (strstr(path, ".PNG") != NULL || strstr(path, ".png") != NULL)
{ {
if (!ps3_load_png(path, out_img)) if (!ps3_load_png(path, out_img))
return false; return false;
@ -326,9 +323,8 @@ bool texture_image_load(void *data, const char *path, void *image_data)
return true; return true;
} }
void texture_image_free(void *data, void *image_data) void texture_image_free(struct texture_image *img)
{ {
struct texture_image *img = (struct texture_image*)image_data;
if (!img) if (!img)
return; return;

View File

@ -199,19 +199,15 @@ static bool rpng_gx_convert_texture32(struct texture_image *image)
#endif #endif
void texture_image_free(void *data, void *image_data) void texture_image_free(struct texture_image *img)
{ {
struct texture_image *img = (struct texture_image*)image_data;
free(img->pixels); free(img->pixels);
memset(img, 0, sizeof(*img)); memset(img, 0, sizeof(*img));
} }
bool texture_image_load(void *data, const char *path, void *image_data) bool texture_image_load(struct texture_image *out_img, const char *path)
{ {
(void)data;
bool ret; bool ret;
struct texture_image *out_img = (struct texture_image*)image_data;
// This interface "leak" is very ugly. FIXME: Fix this properly ... // This interface "leak" is very ugly. FIXME: Fix this properly ...
if (driver.gfx_use_rgba) if (driver.gfx_use_rgba)
@ -224,7 +220,7 @@ bool texture_image_load(void *data, const char *path, void *image_data)
{ {
if (!rpng_gx_convert_texture32(out_img)) if (!rpng_gx_convert_texture32(out_img))
{ {
texture_image_free(data, out_img); texture_image_free(out_img);
ret = false; ret = false;
} }
} }

View File

@ -17,17 +17,16 @@
#include "image.h" #include "image.h"
#include "../../xdk/xdk_d3d.h" #include "../../xdk/xdk_d3d.h"
bool texture_image_load(void *data, const char *path, void *image_data) bool texture_image_load(struct texture_image *out_img, const char *path)
{ {
d3d_video_t *d3d = (d3d_video_t*)data; d3d_video_t *d3d = (d3d_video_t*)data;
struct texture_image *out_img = (struct texture_image*)image_data;
D3DXIMAGE_INFO m_imageInfo; D3DXIMAGE_INFO m_imageInfo;
out_img->pixels = NULL; out_img->pixels = NULL;
out_img->vertex_buf = NULL; out_img->vertex_buf = NULL;
if(FAILED(D3DXCreateTextureFromFileExA(d3d->dev, if (FAILED(D3DXCreateTextureFromFileExA(d3d->dev,
path, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, path, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, &m_imageInfo, NULL, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, &m_imageInfo, NULL,
&out_img->pixels))) &out_img->pixels)))
@ -50,10 +49,8 @@ bool texture_image_load(void *data, const char *path, void *image_data)
return true; return true;
} }
void texture_image_free(void *data, void *image_data) void texture_image_free(struct texture_image *img)
{ {
struct texture_image *img = (struct texture_image*)image_data;
if (!img) if (!img)
return; return;

View File

@ -64,7 +64,7 @@ bool gl_load_luts(const struct gfx_shader *generic_shader, GLuint *lut_textures)
RARCH_LOG("Loading texture image from: \"%s\" ...\n", RARCH_LOG("Loading texture image from: \"%s\" ...\n",
generic_shader->lut[i].path); generic_shader->lut[i].path);
if (!texture_image_load(driver.video_data, generic_shader->lut[i].path, &img)) if (!texture_image_load(&img, generic_shader->lut[i].path))
{ {
RARCH_ERR("Failed to load texture image from: \"%s\"\n", generic_shader->lut[i].path); RARCH_ERR("Failed to load texture image from: \"%s\"\n", generic_shader->lut[i].path);
return false; return false;
@ -74,7 +74,7 @@ bool gl_load_luts(const struct gfx_shader *generic_shader, GLuint *lut_textures)
gl_wrap_type_to_enum(generic_shader->lut[i].wrap), gl_wrap_type_to_enum(generic_shader->lut[i].wrap),
generic_shader->lut[i].filter != RARCH_FILTER_NEAREST, generic_shader->lut[i].filter != RARCH_FILTER_NEAREST,
generic_shader->lut[i].mipmap); generic_shader->lut[i].mipmap);
texture_image_free(driver.video_data, &img); texture_image_free(&img);
} }
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);

View File

@ -164,11 +164,11 @@ static void input_overlay_free_overlay(struct overlay *overlay)
size_t i; size_t i;
for (i = 0; i < overlay->size; i++) for (i = 0; i < overlay->size; i++)
texture_image_free(driver.video_data, &overlay->descs[i].image); texture_image_free(&overlay->descs[i].image);
free(overlay->load_images); free(overlay->load_images);
free(overlay->descs); free(overlay->descs);
texture_image_free(driver.video_data, &overlay->image); texture_image_free(&overlay->image);
} }
static void input_overlay_free_overlays(input_overlay_t *ol) static void input_overlay_free_overlays(input_overlay_t *ol)
@ -199,7 +199,7 @@ static bool input_overlay_load_desc(input_overlay_t *ol, config_file_t *conf, st
fill_pathname_resolve_relative(path, ol->overlay_path, image_path, sizeof(path)); fill_pathname_resolve_relative(path, ol->overlay_path, image_path, sizeof(path));
struct texture_image img = {0}; struct texture_image img = {0};
if (texture_image_load(driver.video_data, path, &img)) if (texture_image_load(&img, path))
desc->image = img; desc->image = img;
} }
@ -352,7 +352,7 @@ static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf,
fill_pathname_resolve_relative(overlay_resolved_path, config_path, fill_pathname_resolve_relative(overlay_resolved_path, config_path,
overlay_path, sizeof(overlay_resolved_path)); overlay_path, sizeof(overlay_resolved_path));
if (texture_image_load(driver.video_data, overlay_resolved_path, &img)) if (texture_image_load(&img, overlay_resolved_path))
overlay->image = img; overlay->image = img;
else else
{ {