From 59fb7700b877451b996dc11f36b104d4d4ecd691 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 19 May 2017 15:25:14 +0200 Subject: [PATCH] Combine menu_driver.c and menu_display.c --- Makefile.common | 1 - command.c | 1 - config.def.h | 2 +- frontend/drivers/platform_linux.c | 1 - griffin/griffin.c | 1 - input/drivers/android_input.c | 2 +- menu/cbs/menu_cbs_get_value.c | 1 - menu/cbs/menu_cbs_ok.c | 1 - menu/cbs/menu_cbs_start.c | 1 - menu/drivers/materialui.c | 1 - menu/drivers/menu_generic.c | 1 - menu/drivers/nuklear.c | 1 - menu/drivers/nuklear/nk_common.c | 2 +- menu/drivers/nuklear/nk_menu.h | 4 +- menu/drivers/null.c | 1 - menu/drivers/rgui.c | 1 - menu/drivers/xmb.c | 1 - menu/drivers/xui.cpp | 1 - menu/drivers/zarch.c | 1 - menu/drivers_display/menu_display_caca.c | 2 +- menu/drivers_display/menu_display_ctr.c | 2 +- menu/drivers_display/menu_display_d3d.cpp | 2 +- menu/drivers_display/menu_display_gdi.c | 2 +- menu/drivers_display/menu_display_gl.c | 2 +- menu/drivers_display/menu_display_null.c | 2 +- menu/drivers_display/menu_display_vga.c | 2 +- menu/drivers_display/menu_display_vita2d.c | 2 +- menu/drivers_display/menu_display_vulkan.c | 2 +- menu/menu_content.c | 1 - menu/menu_display.c | 1230 -------------------- menu/menu_display.h | 317 ----- menu/menu_driver.c | 1200 ++++++++++++++++++- menu/menu_driver.h | 285 +++++ menu/menu_event.c | 1 - menu/menu_setting.c | 1 - menu/widgets/menu_dialog.c | 1 - retroarch.c | 1 - 37 files changed, 1497 insertions(+), 1583 deletions(-) delete mode 100644 menu/menu_display.c delete mode 100644 menu/menu_display.h diff --git a/Makefile.common b/Makefile.common index 068ef85c09..2a8b41c6e2 100644 --- a/Makefile.common +++ b/Makefile.common @@ -582,7 +582,6 @@ ifeq ($(HAVE_MENU_COMMON), 1) menu/cbs/menu_cbs_up.o \ menu/cbs/menu_cbs_down.o \ menu/cbs/menu_cbs_contentlist_switch.o \ - menu/menu_display.o \ menu/menu_displaylist.o \ menu/menu_animation.o \ menu/drivers_display/menu_display_null.o \ diff --git a/command.c b/command.c index fef9e629a6..da186dbe08 100644 --- a/command.c +++ b/command.c @@ -49,7 +49,6 @@ #ifdef HAVE_MENU #include "menu/menu_driver.h" #include "menu/menu_content.h" -#include "menu/menu_display.h" #include "menu/menu_shader.h" #include "menu/widgets/menu_dialog.h" #endif diff --git a/config.def.h b/config.def.h index db8b713298..16bb4418c3 100644 --- a/config.def.h +++ b/config.def.h @@ -226,7 +226,7 @@ static const bool overlay_hide_in_menu = true; static const bool display_keyboard_overlay = false; #ifdef HAVE_MENU -#include "menu/menu_display.h" +#include "menu/menu_driver.h" static bool default_block_config_read = true; diff --git a/frontend/drivers/platform_linux.c b/frontend/drivers/platform_linux.c index 488dedd96f..6055135f1a 100644 --- a/frontend/drivers/platform_linux.c +++ b/frontend/drivers/platform_linux.c @@ -62,7 +62,6 @@ #ifdef HAVE_MENU #include "../../menu/menu_driver.h" -#include "../../menu/menu_display.h" #include "../../menu/menu_entries.h" #endif diff --git a/griffin/griffin.c b/griffin/griffin.c index 1e5b88f4bd..a9f82c3a75 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -978,7 +978,6 @@ MENU #include "../menu/cbs/menu_cbs_down.c" #include "../menu/cbs/menu_cbs_contentlist_switch.c" #include "../menu/menu_shader.c" -#include "../menu/menu_display.c" #include "../menu/menu_displaylist.c" #include "../menu/menu_animation.c" diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 7b8983d4c0..f201574ff2 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -30,7 +30,7 @@ #endif #ifdef HAVE_MENU -#include "../../menu/menu_display.h" +#include "../../menu/menu_driver.h" #endif #include "../input_config.h" diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index 93ea93bc67..dc99bbf803 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -26,7 +26,6 @@ #include "../menu_animation.h" #include "../menu_cbs.h" #include "../menu_shader.h" -#include "../menu_display.h" #include "../../tasks/tasks_internal.h" #include "../../input/input_config.h" diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 284b7b5da8..b0eb67991f 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -28,7 +28,6 @@ #include "../menu_driver.h" #include "../menu_cbs.h" -#include "../menu_display.h" #include "../menu_setting.h" #include "../menu_shader.h" #include "../widgets/menu_dialog.h" diff --git a/menu/cbs/menu_cbs_start.c b/menu/cbs/menu_cbs_start.c index 8bf62dc570..68cbed8a70 100644 --- a/menu/cbs/menu_cbs_start.c +++ b/menu/cbs/menu_cbs_start.c @@ -24,7 +24,6 @@ #include "../menu_driver.h" #include "../menu_cbs.h" #include "../menu_input.h" -#include "../menu_display.h" #include "../menu_setting.h" #include "../menu_shader.h" diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index dff09850b1..b85484b185 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -43,7 +43,6 @@ #include "../menu_driver.h" #include "../menu_animation.h" -#include "../menu_display.h" #include "../menu_event.h" #include "../widgets/menu_input_dialog.h" diff --git a/menu/drivers/menu_generic.c b/menu/drivers/menu_generic.c index ec37d8cbd4..ed9ee8518d 100644 --- a/menu/drivers/menu_generic.c +++ b/menu/drivers/menu_generic.c @@ -22,7 +22,6 @@ #include "menu_generic.h" #include "../menu_driver.h" -#include "../menu_display.h" #include "../widgets/menu_dialog.h" #include "../widgets/menu_input_bind_dialog.h" diff --git a/menu/drivers/nuklear.c b/menu/drivers/nuklear.c index a23b1c4373..b5b72179f4 100644 --- a/menu/drivers/nuklear.c +++ b/menu/drivers/nuklear.c @@ -37,7 +37,6 @@ #include "../menu_driver.h" #include "../menu_animation.h" -#include "../menu_display.h" #include "../../core.h" #include "../../core_info.h" diff --git a/menu/drivers/nuklear/nk_common.c b/menu/drivers/nuklear/nk_common.c index d922743a14..57c55c4853 100644 --- a/menu/drivers/nuklear/nk_common.c +++ b/menu/drivers/nuklear/nk_common.c @@ -29,7 +29,7 @@ #include "nk_common.h" -#include "../../menu_display.h" +#include "../../menu_driver.h" #include "../../../gfx/video_driver.h" #ifdef HAVE_GLSL diff --git a/menu/drivers/nuklear/nk_menu.h b/menu/drivers/nuklear/nk_menu.h index 6957887c1a..0016083ee8 100644 --- a/menu/drivers/nuklear/nk_menu.h +++ b/menu/drivers/nuklear/nk_menu.h @@ -21,9 +21,9 @@ #define _NK_MENU_H #include "nk_common.h" -#include "../../menu_display.h" -#include "../../menu_input.h" +#include "../../menu_driver.h" +#include "../../menu_input.h" enum { diff --git a/menu/drivers/null.c b/menu/drivers/null.c index ac9da843eb..55a6bdc5f3 100644 --- a/menu/drivers/null.c +++ b/menu/drivers/null.c @@ -21,7 +21,6 @@ #include #include "../menu_driver.h" -#include "../menu_display.h" menu_ctx_driver_t menu_ctx_null = { NULL, /* set_texture */ diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 3d9fdbfaa2..22b124f96c 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -40,7 +40,6 @@ #include "../menu_driver.h" #include "../menu_animation.h" -#include "../menu_display.h" #include "../widgets/menu_input_dialog.h" diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 082065cc3b..dbd75d46c4 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -43,7 +43,6 @@ #include "../menu_driver.h" #include "../menu_animation.h" -#include "../menu_display.h" #include "../widgets/menu_entry.h" #include "../widgets/menu_list.h" diff --git a/menu/drivers/xui.cpp b/menu/drivers/xui.cpp index 3cdf8bc466..e379503444 100644 --- a/menu/drivers/xui.cpp +++ b/menu/drivers/xui.cpp @@ -36,7 +36,6 @@ #include "../menu_entries.h" #include "../menu_input.h" #include "../menu_setting.h" -#include "../menu_display.h" #include "../widgets/menu_input_dialog.h" #include "../../gfx/video_driver.h" diff --git a/menu/drivers/zarch.c b/menu/drivers/zarch.c index 5542dc31fb..6af0ef74f4 100644 --- a/menu/drivers/zarch.c +++ b/menu/drivers/zarch.c @@ -42,7 +42,6 @@ #include "../menu_driver.h" #include "../menu_animation.h" #include "../widgets/menu_entry.h" -#include "../menu_display.h" #include "../../retroarch.h" #include "../../gfx/font_driver.h" diff --git a/menu/drivers_display/menu_display_caca.c b/menu/drivers_display/menu_display_caca.c index 5b8ba4c1af..a1f795789c 100644 --- a/menu/drivers_display/menu_display_caca.c +++ b/menu/drivers_display/menu_display_caca.c @@ -23,7 +23,7 @@ #include "../../gfx/font_driver.h" #include "../../gfx/video_driver.h" -#include "../menu_display.h" +#include "../menu_driver.h" static void *menu_display_caca_get_default_mvp(void) { diff --git a/menu/drivers_display/menu_display_ctr.c b/menu/drivers_display/menu_display_ctr.c index bbaca7a280..93b34449f3 100644 --- a/menu/drivers_display/menu_display_ctr.c +++ b/menu/drivers_display/menu_display_ctr.c @@ -19,7 +19,7 @@ #include "../../config.h" #endif -#include "../menu_display.h" +#include "../menu_driver.h" #include "../../retroarch.h" #include "../../gfx/font_driver.h" diff --git a/menu/drivers_display/menu_display_d3d.cpp b/menu/drivers_display/menu_display_d3d.cpp index 1492e427de..65c8c2e2ba 100644 --- a/menu/drivers_display/menu_display_d3d.cpp +++ b/menu/drivers_display/menu_display_d3d.cpp @@ -21,7 +21,7 @@ #include "../../config.h" #endif -#include "../menu_display.h" +#include "../menu_driver.h" #include "../../retroarch.h" #include "../../gfx/font_driver.h" diff --git a/menu/drivers_display/menu_display_gdi.c b/menu/drivers_display/menu_display_gdi.c index b0ae6bff5a..5ad2db0c45 100644 --- a/menu/drivers_display/menu_display_gdi.c +++ b/menu/drivers_display/menu_display_gdi.c @@ -23,7 +23,7 @@ #include "../../gfx/font_driver.h" #include "../../gfx/video_driver.h" -#include "../menu_display.h" +#include "../menu_driver.h" #if defined(_WIN32) && !defined(_XBOX) #include "../../gfx/common/win32_common.h" diff --git a/menu/drivers_display/menu_display_gl.c b/menu/drivers_display/menu_display_gl.c index 2d09dce968..fd70b56de2 100644 --- a/menu/drivers_display/menu_display_gl.c +++ b/menu/drivers_display/menu_display_gl.c @@ -24,7 +24,7 @@ #include "../../gfx/video_driver.h" #include "../../gfx/common/gl_common.h" -#include "../menu_display.h" +#include "../menu_driver.h" static const GLfloat gl_vertexes[] = { 0, 0, diff --git a/menu/drivers_display/menu_display_null.c b/menu/drivers_display/menu_display_null.c index 86cf2d63a7..c4fbe5df57 100644 --- a/menu/drivers_display/menu_display_null.c +++ b/menu/drivers_display/menu_display_null.c @@ -21,7 +21,7 @@ #include "../../gfx/font_driver.h" #include "../../gfx/video_driver.h" -#include "../menu_display.h" +#include "../menu_driver.h" static void *menu_display_null_get_default_mvp(void) { diff --git a/menu/drivers_display/menu_display_vga.c b/menu/drivers_display/menu_display_vga.c index faa362b03d..d6c38bbbda 100644 --- a/menu/drivers_display/menu_display_vga.c +++ b/menu/drivers_display/menu_display_vga.c @@ -23,7 +23,7 @@ #include "../../gfx/font_driver.h" #include "../../gfx/video_driver.h" -#include "../menu_display.h" +#include "../menu_driver.h" static void *menu_display_vga_get_default_mvp(void) { diff --git a/menu/drivers_display/menu_display_vita2d.c b/menu/drivers_display/menu_display_vita2d.c index aad05a106b..1d2a5601fc 100644 --- a/menu/drivers_display/menu_display_vita2d.c +++ b/menu/drivers_display/menu_display_vita2d.c @@ -21,7 +21,7 @@ #include "../../config.h" #endif -#include "../menu_display.h" +#include "../menu_driver.h" #include "../../retroarch.h" #include "../../gfx/font_driver.h" diff --git a/menu/drivers_display/menu_display_vulkan.c b/menu/drivers_display/menu_display_vulkan.c index 5b7dc02663..5b7577b088 100644 --- a/menu/drivers_display/menu_display_vulkan.c +++ b/menu/drivers_display/menu_display_vulkan.c @@ -20,7 +20,7 @@ #include "../../config.h" #endif -#include "../menu_display.h" +#include "../menu_driver.h" #include "../../gfx/font_driver.h" #include "../../gfx/video_driver.h" diff --git a/menu/menu_content.c b/menu/menu_content.c index bcb3a195b9..8eafc352b7 100644 --- a/menu/menu_content.c +++ b/menu/menu_content.c @@ -26,7 +26,6 @@ #include "menu_content.h" #include "menu_driver.h" -#include "menu_display.h" #include "menu_shader.h" #include "../core_info.h" diff --git a/menu/menu_display.c b/menu/menu_display.c deleted file mode 100644 index d36450fd4c..0000000000 --- a/menu/menu_display.c +++ /dev/null @@ -1,1230 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2014-2017 - Jean-AndrĂ© Santoni - * Copyright (C) 2016-2017 - Brad Parker - * - * 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 . - */ - -#include - -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef HAVE_THREADS -#include "../gfx/video_thread_wrapper.h" -#endif - -#include "../config.def.h" -#include "../retroarch.h" -#include "../configuration.h" -#include "../core.h" -#include "../gfx/video_driver.h" -#include "../gfx/video_thread_wrapper.h" -#include "../verbosity.h" - -#include "menu_driver.h" -#include "menu_animation.h" -#include "menu_display.h" - -#define PARTICLES_COUNT 100 - -uintptr_t menu_display_white_texture; - - -static video_coord_array_t menu_disp_ca; - -static enum -menu_toggle_reason menu_display_toggle_reason = MENU_TOGGLE_REASON_NONE; - -static unsigned menu_display_framebuf_width = 0; -static unsigned menu_display_framebuf_height = 0; -static size_t menu_display_framebuf_pitch = 0; -static unsigned menu_display_header_height = 0; -static bool menu_display_has_windowed = false; -static bool menu_display_msg_force = false; -static bool menu_display_font_alloc_framebuf = false; -static bool menu_display_framebuf_dirty = false; -static const uint8_t *menu_display_font_framebuf = NULL; -static msg_queue_t *menu_display_msg_queue = NULL; -static menu_display_ctx_driver_t *menu_disp = NULL; - -static menu_display_ctx_driver_t *menu_display_ctx_drivers[] = { -#ifdef HAVE_D3D - &menu_display_ctx_d3d, -#endif -#ifdef HAVE_OPENGL - &menu_display_ctx_gl, -#endif -#ifdef HAVE_VULKAN - &menu_display_ctx_vulkan, -#endif -#ifdef HAVE_VITA2D - &menu_display_ctx_vita2d, -#endif -#ifdef _3DS - &menu_display_ctx_ctr, -#endif -#ifdef HAVE_CACA - &menu_display_ctx_caca, -#endif -#if defined(_WIN32) && !defined(_XBOX) - &menu_display_ctx_gdi, -#endif -#ifdef DJGPP - &menu_display_ctx_vga, -#endif - &menu_display_ctx_null, - NULL, -}; - -enum menu_toggle_reason menu_display_toggle_get_reason(void) -{ - return menu_display_toggle_reason; -} - -void menu_display_toggle_set_reason(enum menu_toggle_reason reason) -{ - menu_display_toggle_reason = reason; -} - -static const char *menu_video_get_ident(bool video_is_threaded) -{ -#ifdef HAVE_THREADS - if (video_is_threaded) - return video_thread_get_ident(); -#endif - - return video_driver_get_ident(); -} - -static bool menu_display_check_compatibility( - enum menu_display_driver_type type, - bool video_is_threaded) -{ - const char *video_driver = menu_video_get_ident(video_is_threaded); - - switch (type) - { - case MENU_VIDEO_DRIVER_GENERIC: - return true; - case MENU_VIDEO_DRIVER_OPENGL: - if (string_is_equal_fast(video_driver, "gl", 2)) - return true; - break; - case MENU_VIDEO_DRIVER_VULKAN: - if (string_is_equal_fast(video_driver, "vulkan", 6)) - return true; - break; - case MENU_VIDEO_DRIVER_DIRECT3D: - if (string_is_equal_fast(video_driver, "d3d", 3)) - return true; - break; - case MENU_VIDEO_DRIVER_VITA2D: - if (string_is_equal_fast(video_driver, "vita2d", 6)) - return true; - break; - case MENU_VIDEO_DRIVER_CTR: - if (string_is_equal_fast(video_driver, "ctr", 3)) - return true; - break; - case MENU_VIDEO_DRIVER_CACA: - if (string_is_equal_fast(video_driver, "caca", 4)) - return true; - break; - case MENU_VIDEO_DRIVER_GDI: - if (string_is_equal_fast(video_driver, "gdi", 3)) - return true; - break; - case MENU_VIDEO_DRIVER_VGA: - if (string_is_equal_fast(video_driver, "vga", 3)) - return true; - break; - } - - return false; -} - -void menu_display_timedate(menu_display_ctx_datetime_t *datetime) -{ - time_t time_; - - if (!datetime) - return; - - time(&time_); - - switch (datetime->time_mode) - { - case 0: /* Date and time */ - strftime(datetime->s, datetime->len, - "%Y-%m-%d %H:%M:%S", localtime(&time_)); - break; - case 1: /* Date */ - strftime(datetime->s, datetime->len, - "%Y-%m-%d", localtime(&time_)); - break; - case 2: /* Time */ - strftime(datetime->s, datetime->len, - "%H:%M:%S", localtime(&time_)); - break; - case 3: /* Time (hours-minutes) */ - strftime(datetime->s, datetime->len, - "%H:%M", localtime(&time_)); - break; - case 4: /* Date and time, without year and seconds */ - strftime(datetime->s, datetime->len, - "%d/%m %H:%M", localtime(&time_)); - break; - } -} - -void menu_display_blend_begin(void) -{ - if (!menu_disp || !menu_disp->blend_begin) - return; - menu_disp->blend_begin(); -} - -void menu_display_blend_end(void) -{ - if (!menu_disp || !menu_disp->blend_end) - return; - menu_disp->blend_end(); -} - -void menu_display_font_free(font_data_t *font) -{ - font_driver_free(font); -} - -static font_data_t *menu_display_font_main_init(menu_display_ctx_font_t *font, - bool is_threaded) -{ - font_data_t *font_data = NULL; - - if (!font || !menu_disp) - return NULL; - - if (!menu_disp->font_init_first((void**)&font_data, - video_driver_get_ptr(false), - font->path, font->size, is_threaded)) - return NULL; - - return font_data; -} - -font_data_t *menu_display_font(enum application_special_type type, float font_size, - bool is_threaded) -{ - menu_display_ctx_font_t font_info; - char fontpath[PATH_MAX_LENGTH]; - - fontpath[0] = '\0'; - - fill_pathname_application_special(fontpath, sizeof(fontpath), type); - - font_info.path = fontpath; - font_info.size = font_size; - - return menu_display_font_main_init(&font_info, is_threaded); -} - -void menu_display_font_bind_block(font_data_t *font, void *block) -{ - font_driver_bind_block(font, block); -} - -bool menu_display_font_flush_block(unsigned width, unsigned height, - font_data_t *font) -{ - font_driver_flush(width, height, font); - font_driver_bind_block(font, NULL); - return true; -} - -void menu_display_framebuffer_deinit(void) -{ - menu_display_framebuf_width = 0; - menu_display_framebuf_height = 0; - menu_display_framebuf_pitch = 0; -} - -void menu_display_deinit(void) -{ - if (menu_display_msg_queue) - msg_queue_free(menu_display_msg_queue); - - video_coord_array_free(&menu_disp_ca); - menu_display_msg_queue = NULL; - menu_display_msg_force = false; - menu_display_header_height = 0; - menu_disp = NULL; - menu_display_has_windowed = false; - - menu_animation_ctl(MENU_ANIMATION_CTL_DEINIT, NULL); - menu_display_framebuffer_deinit(); -} - -bool menu_display_init(void) -{ - menu_display_msg_queue = msg_queue_new(8); - menu_disp_ca.allocated = 0; - - menu_display_has_windowed = video_driver_has_windowed(); - return true; -} - -void menu_display_coords_array_reset(void) -{ - menu_disp_ca.coords.vertices = 0; -} - -video_coord_array_t *menu_display_get_coords_array(void) -{ - return &menu_disp_ca; -} - -const uint8_t *menu_display_get_font_framebuffer(void) -{ - return menu_display_font_framebuf; -} - -void menu_display_set_font_framebuffer(const uint8_t *buffer) -{ - menu_display_font_framebuf = buffer; -} - -static bool menu_display_libretro_running( - bool rarch_is_inited, - bool rarch_is_dummy_core) -{ - settings_t *settings = config_get_ptr(); - if (!settings->bools.menu_pause_libretro) - { - if (rarch_is_inited && !rarch_is_dummy_core) - return true; - } - return false; -} - -bool menu_display_libretro(bool is_idle, bool rarch_is_inited, bool rarch_is_dummy_core) -{ - video_driver_set_texture_enable(true, false); - - if (menu_display_libretro_running(rarch_is_inited, rarch_is_dummy_core)) - { - if (!input_driver_is_libretro_input_blocked()) - input_driver_set_libretro_input_blocked(); - - core_run(); - - input_driver_unset_libretro_input_blocked(); - return true; - } - - if (is_idle) - return true; /* Maybe return false here for indication of idleness? */ - return video_driver_cached_frame(); -} - -void menu_display_get_fb_size(unsigned *fb_width, - unsigned *fb_height, size_t *fb_pitch) -{ - *fb_width = menu_display_framebuf_width; - *fb_height = menu_display_framebuf_height; - *fb_pitch = menu_display_framebuf_pitch; -} - -void menu_display_set_width(unsigned width) -{ - menu_display_framebuf_width = width; -} - -void menu_display_set_height(unsigned height) -{ - menu_display_framebuf_height = height; -} - -void menu_display_set_header_height(unsigned height) -{ - menu_display_header_height = height; -} - -unsigned menu_display_get_header_height(void) -{ - return menu_display_header_height; -} - -size_t menu_display_get_framebuffer_pitch(void) -{ - return menu_display_framebuf_pitch; -} - -void menu_display_set_framebuffer_pitch(size_t pitch) -{ - menu_display_framebuf_pitch = pitch; -} - -bool menu_display_get_msg_force(void) -{ - return menu_display_msg_force; -} - -void menu_display_set_msg_force(bool state) -{ - menu_display_msg_force = state; -} - -bool menu_display_get_font_data_init(void) -{ - return menu_display_font_alloc_framebuf; -} - -void menu_display_set_font_data_init(bool state) -{ - menu_display_font_alloc_framebuf = state; -} - -bool menu_display_get_update_pending(void) -{ - if (menu_animation_is_active()) - return true; - if (menu_display_get_framebuffer_dirty_flag()) - return true; - return false; -} - -void menu_display_set_viewport(unsigned width, unsigned height) -{ - video_driver_set_viewport(width, height, true, false); -} - -void menu_display_unset_viewport(unsigned width, unsigned height) -{ - video_driver_set_viewport(width, height, false, true); -} - -bool menu_display_get_framebuffer_dirty_flag(void) -{ - return menu_display_framebuf_dirty; -} - -void menu_display_set_framebuffer_dirty_flag(void) -{ - menu_display_framebuf_dirty = true; -} - -void menu_display_unset_framebuffer_dirty_flag(void) -{ - menu_display_framebuf_dirty = false; -} - -float menu_display_get_dpi(void) -{ - gfx_ctx_metrics_t metrics; - settings_t *settings = config_get_ptr(); - float dpi = menu_dpi_override_value; - - if (!settings) - return true; - - metrics.type = DISPLAY_METRIC_DPI; - metrics.value = &dpi; - - if (settings->bools.menu_dpi_override_enable) - return settings->uints.menu_dpi_override_value; - else if (!video_context_driver_get_metrics(&metrics) || !dpi) - return menu_dpi_override_value; - - return dpi; -} - -bool menu_display_init_first_driver(bool video_is_threaded) -{ - unsigned i; - - for (i = 0; menu_display_ctx_drivers[i]; i++) - { - if (!menu_display_check_compatibility( - menu_display_ctx_drivers[i]->type, - video_is_threaded)) - continue; - - RARCH_LOG("[Menu]: Found menu display driver: \"%s\".\n", - menu_display_ctx_drivers[i]->ident); - menu_disp = menu_display_ctx_drivers[i]; - return true; - } - return false; -} - -bool menu_display_restore_clear_color(void) -{ - if (!menu_disp || !menu_disp->restore_clear_color) - return false; - menu_disp->restore_clear_color(); - return true; -} - -void menu_display_clear_color(menu_display_ctx_clearcolor_t *color) -{ - if (!menu_disp || !menu_disp->clear_color) - return; - menu_disp->clear_color(color); -} - -void menu_display_draw(menu_display_ctx_draw_t *draw) -{ - if (!menu_disp || !draw || !menu_disp->draw) - return; - - /* TODO - edge case */ - if (draw->height <= 0) - draw->height = 1; - - menu_disp->draw(draw); -} - -void menu_display_draw_pipeline(menu_display_ctx_draw_t *draw) -{ - if (!menu_disp || !draw || !menu_disp->draw_pipeline) - return; - menu_disp->draw_pipeline(draw); -} - -void menu_display_draw_bg(menu_display_ctx_draw_t *draw, - video_frame_info_t *video_info, bool add_opacity_to_wallpaper) -{ - static struct video_coords coords; - const float *new_vertex = NULL; - const float *new_tex_coord = NULL; - if (!menu_disp || !draw) - return; - - new_vertex = draw->vertex; - new_tex_coord = draw->tex_coord; - - if (!new_vertex) - new_vertex = menu_disp->get_default_vertices(); - if (!new_tex_coord) - new_tex_coord = menu_disp->get_default_tex_coords(); - - coords.vertices = (unsigned)draw->vertex_count; - coords.vertex = new_vertex; - coords.tex_coord = new_tex_coord; - coords.lut_tex_coord = new_tex_coord; - coords.color = (const float*)draw->color; - - draw->coords = &coords; - - if (!video_info->libretro_running && !draw->pipeline.active) - add_opacity_to_wallpaper = true; - - if (add_opacity_to_wallpaper) - menu_display_set_alpha(draw->color, video_info->menu_wallpaper_opacity); - - if (!draw->texture) - draw->texture = menu_display_white_texture; - - draw->matrix_data = (math_matrix_4x4*)menu_disp->get_default_mvp(); -} - -void menu_display_draw_gradient(menu_display_ctx_draw_t *draw, - video_frame_info_t *video_info) -{ - draw->texture = 0; - draw->x = 0; - draw->y = 0; - - menu_display_draw_bg(draw, video_info, false); - menu_display_draw(draw); -} - -void menu_display_draw_quad( - int x, int y, unsigned w, unsigned h, - unsigned width, unsigned height, - float *color) -{ - menu_display_ctx_draw_t draw; - struct video_coords coords; - - coords.vertices = 4; - coords.vertex = NULL; - coords.tex_coord = NULL; - coords.lut_tex_coord = NULL; - coords.color = color; - - menu_display_blend_begin(); - - draw.x = x; - draw.y = (int)height - y - (int)h; - draw.width = w; - draw.height = h; - draw.coords = &coords; - draw.matrix_data = NULL; - draw.texture = menu_display_white_texture; - draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP; - draw.pipeline.id = 0; - - menu_display_draw(&draw); - menu_display_blend_end(); -} - -void menu_display_draw_texture( - int x, int y, unsigned w, unsigned h, - unsigned width, unsigned height, - float *color, uintptr_t texture) -{ - menu_display_ctx_draw_t draw; - menu_display_ctx_rotate_draw_t rotate_draw; - struct video_coords coords; - math_matrix_4x4 mymat; - rotate_draw.matrix = &mymat; - rotate_draw.rotation = 0.0; - rotate_draw.scale_x = 1.0; - rotate_draw.scale_y = 1.0; - rotate_draw.scale_z = 1; - rotate_draw.scale_enable = true; - coords.vertices = 4; - coords.vertex = NULL; - coords.tex_coord = NULL; - coords.lut_tex_coord = NULL; - draw.width = w; - draw.height = h; - draw.coords = &coords; - draw.matrix_data = &mymat; - draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP; - draw.pipeline.id = 0; - coords.color = (const float*)color; - - menu_display_rotate_z(&rotate_draw); - - draw.texture = texture; - draw.x = x; - draw.y = height - y; - menu_display_draw(&draw); -} - -/* Draw the texture split into 9 sections, without scaling the corners. - * The middle sections will only scale in the X axis, and the side - * sections will only scale in the Y axis. */ -void menu_display_draw_texture_slice( - int x, int y, unsigned w, unsigned h, - unsigned new_w, unsigned new_h, - unsigned width, unsigned height, - float *color, unsigned offset, float scale_factor, uintptr_t texture) -{ - menu_display_ctx_draw_t draw; - menu_display_ctx_rotate_draw_t rotate_draw; - struct video_coords coords; - math_matrix_4x4 mymat; - unsigned i; - float V_BL[2], V_BR[2], V_TL[2], V_TR[2], T_BL[2], T_BR[2], T_TL[2], T_TR[2]; - - /* need space for the coordinates of two triangles in a strip, so 8 vertices */ - float *tex_coord = (float*)malloc(8 * sizeof(float)); - float *vert_coord = (float*)malloc(8 * sizeof(float)); - float *colors = (float*)malloc(16 * sizeof(float)); - - /* normalized width/height of the amount to offset from the corners, - * for both the vertex and texture coordinates */ - float vert_woff = (offset * scale_factor) / (float)width; - float vert_hoff = (offset * scale_factor) / (float)height; - float tex_woff = offset / (float)w; - float tex_hoff = offset / (float)h; - - /* the width/height of the middle sections of both the scaled and original image */ - float vert_scaled_mid_width = (new_w - (offset * scale_factor * 2)) / (float)width; - float vert_scaled_mid_height = (new_h - (offset * scale_factor * 2)) / (float)height; - float tex_mid_width = (w - (offset * 2)) / (float)w; - float tex_mid_height = (h - (offset * 2)) / (float)h; - - /* normalized coordinates for the start position of the image */ - float norm_x = x / (float)width; - float norm_y = (height - y) / (float)height; - - /* the four vertices of the top-left corner of the image, - * used as a starting point for all the other sections */ - V_BL[0] = norm_x; - V_BL[1] = norm_y; - V_BR[0] = norm_x + vert_woff; - V_BR[1] = norm_y; - V_TL[0] = norm_x; - V_TL[1] = norm_y + vert_hoff; - V_TR[0] = norm_x + vert_woff; - V_TR[1] = norm_y + vert_hoff; - T_BL[0] = 0.0f; - T_BL[1] = tex_hoff; - T_BR[0] = tex_woff; - T_BR[1] = tex_hoff; - T_TL[0] = 0.0f; - T_TL[1] = 0.0f; - T_TR[0] = tex_woff; - T_TR[1] = 0.0f; - - for (i = 0; i < (16 * sizeof(float)) / sizeof(colors[0]); i++) - colors[i] = 1.0f; - - rotate_draw.matrix = &mymat; - rotate_draw.rotation = 0.0; - rotate_draw.scale_x = 1.0; - rotate_draw.scale_y = 1.0; - rotate_draw.scale_z = 1; - rotate_draw.scale_enable = true; - coords.vertices = 4; - coords.vertex = vert_coord; - coords.tex_coord = tex_coord; - coords.lut_tex_coord = NULL; - draw.width = width; - draw.height = height; - draw.coords = &coords; - draw.matrix_data = &mymat; - draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP; - draw.pipeline.id = 0; - coords.color = (const float*)colors; - - menu_display_rotate_z(&rotate_draw); - - draw.texture = texture; - draw.x = 0; - draw.y = 0; - - /* vertex coords are specfied bottom-up in this order: BL BR TL TR */ - /* texture coords are specfied top-down in this order: BL BR TL TR */ - - /* If someone wants to change this to not draw several times, the - * coordinates will need to be modified because of the triangle strip usage. */ - - /* top-left corner */ - vert_coord[0] = V_BL[0]; - vert_coord[1] = V_BL[1]; - vert_coord[2] = V_BR[0]; - vert_coord[3] = V_BR[1]; - vert_coord[4] = V_TL[0]; - vert_coord[5] = V_TL[1]; - vert_coord[6] = V_TR[0]; - vert_coord[7] = V_TR[1]; - - tex_coord[0] = T_BL[0]; - tex_coord[1] = T_BL[1]; - tex_coord[2] = T_BR[0]; - tex_coord[3] = T_BR[1]; - tex_coord[4] = T_TL[0]; - tex_coord[5] = T_TL[1]; - tex_coord[6] = T_TR[0]; - tex_coord[7] = T_TR[1]; - - menu_display_draw(&draw); - - /* top-middle section */ - vert_coord[0] = V_BL[0] + vert_woff; - vert_coord[1] = V_BL[1]; - vert_coord[2] = V_BR[0] + vert_scaled_mid_width; - vert_coord[3] = V_BR[1]; - vert_coord[4] = V_TL[0] + vert_woff; - vert_coord[5] = V_TL[1]; - vert_coord[6] = V_TR[0] + vert_scaled_mid_width; - vert_coord[7] = V_TR[1]; - - tex_coord[0] = T_BL[0] + tex_woff; - tex_coord[1] = T_BL[1]; - tex_coord[2] = T_BR[0] + tex_mid_width; - tex_coord[3] = T_BR[1]; - tex_coord[4] = T_TL[0] + tex_woff; - tex_coord[5] = T_TL[1]; - tex_coord[6] = T_TR[0] + tex_mid_width; - tex_coord[7] = T_TR[1]; - - menu_display_draw(&draw); - - /* top-right corner */ - vert_coord[0] = V_BL[0] + vert_woff + vert_scaled_mid_width; - vert_coord[1] = V_BL[1]; - vert_coord[2] = V_BR[0] + vert_scaled_mid_width + vert_woff; - vert_coord[3] = V_BR[1]; - vert_coord[4] = V_TL[0] + vert_woff + vert_scaled_mid_width; - vert_coord[5] = V_TL[1]; - vert_coord[6] = V_TR[0] + vert_scaled_mid_width + vert_woff; - vert_coord[7] = V_TR[1]; - - tex_coord[0] = T_BL[0] + tex_woff + tex_mid_width; - tex_coord[1] = T_BL[1]; - tex_coord[2] = T_BR[0] + tex_mid_width + tex_woff; - tex_coord[3] = T_BR[1]; - tex_coord[4] = T_TL[0] + tex_woff + tex_mid_width; - tex_coord[5] = T_TL[1]; - tex_coord[6] = T_TR[0] + tex_mid_width + tex_woff; - tex_coord[7] = T_TR[1]; - - menu_display_draw(&draw); - - /* middle-left section */ - vert_coord[0] = V_BL[0]; - vert_coord[1] = V_BL[1] - vert_scaled_mid_height; - vert_coord[2] = V_BR[0]; - vert_coord[3] = V_BR[1] - vert_scaled_mid_height; - vert_coord[4] = V_TL[0]; - vert_coord[5] = V_TL[1] - vert_hoff; - vert_coord[6] = V_TR[0]; - vert_coord[7] = V_TR[1] - vert_hoff; - - tex_coord[0] = T_BL[0]; - tex_coord[1] = T_BL[1] + tex_mid_height; - tex_coord[2] = T_BR[0]; - tex_coord[3] = T_BR[1] + tex_mid_height; - tex_coord[4] = T_TL[0]; - tex_coord[5] = T_TL[1] + tex_hoff; - tex_coord[6] = T_TR[0]; - tex_coord[7] = T_TR[1] + tex_hoff; - - menu_display_draw(&draw); - - /* center section */ - vert_coord[0] = V_BL[0] + vert_woff; - vert_coord[1] = V_BL[1] - vert_scaled_mid_height; - vert_coord[2] = V_BR[0] + vert_scaled_mid_width; - vert_coord[3] = V_BR[1] - vert_scaled_mid_height; - vert_coord[4] = V_TL[0] + vert_woff; - vert_coord[5] = V_TL[1] - vert_hoff; - vert_coord[6] = V_TR[0] + vert_scaled_mid_width; - vert_coord[7] = V_TR[1] - vert_hoff; - - tex_coord[0] = T_BL[0] + tex_woff; - tex_coord[1] = T_BL[1] + tex_mid_height; - tex_coord[2] = T_BR[0] + tex_mid_width; - tex_coord[3] = T_BR[1] + tex_mid_height; - tex_coord[4] = T_TL[0] + tex_woff; - tex_coord[5] = T_TL[1] + tex_hoff; - tex_coord[6] = T_TR[0] + tex_mid_width; - tex_coord[7] = T_TR[1] + tex_hoff; - - menu_display_draw(&draw); - - /* middle-right section */ - vert_coord[0] = V_BL[0] + vert_woff + vert_scaled_mid_width; - vert_coord[1] = V_BL[1] - vert_scaled_mid_height; - vert_coord[2] = V_BR[0] + vert_woff + vert_scaled_mid_width; - vert_coord[3] = V_BR[1] - vert_scaled_mid_height; - vert_coord[4] = V_TL[0] + vert_woff + vert_scaled_mid_width; - vert_coord[5] = V_TL[1] - vert_hoff; - vert_coord[6] = V_TR[0] + vert_woff + vert_scaled_mid_width; - vert_coord[7] = V_TR[1] - vert_hoff; - - tex_coord[0] = T_BL[0] + tex_woff + tex_mid_width; - tex_coord[1] = T_BL[1] + tex_mid_height; - tex_coord[2] = T_BR[0] + tex_woff + tex_mid_width; - tex_coord[3] = T_BR[1] + tex_mid_height; - tex_coord[4] = T_TL[0] + tex_woff + tex_mid_width; - tex_coord[5] = T_TL[1] + tex_hoff; - tex_coord[6] = T_TR[0] + tex_woff + tex_mid_width; - tex_coord[7] = T_TR[1] + tex_hoff; - - menu_display_draw(&draw); - - /* bottom-left corner */ - vert_coord[0] = V_BL[0]; - vert_coord[1] = V_BL[1] - vert_hoff - vert_scaled_mid_height; - vert_coord[2] = V_BR[0]; - vert_coord[3] = V_BR[1] - vert_hoff - vert_scaled_mid_height; - vert_coord[4] = V_TL[0]; - vert_coord[5] = V_TL[1] - vert_hoff - vert_scaled_mid_height; - vert_coord[6] = V_TR[0]; - vert_coord[7] = V_TR[1] - vert_hoff - vert_scaled_mid_height; - - tex_coord[0] = T_BL[0]; - tex_coord[1] = T_BL[1] + tex_hoff + tex_mid_height; - tex_coord[2] = T_BR[0]; - tex_coord[3] = T_BR[1] + tex_hoff + tex_mid_height; - tex_coord[4] = T_TL[0]; - tex_coord[5] = T_TL[1] + tex_hoff + tex_mid_height; - tex_coord[6] = T_TR[0]; - tex_coord[7] = T_TR[1] + tex_hoff + tex_mid_height; - - menu_display_draw(&draw); - - /* bottom-middle section */ - vert_coord[0] = V_BL[0] + vert_woff; - vert_coord[1] = V_BL[1] - vert_hoff - vert_scaled_mid_height; - vert_coord[2] = V_BR[0] + vert_scaled_mid_width; - vert_coord[3] = V_BR[1] - vert_hoff - vert_scaled_mid_height; - vert_coord[4] = V_TL[0] + vert_woff; - vert_coord[5] = V_TL[1] - vert_scaled_mid_height; - vert_coord[6] = V_TR[0] + vert_scaled_mid_width; - vert_coord[7] = V_TR[1] - vert_scaled_mid_height; - - tex_coord[0] = T_BL[0] + tex_woff; - tex_coord[1] = T_BL[1] + tex_hoff + tex_mid_height; - tex_coord[2] = T_BR[0] + tex_mid_width; - tex_coord[3] = T_BR[1] + tex_hoff + tex_mid_height; - tex_coord[4] = T_TL[0] + tex_woff; - tex_coord[5] = T_TL[1] + tex_mid_height; - tex_coord[6] = T_TR[0] + tex_mid_width; - tex_coord[7] = T_TR[1] + tex_mid_height; - - menu_display_draw(&draw); - - /* bottom-right corner */ - vert_coord[0] = V_BL[0] + vert_woff + vert_scaled_mid_width; - vert_coord[1] = V_BL[1] - vert_hoff - vert_scaled_mid_height; - vert_coord[2] = V_BR[0] + vert_scaled_mid_width + vert_woff; - vert_coord[3] = V_BR[1] - vert_hoff - vert_scaled_mid_height; - vert_coord[4] = V_TL[0] + vert_woff + vert_scaled_mid_width; - vert_coord[5] = V_TL[1] - vert_hoff - vert_scaled_mid_height; - vert_coord[6] = V_TR[0] + vert_scaled_mid_width + vert_woff; - vert_coord[7] = V_TR[1] - vert_hoff - vert_scaled_mid_height; - - tex_coord[0] = T_BL[0] + tex_woff + tex_mid_width; - tex_coord[1] = T_BL[1] + tex_hoff + tex_mid_height; - tex_coord[2] = T_BR[0] + tex_woff + tex_mid_width; - tex_coord[3] = T_BR[1] + tex_hoff + tex_mid_height; - tex_coord[4] = T_TL[0] + tex_woff + tex_mid_width; - tex_coord[5] = T_TL[1] + tex_hoff + tex_mid_height; - tex_coord[6] = T_TR[0] + tex_woff + tex_mid_width; - tex_coord[7] = T_TR[1] + tex_hoff + tex_mid_height; - - menu_display_draw(&draw); - - free(colors); - free(vert_coord); - free(tex_coord); -} - -void menu_display_rotate_z(menu_display_ctx_rotate_draw_t *draw) -{ -#if !defined(VITA) - math_matrix_4x4 matrix_rotated, matrix_scaled; - math_matrix_4x4 *b = NULL; - - if (!draw || !menu_disp || !menu_disp->get_default_mvp) - return; - - b = (math_matrix_4x4*)menu_disp->get_default_mvp(); - - matrix_4x4_rotate_z(matrix_rotated, draw->rotation); - matrix_4x4_multiply(*draw->matrix, matrix_rotated, *b); - - if (!draw->scale_enable) - return; - - matrix_4x4_scale(matrix_scaled, - draw->scale_x, draw->scale_y, draw->scale_z); - matrix_4x4_multiply(*draw->matrix, matrix_scaled, *draw->matrix); -#endif -} - -bool menu_display_get_tex_coords(menu_display_ctx_coord_draw_t *draw) -{ - if (!draw) - return false; - - if (!menu_disp || !menu_disp->get_default_tex_coords) - return false; - - draw->ptr = menu_disp->get_default_tex_coords(); - return true; -} - -void menu_display_handle_thumbnail_upload(void *task_data, - void *user_data, const char *err) -{ - menu_ctx_load_image_t load_image_info; - struct texture_image *img = (struct texture_image*)task_data; - - load_image_info.data = img; - load_image_info.type = MENU_IMAGE_THUMBNAIL; - - menu_driver_load_image(&load_image_info); - - image_texture_free(img); - free(img); - free(user_data); -} - -void menu_display_handle_savestate_thumbnail_upload(void *task_data, - void *user_data, const char *err) -{ - menu_ctx_load_image_t load_image_info; - struct texture_image *img = (struct texture_image*)task_data; - - load_image_info.data = img; - load_image_info.type = MENU_IMAGE_SAVESTATE_THUMBNAIL; - - menu_driver_load_image(&load_image_info); - - image_texture_free(img); - free(img); - free(user_data); -} - -void menu_display_handle_wallpaper_upload(void *task_data, - void *user_data, const char *err) -{ - menu_ctx_load_image_t load_image_info; - struct texture_image *img = (struct texture_image*)task_data; - - load_image_info.data = img; - load_image_info.type = MENU_IMAGE_WALLPAPER; - - menu_driver_load_image(&load_image_info); - image_texture_free(img); - free(img); - free(user_data); -} - -void menu_display_allocate_white_texture(void) -{ - struct texture_image ti; - static const uint8_t white_data[] = { 0xff, 0xff, 0xff, 0xff }; - - ti.width = 1; - ti.height = 1; - ti.pixels = (uint32_t*)&white_data; - - if (menu_display_white_texture) - video_driver_texture_unload(&menu_display_white_texture); - - video_driver_texture_load(&ti, - TEXTURE_FILTER_NEAREST, &menu_display_white_texture); -} - -void menu_display_draw_cursor( - float *color, float cursor_size, uintptr_t texture, - float x, float y, unsigned width, unsigned height) -{ - menu_display_ctx_draw_t draw; - struct video_coords coords; - settings_t *settings = config_get_ptr(); - bool cursor_visible = settings->bools.video_fullscreen || - !menu_display_has_windowed; - - if (!settings->bools.menu_mouse_enable) - return; - if (!cursor_visible) - return; - - coords.vertices = 4; - coords.vertex = NULL; - coords.tex_coord = NULL; - coords.lut_tex_coord = NULL; - coords.color = (const float*)color; - - menu_display_blend_begin(); - - draw.x = x - (cursor_size / 2); - draw.y = (int)height - y - (cursor_size / 2); - draw.width = cursor_size; - draw.height = cursor_size; - draw.coords = &coords; - draw.matrix_data = NULL; - draw.texture = texture; - draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP; - - menu_display_draw(&draw); - menu_display_blend_end(); -} - -static INLINE float menu_display_scalef(float val, - float oldmin, float oldmax, float newmin, float newmax) -{ - return (((val - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin; -} - -static INLINE float menu_display_randf(float min, float max) -{ - return (rand() * ((max - min) / RAND_MAX)) + min; -} - -void menu_display_push_quad( - unsigned width, unsigned height, - const float *colors, int x1, int y1, - int x2, int y2) -{ - float vertex[8]; - video_coords_t coords; - menu_display_ctx_coord_draw_t coord_draw; - video_coord_array_t *ca = menu_display_get_coords_array(); - - vertex[0] = x1 / (float)width; - vertex[1] = y1 / (float)height; - vertex[2] = x2 / (float)width; - vertex[3] = y1 / (float)height; - vertex[4] = x1 / (float)width; - vertex[5] = y2 / (float)height; - vertex[6] = x2 / (float)width; - vertex[7] = y2 / (float)height; - - coord_draw.ptr = NULL; - - menu_display_get_tex_coords(&coord_draw); - - coords.color = colors; - coords.vertex = vertex; - coords.tex_coord = coord_draw.ptr; - coords.lut_tex_coord = coord_draw.ptr; - coords.vertices = 3; - - video_coord_array_append(ca, &coords, 3); - - coords.color += 4; - coords.vertex += 2; - coords.tex_coord += 2; - coords.lut_tex_coord += 2; - - video_coord_array_append(ca, &coords, 3); -} - -void menu_display_snow(int width, int height) -{ - struct display_particle - { - float x, y; - float xspeed, yspeed; - float alpha; - bool alive; - }; - static struct display_particle particles[PARTICLES_COUNT] = {{0}}; - static int timeout = 0; - unsigned i, max_gen = 2; - - for (i = 0; i < PARTICLES_COUNT; ++i) - { - struct display_particle *p = (struct display_particle*)&particles[i]; - - if (p->alive) - { - int16_t mouse_x = menu_input_mouse_state(MENU_MOUSE_X_AXIS); - - p->y += p->yspeed; - p->x += menu_display_scalef(mouse_x, 0, width, -0.3, 0.3); - p->x += p->xspeed; - - p->alive = p->y >= 0 && p->y < height - && p->x >= 0 && p->x < width; - } - else if (max_gen > 0 && timeout <= 0) - { - p->xspeed = menu_display_randf(-0.2, 0.2); - p->yspeed = menu_display_randf(1, 2); - p->y = 0; - p->x = rand() % width; - p->alpha = (float)rand() / (float)RAND_MAX; - p->alive = true; - - max_gen--; - } - } - - if (max_gen == 0) - timeout = 3; - else - timeout--; - - for (i = 0; i < PARTICLES_COUNT; ++i) - { - unsigned j; - float alpha, colors[16]; - struct display_particle *p = &particles[i]; - - if (!p->alive) - continue; - - alpha = menu_display_randf(0, 100) > 90 ? p->alpha/2 : p->alpha; - - for (j = 0; j < 16; j++) - { - colors[j] = 1; - if (j == 3 || j == 7 || j == 11 || j == 15) - colors[j] = alpha; - } - - menu_display_push_quad(width, height, - colors, p->x-2, p->y-2, p->x+2, p->y+2); - - j++; - } -} - -void menu_display_draw_text( - const font_data_t *font, const char *text, - float x, float y, int width, int height, - uint32_t color, enum text_alignment text_align, - float scale, bool shadows_enable, float shadow_offset) -{ - struct font_params params; - - /* Don't draw outside of the screen */ - if (x < -64 || x > width + 64 - || y < -64 || y > height + 64) - return; - - params.x = x / width; - params.y = 1.0f - y / height; - params.scale = scale; - params.drop_mod = 0.0f; - params.drop_x = 0.0f; - params.drop_y = 0.0f; - params.color = color; - params.full_screen = true; - params.text_align = text_align; - - if (shadows_enable) - { - params.drop_x = shadow_offset; - params.drop_y = -shadow_offset; - params.drop_alpha = 0.35f; - } - - video_driver_set_osd_msg(text, ¶ms, (void*)font); -} - -void menu_display_set_alpha(float *color, float alpha_value) -{ - if (!color) - return; - color[3] = color[7] = color[11] = color[15] = alpha_value; -} - -void menu_display_reset_textures_list(const char *texture_path, const char *iconpath, - uintptr_t *item, enum texture_filter_type filter_type) -{ - struct texture_image ti; - char path[PATH_MAX_LENGTH]; - - path[0] = '\0'; - - ti.width = 0; - ti.height = 0; - ti.pixels = NULL; - ti.supports_rgba = video_driver_supports_rgba(); - - if (!string_is_empty(texture_path)) - fill_pathname_join(path, iconpath, texture_path, sizeof(path)); - - if (string_is_empty(path) || !path_file_exists(path)) - return; - - if (!image_texture_load(&ti, path)) - return; - - video_driver_texture_load(&ti, - filter_type, item); - image_texture_free(&ti); -} diff --git a/menu/menu_display.h b/menu/menu_display.h deleted file mode 100644 index 9e89fc165b..0000000000 --- a/menu/menu_display.h +++ /dev/null @@ -1,317 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2014-2017 - Jean-AndrĂ© Santoni - * Copyright (C) 2016-2017 - Brad Parker - * - * 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 . - */ - -#ifndef __MENU_DISPLAY_H__ -#define __MENU_DISPLAY_H__ - -#include -#include - -#include -#include -#include - -#include "../file_path_special.h" -#include "../gfx/font_driver.h" -#include "../gfx/video_driver.h" -#include "../gfx/video_coord_array.h" - -RETRO_BEGIN_DECLS - -enum materialui_color_theme -{ - MATERIALUI_THEME_BLUE = 0, - MATERIALUI_THEME_BLUE_GREY, - MATERIALUI_THEME_DARK_BLUE, - MATERIALUI_THEME_GREEN, - MATERIALUI_THEME_RED, - MATERIALUI_THEME_YELLOW, - MATERIALUI_THEME_NVIDIA_SHIELD, - MATERIALUI_THEME_LAST -}; - -enum xmb_color_theme -{ - XMB_THEME_LEGACY_RED = 0, - XMB_THEME_DARK_PURPLE, - XMB_THEME_MIDNIGHT_BLUE, - XMB_THEME_GOLDEN, - XMB_THEME_ELECTRIC_BLUE, - XMB_THEME_APPLE_GREEN, - XMB_THEME_UNDERSEA, - XMB_THEME_VOLCANIC_RED, - XMB_THEME_DARK, - XMB_THEME_WALLPAPER, - XMB_THEME_LAST -}; - -enum xmb_icon_theme -{ - XMB_ICON_THEME_MONOCHROME = 0, - XMB_ICON_THEME_FLATUI, - XMB_ICON_THEME_RETROACTIVE, - XMB_ICON_THEME_PIXEL, - XMB_ICON_THEME_NEOACTIVE, - XMB_ICON_THEME_SYSTEMATIC, - XMB_ICON_THEME_DOTART, - XMB_ICON_THEME_CUSTOM, - XMB_ICON_THEME_LAST -}; - -enum xmb_shader_pipeline -{ - XMB_SHADER_PIPELINE_WALLPAPER = 0, - XMB_SHADER_PIPELINE_SIMPLE_RIBBON, - XMB_SHADER_PIPELINE_RIBBON, - XMB_SHADER_PIPELINE_SIMPLE_SNOW, - XMB_SHADER_PIPELINE_SNOW, - XMB_SHADER_PIPELINE_BOKEH, - XMB_SHADER_PIPELINE_LAST -}; - -enum menu_display_prim_type -{ - MENU_DISPLAY_PRIM_NONE = 0, - MENU_DISPLAY_PRIM_TRIANGLESTRIP, - MENU_DISPLAY_PRIM_TRIANGLES -}; - -enum menu_display_driver_type -{ - MENU_VIDEO_DRIVER_GENERIC = 0, - MENU_VIDEO_DRIVER_OPENGL, - MENU_VIDEO_DRIVER_VULKAN, - MENU_VIDEO_DRIVER_DIRECT3D, - MENU_VIDEO_DRIVER_VITA2D, - MENU_VIDEO_DRIVER_CTR, - MENU_VIDEO_DRIVER_CACA, - MENU_VIDEO_DRIVER_GDI, - MENU_VIDEO_DRIVER_VGA -}; - -typedef struct menu_display_ctx_clearcolor -{ - float r; - float g; - float b; - float a; -} menu_display_ctx_clearcolor_t; - -typedef struct menu_display_frame_info -{ - bool shadows_enable; -} menu_display_frame_info_t; - -typedef struct menu_display_ctx_draw -{ - float x; - float y; - unsigned width; - unsigned height; - struct video_coords *coords; - void *matrix_data; - uintptr_t texture; - enum menu_display_prim_type prim_type; - float *color; - const float *vertex; - const float *tex_coord; - size_t vertex_count; - struct - { - unsigned id; - const void *backend_data; - size_t backend_data_size; - bool active; - } pipeline; -} menu_display_ctx_draw_t; - -typedef struct menu_display_ctx_rotate_draw -{ - math_matrix_4x4 *matrix; - float rotation; - float scale_x; - float scale_y; - float scale_z; - bool scale_enable; -} menu_display_ctx_rotate_draw_t; - -typedef struct menu_display_ctx_coord_draw -{ - const float *ptr; -} menu_display_ctx_coord_draw_t; - -typedef struct menu_display_ctx_datetime -{ - char *s; - size_t len; - unsigned time_mode; -} menu_display_ctx_datetime_t; - -typedef struct menu_display_ctx_driver -{ - void (*draw)(void *data); - void (*draw_pipeline)(void *data); - void (*viewport)(void *data); - void (*blend_begin)(void); - void (*blend_end)(void); - void (*restore_clear_color)(void); - void (*clear_color)(menu_display_ctx_clearcolor_t *clearcolor); - void *(*get_default_mvp)(void); - const float *(*get_default_vertices)(void); - const float *(*get_default_tex_coords)(void); - bool (*font_init_first)( - void **font_handle, void *video_data, - const char *font_path, float font_size, - bool is_threaded); - enum menu_display_driver_type type; - const char *ident; -} menu_display_ctx_driver_t; - -typedef struct menu_display_ctx_font -{ - const char *path; - float size; -} menu_display_ctx_font_t; - -typedef uintptr_t menu_texture_item; - -enum menu_toggle_reason -{ - MENU_TOGGLE_REASON_NONE = 0, - MENU_TOGGLE_REASON_USER, - MENU_TOGGLE_REASON_MESSAGE -}; - -enum menu_toggle_reason menu_display_toggle_get_reason(void); -void menu_display_toggle_set_reason(enum menu_toggle_reason reason); - -void menu_display_blend_begin(void); -void menu_display_blend_end(void); - -void menu_display_font_free(font_data_t *font); -void menu_display_font_bind_block(font_data_t *font, void *block); -bool menu_display_font_flush_block(unsigned width, unsigned height, font_data_t *font); - -void menu_display_framebuffer_deinit(void); - -void menu_display_deinit(void); -bool menu_display_init(void); - -void menu_display_coords_array_reset(void); -video_coord_array_t *menu_display_get_coords_array(void); -const uint8_t *menu_display_get_font_framebuffer(void); -void menu_display_set_font_framebuffer(const uint8_t *buffer); -bool menu_display_libretro(bool is_idle, bool is_inited, bool is_dummy); - -void menu_display_set_width(unsigned width); -void menu_display_get_fb_size(unsigned *fb_width, unsigned *fb_height, - size_t *fb_pitch); -void menu_display_set_height(unsigned height); -void menu_display_set_header_height(unsigned height); -unsigned menu_display_get_header_height(void); -size_t menu_display_get_framebuffer_pitch(void); -void menu_display_set_framebuffer_pitch(size_t pitch); - -bool menu_display_get_msg_force(void); -void menu_display_set_msg_force(bool state); -bool menu_display_get_font_data_init(void); -void menu_display_set_font_data_init(bool state); -bool menu_display_get_update_pending(void); -void menu_display_set_viewport(unsigned width, unsigned height); -void menu_display_unset_viewport(unsigned width, unsigned height); -bool menu_display_get_framebuffer_dirty_flag(void); -void menu_display_set_framebuffer_dirty_flag(void); -void menu_display_unset_framebuffer_dirty_flag(void); -float menu_display_get_dpi(void); -bool menu_display_init_first_driver(bool video_is_threaded); -bool menu_display_restore_clear_color(void); -void menu_display_clear_color(menu_display_ctx_clearcolor_t *color); -void menu_display_draw(menu_display_ctx_draw_t *draw); - -void menu_display_draw_pipeline(menu_display_ctx_draw_t *draw); -void menu_display_draw_bg( - menu_display_ctx_draw_t *draw, - video_frame_info_t *video_info, - bool add_opacity); -void menu_display_draw_gradient( - menu_display_ctx_draw_t *draw, - video_frame_info_t *video_info); -void menu_display_draw_quad(int x, int y, unsigned w, unsigned h, - unsigned width, unsigned height, - float *color); -void menu_display_draw_texture(int x, int y, unsigned w, unsigned h, - unsigned width, unsigned height, - float *color, uintptr_t texture); -void menu_display_draw_texture_slice(int x, int y, unsigned w, unsigned h, - unsigned new_w, unsigned new_h, unsigned width, unsigned height, - float *color, unsigned offset, float scale_factor, uintptr_t texture); -void menu_display_rotate_z(menu_display_ctx_rotate_draw_t *draw); -bool menu_display_get_tex_coords(menu_display_ctx_coord_draw_t *draw); - -void menu_display_timedate(menu_display_ctx_datetime_t *datetime); - -void menu_display_handle_wallpaper_upload(void *task_data, - void *user_data, const char *err); - -void menu_display_handle_thumbnail_upload(void *task_data, - void *user_data, const char *err); - -void menu_display_handle_savestate_thumbnail_upload(void *task_data, - void *user_data, const char *err); - -void menu_display_push_quad( - unsigned width, unsigned height, - const float *colors, int x1, int y1, - int x2, int y2); - -void menu_display_snow(int width, int height); - -void menu_display_allocate_white_texture(void); - -void menu_display_draw_cursor( - float *color, float cursor_size, uintptr_t texture, - float x, float y, unsigned width, unsigned height); - -void menu_display_draw_text( - const font_data_t *font, const char *text, - float x, float y, int width, int height, - uint32_t color, enum text_alignment text_align, - float scale_factor, bool shadows_enable, float shadow_offset); - -void menu_display_set_alpha(float *color, float alpha_value); - -font_data_t *menu_display_font(enum application_special_type type, float font_size, - bool video_is_threaded); - -void menu_display_reset_textures_list(const char *texture_path, const char *iconpath, - uintptr_t *item, enum texture_filter_type filter_type); - -extern uintptr_t menu_display_white_texture; - -extern menu_display_ctx_driver_t menu_display_ctx_gl; -extern menu_display_ctx_driver_t menu_display_ctx_vulkan; -extern menu_display_ctx_driver_t menu_display_ctx_d3d; -extern menu_display_ctx_driver_t menu_display_ctx_vita2d; -extern menu_display_ctx_driver_t menu_display_ctx_ctr; -extern menu_display_ctx_driver_t menu_display_ctx_caca; -extern menu_display_ctx_driver_t menu_display_ctx_gdi; -extern menu_display_ctx_driver_t menu_display_ctx_vga; -extern menu_display_ctx_driver_t menu_display_ctx_null; - -RETRO_END_DECLS - -#endif diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 6ff901d880..7bef8e796c 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -16,8 +16,12 @@ */ #include +#include #include +#include +#include +#include #include #include @@ -25,16 +29,23 @@ #include "../config.h" #endif +#ifdef HAVE_THREADS +#include "../gfx/video_thread_wrapper.h" +#endif + +#include "../gfx/video_driver.h" + #include "menu_animation.h" #include "menu_driver.h" #include "menu_cbs.h" -#include "menu_display.h" #include "menu_event.h" #include "widgets/menu_dialog.h" #include "widgets/menu_list.h" #include "menu_shader.h" +#include "../config.def.h" #include "../content.h" +#include "../core.h" #include "../configuration.h" #include "../dynamic.h" #include "../driver.h" @@ -46,7 +57,9 @@ #include "../ui/ui_companion_driver.h" #include "../verbosity.h" -#define SCROLL_INDEX_SIZE (2 * (26 + 2) + 1) +#define SCROLL_INDEX_SIZE (2 * (26 + 2) + 1) + +#define PARTICLES_COUNT 100 static const menu_ctx_driver_t *menu_ctx_drivers[] = { #if defined(HAVE_XUI) @@ -71,6 +84,55 @@ static const menu_ctx_driver_t *menu_ctx_drivers[] = { NULL }; +static menu_display_ctx_driver_t *menu_display_ctx_drivers[] = { +#ifdef HAVE_D3D + &menu_display_ctx_d3d, +#endif +#ifdef HAVE_OPENGL + &menu_display_ctx_gl, +#endif +#ifdef HAVE_VULKAN + &menu_display_ctx_vulkan, +#endif +#ifdef HAVE_VITA2D + &menu_display_ctx_vita2d, +#endif +#ifdef _3DS + &menu_display_ctx_ctr, +#endif +#ifdef HAVE_CACA + &menu_display_ctx_caca, +#endif +#if defined(_WIN32) && !defined(_XBOX) + &menu_display_ctx_gdi, +#endif +#ifdef DJGPP + &menu_display_ctx_vga, +#endif + &menu_display_ctx_null, + NULL, +}; + + +uintptr_t menu_display_white_texture; + +static video_coord_array_t menu_disp_ca; + +static enum +menu_toggle_reason menu_display_toggle_reason = MENU_TOGGLE_REASON_NONE; + +static unsigned menu_display_framebuf_width = 0; +static unsigned menu_display_framebuf_height = 0; +static size_t menu_display_framebuf_pitch = 0; +static unsigned menu_display_header_height = 0; +static bool menu_display_has_windowed = false; +static bool menu_display_msg_force = false; +static bool menu_display_font_alloc_framebuf = false; +static bool menu_display_framebuf_dirty = false; +static const uint8_t *menu_display_font_framebuf = NULL; +static msg_queue_t *menu_display_msg_queue = NULL; +static menu_display_ctx_driver_t *menu_disp = NULL; + static struct retro_system_info menu_driver_system; static bool menu_driver_pending_quick_menu = false; static bool menu_driver_prevent_populate = false; @@ -93,6 +155,1140 @@ static unsigned scroll_index_size = 0; static unsigned scroll_acceleration = 0; static size_t menu_driver_selection_ptr = 0; +enum menu_toggle_reason menu_display_toggle_get_reason(void) +{ + return menu_display_toggle_reason; +} + +void menu_display_toggle_set_reason(enum menu_toggle_reason reason) +{ + menu_display_toggle_reason = reason; +} + +static const char *menu_video_get_ident(bool video_is_threaded) +{ +#ifdef HAVE_THREADS + if (video_is_threaded) + return video_thread_get_ident(); +#endif + + return video_driver_get_ident(); +} + +static bool menu_display_check_compatibility( + enum menu_display_driver_type type, + bool video_is_threaded) +{ + const char *video_driver = menu_video_get_ident(video_is_threaded); + + switch (type) + { + case MENU_VIDEO_DRIVER_GENERIC: + return true; + case MENU_VIDEO_DRIVER_OPENGL: + if (string_is_equal_fast(video_driver, "gl", 2)) + return true; + break; + case MENU_VIDEO_DRIVER_VULKAN: + if (string_is_equal_fast(video_driver, "vulkan", 6)) + return true; + break; + case MENU_VIDEO_DRIVER_DIRECT3D: + if (string_is_equal_fast(video_driver, "d3d", 3)) + return true; + break; + case MENU_VIDEO_DRIVER_VITA2D: + if (string_is_equal_fast(video_driver, "vita2d", 6)) + return true; + break; + case MENU_VIDEO_DRIVER_CTR: + if (string_is_equal_fast(video_driver, "ctr", 3)) + return true; + break; + case MENU_VIDEO_DRIVER_CACA: + if (string_is_equal_fast(video_driver, "caca", 4)) + return true; + break; + case MENU_VIDEO_DRIVER_GDI: + if (string_is_equal_fast(video_driver, "gdi", 3)) + return true; + break; + case MENU_VIDEO_DRIVER_VGA: + if (string_is_equal_fast(video_driver, "vga", 3)) + return true; + break; + } + + return false; +} + +void menu_display_timedate(menu_display_ctx_datetime_t *datetime) +{ + time_t time_; + + if (!datetime) + return; + + time(&time_); + + switch (datetime->time_mode) + { + case 0: /* Date and time */ + strftime(datetime->s, datetime->len, + "%Y-%m-%d %H:%M:%S", localtime(&time_)); + break; + case 1: /* Date */ + strftime(datetime->s, datetime->len, + "%Y-%m-%d", localtime(&time_)); + break; + case 2: /* Time */ + strftime(datetime->s, datetime->len, + "%H:%M:%S", localtime(&time_)); + break; + case 3: /* Time (hours-minutes) */ + strftime(datetime->s, datetime->len, + "%H:%M", localtime(&time_)); + break; + case 4: /* Date and time, without year and seconds */ + strftime(datetime->s, datetime->len, + "%d/%m %H:%M", localtime(&time_)); + break; + } +} + +void menu_display_blend_begin(void) +{ + if (!menu_disp || !menu_disp->blend_begin) + return; + menu_disp->blend_begin(); +} + +void menu_display_blend_end(void) +{ + if (!menu_disp || !menu_disp->blend_end) + return; + menu_disp->blend_end(); +} + +void menu_display_font_free(font_data_t *font) +{ + font_driver_free(font); +} + +static font_data_t *menu_display_font_main_init(menu_display_ctx_font_t *font, + bool is_threaded) +{ + font_data_t *font_data = NULL; + + if (!font || !menu_disp) + return NULL; + + if (!menu_disp->font_init_first((void**)&font_data, + video_driver_get_ptr(false), + font->path, font->size, is_threaded)) + return NULL; + + return font_data; +} + +font_data_t *menu_display_font(enum application_special_type type, float font_size, + bool is_threaded) +{ + menu_display_ctx_font_t font_info; + char fontpath[PATH_MAX_LENGTH]; + + fontpath[0] = '\0'; + + fill_pathname_application_special(fontpath, sizeof(fontpath), type); + + font_info.path = fontpath; + font_info.size = font_size; + + return menu_display_font_main_init(&font_info, is_threaded); +} + +void menu_display_font_bind_block(font_data_t *font, void *block) +{ + font_driver_bind_block(font, block); +} + +bool menu_display_font_flush_block(unsigned width, unsigned height, + font_data_t *font) +{ + font_driver_flush(width, height, font); + font_driver_bind_block(font, NULL); + return true; +} + +void menu_display_framebuffer_deinit(void) +{ + menu_display_framebuf_width = 0; + menu_display_framebuf_height = 0; + menu_display_framebuf_pitch = 0; +} + +void menu_display_deinit(void) +{ + if (menu_display_msg_queue) + msg_queue_free(menu_display_msg_queue); + + video_coord_array_free(&menu_disp_ca); + menu_display_msg_queue = NULL; + menu_display_msg_force = false; + menu_display_header_height = 0; + menu_disp = NULL; + menu_display_has_windowed = false; + + menu_animation_ctl(MENU_ANIMATION_CTL_DEINIT, NULL); + menu_display_framebuffer_deinit(); +} + +bool menu_display_init(void) +{ + menu_display_msg_queue = msg_queue_new(8); + menu_disp_ca.allocated = 0; + + menu_display_has_windowed = video_driver_has_windowed(); + return true; +} + +void menu_display_coords_array_reset(void) +{ + menu_disp_ca.coords.vertices = 0; +} + +video_coord_array_t *menu_display_get_coords_array(void) +{ + return &menu_disp_ca; +} + +const uint8_t *menu_display_get_font_framebuffer(void) +{ + return menu_display_font_framebuf; +} + +void menu_display_set_font_framebuffer(const uint8_t *buffer) +{ + menu_display_font_framebuf = buffer; +} + +static bool menu_display_libretro_running( + bool rarch_is_inited, + bool rarch_is_dummy_core) +{ + settings_t *settings = config_get_ptr(); + if (!settings->bools.menu_pause_libretro) + { + if (rarch_is_inited && !rarch_is_dummy_core) + return true; + } + return false; +} + +bool menu_display_libretro(bool is_idle, bool rarch_is_inited, bool rarch_is_dummy_core) +{ + video_driver_set_texture_enable(true, false); + + if (menu_display_libretro_running(rarch_is_inited, rarch_is_dummy_core)) + { + if (!input_driver_is_libretro_input_blocked()) + input_driver_set_libretro_input_blocked(); + + core_run(); + + input_driver_unset_libretro_input_blocked(); + return true; + } + + if (is_idle) + return true; /* Maybe return false here for indication of idleness? */ + return video_driver_cached_frame(); +} + +void menu_display_get_fb_size(unsigned *fb_width, + unsigned *fb_height, size_t *fb_pitch) +{ + *fb_width = menu_display_framebuf_width; + *fb_height = menu_display_framebuf_height; + *fb_pitch = menu_display_framebuf_pitch; +} + +void menu_display_set_width(unsigned width) +{ + menu_display_framebuf_width = width; +} + +void menu_display_set_height(unsigned height) +{ + menu_display_framebuf_height = height; +} + +void menu_display_set_header_height(unsigned height) +{ + menu_display_header_height = height; +} + +unsigned menu_display_get_header_height(void) +{ + return menu_display_header_height; +} + +size_t menu_display_get_framebuffer_pitch(void) +{ + return menu_display_framebuf_pitch; +} + +void menu_display_set_framebuffer_pitch(size_t pitch) +{ + menu_display_framebuf_pitch = pitch; +} + +bool menu_display_get_msg_force(void) +{ + return menu_display_msg_force; +} + +void menu_display_set_msg_force(bool state) +{ + menu_display_msg_force = state; +} + +bool menu_display_get_font_data_init(void) +{ + return menu_display_font_alloc_framebuf; +} + +void menu_display_set_font_data_init(bool state) +{ + menu_display_font_alloc_framebuf = state; +} + +bool menu_display_get_update_pending(void) +{ + if (menu_animation_is_active()) + return true; + if (menu_display_get_framebuffer_dirty_flag()) + return true; + return false; +} + +void menu_display_set_viewport(unsigned width, unsigned height) +{ + video_driver_set_viewport(width, height, true, false); +} + +void menu_display_unset_viewport(unsigned width, unsigned height) +{ + video_driver_set_viewport(width, height, false, true); +} + +bool menu_display_get_framebuffer_dirty_flag(void) +{ + return menu_display_framebuf_dirty; +} + +void menu_display_set_framebuffer_dirty_flag(void) +{ + menu_display_framebuf_dirty = true; +} + +void menu_display_unset_framebuffer_dirty_flag(void) +{ + menu_display_framebuf_dirty = false; +} + +float menu_display_get_dpi(void) +{ + gfx_ctx_metrics_t metrics; + settings_t *settings = config_get_ptr(); + float dpi = menu_dpi_override_value; + + if (!settings) + return true; + + metrics.type = DISPLAY_METRIC_DPI; + metrics.value = &dpi; + + if (settings->bools.menu_dpi_override_enable) + return settings->uints.menu_dpi_override_value; + else if (!video_context_driver_get_metrics(&metrics) || !dpi) + return menu_dpi_override_value; + + return dpi; +} + +bool menu_display_init_first_driver(bool video_is_threaded) +{ + unsigned i; + + for (i = 0; menu_display_ctx_drivers[i]; i++) + { + if (!menu_display_check_compatibility( + menu_display_ctx_drivers[i]->type, + video_is_threaded)) + continue; + + RARCH_LOG("[Menu]: Found menu display driver: \"%s\".\n", + menu_display_ctx_drivers[i]->ident); + menu_disp = menu_display_ctx_drivers[i]; + return true; + } + return false; +} + +bool menu_display_restore_clear_color(void) +{ + if (!menu_disp || !menu_disp->restore_clear_color) + return false; + menu_disp->restore_clear_color(); + return true; +} + +void menu_display_clear_color(menu_display_ctx_clearcolor_t *color) +{ + if (!menu_disp || !menu_disp->clear_color) + return; + menu_disp->clear_color(color); +} + +void menu_display_draw(menu_display_ctx_draw_t *draw) +{ + if (!menu_disp || !draw || !menu_disp->draw) + return; + + /* TODO - edge case */ + if (draw->height <= 0) + draw->height = 1; + + menu_disp->draw(draw); +} + +void menu_display_draw_pipeline(menu_display_ctx_draw_t *draw) +{ + if (!menu_disp || !draw || !menu_disp->draw_pipeline) + return; + menu_disp->draw_pipeline(draw); +} + +void menu_display_draw_bg(menu_display_ctx_draw_t *draw, + video_frame_info_t *video_info, bool add_opacity_to_wallpaper) +{ + static struct video_coords coords; + const float *new_vertex = NULL; + const float *new_tex_coord = NULL; + if (!menu_disp || !draw) + return; + + new_vertex = draw->vertex; + new_tex_coord = draw->tex_coord; + + if (!new_vertex) + new_vertex = menu_disp->get_default_vertices(); + if (!new_tex_coord) + new_tex_coord = menu_disp->get_default_tex_coords(); + + coords.vertices = (unsigned)draw->vertex_count; + coords.vertex = new_vertex; + coords.tex_coord = new_tex_coord; + coords.lut_tex_coord = new_tex_coord; + coords.color = (const float*)draw->color; + + draw->coords = &coords; + + if (!video_info->libretro_running && !draw->pipeline.active) + add_opacity_to_wallpaper = true; + + if (add_opacity_to_wallpaper) + menu_display_set_alpha(draw->color, video_info->menu_wallpaper_opacity); + + if (!draw->texture) + draw->texture = menu_display_white_texture; + + draw->matrix_data = (math_matrix_4x4*)menu_disp->get_default_mvp(); +} + +void menu_display_draw_gradient(menu_display_ctx_draw_t *draw, + video_frame_info_t *video_info) +{ + draw->texture = 0; + draw->x = 0; + draw->y = 0; + + menu_display_draw_bg(draw, video_info, false); + menu_display_draw(draw); +} + +void menu_display_draw_quad( + int x, int y, unsigned w, unsigned h, + unsigned width, unsigned height, + float *color) +{ + menu_display_ctx_draw_t draw; + struct video_coords coords; + + coords.vertices = 4; + coords.vertex = NULL; + coords.tex_coord = NULL; + coords.lut_tex_coord = NULL; + coords.color = color; + + menu_display_blend_begin(); + + draw.x = x; + draw.y = (int)height - y - (int)h; + draw.width = w; + draw.height = h; + draw.coords = &coords; + draw.matrix_data = NULL; + draw.texture = menu_display_white_texture; + draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP; + draw.pipeline.id = 0; + + menu_display_draw(&draw); + menu_display_blend_end(); +} + +void menu_display_draw_texture( + int x, int y, unsigned w, unsigned h, + unsigned width, unsigned height, + float *color, uintptr_t texture) +{ + menu_display_ctx_draw_t draw; + menu_display_ctx_rotate_draw_t rotate_draw; + struct video_coords coords; + math_matrix_4x4 mymat; + rotate_draw.matrix = &mymat; + rotate_draw.rotation = 0.0; + rotate_draw.scale_x = 1.0; + rotate_draw.scale_y = 1.0; + rotate_draw.scale_z = 1; + rotate_draw.scale_enable = true; + coords.vertices = 4; + coords.vertex = NULL; + coords.tex_coord = NULL; + coords.lut_tex_coord = NULL; + draw.width = w; + draw.height = h; + draw.coords = &coords; + draw.matrix_data = &mymat; + draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP; + draw.pipeline.id = 0; + coords.color = (const float*)color; + + menu_display_rotate_z(&rotate_draw); + + draw.texture = texture; + draw.x = x; + draw.y = height - y; + menu_display_draw(&draw); +} + +/* Draw the texture split into 9 sections, without scaling the corners. + * The middle sections will only scale in the X axis, and the side + * sections will only scale in the Y axis. */ +void menu_display_draw_texture_slice( + int x, int y, unsigned w, unsigned h, + unsigned new_w, unsigned new_h, + unsigned width, unsigned height, + float *color, unsigned offset, float scale_factor, uintptr_t texture) +{ + menu_display_ctx_draw_t draw; + menu_display_ctx_rotate_draw_t rotate_draw; + struct video_coords coords; + math_matrix_4x4 mymat; + unsigned i; + float V_BL[2], V_BR[2], V_TL[2], V_TR[2], T_BL[2], T_BR[2], T_TL[2], T_TR[2]; + + /* need space for the coordinates of two triangles in a strip, so 8 vertices */ + float *tex_coord = (float*)malloc(8 * sizeof(float)); + float *vert_coord = (float*)malloc(8 * sizeof(float)); + float *colors = (float*)malloc(16 * sizeof(float)); + + /* normalized width/height of the amount to offset from the corners, + * for both the vertex and texture coordinates */ + float vert_woff = (offset * scale_factor) / (float)width; + float vert_hoff = (offset * scale_factor) / (float)height; + float tex_woff = offset / (float)w; + float tex_hoff = offset / (float)h; + + /* the width/height of the middle sections of both the scaled and original image */ + float vert_scaled_mid_width = (new_w - (offset * scale_factor * 2)) / (float)width; + float vert_scaled_mid_height = (new_h - (offset * scale_factor * 2)) / (float)height; + float tex_mid_width = (w - (offset * 2)) / (float)w; + float tex_mid_height = (h - (offset * 2)) / (float)h; + + /* normalized coordinates for the start position of the image */ + float norm_x = x / (float)width; + float norm_y = (height - y) / (float)height; + + /* the four vertices of the top-left corner of the image, + * used as a starting point for all the other sections */ + V_BL[0] = norm_x; + V_BL[1] = norm_y; + V_BR[0] = norm_x + vert_woff; + V_BR[1] = norm_y; + V_TL[0] = norm_x; + V_TL[1] = norm_y + vert_hoff; + V_TR[0] = norm_x + vert_woff; + V_TR[1] = norm_y + vert_hoff; + T_BL[0] = 0.0f; + T_BL[1] = tex_hoff; + T_BR[0] = tex_woff; + T_BR[1] = tex_hoff; + T_TL[0] = 0.0f; + T_TL[1] = 0.0f; + T_TR[0] = tex_woff; + T_TR[1] = 0.0f; + + for (i = 0; i < (16 * sizeof(float)) / sizeof(colors[0]); i++) + colors[i] = 1.0f; + + rotate_draw.matrix = &mymat; + rotate_draw.rotation = 0.0; + rotate_draw.scale_x = 1.0; + rotate_draw.scale_y = 1.0; + rotate_draw.scale_z = 1; + rotate_draw.scale_enable = true; + coords.vertices = 4; + coords.vertex = vert_coord; + coords.tex_coord = tex_coord; + coords.lut_tex_coord = NULL; + draw.width = width; + draw.height = height; + draw.coords = &coords; + draw.matrix_data = &mymat; + draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP; + draw.pipeline.id = 0; + coords.color = (const float*)colors; + + menu_display_rotate_z(&rotate_draw); + + draw.texture = texture; + draw.x = 0; + draw.y = 0; + + /* vertex coords are specfied bottom-up in this order: BL BR TL TR */ + /* texture coords are specfied top-down in this order: BL BR TL TR */ + + /* If someone wants to change this to not draw several times, the + * coordinates will need to be modified because of the triangle strip usage. */ + + /* top-left corner */ + vert_coord[0] = V_BL[0]; + vert_coord[1] = V_BL[1]; + vert_coord[2] = V_BR[0]; + vert_coord[3] = V_BR[1]; + vert_coord[4] = V_TL[0]; + vert_coord[5] = V_TL[1]; + vert_coord[6] = V_TR[0]; + vert_coord[7] = V_TR[1]; + + tex_coord[0] = T_BL[0]; + tex_coord[1] = T_BL[1]; + tex_coord[2] = T_BR[0]; + tex_coord[3] = T_BR[1]; + tex_coord[4] = T_TL[0]; + tex_coord[5] = T_TL[1]; + tex_coord[6] = T_TR[0]; + tex_coord[7] = T_TR[1]; + + menu_display_draw(&draw); + + /* top-middle section */ + vert_coord[0] = V_BL[0] + vert_woff; + vert_coord[1] = V_BL[1]; + vert_coord[2] = V_BR[0] + vert_scaled_mid_width; + vert_coord[3] = V_BR[1]; + vert_coord[4] = V_TL[0] + vert_woff; + vert_coord[5] = V_TL[1]; + vert_coord[6] = V_TR[0] + vert_scaled_mid_width; + vert_coord[7] = V_TR[1]; + + tex_coord[0] = T_BL[0] + tex_woff; + tex_coord[1] = T_BL[1]; + tex_coord[2] = T_BR[0] + tex_mid_width; + tex_coord[3] = T_BR[1]; + tex_coord[4] = T_TL[0] + tex_woff; + tex_coord[5] = T_TL[1]; + tex_coord[6] = T_TR[0] + tex_mid_width; + tex_coord[7] = T_TR[1]; + + menu_display_draw(&draw); + + /* top-right corner */ + vert_coord[0] = V_BL[0] + vert_woff + vert_scaled_mid_width; + vert_coord[1] = V_BL[1]; + vert_coord[2] = V_BR[0] + vert_scaled_mid_width + vert_woff; + vert_coord[3] = V_BR[1]; + vert_coord[4] = V_TL[0] + vert_woff + vert_scaled_mid_width; + vert_coord[5] = V_TL[1]; + vert_coord[6] = V_TR[0] + vert_scaled_mid_width + vert_woff; + vert_coord[7] = V_TR[1]; + + tex_coord[0] = T_BL[0] + tex_woff + tex_mid_width; + tex_coord[1] = T_BL[1]; + tex_coord[2] = T_BR[0] + tex_mid_width + tex_woff; + tex_coord[3] = T_BR[1]; + tex_coord[4] = T_TL[0] + tex_woff + tex_mid_width; + tex_coord[5] = T_TL[1]; + tex_coord[6] = T_TR[0] + tex_mid_width + tex_woff; + tex_coord[7] = T_TR[1]; + + menu_display_draw(&draw); + + /* middle-left section */ + vert_coord[0] = V_BL[0]; + vert_coord[1] = V_BL[1] - vert_scaled_mid_height; + vert_coord[2] = V_BR[0]; + vert_coord[3] = V_BR[1] - vert_scaled_mid_height; + vert_coord[4] = V_TL[0]; + vert_coord[5] = V_TL[1] - vert_hoff; + vert_coord[6] = V_TR[0]; + vert_coord[7] = V_TR[1] - vert_hoff; + + tex_coord[0] = T_BL[0]; + tex_coord[1] = T_BL[1] + tex_mid_height; + tex_coord[2] = T_BR[0]; + tex_coord[3] = T_BR[1] + tex_mid_height; + tex_coord[4] = T_TL[0]; + tex_coord[5] = T_TL[1] + tex_hoff; + tex_coord[6] = T_TR[0]; + tex_coord[7] = T_TR[1] + tex_hoff; + + menu_display_draw(&draw); + + /* center section */ + vert_coord[0] = V_BL[0] + vert_woff; + vert_coord[1] = V_BL[1] - vert_scaled_mid_height; + vert_coord[2] = V_BR[0] + vert_scaled_mid_width; + vert_coord[3] = V_BR[1] - vert_scaled_mid_height; + vert_coord[4] = V_TL[0] + vert_woff; + vert_coord[5] = V_TL[1] - vert_hoff; + vert_coord[6] = V_TR[0] + vert_scaled_mid_width; + vert_coord[7] = V_TR[1] - vert_hoff; + + tex_coord[0] = T_BL[0] + tex_woff; + tex_coord[1] = T_BL[1] + tex_mid_height; + tex_coord[2] = T_BR[0] + tex_mid_width; + tex_coord[3] = T_BR[1] + tex_mid_height; + tex_coord[4] = T_TL[0] + tex_woff; + tex_coord[5] = T_TL[1] + tex_hoff; + tex_coord[6] = T_TR[0] + tex_mid_width; + tex_coord[7] = T_TR[1] + tex_hoff; + + menu_display_draw(&draw); + + /* middle-right section */ + vert_coord[0] = V_BL[0] + vert_woff + vert_scaled_mid_width; + vert_coord[1] = V_BL[1] - vert_scaled_mid_height; + vert_coord[2] = V_BR[0] + vert_woff + vert_scaled_mid_width; + vert_coord[3] = V_BR[1] - vert_scaled_mid_height; + vert_coord[4] = V_TL[0] + vert_woff + vert_scaled_mid_width; + vert_coord[5] = V_TL[1] - vert_hoff; + vert_coord[6] = V_TR[0] + vert_woff + vert_scaled_mid_width; + vert_coord[7] = V_TR[1] - vert_hoff; + + tex_coord[0] = T_BL[0] + tex_woff + tex_mid_width; + tex_coord[1] = T_BL[1] + tex_mid_height; + tex_coord[2] = T_BR[0] + tex_woff + tex_mid_width; + tex_coord[3] = T_BR[1] + tex_mid_height; + tex_coord[4] = T_TL[0] + tex_woff + tex_mid_width; + tex_coord[5] = T_TL[1] + tex_hoff; + tex_coord[6] = T_TR[0] + tex_woff + tex_mid_width; + tex_coord[7] = T_TR[1] + tex_hoff; + + menu_display_draw(&draw); + + /* bottom-left corner */ + vert_coord[0] = V_BL[0]; + vert_coord[1] = V_BL[1] - vert_hoff - vert_scaled_mid_height; + vert_coord[2] = V_BR[0]; + vert_coord[3] = V_BR[1] - vert_hoff - vert_scaled_mid_height; + vert_coord[4] = V_TL[0]; + vert_coord[5] = V_TL[1] - vert_hoff - vert_scaled_mid_height; + vert_coord[6] = V_TR[0]; + vert_coord[7] = V_TR[1] - vert_hoff - vert_scaled_mid_height; + + tex_coord[0] = T_BL[0]; + tex_coord[1] = T_BL[1] + tex_hoff + tex_mid_height; + tex_coord[2] = T_BR[0]; + tex_coord[3] = T_BR[1] + tex_hoff + tex_mid_height; + tex_coord[4] = T_TL[0]; + tex_coord[5] = T_TL[1] + tex_hoff + tex_mid_height; + tex_coord[6] = T_TR[0]; + tex_coord[7] = T_TR[1] + tex_hoff + tex_mid_height; + + menu_display_draw(&draw); + + /* bottom-middle section */ + vert_coord[0] = V_BL[0] + vert_woff; + vert_coord[1] = V_BL[1] - vert_hoff - vert_scaled_mid_height; + vert_coord[2] = V_BR[0] + vert_scaled_mid_width; + vert_coord[3] = V_BR[1] - vert_hoff - vert_scaled_mid_height; + vert_coord[4] = V_TL[0] + vert_woff; + vert_coord[5] = V_TL[1] - vert_scaled_mid_height; + vert_coord[6] = V_TR[0] + vert_scaled_mid_width; + vert_coord[7] = V_TR[1] - vert_scaled_mid_height; + + tex_coord[0] = T_BL[0] + tex_woff; + tex_coord[1] = T_BL[1] + tex_hoff + tex_mid_height; + tex_coord[2] = T_BR[0] + tex_mid_width; + tex_coord[3] = T_BR[1] + tex_hoff + tex_mid_height; + tex_coord[4] = T_TL[0] + tex_woff; + tex_coord[5] = T_TL[1] + tex_mid_height; + tex_coord[6] = T_TR[0] + tex_mid_width; + tex_coord[7] = T_TR[1] + tex_mid_height; + + menu_display_draw(&draw); + + /* bottom-right corner */ + vert_coord[0] = V_BL[0] + vert_woff + vert_scaled_mid_width; + vert_coord[1] = V_BL[1] - vert_hoff - vert_scaled_mid_height; + vert_coord[2] = V_BR[0] + vert_scaled_mid_width + vert_woff; + vert_coord[3] = V_BR[1] - vert_hoff - vert_scaled_mid_height; + vert_coord[4] = V_TL[0] + vert_woff + vert_scaled_mid_width; + vert_coord[5] = V_TL[1] - vert_hoff - vert_scaled_mid_height; + vert_coord[6] = V_TR[0] + vert_scaled_mid_width + vert_woff; + vert_coord[7] = V_TR[1] - vert_hoff - vert_scaled_mid_height; + + tex_coord[0] = T_BL[0] + tex_woff + tex_mid_width; + tex_coord[1] = T_BL[1] + tex_hoff + tex_mid_height; + tex_coord[2] = T_BR[0] + tex_woff + tex_mid_width; + tex_coord[3] = T_BR[1] + tex_hoff + tex_mid_height; + tex_coord[4] = T_TL[0] + tex_woff + tex_mid_width; + tex_coord[5] = T_TL[1] + tex_hoff + tex_mid_height; + tex_coord[6] = T_TR[0] + tex_woff + tex_mid_width; + tex_coord[7] = T_TR[1] + tex_hoff + tex_mid_height; + + menu_display_draw(&draw); + + free(colors); + free(vert_coord); + free(tex_coord); +} + +void menu_display_rotate_z(menu_display_ctx_rotate_draw_t *draw) +{ +#if !defined(VITA) + math_matrix_4x4 matrix_rotated, matrix_scaled; + math_matrix_4x4 *b = NULL; + + if (!draw || !menu_disp || !menu_disp->get_default_mvp) + return; + + b = (math_matrix_4x4*)menu_disp->get_default_mvp(); + + matrix_4x4_rotate_z(matrix_rotated, draw->rotation); + matrix_4x4_multiply(*draw->matrix, matrix_rotated, *b); + + if (!draw->scale_enable) + return; + + matrix_4x4_scale(matrix_scaled, + draw->scale_x, draw->scale_y, draw->scale_z); + matrix_4x4_multiply(*draw->matrix, matrix_scaled, *draw->matrix); +#endif +} + +bool menu_display_get_tex_coords(menu_display_ctx_coord_draw_t *draw) +{ + if (!draw) + return false; + + if (!menu_disp || !menu_disp->get_default_tex_coords) + return false; + + draw->ptr = menu_disp->get_default_tex_coords(); + return true; +} + +void menu_display_handle_thumbnail_upload(void *task_data, + void *user_data, const char *err) +{ + menu_ctx_load_image_t load_image_info; + struct texture_image *img = (struct texture_image*)task_data; + + load_image_info.data = img; + load_image_info.type = MENU_IMAGE_THUMBNAIL; + + menu_driver_load_image(&load_image_info); + + image_texture_free(img); + free(img); + free(user_data); +} + +void menu_display_handle_savestate_thumbnail_upload(void *task_data, + void *user_data, const char *err) +{ + menu_ctx_load_image_t load_image_info; + struct texture_image *img = (struct texture_image*)task_data; + + load_image_info.data = img; + load_image_info.type = MENU_IMAGE_SAVESTATE_THUMBNAIL; + + menu_driver_load_image(&load_image_info); + + image_texture_free(img); + free(img); + free(user_data); +} + +void menu_display_handle_wallpaper_upload(void *task_data, + void *user_data, const char *err) +{ + menu_ctx_load_image_t load_image_info; + struct texture_image *img = (struct texture_image*)task_data; + + load_image_info.data = img; + load_image_info.type = MENU_IMAGE_WALLPAPER; + + menu_driver_load_image(&load_image_info); + image_texture_free(img); + free(img); + free(user_data); +} + +void menu_display_allocate_white_texture(void) +{ + struct texture_image ti; + static const uint8_t white_data[] = { 0xff, 0xff, 0xff, 0xff }; + + ti.width = 1; + ti.height = 1; + ti.pixels = (uint32_t*)&white_data; + + if (menu_display_white_texture) + video_driver_texture_unload(&menu_display_white_texture); + + video_driver_texture_load(&ti, + TEXTURE_FILTER_NEAREST, &menu_display_white_texture); +} + +void menu_display_draw_cursor( + float *color, float cursor_size, uintptr_t texture, + float x, float y, unsigned width, unsigned height) +{ + menu_display_ctx_draw_t draw; + struct video_coords coords; + settings_t *settings = config_get_ptr(); + bool cursor_visible = settings->bools.video_fullscreen || + !menu_display_has_windowed; + + if (!settings->bools.menu_mouse_enable) + return; + if (!cursor_visible) + return; + + coords.vertices = 4; + coords.vertex = NULL; + coords.tex_coord = NULL; + coords.lut_tex_coord = NULL; + coords.color = (const float*)color; + + menu_display_blend_begin(); + + draw.x = x - (cursor_size / 2); + draw.y = (int)height - y - (cursor_size / 2); + draw.width = cursor_size; + draw.height = cursor_size; + draw.coords = &coords; + draw.matrix_data = NULL; + draw.texture = texture; + draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP; + + menu_display_draw(&draw); + menu_display_blend_end(); +} + +static INLINE float menu_display_scalef(float val, + float oldmin, float oldmax, float newmin, float newmax) +{ + return (((val - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin; +} + +static INLINE float menu_display_randf(float min, float max) +{ + return (rand() * ((max - min) / RAND_MAX)) + min; +} + +void menu_display_push_quad( + unsigned width, unsigned height, + const float *colors, int x1, int y1, + int x2, int y2) +{ + float vertex[8]; + video_coords_t coords; + menu_display_ctx_coord_draw_t coord_draw; + video_coord_array_t *ca = menu_display_get_coords_array(); + + vertex[0] = x1 / (float)width; + vertex[1] = y1 / (float)height; + vertex[2] = x2 / (float)width; + vertex[3] = y1 / (float)height; + vertex[4] = x1 / (float)width; + vertex[5] = y2 / (float)height; + vertex[6] = x2 / (float)width; + vertex[7] = y2 / (float)height; + + coord_draw.ptr = NULL; + + menu_display_get_tex_coords(&coord_draw); + + coords.color = colors; + coords.vertex = vertex; + coords.tex_coord = coord_draw.ptr; + coords.lut_tex_coord = coord_draw.ptr; + coords.vertices = 3; + + video_coord_array_append(ca, &coords, 3); + + coords.color += 4; + coords.vertex += 2; + coords.tex_coord += 2; + coords.lut_tex_coord += 2; + + video_coord_array_append(ca, &coords, 3); +} + +void menu_display_snow(int width, int height) +{ + struct display_particle + { + float x, y; + float xspeed, yspeed; + float alpha; + bool alive; + }; + static struct display_particle particles[PARTICLES_COUNT] = {{0}}; + static int timeout = 0; + unsigned i, max_gen = 2; + + for (i = 0; i < PARTICLES_COUNT; ++i) + { + struct display_particle *p = (struct display_particle*)&particles[i]; + + if (p->alive) + { + int16_t mouse_x = menu_input_mouse_state(MENU_MOUSE_X_AXIS); + + p->y += p->yspeed; + p->x += menu_display_scalef(mouse_x, 0, width, -0.3, 0.3); + p->x += p->xspeed; + + p->alive = p->y >= 0 && p->y < height + && p->x >= 0 && p->x < width; + } + else if (max_gen > 0 && timeout <= 0) + { + p->xspeed = menu_display_randf(-0.2, 0.2); + p->yspeed = menu_display_randf(1, 2); + p->y = 0; + p->x = rand() % width; + p->alpha = (float)rand() / (float)RAND_MAX; + p->alive = true; + + max_gen--; + } + } + + if (max_gen == 0) + timeout = 3; + else + timeout--; + + for (i = 0; i < PARTICLES_COUNT; ++i) + { + unsigned j; + float alpha, colors[16]; + struct display_particle *p = &particles[i]; + + if (!p->alive) + continue; + + alpha = menu_display_randf(0, 100) > 90 ? p->alpha/2 : p->alpha; + + for (j = 0; j < 16; j++) + { + colors[j] = 1; + if (j == 3 || j == 7 || j == 11 || j == 15) + colors[j] = alpha; + } + + menu_display_push_quad(width, height, + colors, p->x-2, p->y-2, p->x+2, p->y+2); + + j++; + } +} + +void menu_display_draw_text( + const font_data_t *font, const char *text, + float x, float y, int width, int height, + uint32_t color, enum text_alignment text_align, + float scale, bool shadows_enable, float shadow_offset) +{ + struct font_params params; + + /* Don't draw outside of the screen */ + if (x < -64 || x > width + 64 + || y < -64 || y > height + 64) + return; + + params.x = x / width; + params.y = 1.0f - y / height; + params.scale = scale; + params.drop_mod = 0.0f; + params.drop_x = 0.0f; + params.drop_y = 0.0f; + params.color = color; + params.full_screen = true; + params.text_align = text_align; + + if (shadows_enable) + { + params.drop_x = shadow_offset; + params.drop_y = -shadow_offset; + params.drop_alpha = 0.35f; + } + + video_driver_set_osd_msg(text, ¶ms, (void*)font); +} + +void menu_display_set_alpha(float *color, float alpha_value) +{ + if (!color) + return; + color[3] = color[7] = color[11] = color[15] = alpha_value; +} + +void menu_display_reset_textures_list(const char *texture_path, const char *iconpath, + uintptr_t *item, enum texture_filter_type filter_type) +{ + struct texture_image ti; + char path[PATH_MAX_LENGTH]; + + path[0] = '\0'; + + ti.width = 0; + ti.height = 0; + ti.pixels = NULL; + ti.supports_rgba = video_driver_supports_rgba(); + + if (!string_is_empty(texture_path)) + fill_pathname_join(path, iconpath, texture_path, sizeof(path)); + + if (string_is_empty(path) || !path_file_exists(path)) + return; + + if (!image_texture_load(&ti, path)) + return; + + video_driver_texture_load(&ti, + filter_type, item); + image_texture_free(&ti); +} + bool menu_driver_is_binding_state(void) { return menu_driver_is_binding; diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 9e0f10c13a..a4efa5db57 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -26,12 +26,16 @@ #include #include +#include #include "widgets/menu_entry.h" #include "menu_input.h" #include "menu_entries.h" #include "../gfx/video_driver.h" +#include "../file_path_special.h" +#include "../gfx/font_driver.h" +#include "../gfx/video_coord_array.h" RETRO_BEGIN_DECLS @@ -206,6 +210,98 @@ enum menu_settings_type MENU_SETTINGS_LAST }; +enum materialui_color_theme +{ + MATERIALUI_THEME_BLUE = 0, + MATERIALUI_THEME_BLUE_GREY, + MATERIALUI_THEME_DARK_BLUE, + MATERIALUI_THEME_GREEN, + MATERIALUI_THEME_RED, + MATERIALUI_THEME_YELLOW, + MATERIALUI_THEME_NVIDIA_SHIELD, + MATERIALUI_THEME_LAST +}; + +enum xmb_color_theme +{ + XMB_THEME_LEGACY_RED = 0, + XMB_THEME_DARK_PURPLE, + XMB_THEME_MIDNIGHT_BLUE, + XMB_THEME_GOLDEN, + XMB_THEME_ELECTRIC_BLUE, + XMB_THEME_APPLE_GREEN, + XMB_THEME_UNDERSEA, + XMB_THEME_VOLCANIC_RED, + XMB_THEME_DARK, + XMB_THEME_WALLPAPER, + XMB_THEME_LAST +}; + +enum xmb_icon_theme +{ + XMB_ICON_THEME_MONOCHROME = 0, + XMB_ICON_THEME_FLATUI, + XMB_ICON_THEME_RETROACTIVE, + XMB_ICON_THEME_PIXEL, + XMB_ICON_THEME_NEOACTIVE, + XMB_ICON_THEME_SYSTEMATIC, + XMB_ICON_THEME_DOTART, + XMB_ICON_THEME_CUSTOM, + XMB_ICON_THEME_LAST +}; + +enum xmb_shader_pipeline +{ + XMB_SHADER_PIPELINE_WALLPAPER = 0, + XMB_SHADER_PIPELINE_SIMPLE_RIBBON, + XMB_SHADER_PIPELINE_RIBBON, + XMB_SHADER_PIPELINE_SIMPLE_SNOW, + XMB_SHADER_PIPELINE_SNOW, + XMB_SHADER_PIPELINE_BOKEH, + XMB_SHADER_PIPELINE_LAST +}; + +enum menu_display_prim_type +{ + MENU_DISPLAY_PRIM_NONE = 0, + MENU_DISPLAY_PRIM_TRIANGLESTRIP, + MENU_DISPLAY_PRIM_TRIANGLES +}; + +enum menu_display_driver_type +{ + MENU_VIDEO_DRIVER_GENERIC = 0, + MENU_VIDEO_DRIVER_OPENGL, + MENU_VIDEO_DRIVER_VULKAN, + MENU_VIDEO_DRIVER_DIRECT3D, + MENU_VIDEO_DRIVER_VITA2D, + MENU_VIDEO_DRIVER_CTR, + MENU_VIDEO_DRIVER_CACA, + MENU_VIDEO_DRIVER_GDI, + MENU_VIDEO_DRIVER_VGA +}; + +enum menu_toggle_reason +{ + MENU_TOGGLE_REASON_NONE = 0, + MENU_TOGGLE_REASON_USER, + MENU_TOGGLE_REASON_MESSAGE +}; + +typedef struct menu_display_ctx_clearcolor +{ + float r; + float g; + float b; + float a; +} menu_display_ctx_clearcolor_t; + +typedef struct menu_display_frame_info +{ + bool shadows_enable; +} menu_display_frame_info_t; + + typedef struct { char deferred_path[PATH_MAX_LENGTH]; @@ -221,6 +317,57 @@ typedef struct char db_playlist_file[PATH_MAX_LENGTH]; } menu_handle_t; +typedef struct menu_display_ctx_draw +{ + float x; + float y; + unsigned width; + unsigned height; + struct video_coords *coords; + void *matrix_data; + uintptr_t texture; + enum menu_display_prim_type prim_type; + float *color; + const float *vertex; + const float *tex_coord; + size_t vertex_count; + struct + { + unsigned id; + const void *backend_data; + size_t backend_data_size; + bool active; + } pipeline; +} menu_display_ctx_draw_t; + +typedef struct menu_display_ctx_rotate_draw +{ + math_matrix_4x4 *matrix; + float rotation; + float scale_x; + float scale_y; + float scale_z; + bool scale_enable; +} menu_display_ctx_rotate_draw_t; + +typedef struct menu_display_ctx_coord_draw +{ + const float *ptr; +} menu_display_ctx_coord_draw_t; + +typedef struct menu_display_ctx_datetime +{ + char *s; + size_t len; + unsigned time_mode; +} menu_display_ctx_datetime_t; + +typedef struct menu_display_ctx_font +{ + const char *path; + float size; +} menu_display_ctx_font_t; + typedef struct menu_ctx_driver { void (*set_texture)(void); @@ -417,6 +564,144 @@ size_t menu_navigation_get_selection(void); void menu_navigation_set_selection(size_t val); +typedef struct menu_display_ctx_driver +{ + void (*draw)(void *data); + void (*draw_pipeline)(void *data); + void (*viewport)(void *data); + void (*blend_begin)(void); + void (*blend_end)(void); + void (*restore_clear_color)(void); + void (*clear_color)(menu_display_ctx_clearcolor_t *clearcolor); + void *(*get_default_mvp)(void); + const float *(*get_default_vertices)(void); + const float *(*get_default_tex_coords)(void); + bool (*font_init_first)( + void **font_handle, void *video_data, + const char *font_path, float font_size, + bool is_threaded); + enum menu_display_driver_type type; + const char *ident; +} menu_display_ctx_driver_t; + +typedef uintptr_t menu_texture_item; + +enum menu_toggle_reason menu_display_toggle_get_reason(void); +void menu_display_toggle_set_reason(enum menu_toggle_reason reason); + +void menu_display_blend_begin(void); +void menu_display_blend_end(void); + +void menu_display_font_free(font_data_t *font); +void menu_display_font_bind_block(font_data_t *font, void *block); +bool menu_display_font_flush_block(unsigned width, unsigned height, font_data_t *font); + +void menu_display_framebuffer_deinit(void); + +void menu_display_deinit(void); +bool menu_display_init(void); + +void menu_display_coords_array_reset(void); +video_coord_array_t *menu_display_get_coords_array(void); +const uint8_t *menu_display_get_font_framebuffer(void); +void menu_display_set_font_framebuffer(const uint8_t *buffer); +bool menu_display_libretro(bool is_idle, bool is_inited, bool is_dummy); + +void menu_display_set_width(unsigned width); +void menu_display_get_fb_size(unsigned *fb_width, unsigned *fb_height, + size_t *fb_pitch); +void menu_display_set_height(unsigned height); +void menu_display_set_header_height(unsigned height); +unsigned menu_display_get_header_height(void); +size_t menu_display_get_framebuffer_pitch(void); +void menu_display_set_framebuffer_pitch(size_t pitch); + +bool menu_display_get_msg_force(void); +void menu_display_set_msg_force(bool state); +bool menu_display_get_font_data_init(void); +void menu_display_set_font_data_init(bool state); +bool menu_display_get_update_pending(void); +void menu_display_set_viewport(unsigned width, unsigned height); +void menu_display_unset_viewport(unsigned width, unsigned height); +bool menu_display_get_framebuffer_dirty_flag(void); +void menu_display_set_framebuffer_dirty_flag(void); +void menu_display_unset_framebuffer_dirty_flag(void); +float menu_display_get_dpi(void); +bool menu_display_init_first_driver(bool video_is_threaded); +bool menu_display_restore_clear_color(void); +void menu_display_clear_color(menu_display_ctx_clearcolor_t *color); +void menu_display_draw(menu_display_ctx_draw_t *draw); + +void menu_display_draw_pipeline(menu_display_ctx_draw_t *draw); +void menu_display_draw_bg( + menu_display_ctx_draw_t *draw, + video_frame_info_t *video_info, + bool add_opacity); +void menu_display_draw_gradient( + menu_display_ctx_draw_t *draw, + video_frame_info_t *video_info); +void menu_display_draw_quad(int x, int y, unsigned w, unsigned h, + unsigned width, unsigned height, + float *color); +void menu_display_draw_texture(int x, int y, unsigned w, unsigned h, + unsigned width, unsigned height, + float *color, uintptr_t texture); +void menu_display_draw_texture_slice(int x, int y, unsigned w, unsigned h, + unsigned new_w, unsigned new_h, unsigned width, unsigned height, + float *color, unsigned offset, float scale_factor, uintptr_t texture); +void menu_display_rotate_z(menu_display_ctx_rotate_draw_t *draw); +bool menu_display_get_tex_coords(menu_display_ctx_coord_draw_t *draw); + +void menu_display_timedate(menu_display_ctx_datetime_t *datetime); + +void menu_display_handle_wallpaper_upload(void *task_data, + void *user_data, const char *err); + +void menu_display_handle_thumbnail_upload(void *task_data, + void *user_data, const char *err); + +void menu_display_handle_savestate_thumbnail_upload(void *task_data, + void *user_data, const char *err); + +void menu_display_push_quad( + unsigned width, unsigned height, + const float *colors, int x1, int y1, + int x2, int y2); + +void menu_display_snow(int width, int height); + +void menu_display_allocate_white_texture(void); + +void menu_display_draw_cursor( + float *color, float cursor_size, uintptr_t texture, + float x, float y, unsigned width, unsigned height); + +void menu_display_draw_text( + const font_data_t *font, const char *text, + float x, float y, int width, int height, + uint32_t color, enum text_alignment text_align, + float scale_factor, bool shadows_enable, float shadow_offset); + +void menu_display_set_alpha(float *color, float alpha_value); + +font_data_t *menu_display_font(enum application_special_type type, float font_size, + bool video_is_threaded); + +void menu_display_reset_textures_list(const char *texture_path, const char *iconpath, + uintptr_t *item, enum texture_filter_type filter_type); + +extern uintptr_t menu_display_white_texture; + +extern menu_display_ctx_driver_t menu_display_ctx_gl; +extern menu_display_ctx_driver_t menu_display_ctx_vulkan; +extern menu_display_ctx_driver_t menu_display_ctx_d3d; +extern menu_display_ctx_driver_t menu_display_ctx_vita2d; +extern menu_display_ctx_driver_t menu_display_ctx_ctr; +extern menu_display_ctx_driver_t menu_display_ctx_caca; +extern menu_display_ctx_driver_t menu_display_ctx_gdi; +extern menu_display_ctx_driver_t menu_display_ctx_vga; +extern menu_display_ctx_driver_t menu_display_ctx_null; + extern menu_ctx_driver_t menu_ctx_xui; extern menu_ctx_driver_t menu_ctx_rgui; extern menu_ctx_driver_t menu_ctx_mui; diff --git a/menu/menu_event.c b/menu/menu_event.c index 4117c0b65e..a20a9344f6 100644 --- a/menu/menu_event.c +++ b/menu/menu_event.c @@ -31,7 +31,6 @@ #include "menu_driver.h" #include "menu_animation.h" -#include "menu_display.h" #include "../configuration.h" #include "../retroarch.h" diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 00618b947e..08982b2e13 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -54,7 +54,6 @@ #include "menu_setting.h" #include "menu_driver.h" #include "menu_animation.h" -#include "menu_display.h" #include "menu_input.h" #include "../core.h" diff --git a/menu/widgets/menu_dialog.c b/menu/widgets/menu_dialog.c index 4ebeb1bbc2..f4e7549283 100644 --- a/menu/widgets/menu_dialog.c +++ b/menu/widgets/menu_dialog.c @@ -27,7 +27,6 @@ #include "menu_dialog.h" -#include "../menu_display.h" #include "../menu_driver.h" #include "../../retroarch.h" diff --git a/retroarch.c b/retroarch.c index 57f1c7bbc7..79c2f868c7 100644 --- a/retroarch.c +++ b/retroarch.c @@ -60,7 +60,6 @@ #ifdef HAVE_MENU #include "menu/menu_driver.h" -#include "menu/menu_display.h" #include "menu/menu_event.h" #include "menu/widgets/menu_dialog.h" #endif