mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 16:20:27 +00:00
(VC EGL) Cleanups
This commit is contained in:
parent
fb257eb21e
commit
f97d6ec909
@ -56,26 +56,23 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
bool smooth;
|
||||||
|
bool vsync_callback_set;
|
||||||
|
bool resize;
|
||||||
|
unsigned res;
|
||||||
|
unsigned fb_width, fb_height;
|
||||||
#ifdef HAVE_EGL
|
#ifdef HAVE_EGL
|
||||||
egl_ctx_data_t egl;
|
egl_ctx_data_t egl;
|
||||||
#endif
|
#endif
|
||||||
EGL_DISPMANX_WINDOW_T native_window;
|
EGL_DISPMANX_WINDOW_T native_window;
|
||||||
DISPMANX_DISPLAY_HANDLE_T dispman_display;
|
DISPMANX_DISPLAY_HANDLE_T dispman_display;
|
||||||
|
|
||||||
/* For vsync wait after eglSwapBuffers when max_swapchain < 3 */
|
/* For vsync wait after eglSwapBuffers when max_swapchain < 3 */
|
||||||
scond_t *vsync_condition;
|
scond_t *vsync_condition;
|
||||||
slock_t *vsync_condition_mutex;
|
slock_t *vsync_condition_mutex;
|
||||||
bool vsync_callback_set;
|
|
||||||
|
|
||||||
bool resize;
|
|
||||||
unsigned fb_width, fb_height;
|
|
||||||
|
|
||||||
EGLImageKHR eglBuffer[MAX_EGLIMAGE_TEXTURES];
|
EGLImageKHR eglBuffer[MAX_EGLIMAGE_TEXTURES];
|
||||||
EGLContext eglimage_ctx;
|
EGLContext eglimage_ctx;
|
||||||
EGLSurface pbuff_surf;
|
EGLSurface pbuff_surf;
|
||||||
VGImage vgimage[MAX_EGLIMAGE_TEXTURES];
|
VGImage vgimage[MAX_EGLIMAGE_TEXTURES];
|
||||||
bool smooth;
|
|
||||||
unsigned res;
|
|
||||||
} vc_ctx_data_t;
|
} vc_ctx_data_t;
|
||||||
|
|
||||||
static enum gfx_ctx_api vc_api;
|
static enum gfx_ctx_api vc_api;
|
||||||
@ -85,7 +82,7 @@ static PFNEGLDESTROYIMAGEKHRPROC peglDestroyImageKHR;
|
|||||||
static INLINE bool gfx_ctx_vc_egl_query_extension(vc_ctx_data_t *vc, const char *ext)
|
static INLINE bool gfx_ctx_vc_egl_query_extension(vc_ctx_data_t *vc, const char *ext)
|
||||||
{
|
{
|
||||||
const char *str = (const char*)eglQueryString(vc->egl.dpy, EGL_EXTENSIONS);
|
const char *str = (const char*)eglQueryString(vc->egl.dpy, EGL_EXTENSIONS);
|
||||||
bool ret = str && strstr(str, ext);
|
bool ret = str && strstr(str, ext);
|
||||||
RARCH_LOG("Querying EGL extension: %s => %s\n",
|
RARCH_LOG("Querying EGL extension: %s => %s\n",
|
||||||
ext, ret ? "exists" : "doesn't exist");
|
ext, ret ? "exists" : "doesn't exist");
|
||||||
|
|
||||||
@ -107,7 +104,7 @@ static void gfx_ctx_vc_check_window(void *data, bool *quit,
|
|||||||
static void gfx_ctx_vc_get_video_size(void *data,
|
static void gfx_ctx_vc_get_video_size(void *data,
|
||||||
unsigned *width, unsigned *height)
|
unsigned *width, unsigned *height)
|
||||||
{
|
{
|
||||||
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
|
|
||||||
/* Use dispmanx upscaling if
|
/* Use dispmanx upscaling if
|
||||||
@ -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;
|
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
||||||
|
|
||||||
|
if (!vc)
|
||||||
|
return;
|
||||||
|
|
||||||
slock_lock(vc->vsync_condition_mutex);
|
slock_lock(vc->vsync_condition_mutex);
|
||||||
scond_signal(vc->vsync_condition);
|
scond_signal(vc->vsync_condition);
|
||||||
slock_unlock(vc->vsync_condition_mutex);
|
slock_unlock(vc->vsync_condition_mutex);
|
||||||
@ -228,50 +228,52 @@ static void *gfx_ctx_vc_init(video_frame_info_t *video_info, void *video_driver)
|
|||||||
if (graphics_get_display_size(0 /* LCD */, &vc->fb_width, &vc->fb_height) < 0)
|
if (graphics_get_display_size(0 /* LCD */, &vc->fb_width, &vc->fb_height) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
dst_rect.x = 0;
|
dst_rect.x = 0;
|
||||||
dst_rect.y = 0;
|
dst_rect.y = 0;
|
||||||
dst_rect.width = vc->fb_width;
|
dst_rect.width = vc->fb_width;
|
||||||
dst_rect.height = vc->fb_height;
|
dst_rect.height = vc->fb_height;
|
||||||
|
|
||||||
src_rect.x = 0;
|
src_rect.x = 0;
|
||||||
src_rect.y = 0;
|
src_rect.y = 0;
|
||||||
|
|
||||||
/* Use dispmanx upscaling if fullscreen_x
|
/* Use dispmanx upscaling if fullscreen_x
|
||||||
* and fullscreen_y are set. */
|
* and fullscreen_y are set. */
|
||||||
if (settings->uints.video_fullscreen_x != 0 &&
|
if ((settings->uints.video_fullscreen_x != 0) &&
|
||||||
settings->uints.video_fullscreen_y != 0)
|
(settings->uints.video_fullscreen_y != 0))
|
||||||
{
|
{
|
||||||
/* Keep input and output aspect ratio equal.
|
/* Keep input and output aspect ratio equal.
|
||||||
* There are other aspect ratio settings which can be used to stretch video output. */
|
* There are other aspect ratio settings which can be used to stretch video output. */
|
||||||
|
|
||||||
/* Calculate source and destination aspect ratios. */
|
/* Calculate source and destination aspect ratios. */
|
||||||
float srcAspect = (float)settings->uints.video_fullscreen_x / (float)settings->uints.video_fullscreen_y;
|
float srcAspect = (float)settings->uints.video_fullscreen_x / (float)settings->uints.video_fullscreen_y;
|
||||||
float dstAspect = (float)vc->fb_width / (float)vc->fb_height;
|
float dstAspect = (float)vc->fb_width / (float)vc->fb_height;
|
||||||
/* If source and destination aspect ratios are not equal correct source width. */
|
/* If source and destination aspect ratios are not equal correct source width. */
|
||||||
if (srcAspect != dstAspect)
|
if (srcAspect != dstAspect)
|
||||||
src_rect.width = (unsigned)(settings->uints.video_fullscreen_y * dstAspect) << 16;
|
src_rect.width = (unsigned)(settings->uints.video_fullscreen_y * dstAspect) << 16;
|
||||||
else
|
else
|
||||||
src_rect.width = settings->uints.video_fullscreen_x << 16;
|
src_rect.width = settings->uints.video_fullscreen_x << 16;
|
||||||
src_rect.height = settings->uints.video_fullscreen_y << 16;
|
src_rect.height = settings->uints.video_fullscreen_y << 16;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
src_rect.width = vc->fb_width << 16;
|
src_rect.width = vc->fb_width << 16;
|
||||||
src_rect.height = vc->fb_height << 16;
|
src_rect.height = vc->fb_height << 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispman_display = vc_dispmanx_display_open(0 /* LCD */);
|
dispman_display = vc_dispmanx_display_open(0 /* LCD */);
|
||||||
vc->dispman_display = dispman_display;
|
vc->dispman_display = dispman_display;
|
||||||
|
|
||||||
vc_dispmanx_display_get_info(dispman_display, &dispman_modeinfo);
|
vc_dispmanx_display_get_info(dispman_display, &dispman_modeinfo);
|
||||||
dispman_update = vc_dispmanx_update_start(0);
|
|
||||||
|
|
||||||
alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
|
dispman_update = vc_dispmanx_update_start(0);
|
||||||
alpha.opacity = 255;
|
|
||||||
alpha.mask = 0;
|
|
||||||
|
|
||||||
dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display,
|
alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
|
||||||
0 /*layer*/, &dst_rect, 0 /*src*/,
|
alpha.opacity = 255;
|
||||||
&src_rect, DISPMANX_PROTECTION_NONE, &alpha, 0 /*clamp*/, DISPMANX_NO_ROTATE);
|
alpha.mask = 0;
|
||||||
|
|
||||||
|
dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display,
|
||||||
|
0 /*layer*/, &dst_rect, 0 /*src*/,
|
||||||
|
&src_rect, DISPMANX_PROTECTION_NONE, &alpha, 0 /*clamp*/, DISPMANX_NO_ROTATE);
|
||||||
|
|
||||||
vc->native_window.element = dispman_element;
|
vc->native_window.element = dispman_element;
|
||||||
|
|
||||||
@ -311,10 +313,13 @@ static void *gfx_ctx_vc_init(video_frame_info_t *video_info, void *video_driver)
|
|||||||
/* For vsync after eglSwapBuffers when max_swapchain < 3 */
|
/* For vsync after eglSwapBuffers when max_swapchain < 3 */
|
||||||
vc->vsync_condition = scond_new();
|
vc->vsync_condition = scond_new();
|
||||||
vc->vsync_condition_mutex = slock_new();
|
vc->vsync_condition_mutex = slock_new();
|
||||||
vc->vsync_callback_set = false;
|
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 */
|
/* 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;
|
vc->vsync_callback_set = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,9 +332,10 @@ error:
|
|||||||
|
|
||||||
static void gfx_ctx_vc_set_swap_interval(void *data, unsigned swap_interval)
|
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
|
#ifdef HAVE_EGL
|
||||||
egl_set_swap_interval(&vc->egl, swap_interval);
|
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
||||||
|
if (vc)
|
||||||
|
egl_set_swap_interval(&vc->egl, swap_interval);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,11 +344,9 @@ static bool gfx_ctx_vc_set_video_mode(void *data,
|
|||||||
unsigned width, unsigned height,
|
unsigned width, unsigned height,
|
||||||
bool fullscreen)
|
bool fullscreen)
|
||||||
{
|
{
|
||||||
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
|
||||||
|
|
||||||
#ifdef HAVE_EGL
|
#ifdef HAVE_EGL
|
||||||
|
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
||||||
if (g_egl_inited)
|
if (!vc || g_egl_inited)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
frontend_driver_install_signal_handler();
|
frontend_driver_install_signal_handler();
|
||||||
@ -462,14 +466,15 @@ static void gfx_ctx_vc_destroy(void *data)
|
|||||||
|
|
||||||
for (i = 0; i < MAX_EGLIMAGE_TEXTURES; i++)
|
for (i = 0; i < MAX_EGLIMAGE_TEXTURES; i++)
|
||||||
{
|
{
|
||||||
vc->eglBuffer[i] = NULL;
|
vc->eglBuffer[i] = NULL;
|
||||||
vc->vgimage[i] = 0;
|
vc->vgimage[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop generating vsync callbacks if we are doing so. Don't destroy the context while cbs are being generated! */
|
/* Stop generating vsync callbacks if we are doing so.
|
||||||
if (vc->vsync_callback_set) {
|
* Don't destroy the context while cbs are being generated! */
|
||||||
|
if (vc->vsync_callback_set)
|
||||||
vc_dispmanx_vsync_callback(vc->dispman_display, NULL, NULL);
|
vc_dispmanx_vsync_callback(vc->dispman_display, NULL, NULL);
|
||||||
}
|
|
||||||
/* Destroy mutexes and conditions. */
|
/* Destroy mutexes and conditions. */
|
||||||
slock_free(vc->vsync_condition_mutex);
|
slock_free(vc->vsync_condition_mutex);
|
||||||
scond_free(vc->vsync_condition);
|
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,
|
static bool gfx_ctx_vc_image_buffer_init(void *data,
|
||||||
const video_info_t *video)
|
const video_info_t *video)
|
||||||
{
|
{
|
||||||
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
|
||||||
EGLBoolean result;
|
EGLBoolean result;
|
||||||
|
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
||||||
EGLint pbufsurface_list[] =
|
EGLint pbufsurface_list[] =
|
||||||
{
|
{
|
||||||
EGL_WIDTH, vc->res,
|
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");
|
peglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)egl_get_proc_address("eglCreateImageKHR");
|
||||||
peglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)egl_get_proc_address("eglDestroyImageKHR");
|
peglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)egl_get_proc_address("eglDestroyImageKHR");
|
||||||
|
|
||||||
if (!peglCreateImageKHR || !peglDestroyImageKHR
|
if ( !peglCreateImageKHR ||
|
||||||
|| !gfx_ctx_vc_egl_query_extension(vc, "KHR_image"))
|
!peglDestroyImageKHR ||
|
||||||
|
!gfx_ctx_vc_egl_query_extension(vc, "KHR_image")
|
||||||
|
)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vc->res = video->input_scale * RARCH_SCALE_BASE;
|
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;
|
bool ret = false;
|
||||||
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
||||||
|
|
||||||
if (index >= MAX_EGLIMAGE_TEXTURES)
|
if (!vc || index >= MAX_EGLIMAGE_TEXTURES)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
eglBindAPI(EGL_OPENVG_API);
|
eglBindAPI(EGL_OPENVG_API);
|
||||||
@ -629,27 +636,32 @@ error:
|
|||||||
|
|
||||||
static void gfx_ctx_vc_swap_buffers(void *data, void *data2)
|
static void gfx_ctx_vc_swap_buffers(void *data, void *data2)
|
||||||
{
|
{
|
||||||
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
#ifdef HAVE_EGL
|
||||||
|
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
||||||
video_frame_info_t *video_info = (video_frame_info_t*)data2;
|
video_frame_info_t *video_info = (video_frame_info_t*)data2;
|
||||||
|
|
||||||
#ifdef HAVE_EGL
|
if (!vc)
|
||||||
|
return;
|
||||||
|
|
||||||
egl_swap_buffers(&vc->egl);
|
egl_swap_buffers(&vc->egl);
|
||||||
|
|
||||||
/* Wait for vsync immediately if we don't want egl_swap_buffers to triple-buffer */
|
/* 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! */
|
/* We DON'T wait to wait without callback function ready! */
|
||||||
if(!vc->vsync_callback_set) {
|
if (!vc->vsync_callback_set)
|
||||||
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;
|
vc->vsync_callback_set = true;
|
||||||
}
|
}
|
||||||
slock_lock(vc->vsync_condition_mutex);
|
slock_lock(vc->vsync_condition_mutex);
|
||||||
scond_wait(vc->vsync_condition, vc->vsync_condition_mutex);
|
scond_wait(vc->vsync_condition, vc->vsync_condition_mutex);
|
||||||
slock_unlock(vc->vsync_condition_mutex);
|
slock_unlock(vc->vsync_condition_mutex);
|
||||||
}
|
}
|
||||||
else if (vc->vsync_callback_set) {
|
/* Stop generating vsync callbacks from now on */
|
||||||
/* Stop generating vsync callbacks from now on */
|
else if (vc->vsync_callback_set)
|
||||||
vc_dispmanx_vsync_callback(vc->dispman_display, NULL, NULL);
|
vc_dispmanx_vsync_callback(vc->dispman_display, NULL, NULL);
|
||||||
}
|
|
||||||
#endif
|
#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;
|
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
|
||||||
|
|
||||||
|
if (!vc)
|
||||||
|
return;
|
||||||
|
|
||||||
#ifdef HAVE_EGL
|
#ifdef HAVE_EGL
|
||||||
egl_bind_hw_render(&vc->egl, enable);
|
egl_bind_hw_render(&vc->egl, enable);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user