Start making overlay loading 'deferred'

This commit is contained in:
twinaphex 2015-02-21 07:29:13 +01:00
parent 6b77b263f7
commit 61bbb2a3fb
4 changed files with 77 additions and 14 deletions

View File

@ -520,16 +520,21 @@ static bool input_overlay_resolve_targets(struct overlay *ol,
return true;
}
static bool input_overlay_load_overlays(input_overlay_t *ol, const char *path)
bool input_overlay_load_overlays(input_overlay_t *ol)
{
size_t i;
bool ret = true;
unsigned overlays = 0;
config_file_t *conf = config_file_new(path);
config_file_t *conf = NULL;
if (!ol)
return false;
conf = config_file_new(ol->overlay_path);
if (!conf)
{
RARCH_ERR("Failed to load config file: %s.\n", path);
RARCH_ERR("Failed to load config file: %s.\n", ol->overlay_path);
return false;
}
@ -557,7 +562,8 @@ static bool input_overlay_load_overlays(input_overlay_t *ol, const char *path)
for (i = 0; i < ol->size; i++)
{
if (!input_overlay_load_overlay(ol, conf, path, &ol->overlays[i], i))
if (!input_overlay_load_overlay(ol, conf,
ol->overlay_path, &ol->overlays[i], i))
{
RARCH_ERR("[Overlay]: Failed to load overlay #%u.\n", (unsigned)i);
ret = false;
@ -575,8 +581,13 @@ static bool input_overlay_load_overlays(input_overlay_t *ol, const char *path)
}
}
ol->state = OVERLAY_STATUS_DEFERRED_DONE;
end:
config_file_free(conf);
if (!ret)
ol->state = OVERLAY_STATUS_DEFERRED_ERROR;
return ret;
}
@ -594,21 +605,22 @@ static void input_overlay_load_active(input_overlay_t *ol,
ol->iface->full_screen(ol->iface_data, ol->active->full_screen);
}
static bool input_overlay_new_done(input_overlay_t *ol, bool enable,
float opacity, float scale_factor)
bool input_overlay_new_done(input_overlay_t *ol)
{
if (!ol)
return false;
ol->active = &ol->overlays[0];
input_overlay_load_active(ol, opacity);
input_overlay_enable(ol, enable);
input_overlay_load_active(ol, ol->deferred.opacity);
input_overlay_enable(ol, ol->deferred.enable);
input_overlay_set_alpha_mod(ol, opacity);
input_overlay_set_scale_factor(ol, scale_factor);
input_overlay_set_alpha_mod(ol, ol->deferred.opacity);
input_overlay_set_scale_factor(ol, ol->deferred.scale_factor);
ol->next_index = (ol->index + 1) % ol->size;
ol->state = OVERLAY_STATUS_ALIVE;
return true;
}
@ -649,10 +661,10 @@ input_overlay_t *input_overlay_new(const char *path, bool enable,
if (!ol->iface)
goto error;
if (!input_overlay_load_overlays(ol, path))
goto error;
if (!input_overlay_new_done(ol, enable, opacity, scale_factor))
goto error;
ol->state = OVERLAY_STATUS_DEFERRED_LOAD;
ol->deferred.enable = enable;
ol->deferred.opacity = opacity;
ol->deferred.scale_factor = scale_factor;
return ol;

View File

@ -67,6 +67,15 @@ enum overlay_type
OVERLAY_TYPE_KEYBOARD
};
enum overlay_status
{
OVERLAY_STATUS_NONE = 0,
OVERLAY_STATUS_DEFERRED_LOAD,
OVERLAY_STATUS_DEFERRED_DONE,
OVERLAY_STATUS_DEFERRED_ERROR,
OVERLAY_STATUS_ALIVE,
};
struct overlay_desc
{
float x;
@ -131,6 +140,15 @@ struct input_overlay
unsigned next_index;
char *overlay_path;
enum overlay_status state;
struct
{
bool enable;
float opacity;
float scale_factor;
} deferred;
};
typedef struct input_overlay input_overlay_t;
@ -157,6 +175,10 @@ typedef struct input_overlay_state
input_overlay_t *input_overlay_new(const char *path, bool enable,
float alpha_mod, float scale_factor);
bool input_overlay_load_overlays(input_overlay_t *ol);
bool input_overlay_new_done(input_overlay_t *ol);
/**
* input_overlay_free:
* @ol : Overlay handle.

View File

@ -482,6 +482,9 @@ static inline void input_poll_overlay(input_overlay_t *overlay_device, float opa
uint16_t key_mod = 0;
bool polled = false;
if (overlay_device->state != OVERLAY_STATUS_ALIVE)
return;
memcpy(old_key_state.keys, driver.overlay_state.keys,
sizeof(driver.overlay_state.keys));
memset(&driver.overlay_state, 0, sizeof(driver.overlay_state));

View File

@ -1013,6 +1013,27 @@ static void rarch_main_iterate_rdl(void)
}
#endif
#ifdef HAVE_OVERLAY
void rarch_main_iterate_overlay_state(void)
{
switch (driver.overlay->state)
{
case OVERLAY_STATUS_NONE:
case OVERLAY_STATUS_ALIVE:
break;
case OVERLAY_STATUS_DEFERRED_LOAD:
input_overlay_load_overlays(driver.overlay);
break;
case OVERLAY_STATUS_DEFERRED_DONE:
input_overlay_new_done(driver.overlay);
break;
case OVERLAY_STATUS_DEFERRED_ERROR:
input_overlay_free(driver.overlay);
break;
}
}
#endif
/**
* rarch_main_iterate:
*
@ -1044,6 +1065,11 @@ int rarch_main_iterate(void)
do_pre_state_checks(input, old_input, trigger_input);
#ifdef HAVE_OVERLAY
if (driver.overlay)
rarch_main_iterate_overlay_state();
#endif
#ifdef HAVE_NETWORKING
if (g_extern.http.handle)
{