RetroArch/gfx/drivers_context/qnx_ctx.c

499 lines
11 KiB
C
Raw Normal View History

2013-02-26 14:12:03 +00:00
/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2017-01-22 12:40:32 +00:00
* Copyright (C) 2011-2017 - Daniel De Matteis
*
2013-02-26 14:12:03 +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 <stdint.h>
2013-02-26 14:12:03 +00:00
#include <bps/screen.h>
#include <bps/navigator.h>
#include <bps/event.h>
#include <screen/screen.h>
#include <sys/platform.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#ifdef HAVE_OPENGLES2
2015-09-16 03:53:34 +00:00
#include <GLES2/gl2.h>
#elif HAVE_OPENGLES3
#include <GLES3/gl3.h>
2016-05-19 18:02:39 +00:00
#endif
2016-09-11 13:10:58 +00:00
2016-05-19 18:02:39 +00:00
#ifdef HAVE_EGL
#include <EGL/egl.h>
#endif
2015-09-16 03:53:34 +00:00
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
#ifdef 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-05-28 19:14:11 +00:00
2017-01-10 20:15:52 +00:00
#include "../../configuration.h"
2019-02-02 21:02:24 +00:00
#include "../../verbosity.h"
2016-09-11 13:10:58 +00:00
2013-02-26 14:12:03 +00:00
#define WINDOW_BUFFERS 2
screen_context_t screen_ctx;
screen_window_t screen_win;
2016-02-14 15:29:58 +00:00
typedef struct
{
2016-03-01 05:49:05 +00:00
#ifdef HAVE_EGL
2016-02-14 15:29:58 +00:00
egl_ctx_data_t egl;
2016-03-01 05:49:05 +00:00
#endif
2016-02-14 15:29:58 +00:00
screen_display_t screen_disp;
bool resize;
} qnx_ctx_data_t;
2013-02-26 14:12:03 +00:00
2018-03-01 20:16:54 +00:00
static enum gfx_ctx_api qnx_api = GFX_CTX_NONE;
2014-05-17 12:36:15 +00:00
static void gfx_ctx_qnx_destroy(void *data)
2013-02-26 14:12:03 +00:00
{
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
2016-03-01 05:49:05 +00:00
#ifdef HAVE_EGL
egl_destroy(&qnx->egl);
#endif
free(data);
2013-02-26 14:12:03 +00:00
}
static void *gfx_ctx_qnx_init(video_frame_info_t *video_info, void *video_driver)
2013-02-26 14:12:03 +00:00
{
EGLint n;
EGLint major, minor;
EGLint context_attributes[] = {
#ifdef HAVE_OPENGLES2
EGL_CONTEXT_CLIENT_VERSION, 2,
#elif HAVE_OPENGLES3
EGL_CONTEXT_CLIENT_VERSION, 3,
#endif
EGL_NONE
};
const EGLint attribs[] = {
#ifdef HAVE_OPENGLES2
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#elif HAVE_OPENGLES3
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
#endif
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_NONE
};
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)calloc(1, sizeof(*qnx));
if (!qnx)
goto screen_error;
/* Create a screen context that will be used to
* create an EGL surface to receive libscreen events */
RARCH_LOG("Initializing screen context...\n");
if (!screen_ctx)
{
screen_create_context(&screen_ctx, 0);
if (screen_request_events(screen_ctx) != BPS_SUCCESS)
{
RARCH_ERR("screen_request_events failed.\n");
goto screen_error;
}
if (navigator_request_events(0) != BPS_SUCCESS)
{
RARCH_ERR("navigator_request_events failed.\n");
goto screen_error;
}
if (navigator_rotation_lock(false) != BPS_SUCCESS)
{
RARCH_ERR("navigator_location_lock failed.\n");
goto screen_error;
}
}
2016-03-01 05:49:05 +00:00
#ifdef HAVE_EGL
if (!egl_init_context(&qnx->egl, EGL_NONE, EGL_DEFAULT_DISPLAY, &major, &minor,
&n, attribs, NULL))
{
egl_report_error();
2013-02-26 14:12:03 +00:00
goto error;
}
2013-02-26 14:12:03 +00:00
2016-03-01 05:49:05 +00:00
if (!egl_create_context(&qnx->egl, context_attributes))
{
egl_report_error();
goto error;
2013-02-26 14:12:03 +00:00
}
2016-03-01 05:49:05 +00:00
#endif
2013-02-26 14:12:03 +00:00
if(!screen_win)
2013-02-26 14:12:03 +00:00
{
if (screen_create_window(&screen_win, screen_ctx))
{
RARCH_ERR("screen_create_window failed:.\n");
goto error;
}
2013-02-26 14:12:03 +00:00
}
int format = SCREEN_FORMAT_RGBX8888;
if (screen_set_window_property_iv(screen_win,
2016-02-14 15:29:58 +00:00
SCREEN_PROPERTY_FORMAT, &format))
2013-02-26 14:12:03 +00:00
{
RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_FORMAT] failed.\n");
goto error;
}
int usage;
#ifdef HAVE_OPENGLES2
usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
#elif HAVE_OPENGLES3
usage = SCREEN_USAGE_OPENGL_ES3 | SCREEN_USAGE_ROTATION;
#endif
if (screen_set_window_property_iv(screen_win,
2016-02-14 15:29:58 +00:00
SCREEN_PROPERTY_USAGE, &usage))
2013-02-26 14:12:03 +00:00
{
RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_USAGE] failed.\n");
goto error;
}
if (screen_get_window_property_pv(screen_win,
2016-02-14 15:29:58 +00:00
SCREEN_PROPERTY_DISPLAY, (void **)&qnx->screen_disp))
2013-02-26 14:12:03 +00:00
{
RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n");
goto error;
}
int screen_resolution[2];
2016-02-14 15:29:58 +00:00
if (screen_get_display_property_iv(qnx->screen_disp,
SCREEN_PROPERTY_SIZE, screen_resolution))
2013-02-26 14:12:03 +00:00
{
RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n");
goto error;
}
#ifndef HAVE_BB10
int angle, size[2];
angle = atoi(getenv("ORIENTATION"));
2013-02-26 14:12:03 +00:00
screen_display_mode_t screen_mode;
2016-02-14 15:29:58 +00:00
if (screen_get_display_property_pv(qnx->screen_disp,
SCREEN_PROPERTY_MODE, (void**)&screen_mode))
2013-02-26 14:12:03 +00:00
{
RARCH_ERR("screen_get_display_property_pv [SCREEN_PROPERTY_MODE] failed.\n");
goto error;
}
if (screen_get_window_property_iv(screen_win,
2016-02-14 15:29:58 +00:00
SCREEN_PROPERTY_BUFFER_SIZE, size))
{
2013-02-26 14:12:03 +00:00
RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
goto error;
}
int buffer_size[2] = {size[0], size[1]};
if ((angle == 0) || (angle == 180))
{
2013-02-26 14:12:03 +00:00
if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
((screen_mode.width < screen_mode.height) && (size[0] > size[1])))
{
2013-02-26 14:12:03 +00:00
buffer_size[1] = size[0];
buffer_size[0] = size[1];
}
}
else if ((angle == 90) || (angle == 270))
{
2013-02-26 14:12:03 +00:00
if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
((screen_mode.width < screen_mode.height && size[0] < size[1])))
{
2013-02-26 14:12:03 +00:00
buffer_size[1] = size[0];
buffer_size[0] = size[1];
}
}
else
{
2013-02-26 14:12:03 +00:00
RARCH_ERR("Navigator returned an unexpected orientation angle.\n");
goto error;
}
if (screen_set_window_property_iv(screen_win,
2016-02-14 15:29:58 +00:00
SCREEN_PROPERTY_BUFFER_SIZE, buffer_size))
2013-02-26 14:12:03 +00:00
{
RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
goto error;
}
if (screen_set_window_property_iv(screen_win,
2016-02-14 15:29:58 +00:00
SCREEN_PROPERTY_ROTATION, &angle))
2013-02-26 14:12:03 +00:00
{
RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_ROTATION] failed.\n");
goto error;
}
#endif
2013-02-26 14:12:03 +00:00
if (screen_create_window_buffers(screen_win, WINDOW_BUFFERS))
2013-02-26 14:12:03 +00:00
{
RARCH_ERR("screen_create_window_buffers failed.\n");
goto error;
}
if (!egl_create_surface(&qnx->egl, screen_win))
2013-02-26 14:12:03 +00:00
goto error;
return qnx;
2013-02-26 14:12:03 +00:00
error:
RARCH_ERR("EGL error: %d.\n", eglGetError());
gfx_ctx_qnx_destroy(video_driver);
screen_error:
screen_stop_events(screen_ctx);
return NULL;
2013-02-26 14:12:03 +00:00
}
static void gfx_ctx_qnx_get_video_size(void *data,
unsigned *width, unsigned *height)
{
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_get_video_size(&qnx->egl, width, height);
#endif
}
2014-05-17 12:36:15 +00:00
static void gfx_ctx_qnx_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height,
bool is_shutdown)
2013-02-26 14:12:03 +00:00
{
unsigned new_width, new_height;
2016-03-01 05:49:05 +00:00
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
2013-02-26 14:12:03 +00:00
*quit = false;
2016-03-01 05:49:05 +00:00
#ifdef HAVE_EGL
egl_get_video_size(&qnx->egl, &new_width, &new_height);
#endif
2013-02-26 14:12:03 +00:00
if (new_width != *width || new_height != *height)
{
*width = new_width;
*height = new_height;
*resize = true;
}
2014-10-27 13:35:23 +00:00
/* Check if we are exiting. */
if (is_shutdown)
2013-02-26 14:12:03 +00:00
*quit = true;
}
2014-05-17 12:36:15 +00:00
static bool gfx_ctx_qnx_set_video_mode(void *data,
2017-01-18 16:41:27 +00:00
video_frame_info_t *video_info,
2013-02-26 14:12:03 +00:00
unsigned width, unsigned height,
bool fullscreen)
{
2014-03-09 16:11:06 +00:00
(void)data;
2013-02-26 14:12:03 +00:00
(void)width;
(void)height;
(void)fullscreen;
return true;
}
2014-10-27 13:35:23 +00:00
static void gfx_ctx_qnx_input_driver(void *data,
const char *joypad_name,
2014-10-27 13:35:23 +00:00
const input_driver_t **input, void **input_data)
2013-02-26 14:12:03 +00:00
{
void *qnxinput = input_qnx.init(joypad_name);
2017-01-10 20:15:52 +00:00
*input = qnxinput ? &input_qnx : NULL;
*input_data = qnxinput;
2013-02-26 14:12:03 +00:00
}
2018-03-01 20:16:54 +00:00
static enum gfx_ctx_api gfx_ctx_qnx_get_api(void *data)
{
return qnx_api;
}
2014-10-27 13:35:23 +00:00
static bool gfx_ctx_qnx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
2013-02-26 14:12:03 +00:00
{
2014-03-09 16:11:06 +00:00
(void)data;
2018-03-01 20:16:54 +00:00
qnx_api = api;
if (api == GFX_CTX_OPENGL_ES_API)
return true;
return false;
2013-02-26 14:12:03 +00:00
}
2014-05-17 12:36:15 +00:00
static bool gfx_ctx_qnx_has_focus(void *data)
2013-02-26 14:12:03 +00:00
{
2014-03-09 16:11:06 +00:00
(void)data;
2013-02-26 14:12:03 +00:00
return true;
}
2015-01-18 21:32:14 +00:00
static bool gfx_ctx_qnx_suppress_screensaver(void *data, bool enable)
{
(void)data;
(void)enable;
return false;
}
static int dpi_get_density(qnx_ctx_data_t *qnx)
{
int screen_dpi[2];
if(!qnx)
return -1;
if (screen_get_display_property_iv(qnx->screen_disp,
SCREEN_PROPERTY_DPI, screen_dpi))
{
RARCH_ERR("screen_get_display_property_iv [SCREEN_PROPERTY_DPI] failed.\n");
return -1;
}
return min(screen_dpi[0], screen_dpi[1]);
}
static bool gfx_ctx_qnx__get_metrics(void *data,
enum display_metric_types type, float *value)
{
static int dpi = -1;
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
switch (type)
{
case DISPLAY_METRIC_MM_WIDTH:
return false;
case DISPLAY_METRIC_MM_HEIGHT:
return false;
case DISPLAY_METRIC_DPI:
if (dpi == -1)
{
dpi = dpi_get_density(qnx);
if (dpi <= 0)
goto dpi_fallback;
}
*value = (float)dpi;
break;
case DISPLAY_METRIC_NONE:
default:
*value = 0;
return false;
}
return true;
dpi_fallback:
/* Add a fallback in case the device doesn't report DPI.
* Calculated as an average of all BB10 device DPIs circa 2016. */
dpi = 345;
*value = (float)dpi;
return true;
}
2018-09-11 22:07:43 +00:00
static void gfx_ctx_qnx_set_swap_interval(void *data, int swap_interval)
2016-03-01 05:49:05 +00:00
{
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_set_swap_interval(&qnx->egl, swap_interval);
#endif
}
2017-05-19 01:34:53 +00:00
static void gfx_ctx_qnx_swap_buffers(void *data, void *data2)
2016-03-01 05:49:05 +00:00
{
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_swap_buffers(&qnx->egl);
#endif
}
static void gfx_ctx_qnx_bind_hw_render(void *data, bool enable)
{
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_bind_hw_render(&qnx->egl, enable);
#endif
}
static gfx_ctx_proc_t gfx_ctx_qnx_get_proc_address(const char *symbol)
{
#ifdef HAVE_EGL
return egl_get_proc_address(symbol);
#endif
}
static uint32_t gfx_ctx_qnx_get_flags(void *data)
{
2016-05-05 15:35:28 +00:00
uint32_t flags = 0;
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
2016-05-05 15:35:28 +00:00
return flags;
}
static void gfx_ctx_qnx_set_flags(void *data, uint32_t flags)
{
(void)flags;
}
const gfx_ctx_driver_t gfx_ctx_qnx = {
2014-05-17 12:36:15 +00:00
gfx_ctx_qnx_init,
gfx_ctx_qnx_destroy,
2018-03-01 20:16:54 +00:00
gfx_ctx_qnx_get_api,
2014-05-17 12:36:15 +00:00
gfx_ctx_qnx_bind_api,
2016-03-01 05:49:05 +00:00
gfx_ctx_qnx_set_swap_interval,
2014-05-17 12:36:15 +00:00
gfx_ctx_qnx_set_video_mode,
2016-03-01 05:49:05 +00:00
gfx_ctx_qnx_get_video_size,
NULL, /* get_refresh_rate */
NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */
gfx_ctx_qnx__get_metrics,
NULL,
2017-01-19 00:58:44 +00:00
NULL, /* update_title */
2014-05-17 12:36:15 +00:00
gfx_ctx_qnx_check_window,
NULL, /* set_resize */
2014-05-17 12:36:15 +00:00
gfx_ctx_qnx_has_focus,
2015-01-18 21:32:14 +00:00
gfx_ctx_qnx_suppress_screensaver,
2017-01-19 01:50:56 +00:00
NULL, /* has_windowed */
2016-03-01 05:49:05 +00:00
gfx_ctx_qnx_swap_buffers,
2014-05-17 12:36:15 +00:00
gfx_ctx_qnx_input_driver,
2016-03-01 05:49:05 +00:00
gfx_ctx_qnx_get_proc_address,
2014-05-17 12:36:15 +00:00
NULL,
NULL,
2013-03-29 12:46:11 +00:00
NULL,
"qnx",
gfx_ctx_qnx_get_flags,
2016-05-05 15:35:28 +00:00
gfx_ctx_qnx_set_flags,
2016-08-31 13:02:07 +00:00
gfx_ctx_qnx_bind_hw_render,
NULL,
NULL
2013-02-26 14:12:03 +00:00
};