Merge branch 'next'
[pandora-u-boot.git] / boot / scene_internal.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Internal header file for scenes
4  *
5  * Copyright 2022 Google LLC
6  * Written by Simon Glass <sjg@chromium.org>
7  */
8
9 #ifndef __SCENE_INTERNAL_H
10 #define __SCENE_INTERNAL_H
11
12 typedef int (*expo_scene_obj_iterator)(struct scene_obj *obj, void *priv);
13
14 /**
15  * expo_lookup_scene_id() - Look up a scene ID
16  *
17  * @exp: Expo to use
18  * @id: scene ID to look up
19  * Returns: Scene for that ID, or NULL if none
20  */
21 struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
22
23 /**
24  * resolve_id() - Automatically allocate an ID if needed
25  *
26  * @exp: Expo to use
27  * @id: ID to use, or 0 to auto-allocate one
28  * Returns: Either @id, or the auto-allocated ID
29  */
30 uint resolve_id(struct expo *exp, uint id);
31
32 /**
33  * scene_obj_find() - Find an object in a scene
34  *
35  * Note that @type is used to restrict the search when the object type is known.
36  * If any type is acceptable, set @type to SCENEOBJT_NONE
37  *
38  * @scn: Scene to search
39  * @id: ID of object to find
40  * @type: Type of the object, or SCENEOBJT_NONE to match any type
41  * Returns: Object found, or NULL if not found
42  */
43 void *scene_obj_find(const struct scene *scn, uint id, enum scene_obj_t type);
44
45 /**
46  * scene_obj_find_by_name() - Find an object in a scene by name
47  *
48  * @scn: Scene to search
49  * @name: Name to search for
50  */
51 void *scene_obj_find_by_name(struct scene *scn, const char *name);
52
53 /**
54  * scene_obj_add() - Add a new object to a scene
55  *
56  * @scn: Scene to update
57  * @name: Name to use (this is allocated by this call)
58  * @id: ID to use for the new object (0 to allocate one)
59  * @type: Type of object to add
60  * @size: Size to allocate for the object, in bytes
61  * @objp: Returns a pointer to the new object (must not be NULL)
62  * Returns: ID number for the object (generally @id), or -ve on error
63  */
64 int scene_obj_add(struct scene *scn, const char *name, uint id,
65                   enum scene_obj_t type, uint size, struct scene_obj **objp);
66
67 /**
68  * scene_obj_flag_clrset() - Adjust object flags
69  *
70  * @scn: Scene to update
71  * @id: ID of object to update
72  * @clr: Bits to clear in the object's flags
73  * @set: Bits to set in the object's flags
74  * Returns 0 if OK, -ENOENT if the object was not found
75  */
76 int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set);
77
78 /**
79  * scene_calc_dims() - Calculate the dimensions of the scene objects
80  *
81  * Updates the width and height of all objects based on their contents
82  *
83  * @scn: Scene to update
84  * @do_menus: true to calculate only menus, false to calculate everything else
85  * Returns 0 if OK, -ENOTSUPP if there is no graphical console
86  */
87 int scene_calc_dims(struct scene *scn, bool do_menus);
88
89 /**
90  * scene_menu_arrange() - Set the position of things in the menu
91  *
92  * This updates any items associated with a menu to make sure they are
93  * positioned correctly relative to the menu. It also selects the first item
94  * if not already done
95  *
96  * @scn: Scene to update
97  * @menu: Menu to process
98  * Returns: 0 if OK, -ve on error
99  */
100 int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu);
101
102 /**
103  * scene_apply_theme() - Apply a theme to a scene
104  *
105  * @scn: Scene to update
106  * @theme: Theme to apply
107  * Returns: 0 if OK, -ve on error
108  */
109 int scene_apply_theme(struct scene *scn, struct expo_theme *theme);
110
111 /**
112  * scene_menu_send_key() - Send a key to a menu for processing
113  *
114  * @scn: Scene to use
115  * @menu: Menu to use
116  * @key: Key code to send (KEY_...)
117  * @event: Place to put any event which is generated by the key
118  * Returns: 0 if OK, -ENOTTY if there is no current menu item, other -ve on other
119  *      error
120  */
121 int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
122                         struct expo_action *event);
123
124 /**
125  * scene_menu_destroy() - Destroy a menu in a scene
126  *
127  * @scn: Scene to destroy
128  */
129 void scene_menu_destroy(struct scene_obj_menu *menu);
130
131 /**
132  * scene_menu_display() - Display a menu as text
133  *
134  * @menu: Menu to display
135  * Returns: 0 if OK, -ENOENT if @id is invalid
136  */
137 int scene_menu_display(struct scene_obj_menu *menu);
138
139 /**
140  * scene_destroy() - Destroy a scene and all its memory
141  *
142  * @scn: Scene to destroy
143  */
144 void scene_destroy(struct scene *scn);
145
146 /**
147  * scene_render() - Render a scene
148  *
149  * This is called from expo_render()
150  *
151  * @scn: Scene to render
152  * Returns: 0 if OK, -ve on error
153  */
154 int scene_render(struct scene *scn);
155
156 /**
157  * scene_send_key() - set a keypress to a scene
158  *
159  * @scn: Scene to receive the key
160  * @key: Key to send (KEYCODE_UP)
161  * @event: Returns resulting event from this keypress
162  * Returns: 0 if OK, -ve on error
163  */
164 int scene_send_key(struct scene *scn, int key, struct expo_action *event);
165
166 /**
167  * scene_menu_render() - Render the background behind a menu
168  *
169  * @menu: Menu to render
170  */
171 void scene_menu_render(struct scene_obj_menu *menu);
172
173 /**
174  * scene_render_deps() - Render an object and its dependencies
175  *
176  * @scn: Scene to render
177  * @id: Object ID to render (or 0 for none)
178  * Returns: 0 if OK, -ve on error
179  */
180 int scene_render_deps(struct scene *scn, uint id);
181
182 /**
183  * scene_menu_render_deps() - Render a menu and its dependencies
184  *
185  * Renders the menu and all of its attached objects
186  *
187  * @scn: Scene to render
188  * @menu: Menu render
189  * Returns: 0 if OK, -ve on error
190  */
191 int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu);
192
193 /**
194  * scene_menu_calc_dims() - Calculate the dimensions of a menu
195  *
196  * Updates the width and height of the menu based on its contents
197  *
198  * @menu: Menu to update
199  * Returns 0 if OK, -ENOTSUPP if there is no graphical console
200  */
201 int scene_menu_calc_dims(struct scene_obj_menu *menu);
202
203 /**
204  * scene_iter_objs() - Iterate through all scene objects
205  *
206  * @scn: Scene to process
207  * @iter: Iterator to call on each object
208  * @priv: Private data to pass to the iterator, in addition to the object
209  * Return: 0 if OK, -ve on error
210  */
211 int scene_iter_objs(struct scene *scn, expo_scene_obj_iterator iter,
212                     void *priv);
213
214 /**
215  * expo_iter_scene_objects() - Iterate through all scene objects
216  *
217  * @exp: Expo to process
218  * @iter: Iterator to call on each object
219  * @priv: Private data to pass to the iterator, in addition to the object
220  * Return: 0 if OK, -ve on error
221  */
222 int expo_iter_scene_objs(struct expo *exp, expo_scene_obj_iterator iter,
223                          void *priv);
224
225 /**
226  * scene_menuitem_find() - Find the menu item for an ID
227  *
228  * Looks up the menu to find the item with the given ID
229  *
230  * @menu: Menu to check
231  * @id: ID to look for
232  * Return: Menu item, or NULL if not found
233  */
234 struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu,
235                                           int id);
236
237 /**
238  * scene_menuitem_find_seq() - Find the menu item at a sequential position
239  *
240  * This numbers the items from 0 and returns the seq'th one
241  *
242  * @menu: Menu to check
243  * @seq: Sequence number to look for
244  * Return: menu item if found, else NULL
245  */
246 struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu,
247                                               uint seq);
248
249 #endif /* __SCENE_INTERNAL_H */