2012-09-18 23:41:58 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2012-2014 - Michael Lelli
|
2012-09-18 23:41:58 +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/>.
|
|
|
|
*/
|
|
|
|
|
2012-09-26 13:59:00 +00:00
|
|
|
// VideoCore context, for Rasperry Pi.
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
#include "../../driver.h"
|
|
|
|
#include "../gfx_context.h"
|
|
|
|
#include "../gl_common.h"
|
|
|
|
#include "../gfx_common.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sched.h>
|
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
2012-10-18 22:59:56 +00:00
|
|
|
#include <EGL/eglext_brcm.h>
|
2012-10-20 01:24:28 +00:00
|
|
|
#include <VG/openvg.h>
|
2012-09-18 23:41:58 +00:00
|
|
|
#include <bcm_host.h>
|
|
|
|
|
|
|
|
static EGLContext g_egl_ctx;
|
|
|
|
static EGLSurface g_egl_surf;
|
|
|
|
static EGLDisplay g_egl_dpy;
|
|
|
|
static EGLConfig g_config;
|
|
|
|
|
|
|
|
static volatile sig_atomic_t g_quit;
|
|
|
|
static bool g_inited;
|
2012-09-26 13:59:00 +00:00
|
|
|
static unsigned g_interval;
|
2012-09-25 00:47:48 +00:00
|
|
|
static enum gfx_ctx_api g_api;
|
2012-09-18 23:41:58 +00:00
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
static unsigned g_fb_width;
|
2012-09-18 23:41:58 +00:00
|
|
|
static unsigned g_fb_height;
|
|
|
|
|
2012-10-20 03:08:53 +00:00
|
|
|
static EGLImageKHR eglBuffer[MAX_EGLIMAGE_TEXTURES];
|
2012-10-20 01:24:28 +00:00
|
|
|
static EGLContext g_eglimage_ctx;
|
|
|
|
static EGLSurface g_pbuff_surf;
|
2012-10-20 03:08:53 +00:00
|
|
|
static VGImage g_egl_vgimage[MAX_EGLIMAGE_TEXTURES];
|
|
|
|
static bool g_smooth;
|
|
|
|
static unsigned g_egl_res;
|
2012-10-18 22:59:56 +00:00
|
|
|
|
2012-10-20 20:36:43 +00:00
|
|
|
static PFNEGLCREATEIMAGEKHRPROC peglCreateImageKHR;
|
|
|
|
static PFNEGLDESTROYIMAGEKHRPROC peglDestroyImageKHR;
|
2012-10-18 22:59:56 +00:00
|
|
|
|
|
|
|
static inline bool gfx_ctx_egl_query_extension(const char *ext)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2012-10-18 22:59:56 +00:00
|
|
|
const char *str = (const char*)eglQueryString(g_egl_dpy, EGL_EXTENSIONS);
|
|
|
|
bool ret = str && strstr(str, ext);
|
|
|
|
RARCH_LOG("Querying EGL extension: %s => %s\n",
|
|
|
|
ext, ret ? "exists" : "doesn't exist");
|
|
|
|
|
|
|
|
return ret;
|
2012-10-20 01:24:28 +00:00
|
|
|
}
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
static void sighandler(int sig)
|
|
|
|
{
|
|
|
|
(void)sig;
|
|
|
|
g_quit = 1;
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_swap_interval(void *data, unsigned interval)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2012-09-26 13:59:00 +00:00
|
|
|
// Can be called before initialization.
|
|
|
|
// Some contexts require that swap interval is known at startup time.
|
|
|
|
g_interval = interval;
|
|
|
|
if (g_egl_dpy)
|
|
|
|
eglSwapInterval(g_egl_dpy, interval);
|
2012-09-18 23:41:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_check_window(void *data, bool *quit,
|
2012-09-18 23:41:58 +00:00
|
|
|
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
|
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2012-09-18 23:41:58 +00:00
|
|
|
(void)frame_count;
|
|
|
|
(void)width;
|
|
|
|
(void)height;
|
|
|
|
|
|
|
|
*resize = false;
|
|
|
|
*quit = g_quit;
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_swap_buffers(void *data)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2012-09-18 23:41:58 +00:00
|
|
|
eglSwapBuffers(g_egl_dpy, g_egl_surf);
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_set_resize(void *data, unsigned width, unsigned height)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2012-09-18 23:41:58 +00:00
|
|
|
(void)width;
|
|
|
|
(void)height;
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_update_window_title(void *data)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2013-10-07 19:54:29 +00:00
|
|
|
char buf[128], buf_fps[128];
|
2013-10-10 23:19:54 +00:00
|
|
|
bool fps_draw = g_settings.fps_show;
|
2013-10-07 19:54:29 +00:00
|
|
|
gfx_get_fps(buf, sizeof(buf), fps_draw ? buf_fps : NULL, sizeof(buf_fps));
|
2013-10-07 18:22:08 +00:00
|
|
|
|
2013-10-08 10:27:25 +00:00
|
|
|
if (fps_draw)
|
2013-10-07 18:22:08 +00:00
|
|
|
msg_queue_push(g_extern.msg_queue, buf_fps, 1, 1);
|
2012-09-18 23:41:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_get_video_size(void *data, unsigned *width, unsigned *height)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2012-09-18 23:41:58 +00:00
|
|
|
*width = g_fb_width;
|
|
|
|
*height = g_fb_height;
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_destroy(void *data);
|
2012-10-20 21:36:56 +00:00
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static bool gfx_ctx_init(void *data)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2012-09-25 00:47:48 +00:00
|
|
|
RARCH_LOG("[VC/EGL]: Initializing...\n");
|
2012-09-18 23:41:58 +00:00
|
|
|
if (g_inited)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[VC/EGL]: Attempted to re-initialize driver.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint num_config;
|
|
|
|
static EGL_DISPMANX_WINDOW_T nativewindow;
|
|
|
|
|
|
|
|
DISPMANX_ELEMENT_HANDLE_T dispman_element;
|
|
|
|
DISPMANX_DISPLAY_HANDLE_T dispman_display;
|
|
|
|
DISPMANX_UPDATE_HANDLE_T dispman_update;
|
|
|
|
DISPMANX_MODEINFO_T dispman_modeinfo;
|
|
|
|
VC_RECT_T dst_rect;
|
|
|
|
VC_RECT_T src_rect;
|
|
|
|
|
|
|
|
static const EGLint attribute_list[] =
|
|
|
|
{
|
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
|
|
|
EGL_ALPHA_SIZE, 8,
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2012-09-19 02:16:43 +00:00
|
|
|
static const EGLint context_attributes[] =
|
|
|
|
{
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2012-09-18 23:41:58 +00:00
|
|
|
bcm_host_init();
|
|
|
|
|
|
|
|
// get an EGL display connection
|
|
|
|
g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
2012-10-20 20:39:46 +00:00
|
|
|
if (!g_egl_dpy)
|
|
|
|
goto error;
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
// initialize the EGL display connection
|
2012-10-20 20:39:46 +00:00
|
|
|
if (!eglInitialize(g_egl_dpy, NULL, NULL))
|
|
|
|
goto error;
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
// get an appropriate EGL frame buffer configuration
|
2012-10-20 20:39:46 +00:00
|
|
|
if (!eglChooseConfig(g_egl_dpy, attribute_list, &g_config, 1, &num_config))
|
|
|
|
goto error;
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
// create an EGL rendering context
|
2012-09-25 00:47:48 +00:00
|
|
|
g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT, (g_api == GFX_CTX_OPENGL_ES_API) ? context_attributes : NULL);
|
2012-10-20 20:39:46 +00:00
|
|
|
if (!g_egl_ctx)
|
|
|
|
goto error;
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
// create an EGL window surface
|
2012-10-20 20:39:46 +00:00
|
|
|
if (graphics_get_display_size(0 /* LCD */, &g_fb_width, &g_fb_height) < 0)
|
|
|
|
goto error;
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
dst_rect.x = 0;
|
|
|
|
dst_rect.y = 0;
|
|
|
|
dst_rect.width = g_fb_width;
|
|
|
|
dst_rect.height = g_fb_height;
|
|
|
|
|
|
|
|
src_rect.x = 0;
|
|
|
|
src_rect.y = 0;
|
|
|
|
src_rect.width = g_fb_width << 16;
|
|
|
|
src_rect.height = g_fb_height << 16;
|
|
|
|
|
|
|
|
dispman_display = vc_dispmanx_display_open(0 /* LCD */);
|
|
|
|
vc_dispmanx_display_get_info(dispman_display, &dispman_modeinfo);
|
|
|
|
dispman_update = vc_dispmanx_update_start(0);
|
|
|
|
|
2012-09-25 01:25:31 +00:00
|
|
|
VC_DISPMANX_ALPHA_T alpha;
|
|
|
|
alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
|
|
|
|
alpha.opacity = 255;
|
|
|
|
alpha.mask = 0;
|
|
|
|
|
2012-09-18 23:41:58 +00:00
|
|
|
dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display,
|
|
|
|
0 /*layer*/, &dst_rect, 0 /*src*/,
|
2012-09-25 01:25:31 +00:00
|
|
|
&src_rect, DISPMANX_PROTECTION_NONE, &alpha, 0 /*clamp*/, DISPMANX_NO_ROTATE);
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
nativewindow.element = dispman_element;
|
|
|
|
nativewindow.width = g_fb_width;
|
|
|
|
nativewindow.height = g_fb_height;
|
|
|
|
vc_dispmanx_update_submit_sync(dispman_update);
|
|
|
|
|
|
|
|
g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_config, &nativewindow, NULL);
|
2012-10-20 20:39:46 +00:00
|
|
|
if (!g_egl_surf)
|
|
|
|
goto error;
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
// connect the context to the surface
|
2012-10-20 20:39:46 +00:00
|
|
|
if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx))
|
|
|
|
goto error;
|
2012-09-18 23:41:58 +00:00
|
|
|
|
|
|
|
return true;
|
2012-10-20 20:39:46 +00:00
|
|
|
|
|
|
|
error:
|
2014-03-09 16:11:06 +00:00
|
|
|
gfx_ctx_destroy(data);
|
2012-10-20 20:39:46 +00:00
|
|
|
return false;
|
2012-09-18 23:41:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static bool gfx_ctx_set_video_mode(void *data,
|
2012-09-18 23:41:58 +00:00
|
|
|
unsigned width, unsigned height,
|
2012-11-20 22:23:18 +00:00
|
|
|
bool fullscreen)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
|
|
|
if (g_inited)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
struct sigaction sa = {{0}};
|
|
|
|
sa.sa_handler = sighandler;
|
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sigaction(SIGINT, &sa, NULL);
|
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
gfx_ctx_swap_interval(data, g_interval);
|
2012-09-26 13:59:00 +00:00
|
|
|
|
2012-09-18 23:41:58 +00:00
|
|
|
g_inited = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static bool gfx_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor)
|
2012-10-20 03:08:53 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2013-06-22 13:06:56 +00:00
|
|
|
(void)major;
|
|
|
|
(void)minor;
|
2012-10-20 03:08:53 +00:00
|
|
|
g_api = api;
|
|
|
|
switch (api)
|
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
return eglBindAPI(EGL_OPENGL_API);
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
|
|
|
return eglBindAPI(EGL_OPENGL_ES_API);
|
|
|
|
case GFX_CTX_OPENVG_API:
|
|
|
|
return eglBindAPI(EGL_OPENVG_API);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_destroy(void *data)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2013-10-22 19:26:33 +00:00
|
|
|
unsigned i;
|
2012-09-18 23:41:58 +00:00
|
|
|
if (g_egl_dpy)
|
|
|
|
{
|
2013-10-22 19:26:33 +00:00
|
|
|
for (i = 0; i < MAX_EGLIMAGE_TEXTURES; i++)
|
2012-10-20 01:24:28 +00:00
|
|
|
{
|
2012-10-20 03:08:53 +00:00
|
|
|
if (eglBuffer[i] && peglDestroyImageKHR)
|
|
|
|
{
|
|
|
|
eglBindAPI(EGL_OPENVG_API);
|
|
|
|
eglMakeCurrent(g_egl_dpy, g_pbuff_surf, g_pbuff_surf, g_eglimage_ctx);
|
|
|
|
peglDestroyImageKHR(g_egl_dpy, eglBuffer[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_egl_vgimage[i])
|
|
|
|
{
|
|
|
|
eglBindAPI(EGL_OPENVG_API);
|
|
|
|
eglMakeCurrent(g_egl_dpy, g_pbuff_surf, g_pbuff_surf, g_eglimage_ctx);
|
|
|
|
vgDestroyImage(g_egl_vgimage[i]);
|
|
|
|
}
|
2012-10-20 01:24:28 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 23:41:58 +00:00
|
|
|
if (g_egl_ctx)
|
|
|
|
{
|
2014-03-13 10:01:46 +00:00
|
|
|
gfx_ctx_bind_api(data, g_api, 0, 0);
|
2012-09-18 23:41:58 +00:00
|
|
|
eglMakeCurrent(g_egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
eglDestroyContext(g_egl_dpy, g_egl_ctx);
|
|
|
|
}
|
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
if (g_eglimage_ctx)
|
|
|
|
{
|
2012-10-20 03:08:53 +00:00
|
|
|
eglBindAPI(EGL_OPENVG_API);
|
2012-10-20 01:24:28 +00:00
|
|
|
eglMakeCurrent(g_egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
eglDestroyContext(g_egl_dpy, g_eglimage_ctx);
|
|
|
|
}
|
|
|
|
|
2012-09-18 23:41:58 +00:00
|
|
|
if (g_egl_surf)
|
2012-10-20 01:24:28 +00:00
|
|
|
{
|
2014-03-13 10:01:46 +00:00
|
|
|
gfx_ctx_bind_api(data, g_api, 0, 0);
|
2012-09-18 23:41:58 +00:00
|
|
|
eglDestroySurface(g_egl_dpy, g_egl_surf);
|
2012-10-20 01:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_pbuff_surf)
|
|
|
|
{
|
2012-10-20 03:08:53 +00:00
|
|
|
eglBindAPI(EGL_OPENVG_API);
|
2012-10-20 01:24:28 +00:00
|
|
|
eglDestroySurface(g_egl_dpy, g_pbuff_surf);
|
|
|
|
}
|
|
|
|
|
2012-10-20 03:08:53 +00:00
|
|
|
eglBindAPI(EGL_OPENVG_API);
|
2012-10-20 01:24:28 +00:00
|
|
|
eglMakeCurrent(g_egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
2014-03-13 10:01:46 +00:00
|
|
|
gfx_ctx_bind_api(data, g_api, 0, 0);
|
2012-10-20 01:24:28 +00:00
|
|
|
eglMakeCurrent(g_egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
2012-09-18 23:41:58 +00:00
|
|
|
eglTerminate(g_egl_dpy);
|
|
|
|
}
|
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
g_egl_ctx = NULL;
|
2012-10-20 03:08:53 +00:00
|
|
|
g_eglimage_ctx = NULL;
|
2012-10-20 01:24:28 +00:00
|
|
|
g_egl_surf = NULL;
|
|
|
|
g_pbuff_surf = NULL;
|
|
|
|
g_egl_dpy = NULL;
|
|
|
|
g_config = 0;
|
|
|
|
g_inited = false;
|
2012-10-20 03:08:53 +00:00
|
|
|
|
2013-10-22 19:26:33 +00:00
|
|
|
for (i = 0; i < MAX_EGLIMAGE_TEXTURES; i++)
|
2012-10-20 03:08:53 +00:00
|
|
|
{
|
|
|
|
eglBuffer[i] = NULL;
|
|
|
|
g_egl_vgimage[i] = 0;
|
|
|
|
}
|
2012-09-18 23:41:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_input_driver(void *data, const input_driver_t **input, void **input_data)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2014-01-24 09:23:48 +00:00
|
|
|
*input = NULL;
|
|
|
|
*input_data = NULL;
|
2012-09-18 23:41:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static bool gfx_ctx_has_focus(void *data)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2012-09-24 23:26:22 +00:00
|
|
|
return g_inited;
|
2012-09-18 23:41:58 +00:00
|
|
|
}
|
|
|
|
|
2012-09-24 23:26:22 +00:00
|
|
|
static gfx_ctx_proc_t gfx_ctx_get_proc_address(const char *symbol)
|
2012-09-18 23:41:58 +00:00
|
|
|
{
|
2012-09-24 23:26:22 +00:00
|
|
|
return eglGetProcAddress(symbol);
|
2012-09-18 23:41:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static float gfx_ctx_translate_aspect(void *data, unsigned width, unsigned height)
|
2012-09-25 11:51:44 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2012-09-25 11:51:44 +00:00
|
|
|
// check for SD televisions: they should always be 4:3.
|
|
|
|
if ((width == 640 || width == 720) && (height == 480 || height == 576))
|
|
|
|
return 4.0f / 3.0f;
|
|
|
|
else
|
|
|
|
return (float)width / height;
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static bool gfx_ctx_init_egl_image_buffer(void *data, const video_info_t *video)
|
2012-10-18 22:59:56 +00:00
|
|
|
{
|
2012-10-20 01:24:28 +00:00
|
|
|
if (g_api == GFX_CTX_OPENVG_API) // don't bother, we just use VGImages for our EGLImage anyway
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
peglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)gfx_ctx_get_proc_address("eglCreateImageKHR");
|
2012-10-18 22:59:56 +00:00
|
|
|
peglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)gfx_ctx_get_proc_address("eglDestroyImageKHR");
|
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
if (!peglCreateImageKHR || !peglDestroyImageKHR || !gfx_ctx_egl_query_extension("KHR_image"))
|
2012-10-18 22:59:56 +00:00
|
|
|
{
|
2012-10-20 01:24:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-18 22:59:56 +00:00
|
|
|
|
2012-10-20 03:08:53 +00:00
|
|
|
g_egl_res = video->input_scale * RARCH_SCALE_BASE;
|
2012-10-18 22:59:56 +00:00
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
EGLint pbufsurface_list[] =
|
|
|
|
{
|
2012-10-20 03:08:53 +00:00
|
|
|
EGL_WIDTH, g_egl_res,
|
|
|
|
EGL_HEIGHT, g_egl_res,
|
2012-10-20 01:24:28 +00:00
|
|
|
EGL_NONE
|
|
|
|
};
|
2012-10-18 22:59:56 +00:00
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
EGLBoolean result;
|
2012-10-18 22:59:56 +00:00
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
eglBindAPI(EGL_OPENVG_API);
|
|
|
|
g_pbuff_surf = eglCreatePbufferSurface(g_egl_dpy, g_config, pbufsurface_list);
|
|
|
|
if (g_pbuff_surf == EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[VideoCore:EGLImage] failed to create PbufferSurface\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-10-18 22:59:56 +00:00
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
g_eglimage_ctx = eglCreateContext(g_egl_dpy, g_config, NULL, NULL);
|
|
|
|
if (g_eglimage_ctx == EGL_NO_CONTEXT)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[VideoCore:EGLImage] failed to create context\n");
|
|
|
|
goto fail;
|
2012-10-18 22:59:56 +00:00
|
|
|
}
|
|
|
|
|
2012-10-20 03:08:53 +00:00
|
|
|
// test to make sure we can switch context
|
2012-10-20 01:24:28 +00:00
|
|
|
result = eglMakeCurrent(g_egl_dpy, g_pbuff_surf, g_pbuff_surf, g_eglimage_ctx);
|
|
|
|
if (result == EGL_FALSE)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[VideoCore:EGLImage] failed to make context current\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-03-13 10:01:46 +00:00
|
|
|
gfx_ctx_bind_api(data, g_api, 0, 0);
|
2012-10-20 01:24:28 +00:00
|
|
|
eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx);
|
|
|
|
|
2012-10-20 03:08:53 +00:00
|
|
|
g_smooth = video->smooth;
|
2012-10-20 01:24:28 +00:00
|
|
|
return true;
|
2012-10-20 03:08:53 +00:00
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
fail:
|
|
|
|
if (g_pbuff_surf != EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
eglDestroySurface(g_egl_dpy, g_pbuff_surf);
|
|
|
|
g_pbuff_surf = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_eglimage_ctx != EGL_NO_CONTEXT)
|
|
|
|
{
|
|
|
|
eglDestroyContext(g_egl_dpy, g_eglimage_ctx);
|
|
|
|
g_pbuff_surf = EGL_NO_CONTEXT;
|
|
|
|
}
|
|
|
|
|
2014-03-13 10:01:46 +00:00
|
|
|
gfx_ctx_bind_api(data, g_api, 0, 0);
|
2012-10-20 01:24:28 +00:00
|
|
|
eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx);
|
2012-10-18 22:59:56 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static bool gfx_ctx_write_egl_image(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, bool rgb32, unsigned index, void **image_handle)
|
2012-10-20 01:24:28 +00:00
|
|
|
{
|
2012-10-20 03:08:53 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (index >= MAX_EGLIMAGE_TEXTURES)
|
|
|
|
{
|
|
|
|
*image_handle = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-20 01:24:28 +00:00
|
|
|
eglBindAPI(EGL_OPENVG_API);
|
|
|
|
eglMakeCurrent(g_egl_dpy, g_pbuff_surf, g_pbuff_surf, g_eglimage_ctx);
|
|
|
|
|
2012-10-20 03:08:53 +00:00
|
|
|
if (!eglBuffer[index] || !g_egl_vgimage[index])
|
|
|
|
{
|
2012-10-20 10:22:10 +00:00
|
|
|
g_egl_vgimage[index] = vgCreateImage(rgb32 ? VG_sXRGB_8888 : VG_sRGB_565, g_egl_res, g_egl_res, VG_IMAGE_QUALITY_NONANTIALIASED);
|
2012-10-20 03:08:53 +00:00
|
|
|
eglBuffer[index] = peglCreateImageKHR(g_egl_dpy, g_eglimage_ctx, EGL_VG_PARENT_IMAGE_KHR, (EGLClientBuffer)g_egl_vgimage[index], NULL);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
2012-10-20 10:22:10 +00:00
|
|
|
vgImageSubData(g_egl_vgimage[index], frame, pitch, (rgb32 ? VG_sXRGB_8888 : VG_sRGB_565), 0, 0, width, height);
|
2012-10-20 03:08:53 +00:00
|
|
|
*image_handle = eglBuffer[index];
|
2012-10-20 01:24:28 +00:00
|
|
|
|
2014-03-15 15:04:23 +00:00
|
|
|
gfx_ctx_bind_api(data, g_api, 0, 0);
|
2012-10-20 01:24:28 +00:00
|
|
|
eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx);
|
|
|
|
|
2012-10-20 03:08:53 +00:00
|
|
|
return ret;
|
2012-10-20 01:24:28 +00:00
|
|
|
}
|
|
|
|
|
2012-09-24 23:26:22 +00:00
|
|
|
const gfx_ctx_driver_t gfx_ctx_videocore = {
|
|
|
|
gfx_ctx_init,
|
|
|
|
gfx_ctx_destroy,
|
|
|
|
gfx_ctx_bind_api,
|
|
|
|
gfx_ctx_swap_interval,
|
|
|
|
gfx_ctx_set_video_mode,
|
|
|
|
gfx_ctx_get_video_size,
|
2012-09-25 11:51:44 +00:00
|
|
|
gfx_ctx_translate_aspect,
|
2012-09-24 23:26:22 +00:00
|
|
|
gfx_ctx_update_window_title,
|
|
|
|
gfx_ctx_check_window,
|
|
|
|
gfx_ctx_set_resize,
|
|
|
|
gfx_ctx_has_focus,
|
|
|
|
gfx_ctx_swap_buffers,
|
|
|
|
gfx_ctx_input_driver,
|
|
|
|
gfx_ctx_get_proc_address,
|
2012-10-20 01:24:28 +00:00
|
|
|
gfx_ctx_init_egl_image_buffer,
|
2012-10-18 22:59:56 +00:00
|
|
|
gfx_ctx_write_egl_image,
|
2013-03-29 12:46:11 +00:00
|
|
|
NULL,
|
2012-09-24 23:26:22 +00:00
|
|
|
"videocore",
|
|
|
|
};
|