summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/evas_object_image.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-03-04 15:57:36 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-03-15 11:11:59 +0900
commitba53f0e7857f9753e8e639ec5768112630b227ad (patch)
tree27cbe87164d5f48b9f3d3976838b14652a525915 /src/lib/evas/canvas/evas_object_image.c
parentb458341a13b93b2f963745fae34b3ce14668f99d (diff)
Efl.Gfx.Buffer: Introduce buffer_set/get/copy_set
Hopefully the doc and signature are better than the current evas image equivalents data_get/data_set. Those APIs are not like map/unmap so we need to decide which model we prefer.
Diffstat (limited to '')
-rw-r--r--src/lib/evas/canvas/evas_object_image.c378
1 files changed, 189 insertions, 189 deletions
diff --git a/src/lib/evas/canvas/evas_object_image.c b/src/lib/evas/canvas/evas_object_image.c
index 10fa5e8208..4046b354c8 100644
--- a/src/lib/evas/canvas/evas_object_image.c
+++ b/src/lib/evas/canvas/evas_object_image.c
@@ -1013,10 +1013,12 @@ _evas_image_efl_gfx_fill_fill_get(Eo *eo_obj EINA_UNUSED, Evas_Image_Data *o,
1013 if (h) *h = o->cur->fill.h; 1013 if (h) *h = o->cur->fill.h;
1014} 1014}
1015 1015
1016EOLIAN static void 1016/* eo equivalent: pixels_set(null, w, h) to (re)allocate an image */
1017_evas_image_efl_gfx_view_view_size_set(Eo *eo_obj, Evas_Image_Data *o, int w, int h) 1017EAPI void
1018evas_object_image_size_set(Eo *eo_obj, int w, int h)
1018{ 1019{
1019 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); 1020 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
1021 Evas_Image_Data *o = eo_data_scope_get(eo_obj, MY_CLASS);
1020 1022
1021 int stride = 0; 1023 int stride = 0;
1022 1024
@@ -1120,7 +1122,7 @@ _evas_image_efl_gfx_view_view_size_get(Eo *eo_obj, Evas_Image_Data *o, int *w, i
1120} 1122}
1121 1123
1122EOLIAN static int 1124EOLIAN static int
1123_evas_image_efl_gfx_buffer_buffer_stride_get(Eo *eo_obj EINA_UNUSED, Evas_Image_Data *o) 1125_evas_image_efl_gfx_buffer_stride_get(Eo *eo_obj EINA_UNUSED, Evas_Image_Data *o)
1124{ 1126{
1125 return o->cur->image.stride; 1127 return o->cur->image.stride;
1126} 1128}
@@ -1168,137 +1170,6 @@ evas_object_image_data_convert(Evas_Object *eo_obj, Evas_Colorspace to_cspace)
1168 return result; 1170 return result;
1169} 1171}
1170 1172
1171EOLIAN static void
1172_evas_image_data_set(Eo *eo_obj, Evas_Image_Data *o, void *data)
1173{
1174 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
1175 void *p_data;
1176 Eina_Bool resize_call = EINA_FALSE;
1177
1178
1179 evas_object_async_block(obj);
1180 evas_render_rendering_wait(obj->layer->evas);
1181
1182 _evas_object_image_cleanup(eo_obj, obj, o);
1183 p_data = o->engine_data;
1184 if (data)
1185 {
1186 if (o->engine_data)
1187 {
1188 o->engine_data = ENFN->image_data_put(ENDT, o->engine_data, data);
1189 }
1190 else
1191 {
1192 o->engine_data = ENFN->image_new_from_data(ENDT,
1193 o->cur->image.w,
1194 o->cur->image.h,
1195 data,
1196 o->cur->has_alpha,
1197 o->cur->cspace);
1198 }
1199 if (o->engine_data)
1200 {
1201 int stride = 0;
1202
1203 if (ENFN->image_scale_hint_set)
1204 ENFN->image_scale_hint_set(ENDT, o->engine_data, o->scale_hint);
1205
1206 if (ENFN->image_content_hint_set)
1207 ENFN->image_content_hint_set(ENDT, o->engine_data, o->content_hint);
1208
1209 if (ENFN->image_stride_get)
1210 ENFN->image_stride_get(ENDT, o->engine_data, &stride);
1211 else
1212 stride = o->cur->image.w * 4;
1213
1214 if (o->cur->image.stride != stride)
1215 {
1216 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
1217 state_write->image.stride = stride;
1218 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
1219 }
1220 }
1221 o->written = EINA_TRUE;
1222 }
1223 else
1224 {
1225 if (o->engine_data)
1226 ENFN->image_free(ENDT, o->engine_data);
1227 o->load_error = EVAS_LOAD_ERROR_NONE;
1228 if ((o->cur->image.w != 0) || (o->cur->image.h != 0))
1229 resize_call = EINA_TRUE;
1230
1231 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
1232 {
1233 state_write->image.w = 0;
1234 state_write->image.h = 0;
1235 state_write->image.stride = 0;
1236 }
1237 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
1238
1239 o->engine_data = NULL;
1240 }
1241/* FIXME - in engine call above
1242 if (o->engine_data)
1243 o->engine_data = ENFN->image_alpha_set(ENDT, o->engine_data, o->cur->has_alpha);
1244*/
1245 if (o->pixels_checked_out > 0) o->pixels_checked_out--;
1246 if (p_data != o->engine_data)
1247 {
1248 EVAS_OBJECT_WRITE_IMAGE_FREE_FILE_AND_KEY(o);
1249 o->pixels_checked_out = 0;
1250 }
1251 if (resize_call) evas_object_inform_call_image_resize(eo_obj);
1252}
1253
1254EOLIAN static void*
1255_evas_image_data_get(const Eo *eo_obj, Evas_Image_Data *_pd EINA_UNUSED, Eina_Bool for_writing)
1256{
1257 Evas_Image_Data *o = (Evas_Image_Data *) _pd;
1258 int stride = 0;
1259 void *pixels;
1260 DATA32 *data;
1261
1262 if (!o->engine_data) return NULL;
1263
1264 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
1265
1266 if (for_writing) evas_object_async_block(obj);
1267 if (for_writing) evas_render_rendering_wait(obj->layer->evas);
1268
1269 data = NULL;
1270 if (ENFN->image_scale_hint_set)
1271 ENFN->image_scale_hint_set(ENDT, o->engine_data, o->scale_hint);
1272 if (ENFN->image_content_hint_set)
1273 ENFN->image_content_hint_set(ENDT, o->engine_data, o->content_hint);
1274 pixels = ENFN->image_data_get(ENDT, o->engine_data, for_writing, &data, &o->load_error, NULL);
1275
1276 /* if we fail to get engine_data, we have to return NULL */
1277 if (!pixels) return NULL;
1278
1279 o->engine_data = pixels;
1280 if (ENFN->image_stride_get)
1281 ENFN->image_stride_get(ENDT, o->engine_data, &stride);
1282 else
1283 stride = o->cur->image.w * 4;
1284
1285 if (o->cur->image.stride != stride)
1286 {
1287 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
1288 state_write->image.stride = stride;
1289 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
1290 }
1291
1292 o->pixels_checked_out++;
1293 if (for_writing)
1294 {
1295 o->written = EINA_TRUE;
1296 EVAS_OBJECT_WRITE_IMAGE_FREE_FILE_AND_KEY(o);
1297 }
1298
1299 return data;
1300}
1301
1302static void 1173static void
1303_image_preload_internal(Eo *eo_obj, void *_pd, Eina_Bool cancel) 1174_image_preload_internal(Eo *eo_obj, void *_pd, Eina_Bool cancel)
1304{ 1175{
@@ -1348,52 +1219,7 @@ _evas_image_efl_image_load_load_async_cancel(Eo *eo_obj, Evas_Image_Data *_pd EI
1348} 1219}
1349 1220
1350EOLIAN static void 1221EOLIAN static void
1351_evas_image_data_copy_set(Eo *eo_obj, Evas_Image_Data *o, void *data) 1222_evas_image_efl_gfx_buffer_buffer_update_add(Eo *eo_obj, Evas_Image_Data *o, int x, int y, int w, int h)
1352{
1353 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
1354
1355 if (!data) return;
1356 evas_object_async_block(obj);
1357 _evas_object_image_cleanup(eo_obj, obj, o);
1358 if ((o->cur->image.w <= 0) ||
1359 (o->cur->image.h <= 0)) return;
1360 if (o->engine_data)
1361 ENFN->image_free(ENDT, o->engine_data);
1362 o->engine_data = ENFN->image_new_from_copied_data(ENDT,
1363 o->cur->image.w,
1364 o->cur->image.h,
1365 data,
1366 o->cur->has_alpha,
1367 o->cur->cspace);
1368 if (o->engine_data)
1369 {
1370 int stride = 0;
1371
1372 o->engine_data =
1373 ENFN->image_alpha_set(ENDT, o->engine_data, o->cur->has_alpha);
1374 if (ENFN->image_scale_hint_set)
1375 ENFN->image_scale_hint_set(ENDT, o->engine_data, o->scale_hint);
1376 if (ENFN->image_content_hint_set)
1377 ENFN->image_content_hint_set(ENDT, o->engine_data, o->content_hint);
1378 if (ENFN->image_stride_get)
1379 ENFN->image_stride_get(ENDT, o->engine_data, &stride);
1380 else
1381 stride = o->cur->image.w * 4;
1382
1383 if (o->cur->image.stride != stride)
1384 {
1385 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
1386 state_write->image.stride = stride;
1387 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
1388 }
1389 o->written = EINA_TRUE;
1390 }
1391 o->pixels_checked_out = 0;
1392 EVAS_OBJECT_WRITE_IMAGE_FREE_FILE_AND_KEY(o);
1393}
1394
1395EOLIAN static void
1396_evas_image_efl_gfx_buffer_buffer_update_region_add(Eo *eo_obj, Evas_Image_Data *o, int x, int y, int w, int h)
1397{ 1223{
1398 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); 1224 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
1399 Eina_Rectangle *r; 1225 Eina_Rectangle *r;
@@ -3146,7 +2972,7 @@ _evas_image_evas_filter_filter_input_alpha(Eo *eo_obj EINA_UNUSED, Evas_Image_Da
3146} 2972}
3147 2973
3148EOLIAN static void 2974EOLIAN static void
3149_evas_image_efl_gfx_filter_filter_program_set(Eo *obj, Evas_Image_Data *pd EINA_UNUSED, 2975_evas_image_efl_gfx_filter_filter_program_set(Eo *obj, Evas_Image_Data *pd,
3150 const char *code, const char *name) 2976 const char *code, const char *name)
3151{ 2977{
3152 pd->has_filter = (code != NULL); 2978 pd->has_filter = (code != NULL);
@@ -4844,6 +4670,186 @@ _evas_object_image_surface_get(Evas_Object *eo, Evas_Object_Protected_Data *obj)
4844 return pd->engine_data; 4670 return pd->engine_data;
4845} 4671}
4846 4672
4673/* Legacy deprecated functions */
4674
4675EAPI void
4676evas_object_image_data_set(Eo *eo_obj, void *data)
4677{
4678 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
4679 Evas_Image_Data *o = eo_data_scope_get(eo_obj, MY_CLASS);
4680 void *p_data;
4681 Eina_Bool resize_call = EINA_FALSE;
4682
4683
4684 evas_object_async_block(obj);
4685 evas_render_rendering_wait(obj->layer->evas);
4686
4687 _evas_object_image_cleanup(eo_obj, obj, o);
4688 p_data = o->engine_data;
4689 if (data)
4690 {
4691 if (o->engine_data)
4692 {
4693 o->engine_data = ENFN->image_data_put(ENDT, o->engine_data, data);
4694 }
4695 else
4696 {
4697 o->engine_data = ENFN->image_new_from_data(ENDT,
4698 o->cur->image.w,
4699 o->cur->image.h,
4700 data,
4701 o->cur->has_alpha,
4702 o->cur->cspace);
4703 }
4704 if (o->engine_data)
4705 {
4706 int stride = 0;
4707
4708 if (ENFN->image_scale_hint_set)
4709 ENFN->image_scale_hint_set(ENDT, o->engine_data, o->scale_hint);
4710
4711 if (ENFN->image_content_hint_set)
4712 ENFN->image_content_hint_set(ENDT, o->engine_data, o->content_hint);
4713
4714 if (ENFN->image_stride_get)
4715 ENFN->image_stride_get(ENDT, o->engine_data, &stride);
4716 else
4717 stride = o->cur->image.w * 4;
4718
4719 if (o->cur->image.stride != stride)
4720 {
4721 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
4722 state_write->image.stride = stride;
4723 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
4724 }
4725 }
4726 o->written = EINA_TRUE;
4727 }
4728 else
4729 {
4730 if (o->engine_data)
4731 ENFN->image_free(ENDT, o->engine_data);
4732 o->load_error = EVAS_LOAD_ERROR_NONE;
4733 if ((o->cur->image.w != 0) || (o->cur->image.h != 0))
4734 resize_call = EINA_TRUE;
4735
4736 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
4737 {
4738 state_write->image.w = 0;
4739 state_write->image.h = 0;
4740 state_write->image.stride = 0;
4741 }
4742 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
4743
4744 o->engine_data = NULL;
4745 }
4746/* FIXME - in engine call above
4747 if (o->engine_data)
4748 o->engine_data = ENFN->image_alpha_set(ENDT, o->engine_data, o->cur->has_alpha);
4749*/
4750 if (o->pixels_checked_out > 0) o->pixels_checked_out--;
4751 if (p_data != o->engine_data)
4752 {
4753 EVAS_OBJECT_WRITE_IMAGE_FREE_FILE_AND_KEY(o);
4754 o->pixels_checked_out = 0;
4755 }
4756 if (resize_call) evas_object_inform_call_image_resize(eo_obj);
4757}
4758
4759EAPI void*
4760evas_object_image_data_get(const Eo *eo_obj, Eina_Bool for_writing)
4761{
4762 Evas_Image_Data *o = eo_data_scope_get(eo_obj, MY_CLASS);
4763 int stride = 0;
4764 void *pixels;
4765 DATA32 *data;
4766
4767 if (!o->engine_data) return NULL;
4768
4769 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
4770
4771 if (for_writing) evas_object_async_block(obj);
4772 if (for_writing) evas_render_rendering_wait(obj->layer->evas);
4773
4774 data = NULL;
4775 if (ENFN->image_scale_hint_set)
4776 ENFN->image_scale_hint_set(ENDT, o->engine_data, o->scale_hint);
4777 if (ENFN->image_content_hint_set)
4778 ENFN->image_content_hint_set(ENDT, o->engine_data, o->content_hint);
4779 pixels = ENFN->image_data_get(ENDT, o->engine_data, for_writing, &data, &o->load_error, NULL);
4780
4781 /* if we fail to get engine_data, we have to return NULL */
4782 if (!pixels) return NULL;
4783
4784 o->engine_data = pixels;
4785 if (ENFN->image_stride_get)
4786 ENFN->image_stride_get(ENDT, o->engine_data, &stride);
4787 else
4788 stride = o->cur->image.w * 4;
4789
4790 if (o->cur->image.stride != stride)
4791 {
4792 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
4793 state_write->image.stride = stride;
4794 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
4795 }
4796
4797 o->pixels_checked_out++;
4798 if (for_writing)
4799 {
4800 o->written = EINA_TRUE;
4801 EVAS_OBJECT_WRITE_IMAGE_FREE_FILE_AND_KEY(o);
4802 }
4803
4804 return data;
4805}
4806
4807EAPI void
4808evas_object_image_data_copy_set(Eo *eo_obj, void *data)
4809{
4810 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
4811 Evas_Image_Data *o = eo_data_scope_get(eo_obj, MY_CLASS);
4812
4813 if (!data) return;
4814 evas_object_async_block(obj);
4815 _evas_object_image_cleanup(eo_obj, obj, o);
4816 if ((o->cur->image.w <= 0) ||
4817 (o->cur->image.h <= 0)) return;
4818 if (o->engine_data)
4819 ENFN->image_free(ENDT, o->engine_data);
4820 o->engine_data = ENFN->image_new_from_copied_data(ENDT,
4821 o->cur->image.w,
4822 o->cur->image.h,
4823 data,
4824 o->cur->has_alpha,
4825 o->cur->cspace);
4826 if (o->engine_data)
4827 {
4828 int stride = 0;
4829
4830 o->engine_data =
4831 ENFN->image_alpha_set(ENDT, o->engine_data, o->cur->has_alpha);
4832 if (ENFN->image_scale_hint_set)
4833 ENFN->image_scale_hint_set(ENDT, o->engine_data, o->scale_hint);
4834 if (ENFN->image_content_hint_set)
4835 ENFN->image_content_hint_set(ENDT, o->engine_data, o->content_hint);
4836 if (ENFN->image_stride_get)
4837 ENFN->image_stride_get(ENDT, o->engine_data, &stride);
4838 else
4839 stride = o->cur->image.w * 4;
4840
4841 if (o->cur->image.stride != stride)
4842 {
4843 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
4844 state_write->image.stride = stride;
4845 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
4846 }
4847 o->written = EINA_TRUE;
4848 }
4849 o->pixels_checked_out = 0;
4850 EVAS_OBJECT_WRITE_IMAGE_FREE_FILE_AND_KEY(o);
4851}
4852
4847/* Legacy wrappers */ 4853/* Legacy wrappers */
4848 4854
4849EAPI Evas_Object * 4855EAPI Evas_Object *
@@ -4963,13 +4969,7 @@ evas_object_image_border_center_fill_get(const Evas_Object *obj)
4963EAPI void 4969EAPI void
4964evas_object_image_size_get(const Evas_Image *obj, int *w, int *h) 4970evas_object_image_size_get(const Evas_Image *obj, int *w, int *h)
4965{ 4971{
4966 efl_gfx_view_size_get((Evas_Image *)obj, w, h); 4972 efl_gfx_view_size_get(obj, w, h);
4967}
4968
4969EAPI void
4970evas_object_image_size_set(Evas_Image *obj, int w, int h)
4971{
4972 efl_gfx_view_size_set(obj, w, h);
4973} 4973}
4974 4974
4975EAPI Evas_Colorspace 4975EAPI Evas_Colorspace
@@ -4987,7 +4987,7 @@ evas_object_image_stride_get(const Evas_Object *obj)
4987EAPI void 4987EAPI void
4988evas_object_image_data_update_add(Evas_Object *obj, int x, int y, int w, int h) 4988evas_object_image_data_update_add(Evas_Object *obj, int x, int y, int w, int h)
4989{ 4989{
4990 efl_gfx_buffer_update_region_add(obj, x, y, w, h); 4990 efl_gfx_buffer_update_add(obj, x, y, w, h);
4991} 4991}
4992 4992
4993EAPI void 4993EAPI void