YaGL: Respect OpenGL ES context version 88/16688/1
authorStanislav Vorobiov <s.vorobiov@samsung.com>
Fri, 21 Feb 2014 12:50:39 +0000 (16:50 +0400)
committerStanislav Vorobiov <s.vorobiov@samsung.com>
Fri, 21 Feb 2014 12:50:39 +0000 (16:50 +0400)
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

16 files changed:
hw/yagl/yagl_apis/egl/yagl_egl_context.c
hw/yagl/yagl_apis/egl/yagl_egl_context.h
hw/yagl/yagl_apis/egl/yagl_host_egl_calls.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.c
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_context.h
hw/yagl/yagl_backends/egl_offscreen/yagl_egl_offscreen_display.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.c
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_context.h
hw/yagl/yagl_backends/egl_onscreen/yagl_egl_onscreen_display.c
hw/yagl/yagl_drivers/egl_agl/yagl_egl_agl.c
hw/yagl/yagl_drivers/egl_glx/yagl_egl_glx.c
hw/yagl/yagl_drivers/egl_wgl/yagl_egl_wgl.c
hw/yagl/yagl_egl_driver.h
hw/yagl/yagl_eglb_display.h

index f9e3bf7f14781f7f6569ffe37c62bb6b36ef3d87..467d521bc1cea262a1db447fbdb2f1927fe1846f 100644 (file)
@@ -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;
index 7271442bbe24a2c3060bfbc4710046f7d55aae71..1a6a9391cb3679558fb254cf740dfaf3bb86714d 100644 (file)
@@ -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,
index 08e2f2fa76ae92b2e86776d7c9ebfb2685e62128..883231a3e66e680223a3db895b5b720db87cbd37 100644 (file)
@@ -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);
index 54e4e9b1a065f108e963ee83bd31983f1c0a4b00..8645ba12a5bd13eb73a9b9e88e6b54bcb6bdd5c7 100644 (file)
@@ -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;
index b7e31ff28c7a4d7f374f4130de0932298942fdc0..e60f832fccb2a253c0ac60fae36ec03e928bf2c3 100644 (file)
@@ -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);
index 2736f2b533cdb7ef3868a1f5dbe03c45b24f800a..647c27131825c194751e4b02c3b77e079646189f 100644 (file)
@@ -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,
index a6ec985edffa45b85c0005c1ea5a5da61cbdc606..0a1f62f01a563d38d40d1f0587e0b8e2d32de336 100644 (file)
@@ -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;
 }
index 8cae6896cae9479842aa7448f66b4a515b334e36..3ddec226326fe79b0aa83f9c198e8c95c46d0b66 100644 (file)
@@ -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;
index b24cb4a99270ca6cfb161e9814e6e27c33f2ed7a..018ea61f6fe262da896ae1d3fffdc77e8464cf16 100644 (file)
@@ -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);
index 0c348b22e77e2e99e2699df9063fb7e27596f544..1954735e75445e5be263ed8b457767395c62f364 100644 (file)
@@ -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);
 
index dacbedeeb25d18a75927fb2d7e891932b71eb2c2..380061936dead7206d01eedc2cab5bc8d198f621 100644 (file)
@@ -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;
 }
index f3593a360e6ef8a1ea21ec45f7cf4e5fa0871f74..8fc1af323c31a3e825800b352a41779bd35ef17b 100644 (file)
@@ -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;
index 8f687a8c10cb4a0ae8ada55bc37904d84c33a11e..5a031257671327bc36c9171f5c7b78a3bc6f31e0 100644 (file)
@@ -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) ?
index d58c24b7f94711ad8cfa520d8103b8f7e089357d..98d621dff3ec4e5a6c53e23d38a9d72d9a2b0b11 100644 (file)
@@ -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;
index 7960e8452ba6098f3a57064a5290bef9678b19a9..cbee5dac798d186c3359593b50d6e1db01547ff2 100644 (file)
@@ -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*/,
index e73afee3696f0e78a5e6b89de3856613f71605ac..85866e1fa930ef223d0e8024f8af88399a9eeb42 100644 (file)
@@ -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.