2015-04-21 12:44:14 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-06-08 12:57:46 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2015-09-26 23:03:58 +00:00
|
|
|
#include <queues/message_queue.h>
|
2015-10-18 05:15:54 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2015-11-02 20:53:51 +00:00
|
|
|
#include <gfx/math/matrix_4x4.h>
|
2015-09-26 23:03:58 +00:00
|
|
|
|
2015-09-25 11:27:15 +00:00
|
|
|
#include "../config.def.h"
|
2015-09-26 23:03:58 +00:00
|
|
|
#include "../gfx/font_renderer_driver.h"
|
|
|
|
#include "../gfx/video_context_driver.h"
|
|
|
|
#include "../gfx/video_thread_wrapper.h"
|
2015-11-02 21:06:51 +00:00
|
|
|
#include "../gfx/video_texture.h"
|
2015-09-25 11:27:15 +00:00
|
|
|
|
2015-04-21 12:44:14 +00:00
|
|
|
#include "menu.h"
|
2015-09-26 23:10:15 +00:00
|
|
|
#include "menu_animation.h"
|
2015-09-25 11:27:15 +00:00
|
|
|
#include "menu_display.h"
|
2015-04-21 12:44:14 +00:00
|
|
|
|
2015-10-18 05:15:54 +00:00
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
#include "../gfx/video_thread_wrapper.h"
|
|
|
|
#endif
|
|
|
|
|
2015-09-25 19:41:24 +00:00
|
|
|
typedef struct menu_framebuf
|
|
|
|
{
|
|
|
|
uint16_t *data;
|
|
|
|
unsigned width;
|
|
|
|
unsigned height;
|
|
|
|
size_t pitch;
|
|
|
|
bool dirty;
|
|
|
|
} menu_framebuf_t;
|
|
|
|
|
2015-09-26 22:11:13 +00:00
|
|
|
typedef struct menu_display
|
|
|
|
{
|
|
|
|
bool msg_force;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
void *buf;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
const uint8_t *framebuf;
|
|
|
|
bool alloc_framebuf;
|
|
|
|
} font;
|
|
|
|
|
|
|
|
unsigned header_height;
|
|
|
|
|
|
|
|
msg_queue_t *msg_queue;
|
|
|
|
} menu_display_t;
|
|
|
|
|
2015-09-25 23:23:10 +00:00
|
|
|
static menu_display_t menu_display_state;
|
|
|
|
|
2015-09-25 19:25:37 +00:00
|
|
|
static menu_framebuf_t frame_buf_state;
|
|
|
|
|
2015-09-26 22:11:13 +00:00
|
|
|
static menu_display_t *menu_display_get_ptr(void)
|
2015-05-18 21:02:04 +00:00
|
|
|
{
|
2015-09-25 23:23:10 +00:00
|
|
|
return &menu_display_state;
|
2015-06-14 13:34:05 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 19:41:24 +00:00
|
|
|
static menu_framebuf_t *menu_display_fb_get_ptr(void)
|
2015-06-14 13:34:05 +00:00
|
|
|
{
|
2015-09-25 19:25:37 +00:00
|
|
|
return &frame_buf_state;
|
2015-06-13 14:42:11 +00:00
|
|
|
}
|
|
|
|
|
2015-06-13 14:47:51 +00:00
|
|
|
static void menu_display_fb_free(menu_framebuf_t *frame_buf)
|
|
|
|
{
|
|
|
|
if (!frame_buf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (frame_buf->data)
|
|
|
|
free(frame_buf->data);
|
|
|
|
frame_buf->data = NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:23:10 +00:00
|
|
|
void menu_display_free(void)
|
2015-04-21 12:44:14 +00:00
|
|
|
{
|
2015-09-25 23:23:10 +00:00
|
|
|
menu_display_t *disp = menu_display_get_ptr();
|
2015-06-15 15:34:12 +00:00
|
|
|
if (!disp)
|
2015-04-21 12:44:14 +00:00
|
|
|
return;
|
|
|
|
|
2015-06-15 00:08:25 +00:00
|
|
|
if (disp->msg_queue)
|
|
|
|
msg_queue_free(disp->msg_queue);
|
|
|
|
disp->msg_queue = NULL;
|
|
|
|
|
2015-09-25 20:24:07 +00:00
|
|
|
menu_animation_free();
|
2015-06-13 14:47:51 +00:00
|
|
|
|
2015-09-25 19:25:37 +00:00
|
|
|
menu_display_fb_free(&frame_buf_state);
|
2015-09-25 23:23:10 +00:00
|
|
|
memset(&frame_buf_state, 0, sizeof(menu_framebuf_t));
|
|
|
|
memset(&menu_display_state, 0, sizeof(menu_display_t));
|
2015-04-21 12:44:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:23:10 +00:00
|
|
|
bool menu_display_init(void)
|
2015-04-21 12:44:14 +00:00
|
|
|
{
|
2015-09-25 23:23:10 +00:00
|
|
|
menu_display_t *disp = menu_display_get_ptr();
|
|
|
|
if (!disp)
|
2015-04-21 12:44:14 +00:00
|
|
|
return false;
|
|
|
|
|
2015-10-26 02:18:13 +00:00
|
|
|
retro_assert(disp->msg_queue = msg_queue_new(8));
|
2015-09-23 23:08:01 +00:00
|
|
|
|
2015-04-21 12:44:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-04-21 13:45:03 +00:00
|
|
|
|
2015-04-24 20:01:33 +00:00
|
|
|
bool menu_display_font_init_first(const void **font_driver,
|
|
|
|
void **font_handle, void *video_data, const char *font_path,
|
|
|
|
float font_size)
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-05-20 17:56:12 +00:00
|
|
|
const struct retro_hw_render_callback *hw_render =
|
|
|
|
(const struct retro_hw_render_callback*)video_driver_callback();
|
2015-04-24 20:01:33 +00:00
|
|
|
|
2015-05-20 17:56:12 +00:00
|
|
|
if (settings->video.threaded && !hw_render->context_type)
|
2015-04-24 20:01:33 +00:00
|
|
|
{
|
2015-06-15 20:49:35 +00:00
|
|
|
thread_packet_t pkt;
|
2015-04-24 20:01:33 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
thread_video_t *thr = (thread_video_t*)driver->video_data;
|
|
|
|
|
|
|
|
if (!thr)
|
|
|
|
return false;
|
|
|
|
|
2015-06-13 00:40:01 +00:00
|
|
|
pkt.type = CMD_FONT_INIT;
|
2015-05-20 19:58:22 +00:00
|
|
|
pkt.data.font_init.method = font_init_first;
|
|
|
|
pkt.data.font_init.font_driver = (const void**)font_driver;
|
|
|
|
pkt.data.font_init.font_handle = font_handle;
|
|
|
|
pkt.data.font_init.video_data = video_data;
|
|
|
|
pkt.data.font_init.font_path = font_path;
|
|
|
|
pkt.data.font_init.font_size = font_size;
|
|
|
|
pkt.data.font_init.api = FONT_DRIVER_RENDER_OPENGL_API;
|
2015-04-24 20:01:33 +00:00
|
|
|
|
2015-05-20 19:58:22 +00:00
|
|
|
thr->send_and_wait(thr, &pkt);
|
2015-04-24 20:01:33 +00:00
|
|
|
|
2015-05-20 19:58:22 +00:00
|
|
|
return pkt.data.font_init.return_value;
|
2015-04-24 20:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return font_init_first(font_driver, font_handle, video_data,
|
|
|
|
font_path, font_size, FONT_DRIVER_RENDER_OPENGL_API);
|
|
|
|
}
|
2015-04-24 21:22:47 +00:00
|
|
|
|
2015-09-26 23:03:58 +00:00
|
|
|
bool menu_display_font_bind_block(void *data, const void *font_data, void *userdata)
|
2015-04-24 21:22:47 +00:00
|
|
|
{
|
2015-09-26 23:03:58 +00:00
|
|
|
const struct font_renderer *font_driver =
|
|
|
|
(const struct font_renderer*)font_data;
|
2015-06-15 15:24:07 +00:00
|
|
|
menu_display_t *disp = menu_display_get_ptr();
|
|
|
|
if (!disp || !font_driver || !font_driver->bind_block)
|
2015-04-24 21:22:47 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-15 15:24:07 +00:00
|
|
|
font_driver->bind_block(disp->font.buf, userdata);
|
2015-04-24 21:28:25 +00:00
|
|
|
|
2015-04-24 21:22:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-26 23:03:58 +00:00
|
|
|
bool menu_display_font_flush_block(void *data, const void *font_data)
|
2015-04-24 21:22:47 +00:00
|
|
|
{
|
2015-09-26 23:03:58 +00:00
|
|
|
const struct font_renderer *font_driver =
|
|
|
|
(const struct font_renderer*)font_data;
|
2015-06-13 21:07:27 +00:00
|
|
|
menu_handle_t *menu = (menu_handle_t*)data;
|
2015-09-25 23:23:10 +00:00
|
|
|
menu_display_t *disp = menu_display_get_ptr();
|
2015-04-24 21:28:25 +00:00
|
|
|
if (!font_driver || !font_driver->flush)
|
2015-04-24 21:22:47 +00:00
|
|
|
return false;
|
|
|
|
|
2015-09-25 23:23:10 +00:00
|
|
|
font_driver->flush(disp->font.buf);
|
2015-04-24 21:22:47 +00:00
|
|
|
|
2015-04-24 21:28:25 +00:00
|
|
|
return menu_display_font_bind_block(menu,
|
|
|
|
font_driver, NULL);
|
2015-04-24 21:22:47 +00:00
|
|
|
}
|
2015-04-26 14:46:56 +00:00
|
|
|
|
2015-09-25 23:23:10 +00:00
|
|
|
void menu_display_free_main_font(void)
|
2015-05-01 12:00:03 +00:00
|
|
|
{
|
2015-06-15 15:24:07 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
menu_display_t *disp = menu_display_get_ptr();
|
2015-05-11 07:56:13 +00:00
|
|
|
|
2015-06-15 15:24:07 +00:00
|
|
|
if (disp && disp->font.buf)
|
2015-05-01 12:00:03 +00:00
|
|
|
{
|
2015-06-15 15:24:07 +00:00
|
|
|
driver->font_osd_driver->free(disp->font.buf);
|
|
|
|
disp->font.buf = NULL;
|
2015-05-01 12:00:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-13 21:07:27 +00:00
|
|
|
bool menu_display_init_main_font(void *data,
|
2015-05-01 12:00:03 +00:00
|
|
|
const char *font_path, float font_size)
|
|
|
|
{
|
2015-06-12 15:23:31 +00:00
|
|
|
bool ret;
|
2015-06-15 15:24:07 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
void *video = video_driver_get_ptr(NULL);
|
2015-09-25 23:23:10 +00:00
|
|
|
menu_display_t *disp = menu_display_get_ptr();
|
2015-06-15 15:24:07 +00:00
|
|
|
|
|
|
|
if (!disp)
|
|
|
|
return false;
|
2015-05-01 12:00:03 +00:00
|
|
|
|
2015-06-15 15:24:07 +00:00
|
|
|
if (disp->font.buf)
|
2015-09-25 23:23:10 +00:00
|
|
|
menu_display_free_main_font();
|
2015-05-01 12:00:03 +00:00
|
|
|
|
2015-06-12 15:23:31 +00:00
|
|
|
ret = menu_display_font_init_first(
|
2015-06-22 00:21:53 +00:00
|
|
|
(const void**)&driver->font_osd_driver,
|
|
|
|
&disp->font.buf, video,
|
2015-05-01 12:00:03 +00:00
|
|
|
font_path, font_size);
|
|
|
|
|
2015-06-12 15:23:31 +00:00
|
|
|
if (ret)
|
2015-06-15 15:24:07 +00:00
|
|
|
disp->font.size = font_size;
|
2015-05-01 12:00:03 +00:00
|
|
|
else
|
2015-06-15 15:24:07 +00:00
|
|
|
disp->font.buf = NULL;
|
2015-05-01 12:00:03 +00:00
|
|
|
|
2015-06-12 15:23:31 +00:00
|
|
|
return ret;
|
2015-05-01 12:00:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 11:27:15 +00:00
|
|
|
bool menu_display_ctl(enum menu_display_ctl_state state, void *data)
|
2015-05-19 22:26:50 +00:00
|
|
|
{
|
|
|
|
unsigned width, height;
|
2015-09-25 11:27:15 +00:00
|
|
|
menu_framebuf_t *frame_buf = menu_display_fb_get_ptr();
|
2015-09-25 19:52:04 +00:00
|
|
|
menu_display_t *disp = menu_display_get_ptr();
|
2015-09-26 01:02:09 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
2015-09-25 11:27:15 +00:00
|
|
|
switch (state)
|
|
|
|
{
|
2015-09-26 22:00:54 +00:00
|
|
|
case MENU_DISPLAY_CTL_FONT_BUF:
|
2015-09-26 22:09:15 +00:00
|
|
|
{
|
|
|
|
void **ptr = (void**)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = disp->font.buf;
|
|
|
|
}
|
2015-09-26 22:00:54 +00:00
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_SET_FONT_BUF:
|
2015-09-26 22:09:15 +00:00
|
|
|
{
|
|
|
|
void **ptr = (void**)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
disp->font.buf = *ptr;
|
|
|
|
}
|
2015-09-26 22:00:54 +00:00
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_FONT_FB:
|
|
|
|
{
|
|
|
|
uint8_t **ptr = (uint8_t**)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = (uint8_t*)disp->font.framebuf;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_SET_FONT_FB:
|
|
|
|
{
|
|
|
|
uint8_t **ptr = (uint8_t**)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
disp->font.framebuf = *ptr;
|
|
|
|
}
|
|
|
|
return true;
|
2015-10-31 16:06:08 +00:00
|
|
|
case MENU_DISPLAY_CTL_LIBRETRO_RUNNING:
|
|
|
|
{
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
if (!settings->menu.pause_libretro)
|
|
|
|
if (global->inited.main && (global->inited.core.type != CORE_TYPE_DUMMY))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2015-09-26 01:02:09 +00:00
|
|
|
case MENU_DISPLAY_CTL_LIBRETRO:
|
|
|
|
video_driver_set_texture_enable(true, false);
|
|
|
|
|
2015-10-31 16:06:08 +00:00
|
|
|
if (menu_display_ctl(MENU_DISPLAY_CTL_LIBRETRO_RUNNING, NULL))
|
2015-09-26 01:02:09 +00:00
|
|
|
{
|
2015-10-31 16:06:08 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
bool block_libretro_input = driver->block_libretro_input;
|
2015-09-26 01:02:09 +00:00
|
|
|
|
2015-10-31 16:06:08 +00:00
|
|
|
driver->block_libretro_input = true;
|
|
|
|
core.retro_run();
|
|
|
|
driver->block_libretro_input = block_libretro_input;
|
|
|
|
return true;
|
2015-09-26 01:02:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
video_driver_cached_frame();
|
|
|
|
return true;
|
2015-09-25 18:28:56 +00:00
|
|
|
case MENU_DISPLAY_CTL_SET_WIDTH:
|
|
|
|
{
|
|
|
|
unsigned *ptr = (unsigned*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
frame_buf->width = *ptr;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_WIDTH:
|
|
|
|
{
|
|
|
|
unsigned *ptr = (unsigned*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = frame_buf->width;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_HEIGHT:
|
|
|
|
{
|
|
|
|
unsigned *ptr = (unsigned*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = frame_buf->height;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-25 19:52:04 +00:00
|
|
|
case MENU_DISPLAY_CTL_HEADER_HEIGHT:
|
|
|
|
{
|
|
|
|
unsigned *ptr = (unsigned*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = disp->header_height;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-26 21:37:25 +00:00
|
|
|
case MENU_DISPLAY_CTL_SET_HEADER_HEIGHT:
|
|
|
|
{
|
|
|
|
unsigned *ptr = (unsigned*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
disp->header_height = *ptr;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_FONT_SIZE:
|
|
|
|
{
|
|
|
|
unsigned *ptr = (unsigned*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = disp->font.size;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_SET_FONT_SIZE:
|
|
|
|
{
|
|
|
|
unsigned *ptr = (unsigned*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
disp->font.size = *ptr;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-25 18:28:56 +00:00
|
|
|
case MENU_DISPLAY_CTL_SET_HEIGHT:
|
|
|
|
{
|
|
|
|
unsigned *ptr = (unsigned*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
frame_buf->height = *ptr;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-25 19:03:23 +00:00
|
|
|
case MENU_DISPLAY_CTL_FB_DATA:
|
|
|
|
{
|
|
|
|
uint16_t **ptr = (uint16_t**)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = frame_buf->data;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-25 19:36:11 +00:00
|
|
|
case MENU_DISPLAY_CTL_SET_FB_DATA:
|
|
|
|
{
|
|
|
|
uint16_t *ptr = (uint16_t*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
frame_buf->data = ptr;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-25 19:03:23 +00:00
|
|
|
case MENU_DISPLAY_CTL_FB_PITCH:
|
|
|
|
{
|
|
|
|
size_t *ptr = (size_t*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = frame_buf->pitch;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-25 19:20:26 +00:00
|
|
|
case MENU_DISPLAY_CTL_SET_FB_PITCH:
|
|
|
|
{
|
|
|
|
size_t *ptr = (size_t*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
frame_buf->pitch = *ptr;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-26 21:51:35 +00:00
|
|
|
case MENU_DISPLAY_CTL_MSG_FORCE:
|
|
|
|
{
|
|
|
|
bool *ptr = (bool*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = disp->msg_force;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_SET_MSG_FORCE:
|
|
|
|
{
|
|
|
|
bool *ptr = (bool*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
disp->msg_force = *ptr;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-26 21:27:03 +00:00
|
|
|
case MENU_DISPLAY_CTL_FONT_DATA_INIT:
|
2015-09-26 21:25:04 +00:00
|
|
|
{
|
|
|
|
bool *ptr = (bool*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
*ptr = disp->font.alloc_framebuf;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-26 21:27:03 +00:00
|
|
|
case MENU_DISPLAY_CTL_SET_FONT_DATA_INIT:
|
2015-09-26 21:25:04 +00:00
|
|
|
{
|
|
|
|
bool *ptr = (bool*)data;
|
|
|
|
if (!ptr)
|
|
|
|
return false;
|
|
|
|
disp->font.alloc_framebuf = *ptr;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-25 12:07:01 +00:00
|
|
|
case MENU_DISPLAY_CTL_UPDATE_PENDING:
|
2015-10-11 11:03:04 +00:00
|
|
|
{
|
|
|
|
bool ptr;
|
|
|
|
menu_display_ctl(MENU_DISPLAY_CTL_GET_FRAMEBUFFER_DIRTY_FLAG, &ptr);
|
|
|
|
if (menu_animation_ctl(MENU_ANIMATION_CTL_IS_ACTIVE, NULL) || ptr)
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-25 12:07:01 +00:00
|
|
|
return false;
|
2015-09-25 11:27:15 +00:00
|
|
|
case MENU_DISPLAY_CTL_SET_VIEWPORT:
|
|
|
|
video_driver_get_size(&width, &height);
|
|
|
|
video_driver_set_viewport(width,
|
|
|
|
height, true, false);
|
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_UNSET_VIEWPORT:
|
|
|
|
video_driver_get_size(&width, &height);
|
|
|
|
video_driver_set_viewport(width,
|
|
|
|
height, false, true);
|
|
|
|
return true;
|
2015-09-25 19:07:12 +00:00
|
|
|
case MENU_DISPLAY_CTL_GET_FRAMEBUFFER_DIRTY_FLAG:
|
|
|
|
{
|
|
|
|
bool *ptr = (bool*)data;
|
2015-10-11 11:03:04 +00:00
|
|
|
if (!ptr || !frame_buf)
|
2015-09-25 19:07:12 +00:00
|
|
|
return false;
|
|
|
|
*ptr = frame_buf->dirty;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-25 11:27:15 +00:00
|
|
|
case MENU_DISPLAY_CTL_SET_FRAMEBUFFER_DIRTY_FLAG:
|
|
|
|
if (frame_buf && frame_buf->data)
|
|
|
|
frame_buf->dirty = true;
|
|
|
|
return true;
|
|
|
|
case MENU_DISPLAY_CTL_UNSET_FRAMEBUFFER_DIRTY_FLAG:
|
|
|
|
if (frame_buf && frame_buf->data)
|
|
|
|
frame_buf->dirty = false;
|
|
|
|
return true;
|
2015-09-25 12:03:20 +00:00
|
|
|
case MENU_DISPLAY_CTL_GET_DPI:
|
|
|
|
{
|
|
|
|
float *dpi = (float*)data;
|
2015-09-26 01:02:09 +00:00
|
|
|
*dpi = menu_dpi_override_value;
|
2015-09-25 12:03:20 +00:00
|
|
|
|
|
|
|
if (!settings)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (settings->menu.dpi.override_enable)
|
|
|
|
*dpi = settings->menu.dpi.override_value;
|
|
|
|
else if (!gfx_ctx_get_metrics(DISPLAY_METRIC_DPI, dpi))
|
|
|
|
*dpi = menu_dpi_override_value;
|
|
|
|
}
|
|
|
|
return true;
|
2015-09-25 11:27:15 +00:00
|
|
|
}
|
2015-04-26 16:08:17 +00:00
|
|
|
|
2015-09-25 11:27:15 +00:00
|
|
|
return false;
|
2015-04-26 16:08:17 +00:00
|
|
|
}
|
2015-06-08 12:57:46 +00:00
|
|
|
|
|
|
|
void menu_display_timedate(char *s, size_t len, unsigned time_mode)
|
|
|
|
{
|
|
|
|
time_t time_;
|
|
|
|
time(&time_);
|
|
|
|
|
|
|
|
switch (time_mode)
|
|
|
|
{
|
|
|
|
case 0: /* Date and time */
|
|
|
|
strftime(s, len, "%Y-%m-%d %H:%M:%S", localtime(&time_));
|
|
|
|
break;
|
|
|
|
case 1: /* Date */
|
|
|
|
strftime(s, len, "%Y-%m-%d", localtime(&time_));
|
|
|
|
break;
|
|
|
|
case 2: /* Time */
|
|
|
|
strftime(s, len, "%H:%M:%S", localtime(&time_));
|
|
|
|
break;
|
|
|
|
case 3: /* Time (hours-minutes) */
|
|
|
|
strftime(s, len, "%H:%M", localtime(&time_));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-22 20:10:43 +00:00
|
|
|
|
|
|
|
void menu_display_msg_queue_push(const char *msg, unsigned prio, unsigned duration,
|
|
|
|
bool flush)
|
|
|
|
{
|
|
|
|
rarch_main_msg_queue_push(msg, prio, duration, flush);
|
|
|
|
}
|
2015-10-18 05:15:54 +00:00
|
|
|
|
2015-11-02 18:47:25 +00:00
|
|
|
void menu_display_matrix_4x4_rotate_z(void *data, float rotation,
|
|
|
|
float scale_x, float scale_y, float scale_z, bool scale_enable)
|
2015-11-02 18:34:01 +00:00
|
|
|
{
|
|
|
|
math_matrix_4x4 matrix_rotated;
|
2015-11-02 18:47:25 +00:00
|
|
|
math_matrix_4x4 matrix_scaled;
|
2015-11-02 18:34:01 +00:00
|
|
|
math_matrix_4x4 *b = NULL;
|
|
|
|
math_matrix_4x4 *matrix = (math_matrix_4x4*)data;
|
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
|
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
b = (math_matrix_4x4*)&gl->mvp_no_rot;
|
|
|
|
#endif
|
|
|
|
if (!matrix)
|
|
|
|
return;
|
|
|
|
|
|
|
|
matrix_4x4_rotate_z(&matrix_rotated, rotation);
|
|
|
|
matrix_4x4_multiply(matrix, &matrix_rotated, b);
|
2015-11-02 18:47:25 +00:00
|
|
|
|
|
|
|
if (!scale_enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
matrix_4x4_scale(&matrix_scaled, scale_x, scale_y, scale_z);
|
|
|
|
matrix_4x4_multiply(matrix, &matrix_scaled, matrix);
|
2015-11-02 18:34:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 21:37:29 +00:00
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
static const GRfloat gl_vertexes[] = {
|
|
|
|
0, 0,
|
|
|
|
1, 0,
|
|
|
|
0, 1,
|
|
|
|
1, 1
|
|
|
|
};
|
|
|
|
|
2015-11-02 21:46:23 +00:00
|
|
|
static const GRfloat gl_tex_coords[] = {
|
|
|
|
0, 1,
|
|
|
|
1, 1,
|
|
|
|
0, 0,
|
|
|
|
1, 0
|
|
|
|
};
|
|
|
|
|
2015-11-02 21:37:29 +00:00
|
|
|
static GLenum menu_display_prim_to_gl_enum(enum menu_display_prim_type prim_type)
|
|
|
|
{
|
|
|
|
switch (prim_type)
|
|
|
|
{
|
|
|
|
case MENU_DISPLAY_PRIM_TRIANGLESTRIP:
|
|
|
|
return GL_TRIANGLE_STRIP;
|
|
|
|
case MENU_DISPLAY_PRIM_TRIANGLES:
|
|
|
|
return GL_TRIANGLES;
|
|
|
|
case MENU_DISPLAY_PRIM_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-02 18:07:36 +00:00
|
|
|
void menu_display_blend_begin(void)
|
2015-11-01 15:23:50 +00:00
|
|
|
{
|
2015-11-02 18:07:36 +00:00
|
|
|
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
|
2015-11-01 15:23:50 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
if (gl->shader && gl->shader->use)
|
|
|
|
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
|
|
|
|
}
|
|
|
|
|
2015-11-02 18:07:36 +00:00
|
|
|
void menu_display_blend_end(void)
|
2015-11-01 15:23:50 +00:00
|
|
|
{
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:43:27 +00:00
|
|
|
void menu_display_draw_frame(
|
2015-10-18 05:15:54 +00:00
|
|
|
unsigned x, unsigned y,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
struct gfx_coords *coords,
|
2015-11-02 20:53:51 +00:00
|
|
|
void *matrix_data,
|
2015-10-24 05:28:49 +00:00
|
|
|
GLuint texture,
|
2015-10-24 05:51:33 +00:00
|
|
|
enum menu_display_prim_type prim_type
|
2015-10-18 05:15:54 +00:00
|
|
|
)
|
|
|
|
{
|
2015-11-02 20:53:51 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
|
|
|
|
math_matrix_4x4 *mat = (math_matrix_4x4*)matrix_data;
|
2015-11-02 17:41:51 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
2015-10-18 05:15:54 +00:00
|
|
|
|
2015-10-28 17:24:51 +00:00
|
|
|
/* TODO - edge case */
|
|
|
|
if (height <= 0)
|
|
|
|
height = 1;
|
|
|
|
|
2015-11-02 18:34:01 +00:00
|
|
|
if (!mat)
|
|
|
|
mat = &gl->mvp_no_rot;
|
2015-11-02 21:37:29 +00:00
|
|
|
if (!coords->vertex)
|
|
|
|
coords->vertex = &gl_vertexes[0];
|
2015-11-02 21:46:23 +00:00
|
|
|
if (!coords->tex_coord)
|
|
|
|
coords->tex_coord = &gl_tex_coords[0];
|
|
|
|
if (!coords->lut_tex_coord)
|
|
|
|
coords->lut_tex_coord = &gl_tex_coords[0];
|
2015-11-02 18:34:01 +00:00
|
|
|
|
2015-10-18 05:15:54 +00:00
|
|
|
glViewport(x, y, width, height);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
|
2015-11-02 17:41:51 +00:00
|
|
|
gl->shader->set_coords(coords);
|
|
|
|
gl->shader->set_mvp(driver->video_data, mat);
|
2015-10-18 05:15:54 +00:00
|
|
|
|
2015-11-02 17:55:05 +00:00
|
|
|
glDrawArrays(menu_display_prim_to_gl_enum(prim_type), 0, coords->vertices);
|
2015-11-02 19:02:06 +00:00
|
|
|
|
|
|
|
gl->coords.color = gl->white_color_ptr;
|
2015-10-18 05:15:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:43:27 +00:00
|
|
|
void menu_display_frame_background(
|
2015-10-18 05:15:54 +00:00
|
|
|
unsigned width,
|
|
|
|
unsigned height,
|
|
|
|
GLuint texture,
|
|
|
|
float handle_alpha,
|
|
|
|
bool force_transparency,
|
|
|
|
GRfloat *coord_color,
|
|
|
|
GRfloat *coord_color2,
|
2015-11-01 21:35:19 +00:00
|
|
|
const GRfloat *vertex,
|
2015-10-24 05:28:49 +00:00
|
|
|
const GRfloat *tex_coord,
|
2015-10-24 05:51:33 +00:00
|
|
|
size_t vertex_count,
|
|
|
|
enum menu_display_prim_type prim_type)
|
2015-10-18 05:15:54 +00:00
|
|
|
{
|
|
|
|
struct gfx_coords coords;
|
2015-11-02 21:46:23 +00:00
|
|
|
const GRfloat *new_vertex = NULL;
|
|
|
|
const GRfloat *new_tex_coord = NULL;
|
2015-11-02 19:41:42 +00:00
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
|
2015-11-02 18:11:09 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
2015-10-18 05:15:54 +00:00
|
|
|
|
2015-11-02 21:46:23 +00:00
|
|
|
new_vertex = vertex;
|
|
|
|
new_tex_coord = tex_coord;
|
2015-11-02 21:37:29 +00:00
|
|
|
|
|
|
|
if (!new_vertex)
|
|
|
|
new_vertex = &gl_vertexes[0];
|
2015-11-02 21:46:23 +00:00
|
|
|
if (!new_tex_coord)
|
|
|
|
new_tex_coord = &gl_tex_coords[0];
|
2015-11-02 21:37:29 +00:00
|
|
|
|
2015-10-24 05:28:49 +00:00
|
|
|
coords.vertices = vertex_count;
|
2015-11-02 21:37:29 +00:00
|
|
|
coords.vertex = new_vertex;
|
2015-11-02 21:46:23 +00:00
|
|
|
coords.tex_coord = new_tex_coord;
|
|
|
|
coords.lut_tex_coord = new_tex_coord;
|
2015-10-18 05:15:54 +00:00
|
|
|
coords.color = (const float*)coord_color;
|
|
|
|
|
2015-11-02 18:07:36 +00:00
|
|
|
menu_display_blend_begin();
|
2015-10-18 05:15:54 +00:00
|
|
|
|
|
|
|
menu_display_ctl(MENU_DISPLAY_CTL_SET_VIEWPORT, NULL);
|
|
|
|
|
|
|
|
if ((settings->menu.pause_libretro
|
|
|
|
|| !global->inited.main || (global->inited.core.type == CORE_TYPE_DUMMY))
|
|
|
|
&& !force_transparency
|
|
|
|
&& texture)
|
|
|
|
coords.color = (const float*)coord_color2;
|
|
|
|
|
2015-10-18 05:43:27 +00:00
|
|
|
menu_display_draw_frame(0, 0, width, height,
|
2015-11-02 17:41:51 +00:00
|
|
|
&coords, &gl->mvp_no_rot,
|
2015-11-02 17:55:05 +00:00
|
|
|
texture, prim_type);
|
2015-11-01 18:24:35 +00:00
|
|
|
|
2015-11-02 18:07:36 +00:00
|
|
|
menu_display_blend_end();
|
2015-10-18 05:15:54 +00:00
|
|
|
|
|
|
|
gl->coords.color = gl->white_color_ptr;
|
|
|
|
}
|
2015-11-01 18:49:19 +00:00
|
|
|
|
2015-11-02 19:02:06 +00:00
|
|
|
void menu_display_restore_clear_color(void)
|
2015-11-01 19:07:23 +00:00
|
|
|
{
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.00f);
|
|
|
|
}
|
|
|
|
|
2015-11-02 19:02:06 +00:00
|
|
|
void menu_display_clear_color(float r, float g, float b, float a)
|
2015-11-01 18:49:19 +00:00
|
|
|
{
|
|
|
|
glClearColor(r, g, b, a);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
2015-11-02 21:06:51 +00:00
|
|
|
|
|
|
|
unsigned menu_display_texture_load(void *data, enum texture_filter_type type)
|
|
|
|
{
|
|
|
|
return video_texture_load(data, TEXTURE_BACKEND_OPENGL, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_display_texture_unload(uintptr_t *id)
|
|
|
|
{
|
|
|
|
if (!id)
|
|
|
|
return;
|
|
|
|
video_texture_unload(id);
|
|
|
|
}
|
2015-10-18 05:15:54 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-02 21:27:19 +00:00
|
|
|
static const char *menu_video_get_ident(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
|
|
|
if (settings->video.threaded)
|
|
|
|
return rarch_threaded_video_get_ident();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return video_driver_get_ident();
|
|
|
|
}
|
|
|
|
|
2015-11-02 19:41:42 +00:00
|
|
|
bool menu_display_check_compatibility(enum menu_display_driver_type type)
|
|
|
|
{
|
2015-11-02 21:25:39 +00:00
|
|
|
const char *video_driver = menu_video_get_ident();
|
2015-11-02 19:41:42 +00:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case MENU_VIDEO_DRIVER_GENERIC:
|
|
|
|
return true;
|
|
|
|
case MENU_VIDEO_DRIVER_OPENGL:
|
2015-11-02 21:25:39 +00:00
|
|
|
if (!strcmp(video_driver, "gl"))
|
|
|
|
return true;
|
2015-11-02 19:41:42 +00:00
|
|
|
break;
|
|
|
|
case MENU_VIDEO_DRIVER_DIRECT3D:
|
2015-11-02 21:25:39 +00:00
|
|
|
if (!strcmp(video_driver, "d3d"))
|
|
|
|
return true;
|
2015-11-02 19:41:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_ERR("Cannot initialize menu driver: video driver of type %d is not active.\n", type);
|
|
|
|
return false;
|
|
|
|
}
|