forked from enlightenment/efl
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 :(
This commit is contained in:
parent
a014b21400
commit
c09b921e34
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
*p2 = *((unsigned int *)p);
|
||||
p += sizeof(unsigned int);
|
||||
p2++;
|
||||
}
|
||||
p += (stride - (w * sizeof(unsigned int)));
|
||||
}
|
||||
ic.data = sl.mem;
|
||||
ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
|
||||
free(ic.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
ic.data = malloc(w * h * sizeof(unsigned int));
|
||||
if (ic.data)
|
||||
{
|
||||
unsigned char *p = sl.mem;
|
||||
unsigned int *p2 = ic.data;
|
||||
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
*p2 = *((unsigned int *)p);
|
||||
p += sizeof(unsigned int);
|
||||
p2++;
|
||||
}
|
||||
p += (stride - (w * sizeof(unsigned int)));
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue