jpeg pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=c09b921e34545ad93bd9091e35a816e687276310

commit c09b921e34545ad93bd9091e35a816e687276310
Author: Jean-Philippe Andre <jp.an...@samsung.com>
Date:   Thu Feb 16 20:40:22 2017 +0900

    win: Avoid malloc in icon_object_set
    
    Also support both Evas.Image and EO Efl.Canvas.Image classes.
    Add a test case in elm_test (under "Icon").
    
    I'm not so happy about this patch... it shows that the API
    barrier between legacy and EO implemented for images may not
    be such a great idea after all :(
---
 src/bin/elementary/test_icon.c  |  6 ++++
 src/lib/elementary/efl_ui_win.c | 73 +++++++++++++++++++++++++++--------------
 2 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/src/bin/elementary/test_icon.c b/src/bin/elementary/test_icon.c
index 5c901a6..0b79b4c 100644
--- a/src/bin/elementary/test_icon.c
+++ b/src/bin/elementary/test_icon.c
@@ -107,6 +107,12 @@ test_icon(void *data EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event_info
    elm_box_pack_end(hbox, bt);
    evas_object_show(bt);
 
+   /* Set window icon too */
+   ic = evas_object_image_filled_add(evas_object_evas_get(win));
+   evas_object_image_file_set(ic, buf, NULL);
+   elm_win_icon_object_set(win, ic);
+   evas_object_show(ic);
+
    evas_object_resize(win, 400, 400);
    evas_object_show(win);
 }
diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c
index f558430..06d3bd5 100644
--- a/src/lib/elementary/efl_ui_win.c
+++ b/src/lib/elementary/efl_ui_win.c
@@ -3185,46 +3185,71 @@ _elm_win_xwin_update(Efl_Ui_Win_Data *sd)
    // set window icon
    if (sd->icon)
      {
-        void *data;
+        Eo *image = NULL;
 
         if (efl_isa(sd->icon, EFL_CANVAS_IMAGE_INTERNAL_CLASS))
+          image = sd->icon;
+
+        if (image)
           {
-             data = evas_object_image_data_get(sd->icon, EINA_FALSE);
-             if (data)
+             int w = 0, h = 0, stride, x, y;
+             Eina_Bool unmap = EINA_FALSE;
+             Eina_Rw_Slice sl = {};
+
+             if (efl_isa(image, EFL_CANVAS_IMAGE_CLASS))
+               {
+                  unmap = EINA_TRUE;
+                  efl_gfx_buffer_size_get(image, &w, &h);
+                  efl_gfx_buffer_map(image, &sl, 
EFL_GFX_BUFFER_ACCESS_MODE_READ,
+                                     0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, 
0,
+                                     &stride);
+               }
+             else
+               {
+                  evas_object_image_size_get(image, &w, &h);
+                  stride = evas_object_image_stride_get(image);
+                  sl.mem = evas_object_image_data_get(image, EINA_FALSE);
+               }
+
+             if (sl.mem)
                {
                   Ecore_X_Icon ic;
-                  int w = 0, h = 0, stride, x, y;
-                  unsigned char *p;
-                  unsigned int *p2;
 
-                  evas_object_image_size_get(sd->icon, &w, &h);
-                  stride = evas_object_image_stride_get(sd->icon);
+                  ic.width = w;
+                  ic.height = h;
                   if ((w > 0) && (h > 0) &&
                       (stride >= (int)(w * sizeof(unsigned int))))
                     {
-                       ic.width = w;
-                       ic.height = h;
-                       ic.data = malloc(w * h * sizeof(unsigned int));
-
-                       if (ic.data)
+                       if (stride == (int)(w * sizeof(unsigned int)))
                          {
-                            p = (unsigned char *)data;
-                            p2 = (unsigned int *)ic.data;
-                            for (y = 0; y < h; y++)
+                            ic.data = sl.mem;
+                            ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
+                         }
+                       else
+                         {
+                            ic.data = malloc(w * h * sizeof(unsigned int));
+                            if (ic.data)
                               {
-                                 for (x = 0; x < w; x++)
+                                 unsigned char *p = sl.mem;
+                                 unsigned int *p2 = ic.data;
+
+                                 for (y = 0; y < h; y++)
                                    {
-                                      *p2 = *((unsigned int *)p);
-                                      p += sizeof(unsigned int);
-                                      p2++;
+                                      for (x = 0; x < w; x++)
+                                        {
+                                           *p2 = *((unsigned int *)p);
+                                           p += sizeof(unsigned int);
+                                           p2++;
+                                        }
+                                      p += (stride - (w * sizeof(unsigned 
int)));
                                    }
-                                 p += (stride - (w * sizeof(unsigned int)));
+                                 ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
+                                 free(ic.data);
                               }
-                            ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
-                            free(ic.data);
                          }
                     }
-                  evas_object_image_data_set(sd->icon, data);
+                  if (unmap) efl_gfx_buffer_unmap(image, &sl);
+                  else evas_object_image_data_set(image, sl.mem);
                }
           }
      }

-- 


Reply via email to