RetroArch/gfx/drivers_context/mali_fbdev_ctx.c

264 lines
6.2 KiB
C
Raw Normal View History

2014-06-05 12:28:17 +02:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
*
* 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 05:53:34 +02:00
#include <unistd.h>
2014-06-05 12:28:17 +02:00
2015-09-16 05:53:34 +02:00
#include <sys/ioctl.h>
2015-01-07 18:06:50 +01:00
/* Includes and defines for framebuffer size retrieval */
#include <linux/fb.h>
#include <linux/vt.h>
2015-09-16 05:53:34 +02:00
2015-09-18 03:55:44 +02:00
#include <retro_file.h>
2015-09-16 05:53:34 +02:00
#include "../../driver.h"
#include "../../general.h"
#include "../../runloop.h"
2015-11-19 13:24:51 +01:00
#include "../common/egl_common.h"
2015-11-17 08:01:33 +01:00
#include "../common/gl_common.h"
2015-12-08 17:32:08 -03:00
typedef struct {
egl_ctx_data_t egl;
fbdev_window native_window;
bool resize;
unsigned width, height;
} mali_ctx_data_t;
2014-06-05 12:28:17 +02:00
static void gfx_ctx_mali_fbdev_destroy(void *data)
2014-06-05 12:28:17 +02:00
{
2015-09-18 03:55:44 +02:00
int fb;
RFILE *fd;
2015-12-08 17:32:08 -03:00
mali_ctx_data_t *mali = (mali_ctx_data_t*)data;
2015-09-18 03:55:44 +02:00
2015-12-08 17:32:08 -03:00
if (mali)
{
egl_destroy(data);
2014-06-05 12:28:17 +02:00
2015-12-08 17:32:08 -03:00
mali->resize = false;
free(mali);
}
2015-01-07 18:06:50 +01:00
/* Clear framebuffer and set cursor on again */
2015-09-18 03:55:44 +02:00
fd = retro_fopen("/dev/tty", RFILE_MODE_READ_WRITE, -1);
fb = retro_get_fd(fd);
2015-09-18 03:55:44 +02:00
ioctl(fb, VT_ACTIVATE,5);
ioctl(fb, VT_ACTIVATE,1);
retro_fclose(fd);
system("setterm -cursor on");
2014-06-05 12:28:17 +02:00
}
static void gfx_ctx_mali_fbdev_get_video_size(void *data,
unsigned *width, unsigned *height)
2014-06-05 12:28:17 +02:00
{
2015-12-08 17:32:08 -03:00
mali_ctx_data_t *mali = (mali_ctx_data_t*)data;
2015-12-08 17:32:08 -03:00
*width = mali->width;
*height = mali->height;
2014-06-05 12:28:17 +02:00
}
static void *gfx_ctx_mali_fbdev_init(void *video_driver)
2014-06-05 12:28:17 +02:00
{
EGLint n;
EGLint major, minor;
EGLint format;
2014-06-05 12:28:17 +02:00
static const EGLint attribs[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_NONE
};
2015-09-09 19:58:05 +02:00
2015-12-08 17:32:08 -03:00
mali_ctx_data_t *mali = (mali_ctx_data_t*)calloc(1, sizeof(*mali));
if (!mali)
return NULL;
2015-11-19 15:55:57 +01:00
egl_install_sighandlers();
/* Disable cursor blinking so it's not visible in RetroArch. */
system("setterm -cursor off");
2015-12-08 17:32:08 -03:00
if (!egl_init_context(mali, EGL_DEFAULT_DISPLAY,
&major, &minor, &n, attribs))
2014-06-05 12:28:17 +02:00
{
egl_report_error();
2014-06-05 12:28:17 +02:00
goto error;
}
2015-12-08 17:32:08 -03:00
return mali;
2014-06-05 12:28:17 +02:00
error:
RARCH_ERR("[Mali fbdev]: EGL error: %d.\n", eglGetError());
gfx_ctx_mali_fbdev_destroy(video_driver);
return NULL;
2014-06-05 12:28:17 +02:00
}
static void gfx_ctx_mali_fbdev_check_window(void *data, bool *quit,
2014-06-05 12:28:17 +02:00
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
unsigned new_width, new_height;
2014-06-05 12:28:17 +02:00
(void)frame_count;
gfx_ctx_mali_fbdev_get_video_size(data, &new_width, &new_height);
2014-06-05 12:28:17 +02:00
if (new_width != *width || new_height != *height)
{
*width = new_width;
*height = new_height;
*resize = true;
}
2015-11-19 15:47:30 +01:00
*quit = g_egl_quit;
2014-06-05 12:28:17 +02:00
}
static void gfx_ctx_mali_fbdev_set_resize(void *data,
unsigned width, unsigned height)
2014-06-05 12:28:17 +02:00
{
(void)data;
(void)width;
(void)height;
}
static void gfx_ctx_mali_fbdev_update_window_title(void *data)
2014-06-05 12:28:17 +02:00
{
2015-06-13 02:10:06 +02:00
char buf[128] = {0};
char buf_fps[128] = {0};
2015-03-20 22:08:36 +01:00
settings_t *settings = config_get_ptr();
2014-06-05 12:28:17 +02:00
(void)data;
video_monitor_get_fps(buf, sizeof(buf),
2015-03-07 23:03:56 +01:00
buf_fps, sizeof(buf_fps));
2015-03-20 22:08:36 +01:00
if (settings->fps_show)
2015-12-07 15:32:14 +01:00
runloop_msg_queue_push(buf_fps, 1, 1, false);
2014-06-05 12:28:17 +02:00
}
static bool gfx_ctx_mali_fbdev_set_video_mode(void *data,
2014-06-05 12:28:17 +02:00
unsigned width, unsigned height,
bool fullscreen)
{
struct fb_var_screeninfo vinfo;
static const EGLint attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2, /* Use version 2, even for GLES3. */
EGL_NONE
};
2015-12-08 17:32:08 -03:00
mali_ctx_data_t *mali = (mali_ctx_data_t*)data;
2015-09-18 03:55:44 +02:00
RFILE *fd = retro_fopen("/dev/fb0", RFILE_MODE_READ_WRITE, -1);
int fb = retro_get_fd(fd);
if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0)
{
2015-11-19 18:36:24 +01:00
RARCH_ERR("Error obtaining framebuffer info.\n");
goto error;
}
2015-09-18 03:55:44 +02:00
retro_fclose(fd);
2015-04-03 04:40:53 +02:00
width = vinfo.xres;
height = vinfo.yres;
2014-06-05 12:28:17 +02:00
2015-12-08 17:32:08 -03:00
mali->width = width;
mali->height = height;
2014-06-05 15:05:43 +02:00
2015-12-08 17:32:08 -03:00
mali->native_window.width = vinfo.xres;
mali->native_window.height = vinfo.yres;
2015-12-08 17:32:08 -03:00
if (!egl_create_context(mali, attribs))
2014-06-05 12:28:17 +02:00
{
2015-11-19 18:36:24 +01:00
egl_report_error();
2014-06-05 12:28:17 +02:00
goto error;
}
2015-12-08 17:32:08 -03:00
if (!egl_create_surface(mali, &mali->native_window))
2014-06-05 12:28:17 +02:00
goto error;
return true;
error:
2015-09-18 03:55:44 +02:00
if (fd)
retro_fclose(fd);
2014-06-05 12:28:17 +02:00
RARCH_ERR("[Mali fbdev]: EGL error: %d.\n", eglGetError());
gfx_ctx_mali_fbdev_destroy(data);
2014-06-05 12:28:17 +02:00
return false;
}
static void gfx_ctx_mali_fbdev_input_driver(void *data,
const input_driver_t **input, void **input_data)
2014-06-05 12:28:17 +02:00
{
(void)data;
*input = NULL;
*input_data = NULL;
}
static bool gfx_ctx_mali_fbdev_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
2014-06-05 12:28:17 +02:00
{
(void)data;
return api == GFX_CTX_OPENGL_ES_API;
}
static bool gfx_ctx_mali_fbdev_has_focus(void *data)
2014-06-05 12:28:17 +02:00
{
(void)data;
return true;
}
2015-01-18 22:32:14 +01:00
static bool gfx_ctx_mali_fbdev_suppress_screensaver(void *data, bool enable)
{
(void)data;
(void)enable;
return false;
}
static bool gfx_ctx_mali_fbdev_has_windowed(void *data)
{
(void)data;
return false;
}
2014-06-05 12:28:17 +02:00
const gfx_ctx_driver_t gfx_ctx_mali_fbdev = {
gfx_ctx_mali_fbdev_init,
gfx_ctx_mali_fbdev_destroy,
gfx_ctx_mali_fbdev_bind_api,
2015-11-19 15:16:37 +01:00
egl_set_swap_interval,
gfx_ctx_mali_fbdev_set_video_mode,
gfx_ctx_mali_fbdev_get_video_size,
NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */
NULL, /* get_metrics */
NULL,
gfx_ctx_mali_fbdev_update_window_title,
gfx_ctx_mali_fbdev_check_window,
gfx_ctx_mali_fbdev_set_resize,
gfx_ctx_mali_fbdev_has_focus,
2015-01-18 22:32:14 +01:00
gfx_ctx_mali_fbdev_suppress_screensaver,
gfx_ctx_mali_fbdev_has_windowed,
2015-11-19 14:38:55 +01:00
egl_swap_buffers,
gfx_ctx_mali_fbdev_input_driver,
2015-11-19 13:24:51 +01:00
egl_get_proc_address,
2014-06-05 12:28:17 +02:00
NULL,
NULL,
NULL,
"mali-fbdev",
2015-11-19 18:36:24 +01:00
egl_bind_hw_render,
2014-06-05 12:28:17 +02:00
};