summaryrefslogtreecommitdiff
path: root/src/bin/edje/edje_cc_handlers.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-06-30 19:26:20 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-07-01 20:46:34 +0900
commit6ca02cbfe898799c9276fdb52971f7697b16cac9 (patch)
tree3aa51a4c878088bf74c00a128c43493787092318 /src/bin/edje/edje_cc_handlers.c
parent161822418ab141a442a7d678adbcb0221e76eda9 (diff)
Edje: Embed verbatim scripts for Efl.Gfx.Filters
This is now like the other embedded scripts, where a verbatim string is parsed. The syntax is now: filters { filter { name: "filter0"; file: "filter.lua"; } filter { name: "filter1"; script { blend {} } } filter.file: "file.lua"; // name is "file.lua" } Thanks @raster for the quick review.
Diffstat (limited to '')
-rw-r--r--src/bin/edje/edje_cc_handlers.c191
1 files changed, 154 insertions, 37 deletions
diff --git a/src/bin/edje/edje_cc_handlers.c b/src/bin/edje/edje_cc_handlers.c
index 18701a21b3..9f2e21b50b 100644
--- a/src/bin/edje/edje_cc_handlers.c
+++ b/src/bin/edje/edje_cc_handlers.c
@@ -213,8 +213,10 @@ static void st_color_class_color2(void);
213static void st_color_class_color3(void); 213static void st_color_class_color3(void);
214static void st_color_class_desc(void); 214static void st_color_class_desc(void);
215 215
216static void st_filters_filter_inline(void); 216static void ob_filters_filter(void);
217static void ob_filters_filter_script(void);
217static void st_filters_filter_file(void); 218static void st_filters_filter_file(void);
219static void st_filters_filter_name(void);
218 220
219static void ob_collections(void); 221static void ob_collections(void);
220static void st_collections_base_scale(void); 222static void st_collections_base_scale(void);
@@ -625,10 +627,8 @@ static void st_collections_group_nobroadcast(void);
625 } 627 }
626 628
627#define FILTERS_STATEMENTS(PREFIX) \ 629#define FILTERS_STATEMENTS(PREFIX) \
628 {PREFIX"filters", NULL}, \ 630 {PREFIX"filters.filter.file", st_filters_filter_file}, \
629 {PREFIX"filters.filter", NULL}, \ 631 {PREFIX"filters.filter.name", st_filters_filter_name},
630 {PREFIX"filters.filter.inline", st_filters_filter_inline}, \
631 {PREFIX"filters.filter.file", st_filters_filter_file},
632 632
633New_Statement_Handler statement_handlers[] = 633New_Statement_Handler statement_handlers[] =
634{ 634{
@@ -1119,6 +1119,9 @@ New_Object_Handler object_handlers[] =
1119 {"color_classes", NULL}, 1119 {"color_classes", NULL},
1120 {"color_classes.color_class", ob_color_class}, 1120 {"color_classes.color_class", ob_color_class},
1121 {"spectra", NULL}, 1121 {"spectra", NULL},
1122 {"filters", NULL},
1123 {"filters.filter", ob_filters_filter},
1124 {"filters.filter.script", ob_filters_filter_script},
1122 {"collections", ob_collections}, 1125 {"collections", ob_collections},
1123 {"collections.externals", NULL}, /* dup */ 1126 {"collections.externals", NULL}, /* dup */
1124 {"collections.set", ob_images_set}, /* dup */ 1127 {"collections.set", ob_images_set}, /* dup */
@@ -1142,6 +1145,9 @@ New_Object_Handler object_handlers[] =
1142 {"collections.vibrations", NULL}, 1145 {"collections.vibrations", NULL},
1143 {"collections.group.vibrations", NULL}, /* dup */ 1146 {"collections.group.vibrations", NULL}, /* dup */
1144 {"collections.vibrations.sample", NULL}, 1147 {"collections.vibrations.sample", NULL},
1148 {"collections.filters", NULL},
1149 {"collections.filters.filter", ob_filters_filter}, /* dup */
1150 {"collections.filters.filter.script", ob_filters_filter_script}, /* dup */
1145 {"collections.group.vibrations.sample", NULL}, /* dup */ 1151 {"collections.group.vibrations.sample", NULL}, /* dup */
1146 {"collections.group", ob_collections_group}, 1152 {"collections.group", ob_collections_group},
1147 {"collections.group.data", NULL}, 1153 {"collections.group.data", NULL},
@@ -1160,6 +1166,9 @@ New_Object_Handler object_handlers[] =
1160 {"collections.group.styles.style", ob_styles_style}, /* dup */ 1166 {"collections.group.styles.style", ob_styles_style}, /* dup */
1161 {"collections.group.color_classes", NULL}, /* dup */ 1167 {"collections.group.color_classes", NULL}, /* dup */
1162 {"collections.group.color_classes.color_class", ob_color_class}, /* dup */ 1168 {"collections.group.color_classes.color_class", ob_color_class}, /* dup */
1169 {"collections.group.filters", NULL},
1170 {"collections.group.filters.filter", ob_filters_filter}, /* dup */
1171 {"collections.group.filters.filter.script", ob_filters_filter_script}, /* dup */
1163 {"collections.group.parts", NULL}, 1172 {"collections.group.parts", NULL},
1164 {"collections.group.parts.set", ob_images_set}, /* dup */ 1173 {"collections.group.parts.set", ob_images_set}, /* dup */
1165 {"collections.group.parts.set.image", ob_images_set_image}, /* dup */ 1174 {"collections.group.parts.set.image", ob_images_set_image}, /* dup */
@@ -4311,7 +4320,7 @@ st_collections_group_data_item(void)
4311 // collections 4320 // collections
4312 // collections.group 4321 // collections.group
4313 filters { 4322 filters {
4314 filter.inline: "key" "Lua script here"; 4323 filter.script: "key" "Lua script here";
4315 filter.file: "other" "filename.lua"; 4324 filter.file: "other" "filename.lua";
4316 .. 4325 ..
4317 } 4326 }
@@ -4343,30 +4352,73 @@ st_collections_group_data_item(void)
4343 @endproperty 4352 @endproperty
4344*/ 4353*/
4345 4354
4346// ensure order so we could do binary search later on 4355static Edje_Gfx_Filter *current_filter = NULL;
4347// since this here happens at build time, we don't care about very hi-perf 4356
4348static void 4357static void
4349_filters_filter_insert(const char *name, const char *script) 4358_filters_filter_sort(void)
4350{ 4359{
4351 Edje_Gfx_Filter *array; 4360 Edje_Gfx_Filter *array, current;
4352 int k, i; 4361 int new_pos, i, cur_pos;
4353 4362
4354 if (!edje_file->filter_dir) 4363 if (!current_filter)
4355 edje_file->filter_dir = mem_alloc(sizeof(Edje_Gfx_Filter_Directory)); 4364 return;
4356 4365
4357 for (k = 0; k < edje_file->filter_dir->filters_count; k++) 4366 if (!current_filter->name)
4358 { 4367 {
4359 int cmp = strcmp(name, edje_file->filter_dir->filters[k].name); 4368 ERR("parse error %s:%i. Filter has no name.",
4360 if (!cmp) 4369 file_in, line - 1);
4370 exit(-1);
4371 }
4372
4373 array = edje_file->filter_dir->filters;
4374 cur_pos = (current_filter - array);
4375
4376 // find position in sorted array
4377 for (new_pos = 0; new_pos < edje_file->filter_dir->filters_count - 1; new_pos++)
4378 {
4379 int cmp;
4380 if (cur_pos == new_pos)
4381 continue;
4382 cmp = strcmp(current_filter->name, array[new_pos].name);
4383 if (cmp == 0)
4361 { 4384 {
4362 ERR("parse error %s:%i. A filter named '%s' already exists within this block.", 4385 ERR("parse error %s:%i. Another filter named '%s' already exists.",
4363 file_in, line - 1, name); 4386 file_in, line - 1, array[new_pos].name);
4364 exit(-1); 4387 exit(-1);
4365 } 4388 }
4366 else if (cmp < 0) 4389 else if (cmp < 0)
4367 break; 4390 break;
4368 } 4391 }
4369 4392
4393 if (new_pos > cur_pos)
4394 new_pos--;
4395
4396 if (cur_pos == new_pos)
4397 return;
4398
4399 current = *current_filter;
4400
4401 // move up
4402 for (i = cur_pos - 1; i >= new_pos; i--)
4403 array[i + 1] = array[i];
4404
4405 // move down
4406 for (i = cur_pos; i < new_pos; i++)
4407 array[i] = array[i + 1];
4408
4409 array[new_pos] = current;
4410 current_filter = &array[new_pos];
4411}
4412
4413static void
4414ob_filters_filter(void)
4415{
4416 Edje_Gfx_Filter *array;
4417
4418 _filters_filter_sort();
4419 if (!edje_file->filter_dir)
4420 edje_file->filter_dir = mem_alloc(sizeof(Edje_Gfx_Filter_Directory));
4421
4370 array = realloc(edje_file->filter_dir->filters, 4422 array = realloc(edje_file->filter_dir->filters,
4371 sizeof(Edje_Gfx_Filter) * (edje_file->filter_dir->filters_count + 1)); 4423 sizeof(Edje_Gfx_Filter) * (edje_file->filter_dir->filters_count + 1));
4372 if (!array) 4424 if (!array)
@@ -4375,39 +4427,71 @@ _filters_filter_insert(const char *name, const char *script)
4375 exit(-1); 4427 exit(-1);
4376 } 4428 }
4377 4429
4378 for (i = edje_file->filter_dir->filters_count - 1; i >= k; i--) 4430 current_filter = &array[edje_file->filter_dir->filters_count];
4379 array[i + 1] = array[i]; 4431 memset(current_filter, 0, sizeof(Edje_Gfx_Filter));
4380
4381 array[k].name = eina_stringshare_add(name);
4382 array[k].script = eina_stringshare_add(script);
4383 edje_file->filter_dir->filters_count++; 4432 edje_file->filter_dir->filters_count++;
4384 edje_file->filter_dir->filters = array; 4433 edje_file->filter_dir->filters = array;
4385} 4434}
4386 4435
4387static void 4436static void
4388st_filters_filter_inline(void) 4437ob_filters_filter_script(void)
4389{ 4438{
4390 char *name, *script; 4439 char *script;
4391 4440
4392 check_arg_count(2); 4441 if (!current_filter)
4442 ob_filters_filter();
4393 4443
4394 name = parse_str(0); 4444 if (!current_filter->name)
4395 script = parse_str(1); 4445 {
4396 _filters_filter_insert(name, script); 4446 ERR("parse error %s:%i. Name for inline filter must be specified first.",
4397 free(name); 4447 file_in, line - 1);
4398 free(script); 4448 exit(-1);
4449 }
4450
4451 if (current_filter->script)
4452 {
4453 ERR("parse error %s:%i. Script for filter '%s' is already defined.",
4454 file_in, line - 1, current_filter->name);
4455 exit(-1);
4456 }
4457
4458 if (!is_verbatim())
4459 track_verbatim(1);
4460 else
4461 {
4462 script = get_verbatim();
4463 if (script)
4464 {
4465 //current_filter->verb_l1 = get_verbatim_line1();
4466 //current_filter->verb_l2 = get_verbatim_line2();
4467 current_filter->script = strdup(script);
4468 set_verbatim(NULL, 0, 0);
4469 _filters_filter_sort();
4470 current_filter = NULL;
4471 }
4472 }
4399} 4473}
4400 4474
4401static void 4475static void
4402st_filters_filter_file(void) 4476st_filters_filter_file(void)
4403{ 4477{
4404 char *name, *file, *script; 4478 char *file, *script;
4405 Eina_File *f; 4479 Eina_File *f;
4480 size_t sz;
4406 4481
4407 check_arg_count(2); 4482 if (!current_filter)
4483 ob_filters_filter();
4408 4484
4409 name = parse_str(0); 4485 if (current_filter->script)
4410 file = parse_str(1); 4486 {
4487 ERR("parse error %s:%i. Script for filter '%s' is already defined.",
4488 file_in, line - 1, current_filter->name);
4489 exit(-1);
4490 }
4491
4492 check_arg_count(1);
4493
4494 file = parse_str(0);
4411 f = eina_file_open(file, EINA_FALSE); 4495 f = eina_file_open(file, EINA_FALSE);
4412 if (!f) 4496 if (!f)
4413 { 4497 {
@@ -4435,11 +4519,44 @@ st_filters_filter_file(void)
4435 file_in, line - 1, file); 4519 file_in, line - 1, file);
4436 exit(-1); 4520 exit(-1);
4437 } 4521 }
4438 _filters_filter_insert(name, script); 4522
4523 sz = eina_file_size_get(f);
4524 if (sz > (10 * 1024 * 1024))
4525 {
4526 ERR("parse error %s:%i. Filter file '%s' is unreasonably large, abort.",
4527 file_in, line - 1, file);
4528 exit(-1);
4529 }
4530
4531 current_filter->script = mem_alloc(sz);
4532 memcpy((char *) current_filter->script, script, sz);
4439 eina_file_map_free(f, script); 4533 eina_file_map_free(f, script);
4440 eina_file_close(f); 4534 eina_file_close(f);
4441 free(name);
4442 4535
4536 if (!current_filter->name)
4537 {
4538 current_filter->name = file;
4539 _filters_filter_sort();
4540 }
4541 else
4542 {
4543 free(file);
4544 _filters_filter_sort();
4545 current_filter = NULL;
4546 }
4547}
4548
4549static void
4550st_filters_filter_name(void)
4551{
4552 if (!current_filter)
4553 ob_filters_filter();
4554
4555 check_arg_count(1);
4556
4557 current_filter->name = parse_str(0);
4558
4559 _filters_filter_sort();
4443} 4560}
4444 4561
4445/** @edcsubsection{collections_group_limits, 4562/** @edcsubsection{collections_group_limits,