From 494dd6200ecc165395f68e3d3c53018ca0aff003 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Apr 2015 05:09:00 +0200 Subject: [PATCH 01/10] (Menu) Cleanups --- menu/menu_entries.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/menu/menu_entries.c b/menu/menu_entries.c index 3db8f2782f..329ad2ba98 100644 --- a/menu/menu_entries.c +++ b/menu/menu_entries.c @@ -91,9 +91,10 @@ int menu_entries_push_list(menu_handle_t *menu, if (menu && menu->list_settings) settings_list_free(menu->list_settings); - menu->list_settings = (rarch_setting_t *)setting_new(setting_flags); + menu->list_settings = (rarch_setting_t *)setting_new(setting_flags); + setting = (rarch_setting_t*)menu_setting_find(label); - if (!(setting = (rarch_setting_t*)menu_setting_find(label))) + if (!setting) return -1; menu_list_clear(list); @@ -101,10 +102,11 @@ int menu_entries_push_list(menu_handle_t *menu, for (; setting->type != ST_END_GROUP; setting++) { if ( - setting->type == ST_GROUP || - setting->type == ST_SUB_GROUP || - setting->type == ST_END_SUB_GROUP || - (setting->flags & SD_FLAG_ADVANCED && !settings->menu.show_advanced_settings) + setting->type == ST_GROUP + || setting->type == ST_SUB_GROUP + || setting->type == ST_END_SUB_GROUP + || (setting->flags & SD_FLAG_ADVANCED && + !settings->menu.show_advanced_settings) ) continue; @@ -197,8 +199,8 @@ int menu_entries_push_horizontal_menu_list(menu_handle_t *menu, const char *path, const char *label, unsigned menu_type) { - core_info_t *info = NULL; - global_t *global = global_get_ptr(); + core_info_t *info = NULL; + global_t *global = global_get_ptr(); core_info_list_t *info_list = (core_info_list_t*)global->core_info; settings_t *settings = config_get_ptr(); @@ -327,10 +329,10 @@ int menu_entries_parse_list( { size_t i, list_size; bool path_is_compressed, push_dir; - int device = 0; + int device = 0; struct string_list *str_list = NULL; - settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); + settings_t *settings = config_get_ptr(); + global_t *global = global_get_ptr(); (void)device; @@ -488,7 +490,7 @@ int menu_entries_deferred_push(file_list_t *list, file_list_t *menu_list) const char *path = NULL; const char *label = NULL; menu_file_list_cbs_t *cbs = NULL; - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); menu_list_get_last_stack(driver->menu->menu_list, &path, &label, &type); From 8b10d0adc2a9a1635534984931262dea27a40493 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Apr 2015 05:15:38 +0200 Subject: [PATCH 02/10] (menu_driver.c) Refactors --- menu/menu_driver.c | 152 ++++++++++++++++++--------------------------- 1 file changed, 59 insertions(+), 93 deletions(-) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 17975e452a..b95d9d63f3 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -174,185 +174,151 @@ menu_handle_t *menu_driver_get_ptr(void) return driver->menu; } -void menu_driver_navigation_increment(void) +static const menu_ctx_driver_t *menu_ctx_driver_get_ptr(void) { driver_t *driver = driver_get_ptr(); - if (!driver) - return; + if (!driver || !driver->menu_ctx) + return NULL; + return driver->menu_ctx; +} - if (driver->menu_ctx && driver->menu_ctx->navigation_increment) - driver->menu_ctx->navigation_increment(); +void menu_driver_navigation_increment(void) +{ + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); + + if (driver->navigation_increment) + driver->navigation_increment(); } void menu_driver_navigation_decrement(void) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->navigation_decrement) - driver->menu_ctx->navigation_decrement(); + if (driver->navigation_decrement) + driver->navigation_decrement(); } void menu_driver_navigation_clear(bool pending_push) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->navigation_clear) - driver->menu_ctx->navigation_clear(pending_push); + if (driver->navigation_clear) + driver->navigation_clear(pending_push); } void menu_driver_navigation_set(bool scroll) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->navigation_set) - driver->menu_ctx->navigation_set(scroll); + if (driver->navigation_set) + driver->navigation_set(scroll); } void menu_driver_navigation_set_last(void) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->navigation_set_last) - driver->menu_ctx->navigation_set_last(); + if (driver->navigation_set_last) + driver->navigation_set_last(); } void menu_driver_set_texture(void) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->set_texture) - driver->menu_ctx->set_texture(); + if (driver->set_texture) + driver->set_texture(); } void menu_driver_context_reset(void) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->context_reset) - driver->menu_ctx->context_reset(); + if (driver->context_reset) + driver->context_reset(); } void menu_driver_frame(void) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->frame) - driver->menu_ctx->frame(); + if (driver->frame) + driver->frame(); } void menu_driver_entry_iterate(unsigned action) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->entry_iterate) - driver->menu_ctx->entry_iterate(action); + if (driver->entry_iterate) + driver->entry_iterate(action); } void menu_driver_free(menu_handle_t *menu) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->free) - driver->menu_ctx->free(menu); + if (driver->free) + driver->free(menu); } void menu_driver_render_messagebox(const char *msg) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; - if (!driver->video_data) - return; - if (!driver->menu_ctx) - return; - if (!driver->menu_ctx->render_messagebox) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); if (!msg) return; - if (msg[0] != '\0') - driver->menu_ctx->render_messagebox(msg); + if (driver->render_messagebox && msg[0] != '\0') + driver->render_messagebox(msg); } void menu_driver_render(void) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; - if (!driver->video_data) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->render) - driver->menu_ctx->render(); + if (driver->render) + driver->render(); } void menu_driver_toggle(bool latch) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->toggle) - driver->menu_ctx->toggle(latch); + if (driver->toggle) + driver->toggle(latch); } void menu_driver_populate_entries(const char *path, const char *label, unsigned k) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->populate_entries) - driver->menu_ctx->populate_entries(path, label, k); + if (driver->populate_entries) + driver->populate_entries(path, label, k); } bool menu_driver_load_background(void *data) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return false; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->load_background) - return driver->menu_ctx->load_background(data); + if (driver->load_background) + return driver->load_background(data); return false; } void menu_driver_navigation_descend_alphabet(size_t *ptr_out) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->navigation_descend_alphabet) - driver->menu_ctx->navigation_descend_alphabet(ptr_out); + if (driver->navigation_descend_alphabet) + driver->navigation_descend_alphabet(ptr_out); } void menu_driver_navigation_ascend_alphabet(size_t *ptr_out) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return; + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); - if (driver->menu_ctx && driver->menu_ctx->navigation_ascend_alphabet) - driver->menu_ctx->navigation_ascend_alphabet(ptr_out); + if (driver->navigation_ascend_alphabet) + driver->navigation_ascend_alphabet(ptr_out); } From aeb359f5b5be64abf66e0728bbdc29a91382175d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Apr 2015 05:28:40 +0200 Subject: [PATCH 03/10] Go through more menu driver wrapper functions --- driver.c | 15 +++++------ menu/menu_driver.c | 49 ++++++++++++++++++++++++++++++++++ menu/menu_driver.h | 13 +++++++++ menu/menu_entries_cbs_toggle.c | 3 +-- menu/menu_list.c | 23 +++++----------- 5 files changed, 77 insertions(+), 26 deletions(-) diff --git a/driver.c b/driver.c index e8a2c143eb..125a7e43fe 100644 --- a/driver.c +++ b/driver.c @@ -431,15 +431,14 @@ void uninit_drivers(int flags) #ifdef HAVE_MENU if (flags & DRIVER_MENU) { - if (driver->menu_ctx && driver->menu_ctx->context_destroy) - driver->menu_ctx->context_destroy(); + menu_driver_context_destroy(); - if (!driver->menu_data_own) - { - menu_free_list(driver->menu); - menu_free(driver->menu); - driver->menu = NULL; - } + if (!driver->menu_data_own) + { + menu_free_list(driver->menu); + menu_free(driver->menu); + driver->menu = NULL; + } } #endif diff --git a/menu/menu_driver.c b/menu/menu_driver.c index b95d9d63f3..5d963aa346 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -182,6 +182,55 @@ static const menu_ctx_driver_t *menu_ctx_driver_get_ptr(void) return driver->menu_ctx; } +void menu_driver_list_delete(file_list_t *list, size_t i, size_t list_size) +{ + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); + + if (driver->list_delete) + driver->list_delete(list, i, list_size); +} + +void menu_driver_list_clear(file_list_t *list) +{ + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); + + if (driver->list_clear) + driver->list_clear(list); +} + +void menu_driver_context_destroy(void) +{ + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); + + if (driver->context_destroy) + driver->context_destroy(); +} + +void menu_driver_list_set_selection(file_list_t *list) +{ + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); + + if (driver->list_set_selection) + driver->list_set_selection(list); +} + +void menu_driver_list_insert(file_list_t *list, const char *path, + const char *label, size_t list_size) +{ + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); + + if (driver->list_insert) + driver->list_insert(list, path, label, list_size); +} + +void menu_driver_list_cache(bool state, unsigned action) +{ + const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); + + if (driver->list_cache) + driver->list_cache(state, action); +} + void menu_driver_navigation_increment(void) { const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 25f0279067..0c67803671 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -336,6 +336,19 @@ void menu_driver_navigation_descend_alphabet(size_t *); void menu_driver_navigation_ascend_alphabet(size_t *); +void menu_driver_list_cache(bool state, unsigned action); + +void menu_driver_list_delete(file_list_t *list, size_t i, size_t list_size); + +void menu_driver_list_insert(file_list_t *list, const char *path, + const char *label, size_t list_size); + +void menu_driver_list_clear(file_list_t *list); + +void menu_driver_list_set_selection(file_list_t *list); + +void menu_driver_context_destroy(void); + #ifdef __cplusplus } #endif diff --git a/menu/menu_entries_cbs_toggle.c b/menu/menu_entries_cbs_toggle.c index bc57170c21..92bc0e369f 100644 --- a/menu/menu_entries_cbs_toggle.c +++ b/menu/menu_entries_cbs_toggle.c @@ -235,8 +235,7 @@ static int action_toggle_mainmenu(unsigned type, const char *label, switch (push_list) { case 1: - if (driver->menu_ctx->list_cache) - driver->menu_ctx->list_cache(true, action); + menu_driver_list_cache(true, action); if (cbs && cbs->action_content_list_switch) return cbs->action_content_list_switch( diff --git a/menu/menu_list.c b/menu/menu_list.c index da1156930e..91e66d244d 100644 --- a/menu/menu_list.c +++ b/menu/menu_list.c @@ -149,8 +149,7 @@ static void menu_list_destroy(file_list_t *list) for (i = 0; i < list->size; i++) { - if (driver->menu_ctx->list_delete) - driver->menu_ctx->list_delete(list, i, list->size); + menu_driver_list_delete(list, i, list->size); menu_common_list_delete(list, i, list->size); } @@ -287,8 +286,7 @@ void menu_list_pop_stack(menu_list_t *list) if (file_list_get_size(list->menu_stack) <= 1) return; - if (driver->menu_ctx->list_cache) - driver->menu_ctx->list_cache(false, 0); + menu_driver_list_cache(false, 0); menu_list_pop(list->menu_stack, &menu->navigation.selection_ptr); menu->need_refresh = true; @@ -325,8 +323,7 @@ void menu_list_pop(file_list_t *list, size_t *directory_ptr) { size_t list_size = list->size - 1; - if (driver->menu_ctx->list_delete) - driver->menu_ctx->list_delete(list, list_size, list_size); + menu_driver_list_delete(list, list_size, list_size); menu_common_list_delete(list, list_size, list_size); } @@ -336,9 +333,7 @@ end: if (!driver->menu_ctx) return; - if (driver->menu_ctx->list_set_selection) - driver->menu_ctx->list_set_selection(list); - + menu_driver_list_set_selection(list); menu_common_list_set_selection(list); } @@ -348,8 +343,7 @@ void menu_list_clear(file_list_t *list) if (!driver->menu_ctx) goto end; - if (driver->menu_ctx->list_clear) - driver->menu_ctx->list_clear(list); + menu_driver_list_clear(list); end: menu_common_list_clear(list); @@ -363,9 +357,7 @@ static void menu_list_insert(file_list_t *list, if (!driver->menu_ctx) return; - if (driver->menu_ctx->list_insert) - driver->menu_ctx->list_insert(list, path, label, list->size - 1); - + menu_driver_list_insert(list, path, label, list->size - 1); menu_common_list_insert(list, path, label, type, list->size - 1); } @@ -410,8 +402,7 @@ int menu_list_push_stack_refresh(menu_list_t *list, const char *path, const char if (!list) return -1; - if (driver->menu_ctx->list_cache) - driver->menu_ctx->list_cache(false, 0); + menu_driver_list_cache(false, 0); menu_list_push_stack(list, path, label, type, directory_ptr); menu_navigation_clear(&menu->navigation, true); From 93c3838b7031c887b75c4c606b52e17150e8ceee Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 11 Apr 2015 05:31:03 +0200 Subject: [PATCH 04/10] Remove unused variables --- menu/menu_list.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/menu/menu_list.c b/menu/menu_list.c index 91e66d244d..71671afe44 100644 --- a/menu/menu_list.c +++ b/menu/menu_list.c @@ -279,7 +279,6 @@ void menu_list_flush_stack_by_needle(menu_list_t *list, void menu_list_pop_stack(menu_list_t *list) { menu_handle_t *menu = menu_driver_get_ptr(); - driver_t *driver = driver_get_ptr(); if (!menu || !list) return; @@ -396,7 +395,6 @@ int menu_list_push_stack_refresh(menu_list_t *list, const char *path, const char unsigned type, size_t directory_ptr) { menu_handle_t *menu = menu_driver_get_ptr(); - driver_t *driver = driver_get_ptr(); if (!menu) return -1; if (!list) From ef825e0c6a95914fc938d179fc665837410c2aa2 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Apr 2015 05:44:35 +0200 Subject: [PATCH 05/10] (Menu/video) Cleanups --- driver.c | 5 ----- gfx/video_driver.c | 16 +++++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/driver.c b/driver.c index 125a7e43fe..3d48a2091c 100644 --- a/driver.c +++ b/driver.c @@ -362,11 +362,6 @@ void init_drivers(int flags) if (flags & DRIVER_VIDEO) { - runloop_t *runloop = rarch_main_get_ptr(); - global_t *global = global_get_ptr(); - - runloop->frames.video.count = 0; - init_video(); if (!driver->video_cache_context_ack diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 11f3181e4e..25ef8bd046 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -410,15 +410,17 @@ void uninit_video_input(void) void init_video(void) { unsigned max_dim, scale, width, height; - video_viewport_t *custom_vp = NULL; - const input_driver_t *tmp = NULL; + video_viewport_t *custom_vp = NULL; + const input_driver_t *tmp = NULL; const struct retro_game_geometry *geom = NULL; - video_info_t video = {0}; + video_info_t video = {0}; static uint16_t dummy_pixels[32] = {0}; - runloop_t *runloop = rarch_main_get_ptr(); - driver_t *driver = driver_get_ptr(); - global_t *global = global_get_ptr(); - settings_t *settings = config_get_ptr(); + runloop_t *runloop = rarch_main_get_ptr(); + driver_t *driver = driver_get_ptr(); + global_t *global = global_get_ptr(); + settings_t *settings = config_get_ptr(); + + runloop->frames.video.count = 0; init_video_filter(global->system.pix_fmt); rarch_main_command(RARCH_CMD_SHADER_DIR_INIT); From 128fbce403a2612a22d66f9e7e98186ea6a53e98 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Apr 2015 05:57:53 +0200 Subject: [PATCH 06/10] video_driver.c - Refactor --- gfx/video_driver.c | 141 ++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 77 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 25ef8bd046..1731009254 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -222,6 +222,14 @@ void *video_driver_get_ptr(const video_driver_t **drv) return driver->video_data; } +static const video_poke_interface_t *video_driver_get_poke_ptr(void) +{ + driver_t *driver = driver_get_ptr(); + if (!driver) + return NULL; + return driver->video_poke; +} + /** * video_driver_get_current_framebuffer: * @@ -233,18 +241,22 @@ void *video_driver_get_ptr(const video_driver_t **drv) uintptr_t video_driver_get_current_framebuffer(void) { #ifdef HAVE_FBO - driver_t *driver = driver_get_ptr(); - if (driver && driver->video_poke && driver->video_poke->get_current_framebuffer) - return driver->video_poke->get_current_framebuffer(driver->video_data); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); + + if (poke && poke->get_current_framebuffer) + return poke->get_current_framebuffer(driver->video_data); #endif return 0; } retro_proc_address_t video_driver_get_proc_address(const char *sym) { - driver_t *driver = driver_get_ptr(); - if (driver && driver->video_data && driver->video_poke && driver->video_poke->get_proc_address) - return driver->video_poke->get_proc_address(driver->video_data, sym); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); + + if (poke && poke->get_proc_address) + return poke->get_proc_address(driver->video_data, sym); return NULL; } @@ -600,30 +612,26 @@ bool video_driver_set_rotation(unsigned rotation) return false; } + void video_driver_set_video_mode(unsigned width, unsigned height, bool fullscreen) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video_data - && driver->video_poke - && driver->video_poke->set_video_mode) - driver->video_poke->set_video_mode(driver->video_data, + if (poke && poke->set_video_mode) + poke->set_video_mode(driver->video_data, width, height, fullscreen); } bool video_driver_get_video_output_size(unsigned *width, unsigned *height) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video_data - && driver->video_poke - && driver->video_poke->get_video_output_size) + if (poke && poke->get_video_output_size) { - driver->video_poke->get_video_output_size(driver->video_data, - width, height); + poke->get_video_output_size(driver->video_data, width, height); return true; } return false; @@ -631,51 +639,40 @@ bool video_driver_get_video_output_size(unsigned *width, unsigned *height) void video_driver_set_aspect_ratio(unsigned aspectratio_index) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video_data - && driver->video_poke - && driver->video_poke->set_aspect_ratio) - driver->video_poke->set_aspect_ratio(driver->video_data, - aspectratio_index); + if (poke && poke->set_aspect_ratio) + poke->set_aspect_ratio(driver->video_data, aspectratio_index); } void video_driver_show_mouse(bool state) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video_data - && driver->video_poke - && driver->video_poke->show_mouse) - driver->video_poke->show_mouse( - driver->video_data, state); + if (poke && poke->show_mouse) + poke->show_mouse(driver->video_data, state); } void video_driver_set_osd_msg(const char *msg, const struct font_params *params, void *font) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video_data - && driver->video_poke - && driver->video_poke->set_osd_msg) - driver->video_poke->set_osd_msg(driver->video_data, - msg, params, font); + if (poke && poke->set_osd_msg) + poke->set_osd_msg(driver->video_data, msg, params, font); } void video_driver_set_texture_enable(bool enable, bool fullscreen) { #ifdef HAVE_MENU - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video_data - && driver->video_poke - && driver->video_poke->set_texture_enable) - driver->video_poke->set_texture_enable(driver->video_data, + if (poke && poke->set_texture_enable) + poke->set_texture_enable(driver->video_data, enable, fullscreen); #endif } @@ -684,14 +681,12 @@ void video_driver_set_texture_frame(const void *frame, bool rgb32, unsigned width, unsigned height, float alpha) { #ifdef HAVE_MENU - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video_data - && driver->video_poke - && driver->video_poke->set_texture_frame) - driver->video_poke->set_texture_frame( - driver->video_data, frame, rgb32, width, height, alpha); + if (poke && poke->set_texture_frame) + poke->set_texture_frame(driver->video_data, + frame, rgb32, width, height, alpha); #endif } @@ -762,46 +757,38 @@ void * video_driver_read_frame_raw(unsigned *width, void video_driver_set_filtering(unsigned index, bool smooth) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video && driver->video_poke - && driver->video_poke->set_filtering) - driver->video_poke->set_filtering(driver->video_data, - index, smooth); + if (poke && poke->set_filtering) + poke->set_filtering(driver->video_data, index, smooth); } void video_driver_apply_state_changes(void) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver && driver->video && driver->video_poke - && driver->video_poke->apply_state_changes) - driver->video_poke->apply_state_changes(driver->video_data); + if (poke && poke->apply_state_changes) + poke->apply_state_changes(driver->video_data); } void video_driver_get_video_output_next(void) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video - && driver->video_data - && driver->video_poke - && driver->video_poke->get_video_output_next) - driver->video_poke->get_video_output_next(driver->video_data); + if (poke && poke->get_video_output_next) + poke->get_video_output_next(driver->video_data); } void video_driver_get_video_output_prev(void) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_poke_interface_t *poke = video_driver_get_poke_ptr(); - if (driver - && driver->video - && driver->video_data - && driver->video_poke - && driver->video_poke->get_video_output_prev) - driver->video_poke->get_video_output_prev(driver->video_data); + if (poke && poke->get_video_output_prev) + poke->get_video_output_prev(driver->video_data); } bool video_driver_frame(const void *frame, unsigned width, From 5112a6883eabb85c1a884d5ed81d34eea36fe8d4 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Apr 2015 06:09:24 +0200 Subject: [PATCH 07/10] Create video_driver_ctx_get_ptr --- gfx/video_driver.c | 97 ++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 1731009254..2cd04c5467 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -230,6 +230,14 @@ static const video_poke_interface_t *video_driver_get_poke_ptr(void) return driver->video_poke; } +static const video_driver_t *video_driver_ctx_get_ptr(void) +{ + driver_t *driver = driver_get_ptr(); + if (!driver) + return NULL; + return driver->video; +} + /** * video_driver_get_current_framebuffer: * @@ -263,18 +271,17 @@ retro_proc_address_t video_driver_get_proc_address(const char *sym) bool video_driver_is_alive(void) { driver_t *driver = driver_get_ptr(); - /* Possible race issue, return true */ - if (driver->video && driver->video_data) - return driver->video->alive(driver->video_data); - return false; + const video_driver_t *video = video_driver_ctx_get_ptr(); + + return video->alive(driver->video_data); } bool video_driver_has_focus(void) { driver_t *driver = driver_get_ptr(); - if (driver->video && driver->video_data) - return driver->video->focus(driver->video_data); - return false; + const video_driver_t *video = video_driver_ctx_get_ptr(); + + return video->focus(driver->video_data); } bool video_driver_set_shader(enum rarch_shader_type type, @@ -585,28 +592,29 @@ void init_video(void) bool video_driver_has_windowed(void) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); - if (!driver || !driver->video) - return false; - return driver->video->has_windowed(driver->video_data); + return video->has_windowed(driver->video_data); } void video_driver_set_nonblock_state(bool toggle) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); - if (driver && driver->video) - driver->video->set_nonblock_state(driver->video_data, toggle); + if (video->set_nonblock_state) + video->set_nonblock_state(driver->video_data, toggle); } bool video_driver_set_rotation(unsigned rotation) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); - if (driver && driver->video) + if (video->set_rotation) { - driver->video->set_rotation(driver->video_data, rotation); + video->set_rotation(driver->video_data, rotation); return true; } return false; @@ -692,14 +700,12 @@ void video_driver_set_texture_frame(const void *frame, bool rgb32, bool video_driver_viewport_info(struct video_viewport *vp) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); - if (driver - && driver->video_data - && driver->video - && driver->video->viewport_info) + if (video->viewport_info) { - driver->video->viewport_info(driver->video_data, vp); + video->viewport_info(driver->video_data, vp); return true; } return false; @@ -707,35 +713,32 @@ bool video_driver_viewport_info(struct video_viewport *vp) bool video_driver_read_viewport(uint8_t *buffer) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); - if (driver - && driver->video - && driver->video->read_viewport) - return driver->video->read_viewport(driver->video_data, + if (video->read_viewport) + return video->read_viewport(driver->video_data, buffer); return false; } bool video_driver_focus(void) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); - if (driver && driver->video) - return driver->video->focus(driver->video_data); - return false; + return video->focus(driver->video_data); } #ifdef HAVE_OVERLAY bool video_driver_overlay_interface(const video_overlay_interface_t **iface) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); - if (driver - && driver->video - && driver->video->overlay_interface) + if (video->overlay_interface) { - driver->video->overlay_interface(driver->video_data, iface); + video->overlay_interface(driver->video_data, iface); return true; } return false; @@ -745,12 +748,11 @@ bool video_driver_overlay_interface(const video_overlay_interface_t **iface) void * video_driver_read_frame_raw(unsigned *width, unsigned *height, size_t *pitch) { - driver_t *driver = driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); - if (driver - && driver->video - && driver->video->read_frame_raw) - return driver->video->read_frame_raw(driver->video_data, width, + if (video->read_frame_raw) + return video->read_frame_raw(driver->video_data, width, height, pitch); return NULL; } @@ -794,11 +796,12 @@ void video_driver_get_video_output_prev(void) bool video_driver_frame(const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { - driver_t *driver = driver_get_ptr(); - runloop_t *runloop = rarch_main_get_ptr(); - if (driver && driver->video - && driver->video->frame(driver->video_data, - frame, width, height, pitch, msg)) + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); + runloop_t *runloop = rarch_main_get_ptr(); + + if (video->frame(driver->video_data, frame, + width, height, pitch, msg)) { runloop->frames.video.count++; return true; From c5cdd729dbb6f64dc79c653b02513d2cc550cc27 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Apr 2015 06:12:27 +0200 Subject: [PATCH 08/10] Create video_driver_suppress_screensaver --- gfx/video_driver.c | 12 +++++++++--- gfx/video_driver.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 2cd04c5467..e6c5b7f256 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -568,9 +568,7 @@ void init_video(void) video_driver_set_rotation( (settings->video.rotation + global->system.rotation) % 4); - if (driver->video->suppress_screensaver) - driver->video->suppress_screensaver(driver->video_data, - settings->ui.suspend_screensaver_enable); + video_driver_suppress_screensaver(settings->ui.suspend_screensaver_enable); if (!driver->input) init_video_input(tmp); @@ -590,6 +588,14 @@ void init_video(void) #endif } +bool video_driver_suppress_screensaver(bool enable) +{ + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); + + return video->suppress_screensaver(driver->video_data, enable); +} + bool video_driver_has_windowed(void) { driver_t *driver = driver_get_ptr(); diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 0097621910..d6c856205d 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -331,6 +331,8 @@ void video_driver_get_video_output_prev(void); bool video_driver_frame(const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg); +bool video_driver_suppress_screensaver(bool enable); + #ifdef __cplusplus } #endif From b77a3c49eec2cd63e27f40d24505e9b5412df819 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Apr 2015 06:17:59 +0200 Subject: [PATCH 09/10] Cleanup video_driver_set_shader --- gfx/video_driver.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index e6c5b7f256..65a9685b03 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -287,15 +287,12 @@ bool video_driver_has_focus(void) bool video_driver_set_shader(enum rarch_shader_type type, const char *path) { - driver_t *driver = driver_get_ptr(); - if (!driver) - return false; - if (!driver->video_data) - return false; - if (!driver->video->set_shader) - return false; + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); - return driver->video->set_shader(driver->video_data, type, path); + if (video->set_shader) + return video->set_shader(driver->video_data, type, path); + return false; } static void deinit_video_filter(void) From c00b1ac7e1ee83adefdb5b4aa31b3e4bcbe9c518 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Apr 2015 06:23:40 +0200 Subject: [PATCH 10/10] init_video - cleanup --- gfx/video_driver.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 65a9685b03..e3842b5e3a 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -481,13 +481,10 @@ void init_video(void) unsigned base_width = roundf(geom->base_height * global->system.aspect_ratio); width = roundf(base_width * settings->video.scale); - height = roundf(geom->base_height * settings->video.scale); } else - { width = roundf(geom->base_width * settings->video.scale); - height = roundf(geom->base_height * settings->video.scale); - } + height = roundf(geom->base_height * settings->video.scale); } if (width && height)