From b07dd0fc1d12de73337896a5a8aa3287d17b9a25 Mon Sep 17 00:00:00 2001 From: Stanislav Vorobiov Date: Fri, 21 Feb 2014 16:50:39 +0400 Subject: [PATCH] YaGL: Respect OpenGL ES context version In order to be able to run OpenGL ES 1.0 applications with OpenGL 3.1+ core on host we must create legacy context for it. The better solution is to reimplement entire OpenGL ES 1.0 API using shaders, but that's the task for the future Change-Id: Id02dd83bc45cb78d70a1d208ce1d6e3109a181c7 --- hw/yagl/yagl_apis/egl/yagl_egl_context.c | 6 ++++-- hw/yagl/yagl_apis/egl/yagl_egl_context.h | 3 ++- hw/yagl/yagl_apis/egl/yagl_host_egl_calls.c | 20 ++++++++++++++++++- .../egl_offscreen/yagl_egl_offscreen.c | 4 ++-- .../yagl_egl_offscreen_context.c | 11 ++++++---- .../yagl_egl_offscreen_context.h | 3 ++- .../yagl_egl_offscreen_display.c | 6 ++++-- .../egl_onscreen/yagl_egl_onscreen.c | 4 ++-- .../egl_onscreen/yagl_egl_onscreen_context.c | 11 ++++++---- .../egl_onscreen/yagl_egl_onscreen_context.h | 3 ++- .../egl_onscreen/yagl_egl_onscreen_display.c | 6 ++++-- hw/yagl/yagl_drivers/egl_agl/yagl_egl_agl.c | 3 ++- hw/yagl/yagl_drivers/egl_glx/yagl_egl_glx.c | 10 ++++++---- hw/yagl/yagl_drivers/egl_wgl/yagl_egl_wgl.c | 3 ++- hw/yagl/yagl_egl_driver.h | 3 ++- hw/yagl/yagl_eglb_display.h | 3 ++- 16 files changed, 69 insertions(+), 30 deletions(-) diff --git a/hw/yagl/yagl_apis/egl/yagl_egl_context.c b/hw/yagl/yagl_apis/egl/yagl_egl_context.c index f9e3bf7f14..467d521bc1 100644 --- a/hw/yagl/yagl_apis/egl/yagl_egl_context.c +++ b/hw/yagl/yagl_apis/egl/yagl_egl_context.c @@ -53,14 +53,16 @@ static void yagl_egl_context_destroy(struct yagl_ref *ref) struct yagl_egl_context *yagl_egl_context_create(struct yagl_egl_display *dpy, struct yagl_egl_config *cfg, - struct yagl_eglb_context *backend_share_ctx) + struct yagl_eglb_context *backend_share_ctx, + int version) { struct yagl_eglb_context *backend_ctx; struct yagl_egl_context *ctx; backend_ctx = dpy->backend_dpy->create_context(dpy->backend_dpy, &cfg->native, - backend_share_ctx); + backend_share_ctx, + version); if (!backend_ctx) { return NULL; diff --git a/hw/yagl/yagl_apis/egl/yagl_egl_context.h b/hw/yagl/yagl_apis/egl/yagl_egl_context.h index 7271442bbe..1a6a9391cb 100644 --- a/hw/yagl/yagl_apis/egl/yagl_egl_context.h +++ b/hw/yagl/yagl_apis/egl/yagl_egl_context.h @@ -59,7 +59,8 @@ struct yagl_egl_context struct yagl_egl_context *yagl_egl_context_create(struct yagl_egl_display *dpy, struct yagl_egl_config *cfg, - struct yagl_eglb_context *backend_share_ctx); + struct yagl_eglb_context *backend_share_ctx, + int version); void yagl_egl_context_update_surfaces(struct yagl_egl_context *ctx, struct yagl_egl_surface *draw, diff --git a/hw/yagl/yagl_apis/egl/yagl_host_egl_calls.c b/hw/yagl/yagl_apis/egl/yagl_host_egl_calls.c index 08e2f2fa76..883231a3e6 100644 --- a/hw/yagl/yagl_apis/egl/yagl_host_egl_calls.c +++ b/hw/yagl/yagl_apis/egl/yagl_host_egl_calls.c @@ -890,6 +890,7 @@ yagl_host_handle yagl_host_eglCreateContext(yagl_host_handle dpy_, const EGLint *attrib_list, int32_t attrib_list_count, EGLint *error) { + int i = 0, version = 1; yagl_host_handle res = 0; struct yagl_egl_display *dpy = NULL; struct yagl_egl_config *config = NULL; @@ -906,6 +907,22 @@ yagl_host_handle yagl_host_eglCreateContext(yagl_host_handle dpy_, goto out; } + if (egl_api_ts->api == EGL_OPENGL_ES_API) { + if (!yagl_egl_is_attrib_list_empty(attrib_list)) { + while (attrib_list[i] != EGL_NONE) { + switch (attrib_list[i]) { + case EGL_CONTEXT_CLIENT_VERSION: + version = attrib_list[i + 1]; + break; + default: + break; + } + + i += 2; + } + } + } + if (share_context_) { if (!yagl_validate_context(dpy, share_context_, &share_context, error)) { goto out; @@ -915,7 +932,8 @@ yagl_host_handle yagl_host_eglCreateContext(yagl_host_handle dpy_, ctx = yagl_egl_context_create(dpy, config, (share_context ? share_context->backend_ctx - : NULL)); + : NULL), + version); if (!ctx) { YAGL_SET_ERR(EGL_BAD_MATCH); diff --git a/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen.c b/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen.c index 54e4e9b1a0..8645ba12a5 100644 --- a/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen.c +++ b/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen.c @@ -281,13 +281,13 @@ struct yagl_egl_backend *yagl_egl_offscreen_create(struct yagl_egl_driver *egl_d goto fail; } - ctx = egl_driver->context_create(egl_driver, dpy, &configs[0], NULL); + ctx = egl_driver->context_create(egl_driver, dpy, &configs[0], NULL, 0); if (ctx == EGL_NO_CONTEXT) { goto fail; } - global_ctx = egl_driver->context_create(egl_driver, dpy, &configs[0], ctx); + global_ctx = egl_driver->context_create(egl_driver, dpy, &configs[0], ctx, 0); if (global_ctx == EGL_NO_CONTEXT) { goto fail; diff --git a/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.c b/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.c index b7e31ff28c..e60f832fcc 100644 --- a/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.c +++ b/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.c @@ -69,7 +69,8 @@ static void yagl_egl_offscreen_context_destroy(struct yagl_eglb_context *ctx) struct yagl_egl_offscreen_context *yagl_egl_offscreen_context_create(struct yagl_egl_offscreen_display *dpy, const struct yagl_egl_native_config *cfg, - struct yagl_egl_offscreen_context *share_context) + struct yagl_egl_offscreen_context *share_context, + int version) { struct yagl_egl_offscreen *egl_offscreen = (struct yagl_egl_offscreen*)dpy->base.backend; @@ -77,15 +78,17 @@ struct yagl_egl_offscreen_context EGLContext native_ctx; YAGL_LOG_FUNC_ENTER(yagl_egl_offscreen_context_create, - "dpy = %p, cfg = %d", + "dpy = %p, cfg = %d, version = %d", dpy, - cfg->config_id); + cfg->config_id, + version); native_ctx = egl_offscreen->egl_driver->context_create( egl_offscreen->egl_driver, dpy->native_dpy, cfg, - egl_offscreen->global_ctx); + egl_offscreen->global_ctx, + version); if (!native_ctx) { YAGL_LOG_FUNC_EXIT(NULL); diff --git a/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.h b/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.h index 2736f2b533..647c271318 100644 --- a/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.h +++ b/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.h @@ -51,7 +51,8 @@ struct yagl_egl_offscreen_context struct yagl_egl_offscreen_context *yagl_egl_offscreen_context_create(struct yagl_egl_offscreen_display *dpy, const struct yagl_egl_native_config *cfg, - struct yagl_egl_offscreen_context *share_context); + struct yagl_egl_offscreen_context *share_context, + int version); bool yagl_egl_offscreen_context_read_pixels(struct yagl_egl_offscreen_context *ctx, uint32_t width, diff --git a/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_display.c b/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_display.c index a6ec985edf..0a1f62f01a 100644 --- a/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_display.c +++ b/hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_display.c @@ -108,14 +108,16 @@ static void yagl_egl_offscreen_display_config_cleanup(struct yagl_eglb_display * static struct yagl_eglb_context *yagl_egl_offscreen_display_create_context(struct yagl_eglb_display *dpy, const struct yagl_egl_native_config *cfg, - struct yagl_eglb_context *share_context) + struct yagl_eglb_context *share_context, + int version) { struct yagl_egl_offscreen_display *egl_offscreen_dpy = (struct yagl_egl_offscreen_display*)dpy; struct yagl_egl_offscreen_context *ctx = yagl_egl_offscreen_context_create(egl_offscreen_dpy, cfg, - (struct yagl_egl_offscreen_context*)share_context); + (struct yagl_egl_offscreen_context*)share_context, + version); return ctx ? &ctx->base : NULL; } diff --git a/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen.c b/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen.c index 8cae6896ca..3ddec22632 100644 --- a/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen.c +++ b/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen.c @@ -374,13 +374,13 @@ struct yagl_egl_backend *yagl_egl_onscreen_create(struct winsys_interface *wsi, } ctx = egl_driver->context_create(egl_driver, dpy, &configs[0], - (EGLContext)ws_info->context); + (EGLContext)ws_info->context, 0); if (ctx == EGL_NO_CONTEXT) { goto fail; } - global_ctx = egl_driver->context_create(egl_driver, dpy, &configs[0], ctx); + global_ctx = egl_driver->context_create(egl_driver, dpy, &configs[0], ctx, 0); if (global_ctx == EGL_NO_CONTEXT) { goto fail; diff --git a/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.c b/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.c index b24cb4a992..018ea61f6f 100644 --- a/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.c +++ b/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.c @@ -77,7 +77,8 @@ static void yagl_egl_onscreen_context_destroy(struct yagl_eglb_context *ctx) struct yagl_egl_onscreen_context *yagl_egl_onscreen_context_create(struct yagl_egl_onscreen_display *dpy, const struct yagl_egl_native_config *cfg, - struct yagl_egl_onscreen_context *share_context) + struct yagl_egl_onscreen_context *share_context, + int version) { struct yagl_egl_onscreen *egl_onscreen = (struct yagl_egl_onscreen*)dpy->base.backend; @@ -85,15 +86,17 @@ struct yagl_egl_onscreen_context EGLContext native_ctx; YAGL_LOG_FUNC_ENTER(yagl_egl_onscreen_context_create, - "dpy = %p, cfg = %d", + "dpy = %p, cfg = %d, version = %d", dpy, - cfg->config_id); + cfg->config_id, + version); native_ctx = egl_onscreen->egl_driver->context_create( egl_onscreen->egl_driver, dpy->native_dpy, cfg, - egl_onscreen->global_ctx); + egl_onscreen->global_ctx, + version); if (!native_ctx) { YAGL_LOG_FUNC_EXIT(NULL); diff --git a/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.h b/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.h index 0c348b22e7..1954735e75 100644 --- a/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.h +++ b/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.h @@ -74,7 +74,8 @@ struct yagl_egl_onscreen_context struct yagl_egl_onscreen_context *yagl_egl_onscreen_context_create(struct yagl_egl_onscreen_display *dpy, const struct yagl_egl_native_config *cfg, - struct yagl_egl_onscreen_context *share_context); + struct yagl_egl_onscreen_context *share_context, + int version); void yagl_egl_onscreen_context_setup(struct yagl_egl_onscreen_context *ctx); diff --git a/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_display.c b/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_display.c index dacbedeeb2..380061936d 100644 --- a/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_display.c +++ b/hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_display.c @@ -106,14 +106,16 @@ static void yagl_egl_onscreen_display_config_cleanup(struct yagl_eglb_display *d static struct yagl_eglb_context *yagl_egl_onscreen_display_create_context(struct yagl_eglb_display *dpy, const struct yagl_egl_native_config *cfg, - struct yagl_eglb_context *share_context) + struct yagl_eglb_context *share_context, + int version) { struct yagl_egl_onscreen_display *egl_onscreen_dpy = (struct yagl_egl_onscreen_display*)dpy; struct yagl_egl_onscreen_context *ctx = yagl_egl_onscreen_context_create(egl_onscreen_dpy, cfg, - (struct yagl_egl_onscreen_context*)share_context); + (struct yagl_egl_onscreen_context*)share_context, + version); return ctx ? &ctx->base : NULL; } diff --git a/hw/yagl/yagl_drivers/egl_agl/yagl_egl_agl.c b/hw/yagl/yagl_drivers/egl_agl/yagl_egl_agl.c index f3593a360e..8fc1af323c 100644 --- a/hw/yagl/yagl_drivers/egl_agl/yagl_egl_agl.c +++ b/hw/yagl/yagl_drivers/egl_agl/yagl_egl_agl.c @@ -170,7 +170,8 @@ static void yagl_egl_agl_config_cleanup(struct yagl_egl_driver *driver, static EGLContext yagl_egl_agl_context_create(struct yagl_egl_driver *driver, EGLNativeDisplayType egl_dpy, const struct yagl_egl_native_config *cfg, - EGLContext share_context) + EGLContext share_context, + int version) { YaglEglAglContext *egl_glc; AGLContext agl_share_glc; diff --git a/hw/yagl/yagl_drivers/egl_glx/yagl_egl_glx.c b/hw/yagl/yagl_drivers/egl_glx/yagl_egl_glx.c index 8f687a8c10..5a03125767 100644 --- a/hw/yagl/yagl_drivers/egl_glx/yagl_egl_glx.c +++ b/hw/yagl/yagl_drivers/egl_glx/yagl_egl_glx.c @@ -578,7 +578,8 @@ static void yagl_egl_glx_pbuffer_surface_destroy(struct yagl_egl_driver *driver, static EGLContext yagl_egl_glx_context_create(struct yagl_egl_driver *driver, EGLNativeDisplayType dpy, const struct yagl_egl_native_config *cfg, - EGLContext share_context) + EGLContext share_context, + int version) { struct yagl_egl_glx *egl_glx = (struct yagl_egl_glx*)driver; GLXContext ctx; @@ -592,11 +593,12 @@ static EGLContext yagl_egl_glx_context_create(struct yagl_egl_driver *driver, }; YAGL_EGL_GLX_ENTER(yagl_egl_glx_context_create, - "dpy = %p, share_context = %p", + "dpy = %p, share_context = %p, version = %d", dpy, - share_context); + share_context, + version); - if (egl_glx->base.gl_version > yagl_gl_2) { + if ((egl_glx->base.gl_version > yagl_gl_2) && (version != 1)) { ctx = egl_glx->glXCreateContextAttribsARB(dpy, (GLXFBConfig)cfg->driver_data, ((share_context == EGL_NO_CONTEXT) ? diff --git a/hw/yagl/yagl_drivers/egl_wgl/yagl_egl_wgl.c b/hw/yagl/yagl_drivers/egl_wgl/yagl_egl_wgl.c index d58c24b7f9..98d621dff3 100644 --- a/hw/yagl/yagl_drivers/egl_wgl/yagl_egl_wgl.c +++ b/hw/yagl/yagl_drivers/egl_wgl/yagl_egl_wgl.c @@ -500,7 +500,8 @@ fail: static EGLContext yagl_egl_wgl_context_create(struct yagl_egl_driver *driver, EGLNativeDisplayType egl_dpy, const struct yagl_egl_native_config *cfg, - EGLContext share_context) + EGLContext share_context, + int version) { YaglEglWglDriver *egl_wgl = (YaglEglWglDriver *)(driver); YaglEglWglDpy *dpy = (YaglEglWglDpy *)egl_dpy; diff --git a/hw/yagl/yagl_egl_driver.h b/hw/yagl/yagl_egl_driver.h index 7960e8452b..cbee5dac79 100644 --- a/hw/yagl/yagl_egl_driver.h +++ b/hw/yagl/yagl_egl_driver.h @@ -88,7 +88,8 @@ struct yagl_egl_driver EGLContext (*context_create)(struct yagl_egl_driver */*driver*/, EGLNativeDisplayType /*dpy*/, const struct yagl_egl_native_config */*cfg*/, - EGLContext /*share_context*/); + EGLContext /*share_context*/, + int /*version*/); void (*context_destroy)(struct yagl_egl_driver */*driver*/, EGLNativeDisplayType /*dpy*/, diff --git a/hw/yagl/yagl_eglb_display.h b/hw/yagl/yagl_eglb_display.h index e73afee369..85866e1fa9 100644 --- a/hw/yagl/yagl_eglb_display.h +++ b/hw/yagl/yagl_eglb_display.h @@ -54,7 +54,8 @@ struct yagl_eglb_display struct yagl_eglb_context *(*create_context)(struct yagl_eglb_display */*dpy*/, const struct yagl_egl_native_config */*cfg*/, - struct yagl_eglb_context */*share_context*/); + struct yagl_eglb_context */*share_context*/, + int /*version*/); /* * 'pixels' are locked in target's memory, no page fault possible. -- 2.34.1