YaGL: Add EGL_KHR_gl_texture_2D_image support
authorVasiliy Ulyanov <v.ulyanov@samsung.com>
Mon, 18 May 2015 12:53:58 +0000 (15:53 +0300)
committerjinhyung.jo <jinhyung.jo@samsung.com>
Tue, 26 May 2015 09:48:12 +0000 (18:48 +0900)
eglCreateImageKHR(...) now supports EGL_GL_TEXTURE_2D_KHR
target (onscreen backend only)

Change-Id: Ie41c494246237ce79e36fde63b49bb7cf876737b
Signed-off-by: Vasiliy Ulyanov <v.ulyanov@samsung.com>
13 files changed:
EGL/CMakeLists.txt
EGL/yagl_backend.h
EGL/yagl_display.c
EGL/yagl_egl_calls.c
EGL/yagl_offscreen.c
EGL/yagl_onscreen.c
EGL/yagl_onscreen_image_gl_texture_2d.c [new file with mode: 0644]
EGL/yagl_onscreen_image_gl_texture_2d.h [new file with mode: 0644]
GLES_common/yagl_gles_image.c
GLES_common/yagl_gles_image.h
GLESv1_CM/yagl_gles1_interface.c
GLESv2/yagl_gles2_interface.c
include/yagl_client_interface.h

index fc78e43a304eff2a84745bf311047f2a15bc3021..58b295a845fde8626e1f2f2829a9ea938c2a76a4 100644 (file)
@@ -21,6 +21,7 @@ set(SOURCES
     yagl_offscreen_surface.c
     yagl_onscreen.c
     yagl_onscreen_image_pixmap.c
+    yagl_onscreen_image_gl_texture_2d.c
     yagl_onscreen_surface.c
     yagl_onscreen_fence.c
     yagl_onscreen_utils.c
index 380482067c25bfe7cd2054d94a10539f79b43b68..d939ba64b064b4cff3ddd7e806e33dcd787ad175 100644 (file)
@@ -47,6 +47,7 @@ struct yagl_native_platform;
 struct yagl_native_drawable;
 struct yagl_client_interface;
 struct wl_resource;
+struct yagl_context;
 
 struct yagl_backend
 {
@@ -84,6 +85,11 @@ struct yagl_backend
                                                  struct wl_resource */*buffer*/,
                                                  struct yagl_client_interface */*iface*/);
 
+    struct yagl_image *(*create_image_gl_texture_2d)(struct yagl_display */*dpy*/,
+                                                     struct yagl_context */*ctx*/,
+                                                     yagl_object_name /*texture*/,
+                                                     struct yagl_client_interface */*iface*/);
+
     struct yagl_fence *(*create_fence)(struct yagl_display */*dpy*/);
 
     void (*destroy)(struct yagl_backend */*backend*/);
index 775d1d6f6b0a3fe8729d7f0aa2ccec39b8fcbeec..d18281c83ae728ad3cf815b4660b198ddef42f85 100644 (file)
@@ -57,6 +57,8 @@
 
 #define YAGL_EGL_WL_BIND_WAYLAND_DISPLAY_EXTENSIONS "EGL_WL_bind_wayland_display "
 
+#define YAGL_EGL_GL_TEXTURE_EXTENSIONS "EGL_KHR_gl_texture_2D_image "
+
 #define YAGL_EGL_BUFFER_AGE_EXTENSIONS "EGL_EXT_buffer_age "
 
 #define YAGL_EGL_FENCE_EXTENSIONS "EGL_KHR_fence_sync "
@@ -306,6 +308,8 @@ const char *yagl_display_get_extensions(struct yagl_display *dpy)
             len += strlen(YAGL_EGL_FENCE_EXTENSIONS);
         }
 
+        len += strlen(YAGL_EGL_GL_TEXTURE_EXTENSIONS);
+
         dpy->extensions = yagl_malloc(len + 1);
 
         strcpy(dpy->extensions, YAGL_EGL_BASE_EXTENSIONS);
@@ -325,6 +329,8 @@ const char *yagl_display_get_extensions(struct yagl_display *dpy)
         if (yagl_egl_fence_supported()) {
             strcat(dpy->extensions, YAGL_EGL_FENCE_EXTENSIONS);
         }
+
+        strcat(dpy->extensions, YAGL_EGL_GL_TEXTURE_EXTENSIONS);
     }
 
     pthread_mutex_unlock(&dpy->mutex);
index 9216560ff7aaa3fa771c2630345b572b9e0cad69..59aa871e31f7db6bc1351dfc99f5f5a0b4a27b64 100644 (file)
@@ -1631,7 +1631,7 @@ out:
 }
 
 YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
-                                       EGLContext ctx,
+                                       EGLContext ctx_,
                                        EGLenum target,
                                        EGLClientBuffer buffer,
                                        const EGLint *attrib_list)
@@ -1639,6 +1639,7 @@ YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
     EGLImageKHR ret = EGL_NO_IMAGE_KHR;
     struct yagl_client_interface *iface = NULL;
     struct yagl_display *dpy = NULL;
+    struct yagl_context *ctx = NULL;
     struct yagl_native_drawable *native_buffer = NULL;
     struct yagl_image *image = NULL;
     int i = 0;
@@ -1646,7 +1647,7 @@ YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
     YAGL_LOG_FUNC_ENTER(eglCreateImageKHR,
                         "dpy = %u, ctx = %u, target = %u, buffer = %p",
                         (yagl_host_handle)dpy_,
-                        (yagl_host_handle)ctx,
+                        (yagl_host_handle)ctx_,
                         target,
                         buffer);
 
@@ -1733,6 +1734,36 @@ YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
             goto out;
         }
 
+        break;
+    case EGL_GL_TEXTURE_2D_KHR:
+        if (attrib_list) {
+            while (attrib_list[i] != EGL_NONE) {
+                switch (attrib_list[i]) {
+                case EGL_IMAGE_PRESERVED_KHR:
+                case EGL_GL_TEXTURE_LEVEL_KHR:
+                    break;
+                default:
+                    YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
+                    goto out;
+                }
+
+                i += 2;
+            }
+        }
+
+        if (!yagl_validate_context(dpy, ctx_, &ctx)) {
+            goto out;
+        }
+
+        image = yagl_get_backend()->create_image_gl_texture_2d(dpy,
+                                                               ctx,
+                                                               (yagl_object_name)buffer,
+                                                               iface);
+
+        if (!image) {
+            goto out;
+        }
+
         break;
     default:
         YAGL_SET_ERR(EGL_BAD_PARAMETER);
@@ -1749,6 +1780,8 @@ YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
 out:
     yagl_image_release(image);
 
+    yagl_context_release(ctx);
+
     YAGL_LOG_FUNC_EXIT("%p", ret);
 
     return ret;
index 4bb21fa59000f85b53b07608f8cd4587a7f70157..e8c3781c27ec851599e8447f38cabd5d44f03a44 100644 (file)
@@ -134,6 +134,15 @@ static struct yagl_image
     return NULL;
 }
 
+static struct yagl_image
+    *yagl_offscreen_create_image_gl_texture_2d(struct yagl_display *dpy,
+                                               struct yagl_context *ctx,
+                                               yagl_object_name texture,
+                                               struct yagl_client_interface *iface)
+{
+    return NULL;
+}
+
 static struct yagl_fence
     *yagl_offscreen_create_fence(struct yagl_display *dpy)
 {
@@ -157,6 +166,7 @@ struct yagl_backend *yagl_offscreen_create()
     backend->create_pbuffer_surface = &yagl_offscreen_create_pbuffer_surface;
     backend->create_image_pixmap = &yagl_offscreen_create_image_pixmap;
     backend->create_image_wl_buffer = &yagl_offscreen_create_image_wl_buffer;
+    backend->create_image_gl_texture_2d = &yagl_offscreen_create_image_gl_texture_2d;
     backend->create_fence = &yagl_offscreen_create_fence;
     backend->destroy = &yagl_offscreen_destroy;
     backend->y_inverted = 1;
index 8fd1f381914f40fed2fc3cb5b79a767ebbfdf374..4af18638a3f188f76b09aaa43c002410d9fe84bf 100644 (file)
@@ -37,6 +37,7 @@
 #ifdef YAGL_PLATFORM_WAYLAND
 #include "yagl_onscreen_image_wl_buffer.h"
 #endif
+#include "yagl_onscreen_image_gl_texture_2d.h"
 #include "yagl_onscreen_fence.h"
 #include "yagl_backend.h"
 #include "yagl_malloc.h"
@@ -147,6 +148,18 @@ static struct yagl_image
 #endif
 }
 
+static struct yagl_image
+    *yagl_onscreen_create_image_gl_texture_2d(struct yagl_display *dpy,
+                                              struct yagl_context *ctx,
+                                              yagl_object_name texture,
+                                              struct yagl_client_interface *iface)
+{
+    struct yagl_onscreen_image_gl_texture_2d *image =
+        yagl_onscreen_image_gl_texture_2d_create(dpy, ctx, texture, iface);
+
+    return image ? &image->base: NULL;
+}
+
 static struct yagl_fence
     *yagl_onscreen_create_fence(struct yagl_display *dpy)
 {
@@ -172,6 +185,7 @@ struct yagl_backend *yagl_onscreen_create()
     backend->create_pbuffer_surface = &yagl_onscreen_create_pbuffer_surface;
     backend->create_image_pixmap = &yagl_onscreen_create_image_pixmap;
     backend->create_image_wl_buffer = &yagl_onscreen_create_image_wl_buffer;
+    backend->create_image_gl_texture_2d = &yagl_onscreen_create_image_gl_texture_2d;
     backend->create_fence = &yagl_onscreen_create_fence;
     backend->destroy = &yagl_onscreen_destroy;
     backend->y_inverted = 0;
diff --git a/EGL/yagl_onscreen_image_gl_texture_2d.c b/EGL/yagl_onscreen_image_gl_texture_2d.c
new file mode 100644 (file)
index 0000000..ede3b1c
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * YaGL
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact :
+ * Vasily Ulyanov <v.ulyanov@samsung.com>
+ * Jinhyung Jo <jinhyung.jo@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include "yagl_onscreen_image_gl_texture_2d.h"
+#include "yagl_client_interface.h"
+#include "yagl_client_image.h"
+#include "yagl_egl_state.h"
+#include "yagl_context.h"
+#include "yagl_malloc.h"
+
+static void yagl_onscreen_image_gl_texture_2d_update(struct yagl_image *image)
+{
+}
+
+static void yagl_onscreen_image_gl_texture_2d_destroy(struct yagl_ref *ref)
+{
+    struct yagl_onscreen_image_gl_texture_2d *image = (struct yagl_onscreen_image_gl_texture_2d *)ref;
+
+    yagl_object_release(image->texture_obj);
+
+    yagl_image_cleanup(&image->base);
+
+    yagl_free(image);
+}
+
+
+struct yagl_onscreen_image_gl_texture_2d
+    *yagl_onscreen_image_gl_texture_2d_create(struct yagl_display *dpy,
+                                              struct yagl_context *ctx,
+                                              yagl_object_name texture,
+                                              struct yagl_client_interface *iface)
+{
+    struct yagl_client_image *client_image;
+    struct yagl_onscreen_image_gl_texture_2d *image;
+    struct yagl_object *texture_obj = NULL;
+
+    image = yagl_malloc0(sizeof(*image));
+
+    client_image = iface->wrap_texture(iface,
+                                       ctx->client_ctx,
+                                       texture,
+                                       &texture_obj);
+
+    if (!client_image) {
+        yagl_set_error(EGL_BAD_PARAMETER);
+        goto fail;
+    }
+
+    yagl_image_init(&image->base,
+                    &yagl_onscreen_image_gl_texture_2d_destroy,
+                    dpy,
+                    (EGLImageKHR)image,
+                    client_image);
+
+    yagl_client_image_release(client_image);
+
+    image->base.update = &yagl_onscreen_image_gl_texture_2d_update;
+
+    image->texture_obj = texture_obj;
+
+    return image;
+
+fail:
+    if (texture_obj) {
+        yagl_object_release(texture_obj);
+    }
+
+    yagl_free(image);
+
+    return NULL;
+}
diff --git a/EGL/yagl_onscreen_image_gl_texture_2d.h b/EGL/yagl_onscreen_image_gl_texture_2d.h
new file mode 100644 (file)
index 0000000..16b1245
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * YaGL
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact :
+ * Vasily Ulyanov <v.ulyanov@samsung.com>
+ * Jinhyung Jo <jinhyung.jo@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef _YAGL_ONSCREEN_IMAGE_GL_TEXTURE_2D_H_
+#define _YAGL_ONSCREEN_IMAGE_GL_TEXTURE_2D_H_
+
+#include "yagl_image.h"
+#include "EGL/egl.h"
+
+struct yagl_context;
+struct yagl_client_interface;
+
+struct yagl_onscreen_image_gl_texture_2d
+{
+    struct yagl_image base;
+
+    struct yagl_object *texture_obj;
+};
+
+struct yagl_onscreen_image_gl_texture_2d
+    *yagl_onscreen_image_gl_texture_2d_create(struct yagl_display *dpy,
+                                              struct yagl_context *ctx,
+                                              yagl_object_name texture,
+                                              struct yagl_client_interface *iface);
+
+#endif
index bdd81a0cb7aa403c592b6f4b6513ef36cee719f4..ffb95a6f7e9453161b2c38e05c9acf8c4ebdb252 100644 (file)
@@ -33,6 +33,9 @@
 
 #include "GL/gl.h"
 #include "yagl_gles_image.h"
+#include "yagl_gles_texture.h"
+#include "yagl_client_context.h"
+#include "yagl_sharegroup.h"
 #include "yagl_malloc.h"
 #include "yagl_host_gles_calls.h"
 
@@ -56,7 +59,9 @@ static void yagl_gles_image_destroy(struct yagl_ref *ref)
 {
     struct yagl_gles_image *image = (struct yagl_gles_image*)ref;
 
-    yagl_host_glDeleteObjects(&image->tex_global_name, 1);
+    if (image->own_tex) {
+        yagl_host_glDeleteObjects(&image->tex_global_name, 1);
+    }
 
     yagl_client_image_cleanup(&image->base);
 
@@ -74,8 +79,43 @@ struct yagl_gles_image *yagl_gles_image_create(yagl_object_name tex_global_name)
     image->base.update = &yagl_gles_image_update;
 
     image->tex_global_name = tex_global_name;
+    image->own_tex = 1;
+
+    return image;
+}
+
+struct yagl_gles_image *yagl_gles_image_wrap_tex(struct yagl_client_context *ctx,
+                                                 yagl_object_name tex_local_name,
+                                                 struct yagl_object **obj)
+{
+    struct yagl_gles_texture *texture_obj;
+    struct yagl_gles_image *image;
+
+    texture_obj = (struct yagl_gles_texture *)yagl_sharegroup_acquire_object(ctx->sg,
+                                                                             YAGL_NS_TEXTURE,
+                                                                             tex_local_name);
+
+    if (!texture_obj) {
+        goto fail;
+    }
+
+    image = yagl_malloc0(sizeof(*image));
+
+    yagl_client_image_init(&image->base, &yagl_gles_image_destroy);
+
+    image->base.update = &yagl_gles_image_update;
+
+    image->tex_global_name = texture_obj->global_name;
+    image->own_tex = 0;
+
+    *obj = &texture_obj->base;
 
     return image;
+
+fail:
+    yagl_gles_texture_release(texture_obj);
+
+    return NULL;
 }
 
 void yagl_gles_image_acquire(struct yagl_gles_image *image)
index ece73a3818c2e7b14bdddd4b37542b83bd9e2eb0..431eb790105142181836d569008c6c4e2c9d7d8a 100644 (file)
 #include "yagl_types.h"
 #include "yagl_client_image.h"
 
+struct yagl_client_context;
+
 struct yagl_gles_image
 {
     struct yagl_client_image base;
 
     yagl_object_name tex_global_name;
+
+    int own_tex;
 };
 
 struct yagl_gles_image *yagl_gles_image_create(yagl_object_name tex_global_name);
 
+struct yagl_gles_image *yagl_gles_image_wrap_tex(struct yagl_client_context *ctx,
+                                                 yagl_object_name tex_local_name,
+                                                 struct yagl_object **obj);
+
 /*
  * Passing NULL won't hurt, this is for convenience.
  */
index 93e3a00c6298b93d0149d31667855583f2404c3b..0d7315686635e7110da6df006b3b176f5b06f93c 100644 (file)
@@ -52,6 +52,15 @@ static struct yagl_client_image
     return &yagl_gles_image_create(tex_global_name)->base;
 }
 
+static struct yagl_client_image
+    *yagl_gles1_wrap_texture(struct yagl_client_interface *iface,
+                             struct yagl_client_context *ctx,
+                             yagl_object_name tex_local_name,
+                             struct yagl_object **texture_obj)
+{
+    return &yagl_gles_image_wrap_tex(ctx,tex_local_name, texture_obj)->base;
+}
+
 static void yagl_gles1_release_tex_image(struct yagl_client_interface *iface,
                                          void *cookie)
 {
@@ -64,5 +73,6 @@ YAGL_API struct yagl_client_interface yagl_gles1_interface =
 {
     .create_ctx = &yagl_gles1_create_ctx,
     .create_image = &yagl_gles1_create_image,
+    .wrap_texture = &yagl_gles1_wrap_texture,
     .release_tex_image = &yagl_gles1_release_tex_image
 };
index be48b1f5010c4fcaaeaf62c2b878022e72a4e094..4b24e099628c9159a2d197cceb5f4da3b22cb876 100644 (file)
@@ -60,6 +60,15 @@ static struct yagl_client_image
     return &yagl_gles_image_create(tex_global_name)->base;
 }
 
+static struct yagl_client_image
+    *yagl_gles2_wrap_texture(struct yagl_client_interface *iface,
+                             struct yagl_client_context *ctx,
+                             yagl_object_name tex_local_name,
+                             struct yagl_object **texture_obj)
+{
+    return &yagl_gles_image_wrap_tex(ctx, tex_local_name, texture_obj)->base;
+}
+
 static void yagl_gles2_release_tex_image(struct yagl_client_interface *iface,
                                          void *cookie)
 {
@@ -72,5 +81,6 @@ YAGL_API struct yagl_client_interface yagl_gles2_interface =
 {
     .create_ctx = &yagl_gles2_create_ctx,
     .create_image = &yagl_gles2_create_image,
+    .wrap_texture = &yagl_gles2_wrap_texture,
     .release_tex_image = &yagl_gles2_release_tex_image
 };
index db5e461b1a981bb03bf560d61aa8e75d8ee9e750..62fb3dfe66d3dd64e6f72d1e2fdb66ad7c77e199 100644 (file)
@@ -39,6 +39,7 @@
 struct yagl_client_context;
 struct yagl_client_image;
 struct yagl_sharegroup;
+struct yagl_object;
 
 struct yagl_client_interface
 {
@@ -50,6 +51,12 @@ struct yagl_client_interface
         *(*create_image)(struct yagl_client_interface */*iface*/,
                          yagl_object_name /*tex_global_name*/);
 
+    struct yagl_client_image
+        *(*wrap_texture)(struct yagl_client_interface */*iface*/,
+                         struct yagl_client_context */*ctx*/,
+                         yagl_object_name /*tex_local_name*/,
+                         struct yagl_object **/*obj*/);
+
     void (*release_tex_image)(struct yagl_client_interface */*iface*/,
                               void */*cookie*/);
 };