2016-05-10 05:54:47 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <file/nbio.h>
|
|
|
|
#include <formats/image.h>
|
|
|
|
#include <compat/strl.h>
|
|
|
|
#include <retro_assert.h>
|
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
#include <lists/string_list.h>
|
|
|
|
#include <rhash.h>
|
|
|
|
|
2016-12-29 22:14:48 +00:00
|
|
|
#include "../gfx/video_driver.h"
|
2016-07-23 09:28:24 +00:00
|
|
|
#include "../file_path_special.h"
|
2016-05-10 05:54:47 +00:00
|
|
|
#include "../verbosity.h"
|
|
|
|
|
2016-07-23 09:28:24 +00:00
|
|
|
#include "tasks_internal.h"
|
|
|
|
|
2016-05-10 05:55:31 +00:00
|
|
|
enum image_status_enum
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-05-10 05:55:31 +00:00
|
|
|
IMAGE_STATUS_POLL = 0,
|
|
|
|
IMAGE_STATUS_TRANSFER,
|
|
|
|
IMAGE_STATUS_TRANSFER_PARSE,
|
|
|
|
IMAGE_STATUS_PROCESS_TRANSFER,
|
|
|
|
IMAGE_STATUS_PROCESS_TRANSFER_PARSE,
|
|
|
|
IMAGE_STATUS_TRANSFER_PARSE_FREE
|
2016-05-10 05:54:47 +00:00
|
|
|
};
|
|
|
|
|
2016-05-13 13:00:44 +00:00
|
|
|
struct nbio_image_handle
|
|
|
|
{
|
|
|
|
struct texture_image ti;
|
|
|
|
bool is_blocking;
|
|
|
|
bool is_blocking_on_processing;
|
|
|
|
bool is_finished;
|
|
|
|
transfer_cb_t cb;
|
|
|
|
void *handle;
|
|
|
|
size_t size;
|
|
|
|
unsigned processing_pos_increment;
|
|
|
|
unsigned pos_increment;
|
|
|
|
int processing_final_state;
|
2016-05-20 17:32:09 +00:00
|
|
|
enum image_status_enum status;
|
2016-05-13 13:00:44 +00:00
|
|
|
};
|
|
|
|
|
2016-05-10 05:54:47 +00:00
|
|
|
static int cb_image_menu_upload_generic(void *data, size_t len)
|
|
|
|
{
|
|
|
|
unsigned r_shift, g_shift, b_shift, a_shift;
|
2016-09-23 00:49:25 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-26 15:47:21 +00:00
|
|
|
if (!image)
|
2016-05-10 05:54:47 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
if (image->processing_final_state == IMAGE_PROCESS_ERROR ||
|
|
|
|
image->processing_final_state == IMAGE_PROCESS_ERROR_END)
|
2016-05-10 05:54:47 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
image_texture_set_color_shifts(&r_shift, &g_shift, &b_shift,
|
2016-12-29 22:22:40 +00:00
|
|
|
&a_shift, &image->ti);
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-18 10:57:44 +00:00
|
|
|
image_texture_color_convert(r_shift, g_shift, b_shift,
|
2016-05-13 13:18:40 +00:00
|
|
|
a_shift, &image->ti);
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
image->is_blocking_on_processing = false;
|
|
|
|
image->is_blocking = true;
|
|
|
|
image->is_finished = true;
|
|
|
|
nbio->is_finished = true;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:13:36 +00:00
|
|
|
static int task_image_iterate_transfer_parse(nbio_handle_t *nbio)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-09-23 00:49:25 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-13 13:18:40 +00:00
|
|
|
|
|
|
|
if (image->handle && image->cb)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
|
|
|
size_t len = 0;
|
2016-05-13 13:18:40 +00:00
|
|
|
image->cb(nbio, len);
|
2016-05-10 05:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:13:36 +00:00
|
|
|
static int task_image_process(
|
2016-05-12 11:13:14 +00:00
|
|
|
nbio_handle_t *nbio,
|
|
|
|
unsigned *width,
|
|
|
|
unsigned *height)
|
|
|
|
{
|
2016-09-23 00:49:25 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-20 19:03:42 +00:00
|
|
|
|
|
|
|
int retval = image_transfer_process(
|
|
|
|
image->handle,
|
|
|
|
nbio->image_type,
|
2016-05-13 13:18:40 +00:00
|
|
|
&image->ti.pixels, image->size, width, height);
|
2016-05-12 11:13:14 +00:00
|
|
|
|
|
|
|
if (retval == IMAGE_PROCESS_ERROR)
|
|
|
|
return IMAGE_PROCESS_ERROR;
|
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
image->ti.width = *width;
|
|
|
|
image->ti.height = *height;
|
2016-05-10 06:23:49 +00:00
|
|
|
|
2016-05-11 18:38:09 +00:00
|
|
|
return retval;
|
2016-05-10 06:23:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 01:55:09 +00:00
|
|
|
static int cb_image_menu_generic(nbio_handle_t *nbio)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-05-26 15:47:21 +00:00
|
|
|
int retval;
|
2016-05-10 05:54:47 +00:00
|
|
|
unsigned width = 0, height = 0;
|
2016-09-23 00:49:25 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-26 04:32:25 +00:00
|
|
|
|
2016-05-26 15:47:21 +00:00
|
|
|
if (!image)
|
2016-05-10 05:54:47 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-05-26 04:32:25 +00:00
|
|
|
retval = task_image_process(nbio, &width, &height);
|
|
|
|
if ((retval == IMAGE_PROCESS_ERROR) || (retval == IMAGE_PROCESS_ERROR_END))
|
|
|
|
return -1;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-26 04:32:25 +00:00
|
|
|
image->is_blocking_on_processing = (retval != IMAGE_PROCESS_END);
|
|
|
|
image->is_finished = (retval == IMAGE_PROCESS_END);
|
2016-05-10 05:54:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cb_image_menu_thumbnail(void *data, size_t len)
|
|
|
|
{
|
2016-05-18 21:28:03 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
2016-09-23 00:49:25 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-11 01:55:09 +00:00
|
|
|
if (cb_image_menu_generic(nbio) != 0)
|
2016-05-10 05:54:47 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
image->cb = &cb_image_menu_upload_generic;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:13:36 +00:00
|
|
|
static int task_image_iterate_process_transfer(nbio_handle_t *nbio)
|
2016-05-11 19:22:45 +00:00
|
|
|
{
|
|
|
|
int retval = 0;
|
2016-05-26 15:47:21 +00:00
|
|
|
unsigned i, width = 0, height = 0;
|
2016-09-23 00:49:25 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-11 19:22:45 +00:00
|
|
|
|
2016-05-26 15:47:21 +00:00
|
|
|
if (!image)
|
2016-05-11 19:22:45 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
for (i = 0; i < image->processing_pos_increment; i++)
|
2016-05-11 19:22:45 +00:00
|
|
|
{
|
2016-05-13 08:13:36 +00:00
|
|
|
retval = task_image_process(nbio,
|
2016-05-11 19:22:45 +00:00
|
|
|
&width, &height);
|
|
|
|
if (retval != IMAGE_PROCESS_NEXT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == IMAGE_PROCESS_NEXT)
|
|
|
|
return 0;
|
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
image->processing_final_state = retval;
|
2016-05-11 19:22:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:13:36 +00:00
|
|
|
static int task_image_iterate_transfer(nbio_handle_t *nbio)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2016-09-23 00:49:25 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-26 15:47:21 +00:00
|
|
|
if (!image)
|
2016-05-12 11:13:14 +00:00
|
|
|
goto error;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
if (image->is_finished)
|
2016-05-10 05:54:47 +00:00
|
|
|
return 0;
|
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
for (i = 0; i < image->pos_increment; i++)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-05-13 13:18:40 +00:00
|
|
|
if (!image_transfer_iterate(image->handle, nbio->image_type))
|
2016-05-12 11:13:14 +00:00
|
|
|
goto error;
|
2016-05-10 05:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-05-27 16:14:47 +00:00
|
|
|
static void task_image_load_free_internal(nbio_handle_t *nbio)
|
2016-05-10 06:09:12 +00:00
|
|
|
{
|
2016-09-23 00:49:25 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-13 13:00:44 +00:00
|
|
|
|
2016-09-23 00:50:29 +00:00
|
|
|
if (!image)
|
|
|
|
return;
|
2016-05-13 13:00:44 +00:00
|
|
|
|
2016-09-23 00:50:29 +00:00
|
|
|
image_transfer_free(image->handle, nbio->image_type);
|
2016-05-10 06:09:12 +00:00
|
|
|
|
2016-09-23 00:50:29 +00:00
|
|
|
image->handle = NULL;
|
|
|
|
image->cb = NULL;
|
2016-05-10 06:09:12 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 02:03:21 +00:00
|
|
|
static int cb_nbio_generic(nbio_handle_t *nbio, size_t *len)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-09-23 00:50:29 +00:00
|
|
|
void *ptr = NULL;
|
2016-09-23 00:49:25 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
if (!image || !image->handle)
|
2016-05-10 06:09:12 +00:00
|
|
|
goto error;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
|
|
|
ptr = nbio_get_ptr(nbio->handle, len);
|
|
|
|
|
|
|
|
if (!ptr)
|
2016-05-10 06:09:12 +00:00
|
|
|
goto error;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
image_transfer_set_buffer_ptr(image->handle, nbio->image_type, ptr);
|
2016-05-11 01:51:26 +00:00
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
image->size = *len;
|
|
|
|
image->pos_increment = (*len / 2) ? (*len / 2) : 1;
|
2016-05-18 22:16:30 +00:00
|
|
|
image->processing_pos_increment = (*len / 4) ? (*len / 4) : 1;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
if (!image_transfer_start(image->handle, nbio->image_type))
|
2016-05-13 02:33:11 +00:00
|
|
|
goto error;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
image->is_blocking = false;
|
|
|
|
image->is_finished = false;
|
|
|
|
nbio->is_finished = true;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-05-10 06:09:12 +00:00
|
|
|
|
|
|
|
error:
|
2016-05-27 16:14:47 +00:00
|
|
|
task_image_load_free_internal(nbio);
|
2016-12-27 22:48:10 +00:00
|
|
|
if (nbio)
|
|
|
|
{
|
|
|
|
if (nbio->data)
|
|
|
|
free(nbio->data);
|
|
|
|
nbio->data = NULL;
|
|
|
|
}
|
2016-05-10 06:09:12 +00:00
|
|
|
return -1;
|
2016-05-10 05:54:47 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 01:56:31 +00:00
|
|
|
static int cb_nbio_image_menu_thumbnail(void *data, size_t len)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-12-29 21:53:10 +00:00
|
|
|
struct nbio_image_handle *image = NULL;
|
|
|
|
void *handle = NULL;
|
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-18 21:28:03 +00:00
|
|
|
if (!nbio)
|
2016-05-18 15:27:05 +00:00
|
|
|
goto error;
|
2016-05-13 02:28:16 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
handle = image_transfer_new(nbio->image_type);
|
2016-05-13 02:28:16 +00:00
|
|
|
|
2016-05-18 15:27:05 +00:00
|
|
|
if (!handle)
|
2016-05-13 02:28:16 +00:00
|
|
|
goto error;
|
2016-05-18 21:28:03 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
image = (struct nbio_image_handle*)nbio->data;
|
2016-05-18 15:27:05 +00:00
|
|
|
|
|
|
|
image->handle = handle;
|
|
|
|
image->size = len;
|
2016-05-13 13:18:40 +00:00
|
|
|
image->cb = &cb_image_menu_thumbnail;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
return cb_nbio_generic(nbio, &len);
|
2016-05-13 02:28:16 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
return -1;
|
2016-05-10 05:54:47 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 16:14:47 +00:00
|
|
|
bool task_image_load_handler(retro_task_t *task)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-12-29 21:53:10 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
|
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-27 23:40:46 +00:00
|
|
|
if (image)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-12-27 23:40:46 +00:00
|
|
|
switch (image->status)
|
|
|
|
{
|
|
|
|
case IMAGE_STATUS_PROCESS_TRANSFER:
|
2016-12-29 21:53:10 +00:00
|
|
|
if (task_image_iterate_process_transfer(nbio) == -1)
|
2016-12-27 23:40:46 +00:00
|
|
|
image->status = IMAGE_STATUS_PROCESS_TRANSFER_PARSE;
|
2016-05-10 05:54:47 +00:00
|
|
|
break;
|
2016-12-27 23:40:46 +00:00
|
|
|
case IMAGE_STATUS_TRANSFER_PARSE:
|
2016-12-29 21:53:10 +00:00
|
|
|
task_image_iterate_transfer_parse(nbio);
|
2016-12-27 23:40:46 +00:00
|
|
|
if (image->is_blocking_on_processing)
|
|
|
|
image->status = IMAGE_STATUS_PROCESS_TRANSFER;
|
|
|
|
break;
|
|
|
|
case IMAGE_STATUS_TRANSFER:
|
|
|
|
if (!image->is_blocking)
|
2016-12-29 21:53:10 +00:00
|
|
|
if (task_image_iterate_transfer(nbio) == -1)
|
2016-12-27 23:40:46 +00:00
|
|
|
image->status = IMAGE_STATUS_TRANSFER_PARSE;
|
|
|
|
break;
|
|
|
|
case IMAGE_STATUS_PROCESS_TRANSFER_PARSE:
|
2016-12-29 21:53:10 +00:00
|
|
|
task_image_iterate_transfer_parse(nbio);
|
2016-12-27 23:40:46 +00:00
|
|
|
if (!image->is_finished)
|
|
|
|
break;
|
|
|
|
case IMAGE_STATUS_TRANSFER_PARSE_FREE:
|
|
|
|
case IMAGE_STATUS_POLL:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-05-10 05:54:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
if ( (nbio && nbio->is_finished )
|
2016-12-27 23:40:46 +00:00
|
|
|
&& (image && image->is_finished )
|
2016-12-29 05:50:18 +00:00
|
|
|
&& (task && !task_get_cancelled(task)))
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-12-29 05:50:18 +00:00
|
|
|
void *data = malloc(sizeof(image->ti));
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-29 05:50:18 +00:00
|
|
|
if (data)
|
|
|
|
memcpy(data, &image->ti, sizeof(image->ti));
|
|
|
|
|
|
|
|
task_set_data(task, data);
|
2016-05-10 05:54:47 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-30 04:33:04 +00:00
|
|
|
bool task_push_image_load(const char *fullpath, retro_task_callback_t cb, void *user_data)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-12-29 21:53:10 +00:00
|
|
|
nbio_handle_t *nbio = NULL;
|
2016-09-23 00:50:29 +00:00
|
|
|
struct nbio_image_handle *image = NULL;
|
2016-12-30 04:33:04 +00:00
|
|
|
retro_task_t *t = (retro_task_t*)calloc(1, sizeof(*t));
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
if (!t)
|
2016-05-23 20:41:24 +00:00
|
|
|
goto error_msg;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio));
|
2016-12-30 04:33:04 +00:00
|
|
|
|
2016-05-10 05:54:47 +00:00
|
|
|
if (!nbio)
|
2016-05-10 06:28:48 +00:00
|
|
|
goto error;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-30 03:58:58 +00:00
|
|
|
strlcpy(nbio->path, fullpath, sizeof(nbio->path));
|
2016-05-23 20:41:24 +00:00
|
|
|
|
2016-12-30 04:36:06 +00:00
|
|
|
if (video_driver_supports_rgba())
|
2016-12-29 22:14:48 +00:00
|
|
|
BIT32_SET(nbio->status_flags, NBIO_FLAG_IMAGE_SUPPORTS_RGBA);
|
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
image = (struct nbio_image_handle*)calloc(1, sizeof(*image));
|
2016-05-13 22:48:40 +00:00
|
|
|
if (!image)
|
|
|
|
goto error;
|
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
image->status = IMAGE_STATUS_TRANSFER;
|
2016-05-18 21:28:03 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
nbio->data = (struct nbio_image_handle*)image;
|
|
|
|
nbio->is_finished = false;
|
|
|
|
nbio->cb = &cb_nbio_image_menu_thumbnail;
|
2016-12-30 03:58:58 +00:00
|
|
|
nbio->status = NBIO_STATUS_INIT;
|
2016-05-11 02:10:42 +00:00
|
|
|
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
t->state = nbio;
|
|
|
|
t->handler = task_file_load_handler;
|
|
|
|
t->cleanup = task_image_load_free;
|
|
|
|
t->callback = cb;
|
|
|
|
t->user_data = user_data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
task_queue_ctl(TASK_QUEUE_CTL_PUSH, t);
|
2016-05-10 06:28:48 +00:00
|
|
|
|
2016-05-10 05:54:47 +00:00
|
|
|
return true;
|
2016-05-10 06:28:48 +00:00
|
|
|
|
|
|
|
error:
|
2016-12-29 21:53:10 +00:00
|
|
|
task_image_load_free(t);
|
|
|
|
free(t);
|
|
|
|
if (nbio)
|
|
|
|
free(nbio);
|
2016-05-14 04:00:53 +00:00
|
|
|
|
2016-05-23 20:41:24 +00:00
|
|
|
error_msg:
|
2016-05-10 06:28:48 +00:00
|
|
|
RARCH_ERR("[image load] Failed to open '%s': %s.\n",
|
|
|
|
fullpath, strerror(errno));
|
2016-05-23 20:41:24 +00:00
|
|
|
|
2016-05-10 06:28:48 +00:00
|
|
|
return false;
|
2016-05-10 05:54:47 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 16:14:47 +00:00
|
|
|
void task_image_load_free(retro_task_t *task)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-05-19 00:09:56 +00:00
|
|
|
nbio_handle_t *nbio = task ? (nbio_handle_t*)task->state : NULL;
|
2016-05-10 06:09:12 +00:00
|
|
|
|
2016-12-27 22:48:10 +00:00
|
|
|
if (nbio)
|
|
|
|
{
|
2016-05-27 16:14:47 +00:00
|
|
|
task_image_load_free_internal(nbio);
|
2016-12-27 22:48:10 +00:00
|
|
|
if (nbio->data)
|
|
|
|
free(nbio->data);
|
2016-05-23 20:41:24 +00:00
|
|
|
nbio_free(nbio->handle);
|
2016-12-27 22:48:10 +00:00
|
|
|
nbio->data = NULL;
|
2016-05-23 20:41:24 +00:00
|
|
|
nbio->handle = NULL;
|
|
|
|
free(nbio);
|
|
|
|
}
|
|
|
|
}
|