2014-07-27 20:19:11 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 17:06:50 +00:00
|
|
|
* Copyright (C) 2014 2015 - Jean-Andre Santoni
|
2014-07-27 20:19:11 +00:00
|
|
|
*
|
|
|
|
* 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-09-16 03:53:34 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
2016-09-06 17:39:02 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-03-01 05:49:05 +00:00
|
|
|
#ifdef HAVE_EGL
|
2015-11-19 12:24:51 +00:00
|
|
|
#include "../common/egl_common.h"
|
2016-03-01 05:49:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
2015-11-17 07:01:33 +00:00
|
|
|
#include "../common/gl_common.h"
|
2016-03-01 05:49:05 +00:00
|
|
|
#endif
|
2014-07-27 20:19:11 +00:00
|
|
|
|
2016-09-11 13:10:58 +00:00
|
|
|
#include "../../configuration.h"
|
|
|
|
#include "../../frontend/frontend_driver.h"
|
|
|
|
#include "../../runloop.h"
|
|
|
|
|
2016-03-01 05:49:05 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
#ifdef HAVE_EGL
|
2015-12-08 20:05:18 +00:00
|
|
|
egl_ctx_data_t egl;
|
2016-03-01 05:49:05 +00:00
|
|
|
#endif
|
2016-07-08 12:29:16 +00:00
|
|
|
|
|
|
|
EGLNativeWindowType native_window;
|
2015-12-08 20:05:18 +00:00
|
|
|
bool resize;
|
|
|
|
unsigned width, height;
|
|
|
|
} vivante_ctx_data_t;
|
2014-07-27 20:19:11 +00:00
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_vivante_destroy(void *data)
|
2014-07-27 20:19:11 +00:00
|
|
|
{
|
2015-12-08 20:05:18 +00:00
|
|
|
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
|
2016-03-01 05:49:05 +00:00
|
|
|
|
2016-07-08 12:29:16 +00:00
|
|
|
if (viv)
|
|
|
|
{
|
2016-03-01 05:49:05 +00:00
|
|
|
#ifdef HAVE_EGL
|
2016-07-08 12:29:16 +00:00
|
|
|
egl_destroy(&viv->egl);
|
2016-03-01 05:49:05 +00:00
|
|
|
#endif
|
2014-07-27 20:19:11 +00:00
|
|
|
|
2016-07-08 12:29:16 +00:00
|
|
|
viv->resize = false;
|
|
|
|
free(viv);
|
|
|
|
}
|
|
|
|
|
2014-07-27 20:19:11 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 15:18:57 +00:00
|
|
|
static void *gfx_ctx_vivante_init(void *video_driver)
|
2014-07-27 20:19:11 +00:00
|
|
|
{
|
2016-03-01 05:49:05 +00:00
|
|
|
#ifdef HAVE_EGL
|
2015-11-19 17:10:59 +00:00
|
|
|
EGLint n;
|
|
|
|
EGLint major, minor;
|
2015-01-10 16:51:00 +00:00
|
|
|
EGLint format;
|
2014-07-27 20:19:11 +00:00
|
|
|
static const EGLint attribs[] = {
|
2014-10-27 13:35:23 +00:00
|
|
|
#if 0
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
#endif
|
2014-07-27 20:19:11 +00:00
|
|
|
EGL_BLUE_SIZE, 5,
|
|
|
|
EGL_GREEN_SIZE, 6,
|
|
|
|
EGL_RED_SIZE, 5,
|
|
|
|
EGL_ALPHA_SIZE, 0,
|
|
|
|
EGL_SAMPLES, 0,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2016-03-01 05:49:05 +00:00
|
|
|
#endif
|
2015-12-08 20:05:18 +00:00
|
|
|
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)calloc(1, sizeof(*viv));
|
|
|
|
|
|
|
|
if (!viv)
|
|
|
|
return NULL;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-03-01 05:49:05 +00:00
|
|
|
#ifdef HAVE_EGL
|
2016-07-08 10:58:06 +00:00
|
|
|
frontend_driver_install_signal_handler();
|
2016-07-08 12:29:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Disable cursor blinking so it's not visible in RetroArch. */
|
|
|
|
system("setterm -cursor off");
|
2014-07-27 20:19:11 +00:00
|
|
|
|
2016-07-08 12:29:16 +00:00
|
|
|
#ifdef HAVE_EGL
|
2016-03-01 05:49:05 +00:00
|
|
|
if (!egl_init_context(&viv->egl, EGL_DEFAULT_DISPLAY, &major, &minor,
|
2015-11-19 17:10:59 +00:00
|
|
|
&n, attribs))
|
2014-07-27 20:19:11 +00:00
|
|
|
{
|
2015-11-19 17:10:59 +00:00
|
|
|
egl_report_error();
|
2014-07-27 20:19:11 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2016-03-01 05:49:05 +00:00
|
|
|
#endif
|
2014-07-27 20:19:11 +00:00
|
|
|
|
2015-12-08 20:05:18 +00:00
|
|
|
return viv;
|
2014-07-27 20:19:11 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
RARCH_ERR("[Vivante fbdev]: EGL error: %d.\n", eglGetError());
|
2015-12-08 20:05:18 +00:00
|
|
|
gfx_ctx_vivante_destroy(viv);
|
2015-12-08 15:18:57 +00:00
|
|
|
return NULL;
|
2014-07-27 20:19:11 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 21:29:26 +00:00
|
|
|
static void gfx_ctx_vivante_get_video_size(void *data,
|
|
|
|
unsigned *width, unsigned *height)
|
|
|
|
{
|
|
|
|
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
|
|
|
|
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
egl_get_video_size(&viv->egl, width, height);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_vivante_check_window(void *data, bool *quit,
|
2014-07-27 20:19:11 +00:00
|
|
|
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
|
|
|
|
{
|
2015-01-10 16:51:00 +00:00
|
|
|
unsigned new_width, new_height;
|
2016-03-01 05:49:05 +00:00
|
|
|
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-03-01 05:49:05 +00:00
|
|
|
#ifdef HAVE_EGL
|
|
|
|
gfx_ctx_vivante_get_video_size(&viv->egl, &new_width, &new_height);
|
|
|
|
#endif
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2014-07-27 20:19:11 +00:00
|
|
|
if (new_width != *width || new_height != *height)
|
|
|
|
{
|
|
|
|
*width = new_width;
|
|
|
|
*height = new_height;
|
|
|
|
*resize = true;
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:58:06 +00:00
|
|
|
*quit = (bool)frontend_driver_get_signal_handler_state();
|
2014-07-27 20:19:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 23:58:33 +00:00
|
|
|
static bool gfx_ctx_vivante_set_resize(void *data,
|
2014-10-08 16:09:01 +00:00
|
|
|
unsigned width, unsigned height)
|
2014-07-27 20:19:11 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)width;
|
|
|
|
(void)height;
|
2016-01-06 23:58:33 +00:00
|
|
|
return false;
|
2014-07-27 20:19:11 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_vivante_update_window_title(void *data)
|
2014-07-27 20:19:11 +00:00
|
|
|
{
|
2016-12-22 22:36:11 +00:00
|
|
|
char buf[128] = {0};
|
|
|
|
char buf_fps[128] = {0};
|
2015-03-20 21:08:36 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2014-07-27 20:19:11 +00:00
|
|
|
|
2015-01-10 16:51:00 +00:00
|
|
|
(void)data;
|
|
|
|
|
2015-01-18 19:03:33 +00:00
|
|
|
video_monitor_get_fps(buf, sizeof(buf),
|
2015-03-07 22:03:56 +00:00
|
|
|
buf_fps, sizeof(buf_fps));
|
2015-03-20 21:08:36 +00:00
|
|
|
if (settings->fps_show)
|
2016-12-22 22:36:11 +00:00
|
|
|
runloop_msg_queue_push(buf_fps, 1, 1, false);
|
2014-07-27 20:19:11 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_vivante_set_video_mode(void *data,
|
2014-07-27 20:19:11 +00:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
|
|
|
{
|
2016-03-01 05:49:05 +00:00
|
|
|
#ifdef HAVE_EGL
|
2015-01-10 16:51:00 +00:00
|
|
|
static const EGLint attribs[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2, /* Use version 2, even for GLES3. */
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2016-03-01 05:49:05 +00:00
|
|
|
#endif
|
2015-12-08 20:05:18 +00:00
|
|
|
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2014-10-27 13:35:23 +00:00
|
|
|
/* Pick some arbitrary default. */
|
2014-07-27 20:19:11 +00:00
|
|
|
if (!width || !fullscreen)
|
|
|
|
width = 1280;
|
|
|
|
if (!height || !fullscreen)
|
|
|
|
height = 1024;
|
|
|
|
|
2015-12-08 20:05:18 +00:00
|
|
|
viv->width = width;
|
|
|
|
viv->height = height;
|
2014-07-27 20:19:11 +00:00
|
|
|
|
2016-03-01 05:49:05 +00:00
|
|
|
#ifdef HAVE_EGL
|
|
|
|
if (!egl_create_context(&viv->egl, attribs))
|
2015-11-19 17:29:15 +00:00
|
|
|
{
|
|
|
|
egl_report_error();
|
|
|
|
goto error;
|
|
|
|
}
|
2016-03-01 05:49:05 +00:00
|
|
|
#endif
|
2015-11-19 17:29:15 +00:00
|
|
|
|
2016-07-08 12:29:16 +00:00
|
|
|
viv->native_window = fbCreateWindow(fbGetDisplayByIndex(0), 0, 0, 0, 0);
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2016-03-01 05:49:05 +00:00
|
|
|
#ifdef HAVE_EGL
|
2016-07-08 12:29:16 +00:00
|
|
|
if (!egl_create_surface(&viv->egl, viv->native_window))
|
2014-07-27 20:19:11 +00:00
|
|
|
goto error;
|
2016-03-01 05:49:05 +00:00
|
|
|
#endif
|
2014-07-27 20:19:11 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
RARCH_ERR("[Vivante fbdev]: EGL error: %d.\n", eglGetError());
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_vivante_destroy(data);
|
2014-07-27 20:19:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static void gfx_ctx_vivante_input_driver(void *data,
|
|
|
|
const input_driver_t **input, void **input_data)
|
2014-07-27 20:19:11 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*input = NULL;
|
|
|
|
*input_data = NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_vivante_bind_api(void *data,
|
|
|
|
enum gfx_ctx_api api, unsigned major, unsigned minor)
|
2014-07-27 20:19:11 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return api == GFX_CTX_OPENGL_ES_API;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_vivante_has_focus(void *data)
|
2014-07-27 20:19:11 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-18 21:32:14 +00:00
|
|
|
static bool gfx_ctx_vivante_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)enable;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:09:01 +00:00
|
|
|
static bool gfx_ctx_vivante_has_windowed(void *data)
|
2014-10-08 15:23:02 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-01 05:49:05 +00:00
|
|
|
static void gfx_ctx_vivante_set_swap_interval(void *data, unsigned swap_interval)
|
|
|
|
{
|
|
|
|
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
|
2016-07-08 12:29:16 +00:00
|
|
|
|
2016-03-01 05:49:05 +00:00
|
|
|
#ifdef HAVE_EGL
|
|
|
|
egl_set_swap_interval(&viv->egl, swap_interval);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-07-08 12:29:16 +00:00
|
|
|
static void gfx_ctx_vivante_swap_buffers(void *data)
|
|
|
|
{
|
|
|
|
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
|
|
|
|
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
egl_swap_buffers(&viv->egl);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-03-01 05:49:05 +00:00
|
|
|
static gfx_ctx_proc_t gfx_ctx_vivante_get_proc_address(const char *symbol)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
return egl_get_proc_address(symbol);
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_ctx_vivante_bind_hw_render(void *data, bool enable)
|
|
|
|
{
|
|
|
|
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
|
|
|
|
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
egl_bind_hw_render(&viv->egl, enable);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-05-05 03:35:35 +00:00
|
|
|
static uint32_t gfx_ctx_vivante_get_flags(void *data)
|
2016-05-05 15:35:28 +00:00
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_NONE);
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_ctx_vivante_set_flags(void *data, uint32_t flags)
|
2016-05-05 03:35:35 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
2014-07-27 20:19:11 +00:00
|
|
|
const gfx_ctx_driver_t gfx_ctx_vivante_fbdev = {
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_vivante_init,
|
|
|
|
gfx_ctx_vivante_destroy,
|
|
|
|
gfx_ctx_vivante_bind_api,
|
2016-03-01 05:49:05 +00:00
|
|
|
gfx_ctx_vivante_set_swap_interval,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_vivante_set_video_mode,
|
2016-03-01 05:49:05 +00:00
|
|
|
gfx_ctx_vivante_get_video_size,
|
2015-02-24 20:36:23 +00:00
|
|
|
NULL, /* get_video_output_size */
|
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2015-04-08 18:10:30 +00:00
|
|
|
NULL, /* get_metrics */
|
2015-02-24 18:58:14 +00:00
|
|
|
NULL,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_vivante_update_window_title,
|
|
|
|
gfx_ctx_vivante_check_window,
|
|
|
|
gfx_ctx_vivante_set_resize,
|
|
|
|
gfx_ctx_vivante_has_focus,
|
2015-01-18 21:32:14 +00:00
|
|
|
gfx_ctx_vivante_suppress_screensaver,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_vivante_has_windowed,
|
2016-03-01 05:49:05 +00:00
|
|
|
gfx_ctx_vivante_swap_buffers,
|
2014-10-08 16:09:01 +00:00
|
|
|
gfx_ctx_vivante_input_driver,
|
2016-03-01 05:49:05 +00:00
|
|
|
gfx_ctx_vivante_get_proc_address,
|
2014-07-27 20:19:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
"vivante-fbdev",
|
2016-05-05 03:35:35 +00:00
|
|
|
gfx_ctx_vivante_get_flags,
|
2016-05-05 15:35:28 +00:00
|
|
|
gfx_ctx_vivante_set_flags,
|
2016-08-31 13:02:07 +00:00
|
|
|
gfx_ctx_vivante_bind_hw_render,
|
|
|
|
NULL,
|
|
|
|
NULL
|
2014-07-27 20:19:11 +00:00
|
|
|
};
|