gl: remove orient mismatch between texture and image 72/253572/2
authorShinwoo Kim <cinoo.kim@samsung.com>
Mon, 25 Jan 2021 11:53:03 +0000 (20:53 +0900)
committerShinwoo Kim <cinoo.kim@samsung.com>
Tue, 16 Feb 2021 03:18:26 +0000 (03:18 +0000)
With following step, we got abnormal image,
because there is a mismatch between texture and image.

evas_object_image_orient_set(90)
evas_object_image_data_get

evas_object_image_orient_set(180)
evas_object_image_data_get

evas_object_image_orient_set(270)
evas_object_image_data_get

evas_object_image_orient_set(0)
evas_object_image_data_get

The evas_object_image_data_get create rotated image and texture.
The rotated image and texture is used in evas_gl_common_context_image_push.
evas_gl_common_context_image_push has been used 0 orient texture so far.

But following commit made evas_gl_common_context_image_push use
rotated texture

  0abf1ee [evas_gl] change oreint_set() / data_set() / data_get() ...

And for more information,
The following commit increase ref count of rotated texture
So by somehow... rotated texture was used with 0 orient image.

  1b91101 evas: fix usage of the same ressource ...

*tizen_fix

Change-Id: I8429cedd835cdf1dc94931e1c9c4b308d775ac71

src/modules/evas/engines/gl_common/evas_gl_context.c
src/modules/evas/engines/gl_generic/evas_engine.c

index 4b31c69..218e0d1 100644 (file)
@@ -2433,6 +2433,15 @@ evas_gl_common_context_image_push(Evas_Engine_GL_Context *gc,
    pw = pt->w;
    ph = pt->h;
 
+   // TIZEN_ONLY(20210125): use rotated texture
+   Evas_Image_Orient orient_tmp;
+   if (tex->im && tex->im->rotated_orient != EVAS_IMAGE_ORIENT_NONE)
+     {
+        orient_tmp = tex->im->orient;
+        tex->im->orient = EVAS_IMAGE_ORIENT_NONE;
+     }
+   //
+
    if (tex->im &&
        (tex->im->orient == EVAS_IMAGE_ORIENT_90))
      {
@@ -2693,6 +2702,13 @@ evas_gl_common_context_image_push(Evas_Engine_GL_Context *gc,
 
    if (!nomul)
      PUSH_6_COLORS(pn, r, g, b, a);
+
+   // TIZEN_ONLY(20210125): use rotated texture
+   if (tex->im && tex->im->rotated_orient != EVAS_IMAGE_ORIENT_NONE)
+     {
+        tex->im->orient = orient_tmp;
+     }
+   //
 }
 
 void
index 09b6ce6..9ca7d0e 100755 (executable)
@@ -802,6 +802,25 @@ _rotate_image_data(Render_Engine_GL_Generic *re, Evas_GL_Image *im1)
         //
      }
 
+   // TIZEN_ONLY(20210125): use rotated texture
+   if (im1->rotated_orient != EVAS_IMAGE_ORIENT_NONE)
+     {
+        alpha = eng_image_alpha_get(re, im1);
+        gl_context = gl_generic_context_find(re, 1);
+        im2 = evas_gl_common_image_new_from_copied_data(gl_context, im1->w, im1->h, im1->im->image.data, alpha, im1->cs.space);
+        if (!im2 || !im2->im) goto on_error;
+        im2->rotated_orient = im1->orient;
+
+        pixels_in = im1->im->image.data;
+        pixels_out = im2->im->image.data;
+
+        if (!pixels_out || !pixels_in) goto on_error;
+
+        memcpy(pixels_out, pixels_in, sizeof (unsigned int) * im1->w * im1->h);
+        return im2;
+     }
+   //
+
    w = im1->w;
    h = im1->h;
 
@@ -1124,6 +1143,15 @@ eng_image_data_get(void *engine, void *image, int to_write, DATA32 **image_data,
 
 rotate_image:
    // rotate data for image save
+
+   // TIZEN_ONLY(20210125): use rotated texture
+   if (!tofree && im->rotated_orient != EVAS_IMAGE_ORIENT_NONE)
+     {
+        /* already rotated, do not have to rotate */
+        return im;
+     }
+   //
+
    im_new = _rotate_image_data(engine, image);
    if (!im_new)
      {
@@ -1133,6 +1161,12 @@ rotate_image:
      }
    *tofree = EINA_TRUE;
    *image_data = im_new->im->image.data;
+
+   // TIZEN_ONLY(20210125): use rotated texture
+   im_new->orient = im->orient;
+   /* do not have to create texture here */
+   //
+
    return im_new;
 }
 
@@ -1328,7 +1362,13 @@ eng_image_orient_set(void *engine, void *image, Evas_Image_Orient orient)
    //TIZEN_ONLY
 
    im_new->orient = orient;
-   if (im->tex)
+
+   // TIZEN_ONLY(20210125): use rotated texture
+   /* do not keep rotated texture by increasing ref count
+      if the texture is rotated, then remove it. If it is not removed,
+      it does not match between texture orient and image orient */
+   if (im->tex && im->rotated_orient == EVAS_IMAGE_ORIENT_NONE)
+   //
      {
         im_new->tex = im->tex;
         im_new->tex->references++;