YaGL: Fixed a memory bug in glGetBooleanv and glGetFloatv
authorStanislav Vorobiov <s.vorobiov@samsung.com>
Fri, 21 Sep 2012 08:40:20 +0000 (12:40 +0400)
committerEvgeny Voevodin <e.voevodin@samsung.com>
Mon, 8 Oct 2012 08:21:38 +0000 (12:21 +0400)
YaGL: Fixed for Tizen 2.0

hw/yagl_apis/egl/yagl_host_egl_calls.c
hw/yagl_apis/gles/yagl_host_gles_calls.c
hw/yagl_apis/gles/yagl_host_gles_calls.h
hw/yagl_apis/gles2/yagl_gles2_context.c
hw/yagl_mem_gl.h
hw/yagl_version.h

index 2e9fa4e3dd9ba4b27bfa225d8b88eebe5386d28c..7086af3fd45b7df91adae29d913326b4df53a89b 100644 (file)
@@ -1237,6 +1237,12 @@ EGLBoolean yagl_host_eglMakeCurrent(yagl_host_handle dpy_,
         yagl_egl_context_update_surfaces(prev_ctx, NULL, NULL);
     }
 
+    YAGL_LOG_TRACE("Context switched (%u, %u, %u, %u)",
+                   dpy_,
+                   draw_,
+                   read_,
+                   ctx_);
+
     ret = EGL_TRUE;
 
 out:
@@ -1480,7 +1486,82 @@ yagl_host_handle yagl_host_eglCreatePixmapSurfaceOffscreenYAGL(yagl_host_handle
     target_ulong /* void* */ pixels_,
     target_ulong /* const EGLint* */ attrib_list_)
 {
-    YAGL_UNIMPLEMENTED(eglCreatePixmapSurfaceOffscreenYAGL, 0);
+    yagl_host_handle ret = 0;
+    EGLint *attrib_list = NULL;
+    struct yagl_compiled_transfer *bimage_ct = NULL;
+    struct yagl_egl_pixmap_attribs attribs;
+    struct yagl_egl_display *dpy = NULL;
+    struct yagl_egl_config *config = NULL;
+    struct yagl_egl_surface *surface = NULL;
+
+    YAGL_LOG_FUNC_SET_TS(egl_api_ts->ts, eglCreatePixmapSurfaceOffscreenYAGL);
+
+    if (attrib_list_) {
+        attrib_list = yagl_mem_get_attrib_list(egl_api_ts->ts,
+                                               attrib_list_);
+
+        if (!attrib_list) {
+            YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
+            goto out;
+        }
+    }
+
+    bimage_ct = yagl_compiled_transfer_create(egl_api_ts->ts,
+                                              pixels_,
+                                              (width * height * bpp),
+                                              true);
+
+    if (!bimage_ct) {
+        YAGL_SET_ERR(EGL_BAD_NATIVE_PIXMAP);
+        goto out;
+    }
+
+    yagl_egl_pixmap_attribs_init(&attribs);
+
+    if (!yagl_egl_is_attrib_list_empty(attrib_list)) {
+        YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
+        goto out;
+    }
+
+    if (!yagl_validate_display(dpy_, &dpy)) {
+        goto out;
+    }
+
+    if (!yagl_validate_config(dpy, config_, &config)) {
+        goto out;
+    }
+
+    surface = yagl_egl_surface_create_pixmap(dpy,
+                                             config,
+                                             &attribs,
+                                             bimage_ct,
+                                             width,
+                                             height,
+                                             bpp);
+
+    if (!surface) {
+        YAGL_SET_ERR(EGL_BAD_ALLOC);
+        goto out;
+    }
+
+    /*
+     * Owned by 'surface' now.
+     */
+    bimage_ct = NULL;
+
+    yagl_egl_display_add_surface(dpy, surface);
+    yagl_egl_surface_release(surface);
+
+    ret = surface->res.handle;
+
+out:
+    yagl_egl_config_release(config);
+    if (bimage_ct) {
+        yagl_compiled_transfer_destroy(bimage_ct);
+    }
+    g_free(attrib_list);
+
+    return ret;
 }
 
 EGLBoolean yagl_host_eglResizeOffscreenSurfaceYAGL(yagl_host_handle dpy_,
index edb6e3808b5c8d9878dad519a03a0b30c6ee63c9..421a0f92383723ce21a228e813ddb5cdf52022ff 100644 (file)
@@ -861,6 +861,7 @@ void yagl_host_glGetBooleanv(GLenum pname,
     YAGL_GET_CTX(glGetBooleanv);
 
     if (!ctx->get_param_count(ctx, pname, &count)) {
+        YAGL_LOG_ERROR("Bad pname = 0x%X", pname);
         YAGL_SET_ERR(GL_INVALID_ENUM);
         goto out;
     }
@@ -879,9 +880,9 @@ void yagl_host_glGetBooleanv(GLenum pname,
 
     if (params_) {
         for (i = 0; i < count; ++i) {
-            yagl_mem_put_GLuint(ts,
-                                params_ + (i * sizeof(*params)),
-                                params[i]);
+            yagl_mem_put_GLboolean(ts,
+                                   params_ + (i * sizeof(*params)),
+                                   params[i]);
         }
     }
 
@@ -920,6 +921,7 @@ void yagl_host_glGetFloatv(GLenum pname,
     YAGL_GET_CTX(glGetFloatv);
 
     if (!ctx->get_param_count(ctx, pname, &count)) {
+        YAGL_LOG_ERROR("Bad pname = 0x%X", pname);
         YAGL_SET_ERR(GL_INVALID_ENUM);
         goto out;
     }
@@ -938,9 +940,9 @@ void yagl_host_glGetFloatv(GLenum pname,
 
     if (params_) {
         for (i = 0; i < count; ++i) {
-            yagl_mem_put_GLuint(ts,
-                                params_ + (i * sizeof(*params)),
-                                params[i]);
+            yagl_mem_put_GLfloat(ts,
+                                 params_ + (i * sizeof(*params)),
+                                 params[i]);
         }
     }
 
@@ -957,6 +959,7 @@ void yagl_host_glGetIntegerv(GLenum pname,
     YAGL_GET_CTX(glGetIntegerv);
 
     if (!ctx->get_param_count(ctx, pname, &count)) {
+        YAGL_LOG_ERROR("Bad pname = 0x%X", pname);
         YAGL_SET_ERR(GL_INVALID_ENUM);
         goto out;
     }
@@ -1048,9 +1051,54 @@ void yagl_host_glReadPixels(GLint x,
     GLsizei height,
     GLenum format,
     GLenum type,
-    target_ulong /* GLvoid* */ pixels)
+    target_ulong /* GLvoid* */ pixels_)
 {
-    YAGL_UNIMPLEMENTED(glReadPixels);
+    yagl_object_name current_pbo = 0;
+    GLvoid *pixels = NULL;
+    GLsizei stride = 0;
+
+    YAGL_GET_CTX(glReadPixels);
+
+    if (pixels_ && (width > 0) && (height > 0)) {
+        if (!yagl_get_stride(ctx->driver_ps,
+                             GL_PACK_ALIGNMENT,
+                             width,
+                             format,
+                             type,
+                             &stride)) {
+            YAGL_SET_ERR(GL_INVALID_VALUE);
+            goto out;
+        }
+        pixels = yagl_gles_context_malloc(ctx, stride * height);
+        ctx->driver_ps->GetIntegerv(ctx->driver_ps,
+                                    GL_PIXEL_PACK_BUFFER_BINDING_ARB,
+                                    (GLint*)&current_pbo);
+        if (current_pbo != 0) {
+            ctx->driver_ps->BindBuffer(ctx->driver_ps,
+                                       GL_PIXEL_PACK_BUFFER_ARB,
+                                       0);
+        }
+
+        ctx->driver_ps->ReadPixels(ctx->driver_ps,
+                                   x,
+                                   y,
+                                   width,
+                                   height,
+                                   format,
+                                   type,
+                                   pixels);
+
+        if (current_pbo != 0) {
+            ctx->driver_ps->BindBuffer(ctx->driver_ps,
+                                       GL_PIXEL_PACK_BUFFER_ARB,
+                                       current_pbo);
+        }
+
+        yagl_mem_put(ts, pixels_, stride * height, pixels);
+    }
+
+out:
+    (void)0;
 }
 
 void yagl_host_glSampleCoverage(GLclampf value,
index 148d16a8952f7274860187ca5b4d3362967956dd..95ac2f74fd0ac817a4a1892c9fef136c98fe46aa 100644 (file)
@@ -119,7 +119,7 @@ void yagl_host_glReadPixels(GLint x,
     GLsizei height,
     GLenum format,
     GLenum type,
-    target_ulong /* GLvoid* */ pixels);
+    target_ulong /* GLvoid* */ pixels_);
 void yagl_host_glSampleCoverage(GLclampf value,
     GLboolean invert);
 void yagl_host_glScissor(GLint x,
index 5ba0084257363c4328a42c0d7b779dd70616005d..ec8835c53c8dbcff5eebf24bf2047a07c69d250c 100644 (file)
@@ -6,6 +6,7 @@
 #include "yagl_thread.h"
 #include "yagl_sharegroup.h"
 #include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
 #include "yagl_gles2_driver.h"
 
 static void yagl_gles2_array_apply(struct yagl_gles_array *array)
@@ -137,6 +138,7 @@ static bool yagl_gles2_context_get_param_count(struct yagl_gles_context *ctx,
     case GL_TEXTURE_BINDING_CUBE_MAP: *count = 1; break;
     case GL_UNPACK_ALIGNMENT: *count = 1; break;
     case GL_VIEWPORT: *count = 4; break;
+    case GL_MAX_SAMPLES_IMG: *count = 1; break;
     default: return false;
     }
     return true;
index 1be3a023f32418f7fdce61a6b9fdc8b0002430a9..1ffc97cc37b5a0816bfc60b2d7715da7d66cbd1a 100644 (file)
@@ -11,5 +11,9 @@
 #define yagl_mem_get_GLsizei(ts, va, value) yagl_mem_get_int32((ts), (va), (value))
 #define yagl_mem_put_GLenum(ts, va, value) yagl_mem_put_uint32((ts), (va), (value))
 #define yagl_mem_get_GLenum(ts, va, value) yagl_mem_get_uint32((ts), (va), (value))
+#define yagl_mem_put_GLfloat(ts, va, value) yagl_mem_put_float((ts), (va), (value))
+#define yagl_mem_get_GLfloat(ts, va, value) yagl_mem_get_float((ts), (va), (value))
+#define yagl_mem_put_GLboolean(ts, va, value) yagl_mem_put_uint8((ts), (va), (value))
+#define yagl_mem_get_GLboolean(ts, va, value) yagl_mem_get_uint8((ts), (va), (value))
 
 #endif
index 6ba7f3cb3c4e73518ab9cbc3242a2ccb289ccf8a..166ecfcd1ed69a3a7f45f37b5d3552045660d5ee 100644 (file)
@@ -6,6 +6,6 @@
 /*
  * Whenever protocol changes be sure to bump this.
  */
-#define YAGL_VERSION 5
+#define YAGL_VERSION 6
 
 #endif