Package: GL
authormunkyu.im <munkyu.im@samsung.com>
Mon, 28 Jan 2013 02:10:11 +0000 (11:10 +0900)
committermunkyu.im <munkyu.im@samsung.com>
Mon, 28 Jan 2013 02:10:11 +0000 (11:10 +0900)
 Fix mac blank screen in browser, webapp and code clean up of gloffscreen_agl.c
 Fix effectsApp crash QEMU on MAC.

Signed-off-by: Zhai Edwin <edwin.zhai@intel.com>
Signed-off-by: Gao Fengqian <fengqian.gao@intel.com>
tizen/src/hw/gloffscreen.h
tizen/src/hw/gloffscreen_agl.c
tizen/src/hw/gloffscreen_wgl.c
tizen/src/hw/gloffscreen_xcomposite.c
tizen/src/hw/opengl_exec.c

index 05e377a..806db14 100644 (file)
@@ -81,7 +81,7 @@ extern GloContext *glo_context_create(int formatFlags, GloContext *shareLists);
 extern void glo_context_destroy(GloContext *context);
 
 /* Update the context in surface and free previous light-weight context */
-extern int glo_surface_update_context(GloSurface *surface, GloContext *context);
+extern void glo_surface_update_context(GloSurface *surface, GloContext *context, int free_flags);
 
 /* Link the pixmap associated with surface as texture */
 extern void glo_surface_as_texture(GloSurface *surface);
index 80577a3..4a42907 100644 (file)
@@ -177,7 +177,7 @@ GloContext *__glo_context_create(int formatFlags)
             default: fprintf(stderr, "got unsupported stencil %d", s); break;
          }
      }
-    GloContext *context = (GloContext *)malloc(sizeof(*context));
+    GloContext *context = (GloContext *)g_malloc(sizeof(*context));
     memset(context, 0, sizeof(*context));
     context->formatFlags = formatFlags;
     context->pixelFormat = pf;
@@ -188,48 +188,53 @@ GloContext *__glo_context_create(int formatFlags)
  
 GloContext *glo_context_create(int formatFlags, GloContext *shareLists) 
 { 
-       GloContext *context = __glo_context_create(formatFlags);
-       if(!context)
-               return NULL;
+        GloContext *context = __glo_context_create(formatFlags);
+        if(!context)
+                return NULL;
 
-       context->context = aglCreateContext(context->pixelFormat, shareLists ? shareLists->context : NULL); 
-       if (context->context == NULL) 
-       { 
-        fprintf(stderr, "aglCreateContext failed: %s", aglErrorString(aglGetError())); 
-       } 
+        context->context = aglCreateContext(context->pixelFormat, shareLists ? shareLists->context : NULL); 
+        if (context->context == NULL) 
+        { 
+                fprintf(stderr, "aglCreateContext failed: %s", aglErrorString(aglGetError())); 
+        } 
+        else
+        {
+                if(context->pixelFormat != NULL)
+                {
+                        aglDestroyPixelFormat(context->pixelFormat);
+                        context->pixelFormat = NULL;    
+                }
+        }
 
-       TRACE("context=%p", context); 
-       return context; 
+        TRACE("context=%p", context); 
+        return context; 
 } 
-  
+
 /* Destroy a previously created OpenGL context */ 
 void glo_context_destroy(GloContext *context) 
 { 
      TRACE("context=%p", context); 
      if (context) 
      { 
-         aglDestroyContext(context->context); 
-         aglDestroyPixelFormat(context->pixelFormat); 
-         context->context = NULL; 
-         context->pixelFormat = NULL; 
-         free(context); 
+             aglDestroyContext(context->context);
+             if(context->pixelFormat != NULL)
+             { 
+                     aglDestroyPixelFormat(context->pixelFormat);
+                     context->pixelFormat = NULL; 
+             }
+             context->context = NULL;  
+             g_free(context); 
      } 
  }
 
-int glo_surface_update_context(GloSurface *surface, GloContext *context)
+void glo_surface_update_context(GloSurface *surface, GloContext *context, int free_flags)
 {
-
-    int prev_context_valid = 0;
-
     if ( surface->context )
     {
-        prev_context_valid = (surface->context->context != 0);
-        if ( !prev_context_valid ) /* light-weight context */
-            g_free(surface->context);
+            if (free_flags) /* light-weight context */
+                    g_free(surface->context);
     }
     surface->context = context;
-
-    return prev_context_valid;
 }
 
  
@@ -241,7 +246,7 @@ GloSurface *glo_surface_create(int width, int height, GloContext *context)
      GloSurface *surface = NULL; 
      if (context) 
      { 
-         surface = (GloSurface *)malloc(sizeof(*surface)); 
+         surface = (GloSurface *)g_malloc(sizeof(*surface)); 
          memset(surface, 0, sizeof(*surface)); 
          surface->width = width; 
          surface->height = height; 
@@ -264,7 +269,7 @@ void glo_surface_destroy(GloSurface *surface)
     { 
        aglDestroyPBuffer(surface->pbuffer); 
        surface->pbuffer = NULL; 
-       free(surface); 
+       g_free(surface); 
     } 
 } 
  
index bb73d83..0290d76 100644 (file)
@@ -871,21 +871,18 @@ void glo_context_destroy(GloContext *context) {
 /* ------------------------------------------------------------------------ */
 
 /* Update the context in surface and handle previous context */
-int glo_surface_update_context(GloSurface *surface, GloContext *context)
+void glo_surface_update_context(GloSurface *surface, GloContext *context, int free_flags)
 {
     /* If previous context is light-weight context, just free it. If previous
      * context is valid one binded with surface via MakeCurrent, we need unbind
      * from original glstate */
-    int prev_context_valid = 0;
 
     if ( surface->context )
     {
-        prev_context_valid = (surface->context->hContext != 0);
-        if ( !prev_context_valid ) /* light-weight context */
+            if ( free_flags) /* light-weight context */
             g_free(surface->context);
     }
     surface->context = context;
-    return prev_context_valid;
 }
 
 /* Create a surface with given width and height, formatflags are from the
index 0ca1f12..af37dce 100644 (file)
@@ -256,21 +256,18 @@ static void glo_surface_try_alloc_xshm_image(GloSurface *surface) {
 /* ------------------------------------------------------------------------ */
 
 /* Update the context in surface and handle previous context */
-int glo_surface_update_context(GloSurface *surface, GloContext *context)
+void glo_surface_update_context(GloSurface *surface, GloContext *context, int free_flags)
  {
     /* If previous context is light-weight context, just free it. If previous
      * context is valid one binded with surface via MakeCurrent, we need unbind
      * from original glstate */
-    int prev_context_valid = 0;
 
      if ( surface->context )
     {
-        prev_context_valid = (surface->context->context != 0);
-        if ( !prev_context_valid ) /* light-weight context */
+            if ( free_flags ) /* light-weight context */
             g_free(surface->context);
     }
     surface->context = context;
-    return prev_context_valid;
 }
 
 /* Create a surface with given width and height, formatflags are from the
index 7f14336..b1b438f 100644 (file)
@@ -208,12 +208,18 @@ enum {
     SURFACE_PBUFFER,
 };
 
+enum {
+        SURFACE_PENDING,    /* Created with light-weight context */
+        SURFACE_ACTIVE,     /* Ready after MakeCurrent */
+};
+
 typedef struct QGloSurface {
     GLState *glstate;
     GloSurface *surface;
     ClientGLXDrawable *client_drawable;
     int type; /* window, pixmap or pbuffer */
     int ready;
+    int status;
     int ref;
     QTAILQ_ENTRY(QGloSurface) next;
 } QGloSurface;
@@ -653,6 +659,7 @@ static int set_current_qsurface(GLState *state,
     QTAILQ_FOREACH(qsurface, &state->qsurfaces, next) {
         if(qsurface->client_drawable == client_drawable) {
             state->current_qsurface = qsurface;
+            qsurface->glstate = state;
             return 1;
         }
     }
@@ -731,8 +738,18 @@ static int link_qsurface(ProcessState *process, GLState *glstate, ClientGLXDrawa
 #endif
 
             qsurface->ref = 1;
-            if ( glo_surface_update_context(qsurface->surface, glstate->context) )
-                unbind_qsurface(qsurface->glstate, qsurface);
+            if(qsurface->status == SURFACE_PENDING)
+            {
+                    glo_surface_update_context(qsurface->surface, glstate->context, 1);
+                    qsurface->status = SURFACE_ACTIVE;
+            }
+            else
+            {
+                    unbind_qsurface(qsurface->glstate, qsurface);
+                    glo_surface_update_context(qsurface->surface, glstate->context, 0);
+
+            }
+
             bind_qsurface(glstate, qsurface);
             return 1;
         }
@@ -1962,7 +1979,8 @@ int do_function_call(ProcessState *process, int func_number, unsigned long *args
                 DEBUGF( "glXCreatePixmap: %dX%d.\n", width, height);
                 qsurface->surface = glo_surface_create(width, height, context);
                 qsurface->client_drawable = client_drawable;
-               qsurface->type = SURFACE_PIXMAP;
+                qsurface->type = SURFACE_PIXMAP;
+                qsurface->status = SURFACE_PENDING;
                 /*                qsurface->ref = 1;*/
 
                 /* Keep this surface, will link it with context in MakeCurrent */
@@ -2987,6 +3005,17 @@ int do_function_call(ProcessState *process, int func_number, unsigned long *args
                 glColorPointer(4, GL_UNSIGNED_BYTE, stride,
                                ptr + 6 * sizeof(float));
             glDrawArrays(mode, 0, count);
+
+#ifdef __APPLE__  //only for mac
+            {
+                    int prev_fbo;
+                    glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+                    if ( prev_fbo != 0 )
+                            glFlush();
+            }
+#endif
+
+
             break;
         }
 
@@ -3457,6 +3486,16 @@ int do_function_call(ProcessState *process, int func_number, unsigned long *args
     case _glDrawElements_buffer_func:
         {
             glDrawElements(args[0], args[1], args[2], (void *) args[3]);
+
+#ifdef __APPLE__  //only for mac
+            {
+                    int prev_fbo;
+                    glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+                    if ( prev_fbo != 0 )
+                            glFlush();
+            }
+#endif
+
             break;
         }
 #ifndef _WIN32
@@ -3473,8 +3512,37 @@ int do_function_call(ProcessState *process, int func_number, unsigned long *args
                         (int, int *, int, void **, int));
             ptr_func_glMultiDrawElements(args[0], (int *) args[1], args[2],
                                          (void **) args[3], args[4]);
+#ifdef __APPLE__  //only for mac
+            {
+                    int prev_fbo;
+                    glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+                    if ( prev_fbo != 0 )
+                            glFlush();
+            }
+#endif
+
             break;
         }
+#ifdef __APPLE__  // only for mac
+    case glDrawArrays_func:
+        {
+                int prev_fbo;
+                glDrawArrays(ARG_TO_UNSIGNED_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]));
+                glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+                if ( prev_fbo != 0 )
+                        glFlush();
+                break;
+        }
+    case glDrawElements_func:
+        {
+                int prev_fbo;
+                glDrawElements(ARG_TO_UNSIGNED_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_UNSIGNED_INT(args[2]), (const void*)(args[3]));
+                glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &prev_fbo);
+                if ( prev_fbo != 0 )
+                        glFlush();
+                break;
+        }
+#endif
 
     case _glGetError_fake_func:
         {