2012-10-05 01:19:39 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 18:06:50 +01:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2012-10-05 01:19:39 +02: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 05:45:50 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <sys/system_properties.h>
|
|
|
|
|
|
|
|
#include <formats/image.h>
|
2012-10-05 01:19:39 +02:00
|
|
|
|
|
|
|
#include "../../driver.h"
|
2013-02-16 12:30:26 +01:00
|
|
|
#include "../../general.h"
|
2015-03-15 02:47:23 +01:00
|
|
|
#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"
|
2012-10-05 01:19:39 +02:00
|
|
|
|
2015-09-16 05:45:50 +02:00
|
|
|
#include "../../frontend/drivers/platform_linux.h"
|
2012-10-05 01:19:39 +02:00
|
|
|
|
2015-04-21 00:57:51 +02:00
|
|
|
/* forward declaration */
|
2015-11-14 19:22:15 +01:00
|
|
|
int system_property_get(const char *cmd, const char *args, char *value);
|
2015-04-21 00:57:51 +02:00
|
|
|
|
2014-04-14 13:17:05 +02:00
|
|
|
static bool g_es3;
|
2012-10-05 01:47:52 +02:00
|
|
|
|
2015-12-08 14:30:45 -03:00
|
|
|
static void *android_gfx_ctx_init(void *video_driver)
|
2012-10-05 01:19:39 +02:00
|
|
|
{
|
2015-11-19 17:55:49 +01:00
|
|
|
EGLint n, major, minor;
|
2015-01-10 17:51:00 +01:00
|
|
|
EGLint format;
|
|
|
|
EGLint context_attributes[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, g_es3 ? 3 : 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2012-10-05 01:19:39 +02:00
|
|
|
const EGLint attribs[] = {
|
2012-10-31 17:12:18 +01:00
|
|
|
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,
|
2014-02-13 12:04:08 +01:00
|
|
|
EGL_ALPHA_SIZE, 8,
|
2012-10-31 17:12:18 +01:00
|
|
|
EGL_NONE
|
2012-10-21 19:56:36 +02:00
|
|
|
};
|
2015-01-18 22:39:23 +01:00
|
|
|
struct android_app *android_app = (struct android_app*)g_android;
|
2015-12-08 14:30:45 -03:00
|
|
|
egl_ctx_data_t *egl;
|
|
|
|
|
2015-01-10 17:51:00 +01:00
|
|
|
if (!android_app)
|
|
|
|
return false;
|
2012-10-21 19:56:36 +02:00
|
|
|
|
2015-12-08 14:30:45 -03:00
|
|
|
egl = (egl_ctx_data_t*)calloc(1, sizeof(*egl));
|
|
|
|
|
2014-10-24 18:58:53 +02:00
|
|
|
RARCH_LOG("Android EGL: GLES version = %d.\n", g_es3 ? 3 : 2);
|
|
|
|
|
2015-12-08 14:30:45 -03:00
|
|
|
if (!egl_init_context(egl, EGL_DEFAULT_DISPLAY,
|
2015-11-19 17:55:49 +01:00
|
|
|
&major, &minor, &n, attribs))
|
2015-11-19 18:01:37 +01:00
|
|
|
{
|
|
|
|
egl_report_error();
|
2012-10-21 19:56:36 +02:00
|
|
|
goto error;
|
2015-11-19 18:01:37 +01:00
|
|
|
}
|
2012-10-21 19:56:36 +02:00
|
|
|
|
2015-12-08 14:30:45 -03:00
|
|
|
if (!egl_get_native_visual_id(egl, &format))
|
2012-10-21 19:56:36 +02:00
|
|
|
goto error;
|
|
|
|
|
2013-01-05 07:20:02 +01:00
|
|
|
ANativeWindow_setBuffersGeometry(android_app->window, 0, 0, format);
|
2012-10-21 19:56:36 +02:00
|
|
|
|
2015-12-08 14:30:45 -03:00
|
|
|
if (!egl_create_context(egl, context_attributes))
|
2012-11-09 09:42:52 +01:00
|
|
|
{
|
2015-11-19 18:25:19 +01:00
|
|
|
egl_report_error();
|
|
|
|
goto error;
|
2012-11-09 09:42:52 +01:00
|
|
|
}
|
2012-10-21 19:56:36 +02:00
|
|
|
|
2015-12-08 14:30:45 -03:00
|
|
|
if (!egl_create_surface(egl, android_app->window))
|
2012-10-21 19:56:36 +02:00
|
|
|
goto error;
|
|
|
|
|
2015-12-08 14:30:45 -03:00
|
|
|
return egl;
|
2012-10-21 19:56:36 +02:00
|
|
|
|
|
|
|
error:
|
2015-12-08 14:30:45 -03:00
|
|
|
if (egl)
|
|
|
|
{
|
|
|
|
egl_destroy(egl);
|
|
|
|
free(egl);
|
|
|
|
}
|
2014-10-24 18:58:53 +02:00
|
|
|
|
2015-12-08 14:30:45 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void android_gfx_ctx_destroy(void *data)
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
egl_destroy(data);
|
|
|
|
free(data);
|
|
|
|
}
|
2012-10-05 01:19:39 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void android_gfx_ctx_check_window(void *data, bool *quit,
|
2012-10-05 01:19:39 +02:00
|
|
|
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
|
|
|
|
{
|
2014-10-24 18:58:53 +02:00
|
|
|
unsigned new_width, new_height;
|
|
|
|
|
2012-10-05 01:19:39 +02:00
|
|
|
(void)frame_count;
|
2012-10-16 12:49:56 +02:00
|
|
|
|
|
|
|
*quit = false;
|
2012-12-27 23:30:27 +01:00
|
|
|
|
2015-11-19 15:21:04 +01:00
|
|
|
egl_get_video_size(data, &new_width, &new_height);
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2012-12-28 00:12:18 +01:00
|
|
|
if (new_width != *width || new_height != *height)
|
|
|
|
{
|
|
|
|
*width = new_width;
|
|
|
|
*height = new_height;
|
|
|
|
*resize = true;
|
|
|
|
}
|
2012-12-16 17:13:49 +01:00
|
|
|
|
2015-01-07 18:06:50 +01:00
|
|
|
/* Check if we are exiting. */
|
2015-12-04 12:44:12 +01:00
|
|
|
if (runloop_ctl(RUNLOOP_CTL_IS_SHUTDOWN, NULL))
|
2012-10-21 16:37:15 +02:00
|
|
|
*quit = true;
|
2012-10-05 01:19:39 +02:00
|
|
|
}
|
|
|
|
|
2014-10-24 18:58:53 +02:00
|
|
|
static void android_gfx_ctx_set_resize(void *data,
|
|
|
|
unsigned width, unsigned height)
|
2012-10-05 01:19:39 +02:00
|
|
|
{
|
2014-03-09 17:11:06 +01:00
|
|
|
(void)data;
|
2012-10-05 01:19:39 +02:00
|
|
|
(void)width;
|
|
|
|
(void)height;
|
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void android_gfx_ctx_update_window_title(void *data)
|
2012-10-05 01:19:39 +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();
|
2013-10-07 20:22:08 +02:00
|
|
|
|
2015-01-18 20:03:33 +01:00
|
|
|
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);
|
2012-10-05 01:19:39 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static bool android_gfx_ctx_set_video_mode(void *data,
|
2012-10-05 01:19:39 +02:00
|
|
|
unsigned width, unsigned height,
|
2012-11-20 23:23:18 +01:00
|
|
|
bool fullscreen)
|
2012-10-05 01:19:39 +02:00
|
|
|
{
|
2014-03-09 17:11:06 +01:00
|
|
|
(void)data;
|
2012-10-05 01:19:39 +02:00
|
|
|
(void)width;
|
|
|
|
(void)height;
|
|
|
|
(void)fullscreen;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void android_gfx_ctx_input_driver(void *data,
|
|
|
|
const input_driver_t **input, void **input_data)
|
2012-10-05 01:19:39 +02:00
|
|
|
{
|
2013-11-01 16:33:32 +01:00
|
|
|
void *androidinput = input_android.init();
|
2015-01-10 17:51:00 +01:00
|
|
|
|
|
|
|
(void)data;
|
|
|
|
|
2013-11-01 16:33:32 +01:00
|
|
|
*input = androidinput ? &input_android : NULL;
|
|
|
|
*input_data = androidinput;
|
2012-10-05 01:19:39 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static bool android_gfx_ctx_bind_api(void *data,
|
|
|
|
enum gfx_ctx_api api, unsigned major, unsigned minor)
|
2012-10-05 01:19:39 +02:00
|
|
|
{
|
2015-01-10 17:51:00 +01:00
|
|
|
unsigned version = major * 100 + minor;
|
|
|
|
|
2014-03-09 17:11:06 +01:00
|
|
|
(void)data;
|
2014-04-14 13:17:05 +02:00
|
|
|
|
|
|
|
if (version > 300)
|
|
|
|
return false;
|
|
|
|
if (version < 300)
|
|
|
|
g_es3 = false;
|
|
|
|
else if (version == 300)
|
|
|
|
g_es3 = true;
|
2012-10-05 01:19:39 +02:00
|
|
|
return api == GFX_CTX_OPENGL_ES_API;
|
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static bool android_gfx_ctx_has_focus(void *data)
|
2012-10-05 01:19:39 +02:00
|
|
|
{
|
2015-11-27 20:38:29 +01:00
|
|
|
struct android_app *android_app = (struct android_app*)g_android;
|
|
|
|
|
|
|
|
if (!android_app)
|
|
|
|
return true;
|
|
|
|
return (android_app->unfocused == true ) ? false : true;
|
2012-10-05 01:19:39 +02:00
|
|
|
}
|
|
|
|
|
2015-01-18 22:32:14 +01:00
|
|
|
static bool android_gfx_ctx_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)enable;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static bool android_gfx_ctx_has_windowed(void *data)
|
2014-10-08 17:23:02 +02:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-02 18:28:51 +02:00
|
|
|
static void dpi_get_density(char *s, size_t len)
|
2015-04-21 00:57:51 +02:00
|
|
|
{
|
2015-11-14 19:22:15 +01:00
|
|
|
system_property_get("getprop", "ro.sf.lcd_density", s);
|
2015-04-21 00:57:51 +02:00
|
|
|
|
2015-06-02 18:28:51 +02:00
|
|
|
if (s[0] == '\0')
|
2015-11-14 19:22:15 +01:00
|
|
|
system_property_get("wm", "density", s);
|
2015-04-21 00:57:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool android_gfx_ctx_get_metrics(void *data,
|
|
|
|
enum display_metric_types type, float *value)
|
|
|
|
{
|
2015-11-14 03:18:00 +01:00
|
|
|
static int dpi = -1;
|
2015-06-13 02:10:06 +02:00
|
|
|
char density[PROP_VALUE_MAX] = {0};
|
2015-04-09 03:27:28 +02:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case DISPLAY_METRIC_MM_WIDTH:
|
|
|
|
return false;
|
|
|
|
case DISPLAY_METRIC_MM_HEIGHT:
|
|
|
|
return false;
|
|
|
|
case DISPLAY_METRIC_DPI:
|
2015-11-14 03:18:00 +01:00
|
|
|
if (dpi == -1)
|
|
|
|
{
|
|
|
|
dpi_get_density(density, sizeof(density));
|
|
|
|
if (density[0] == '\0')
|
|
|
|
return false;
|
|
|
|
dpi = atoi(density);
|
|
|
|
}
|
2015-04-21 00:57:51 +02:00
|
|
|
*value = (float)dpi;
|
2015-04-09 03:27:28 +02:00
|
|
|
break;
|
|
|
|
case DISPLAY_METRIC_NONE:
|
|
|
|
default:
|
|
|
|
*value = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-05 01:19:39 +02:00
|
|
|
const gfx_ctx_driver_t gfx_ctx_android = {
|
2014-10-08 18:09:01 +02:00
|
|
|
android_gfx_ctx_init,
|
2015-12-08 14:30:45 -03:00
|
|
|
android_gfx_ctx_destroy,
|
2014-10-08 18:09:01 +02:00
|
|
|
android_gfx_ctx_bind_api,
|
2015-11-19 15:16:37 +01:00
|
|
|
egl_set_swap_interval,
|
2014-10-08 18:09:01 +02:00
|
|
|
android_gfx_ctx_set_video_mode,
|
2015-11-19 15:21:04 +01:00
|
|
|
egl_get_video_size,
|
2015-02-24 21:36:23 +01:00
|
|
|
NULL, /* get_video_output_size */
|
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2015-04-09 03:27:28 +02:00
|
|
|
android_gfx_ctx_get_metrics,
|
2015-02-24 19:58:14 +01:00
|
|
|
NULL,
|
2014-10-08 18:09:01 +02:00
|
|
|
android_gfx_ctx_update_window_title,
|
|
|
|
android_gfx_ctx_check_window,
|
|
|
|
android_gfx_ctx_set_resize,
|
|
|
|
android_gfx_ctx_has_focus,
|
2015-01-18 22:32:14 +01:00
|
|
|
android_gfx_ctx_suppress_screensaver,
|
2014-10-08 18:09:01 +02:00
|
|
|
android_gfx_ctx_has_windowed,
|
2015-11-19 14:38:55 +01:00
|
|
|
egl_swap_buffers,
|
2014-10-08 18:09:01 +02:00
|
|
|
android_gfx_ctx_input_driver,
|
2015-11-19 13:24:51 +01:00
|
|
|
egl_get_proc_address,
|
2014-03-09 17:11:06 +01:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2013-03-29 13:46:11 +01:00
|
|
|
NULL,
|
2012-10-05 01:19:39 +02:00
|
|
|
"android",
|
2015-11-19 14:32:39 +01:00
|
|
|
egl_bind_hw_render,
|
2012-10-05 01:19:39 +02:00
|
|
|
};
|