Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC7A3C433FE for ; Mon, 17 Oct 2022 20:35:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1259D84F98; Mon, 17 Oct 2022 22:31:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="X/mHovBc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 302C084F42; Mon, 17 Oct 2022 22:31:24 +0200 (CEST) Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 841DC84F69 for ; Mon, 17 Oct 2022 22:30:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2a.google.com with SMTP id o65so10121189iof.4 for ; Mon, 17 Oct 2022 13:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WePuI35jl0jf+j44WKqgJMF42Gmm7RFQ7ANzapfyH2M=; b=X/mHovBcNYG8mu0Vg+WSMf1RZdOIcqoW5uhnRahrYkoDE/AvWk6Wp3apX4nf3ZAYmX gpAUbVQ5Eh3j1CbaW4RfikYu1BOSPbuUGEFez54ApDENVEQMvgTenZR35ZT7o6Eu+ZMU 6+eYk1g0nZcpJbI6RF8uEo5QWoPDerbMsGo20= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WePuI35jl0jf+j44WKqgJMF42Gmm7RFQ7ANzapfyH2M=; b=Qv4K1OmiTDj4rJ237RvwxV9YOmVM/lN+Ciput6rkSpIcgiPzYKYGOCjgxw1Lw6dRU4 LcDSNO76+IqRHOyb0QjB/zLxWkeaX2JZ94gJg2919AvPCJGhnWbyKgLPeKnII2Cqy6uQ zC/Aillk+N1ko/8dXzm0vx2MGRRGFeMZhuDPYWlwPcVZ/tfXe16l5XbzfjNYzW4Uyt3e FzDyc2SYC2YJmlUUeQjTlU5IB7GvBu9nBSKpJFpKBrov0e0mFrMnIGQkkWAtUDzjuue3 NMyT6P98KmmDQYA2JVSWNj8hJUzkijzf+0cHlCvq48oO5lyq7YvHaD+BCAwtpIcSbwCU Xe4Q== X-Gm-Message-State: ACrzQf3+ihXueHFJhHSmk/JPGExWZanM+12uORXj8uER+ntvlcUl+XrQ YL2bweuHI+dCFW8hjc2QEYjFuU4Qr5tVVA== X-Google-Smtp-Source: AMsMyM7O5SUHjQB+0mRA5PPoUU5JmBepjVr2ZNBoDjFtxdEfYoEFUWwVKHavH6QokAA7s9WAV7lm6w== X-Received: by 2002:a05:6602:2b92:b0:6a8:bdb5:a5d5 with SMTP id r18-20020a0566022b9200b006a8bdb5a5d5mr5317117iov.85.1666038633296; Mon, 17 Oct 2022 13:30:33 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:91e:7804:2764:d161]) by smtp.gmail.com with ESMTPSA id j9-20020a926e09000000b002e939413e83sm258071ilc.48.2022.10.17.13.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 13:30:32 -0700 (PDT) From: Simon Glass To: u-boot@lists.denx.de Cc: Anatolij Gustschin , Tom Rini , Simon Glass , Artem Lapkin , John Keeping Subject: [PATCH 19/24] expo: Add support for scene menus Date: Mon, 17 Oct 2022 14:29:55 -0600 Message-Id: <20221017203000.2207887-20-sjg@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221017203000.2207887-1-sjg@chromium.org> References: <20221017203000.2207887-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean A menu is a key part of the expo design. It consists of a number of items which the user can select from. Add the initial implementation of this. Signed-off-by: Simon Glass --- boot/Makefile | 2 + boot/scene_menu.c | 372 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 374 insertions(+) create mode 100644 boot/scene_menu.c diff --git a/boot/Makefile b/boot/Makefile index f0c31549213..0b30fcd64a9 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -47,6 +47,8 @@ ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o endif +obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += expo.o scene.o scene_menu.o + obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o vbe_request.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o diff --git a/boot/scene_menu.c b/boot/scene_menu.c new file mode 100644 index 00000000000..609295567c5 --- /dev/null +++ b/boot/scene_menu.c @@ -0,0 +1,372 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Implementation of a menu in a scene + * + * Copyright 2022 Google LLC + * Written by Simon Glass + */ + +#define LOG_CATEGORY LOGC_BOOT + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "scene_internal.h" + +static void scene_menuitem_destroy(struct scene_menuitem *item) +{ + free(item->name); + free(item); +} + +void scene_menu_destroy(struct scene_obj_menu *menu) +{ + struct scene_menuitem *item, *next; + + list_for_each_entry_safe(item, next, &menu->item_head, sibling) + scene_menuitem_destroy(item); +} + +/** + * menu_point_to_item() - Point to a particular menu item + * + * Sets the currently pointed-to / highlighted menu item + */ +static void menu_point_to_item(struct scene_obj_menu *menu, uint item_id) +{ + menu->cur_item_id = item_id; +} + +int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu) +{ + struct scene_menuitem *item; + int y, cur_y; + int ret; + + y = menu->obj.y; + if (menu->title_id) { + ret = scene_obj_set_pos(scn, menu->title_id, menu->obj.x, y); + if (ret < 0) + return log_msg_ret("tit", ret); + + ret = scene_obj_get_hw(scn, menu->title_id, NULL); + if (ret < 0) + return log_msg_ret("hei", ret); + + y += ret * 2; + } + + /* + * Currently everything is hard-coded to particular columns so this + * won't work on small displays and looks strange if the font size is + * small. This can be updated once text measuring is supported in + * vidconsole + */ + cur_y = -1; + list_for_each_entry(item, &menu->item_head, sibling) { + int height; + + ret = scene_obj_get_hw(scn, item->desc_id, NULL); + if (ret < 0) + return log_msg_ret("get", ret); + height = ret; + + if (item->flags & SCENEMIF_GAP_BEFORE) + y += height; + + /* select an item if not done already */ + if (!menu->cur_item_id) + menu_point_to_item(menu, item->id); + + /* + * Put the label on the left, then leave a space for the + * pointer, then the key and the description + */ + if (item->label_id) { + ret = scene_obj_set_pos(scn, item->label_id, menu->obj.x, + y); + if (ret < 0) + return log_msg_ret("nam", ret); + } + + ret = scene_obj_set_pos(scn, item->key_id, menu->obj.x + 230, + y); + if (ret < 0) + return log_msg_ret("key", ret); + + ret = scene_obj_set_pos(scn, item->desc_id, menu->obj.x + 280, + y); + if (ret < 0) + return log_msg_ret("des", ret); + + if (menu->cur_item_id == item->id) + cur_y = y; + + if (item->preview_id) { + bool hide; + + /* + * put all previews on top of each other, on the right + * size of the display + */ + ret = scene_obj_set_pos(scn, item->preview_id, -4, y); + if (ret < 0) + return log_msg_ret("prev", ret); + + hide = menu->cur_item_id != item->id; + ret = scene_obj_set_hide(scn, item->preview_id, hide); + if (ret < 0) + return log_msg_ret("hid", ret); + } + + y += height; + } + + if (menu->pointer_id && cur_y != -1) { + /* + * put the pointer to the right of and level with the item it + * points to + */ + ret = scene_obj_set_pos(scn, menu->pointer_id, + menu->obj.x + 200, cur_y); + if (ret < 0) + return log_msg_ret("ptr", ret); + } + + return 0; +} + +int scene_menu_add(struct scene *scn, const char *name, uint id, + struct scene_obj_menu **menup) +{ + struct scene_obj_menu *menu; + int ret; + + ret = scene_obj_add(scn, name, id, SCENEOBJT_MENU, + sizeof(struct scene_obj_menu), + (struct scene_obj **)&menu); + if (ret < 0) + return log_msg_ret("obj", -ENOMEM); + + if (menup) + *menup = menu; + INIT_LIST_HEAD(&menu->item_head); + + ret = scene_menu_arrange(scn, menu); + if (ret) + return log_msg_ret("pos", ret); + + return menu->obj.id; +} + +static struct scene_menuitem *scene_menu_find_key(struct scene *scn, + struct scene_obj_menu *menu, + int key) +{ + struct scene_menuitem *item; + + list_for_each_entry(item, &menu->item_head, sibling) { + if (item->key_id) { + struct scene_obj_txt *txt; + + txt = scene_obj_find(scn, item->key_id, SCENEOBJT_TEXT); + if (txt && txt->str && *txt->str == key) + return item; + } + } + + return NULL; +} + +int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key, + struct expo_action *event) +{ + struct scene_menuitem *item, *cur, *key_item; + + cur = NULL; + key_item = NULL; + + if (!list_empty(&menu->item_head)) { + list_for_each_entry(item, &menu->item_head, sibling) { + /* select an item if not done already */ + if (menu->cur_item_id == item->id) { + cur = item; + break; + } + } + } + + if (!cur) + return -ENOTTY; + + switch (key) { + case BKEY_UP: + if (item != list_first_entry(&menu->item_head, + struct scene_menuitem, sibling)) { + item = list_entry(item->sibling.prev, + struct scene_menuitem, sibling); + event->type = EXPOACT_POINT; + event->select.id = item->id; + log_debug("up to item %d\n", event->select.id); + } + break; + case BKEY_DOWN: + if (!list_is_last(&item->sibling, &menu->item_head)) { + item = list_entry(item->sibling.next, + struct scene_menuitem, sibling); + event->type = EXPOACT_POINT; + event->select.id = item->id; + log_debug("down to item %d\n", event->select.id); + } + break; + case BKEY_SELECT: + event->type = EXPOACT_SELECT; + event->select.id = item->id; + log_debug("select item %d\n", event->select.id); + break; + case BKEY_QUIT: + event->type = EXPOACT_QUIT; + log_debug("quit\n"); + break; + case '0'...'9': + key_item = scene_menu_find_key(scn, menu, key); + if (key_item) { + event->type = EXPOACT_SELECT; + event->select.id = key_item->id; + } + break; + } + + menu_point_to_item(menu, item->id); + + return 0; +} + +int scene_menuitem_add(struct scene *scn, uint menu_id, const char *name, + uint id, uint key_id, uint label_id, uint desc_id, + uint preview_id, uint flags, + struct scene_menuitem **itemp) +{ + struct scene_obj_menu *menu; + struct scene_menuitem *item; + int ret; + + menu = scene_obj_find(scn, menu_id, SCENEOBJT_MENU); + if (!menu) + return log_msg_ret("find", -ENOENT); + + /* Check that the text ID is valid */ + if (!scene_obj_find(scn, desc_id, SCENEOBJT_TEXT)) + return log_msg_ret("txt", -EINVAL); + + item = calloc(1, sizeof(struct scene_obj_menu)); + if (!item) + return log_msg_ret("item", -ENOMEM); + item->name = strdup(name); + if (!item->name) { + free(item); + return log_msg_ret("name", -ENOMEM); + } + + item->id = resolve_id(scn->expo, id); + item->key_id = key_id; + item->label_id = label_id; + item->desc_id = desc_id; + item->preview_id = preview_id; + item->flags = flags; + list_add_tail(&item->sibling, &menu->item_head); + + ret = scene_menu_arrange(scn, menu); + if (ret) + return log_msg_ret("pos", ret); + + if (itemp) + *itemp = item; + + return item->id; +} + +int scene_menu_set_title(struct scene *scn, uint id, uint title_id) +{ + struct scene_obj_menu *menu; + struct scene_obj_txt *txt; + + menu = scene_obj_find(scn, id, SCENEOBJT_MENU); + if (!menu) + return log_msg_ret("menu", -ENOENT); + + /* Check that the ID is valid */ + if (title_id) { + txt = scene_obj_find(scn, title_id, SCENEOBJT_TEXT); + if (!txt) + return log_msg_ret("txt", -EINVAL); + } + + menu->title_id = title_id; + + return 0; +} + +int scene_menu_set_pointer(struct scene *scn, uint id, uint pointer_id) +{ + struct scene_obj_menu *menu; + struct scene_obj *obj; + + menu = scene_obj_find(scn, id, SCENEOBJT_MENU); + if (!menu) + return log_msg_ret("menu", -ENOENT); + + /* Check that the ID is valid */ + if (pointer_id) { + obj = scene_obj_find(scn, pointer_id, SCENEOBJT_NONE); + if (!obj) + return log_msg_ret("obj", -EINVAL); + } + + menu->pointer_id = pointer_id; + + return 0; +} + +int scene_menu_display(struct scene_obj_menu *menu) +{ + struct scene *scn = menu->obj.scene; + struct scene_obj_txt *pointer; + struct scene_menuitem *item; + + printf("U-Boot : Boot Menu\n\n"); + if (menu->title_id) { + struct scene_obj_txt *txt; + + txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_TEXT); + if (!txt) + return log_msg_ret("txt", -EINVAL); + + printf("%s\n\n", txt->str); + } + + if (list_empty(&menu->item_head)) + return 0; + + pointer = scene_obj_find(scn, menu->pointer_id, SCENEOBJT_TEXT); + + list_for_each_entry(item, &menu->item_head, sibling) { + struct scene_obj_txt *key = NULL, *label = NULL; + struct scene_obj_txt *desc = NULL; + + key = scene_obj_find(scn, item->key_id, SCENEOBJT_TEXT); + label = scene_obj_find(scn, item->label_id, SCENEOBJT_TEXT); + desc = scene_obj_find(scn, item->desc_id, SCENEOBJT_TEXT); + printf("%3s %3s %-10s %s\n", + pointer && menu->cur_item_id == item->id ? pointer->str : + "", key->str, label->str, desc->str); + } + + return -ENOTSUPP; +} -- 2.38.0.413.g74048e4d9e-goog