1 // SPDX-License-Identifier: GPL-2.0+
3 * Implementation of a expo, a collection of scenes providing menu options
5 * Copyright 2022 Google LLC
9 #define LOG_CATEGORY LOGC_EXPO
15 #include "scene_internal.h"
17 int expo_new(const char *name, void *priv, struct expo **expp)
21 exp = calloc(1, sizeof(struct expo));
23 return log_msg_ret("expo", -ENOMEM);
24 exp->name = strdup(name);
27 return log_msg_ret("name", -ENOMEM);
30 INIT_LIST_HEAD(&exp->scene_head);
31 INIT_LIST_HEAD(&exp->str_head);
38 static void estr_destroy(struct expo_string *estr)
43 void expo_destroy(struct expo *exp)
45 struct scene *scn, *next;
46 struct expo_string *estr, *enext;
48 list_for_each_entry_safe(scn, next, &exp->scene_head, sibling)
51 list_for_each_entry_safe(estr, enext, &exp->str_head, sibling)
58 uint resolve_id(struct expo *exp, uint id)
60 log_debug("resolve id %d\n", id);
63 else if (id >= exp->next_id)
64 exp->next_id = id + 1;
69 void expo_set_dynamic_start(struct expo *exp, uint dyn_start)
71 exp->next_id = dyn_start;
74 int expo_str(struct expo *exp, const char *name, uint id, const char *str)
76 struct expo_string *estr;
78 estr = calloc(1, sizeof(struct expo_string));
80 return log_msg_ret("obj", -ENOMEM);
82 estr->id = resolve_id(exp, id);
84 list_add_tail(&estr->sibling, &exp->str_head);
89 const char *expo_get_str(struct expo *exp, uint id)
91 struct expo_string *estr;
93 list_for_each_entry(estr, &exp->str_head, sibling) {
101 int expo_set_display(struct expo *exp, struct udevice *dev)
103 struct udevice *cons;
106 ret = device_find_first_child_by_uclass(dev, UCLASS_VIDEO_CONSOLE,
109 return log_msg_ret("con", ret);
117 int expo_calc_dims(struct expo *exp)
123 return log_msg_ret("dim", -ENOTSUPP);
125 list_for_each_entry(scn, &exp->scene_head, sibling) {
127 * Do the menus last so that all the menus' text objects
130 ret = scene_calc_dims(scn, false);
132 return log_msg_ret("scn", ret);
133 ret = scene_calc_dims(scn, true);
135 return log_msg_ret("scn", ret);
141 void expo_set_text_mode(struct expo *exp, bool text_mode)
143 exp->text_mode = text_mode;
146 struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id)
150 list_for_each_entry(scn, &exp->scene_head, sibling) {
151 if (scn->id == scene_id)
158 int expo_set_scene_id(struct expo *exp, uint scene_id)
163 scn = expo_lookup_scene_id(exp, scene_id);
165 return log_msg_ret("id", -ENOENT);
166 ret = scene_arrange(scn);
168 return log_msg_ret("arr", ret);
170 exp->scene_id = scene_id;
175 int expo_first_scene_id(struct expo *exp)
179 if (list_empty(&exp->scene_head))
182 scn = list_first_entry(&exp->scene_head, struct scene, sibling);
187 int expo_render(struct expo *exp)
189 struct udevice *dev = exp->display;
190 struct video_priv *vid_priv = dev_get_uclass_priv(dev);
191 struct scene *scn = NULL;
192 enum colour_idx back;
196 back = CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK) ? VID_BLACK : VID_WHITE;
197 colour = video_index_to_colour(vid_priv, back);
198 ret = video_fill(dev, colour);
200 return log_msg_ret("fill", ret);
203 scn = expo_lookup_scene_id(exp, exp->scene_id);
205 return log_msg_ret("scn", -ENOENT);
207 ret = scene_render(scn);
209 return log_msg_ret("ren", ret);
212 video_sync(dev, true);
214 return scn ? 0 : -ECHILD;
217 int expo_send_key(struct expo *exp, int key)
219 struct scene *scn = NULL;
224 scn = expo_lookup_scene_id(exp, exp->scene_id);
226 return log_msg_ret("scn", -ENOENT);
228 ret = scene_send_key(scn, key, &exp->action);
230 return log_msg_ret("key", ret);
232 /* arrange it to get any changes */
233 ret = scene_arrange(scn);
235 return log_msg_ret("arr", ret);
238 return scn ? 0 : -ECHILD;
241 int expo_action_get(struct expo *exp, struct expo_action *act)
244 exp->action.type = EXPOACT_NONE;
246 return act->type == EXPOACT_NONE ? -EAGAIN : 0;
249 int expo_apply_theme(struct expo *exp, ofnode node)
252 struct expo_theme *theme = &exp->theme;
255 log_debug("Applying theme %s\n", ofnode_get_name(node));
257 memset(theme, '\0', sizeof(struct expo_theme));
258 ofnode_read_u32(node, "font-size", &theme->font_size);
259 ofnode_read_u32(node, "menu-inset", &theme->menu_inset);
260 ofnode_read_u32(node, "menuitem-gap-y", &theme->menuitem_gap_y);
262 list_for_each_entry(scn, &exp->scene_head, sibling) {
263 ret = scene_apply_theme(scn, theme);
265 return log_msg_ret("app", ret);
271 int expo_iter_scene_objs(struct expo *exp, expo_scene_obj_iterator iter,
277 list_for_each_entry(scn, &exp->scene_head, sibling) {
278 ret = scene_iter_objs(scn, iter, priv);
280 return log_msg_ret("wr", ret);