diff --git a/gfx/video_driver.c b/gfx/video_driver.c index d93decb44d..bc17f61234 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -1503,6 +1503,7 @@ void video_driver_set_rgba(void) { video_driver_lock(); video_driver_use_rgba = true; + image_texture_set_rgba(); video_driver_unlock(); } @@ -1510,6 +1511,7 @@ void video_driver_unset_rgba(void) { video_driver_lock(); video_driver_use_rgba = false; + image_texture_unset_rgba(); video_driver_unlock(); } diff --git a/libretro-common/formats/image_texture.c b/libretro-common/formats/image_texture.c index a9eeef1cfb..72de97ed12 100644 --- a/libretro-common/formats/image_texture.c +++ b/libretro-common/formats/image_texture.c @@ -38,8 +38,19 @@ enum video_image_format IMAGE_FORMAT_BMP }; +static bool image_texture_supports_rgba = false; + +void image_texture_set_rgba(void) +{ + image_texture_supports_rgba = true; +} + +void image_texture_unset_rgba(void) +{ + image_texture_supports_rgba = false; +} + bool image_texture_set_color_shifts( - struct texture_image *out_img, unsigned *r_shift, unsigned *g_shift, unsigned *b_shift, unsigned *a_shift) { @@ -48,7 +59,7 @@ bool image_texture_set_color_shifts( *g_shift = 8; *b_shift = 0; - if (out_img->supports_rgba) + if (image_texture_supports_rgba) { *r_shift = 0; *b_shift = 16; @@ -272,8 +283,7 @@ bool image_texture_load(struct texture_image *out_img, void *ptr = NULL; enum video_image_format fmt = image_texture_get_type(path); - image_texture_set_color_shifts(out_img, - &r_shift, &g_shift, &b_shift, + image_texture_set_color_shifts(&r_shift, &g_shift, &b_shift, &a_shift); if (fmt != IMAGE_FORMAT_NONE) diff --git a/libretro-common/include/formats/image.h b/libretro-common/include/formats/image.h index 048ba86a88..882c17d1c6 100644 --- a/libretro-common/include/formats/image.h +++ b/libretro-common/include/formats/image.h @@ -44,7 +44,6 @@ struct texture_image unsigned width; unsigned height; uint32_t *pixels; - bool supports_rgba; }; enum image_type_enum @@ -56,9 +55,7 @@ enum image_type_enum IMAGE_TYPE_TGA }; -bool image_texture_set_color_shifts( - struct texture_image *out_img, - unsigned *r_shift, unsigned *g_shift, +bool image_texture_set_color_shifts(unsigned *r_shift, unsigned *g_shift, unsigned *b_shift, unsigned *a_shift); bool image_texture_color_convert(unsigned r_shift, @@ -67,6 +64,8 @@ bool image_texture_color_convert(unsigned r_shift, bool image_texture_load(struct texture_image *img, const char *path); void image_texture_free(struct texture_image *img); +void image_texture_set_rgba(void); +void image_texture_unset_rgba(void); /* Image transfer */ diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index b388d0e17b..3c98971515 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1058,9 +1058,7 @@ static int generic_action_ok(const char *path, strlcpy(settings->path.menu_wallpaper, action_path, sizeof(settings->path.menu_wallpaper)); - task_push_image_load( - video_driver_supports_rgba(), - action_path, + task_push_image_load(action_path, MENU_ENUM_LABEL_CB_MENU_WALLPAPER, menu_display_handle_wallpaper_upload, NULL); } diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index dc5471ee78..6da387fc1a 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -1565,8 +1565,7 @@ static void mui_context_reset(void *data) menu_display_allocate_white_texture(); mui_context_reset_textures(mui); - task_push_image_load(video_driver_supports_rgba(), - settings->path.menu_wallpaper, + task_push_image_load(settings->path.menu_wallpaper, MENU_ENUM_LABEL_CB_MENU_WALLPAPER, menu_display_handle_wallpaper_upload, NULL); } diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index d74cb1d4e2..76e6735220 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -997,9 +997,7 @@ static void xmb_update_thumbnail_image(void *data) return; if (path_file_exists(xmb->thumbnail_file_path)) - task_push_image_load( - video_driver_supports_rgba(), - xmb->thumbnail_file_path, + task_push_image_load(xmb->thumbnail_file_path, MENU_ENUM_LABEL_CB_MENU_THUMBNAIL, menu_display_handle_thumbnail_upload, NULL); else if (xmb->depth == 1) @@ -1013,9 +1011,7 @@ static void xmb_update_savestate_thumbnail_image(void *data) return; if (path_file_exists(xmb->savestate_thumbnail_file_path)) - task_push_image_load( - video_driver_supports_rgba(), - xmb->savestate_thumbnail_file_path, + task_push_image_load(xmb->savestate_thumbnail_file_path, MENU_ENUM_LABEL_CB_MENU_SAVESTATE_THUMBNAIL, menu_display_handle_savestate_thumbnail_upload, NULL); else @@ -1359,9 +1355,7 @@ static void xmb_list_switch_new(xmb_handle_t *xmb, { if(path_file_exists(path)) { - task_push_image_load( - video_driver_supports_rgba(), - path, + task_push_image_load(path, MENU_ENUM_LABEL_CB_MENU_WALLPAPER, menu_display_handle_wallpaper_upload, NULL); strlcpy(xmb->background_file_path, @@ -3467,9 +3461,7 @@ static void xmb_context_reset_background(const char *iconpath) if (path_file_exists(path)) - task_push_image_load( - video_driver_supports_rgba(), - path, + task_push_image_load(path, MENU_ENUM_LABEL_CB_MENU_WALLPAPER, menu_display_handle_wallpaper_upload, NULL); } diff --git a/tasks/task_image.c b/tasks/task_image.c index d566830343..855b5e5f45 100644 --- a/tasks/task_image.c +++ b/tasks/task_image.c @@ -55,12 +55,6 @@ struct nbio_image_handle enum image_status_enum status; }; -struct nbio_wrapper_handle -{ - nbio_handle_t *nbio; - bool supports_rgba; -}; - static int cb_image_menu_upload_generic(void *data, size_t len) { unsigned r_shift, g_shift, b_shift, a_shift; @@ -74,9 +68,7 @@ static int cb_image_menu_upload_generic(void *data, size_t len) image->processing_final_state == IMAGE_PROCESS_ERROR_END) return -1; - image_texture_set_color_shifts( - &image->ti, - &r_shift, &g_shift, &b_shift, + image_texture_set_color_shifts(&r_shift, &g_shift, &b_shift, &a_shift); image_texture_color_convert(r_shift, g_shift, b_shift, @@ -257,25 +249,25 @@ error: static int cb_nbio_image_menu_thumbnail(void *data, size_t len) { - struct nbio_image_handle *image = NULL; - void *handle = NULL; - struct nbio_wrapper_handle *nbio = (struct nbio_wrapper_handle*)data; + struct nbio_image_handle *image = NULL; + void *handle = NULL; + nbio_handle_t *nbio = (nbio_handle_t*)data; if (!nbio) goto error; - handle = image_transfer_new(nbio->nbio->image_type); + handle = image_transfer_new(nbio->image_type); if (!handle) goto error; - image = (struct nbio_image_handle*)nbio->nbio->data; + image = (struct nbio_image_handle*)nbio->data; image->handle = handle; image->size = len; image->cb = &cb_image_menu_thumbnail; - return cb_nbio_generic(nbio->nbio, &len); + return cb_nbio_generic(nbio, &len); error: return -1; @@ -283,29 +275,29 @@ error: bool task_image_load_handler(retro_task_t *task) { - struct nbio_wrapper_handle *nbio = (struct nbio_wrapper_handle *)task->state; - struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->nbio->data; + nbio_handle_t *nbio = (nbio_handle_t*)task->state; + struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data; if (image) { switch (image->status) { case IMAGE_STATUS_PROCESS_TRANSFER: - if (task_image_iterate_process_transfer(nbio->nbio) == -1) + if (task_image_iterate_process_transfer(nbio) == -1) image->status = IMAGE_STATUS_PROCESS_TRANSFER_PARSE; break; case IMAGE_STATUS_TRANSFER_PARSE: - task_image_iterate_transfer_parse(nbio->nbio); + task_image_iterate_transfer_parse(nbio); if (image->is_blocking_on_processing) image->status = IMAGE_STATUS_PROCESS_TRANSFER; break; case IMAGE_STATUS_TRANSFER: if (!image->is_blocking) - if (task_image_iterate_transfer(nbio->nbio) == -1) + if (task_image_iterate_transfer(nbio) == -1) image->status = IMAGE_STATUS_TRANSFER_PARSE; break; case IMAGE_STATUS_PROCESS_TRANSFER_PARSE: - task_image_iterate_transfer_parse(nbio->nbio); + task_image_iterate_transfer_parse(nbio); if (!image->is_finished) break; case IMAGE_STATUS_TRANSFER_PARSE_FREE: @@ -315,7 +307,7 @@ bool task_image_load_handler(retro_task_t *task) } } - if ( (nbio->nbio && nbio->nbio->is_finished ) + if ( (nbio && nbio->is_finished ) && (image && image->is_finished ) && (task && !task_get_cancelled(task))) { @@ -332,76 +324,70 @@ bool task_image_load_handler(retro_task_t *task) return true; } -bool task_push_image_load(bool supports_rgba, - const char *fullpath, +bool task_push_image_load(const char *fullpath, enum msg_hash_enums enum_idx, retro_task_callback_t cb, void *user_data) { - retro_task_t *task = NULL; + nbio_handle_t *nbio = NULL; + retro_task_t *t = NULL; struct nbio_t *handle = NULL; struct nbio_image_handle *image = NULL; - struct nbio_wrapper_handle *nbio = NULL; if (enum_idx == MSG_UNKNOWN) goto error_msg; - task = (retro_task_t*)calloc(1, sizeof(*task)); - if (!task) + t = (retro_task_t*)calloc(1, sizeof(*t)); + if (!t) goto error_msg; - nbio = (struct nbio_wrapper_handle*)calloc(1, sizeof(*nbio)); + nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio)); if (!nbio) goto error; - nbio->nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio->nbio)); - if (!nbio->nbio) - goto error; - - handle = nbio_open(fullpath, NBIO_READ); + handle = nbio_open(fullpath, NBIO_READ); if (!handle) goto error; - nbio->supports_rgba = supports_rgba; - nbio->nbio->handle = handle; + nbio->handle = handle; - image = (struct nbio_image_handle*)calloc(1, sizeof(*image)); + image = (struct nbio_image_handle*)calloc(1, sizeof(*image)); if (!image) goto error; - image->status = IMAGE_STATUS_TRANSFER; + image->status = IMAGE_STATUS_TRANSFER; - nbio->nbio->data = (struct nbio_image_handle*)image; - nbio->nbio->is_finished = false; - nbio->nbio->cb = &cb_nbio_image_menu_thumbnail; - nbio->nbio->status = NBIO_STATUS_TRANSFER; + nbio->data = (struct nbio_image_handle*)image; + nbio->is_finished = false; + nbio->cb = &cb_nbio_image_menu_thumbnail; + nbio->status = NBIO_STATUS_TRANSFER; if (strstr(fullpath, file_path_str(FILE_PATH_PNG_EXTENSION))) - nbio->nbio->image_type = IMAGE_TYPE_PNG; + nbio->image_type = IMAGE_TYPE_PNG; else if (strstr(fullpath, file_path_str(FILE_PATH_JPEG_EXTENSION)) || strstr(fullpath, file_path_str(FILE_PATH_JPG_EXTENSION))) - nbio->nbio->image_type = IMAGE_TYPE_JPEG; + nbio->image_type = IMAGE_TYPE_JPEG; else if (strstr(fullpath, file_path_str(FILE_PATH_BMP_EXTENSION))) - nbio->nbio->image_type = IMAGE_TYPE_BMP; + nbio->image_type = IMAGE_TYPE_BMP; else if (strstr(fullpath, file_path_str(FILE_PATH_TGA_EXTENSION))) - nbio->nbio->image_type = IMAGE_TYPE_TGA; + nbio->image_type = IMAGE_TYPE_TGA; nbio_begin_read(handle); - task->state = nbio; - task->handler = task_file_load_handler; - task->cleanup = task_image_load_free; - task->callback = cb; - task->user_data = user_data; + t->state = nbio; + t->handler = task_file_load_handler; + t->cleanup = task_image_load_free; + t->callback = cb; + t->user_data = user_data; - task_queue_ctl(TASK_QUEUE_CTL_PUSH, task); + task_queue_ctl(TASK_QUEUE_CTL_PUSH, t); return true; error: nbio_free(handle); - task_image_load_free(task); - free(task); - if (nbio->nbio) - free(nbio->nbio); + task_image_load_free(t); + free(t); + if (nbio) + free(nbio); error_msg: RARCH_ERR("[image load] Failed to open '%s': %s.\n", diff --git a/tasks/tasks_internal.h b/tasks/tasks_internal.h index 234638e250..b070f29290 100644 --- a/tasks/tasks_internal.h +++ b/tasks/tasks_internal.h @@ -100,12 +100,9 @@ bool task_push_netplay_lan_scan(void); #endif -bool task_push_image_load( - bool supports_rgba, - const char *fullpath, +bool task_push_image_load(const char *fullpath, enum msg_hash_enums enum_idx, - retro_task_callback_t cb, - void *userdata); + retro_task_callback_t cb, void *userdata); #ifdef HAVE_LIBRETRODB bool task_push_dbscan(const char *fullpath,