(VC EGL) Cleanups

This commit is contained in:
twinaphex 2018-01-20 02:03:49 +01:00
parent fb257eb21e
commit f97d6ec909

View File

@ -56,26 +56,23 @@
typedef struct
{
bool smooth;
bool vsync_callback_set;
bool resize;
unsigned res;
unsigned fb_width, fb_height;
#ifdef HAVE_EGL
egl_ctx_data_t egl;
#endif
EGL_DISPMANX_WINDOW_T native_window;
DISPMANX_DISPLAY_HANDLE_T dispman_display;
/* For vsync wait after eglSwapBuffers when max_swapchain < 3 */
scond_t *vsync_condition;
slock_t *vsync_condition_mutex;
bool vsync_callback_set;
bool resize;
unsigned fb_width, fb_height;
EGLImageKHR eglBuffer[MAX_EGLIMAGE_TEXTURES];
EGLContext eglimage_ctx;
EGLSurface pbuff_surf;
VGImage vgimage[MAX_EGLIMAGE_TEXTURES];
bool smooth;
unsigned res;
} vc_ctx_data_t;
static enum gfx_ctx_api vc_api;
@ -145,6 +142,9 @@ static void dispmanx_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data)
{
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
if (!vc)
return;
slock_lock(vc->vsync_condition_mutex);
scond_signal(vc->vsync_condition);
slock_unlock(vc->vsync_condition_mutex);
@ -238,8 +238,8 @@ static void *gfx_ctx_vc_init(video_frame_info_t *video_info, void *video_driver)
/* Use dispmanx upscaling if fullscreen_x
* and fullscreen_y are set. */
if (settings->uints.video_fullscreen_x != 0 &&
settings->uints.video_fullscreen_y != 0)
if ((settings->uints.video_fullscreen_x != 0) &&
(settings->uints.video_fullscreen_y != 0))
{
/* Keep input and output aspect ratio equal.
* There are other aspect ratio settings which can be used to stretch video output. */
@ -262,7 +262,9 @@ static void *gfx_ctx_vc_init(video_frame_info_t *video_info, void *video_driver)
dispman_display = vc_dispmanx_display_open(0 /* LCD */);
vc->dispman_display = dispman_display;
vc_dispmanx_display_get_info(dispman_display, &dispman_modeinfo);
dispman_update = vc_dispmanx_update_start(0);
alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
@ -312,9 +314,12 @@ static void *gfx_ctx_vc_init(video_frame_info_t *video_info, void *video_driver)
vc->vsync_condition = scond_new();
vc->vsync_condition_mutex = slock_new();
vc->vsync_callback_set = false;
if (video_info->max_swapchain_images <= 2) {
if (video_info->max_swapchain_images <= 2)
{
/* Start sending vsync callbacks so we can wait for vsync after eglSwapBuffers */
vc_dispmanx_vsync_callback(vc->dispman_display, dispmanx_vsync_callback, (void*)vc);
vc_dispmanx_vsync_callback(vc->dispman_display,
dispmanx_vsync_callback, (void*)vc);
vc->vsync_callback_set = true;
}
@ -327,8 +332,9 @@ error:
static void gfx_ctx_vc_set_swap_interval(void *data, unsigned swap_interval)
{
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
#ifdef HAVE_EGL
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
if (vc)
egl_set_swap_interval(&vc->egl, swap_interval);
#endif
}
@ -338,11 +344,9 @@ static bool gfx_ctx_vc_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
{
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
#ifdef HAVE_EGL
if (g_egl_inited)
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
if (!vc || g_egl_inited)
return false;
frontend_driver_install_signal_handler();
@ -466,10 +470,11 @@ static void gfx_ctx_vc_destroy(void *data)
vc->vgimage[i] = 0;
}
/* Stop generating vsync callbacks if we are doing so. Don't destroy the context while cbs are being generated! */
if (vc->vsync_callback_set) {
/* Stop generating vsync callbacks if we are doing so.
* Don't destroy the context while cbs are being generated! */
if (vc->vsync_callback_set)
vc_dispmanx_vsync_callback(vc->dispman_display, NULL, NULL);
}
/* Destroy mutexes and conditions. */
slock_free(vc->vsync_condition_mutex);
scond_free(vc->vsync_condition);
@ -509,8 +514,8 @@ static float gfx_ctx_vc_translate_aspect(void *data,
static bool gfx_ctx_vc_image_buffer_init(void *data,
const video_info_t *video)
{
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
EGLBoolean result;
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
EGLint pbufsurface_list[] =
{
EGL_WIDTH, vc->res,
@ -525,8 +530,10 @@ static bool gfx_ctx_vc_image_buffer_init(void *data,
peglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)egl_get_proc_address("eglCreateImageKHR");
peglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)egl_get_proc_address("eglDestroyImageKHR");
if (!peglCreateImageKHR || !peglDestroyImageKHR
|| !gfx_ctx_vc_egl_query_extension(vc, "KHR_image"))
if ( !peglCreateImageKHR ||
!peglDestroyImageKHR ||
!gfx_ctx_vc_egl_query_extension(vc, "KHR_image")
)
return false;
vc->res = video->input_scale * RARCH_SCALE_BASE;
@ -585,7 +592,7 @@ static bool gfx_ctx_vc_image_buffer_write(void *data, const void *frame, unsigne
bool ret = false;
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
if (index >= MAX_EGLIMAGE_TEXTURES)
if (!vc || index >= MAX_EGLIMAGE_TEXTURES)
goto error;
eglBindAPI(EGL_OPENVG_API);
@ -629,27 +636,32 @@ error:
static void gfx_ctx_vc_swap_buffers(void *data, void *data2)
{
#ifdef HAVE_EGL
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
video_frame_info_t *video_info = (video_frame_info_t*)data2;
#ifdef HAVE_EGL
if (!vc)
return;
egl_swap_buffers(&vc->egl);
/* Wait for vsync immediately if we don't want egl_swap_buffers to triple-buffer */
if (video_info->max_swapchain_images <= 2) {
if (video_info->max_swapchain_images <= 2)
{
/* We DON'T wait to wait without callback function ready! */
if(!vc->vsync_callback_set) {
vc_dispmanx_vsync_callback(vc->dispman_display, dispmanx_vsync_callback, (void*)vc);
if (!vc->vsync_callback_set)
{
vc_dispmanx_vsync_callback(vc->dispman_display,
dispmanx_vsync_callback, (void*)vc);
vc->vsync_callback_set = true;
}
slock_lock(vc->vsync_condition_mutex);
scond_wait(vc->vsync_condition, vc->vsync_condition_mutex);
slock_unlock(vc->vsync_condition_mutex);
}
else if (vc->vsync_callback_set) {
/* Stop generating vsync callbacks from now on */
else if (vc->vsync_callback_set)
vc_dispmanx_vsync_callback(vc->dispman_display, NULL, NULL);
}
#endif
}
@ -657,6 +669,9 @@ static void gfx_ctx_vc_bind_hw_render(void *data, bool enable)
{
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
if (!vc)
return;
#ifdef HAVE_EGL
egl_bind_hw_render(&vc->egl, enable);
#endif