"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

expo: Create a struct for generic text attributes

In preparation for adding more text types, refactor the common fields
into a new structure. This will allow common code to be used.

Signed-off-by: Simon Glass <sjg@chromium.org>

Simon Glass 5a80996c 5ea2b533

+80 -49
+1 -1
boot/cedit.c
··· 271 271 if (!txt) 272 272 return log_msg_ret("txt", -ENOENT); 273 273 274 - str = expo_get_str(scn->expo, txt->str_id); 274 + str = expo_get_str(scn->expo, txt->gen.str_id); 275 275 if (!str) 276 276 return log_msg_ret("str", -ENOENT); 277 277 *strp = str;
+43 -22
boot/scene.c
··· 142 142 return img->obj.id; 143 143 } 144 144 145 + int scene_txt_generic_init(struct expo *exp, struct scene_txt_generic *gen, 146 + const char *name, uint str_id, const char *str) 147 + { 148 + int ret; 149 + 150 + if (str) { 151 + ret = expo_str(exp, name, str_id, str); 152 + if (ret < 0) 153 + return log_msg_ret("str", ret); 154 + if (str_id && ret != str_id) 155 + return log_msg_ret("id", -EEXIST); 156 + str_id = ret; 157 + } else { 158 + ret = resolve_id(exp, str_id); 159 + if (ret < 0) 160 + return log_msg_ret("nst", ret); 161 + if (str_id && ret != str_id) 162 + return log_msg_ret("nid", -EEXIST); 163 + } 164 + 165 + gen->str_id = str_id; 166 + 167 + return 0; 168 + } 169 + 145 170 int scene_txt(struct scene *scn, const char *name, uint id, uint str_id, 146 171 struct scene_obj_txt **txtp) 147 172 { ··· 154 179 if (ret < 0) 155 180 return log_msg_ret("obj", ret); 156 181 157 - txt->str_id = str_id; 158 - 182 + ret = scene_txt_generic_init(scn->expo, &txt->gen, name, str_id, NULL); 183 + if (ret) 184 + return log_msg_ret("stg", ret); 159 185 if (txtp) 160 186 *txtp = txt; 161 187 ··· 168 194 struct scene_obj_txt *txt; 169 195 int ret; 170 196 171 - ret = expo_str(scn->expo, name, str_id, str); 172 - if (ret < 0) 173 - return log_msg_ret("str", ret); 174 - if (str_id && ret != str_id) 175 - return log_msg_ret("id", -EEXIST); 176 - str_id = ret; 177 - 178 197 ret = scene_obj_add(scn, name, id, SCENEOBJT_TEXT, 179 198 sizeof(struct scene_obj_txt), 180 199 (struct scene_obj **)&txt); 181 200 if (ret < 0) 182 201 return log_msg_ret("obj", ret); 183 202 184 - txt->str_id = str_id; 185 - 203 + ret = scene_txt_generic_init(scn->expo, &txt->gen, name, str_id, str); 204 + if (ret) 205 + return log_msg_ret("tsg", ret); 186 206 if (txtp) 187 207 *txtp = txt; 188 208 ··· 197 217 txt = scene_obj_find(scn, id, SCENEOBJT_TEXT); 198 218 if (!txt) 199 219 return log_msg_ret("find", -ENOENT); 200 - txt->font_name = font_name; 201 - txt->font_size = font_size; 220 + txt->gen.font_name = font_name; 221 + txt->gen.font_size = font_size; 202 222 203 223 return 0; 204 224 } ··· 313 333 return height; 314 334 } 315 335 case SCENEOBJT_TEXT: { 316 - struct scene_obj_txt *txt = (struct scene_obj_txt *)obj; 336 + struct scene_txt_generic *gen = &((struct scene_obj_txt *)obj)->gen; 317 337 struct expo *exp = scn->expo; 318 338 struct vidconsole_bbox bbox; 319 339 const char *str; 320 340 int len, ret; 321 341 322 - str = expo_get_str(exp, txt->str_id); 342 + str = expo_get_str(exp, gen->str_id); 323 343 if (!str) 324 344 return log_msg_ret("str", -ENOENT); 325 345 len = strlen(str); ··· 331 351 return 16; 332 352 } 333 353 334 - ret = vidconsole_measure(scn->expo->cons, txt->font_name, 335 - txt->font_size, str, -1, &bbox, NULL); 354 + ret = vidconsole_measure(scn->expo->cons, gen->font_name, 355 + gen->font_size, str, -1, &bbox, NULL); 336 356 if (ret) 337 357 return log_msg_ret("mea", ret); 338 358 if (widthp) ··· 424 444 break; 425 445 } 426 446 case SCENEOBJT_TEXT: { 427 - struct scene_obj_txt *txt = (struct scene_obj_txt *)obj; 447 + struct scene_txt_generic *gen = 448 + &((struct scene_obj_txt *)obj)->gen; 428 449 const char *str; 429 450 430 451 if (!cons) 431 452 return -ENOTSUPP; 432 453 433 - if (txt->font_name || txt->font_size) { 454 + if (gen->font_name || gen->font_size) { 434 455 ret = vidconsole_select_font(cons, 435 - txt->font_name, 436 - txt->font_size); 456 + gen->font_name, 457 + gen->font_size); 437 458 } else { 438 459 ret = vidconsole_select_font(cons, NULL, 0); 439 460 } 440 461 if (ret && ret != -ENOSYS) 441 462 return log_msg_ret("font", ret); 442 - str = expo_get_str(exp, txt->str_id); 463 + str = expo_get_str(exp, gen->str_id); 443 464 if (str) { 444 465 struct video_priv *vid_priv; 445 466 struct vidconsole_colour old;
+6 -6
boot/scene_menu.c
··· 359 359 360 360 txt = scene_obj_find(scn, item->key_id, SCENEOBJT_TEXT); 361 361 if (txt) { 362 - str = expo_get_str(scn->expo, txt->str_id); 362 + str = expo_get_str(scn->expo, txt->gen.str_id); 363 363 if (str && *str == key) 364 364 return item; 365 365 } ··· 562 562 if (!txt) 563 563 return log_msg_ret("txt", -EINVAL); 564 564 565 - str = expo_get_str(exp, txt->str_id); 565 + str = expo_get_str(exp, txt->gen.str_id); 566 566 printf("%s\n\n", str); 567 567 } 568 568 ··· 570 570 return 0; 571 571 572 572 pointer = scene_obj_find(scn, menu->pointer_id, SCENEOBJT_TEXT); 573 - pstr = expo_get_str(scn->expo, pointer->str_id); 573 + pstr = expo_get_str(scn->expo, pointer->gen.str_id); 574 574 575 575 list_for_each_entry(item, &menu->item_head, sibling) { 576 576 struct scene_obj_txt *key = NULL, *label = NULL; ··· 579 579 580 580 key = scene_obj_find(scn, item->key_id, SCENEOBJT_TEXT); 581 581 if (key) 582 - kstr = expo_get_str(exp, key->str_id); 582 + kstr = expo_get_str(exp, key->gen.str_id); 583 583 584 584 label = scene_obj_find(scn, item->label_id, SCENEOBJT_TEXT); 585 585 if (label) 586 - lstr = expo_get_str(exp, label->str_id); 586 + lstr = expo_get_str(exp, label->gen.str_id); 587 587 588 588 desc = scene_obj_find(scn, item->desc_id, SCENEOBJT_TEXT); 589 589 if (desc) 590 - dstr = expo_get_str(exp, desc->str_id); 590 + dstr = expo_get_str(exp, desc->gen.str_id); 591 591 592 592 printf("%3s %3s %-10s %s\n", 593 593 pointer && menu->cur_item_id == item->id ? pstr : "",
+5 -5
boot/scene_textline.c
··· 71 71 if (!txt) 72 72 return log_msg_ret("dim", -ENOENT); 73 73 74 - ret = vidconsole_nominal(scn->expo->cons, txt->font_name, 75 - txt->font_size, tline->max_chars, &bbox); 74 + ret = vidconsole_nominal(scn->expo->cons, txt->gen.font_name, 75 + txt->gen.font_size, tline->max_chars, &bbox); 76 76 if (ret) 77 77 return log_msg_ret("nom", ret); 78 78 ··· 191 191 if (!txt) 192 192 return log_msg_ret("cur", -ENOENT); 193 193 194 - if (txt->font_name || txt->font_size) { 194 + if (txt->gen.font_name || txt->gen.font_size) { 195 195 ret = vidconsole_select_font(cons, 196 - txt->font_name, 197 - txt->font_size); 196 + txt->gen.font_name, 197 + txt->gen.font_size); 198 198 } else { 199 199 ret = vidconsole_select_font(cons, NULL, 0); 200 200 }
+15 -6
include/expo.h
··· 291 291 }; 292 292 293 293 /** 294 + * struct scene_txt_generic - Generic information common to text objects 295 + * 296 + * @str_id: ID of the text string to display 297 + * @font_name: Name of font (allocated by caller) 298 + * @font_size: Nominal size of font in pixels 299 + */ 300 + struct scene_txt_generic { 301 + uint str_id; 302 + const char *font_name; 303 + uint font_size; 304 + }; 305 + 306 + /** 294 307 * struct scene_obj_txt - information about a text object in a scene 295 308 * 296 309 * This is a single-line text object 297 310 * 298 311 * @obj: Basic object information 299 - * @str_id: ID of the text string to display 300 - * @font_name: Name of font (allocated by caller) 301 - * @font_size: Nominal size of font in pixels 312 + * @gen: Generic information common to all objects which show text 302 313 */ 303 314 struct scene_obj_txt { 304 315 struct scene_obj obj; 305 - uint str_id; 306 - const char *font_name; 307 - uint font_size; 316 + struct scene_txt_generic gen; 308 317 }; 309 318 310 319 /**
+1 -1
test/boot/bootflow.c
··· 858 858 txt = scene_obj_find(scn, id, SCENEOBJT_TEXT); 859 859 ut_assertnonnull(txt); 860 860 861 - ut_asserteq(font_size, txt->font_size); 861 + ut_asserteq(font_size, txt->gen.font_size); 862 862 863 863 return 0; 864 864 }
+1 -1
test/boot/cedit.c
··· 48 48 49 49 txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE); 50 50 ut_assertnonnull(txt); 51 - ut_asserteq_str("AC Power", expo_get_str(exp, txt->str_id)); 51 + ut_asserteq_str("AC Power", expo_get_str(exp, txt->gen.str_id)); 52 52 53 53 ut_asserteq(ID_AC_ON, menu->cur_item_id); 54 54
+8 -7
test/boot/expo.c
··· 280 280 281 281 strcpy(name, "font2"); 282 282 ut_assertok(scene_txt_set_font(scn, OBJ_TEXT, name, 42)); 283 - ut_asserteq_ptr(name, txt->font_name); 284 - ut_asserteq(42, txt->font_size); 283 + ut_asserteq_ptr(name, txt->gen.font_name); 284 + ut_asserteq(42, txt->gen.font_size); 285 285 286 286 ut_asserteq(-ENOENT, scene_txt_set_font(scn, OBJ_TEXT2, name, 42)); 287 287 ··· 296 296 node = ofnode_path("/bootstd/theme"); 297 297 ut_assert(ofnode_valid(node)); 298 298 ut_assertok(expo_apply_theme(exp, node)); 299 - ut_asserteq(30, txt->font_size); 299 + ut_asserteq(30, txt->gen.font_size); 300 300 301 301 expo_destroy(exp); 302 302 ··· 727 727 ut_assertnonnull(scn); 728 728 ut_asserteq_str("main", scn->name); 729 729 ut_asserteq(ID_SCENE1, scn->id); 730 - ut_asserteq(ID_DYNAMIC_START + 1, scn->title_id); 730 + ut_asserteq(ID_DYNAMIC_START, scn->title_id); 731 731 ut_asserteq(0, scn->highlight_id); 732 732 733 733 /* check the title */ ··· 739 739 ut_asserteq(scn->title_id, obj->id); 740 740 ut_asserteq(SCENEOBJT_TEXT, obj->type); 741 741 ut_asserteq(0, obj->flags); 742 - ut_asserteq_str("Test Configuration", expo_get_str(exp, txt->str_id)); 742 + ut_asserteq_str("Test Configuration", 743 + expo_get_str(exp, txt->gen.str_id)); 743 744 744 745 /* check the menu */ 745 746 menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_NONE); ··· 751 752 ut_asserteq(0, obj->flags); 752 753 753 754 txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE); 754 - ut_asserteq_str("CPU speed", expo_get_str(exp, txt->str_id)); 755 + ut_asserteq_str("CPU speed", expo_get_str(exp, txt->gen.str_id)); 755 756 756 757 ut_asserteq(0, menu->cur_item_id); 757 758 ut_asserteq(0, menu->pointer_id); ··· 768 769 ut_asserteq(0, item->value); 769 770 770 771 txt = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE); 771 - ut_asserteq_str("2 GHz", expo_get_str(exp, txt->str_id)); 772 + ut_asserteq_str("2 GHz", expo_get_str(exp, txt->gen.str_id)); 772 773 773 774 count = list_count_nodes(&menu->item_head); 774 775 ut_asserteq(3, count);