summaryrefslogtreecommitdiff
path: root/src/lib/elementary
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-02-16 20:40:22 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-02-16 21:05:32 +0900
commitc09b921e34545ad93bd9091e35a816e687276310 (patch)
tree350a80dcd5c843f2f0e8b15bc92421fbb7dd6009 /src/lib/elementary
parenta014b2140069c8c9b03f048698537abe7316cc10 (diff)
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 :(
Diffstat (limited to 'src/lib/elementary')
-rw-r--r--src/lib/elementary/efl_ui_win.c73
1 files changed, 49 insertions, 24 deletions
diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c
index f558430860..06d3bd501b 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)
3185 // set window icon 3185 // set window icon
3186 if (sd->icon) 3186 if (sd->icon)
3187 { 3187 {
3188 void *data; 3188 Eo *image = NULL;
3189 3189
3190 if (efl_isa(sd->icon, EFL_CANVAS_IMAGE_INTERNAL_CLASS)) 3190 if (efl_isa(sd->icon, EFL_CANVAS_IMAGE_INTERNAL_CLASS))
3191 image = sd->icon;
3192
3193 if (image)
3191 { 3194 {
3192 data = evas_object_image_data_get(sd->icon, EINA_FALSE); 3195 int w = 0, h = 0, stride, x, y;
3193 if (data) 3196 Eina_Bool unmap = EINA_FALSE;
3197 Eina_Rw_Slice sl = {};
3198
3199 if (efl_isa(image, EFL_CANVAS_IMAGE_CLASS))
3200 {
3201 unmap = EINA_TRUE;
3202 efl_gfx_buffer_size_get(image, &w, &h);
3203 efl_gfx_buffer_map(image, &sl, EFL_GFX_BUFFER_ACCESS_MODE_READ,
3204 0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, 0,
3205 &stride);
3206 }
3207 else
3208 {
3209 evas_object_image_size_get(image, &w, &h);
3210 stride = evas_object_image_stride_get(image);
3211 sl.mem = evas_object_image_data_get(image, EINA_FALSE);
3212 }
3213
3214 if (sl.mem)
3194 { 3215 {
3195 Ecore_X_Icon ic; 3216 Ecore_X_Icon ic;
3196 int w = 0, h = 0, stride, x, y;
3197 unsigned char *p;
3198 unsigned int *p2;
3199 3217
3200 evas_object_image_size_get(sd->icon, &w, &h); 3218 ic.width = w;
3201 stride = evas_object_image_stride_get(sd->icon); 3219 ic.height = h;
3202 if ((w > 0) && (h > 0) && 3220 if ((w > 0) && (h > 0) &&
3203 (stride >= (int)(w * sizeof(unsigned int)))) 3221 (stride >= (int)(w * sizeof(unsigned int))))
3204 { 3222 {
3205 ic.width = w; 3223 if (stride == (int)(w * sizeof(unsigned int)))
3206 ic.height = h;
3207 ic.data = malloc(w * h * sizeof(unsigned int));
3208
3209 if (ic.data)
3210 { 3224 {
3211 p = (unsigned char *)data; 3225 ic.data = sl.mem;
3212 p2 = (unsigned int *)ic.data; 3226 ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
3213 for (y = 0; y < h; y++) 3227 }
3228 else
3229 {
3230 ic.data = malloc(w * h * sizeof(unsigned int));
3231 if (ic.data)
3214 { 3232 {
3215 for (x = 0; x < w; x++) 3233 unsigned char *p = sl.mem;
3234 unsigned int *p2 = ic.data;
3235
3236 for (y = 0; y < h; y++)
3216 { 3237 {
3217 *p2 = *((unsigned int *)p); 3238 for (x = 0; x < w; x++)
3218 p += sizeof(unsigned int); 3239 {
3219 p2++; 3240 *p2 = *((unsigned int *)p);
3241 p += sizeof(unsigned int);
3242 p2++;
3243 }
3244 p += (stride - (w * sizeof(unsigned int)));
3220 } 3245 }
3221 p += (stride - (w * sizeof(unsigned int))); 3246 ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
3247 free(ic.data);
3222 } 3248 }
3223 ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
3224 free(ic.data);
3225 } 3249 }
3226 } 3250 }
3227 evas_object_image_data_set(sd->icon, data); 3251 if (unmap) efl_gfx_buffer_unmap(image, &sl);
3252 else evas_object_image_data_set(image, sl.mem);
3228 } 3253 }
3229 } 3254 }
3230 } 3255 }