Turn nbio_image_handle_t member image into pointer

This commit is contained in:
twinaphex 2016-05-13 15:00:44 +02:00
parent 7a16cf8806
commit acbc9116e3
3 changed files with 65 additions and 56 deletions

View File

@ -81,7 +81,7 @@ void rarch_task_file_load_handler(retro_task_t *task)
break; break;
} }
if (nbio->image.handle) if (nbio->image)
{ {
if (!rarch_task_image_load_handler(task)) if (!rarch_task_image_load_handler(task))
goto task_finished; goto task_finished;
@ -102,7 +102,7 @@ void rarch_task_file_load_handler(retro_task_t *task)
task_finished: task_finished:
task->finished = true; task->finished = true;
if (nbio->image.handle != NULL) if (nbio->image != NULL)
rarch_task_image_load_free(task); rarch_task_image_load_free(task);
nbio_free(nbio->handle); nbio_free(nbio->handle);

View File

@ -42,6 +42,21 @@ enum image_status_enum
IMAGE_STATUS_TRANSFER_PARSE_FREE IMAGE_STATUS_TRANSFER_PARSE_FREE
}; };
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;
unsigned status;
};
static int cb_image_menu_upload_generic(void *data, size_t len) static int cb_image_menu_upload_generic(void *data, size_t len)
{ {
unsigned r_shift, g_shift, b_shift, a_shift; unsigned r_shift, g_shift, b_shift, a_shift;
@ -50,19 +65,19 @@ static int cb_image_menu_upload_generic(void *data, size_t len)
if (!nbio) if (!nbio)
return -1; return -1;
if (nbio->image.processing_final_state == IMAGE_PROCESS_ERROR || if (nbio->image->processing_final_state == IMAGE_PROCESS_ERROR ||
nbio->image.processing_final_state == IMAGE_PROCESS_ERROR_END) nbio->image->processing_final_state == IMAGE_PROCESS_ERROR_END)
return -1; return -1;
video_texture_image_set_color_shifts(&r_shift, &g_shift, &b_shift, video_texture_image_set_color_shifts(&r_shift, &g_shift, &b_shift,
&a_shift); &a_shift);
video_texture_image_color_convert(r_shift, g_shift, b_shift, video_texture_image_color_convert(r_shift, g_shift, b_shift,
a_shift, &nbio->image.ti); a_shift, &nbio->image->ti);
nbio->image.is_blocking_on_processing = false; nbio->image->is_blocking_on_processing = false;
nbio->image.is_blocking = true; nbio->image->is_blocking = true;
nbio->image.is_finished = true; nbio->image->is_finished = true;
nbio->is_finished = true; nbio->is_finished = true;
return 0; return 0;
@ -70,10 +85,10 @@ static int cb_image_menu_upload_generic(void *data, size_t len)
static int task_image_iterate_transfer_parse(nbio_handle_t *nbio) static int task_image_iterate_transfer_parse(nbio_handle_t *nbio)
{ {
if (nbio->image.handle && nbio->image.cb) if (nbio->image->handle && nbio->image->cb)
{ {
size_t len = 0; size_t len = 0;
nbio->image.cb(nbio, len); nbio->image->cb(nbio, len);
} }
return 0; return 0;
@ -99,15 +114,15 @@ static int task_image_process(
unsigned *height) unsigned *height)
{ {
int retval = image_transfer_process( int retval = image_transfer_process(
nbio->image.handle, nbio->image->handle,
nbio->image_type, nbio->image_type,
&nbio->image.ti.pixels, nbio->image.size, width, height); &nbio->image->ti.pixels, nbio->image->size, width, height);
if (retval == IMAGE_PROCESS_ERROR) if (retval == IMAGE_PROCESS_ERROR)
return IMAGE_PROCESS_ERROR; return IMAGE_PROCESS_ERROR;
nbio->image.ti.width = *width; nbio->image->ti.width = *width;
nbio->image.ti.height = *height; nbio->image->ti.height = *height;
return retval; return retval;
} }
@ -128,8 +143,8 @@ static int cb_image_menu_generic(nbio_handle_t *nbio)
break; break;
} }
nbio->image.is_blocking_on_processing = true; nbio->image->is_blocking_on_processing = true;
nbio->image.is_finished = false; nbio->image->is_finished = false;
return 0; return 0;
} }
@ -141,7 +156,7 @@ static int cb_image_menu_thumbnail(void *data, size_t len)
if (cb_image_menu_generic(nbio) != 0) if (cb_image_menu_generic(nbio) != 0)
return -1; return -1;
nbio->image.cb = &cb_image_menu_upload_generic; nbio->image->cb = &cb_image_menu_upload_generic;
return 0; return 0;
} }
@ -154,7 +169,7 @@ static int task_image_iterate_process_transfer(nbio_handle_t *nbio)
if (!nbio) if (!nbio)
return -1; return -1;
for (i = 0; i < nbio->image.processing_pos_increment; i++) for (i = 0; i < nbio->image->processing_pos_increment; i++)
{ {
retval = task_image_process(nbio, retval = task_image_process(nbio,
&width, &height); &width, &height);
@ -165,7 +180,7 @@ static int task_image_iterate_process_transfer(nbio_handle_t *nbio)
if (retval == IMAGE_PROCESS_NEXT) if (retval == IMAGE_PROCESS_NEXT)
return 0; return 0;
nbio->image.processing_final_state = retval; nbio->image->processing_final_state = retval;
return -1; return -1;
} }
@ -176,12 +191,12 @@ static int task_image_iterate_transfer(nbio_handle_t *nbio)
if (!nbio) if (!nbio)
goto error; goto error;
if (nbio->image.is_finished) if (nbio->image->is_finished)
return 0; return 0;
for (i = 0; i < nbio->image.pos_increment; i++) for (i = 0; i < nbio->image->pos_increment; i++)
{ {
if (!image_transfer_iterate(nbio->image.handle, nbio->image_type)) if (!image_transfer_iterate(nbio->image->handle, nbio->image_type))
goto error; goto error;
} }
@ -193,10 +208,16 @@ error:
static void rarch_task_image_load_free_internal(nbio_handle_t *nbio) static void rarch_task_image_load_free_internal(nbio_handle_t *nbio)
{ {
nbio_image_handle_t *image = nbio ? &nbio->image : NULL; nbio_image_handle_t *image = nbio ? nbio->image : NULL;
if (nbio->image)
free(nbio->image);
nbio->image = NULL;
image_transfer_free(image->handle, nbio->image_type); image_transfer_free(image->handle, nbio->image_type);
image->handle = NULL; image->handle = NULL;
image->cb = NULL; image->cb = NULL;
} }
@ -205,7 +226,7 @@ static int cb_nbio_generic(nbio_handle_t *nbio, size_t *len)
{ {
void *ptr = NULL; void *ptr = NULL;
if (!nbio->image.handle) if (!nbio->image->handle)
goto error; goto error;
ptr = nbio_get_ptr(nbio->handle, len); ptr = nbio_get_ptr(nbio->handle, len);
@ -213,17 +234,17 @@ static int cb_nbio_generic(nbio_handle_t *nbio, size_t *len)
if (!ptr) if (!ptr)
goto error; goto error;
image_transfer_set_buffer_ptr(nbio->image.handle, nbio->image_type, ptr); image_transfer_set_buffer_ptr(nbio->image->handle, nbio->image_type, ptr);
nbio->image.size = *len; nbio->image->size = *len;
nbio->image.pos_increment = (*len / 2) ? (*len / 2) : 1; nbio->image->pos_increment = (*len / 2) ? (*len / 2) : 1;
nbio->image.processing_pos_increment = (*len / 4) ? (*len / 4) : 1; nbio->image->processing_pos_increment = (*len / 4) ? (*len / 4) : 1;
if (!image_transfer_start(nbio->image.handle, nbio->image_type)) if (!image_transfer_start(nbio->image->handle, nbio->image_type))
goto error; goto error;
nbio->image.is_blocking = false; nbio->image->is_blocking = false;
nbio->image.is_finished = false; nbio->image->is_finished = false;
nbio->is_finished = true; nbio->is_finished = true;
return 0; return 0;
@ -240,25 +261,25 @@ static int cb_nbio_image_menu_thumbnail(void *data, size_t len)
if (!nbio || !data) if (!nbio || !data)
return -1; return -1;
nbio->image.handle = image_transfer_new(nbio->image_type); nbio->image->handle = image_transfer_new(nbio->image_type);
nbio->image.size = len; nbio->image->size = len;
if (!nbio->image.handle) if (!nbio->image->handle)
goto error; goto error;
nbio->image.cb = &cb_image_menu_thumbnail; nbio->image->cb = &cb_image_menu_thumbnail;
return cb_nbio_generic(nbio, &len); return cb_nbio_generic(nbio, &len);
error: error:
nbio->image.handle = 0; nbio->image->handle = 0;
return -1; return -1;
} }
bool rarch_task_image_load_handler(retro_task_t *task) bool rarch_task_image_load_handler(retro_task_t *task)
{ {
nbio_handle_t *nbio = (nbio_handle_t*)task->state; nbio_handle_t *nbio = (nbio_handle_t*)task->state;
nbio_image_handle_t *image = nbio ? &nbio->image : NULL; nbio_image_handle_t *image = nbio ? nbio->image : NULL;
switch (image->status) switch (image->status)
{ {
@ -287,13 +308,13 @@ bool rarch_task_image_load_handler(retro_task_t *task)
} }
if ( nbio->is_finished if ( nbio->is_finished
&& nbio->image.is_finished && nbio->image->is_finished
&& !task->cancelled) && !task->cancelled)
{ {
task->task_data = malloc(sizeof(nbio->image.ti)); task->task_data = malloc(sizeof(nbio->image->ti));
if (task->task_data) if (task->task_data)
memcpy(task->task_data, &nbio->image.ti, sizeof(nbio->image.ti)); memcpy(task->task_data, &nbio->image->ti, sizeof(nbio->image->ti));
return false; return false;
} }
@ -317,11 +338,12 @@ bool rarch_task_push_image_load(const char *fullpath,
if (!nbio) if (!nbio)
goto error; goto error;
nbio->image = (struct nbio_image_handle*)calloc(1, sizeof(*nbio->image));
nbio->handle = handle; nbio->handle = handle;
nbio->is_finished = false; nbio->is_finished = false;
nbio->cb = &cb_nbio_default; nbio->cb = &cb_nbio_default;
nbio->status = NBIO_STATUS_TRANSFER; nbio->status = NBIO_STATUS_TRANSFER;
nbio->image.status = IMAGE_STATUS_TRANSFER; nbio->image->status = IMAGE_STATUS_TRANSFER;
if (strstr(fullpath, ".png")) if (strstr(fullpath, ".png"))
nbio->image_type = IMAGE_TYPE_PNG; nbio->image_type = IMAGE_TYPE_PNG;

View File

@ -54,25 +54,12 @@ typedef struct http_transfer_info
} http_transfer_info_t; } http_transfer_info_t;
#endif #endif
typedef struct nbio_image_handle typedef struct nbio_image_handle nbio_image_handle_t;
{
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;
unsigned status;
} nbio_image_handle_t;
typedef struct nbio_handle typedef struct nbio_handle
{ {
enum image_type_enum image_type; enum image_type_enum image_type;
nbio_image_handle_t image; nbio_image_handle_t *image;
bool is_finished; bool is_finished;
transfer_cb_t cb; transfer_cb_t cb;
struct nbio_t *handle; struct nbio_t *handle;