more complete gl-texture-pixmap handling, but still is broken on fglrx. hmmm.
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sun, 31 Jan 2010 02:50:01 +0000 (02:50 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sun, 31 Jan 2010 02:50:01 +0000 (02:50 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/evas@45750 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/modules/engines/gl_common/evas_gl_common.h
src/modules/engines/gl_common/evas_gl_context.c
src/modules/engines/gl_common/evas_gl_texture.c
src/modules/engines/gl_x11/evas_engine.c
src/modules/engines/gl_x11/evas_engine.h
src/modules/engines/gl_x11/evas_x_main.c
src/modules/engines/software_x11/evas_engine.c
src/modules/engines/xrender_x11/evas_engine.c

index 13df063..87c9e6c 100644 (file)
@@ -202,7 +202,9 @@ struct _Evas_GL_Image
          void     (*free)   (void *data, void *image);
          void      *data;
       } func;
-      unsigned char yinvert : 1;
+      int           yinvert;
+      int           target;
+      int           mipmap;
       unsigned char loose : 1;
    } native;
    
index fff65f9..49821a3 100644 (file)
@@ -916,9 +916,12 @@ shader_array_flush(Evas_GL_Context *gc)
      }
    if (gc->array.im)
      {
-        if (gc->array.im->native.func.bind)
-          gc->array.im->native.func.bind(gc->array.im->native.func.data, 
-                                         gc->array.im);
+        if (!gc->array.im->native.func.bind)
+          {
+             if (gc->array.im->native.func.bind)
+               gc->array.im->native.func.bind(gc->array.im->native.func.data, 
+                                              gc->array.im);
+          }
      }
    if (gc->shader.render_op != gc->shader.current.render_op)
      {
@@ -1051,9 +1054,12 @@ shader_array_flush(Evas_GL_Context *gc)
      }
    if (gc->array.im)
      {
-        if (gc->array.im->native.func.unbind)
-          gc->array.im->native.func.unbind(gc->array.im->native.func.data, 
-                                           gc->array.im);
+        if (!gc->array.im->native.func.bind)
+          {
+             if (gc->array.im->native.func.unbind)
+               gc->array.im->native.func.unbind(gc->array.im->native.func.data, 
+                                                gc->array.im);
+          }
 /*        
         gc->shader.cur_tex = 0;
         glBindTexture(GL_TEXTURE_2D, gc->shader.cur_tex);
index b10caa2..7b6faaf 100644 (file)
@@ -243,6 +243,7 @@ evas_gl_common_texture_new(Evas_GL_Context *gc, RGBA_Image *im)
                               &u, &v, &l_after, 1024);
    if (!tex->pt)
      {
+        memset(tex, 0x11, sizeof(Evas_GL_Texture)); // mark as freed
         free(tex);
         return NULL;
      }
@@ -318,20 +319,26 @@ _pool_tex_native_new(Evas_GL_Context *gc, int w, int h, int intformat, int forma
    pt = calloc(1, sizeof(Evas_GL_Texture_Pool));
    if (!pt) return NULL;
    pt->gc = gc;
-   pt->w = w;
-   pt->h = h;
+   if (im->native.target == GL_TEXTURE_RECTANGLE_ARB)
+     {
+        printf("REEEEEEEEECT\n");
+     }
+   else
+     {
+        printf("%i %i\n", w, h);
+        // FIXME: handle npo2
+        pt->w = w;
+        pt->h = h;
+     }
    pt->intformat = intformat;
    pt->format = format;
    pt->dataformat = GL_UNSIGNED_BYTE;
    pt->references = 0;
    pt->native = 1;
    glGenTextures(1, &(pt->texture));
-   glBindTexture(GL_TEXTURE_2D, pt->texture);
+   glBindTexture(im->native.target, pt->texture);
    
 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
-   // is this really needed for gl-es?
-//   glTexImage2D(GL_TEXTURE_2D, 0, intformat, w, h, 0, format, 
-//                GL_UNSIGNED_BYTE, 0);
 #else
    if (im->native.loose)
      {
@@ -340,12 +347,12 @@ _pool_tex_native_new(Evas_GL_Context *gc, int w, int h, int intformat, int forma
      }
 #endif
    
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-   glBindTexture(GL_TEXTURE_2D, 0);
-   glBindTexture(GL_TEXTURE_2D, gc->shader.cur_tex);
+   glTexParameteri(im->native.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+   glTexParameteri(im->native.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+   glTexParameteri(im->native.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+   glTexParameteri(im->native.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+   glBindTexture(im->native.target, 0);
+   glBindTexture(im->native.target, gc->shader.cur_tex);
    return pt;
 }
 
@@ -362,8 +369,10 @@ pt_unref(Evas_GL_Texture_Pool *pt)
           pt->gc->shared->tex.atlas [pt->slot][pt->fslot] =
           eina_list_remove(pt->gc->shared->tex.atlas[pt->slot][pt->fslot], pt);
      }
+   
    glDeleteTextures(1, &(pt->texture));
    if (pt->fb) glsym_glDeleteFramebuffers(1, &(pt->fb));
+   memset(pt, 0x22, sizeof(Evas_GL_Texture_Pool)); // mark as freed
    free(pt);
 }
 
@@ -386,6 +395,7 @@ evas_gl_common_texture_native_new(Evas_GL_Context *gc, int w, int h, int alpha,
      tex->pt = _pool_tex_native_new(gc, w, h, rgb_ifmt, rgb_fmt, im);
    if (!tex->pt)
      {
+        memset(tex, 0x33, sizeof(Evas_GL_Texture)); // mark as freed
         free(tex);
         return NULL;
      }
@@ -416,6 +426,7 @@ evas_gl_common_texture_render_new(Evas_GL_Context *gc, int w, int h, int alpha)
      tex->pt = _pool_tex_render_new(gc, w, h, rgb_ifmt, rgb_fmt);
    if (!tex->pt)
      {
+        memset(tex, 0x44, sizeof(Evas_GL_Texture)); // mark as freed
         free(tex);
         return NULL;
      }
@@ -514,6 +525,7 @@ evas_gl_common_texture_free(Evas_GL_Texture *tex)
      }
    if (tex->ptu) pt_unref(tex->ptu);
    if (tex->ptv) pt_unref(tex->ptv);
+   memset(tex, 0x55, sizeof(Evas_GL_Texture)); // mark as freed
    free(tex);
 }
 
@@ -537,6 +549,7 @@ evas_gl_common_texture_alpha_new(Evas_GL_Context *gc, DATA8 *pixels,
                             &l_after, tw);
    if (!tex->pt)
      {
+        memset(tex, 0x66, sizeof(Evas_GL_Texture)); // mark as freed
         free(tex);
         return NULL;
      }
@@ -585,6 +598,7 @@ evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, int w, int h)
    tex->pt = _pool_tex_new(gc, w + 1, h  + 1, lum_ifmt, lum_fmt);
    if (!tex->pt)
      {
+        memset(tex, 0x77, sizeof(Evas_GL_Texture)); // mark as freed
         free(tex);
         return NULL;
      }
@@ -595,6 +609,8 @@ evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, int w, int h)
    tex->ptu = _pool_tex_new(gc, (w / 2) + 1, (h / 2)  + 1, lum_ifmt, lum_fmt);
    if (!tex->ptu)
      {
+        pt_unref(tex->pt);
+        memset(tex, 0x88, sizeof(Evas_GL_Texture)); // mark as freed
         free(tex);
         return NULL;
      }
@@ -605,6 +621,9 @@ evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, int w, int h)
    tex->ptv = _pool_tex_new(gc, (w / 2) + 1, (h / 2)  + 1, lum_ifmt, lum_fmt);
    if (!tex->ptv)
      {
+        pt_unref(tex->pt);
+        pt_unref(tex->ptu);
+        memset(tex, 0x99, sizeof(Evas_GL_Texture)); // mark as freed
         free(tex);
         return NULL;
      }
index ea5f898..91da824 100644 (file)
@@ -30,7 +30,7 @@ typedef void (*_eng_fn) (void);
 _eng_fn  (*glsym_glXGetProcAddress)  (const char *a) = NULL;
 void     (*glsym_glXBindTexImage)    (Display *a, GLXDrawable b, int c, int *d) = NULL;
 void     (*glsym_glXReleaseTexImage) (Display *a, GLXDrawable b, int c) = NULL;
-int      (*glsym_glXGetVideoSync)    (Display *a) = NULL;
+int      (*glsym_glXGetVideoSync)    (unsigned int *a) = NULL;
 int      (*glsym_glXWaitVideoSync)   (int a, int b, unsigned int *c) = NULL;
 #endif
                 
@@ -215,9 +215,9 @@ eng_setup(Evas *e, void *in)
                          }
                        else
                          re->xr.dpi = atoi(str) * 1000;
+                       evas_common_font_dpi_set(re->xr.dpi / 1000);
                     }
                }
-             evas_common_font_dpi_set(re->xr.dpi / 1000);
           }
         
        evas_common_cpu_init();
@@ -461,7 +461,7 @@ eng_output_flush(void *data)
 # endif
    if (re->info->callback.pre_swap)
      {
-        glXWaitGL();
+        glFinish();
         re->info->callback.pre_swap(re->info->callback.data, re->evas);
      }
    glXSwapBuffers(re->win->disp, re->win->win);
@@ -1086,7 +1086,7 @@ struct _Native
 // why is this the case? does anyone know? has anyone tried it on other gfx
 // drivers?
 // 
-#define GLX_TEX_PIXMAP_RECREATE 1
+//#define GLX_TEX_PIXMAP_RECREATE 1
 
 static void
 _native_bind_cb(void *data, void *image)
@@ -1127,9 +1127,8 @@ _native_bind_cb(void *data, void *image)
         n->glx_pixmap = glXCreatePixmap(re->win->disp, n->fbc, 
                                         n->pixmap, pixmap_att);
 #endif        
-        if (!im->native.loose)
-          glsym_glXBindTexImage(re->win->disp, n->glx_pixmap, 
-                                GLX_FRONT_LEFT_EXT, NULL);
+        glsym_glXBindTexImage(re->win->disp, n->glx_pixmap, 
+                              GLX_FRONT_LEFT_EXT, NULL);
      }
 # endif
 #endif
@@ -1154,9 +1153,8 @@ _native_unbind_cb(void *data, void *image)
 # ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
    if (glsym_glXReleaseTexImage)
      {
-        if (!im->native.loose)
-          glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap, 
-                                   GLX_FRONT_LEFT_EXT);
+        glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap, 
+                                 GLX_FRONT_LEFT_EXT);
 #ifdef GLX_TEX_PIXMAP_RECREATE        
         glXDestroyPixmap(re->win->disp, n->glx_pixmap);
         n->glx_pixmap = 0;
@@ -1316,90 +1314,101 @@ eng_image_native_set(void *data, void *image, void *native)
      }
    if (native)
      {
-        VisualID vid;
-        GLXFBConfig *fbc;
-        int i, num;
-        int yinvert = 0;
+        int dummy;
+        unsigned int w, h, depth = 32, border;
+        Window wdummy;
+        Native *n;
         
-        vid = XVisualIDFromVisual(vis);
-        fbc = glXGetFBConfigs(re->win->disp,
-                              0 /* FIXME: screen 0 assumption */,
-                              &num);
-        if (fbc)
+        XGetGeometry(re->win->disp, pm, &wdummy, &dummy, &dummy, 
+                     &w, &h, &border, &depth);
+        n = calloc(1, sizeof(Native));
+        if (n)
           {
-             for (i = 0; i < num; i++)
+#ifndef GLX_TEX_PIXMAP_RECREATE        
+             int pixmap_att[20];
+             int target = 0;
+             int i = 0;
+             
+             if ((re->win->depth_cfg[depth].tex_target &
+                  GLX_TEXTURE_2D_BIT_EXT) &&
+                 (1) // we assume npo2 for now
+                 // size is pow2 || mnpo2 supported
+                 )
                {
-                  XVisualInfo *vi;
-                  int val;
-                  
-                  vi = glXGetVisualFromFBConfig(re->win->disp, fbc[i]);
-                  if ((!vi) || (vi->visualid != vid))
-                    continue;
-                  
-                  glXGetFBConfigAttrib(re->win->disp, fbc[i], 
-                                       GLX_DRAWABLE_TYPE, &val);
-                  if (!(val & GLX_PIXMAP_BIT)) continue;
-                  
-                  glXGetFBConfigAttrib(re->win->disp, fbc[i],
-                                       GLX_BIND_TO_TEXTURE_TARGETS_EXT, &val);
-                  if (!(val & GLX_TEXTURE_2D_BIT_EXT)) continue;
-                  
-                  glXGetFBConfigAttrib(re->win->disp, fbc[i],
-                                       GLX_BIND_TO_TEXTURE_RGBA_EXT, &val);
-                  if (!val)
+                  printf("2d\n");
+                  target = GLX_TEXTURE_2D_EXT;
+               }
+             else if ((re->win->depth_cfg[depth].tex_target &
+                      GLX_TEXTURE_RECTANGLE_BIT_EXT))
+               {
+                  printf("rect\n");
+                  target = GLX_TEXTURE_RECTANGLE_EXT;
+               }
+             if (!target)
+               {
+                  printf("broken text-from-pixmap\n");
+                  if (!(re->win->depth_cfg[depth].tex_target &
+                        GLX_TEXTURE_2D_BIT_EXT))
                     {
-                       glXGetFBConfigAttrib(re->win->disp, fbc[i],
-                                            GLX_BIND_TO_TEXTURE_RGB_EXT, &val);
-                       if (!val) continue;
+                       target = GLX_TEXTURE_RECTANGLE_EXT;
+                    }
+                  else if (!(re->win->depth_cfg[depth].tex_target &
+                             GLX_TEXTURE_RECTANGLE_BIT_EXT))
+                    {
+                       target = GLX_TEXTURE_2D_EXT;
                     }
-                  
-                  glXGetFBConfigAttrib(re->win->disp, fbc[i],
-                                       GLX_Y_INVERTED_EXT, &val);
-                  if (val) yinvert = 1;
-                  break;
                }
-             if (i == num)
+             
+             
+             pixmap_att[i++] = GLX_TEXTURE_FORMAT_EXT;
+             pixmap_att[i++] = re->win->depth_cfg[depth].tex_format;
+             pixmap_att[i++] = GLX_MIPMAP_TEXTURE_EXT;
+             pixmap_att[i++] = re->win->depth_cfg[depth].mipmap;
+             
+             if (target)
                {
-                  printf("  err \n");
-                  // error
+                  pixmap_att[i++] = GLX_TEXTURE_TARGET_EXT;
+                  pixmap_att[i++] = target;
+               }
+             
+             pixmap_att[i++] = 0;
+#endif
+             memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
+             n->pixmap = pm;
+             n->visual = vis;
+             n->fbc = re->win->depth_cfg[depth].fbc;
+             im->native.yinvert     = re->win->depth_cfg[depth].yinvert;
+             im->native.target      = GL_TEXTURE_2D;
+             im->native.loose       = 0;
+             im->native.data        = n;
+             im->native.func.data   = re;
+             im->native.func.bind   = _native_bind_cb;
+             im->native.func.unbind = _native_unbind_cb;
+             im->native.func.free   = _native_free_cb;
+#ifndef GLX_TEX_PIXMAP_RECREATE
+             n->glx_pixmap = glXCreatePixmap(re->win->disp, n->fbc, 
+                                             n->pixmap, pixmap_att);
+             if (!target)
+               {
+                  printf("notgt\n");
+                  glXQueryDrawable(re->win->disp, n->pixmap, GLX_TEXTURE_TARGET_EXT, &target);
+               }
+             if (target == GLX_TEXTURE_2D_EXT)
+               {
+                  im->native.target = GL_TEXTURE_2D;
+                  im->native.mipmap = re->win->depth_cfg[depth].mipmap;
+               }
+             else if (target == GLX_TEXTURE_RECTANGLE_EXT)
+               {
+                  im->native.target = GL_TEXTURE_RECTANGLE_ARB;
+                  im->native.mipmap = 0;
                }
              else
                {
-                  Native *n;
-                  
-                  n = calloc(1, sizeof(Native));
-                  if (n)
-                    {
-#ifndef GLX_TEX_PIXMAP_RECREATE        
-                       const int pixmap_att[] =
-                         {
-                            GLX_TEXTURE_TARGET_EXT, 
-                              GLX_TEXTURE_2D_EXT,
-                              GLX_TEXTURE_FORMAT_EXT, 
-//                              GLX_TEXTURE_FORMAT_RGBA_EXT,
-                              GLX_TEXTURE_FORMAT_RGB_EXT,
-                              0
-                         };
-#endif        
-                       memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
-                       n->pixmap = pm;
-                       n->visual = vis;
-                       memcpy(&(n->fbc), fbc, sizeof(GLXFBConfig));
-                       n->fbc = *fbc;
-                       im->native.yinvert     = yinvert;
-                       im->native.loose       = 0;
-                       im->native.data        = n;
-                       im->native.func.data   = re;
-                       im->native.func.bind   = _native_bind_cb;
-                       im->native.func.unbind = _native_unbind_cb;
-                       im->native.func.free   = _native_free_cb;
-#ifndef GLX_TEX_PIXMAP_RECREATE
-                       n->glx_pixmap = glXCreatePixmap(re->win->disp, n->fbc, 
-                                                       n->pixmap, pixmap_att);
-#endif                       
-                       evas_gl_common_image_native_enable(im);
-                    }
+                  printf("still unknown target\n");
                }
+#endif                       
+             evas_gl_common_image_native_enable(im);
           }
      }
 # endif   
index 74359bd..94b6afc 100644 (file)
@@ -94,6 +94,13 @@ struct _Evas_GL_X11_Window
    EGLDisplay       egl_disp;
 #else   
    GLXContext       context;
+   struct {
+      GLXFBConfig   fbc;
+      int           tex_format;
+      int           tex_target;
+      int           mipmap;
+      unsigned char yinvert : 1;
+   } depth_cfg[33]; // config for all 32 possible depths!
 #endif
 
 };
index e9210c6..96b7f2a 100644 (file)
@@ -140,8 +140,90 @@ eng_window_new(Display *disp,
    if (!context)
      context = glXCreateContext(disp, gw->visualinfo, NULL, GL_TRUE);
    gw->context = context;
-   
-   glXMakeCurrent(gw->disp, gw->win, gw->context);
+
+   if (gw->context)
+     {
+        int i, j,  num;
+        GLXFBConfig *fbc;
+        
+        glXMakeCurrent(gw->disp, gw->win, gw->context);
+        
+        fbc = glXGetFBConfigs(disp, 0/* FIXME: assume screen 0 */, &num);
+        for (i = 0; i <= 32; i++)
+          {
+             for (j = 0; j < num; j++)
+               {
+                  XVisualInfo *vi;
+                  int vd;
+                  int alpha, val, dbuf, stencil, depth;
+                  int rgba;
+                  
+                  vi = glXGetVisualFromFBConfig(disp, fbc[j]);
+                  if (!vi) continue;
+                  vd = vi->depth;
+                  XFree(vi);
+                  
+                  if (vd != i) continue;
+                  
+                  glXGetFBConfigAttrib(disp, fbc[j], GLX_ALPHA_SIZE, &alpha);
+                  glXGetFBConfigAttrib(disp, fbc[j], GLX_BUFFER_SIZE, &val);
+                  
+                  if ((val != i) && ((val - alpha) != i)) continue;
+                  
+                  val = 0;
+                  rgba = 0;
+                  
+                  if (i == 32)
+                    {
+                       glXGetFBConfigAttrib(disp, fbc[j], GLX_BIND_TO_TEXTURE_RGBA_EXT, &val);
+                       if (val)
+                         {
+                            rgba = 1;
+                            gw->depth_cfg[i].tex_format = GLX_TEXTURE_FORMAT_RGBA_EXT;
+                         }
+                    }
+                  if (!val)
+                    {
+                       if (rgba) continue;
+                       glXGetFBConfigAttrib(disp, fbc[j], GLX_BIND_TO_TEXTURE_RGB_EXT, &val);
+                       if (!val) continue;
+                       gw->depth_cfg[i].tex_format = GLX_TEXTURE_FORMAT_RGB_EXT;
+                    }
+                  
+                  dbuf = 0x7fff;
+                  glXGetFBConfigAttrib(disp, fbc[j], GLX_DOUBLEBUFFER, &val);
+                  if (val > dbuf) continue;
+                  dbuf = val;
+                  
+                  stencil = 0x7fff;
+                  glXGetFBConfigAttrib(disp, fbc[j], GLX_STENCIL_SIZE, &val);
+                  if (val > stencil) continue;
+                  stencil = val;
+                  
+                  depth = 0x7fff;
+                  glXGetFBConfigAttrib(disp, fbc[j], GLX_DEPTH_SIZE, &val);
+                  if (val > depth) continue;
+                  depth = val;
+                  
+                  glXGetFBConfigAttrib(disp, fbc[j], GLX_BIND_TO_MIPMAP_TEXTURE_EXT, &val);
+                  if (val < 0) continue;
+                  gw->depth_cfg[i].mipmap = val;
+                  
+                  glXGetFBConfigAttrib(disp, fbc[j], GLX_Y_INVERTED_EXT, &val);
+                  gw->depth_cfg[i].yinvert = val;
+                  
+                  glXGetFBConfigAttrib(disp, fbc[j], GLX_BIND_TO_TEXTURE_TARGETS_EXT, &val);
+                  gw->depth_cfg[i].tex_target = val;
+                  
+                  gw->depth_cfg[i].fbc = fbc[i];
+               }
+          }
+        XFree(fbc);
+        if (!gw->depth_cfg[DefaultDepth(disp, 0/* FIXMEL assume screen 0*/)].fbc)
+          {
+             printf("text from pixmap not going to work\n");
+          }
+     }
 #endif
    _evas_gl_x11_window = gw;
    
index 0d42d33..9cd0ef2 100644 (file)
@@ -139,9 +139,9 @@ _output_xlib_setup(int      w,
                     }
                   else
                     re->xr.dpi = atoi(str) * 1000;
+                  evas_common_font_dpi_set(re->xr.dpi / 1000);
                }
           }
-        evas_common_font_dpi_set(re->xr.dpi / 1000);
      }
    
    re->ob = evas_software_xlib_outbuf_setup_x(w,
index 200f562..7337faf 100644 (file)
@@ -265,9 +265,9 @@ _output_xlib_setup(int           width,
                     }
                   else
                     re->xr.dpi = atoi(str) * 1000;
+                  evas_common_font_dpi_set(re->xr.dpi / 1000);
                }
           }
-        evas_common_font_dpi_set(re->xr.dpi / 1000);
      }
    
    return re;