Have to rewrite EGL context code

This commit is contained in:
twinaphex 2016-03-01 06:49:05 +01:00
parent ae6302ede2
commit e938be3747
10 changed files with 475 additions and 138 deletions

View File

@ -63,9 +63,8 @@ gfx_ctx_proc_t egl_get_proc_address(const char *symbol)
return eglGetProcAddress(symbol);
}
void egl_destroy(void *data)
void egl_destroy(egl_ctx_data_t *egl)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
if (egl->dpy)
{
#if defined HAVE_OPENGL
@ -104,9 +103,8 @@ void egl_destroy(void *data)
g_egl_inited = false;
}
void egl_bind_hw_render(void *data, bool enable)
void egl_bind_hw_render(egl_ctx_data_t *egl, bool enable)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
egl->use_hw_ctx = enable;
if (egl->dpy == EGL_NO_DISPLAY)
@ -122,6 +120,7 @@ void egl_bind_hw_render(void *data, bool enable)
void egl_swap_buffers(void *data)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
if (egl->dpy == EGL_NO_DISPLAY)
return;
if (egl->surf == EGL_NO_SURFACE)
@ -129,9 +128,8 @@ void egl_swap_buffers(void *data)
eglSwapBuffers(egl->dpy, egl->surf);
}
void egl_set_swap_interval(void *data, unsigned interval)
void egl_set_swap_interval(egl_ctx_data_t *egl, unsigned interval)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
/* Can be called before initialization.
* Some contexts require that swap interval
* is known at startup time.
@ -151,10 +149,8 @@ void egl_set_swap_interval(void *data, unsigned interval)
}
}
void egl_get_video_size(void *data, unsigned *width, unsigned *height)
void egl_get_video_size(egl_ctx_data_t *egl, unsigned *width, unsigned *height)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
*width = 0;
*height = 0;
@ -188,11 +184,11 @@ void egl_install_sighandlers(void)
sigaction(SIGTERM, &sa, NULL);
}
bool egl_init_context(void *data, NativeDisplayType display,
bool egl_init_context(egl_ctx_data_t *egl,
NativeDisplayType display,
EGLint *major, EGLint *minor,
EGLint *n, const EGLint *attrib_ptr)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
egl->dpy = eglGetDisplay(display);
if (!egl->dpy)
{
@ -214,9 +210,8 @@ bool egl_init_context(void *data, NativeDisplayType display,
return true;
}
bool egl_create_context(void *data, const EGLint *egl_attribs)
bool egl_create_context(egl_ctx_data_t *egl, const EGLint *egl_attribs)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
egl->ctx = eglCreateContext(egl->dpy, egl->config, EGL_NO_CONTEXT,
egl_attribs);
egl->hw_ctx = NULL;
@ -237,9 +232,8 @@ bool egl_create_context(void *data, const EGLint *egl_attribs)
return true;
}
bool egl_create_surface(void *data, NativeWindowType native_window)
bool egl_create_surface(egl_ctx_data_t *egl, NativeWindowType native_window)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
egl->surf = eglCreateWindowSurface(egl->dpy, egl->config, native_window, NULL);
if (egl->surf == EGL_NO_SURFACE)
@ -254,9 +248,8 @@ bool egl_create_surface(void *data, NativeWindowType native_window)
return true;
}
bool egl_get_native_visual_id(void *data, EGLint *value)
bool egl_get_native_visual_id(egl_ctx_data_t *egl, EGLint *value)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
if (!eglGetConfigAttrib(egl->dpy, egl->config,
EGL_NATIVE_VISUAL_ID, value))
{
@ -267,9 +260,8 @@ bool egl_get_native_visual_id(void *data, EGLint *value)
return true;
}
bool egl_has_config(void *data)
bool egl_has_config(egl_ctx_data_t *egl)
{
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
if (!egl->config)
{
RARCH_ERR("[EGL]: No EGL configurations available.\n");

View File

@ -68,31 +68,34 @@ extern unsigned g_egl_minor;
void egl_report_error(void);
void egl_destroy(void *data);
void egl_destroy(egl_ctx_data_t *egl);
gfx_ctx_proc_t egl_get_proc_address(const char *symbol);
void egl_bind_hw_render(void *data, bool enable);
void egl_bind_hw_render(egl_ctx_data_t *egl, bool enable);
void egl_swap_buffers(void *data);
void egl_set_swap_interval(void *data, unsigned interval);
void egl_set_swap_interval(egl_ctx_data_t *egl, unsigned interval);
void egl_get_video_size(void *data, unsigned *width, unsigned *height);
void egl_get_video_size(egl_ctx_data_t *egl, unsigned *width, unsigned *height);
void egl_install_sighandlers(void);
bool egl_init_context(void *data, NativeDisplayType display,
EGLint *major, EGLint *minor,
EGLint *n, const EGLint *attrib_ptr);
bool egl_init_context(egl_ctx_data_t *egl,
NativeDisplayType display,
EGLint *major,
EGLint *minor,
EGLint *n,
const EGLint *attrib_ptr);
bool egl_create_context(void *data, const EGLint *egl_attribs);
bool egl_create_context(egl_ctx_data_t *egl, const EGLint *egl_attribs);
bool egl_create_surface(void *data, NativeWindowType native_window);
bool egl_create_surface(egl_ctx_data_t *egl, NativeWindowType native_window);
bool egl_get_native_visual_id(void *data, EGLint *value);
bool egl_get_native_visual_id(egl_ctx_data_t *egl, EGLint *value);
bool egl_has_config(void *data);
bool egl_has_config(egl_ctx_data_t *egl);
#ifdef __cplusplus
}

View File

@ -43,9 +43,15 @@ int system_property_get(const char *cmd, const char *args, char *value);
static bool g_es3;
#endif
#ifdef HAVE_ANDROID
static unsigned vk_swap_interval;
typedef struct
{
#ifdef HAVE_EGL
egl_ctx_data_t egl;
#endif
#ifdef HAVE_VULKAN
unsigned swap_interval;
#endif
} android_ctx_data_t;
static void *android_gfx_ctx_init(void *video_driver)
{
@ -65,11 +71,11 @@ static void *android_gfx_ctx_init(void *video_driver)
EGL_ALPHA_SIZE, 8,
EGL_NONE
};
egl_ctx_data_t *egl = NULL;
#endif
struct android_app *android_app = (struct android_app*)g_android;
android_ctx_data_t *and = (android_ctx_data_t*)calloc(1, sizeof(*and));
if (!android_app)
if (!android_app || !and)
return false;
switch (android_api)
@ -77,18 +83,16 @@ static void *android_gfx_ctx_init(void *video_driver)
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
egl = (egl_ctx_data_t*)calloc(1, sizeof(*egl));
RARCH_LOG("Android EGL: GLES version = %d.\n", g_es3 ? 3 : 2);
if (!egl_init_context(egl, EGL_DEFAULT_DISPLAY,
if (!egl_init_context(&and->egl, EGL_DEFAULT_DISPLAY,
&major, &minor, &n, attribs))
{
egl_report_error();
goto error;
}
if (!egl_get_native_visual_id(egl, &format))
if (!egl_get_native_visual_id(&and->egl, &format))
goto error;
#endif
break;
@ -108,13 +112,13 @@ static void *android_gfx_ctx_init(void *video_driver)
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
if (!egl_create_context(egl, context_attributes))
if (!egl_create_context(&and->egl, context_attributes))
{
egl_report_error();
goto unlock_error;
}
if (!egl_create_surface(egl, android_app->window))
if (!egl_create_surface(&and->egl, android_app->window))
goto unlock_error;
#endif
break;
@ -124,7 +128,7 @@ static void *android_gfx_ctx_init(void *video_driver)
}
slock_unlock(android_app->mutex);
return egl;
return and;
unlock_error:
slock_unlock(android_app->mutex);
@ -134,11 +138,7 @@ error:
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
if (egl)
{
egl_destroy(egl);
free(egl);
}
egl_destroy(&and->egl);
#endif
break;
case GFX_CTX_NONE:
@ -151,19 +151,23 @@ error:
static void android_gfx_ctx_destroy(void *data)
{
if (data)
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
if (!and)
return;
#ifdef HAVE_OPENGLES
egl_destroy(data);
egl_destroy(&and->egl);
#endif
free(data);
}
free(data);
}
static void android_gfx_ctx_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
unsigned new_width, new_height;
android_ctx_data_t *and = (android_ctx_data_t*)data;
(void)frame_count;
@ -174,7 +178,7 @@ static void android_gfx_ctx_check_window(void *data, bool *quit,
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_OPENGLES
egl_get_video_size(data, &new_width, &new_height);
egl_get_video_size(&and->egl, &new_width, &new_height);
#endif
break;
case GFX_CTX_NONE:
@ -338,13 +342,15 @@ static bool android_gfx_ctx_get_metrics(void *data,
static void android_gfx_ctx_swap_buffers(void *data)
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
switch (android_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
egl_swap_buffers(data);
egl_swap_buffers(&and->egl);
#endif
break;
case GFX_CTX_NONE:
@ -355,12 +361,14 @@ static void android_gfx_ctx_swap_buffers(void *data)
static void android_gfx_ctx_set_swap_interval(void *data, unsigned swap_interval)
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
switch (android_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
egl_set_swap_interval(data, swap_interval);
egl_set_swap_interval(&and->egl, swap_interval);
#endif
break;
case GFX_CTX_NONE:
@ -372,12 +380,14 @@ static void android_gfx_ctx_set_swap_interval(void *data, unsigned swap_interval
static void android_gfx_ctx_get_video_size(void *data,
unsigned *width, unsigned *height)
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
switch (android_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
egl_get_video_size(data, width, height);
egl_get_video_size(&and->egl, width, height);
#endif
break;
case GFX_CTX_NONE:
@ -407,12 +417,14 @@ static gfx_ctx_proc_t android_gfx_ctx_get_proc_address(const char *symbol)
static void android_gfx_ctx_bind_hw_render(void *data, bool enable)
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
switch (android_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
egl_bind_hw_render(data, enable);
egl_bind_hw_render(&and->egl, enable);
#endif
break;
case GFX_CTX_NONE:

View File

@ -27,8 +27,14 @@
#include "../../driver.h"
#include "../../general.h"
#include "../../runloop.h"
#ifdef HAVE_EGL
#include "../common/egl_common.h"
#endif
#ifdef HAVE_OPENGLES
#include "../common/gl_common.h"
#endif
#include "../image/image.h"
@ -38,7 +44,9 @@ screen_context_t screen_ctx;
typedef struct
{
#ifdef HAVE_EGL
egl_ctx_data_t egl;
#endif
screen_window_t screen_win;
screen_display_t screen_disp;
bool resize;
@ -47,7 +55,10 @@ typedef struct
static void gfx_ctx_qnx_destroy(void *data)
{
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
egl_destroy(data);
#ifdef HAVE_EGL
egl_destroy(&qnx->egl);
#endif
qnx->resize = false;
free(data);
@ -105,24 +116,26 @@ static void *gfx_ctx_qnx_init(void *video_driver)
usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
#ifdef HAVE_EGL
if (!eglBindAPI(EGL_OPENGL_ES_API))
{
RARCH_ERR("eglBindAPI failed.\n");
goto error;
}
if (!egl_init_context(qnx, EGL_DEFAULT_DISPLAY, &major, &minor,
if (!egl_init_context(&qnx->egl, EGL_DEFAULT_DISPLAY, &major, &minor,
&n, attribs))
{
egl_report_error();
goto error;
}
if (!egl_create_context(qnx, context_attributes))
if (!egl_create_context(&qnx->egl, context_attributes))
{
egl_report_error();
goto error;
}
#endif
if(!qnx->screen_win)
{
@ -246,13 +259,17 @@ static void gfx_ctx_qnx_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
unsigned new_width, new_height;
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
(void)data;
(void)frame_count;
*quit = false;
egl_get_video_size(data, &new_width, &new_height);
#ifdef HAVE_EGL
egl_get_video_size(&qnx->egl, &new_width, &new_height);
#endif
if (new_width != *width || new_height != *height)
{
*width = new_width;
@ -337,13 +354,57 @@ static bool gfx_ctx_qnx_has_windowed(void *data)
return false;
}
static void gfx_ctx_qnx_set_swap_interval(void *data, unsigned swap_interval)
{
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_set_swap_interval(&qnx->egl, swap_interval);
#endif
}
static void gfx_ctx_qnx_swap_buffers(void *data)
{
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 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
}
const gfx_ctx_driver_t gfx_ctx_bbqnx = {
gfx_ctx_qnx_init,
gfx_ctx_qnx_destroy,
gfx_ctx_qnx_bind_api,
egl_set_swap_interval,
gfx_ctx_qnx_set_swap_interval,
gfx_ctx_qnx_set_video_mode,
egl_get_video_size,
gfx_ctx_qnx_get_video_size,
NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */
@ -355,12 +416,12 @@ const gfx_ctx_driver_t gfx_ctx_bbqnx = {
gfx_ctx_qnx_has_focus,
gfx_ctx_qnx_suppress_screensaver,
gfx_ctx_qnx_has_windowed,
egl_swap_buffers,
gfx_ctx_qnx_swap_buffers,
gfx_ctx_qnx_input_driver,
egl_get_proc_address,
gfx_ctx_qnx_get_proc_address,
NULL,
NULL,
NULL,
"blackberry_qnx",
egl_bind_hw_render,
gfx_ctx_qnx_bind_hw_render,
};

View File

@ -250,7 +250,7 @@ static void gfx_ctx_drm_swap_buffers(void *data)
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
egl_swap_buffers(drm);
egl_swap_buffers(&drm->egl);
#endif
break;
default:
@ -345,7 +345,7 @@ static void gfx_ctx_drm_destroy_resources(gfx_ctx_drm_data_t *drm)
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
egl_destroy(drm);
egl_destroy(&drm->egl);
#endif
break;
case GFX_CTX_NONE:
@ -597,18 +597,18 @@ static bool gfx_ctx_drm_egl_set_video_mode(gfx_ctx_drm_data_t *drm)
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
if (!egl_init_context(drm, (EGLNativeDisplayType)g_gbm_dev, &major,
if (!egl_init_context(&drm->egl, (EGLNativeDisplayType)g_gbm_dev, &major,
&minor, &n, attrib_ptr))
goto error;
attr = gfx_ctx_drm_egl_fill_attribs(drm, egl_attribs);
egl_attribs_ptr = &egl_attribs[0];
if (!egl_create_context(drm, (attr != egl_attribs_ptr)
if (!egl_create_context(&drm->egl, (attr != egl_attribs_ptr)
? egl_attribs_ptr : NULL))
goto error;
if (!egl_create_surface(drm, (EGLNativeWindowType)g_gbm_surface))
if (!egl_create_surface(&drm->egl, (EGLNativeWindowType)g_gbm_surface))
return false;
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glClear(GL_COLOR_BUFFER_BIT);
@ -851,13 +851,15 @@ static gfx_ctx_proc_t gfx_ctx_drm_get_proc_address(const char *symbol)
static void gfx_ctx_drm_bind_hw_render(void *data, bool enable)
{
gfx_ctx_drm_data_t *drm = (gfx_ctx_drm_data_t*)data;
switch (drm_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
egl_bind_hw_render(data, enable);
egl_bind_hw_render(&drm->egl, enable);
#endif
break;
case GFX_CTX_NONE:

View File

@ -29,14 +29,19 @@
#include "../common/egl_common.h"
#include "../common/gl_common.h"
typedef struct {
typedef struct
{
#ifdef HAVE_EGL
egl_ctx_data_t egl;
#endif
struct mali_native_window native_window;
bool resize;
unsigned width, height;
} mali_ctx_data_t;
static enum gfx_ctx_api mali_api;
static void gfx_ctx_mali_fbdev_destroy(void *data)
{
int fb;
@ -45,7 +50,9 @@ static void gfx_ctx_mali_fbdev_destroy(void *data)
if (mali)
{
egl_destroy(data);
#ifdef HAVE_EGL
egl_destroy(&mali->egl);
#endif
mali->resize = false;
free(mali);
@ -72,6 +79,7 @@ static void gfx_ctx_mali_fbdev_get_video_size(void *data,
static void *gfx_ctx_mali_fbdev_init(void *video_driver)
{
#ifdef HAVE_EGL
EGLint n;
EGLint major, minor;
EGLint format;
@ -84,23 +92,28 @@ static void *gfx_ctx_mali_fbdev_init(void *video_driver)
EGL_ALPHA_SIZE, 8,
EGL_NONE
};
#endif
mali_ctx_data_t *mali = (mali_ctx_data_t*)calloc(1, sizeof(*mali));
if (!mali)
return NULL;
#ifdef HAVE_EGL
egl_install_sighandlers();
#endif
/* Disable cursor blinking so it's not visible in RetroArch. */
system("setterm -cursor off");
if (!egl_init_context(mali, EGL_DEFAULT_DISPLAY,
#ifdef HAVE_EGL
if (!egl_init_context(&mali->egl, EGL_DEFAULT_DISPLAY,
&major, &minor, &n, attribs))
{
egl_report_error();
goto error;
}
#endif
return mali;
@ -162,8 +175,8 @@ static bool gfx_ctx_mali_fbdev_set_video_mode(void *data,
EGL_NONE
};
mali_ctx_data_t *mali = (mali_ctx_data_t*)data;
RFILE *fd = retro_fopen("/dev/fb0", RFILE_MODE_READ_WRITE, -1);
int fb = retro_get_fd(fd);
RFILE *fd = retro_fopen("/dev/fb0", RFILE_MODE_READ_WRITE, -1);
int fb = retro_get_fd(fd);
if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0)
{
@ -172,23 +185,25 @@ static bool gfx_ctx_mali_fbdev_set_video_mode(void *data,
}
retro_fclose(fd);
width = vinfo.xres;
height = vinfo.yres;
width = vinfo.xres;
height = vinfo.yres;
mali->width = width;
mali->height = height;
mali->width = width;
mali->height = height;
mali->native_window.width = vinfo.xres;
mali->native_window.height = vinfo.yres;
if (!egl_create_context(mali, attribs))
#ifdef HAVE_EGL
if (!egl_create_context(&mali->egl, attribs))
{
egl_report_error();
goto error;
}
if (!egl_create_surface(mali, &mali->native_window))
if (!egl_create_surface(&mali->egl, &mali->native_window))
goto error;
#endif
return true;
@ -212,6 +227,7 @@ static bool gfx_ctx_mali_fbdev_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
mali_api = api;
return api == GFX_CTX_OPENGL_ES_API;
}
@ -234,11 +250,45 @@ static bool gfx_ctx_mali_fbdev_has_windowed(void *data)
return false;
}
static void gfx_ctx_mali_fbdev_set_swap_interval(void *data, unsigned swap_interval)
{
mali_ctx_data_t *mali = (mali_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_set_swap_interval(&mali->egl, swap_interval);
#endif
}
static void gfx_ctx_mali_fbdev_swap_buffers(void *data)
{
mali_ctx_data_t *mali = (mali_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_swap_buffers(&mali->egl);
#endif
}
static gfx_ctx_proc_t gfx_ctx_mali_fbdev_get_proc_address(const char *symbol)
{
#ifdef HAVE_EGL
return egl_get_proc_address(symbol);
#else
}
static void gfx_ctx_mali_fbdev_bind_hw_render(void *data, bool enable)
{
mali_ctx_data_t *mali = (mali_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_bind_hw_render(&mali->egl, enable);
#endif
}
const gfx_ctx_driver_t gfx_ctx_mali_fbdev = {
gfx_ctx_mali_fbdev_init,
gfx_ctx_mali_fbdev_destroy,
gfx_ctx_mali_fbdev_bind_api,
egl_set_swap_interval,
gfx_ctx_mali_fbdev_set_swap_interval,
gfx_ctx_mali_fbdev_set_video_mode,
gfx_ctx_mali_fbdev_get_video_size,
NULL, /* get_video_output_size */
@ -252,13 +302,13 @@ const gfx_ctx_driver_t gfx_ctx_mali_fbdev = {
gfx_ctx_mali_fbdev_has_focus,
gfx_ctx_mali_fbdev_suppress_screensaver,
gfx_ctx_mali_fbdev_has_windowed,
egl_swap_buffers,
gfx_ctx_mali_fbdev_swap_buffers,
gfx_ctx_mali_fbdev_input_driver,
egl_get_proc_address,
gfx_ctx_mali_fbdev_get_proc_address,
NULL,
NULL,
NULL,
"mali-fbdev",
egl_bind_hw_render,
gfx_ctx_mali_fbdev_bind_hw_render
};

View File

@ -29,17 +29,29 @@
#include "../../driver.h"
#include "../../runloop.h"
#include "../video_context_driver.h"
#include "../common/egl_common.h"
#include "../common/gl_common.h"
#ifdef HAVE_EGL
#include "../common/egl_common.h"
#endif
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
#include "../common/gl_common.h"
#endif
#ifdef HAVE_EGL
#include <EGL/eglext_brcm.h>
#endif
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
typedef struct {
typedef struct
{
#ifdef HAVE_EGL
egl_ctx_data_t egl;
#endif
bool resize;
unsigned fb_width, fb_height;
@ -149,6 +161,7 @@ static void *gfx_ctx_vc_init(void *video_driver)
VC_RECT_T dst_rect;
VC_RECT_T src_rect;
#ifdef HAVE_EGL
static const EGLint attribute_list[] =
{
EGL_RED_SIZE, 8,
@ -164,8 +177,9 @@ static void *gfx_ctx_vc_init(void *video_driver)
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
#endif
settings_t *settings = config_get_ptr();
vc_ctx_data_t *vc;
vc_ctx_data_t *vc = NULL;
if (g_egl_inited)
{
@ -180,18 +194,20 @@ static void *gfx_ctx_vc_init(void *video_driver)
bcm_host_init();
if (!egl_init_context(vc, EGL_DEFAULT_DISPLAY,
#ifdef HAVE_EGL
if (!egl_init_context(&vc->egl, EGL_DEFAULT_DISPLAY,
&major, &minor, &n, attribute_list))
{
egl_report_error();
goto error;
}
if (!egl_create_context(vc, (vc_api == GFX_CTX_OPENGL_ES_API) ? context_attributes : NULL))
if (!egl_create_context(&vc->egl, (vc_api == GFX_CTX_OPENGL_ES_API) ? context_attributes : NULL))
{
egl_report_error();
goto error;
}
#endif
/* Create an EGL window surface. */
if (graphics_get_display_size(0 /* LCD */, &vc->fb_width, &vc->fb_height) < 0)
@ -225,7 +241,7 @@ static void *gfx_ctx_vc_init(void *video_driver)
}
else
{
src_rect.width = vc->fb_width << 16;
src_rect.width = vc->fb_width << 16;
src_rect.height = vc->fb_height << 16;
}
@ -270,8 +286,10 @@ static void *gfx_ctx_vc_init(void *video_driver)
}
vc_dispmanx_update_submit_sync(dispman_update);
if (!egl_create_surface(vc, &nativewindow))
#ifdef HAVE_EGL
if (!egl_create_surface(&vc->egl, &nativewindow))
goto error;
#endif
return vc;
@ -286,13 +304,15 @@ static bool gfx_ctx_vc_set_video_mode(void *data,
{
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
#ifdef HAVE_EGL
if (g_egl_inited)
return false;
egl_install_sighandlers();
egl_set_swap_interval(data, vc->egl.interval);
gfx_ctx_vc_set_swap_interval(&vc->egl, vc->egl.interval);
g_egl_inited = true;
#endif
return true;
}
@ -463,10 +483,8 @@ static bool gfx_ctx_vc_image_buffer_init(void *data,
if (vc_api == GFX_CTX_OPENVG_API)
return false;
peglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)
egl_get_proc_address("eglCreateImageKHR");
peglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)
egl_get_proc_address("eglDestroyImageKHR");
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"))
@ -570,11 +588,47 @@ error:
return false;
}
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
egl_set_swap_interval(&vc->egl, swap_interval);
#endif
}
static void gfx_ctx_vc_swap_buffers(void *data)
{
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_swap_buffers(&vc->egl);
#endif
}
static void gfx_ctx_vc_bind_hw_render(void *data, bool enable)
{
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_bind_hw_render(&vc->egl, enable);
#endif
}
static gfx_ctx_proc_t gfx_ctx_vc_get_proc_address(const char *symbol)
{
#ifdef HAVE_EGL
return egl_get_proc_address(symbol);
#else
return NULL;
#endif
}
const gfx_ctx_driver_t gfx_ctx_videocore = {
gfx_ctx_vc_init,
gfx_ctx_vc_destroy,
gfx_ctx_vc_bind_api,
egl_set_swap_interval,
gfx_ctx_vc_set_swap_interval,
gfx_ctx_vc_set_video_mode,
gfx_ctx_vc_get_video_size,
NULL, /* get_video_output_size */
@ -588,12 +642,12 @@ const gfx_ctx_driver_t gfx_ctx_videocore = {
gfx_ctx_vc_has_focus,
gfx_ctx_vc_suppress_screensaver,
gfx_ctx_vc_has_windowed,
egl_swap_buffers,
gfx_ctx_vc_swap_buffers,
gfx_ctx_vc_input_driver,
egl_get_proc_address,
gfx_ctx_vc_get_proc_address,
gfx_ctx_vc_image_buffer_init,
gfx_ctx_vc_image_buffer_write,
NULL,
"videocore",
egl_bind_hw_render,
gfx_ctx_vc_bind_hw_render,
};

View File

@ -19,11 +19,20 @@
#include "../../driver.h"
#include "../../general.h"
#include "../../runloop.h"
#include "../common/egl_common.h"
#include "../common/gl_common.h"
typedef struct {
#ifdef HAVE_EGL
#include "../common/egl_common.h"
#endif
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
#include "../common/gl_common.h"
#endif
typedef struct
{
#ifdef HAVE_EGL
egl_ctx_data_t egl;
#endif
bool resize;
unsigned width, height;
} vivante_ctx_data_t;
@ -31,7 +40,10 @@ typedef struct {
static void gfx_ctx_vivante_destroy(void *data)
{
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
egl_destroy(data);
#ifdef HAVE_EGL
egl_destroy(&viv->egl);
#endif
viv->resize = false;
free(viv);
@ -39,6 +51,7 @@ static void gfx_ctx_vivante_destroy(void *data)
static void *gfx_ctx_vivante_init(void *video_driver)
{
#ifdef HAVE_EGL
EGLint n;
EGLint major, minor;
EGLint format;
@ -54,6 +67,7 @@ static void *gfx_ctx_vivante_init(void *video_driver)
EGL_SAMPLES, 0,
EGL_NONE
};
#endif
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)calloc(1, sizeof(*viv));
if (!viv)
@ -61,14 +75,16 @@ static void *gfx_ctx_vivante_init(void *video_driver)
(void)video_driver;
#ifdef HAVE_EGL
egl_install_sighandlers();
if (!egl_init_context(viv, EGL_DEFAULT_DISPLAY, &major, &minor,
if (!egl_init_context(&viv->egl, EGL_DEFAULT_DISPLAY, &major, &minor,
&n, attribs))
{
egl_report_error();
goto error;
}
#endif
return viv;
@ -82,8 +98,11 @@ static void gfx_ctx_vivante_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
unsigned new_width, new_height;
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
egl_get_video_size(data, &new_width, &new_height);
#ifdef HAVE_EGL
gfx_ctx_vivante_get_video_size(&viv->egl, &new_width, &new_height);
#endif
if (new_width != *width || new_height != *height)
{
@ -122,11 +141,13 @@ static bool gfx_ctx_vivante_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
{
#ifdef HAVE_EGL
EGLNativeWindowType window;
static const EGLint attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2, /* Use version 2, even for GLES3. */
EGL_NONE
};
#endif
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
/* Pick some arbitrary default. */
@ -138,16 +159,20 @@ static bool gfx_ctx_vivante_set_video_mode(void *data,
viv->width = width;
viv->height = height;
if (!egl_create_context(viv, attribs))
#ifdef HAVE_EGL
if (!egl_create_context(&viv->egl, attribs))
{
egl_report_error();
goto error;
}
#endif
window = fbCreateWindow(fbGetDisplayByIndex(0), 0, 0, 0, 0);
if (!egl_create_surface(viv, window))
#ifdef HAVE_EGL
if (!egl_create_surface(&viv->egl, window))
goto error;
#endif
return true;
@ -191,13 +216,58 @@ static bool gfx_ctx_vivante_has_windowed(void *data)
return false;
}
static void gfx_ctx_vivante_set_swap_interval(void *data, unsigned swap_interval)
{
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_set_swap_interval(&viv->egl, swap_interval);
#endif
}
static gfx_ctx_proc_t gfx_ctx_vivante_get_proc_address(const char *symbol)
{
#ifdef HAVE_EGL
return egl_get_proc_address(symbol);
#else
return NULL;
#endif
}
static void gfx_ctx_vivante_bind_hw_render(void *data, bool enable)
{
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_bind_hw_render(&viv->egl, enable);
#endif
}
static void gfx_ctx_vivante_swap_buffers(void *data)
{
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_swap_buffers(&viv->egl);
#endif
}
static void gfx_ctx_vivante_get_video_size(void *data,
unsigned *width, unsigned *height)
{
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_get_video_size(&viv->egl, width, height);
#endif
}
const gfx_ctx_driver_t gfx_ctx_vivante_fbdev = {
gfx_ctx_vivante_init,
gfx_ctx_vivante_destroy,
gfx_ctx_vivante_bind_api,
egl_set_swap_interval,
gfx_ctx_vivante_set_swap_interval,
gfx_ctx_vivante_set_video_mode,
egl_get_video_size,
gfx_ctx_vivante_get_video_size,
NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */
@ -209,12 +279,12 @@ const gfx_ctx_driver_t gfx_ctx_vivante_fbdev = {
gfx_ctx_vivante_has_focus,
gfx_ctx_vivante_suppress_screensaver,
gfx_ctx_vivante_has_windowed,
egl_swap_buffers,
gfx_ctx_vivante_swap_buffers,
gfx_ctx_vivante_input_driver,
egl_get_proc_address,
gfx_ctx_vivante_get_proc_address,
NULL,
NULL,
NULL,
"vivante-fbdev",
egl_bind_hw_render,
gfx_ctx_vivante_bind_hw_render,
};

View File

@ -255,7 +255,7 @@ static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl)
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
egl_destroy(wl);
egl_destroy(&wl->egl);
if (wl->win)
wl_egl_window_destroy(wl->win);
@ -591,14 +591,15 @@ static void *gfx_ctx_wl_init(void *video_driver)
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
if (!egl_init_context(wl, (EGLNativeDisplayType)wl->dpy,
if (!egl_init_context(&wl->egl,
(EGLNativeDisplayType)wl->dpy,
&major, &minor, &n, attrib_ptr))
{
egl_report_error();
goto error;
}
if (n == 0 || !egl_has_config(wl))
if (n == 0 || !egl_has_config(&wl->egl))
goto error;
#endif
break;
@ -728,7 +729,7 @@ static void gfx_ctx_wl_set_swap_interval(void *data, unsigned swap_interval)
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
egl_set_swap_interval(data, swap_interval);
egl_set_swap_interval(&wl->egl, swap_interval);
#endif
break;
case GFX_CTX_VULKAN_API:
@ -791,15 +792,15 @@ static bool gfx_ctx_wl_set_video_mode(void *data,
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
if (!egl_create_context(wl, (attr != egl_attribs) ? egl_attribs : NULL))
if (!egl_create_context(&wl->egl, (attr != egl_attribs) ? egl_attribs : NULL))
{
egl_report_error();
goto error;
}
if (!egl_create_surface(wl, (EGLNativeWindowType)wl->win))
if (!egl_create_surface(&wl->egl, (EGLNativeWindowType)wl->win))
goto error;
egl_set_swap_interval(wl, wl->egl.interval);
egl_set_swap_interval(&wl->egl, wl->egl.interval);
#endif
break;
case GFX_CTX_NONE:
@ -1083,7 +1084,7 @@ static void gfx_ctx_wl_swap_buffers(void *data)
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
egl_swap_buffers(data);
egl_swap_buffers(&wl->egl);
#endif
break;
case GFX_CTX_VULKAN_API:
@ -1121,13 +1122,15 @@ static gfx_ctx_proc_t gfx_ctx_wl_get_proc_address(const char *symbol)
static void gfx_ctx_wl_bind_hw_render(void *data, bool enable)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
switch (wl_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
egl_bind_hw_render(data, enable);
egl_bind_hw_render(&wl->egl, enable);
#endif
break;
case GFX_CTX_NONE:

View File

@ -27,8 +27,11 @@
#define EGL_OPENGL_ES3_BIT_KHR 0x0040
#endif
typedef struct {
typedef struct
{
#ifdef HAVE_EGL
egl_ctx_data_t egl;
#endif
XF86VidModeModeInfo desktop_mode;
bool should_reset_mode;
} xegl_ctx_data_t;
@ -47,7 +50,9 @@ static void gfx_ctx_xegl_destroy(void *data)
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
x11_input_ctx_destroy();
egl_destroy(data);
#ifdef HAVE_EGL
egl_destroy(&xegl->egl);
#endif
if (g_x11_win)
{
@ -91,6 +96,7 @@ EGL_DEPTH_SIZE, 0
static void *gfx_ctx_xegl_init(void *video_driver)
{
#ifdef HAVE_EGL
static const EGLint egl_attribs_gl[] = {
XEGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
@ -120,9 +126,9 @@ static void *gfx_ctx_xegl_init(void *video_driver)
const EGLint *attrib_ptr;
EGLint major, minor;
EGLint n;
#endif
xegl_ctx_data_t *xegl;
if (g_egl_inited)
return NULL;
@ -155,15 +161,17 @@ static void *gfx_ctx_xegl_init(void *video_driver)
if (!x11_connect())
goto error;
if (!egl_init_context(xegl, (EGLNativeDisplayType)g_x11_dpy,
#ifdef HAVE_EGL
if (!egl_init_context(&xegl->egl, (EGLNativeDisplayType)g_x11_dpy,
&major, &minor, &n, attrib_ptr))
{
egl_report_error();
goto error;
}
if (n == 0 || !egl_has_config(xegl))
if (n == 0 || !egl_has_config(&xegl->egl))
goto error;
#endif
return xegl;
@ -238,6 +246,9 @@ static EGLint *xegl_fill_attribs(xegl_ctx_data_t *xegl, EGLint *attr)
return attr;
}
/* forward declaration */
static void gfx_ctx_xegl_set_swap_interval(void *data, unsigned swap_interval);
static bool gfx_ctx_xegl_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
@ -265,8 +276,10 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
attr = egl_attribs;
attr = xegl_fill_attribs(xegl, attr);
if (!egl_get_native_visual_id(xegl, &vid))
#ifdef HAVE_EGL
if (!egl_get_native_visual_id(&xegl->egl, &vid))
goto error;
#endif
temp.visualid = vid;
@ -325,13 +338,13 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
(true_full ? CWOverrideRedirect : 0), &swa);
XSetWindowBackground(g_x11_dpy, g_x11_win, 0);
if (!egl_create_context(xegl, (attr != egl_attribs) ? egl_attribs : NULL))
if (!egl_create_context(&xegl->egl, (attr != egl_attribs) ? egl_attribs : NULL))
{
egl_report_error();
goto error;
}
if (!egl_create_surface(xegl, (EGLNativeWindowType)g_x11_win))
if (!egl_create_surface(&xegl->egl, (EGLNativeWindowType)g_x11_win))
goto error;
x11_set_window_attr(g_x11_dpy, g_x11_win);
@ -375,7 +388,9 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
x11_event_queue_check(&event);
x11_install_quit_atom();
egl_set_swap_interval(xegl, xegl->egl.interval);
#ifdef HAVE_EGL
gfx_ctx_xegl_set_swap_interval(&xegl->egl, xegl->egl.interval);
#endif
/* This can blow up on some drivers. It's not fatal,
* so override errors for this call.
@ -478,12 +493,87 @@ static void gfx_ctx_xegl_show_mouse(void *data, bool state)
x11_show_mouse(g_x11_dpy, g_x11_win, state);
}
static void gfx_ctx_xegl_swap_buffers(void *data)
{
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
switch (x_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
egl_swap_buffers(&xegl->egl);
#endif
break;
case GFX_CTX_NONE:
default:
break;
}
}
static void gfx_ctx_xegl_bind_hw_render(void *data, bool enable)
{
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
switch (x_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
egl_bind_hw_render(&xegl->egl, enable);
#endif
break;
case GFX_CTX_NONE:
default:
break;
}
}
static void gfx_ctx_xegl_set_swap_interval(void *data, unsigned swap_interval)
{
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
switch (x_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
egl_set_swap_interval(&xegl->egl, swap_interval);
#endif
break;
case GFX_CTX_NONE:
default:
break;
}
}
static gfx_ctx_proc_t gfx_ctx_xegl_get_proc_address(const char *symbol)
{
switch (x_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
return egl_get_proc_address(symbol);
#else
break;
#endif
case GFX_CTX_NONE:
default:
break;
}
return NULL;
}
const gfx_ctx_driver_t gfx_ctx_x_egl =
{
gfx_ctx_xegl_init,
gfx_ctx_xegl_destroy,
gfx_ctx_xegl_bind_api,
egl_set_swap_interval,
gfx_ctx_xegl_set_swap_interval,
gfx_ctx_xegl_set_video_mode,
x11_get_video_size,
NULL, /* get_video_output_size */
@ -497,12 +587,12 @@ const gfx_ctx_driver_t gfx_ctx_x_egl =
gfx_ctx_xegl_has_focus,
gfx_ctx_xegl_suppress_screensaver,
gfx_ctx_xegl_has_windowed,
egl_swap_buffers,
gfx_ctx_xegl_swap_buffers,
gfx_ctx_xegl_input_driver,
egl_get_proc_address,
gfx_ctx_xegl_get_proc_address,
NULL,
NULL,
gfx_ctx_xegl_show_mouse,
"x-egl",
egl_bind_hw_render,
gfx_ctx_xegl_bind_hw_render,
};