raster pushed a commit to branch master.

commit 199fb6523edabbebeab01902f726ba637bbf9375
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date:   Thu Jul 11 12:39:44 2013 +0900

    evas gl engine - paranoia: check max texture size limits on texture alloc
---
 .../evas/engines/gl_common/evas_gl_common.h        |   4 +-
 .../evas/engines/gl_common/evas_gl_preload.c       |  16 +-
 .../evas/engines/gl_common/evas_gl_texture.c       | 216 +++++++++++++--------
 3 files changed, 145 insertions(+), 91 deletions(-)

diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h 
b/src/modules/evas/engines/gl_common/evas_gl_common.h
index f0f3bd1..1f4f1fa 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -795,8 +795,10 @@ Eina_Bool evas_gl_common_module_open(void);
 void      evas_gl_common_module_close(void);
 
 static inline void
-_tex_sub_2d(int x, int y, int w, int h, int fmt, int type, const void *pix)
+_tex_sub_2d(Evas_Engine_GL_Context *gc, int x, int y, int w, int h, int fmt, 
int type, const void *pix)
 {
+   if ((w > gc->shared->info.max_texture_size) ||
+       (h > gc->shared->info.max_texture_size)) return;
    glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, fmt, type, pix);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
 }
diff --git a/src/modules/evas/engines/gl_common/evas_gl_preload.c 
b/src/modules/evas/engines/gl_common/evas_gl_preload.c
index 6744130..bdaa8de 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_preload.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_preload.c
@@ -199,28 +199,28 @@ _evas_gl_preload_tile_async(void *data EINA_UNUSED, 
Eina_Thread t EINA_UNUSED)
         //  +-+
         //  +-+
         //
-        _tex_sub_2d(async->tex->x, async->tex->y,
+        _tex_sub_2d(async->tex->gc, async->tex->x, async->tex->y,
                     async->im->cache_entry.w, async->im->cache_entry.h,
                     fmt, async->tex->pt->dataformat,
                     async->im->image.data);
         //  xxx
         //  xxx
         //  ---
-        _tex_sub_2d(async->tex->x, async->tex->y + async->im->cache_entry.h,
+        _tex_sub_2d(async->tex->gc, async->tex->x, async->tex->y + 
async->im->cache_entry.h,
                     async->im->cache_entry.w, 1,
                     fmt, async->tex->pt->dataformat,
                     async->im->image.data + ((async->im->cache_entry.h - 1) * 
async->im->cache_entry.w));
         //  xxx
         //  xxx
         // o
-        _tex_sub_2d(async->tex->x - 1, async->tex->y + 
async->im->cache_entry.h,
+        _tex_sub_2d(async->tex->gc, async->tex->x - 1, async->tex->y + 
async->im->cache_entry.h,
                     1, 1,
                     fmt, async->tex->pt->dataformat,
                     async->im->image.data + ((async->im->cache_entry.h - 1) * 
async->im->cache_entry.w));
         //  xxx
         //  xxx
         //     o
-        _tex_sub_2d(async->tex->x + async->im->cache_entry.w, async->tex->y + 
async->im->cache_entry.h,
+        _tex_sub_2d(async->tex->gc, async->tex->x + async->im->cache_entry.w, 
async->tex->y + async->im->cache_entry.h,
                     1, 1,
                     fmt, async->tex->pt->dataformat,
                     async->im->image.data + ((async->im->cache_entry.h - 1) * 
async->im->cache_entry.w) + (async->im->cache_entry.w - 1));
@@ -231,14 +231,14 @@ _evas_gl_preload_tile_async(void *data EINA_UNUSED, 
Eina_Thread t EINA_UNUSED)
              // |xxx
              // |xxx
              //
-             _tex_sub_2d(async->tex->x - 1, async->tex->y,
+             _tex_sub_2d(async->tex->gc, async->tex->x - 1, async->tex->y,
                          1, async->im->cache_entry.h,
                          fmt, async->tex->pt->dataformat,
                          async->im->image.data);
              //  xxx|
              //  xxx|
              //
-             _tex_sub_2d(async->tex->x + async->im->cache_entry.w, 
async->tex->y,
+             _tex_sub_2d(async->tex->gc, async->tex->x + 
async->im->cache_entry.w, async->tex->y,
                          1, async->im->cache_entry.h,
                          fmt, async->tex->pt->dataformat,
                          async->im->image.data + (async->im->cache_entry.w - 
1));
@@ -260,7 +260,7 @@ _evas_gl_preload_tile_async(void *data EINA_UNUSED, 
Eina_Thread t EINA_UNUSED)
              // |xxx
              // |xxx
              //
-             _tex_sub_2d(async->tex->x - 1, async->tex->y,
+             _tex_sub_2d(async->tex->gc, async->tex->x - 1, async->tex->y,
                          1, async->im->cache_entry.h,
                          fmt, async->tex->pt->dataformat,
                          tpix);
@@ -275,7 +275,7 @@ _evas_gl_preload_tile_async(void *data EINA_UNUSED, 
Eina_Thread t EINA_UNUSED)
              //  xxx|
              //  xxx|
              //
-             _tex_sub_2d(async->tex->x + async->im->cache_entry.w, 
async->tex->y,
+             _tex_sub_2d(async->tex->gc, async->tex->x + 
async->im->cache_entry.w, async->tex->y,
                          1, async->im->cache_entry.h,
                          fmt, async->tex->pt->dataformat,
                          tpix);
diff --git a/src/modules/evas/engines/gl_common/evas_gl_texture.c 
b/src/modules/evas/engines/gl_common/evas_gl_texture.c
index 76bde12..d63645d 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_texture.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_texture.c
@@ -115,7 +115,7 @@ _tex_round_slot(Evas_Engine_GL_Context *gc, int h)
    if (!gc->shared->info.tex_npo2)
      h = _nearest_pow2(h);
    return (h + gc->shared->info.tune.atlas.slot_size - 1) /
-      gc->shared->info.tune.atlas.slot_size;
+     gc->shared->info.tune.atlas.slot_size;
 }
 
 static int
@@ -140,9 +140,15 @@ _tex_format_index(GLuint format)
    return 0;
 }
 
-static void
-_tex_2d(int intfmt, int w, int h, int fmt, int type)
+static Eina_Bool
+_tex_2d(Evas_Engine_GL_Context *gc, int intfmt, int w, int h, int fmt, int 
type)
 {
+   if ((w > gc->shared->info.max_texture_size) ||
+       (h > gc->shared->info.max_texture_size))
+     {
+        ERR("Fail tex too big %ix%i", w, h);
+        return EINA_FALSE;
+     }
    glTexImage2D(GL_TEXTURE_2D, 0, intfmt, w, h, 0, fmt, type, NULL);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
 #ifdef GL_TEXTURE_INTERNAL_FORMAT
@@ -159,6 +165,7 @@ _tex_2d(int intfmt, int w, int h, int fmt, int type)
           {
              ERR("Fail tex alloc %ix%i", w, h);
              //        XXX send async err to evas
+             return EINA_FALSE;
           }
      }
 //   else
@@ -166,7 +173,8 @@ _tex_2d(int intfmt, int w, int h, int fmt, int type)
 //        ERR("GL_TEXTURE_INTERNAL_FORMAT defined but no symbol loaded.");
 //     }
 # endif   
-#endif   
+#endif
+   return EINA_TRUE;
 }
 
 static Evas_GL_Texture *
@@ -198,7 +206,14 @@ static Evas_GL_Texture_Pool *
 _pool_tex_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, GLenum 
format)
 {
    Evas_GL_Texture_Pool *pt;
+   Eina_Bool ok;
 
+   if ((w > gc->shared->info.max_texture_size) ||
+       (h > gc->shared->info.max_texture_size))
+     {
+        ERR("Fail tex too big %ix%i", w, h);
+        return NULL;
+     }
    pt = calloc(1, sizeof(Evas_GL_Texture_Pool));
    if (!pt) return NULL;
    h = _tex_round_slot(gc, h) * gc->shared->info.tune.atlas.slot_size;
@@ -211,24 +226,6 @@ _pool_tex_new(Evas_Engine_GL_Context *gc, int w, int h, 
int intformat, GLenum fo
    pt->dataformat = GL_UNSIGNED_BYTE;
    pt->references = 0;
 
-   if (format == alpha_fmt)
-      {
-         texinfo.a.num++;
-         texinfo.a.pix += pt->w * pt->h;
-      }
-   else if (format == lum_fmt)
-      {
-         texinfo.v.num++;
-         texinfo.v.pix += pt->w * pt->h;
-      }
-   else
-      {
-         texinfo.c.num++;
-         texinfo.c.pix += pt->w * pt->h;
-      }
-
-   _print_tex_count();
-
    glGenTextures(1, &(pt->texture));
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
    glBindTexture(GL_TEXTURE_2D, pt->texture);
@@ -241,9 +238,32 @@ _pool_tex_new(Evas_Engine_GL_Context *gc, int w, int h, 
int intformat, GLenum fo
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-   _tex_2d(pt->intformat, w, h, pt->format, pt->dataformat);
+   ok = _tex_2d(gc, pt->intformat, w, h, pt->format, pt->dataformat);
    glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
+   if (!ok)
+     {
+        glDeleteTextures(1, &(pt->texture));
+        free(pt);
+        return NULL;
+     }
+
+   if (format == alpha_fmt)
+     {
+        texinfo.a.num++;
+        texinfo.a.pix += pt->w * pt->h;
+     }
+   else if (format == lum_fmt)
+     {
+        texinfo.v.num++;
+        texinfo.v.pix += pt->w * pt->h;
+     }
+   else
+     {
+        texinfo.c.num++;
+        texinfo.c.pix += pt->w * pt->h;
+     }
+   _print_tex_count();
    return pt;
 }
 
@@ -380,7 +400,14 @@ _pool_tex_render_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, in
 {
    Evas_GL_Texture_Pool *pt;
    int fnum;
+   Eina_Bool ok;
 
+   if ((w > gc->shared->info.max_texture_size) ||
+       (h > gc->shared->info.max_texture_size))
+     {
+        ERR("Fail tex too big %ix%i", w, h);
+        return NULL;
+     }
    pt = calloc(1, sizeof(Evas_GL_Texture_Pool));
    if (!pt) return NULL;
    _tex_adjust(gc, &w, &h);
@@ -407,11 +434,6 @@ _pool_tex_render_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, in
 #  define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT
 # endif
 #endif
-   texinfo.r.num++;
-   texinfo.r.pix += pt->w * pt->h;
-
-   _print_tex_count();
-
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fnum);
    glGenTextures(1, &(pt->texture));
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
@@ -425,7 +447,7 @@ _pool_tex_render_new(Evas_Engine_GL_Context *gc, int w, int 
h, int intformat, in
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-   _tex_2d(pt->intformat, w, h, pt->format, pt->dataformat);
+   ok = _tex_2d(gc, pt->intformat, w, h, pt->format, pt->dataformat);
 
    glsym_glGenFramebuffers(1, &(pt->fb));
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
@@ -438,6 +460,17 @@ _pool_tex_render_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, in
 
    glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
+   
+   if (!ok)
+     {
+        glDeleteTextures(1, &(pt->texture));
+        free(pt);
+        return NULL;
+     }
+   
+   texinfo.r.num++;
+   texinfo.r.pix += pt->w * pt->h;
+   _print_tex_count();
    return pt;
 }
 
@@ -446,6 +479,12 @@ _pool_tex_native_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, in
 {
    Evas_GL_Texture_Pool *pt;
 
+   if ((w > gc->shared->info.max_texture_size) ||
+       (h > gc->shared->info.max_texture_size))
+     {
+        ERR("Fail tex too big %ix%i", w, h);
+        return NULL;
+     }
    pt = calloc(1, sizeof(Evas_GL_Texture_Pool));
    if (!pt) return NULL;
    pt->gc = gc;
@@ -468,11 +507,6 @@ _pool_tex_native_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, in
    pt->dataformat = GL_UNSIGNED_BYTE;
    pt->references = 0;
    pt->native = 1;
-   texinfo.n.num++;
-   texinfo.n.pix += pt->w * pt->h;
-
-   _print_tex_count();
-
    glGenTextures(1, &(pt->texture));
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
    glBindTexture(im->native.target, pt->texture);
@@ -499,6 +533,10 @@ _pool_tex_native_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, in
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
    glBindTexture(im->native.target, gc->pipe[0].shader.cur_tex);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
+   
+   texinfo.n.num++;
+   texinfo.n.pix += pt->w * pt->h;
+   _print_tex_count();
    return pt;
 }
 
@@ -882,7 +920,7 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, 
RGBA_Image *im)
         glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
 
-        _tex_sub_2d(u, tex->ty, EVAS_GL_TILE_SIZE, EVAS_GL_TILE_SIZE, fmt, 
tex->ptt->dataformat, out);
+        _tex_sub_2d(tex->gc, u, tex->ty, EVAS_GL_TILE_SIZE, EVAS_GL_TILE_SIZE, 
fmt, tex->ptt->dataformat, out);
 
         // Switch back to current texture
         if (tex->ptt->texture != tex->gc->pipe[0].shader.cur_tex)
@@ -932,28 +970,28 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, 
RGBA_Image *im)
    //  +-+
    //  +-+
    //
-   _tex_sub_2d(tex->x, tex->y,
+   _tex_sub_2d(tex->gc, tex->x, tex->y,
                im->cache_entry.w, im->cache_entry.h,
                fmt, tex->pt->dataformat,
                im->image.data);
    //  xxx
    //  xxx
    //  ---
-   _tex_sub_2d(tex->x, tex->y + im->cache_entry.h,
+   _tex_sub_2d(tex->gc, tex->x, tex->y + im->cache_entry.h,
                im->cache_entry.w, 1,
                fmt, tex->pt->dataformat,
                im->image.data + ((im->cache_entry.h - 1) * im->cache_entry.w));
    //  xxx
    //  xxx
    // o
-   _tex_sub_2d(tex->x - 1, tex->y + im->cache_entry.h,
+   _tex_sub_2d(tex->gc, tex->x - 1, tex->y + im->cache_entry.h,
                1, 1,
                fmt, tex->pt->dataformat,
                im->image.data + ((im->cache_entry.h - 1) * im->cache_entry.w));
    //  xxx
    //  xxx
    //     o
-   _tex_sub_2d(tex->x + im->cache_entry.w, tex->y + im->cache_entry.h,
+   _tex_sub_2d(tex->gc, tex->x + im->cache_entry.w, tex->y + im->cache_entry.h,
                1, 1,
                fmt, tex->pt->dataformat,
                im->image.data + ((im->cache_entry.h - 1) * im->cache_entry.w) 
+ (im->cache_entry.w - 1));
@@ -964,14 +1002,14 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, 
RGBA_Image *im)
         // |xxx
         // |xxx
         //
-        _tex_sub_2d(tex->x - 1, tex->y,
+        _tex_sub_2d(tex->gc, tex->x - 1, tex->y,
                     1, im->cache_entry.h,
                     fmt, tex->pt->dataformat,
                     im->image.data);
         //  xxx|
         //  xxx|
         //
-        _tex_sub_2d(tex->x + im->cache_entry.w, tex->y,
+        _tex_sub_2d(tex->gc, tex->x + im->cache_entry.w, tex->y,
                     1, im->cache_entry.h,
                     fmt, tex->pt->dataformat,
                     im->image.data + (im->cache_entry.w - 1));
@@ -993,7 +1031,7 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, 
RGBA_Image *im)
         // |xxx
         // |xxx
         //
-        _tex_sub_2d(tex->x - 1, tex->y,
+        _tex_sub_2d(tex->gc, tex->x - 1, tex->y,
                     1, im->cache_entry.h,
                     fmt, tex->pt->dataformat,
                     tpix);
@@ -1008,7 +1046,7 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, 
RGBA_Image *im)
         //  xxx|
         //  xxx|
         //
-        _tex_sub_2d(tex->x + im->cache_entry.w, tex->y,
+        _tex_sub_2d(tex->gc, tex->x + im->cache_entry.w, tex->y,
                     1, im->cache_entry.h,
                     fmt, tex->pt->dataformat,
                     tpix);
@@ -1104,8 +1142,8 @@ evas_gl_common_texture_alpha_update(Evas_GL_Texture *tex, 
DATA8 *pixels,
      }
    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-   _tex_sub_2d(tex->x, tex->y, w, h, tex->pt->format, tex->pt->dataformat,
-               pixels);
+   _tex_sub_2d(tex->gc, tex->x, tex->y, w, h, tex->pt->format,
+               tex->pt->dataformat, pixels);
    if (tex->pt->texture != tex->gc->pipe[0].shader.cur_tex)
      {
         glBindTexture(GL_TEXTURE_2D, tex->gc->pipe[0].shader.cur_tex);
@@ -1173,20 +1211,23 @@ evas_gl_common_texture_yuv_update(Evas_GL_Texture *tex, 
DATA8 **rows, unsigned i
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
         glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat);
-        _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, rows[0]);
+        if (!_tex_2d(tex->gc, tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat))
+          return;
+        _tex_sub_2d(tex->gc, 0, 0, w, h, tex->pt->format, tex->pt->dataformat, 
rows[0]);
         glBindTexture(GL_TEXTURE_2D, tex->ptu->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
         glPixelStorei(GL_UNPACK_ROW_LENGTH, rows[h + 1] - rows[h]);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->ptu->intformat, w / 2, h / 2, tex->ptu->format, 
tex->ptu->dataformat);
-        _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptu->format, 
tex->ptu->dataformat, rows[h]);
+        if (!_tex_2d(tex->gc, tex->ptu->intformat, w / 2, h / 2, 
tex->ptu->format, tex->ptu->dataformat))
+          return;
+        _tex_sub_2d(tex->gc, 0, 0, w / 2, h / 2, tex->ptu->format, 
tex->ptu->dataformat, rows[h]);
         glBindTexture(GL_TEXTURE_2D, tex->ptv->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
         glPixelStorei(GL_UNPACK_ROW_LENGTH, rows[h + (h / 2) + 1] - rows[h + 
(h / 2)]);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->ptv->intformat, w / 2, h / 2, tex->ptv->format, 
tex->ptv->dataformat);
-        _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptv->format, 
tex->ptv->dataformat, rows[h + (h / 2)]);
+        if (!_tex_2d(tex->gc, tex->ptv->intformat, w / 2, h / 2, 
tex->ptv->format, tex->ptv->dataformat))
+          return;
+        _tex_sub_2d(tex->gc, 0, 0, w / 2, h / 2, tex->ptv->format, 
tex->ptv->dataformat, rows[h + (h / 2)]);
      }
    else
      {
@@ -1196,35 +1237,38 @@ evas_gl_common_texture_yuv_update(Evas_GL_Texture *tex, 
DATA8 **rows, unsigned i
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
         glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat);
+        if (!_tex_2d(tex->gc, tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat))
+          return;
         if ((rows[1] - rows[0]) == (int)w)
-          _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, 
rows[0]);
+          _tex_sub_2d(tex->gc, 0, 0, w, h, tex->pt->format, 
tex->pt->dataformat, rows[0]);
         else
           {
              for (y = 0; y < h; y++)
-               _tex_sub_2d(0, y, w, 1, tex->pt->format, tex->pt->dataformat, 
rows[y]);
+               _tex_sub_2d(tex->gc, 0, y, w, 1, tex->pt->format, 
tex->pt->dataformat, rows[y]);
           }
         
         glBindTexture(GL_TEXTURE_2D, tex->ptu->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->ptu->intformat, w / 2, h / 2, tex->ptu->format, 
tex->ptu->dataformat);
+        if (!_tex_2d(tex->gc, tex->ptu->intformat, w / 2, h / 2, 
tex->ptu->format, tex->ptu->dataformat))
+          return;
         if ((rows[h + 1] - rows[h]) == (int)(w / 2))
-          _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptu->format, 
tex->ptu->dataformat, rows[h]);
+          _tex_sub_2d(tex->gc, 0, 0, w / 2, h / 2, tex->ptu->format, 
tex->ptu->dataformat, rows[h]);
         else
           {
              for (y = 0; y < (h / 2); y++)
-               _tex_sub_2d(0, y, w / 2, 1, tex->ptu->format, 
tex->ptu->dataformat, rows[h + y]);
+               _tex_sub_2d(tex->gc, 0, y, w / 2, 1, tex->ptu->format, 
tex->ptu->dataformat, rows[h + y]);
           }
         
         glBindTexture(GL_TEXTURE_2D, tex->ptv->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->ptv->intformat, w / 2, h / 2, tex->ptv->format, 
tex->ptv->dataformat);
+        if (!_tex_2d(tex->gc, tex->ptv->intformat, w / 2, h / 2, 
tex->ptv->format, tex->ptv->dataformat))
+          return;
         if ((rows[h + (h / 2) + 1] - rows[h + (h / 2)]) == (int)(w / 2))
-          _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptv->format, 
tex->ptv->dataformat, rows[h + (h / 2)]);
+          _tex_sub_2d(tex->gc, 0, 0, w / 2, h / 2, tex->ptv->format, 
tex->ptv->dataformat, rows[h + (h / 2)]);
         else
           {
              for (y = 0; y < (h / 2); y++)
-               _tex_sub_2d(0, y, w / 2, 1, tex->ptv->format, 
tex->ptv->dataformat, rows[h + (h / 2) + y]);
+               _tex_sub_2d(tex->gc, 0, y, w / 2, 1, tex->ptv->format, 
tex->ptv->dataformat, rows[h + (h / 2) + y]);
           }
      }
    if (tex->pt->texture != tex->gc->pipe[0].shader.cur_tex)
@@ -1374,30 +1418,32 @@ evas_gl_common_texture_yuy2_update(Evas_GL_Texture 
*tex, DATA8 **rows, unsigned
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
    glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-   _tex_2d(tex->pt->intformat, w, h, tex->pt->format, tex->pt->dataformat);
+   if (!_tex_2d(tex->gc, tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat))
+     return;
    if ((rows[1] - rows[0]) == (int)w * 4)
-     _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, rows[0]);
+     _tex_sub_2d(tex->gc, 0, 0, w, h, tex->pt->format, tex->pt->dataformat, 
rows[0]);
    else
      {
         for (y = 0; y < h; y++)
-          _tex_sub_2d(0, y, w, 1, tex->pt->format, tex->pt->dataformat, 
rows[y]);
+          _tex_sub_2d(tex->gc, 0, y, w, 1, tex->pt->format, 
tex->pt->dataformat, rows[y]);
      }
 
    glBindTexture(GL_TEXTURE_2D, tex->ptuv->texture);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-   _tex_2d(tex->ptuv->intformat, w / 2, h, tex->ptuv->format, 
tex->ptuv->dataformat);
+   if (!_tex_2d(tex->gc, tex->ptuv->intformat, w / 2, h, tex->ptuv->format, 
tex->ptuv->dataformat))
+     return;
 #if 0
    /*
      FIXME: this piece of code doesn't work anymore since texture width
      is not anymore exactly w / 2. I don't understand why.
    */
    if ((rows[1] - rows[0]) == (int)(w * 2))
-     _tex_sub_2d(0, 0, w / 2, h, tex->ptuv->format, tex->ptuv->dataformat, 
rows[0]);
+     _tex_sub_2d(tex->gc, 0, 0, w / 2, h, tex->ptuv->format, 
tex->ptuv->dataformat, rows[0]);
    else
 #endif
      {
         for (y = 0; y < h; y++)
-          _tex_sub_2d(0, y, w / 2, 1, tex->ptuv->format, 
tex->ptuv->dataformat, rows[y]);
+          _tex_sub_2d(tex->gc, 0, y, w / 2, 1, tex->ptuv->format, 
tex->ptuv->dataformat, rows[y]);
      }
 
    if (tex->pt->texture != tex->gc->pipe[0].shader.cur_tex)
@@ -1425,14 +1471,16 @@ evas_gl_common_texture_nv12_update(Evas_GL_Texture 
*tex, DATA8 **rows, unsigned
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
         glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat);
-        _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, rows[0]);
+        if (!_tex_2d(tex->gc, tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat))
+          return;
+        _tex_sub_2d(tex->gc, 0, 0, w, h, tex->pt->format, tex->pt->dataformat, 
rows[0]);
         glBindTexture(GL_TEXTURE_2D, tex->ptuv->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
         glPixelStorei(GL_UNPACK_ROW_LENGTH, rows[h + 1] - rows[h]);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->ptuv->intformat, w / 2, h / 2, tex->ptuv->format, 
tex->ptuv->dataformat);
-        _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptuv->format, 
tex->ptuv->dataformat, rows[h]);
+        if (!_tex_2d(tex->gc, tex->ptuv->intformat, w / 2, h / 2, 
tex->ptuv->format, tex->ptuv->dataformat))
+          return;
+        _tex_sub_2d(tex->gc, 0, 0, w / 2, h / 2, tex->ptuv->format, 
tex->ptuv->dataformat, rows[h]);
      }
    else
      {
@@ -1442,24 +1490,26 @@ evas_gl_common_texture_nv12_update(Evas_GL_Texture 
*tex, DATA8 **rows, unsigned
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
         glBindTexture(GL_TEXTURE_2D, tex->pt->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat);
+        if (!_tex_2d(tex->gc, tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat))
+          return;
         if ((rows[1] - rows[0]) == (int)w)
-          _tex_sub_2d(0, 0, w, h, tex->pt->format, tex->pt->dataformat, 
rows[0]);
+          _tex_sub_2d(tex->gc, 0, 0, w, h, tex->pt->format, 
tex->pt->dataformat, rows[0]);
         else
           {
              for (y = 0; y < h; y++)
-               _tex_sub_2d(0, y, w, 1, tex->pt->format, tex->pt->dataformat, 
rows[y]);
+               _tex_sub_2d(tex->gc, 0, y, w, 1, tex->pt->format, 
tex->pt->dataformat, rows[y]);
           }
         
         glBindTexture(GL_TEXTURE_2D, tex->ptuv->texture);
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
-        _tex_2d(tex->ptuv->intformat, w / 2, h / 2, tex->ptuv->format, 
tex->ptuv->dataformat);
+        if (!_tex_2d(tex->gc, tex->ptuv->intformat, w / 2, h / 2, 
tex->ptuv->format, tex->ptuv->dataformat))
+          return;
         if ((rows[h + 1] - rows[h]) == (int)(w / 2))
-          _tex_sub_2d(0, 0, w / 2, h / 2, tex->ptuv->format, 
tex->ptuv->dataformat, rows[h]);
+          _tex_sub_2d(tex->gc, 0, 0, w / 2, h / 2, tex->ptuv->format, 
tex->ptuv->dataformat, rows[h]);
         else
           {
              for (y = 0; y < (h / 2); y++)
-               _tex_sub_2d(0, y, w / 2, 1, tex->ptuv->format, 
tex->ptuv->dataformat, rows[h + y]);
+               _tex_sub_2d(tex->gc, 0, y, w / 2, 1, tex->ptuv->format, 
tex->ptuv->dataformat, rows[h + y]);
           }
      }
    if (tex->pt->texture != tex->gc->pipe[0].shader.cur_tex)
@@ -1630,7 +1680,8 @@ evas_gl_common_texture_nv12tiled_update(Evas_GL_Texture 
*tex, DATA8 **rows, unsi
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
 
    // We are telling the driver to not swizzle back the buffer as we are going 
to replace all pixel
-   _tex_2d(tex->pt->intformat, w, h, tex->pt->format, tex->pt->dataformat);
+   if (!_tex_2d(tex->gc, tex->pt->intformat, w, h, tex->pt->format, 
tex->pt->dataformat))
+     return;
 
    /* Iterate each Y macroblock like we do in evas_convert_yuv.c */
    for (mb_y = 0; mb_y < (mb_h >> 1); mb_y++)
@@ -1646,7 +1697,7 @@ evas_gl_common_texture_nv12tiled_update(Evas_GL_Texture 
*tex, DATA8 **rows, unsi
 
        for (mb_x = 0; mb_x < mb_w * 2; mb_x++, rmb_x += 64 * 32)
          {
-            _tex_sub_2d(x, ry[offset], 64, 32, tex->pt->format, 
tex->pt->dataformat, rows[mb_y] + rmb_x);
+            _tex_sub_2d(tex->gc, x, ry[offset], 64, 32, tex->pt->format, 
tex->pt->dataformat, rows[mb_y] + rmb_x);
 
             step++;
             if ((step & 0x3) == 0)
@@ -1670,13 +1721,14 @@ evas_gl_common_texture_nv12tiled_update(Evas_GL_Texture 
*tex, DATA8 **rows, unsi
        ry = mb_y * 2 * 32;
 
        for (mb_x = 0; mb_x < mb_w; mb_x++, x += 64, rmb_x += 64 * 32)
-         _tex_sub_2d(x, ry, 64, 32, tex->pt->format, tex->pt->dataformat, 
rows[mb_y] + rmb_x);
+         _tex_sub_2d(tex->gc, x, ry, 64, 32, tex->pt->format, 
tex->pt->dataformat, rows[mb_y] + rmb_x);
      }
 
    glBindTexture(GL_TEXTURE_2D, tex->ptuv->texture);
    GLERR(__FUNCTION__, __FILE__, __LINE__, "");
 
-   _tex_2d(tex->ptuv->intformat, w, h, tex->ptuv->format, 
tex->ptuv->dataformat);
+   if (!_tex_2d(tex->gc, tex->ptuv->intformat, w, h, tex->ptuv->format, 
tex->ptuv->dataformat))
+     return;
 
    /* Iterate each UV macroblock like we do in evas_convert_yuv.c */
    base_h = (mb_h >> 1) + (mb_h & 0x1);
@@ -1701,7 +1753,7 @@ evas_gl_common_texture_nv12tiled_update(Evas_GL_Texture 
*tex, DATA8 **rows, unsi
 
        for (mb_x = 0; mb_x < mb_w * 2; mb_x++, rmb_x += 64 * 32)
          {
-             _tex_sub_2d(x, ry[offset], 32, 32,
+             _tex_sub_2d(tex->gc, x, ry[offset], 32, 32,
                          tex->ptuv->format, tex->ptuv->dataformat,
                          rows[mb_y + base_h] + rmb_x);
              step++;
@@ -1726,6 +1778,6 @@ evas_gl_common_texture_nv12tiled_update(Evas_GL_Texture 
*tex, DATA8 **rows, unsi
        ry = mb_y * 2 * 32;
 
        for (mb_x = 0; mb_x < mb_w; mb_x++, x += 32, rmb_x += 64 * 32)
-         _tex_sub_2d(x, ry, 64, 32, tex->ptuv->format, tex->ptuv->dataformat, 
rows[mb_y + base_h] + rmb_x);
+         _tex_sub_2d(tex->gc, x, ry, 64, 32, tex->ptuv->format, 
tex->ptuv->dataformat, rows[mb_y + base_h] + rmb_x);
      }
 }

-- 

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk

Reply via email to