Rename the existing expo_apply_theme() to expo_setup_theme() and adjust
the former so that it applies a theme which has already been read into
the struct. This will make it easier for tests to check theme
adjustments, since they won't have to put them in a node.

Add the white-on-black property into the theme struct while we are.

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

 boot/bootflow_menu.c |  2 +-
 boot/expo.c          | 33 +++++++++++++++++++++++----------
 cmd/cedit.c          |  2 +-
 include/expo.h       | 18 ++++++++++++++++--
 test/boot/bootflow.c |  2 +-
 test/boot/expo.c     |  2 +-
 6 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/boot/bootflow_menu.c b/boot/bootflow_menu.c
index 934165d2855..a0437177364 100644
--- a/boot/bootflow_menu.c
+++ b/boot/bootflow_menu.c
@@ -261,7 +261,7 @@ int bootflow_menu_start(struct bootstd_priv *std, bool 
text_mode,
                return log_msg_ret("bma", ret);
 
        if (ofnode_valid(std->theme)) {
-               ret = expo_apply_theme(exp, std->theme);
+               ret = expo_setup_theme(exp, std->theme);
                if (ret)
                        return log_msg_ret("thm", ret);
        }
diff --git a/boot/expo.c b/boot/expo.c
index 64d3febacdb..a218ea0e4e9 100644
--- a/boot/expo.c
+++ b/boot/expo.c
@@ -281,11 +281,28 @@ int expo_action_get(struct expo *exp, struct expo_action 
*act)
        return act->type == EXPOACT_NONE ? -EAGAIN : 0;
 }
 
-int expo_apply_theme(struct expo *exp, ofnode node)
+int expo_apply_theme(struct expo *exp)
 {
+       struct expo_theme *theme = &exp->theme;
        struct scene *scn;
+
+       if (exp->display)
+               video_set_white_on_black(exp->display, theme->white_on_black);
+
+       list_for_each_entry(scn, &exp->scene_head, sibling) {
+               int ret;
+
+               ret = scene_apply_theme(scn, theme);
+               if (ret)
+                       return log_msg_ret("asn", ret);
+       }
+
+       return 0;
+}
+
+int expo_setup_theme(struct expo *exp, ofnode node)
+{
        struct expo_theme *theme = &exp->theme;
-       bool white_on_black;
        int ret;
 
        log_debug("Applying theme %s\n", ofnode_get_name(node));
@@ -296,15 +313,11 @@ int expo_apply_theme(struct expo *exp, ofnode node)
        ofnode_read_u32(node, "menuitem-gap-y", &theme->menuitem_gap_y);
        ofnode_read_u32(node, "menu-title-margin-x",
                        &theme->menu_title_margin_x);
-       white_on_black = ofnode_read_bool(node, "white-on-black");
-       if (exp->display)
-               video_set_white_on_black(exp->display, white_on_black);
+       theme->white_on_black = ofnode_read_bool(node, "white-on-black");
 
-       list_for_each_entry(scn, &exp->scene_head, sibling) {
-               ret = scene_apply_theme(scn, theme);
-               if (ret)
-                       return log_msg_ret("app", ret);
-       }
+       ret = expo_apply_theme(exp);
+       if (ret)
+               return log_msg_ret("asn", ret);
 
        return 0;
 }
diff --git a/cmd/cedit.c b/cmd/cedit.c
index 2e15b063462..9c492d45171 100644
--- a/cmd/cedit.c
+++ b/cmd/cedit.c
@@ -274,7 +274,7 @@ static int do_cedit_run(struct cmd_tbl *cmdtp, int flag, 
int argc,
 
        node = ofnode_path("/bootstd/cedit-theme");
        if (ofnode_valid(node)) {
-               ret = expo_apply_theme(cur_exp, node);
+               ret = expo_setup_theme(cur_exp, node);
                if (ret)
                        return CMD_RET_FAILURE;
        } else {
diff --git a/include/expo.h b/include/expo.h
index 75ff1df3cfc..0b25a9d8b41 100644
--- a/include/expo.h
+++ b/include/expo.h
@@ -83,12 +83,15 @@ struct expo_action {
  * @menuitem_gap_y: Gap between menu items in pixels
  * @menu_title_margin_x: Gap between right side of menu title and left size of
  *     menu label
+ * @white_on_black: True to use white-on-black for the expo, false for
+ *     black-on-white
  */
 struct expo_theme {
        u32 font_size;
        u32 menu_inset;
        u32 menuitem_gap_y;
        u32 menu_title_margin_x;
+       bool white_on_black;
 };
 
 /**
@@ -994,12 +997,23 @@ int expo_send_key(struct expo *exp, int key);
 int expo_action_get(struct expo *exp, struct expo_action *act);
 
 /**
- * expo_apply_theme() - Apply a theme to an expo
+ * expo_setup_theme() - Read a theme from a node and apply it to an expo
  *
  * @exp: Expo to update
  * @node: Node containing the theme
+ * Returns: 0 if OK, -ve on error
+ */
+int expo_setup_theme(struct expo *exp, ofnode node);
+
+/**
+ * expo_apply_theme() - Apply an expo's theme
+ *
+ * The theme to be applied must be set up exp->theme
+ *
+ * @exp: Expo to update
+ * Returns: 0 if OK, -ve on error
  */
-int expo_apply_theme(struct expo *exp, ofnode node);
+int expo_apply_theme(struct expo *exp);
 
 /**
  * expo_build() - Build an expo from an FDT description
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 670e73c265b..0dd8fa71261 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -884,7 +884,7 @@ static int bootflow_menu_theme(struct unit_test_state *uts)
        ut_assertok(bootflow_menu_add_all(exp));
        node = ofnode_path("/bootstd/theme");
        ut_assert(ofnode_valid(node));
-       ut_assertok(expo_apply_theme(exp, node));
+       ut_assertok(expo_setup_theme(exp, node));
 
        scn = expo_lookup_scene_id(exp, MAIN);
        ut_assertnonnull(scn);
diff --git a/test/boot/expo.c b/test/boot/expo.c
index 64b6c154b15..824ef023c1c 100644
--- a/test/boot/expo.c
+++ b/test/boot/expo.c
@@ -302,7 +302,7 @@ static int expo_object_attr(struct unit_test_state *uts)
 
        node = ofnode_path("/bootstd/theme");
        ut_assert(ofnode_valid(node));
-       ut_assertok(expo_apply_theme(exp, node));
+       ut_assertok(expo_setup_theme(exp, node));
        ut_asserteq(30, txt->gen.font_size);
 
        expo_destroy(exp);
-- 
2.43.0

Reply via email to