From patchwork Fri Oct 10 03:42:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 575 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760067830; bh=rtm7s39zJrKXS6ptSzfIU9xrhw3DWR+jKb4UyndakQU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ix2noS/6JOuXdlpSn4nR1EgqpDyDJQAWwHGPwV4N6xEEsGppFBVCLMFgM9olsi/S+ tE4pvs5l/CFMIo7R7xDbMs/YZRe6fmvURzu1ruGUE9k5Gk0M+IS0MaXwj/z3CcRR5s x8Kwq7P1kTbms5X9cHT6znUTbwu4rOrHkMANLP9Y2LgscTn8bIkVYIgPI7ae0nkBAm jrD3By40PxqbOj88c7Xec/nSjP3PMoDm+ko448vP9dvGxAxft6dRFFD8e0LNnMflcn lZRq0iMC5qQd0ad0QHnRooWyBKh9RCSPBKGZG+ugD9U2RlN0rwG9VVCh8PAbVc1kfm Bvrcc/T4aLGFQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5F7AE68080 for ; Thu, 9 Oct 2025 21:43:50 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id eNpKErrQw1zT for ; Thu, 9 Oct 2025 21:43:50 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760067830; bh=rtm7s39zJrKXS6ptSzfIU9xrhw3DWR+jKb4UyndakQU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ix2noS/6JOuXdlpSn4nR1EgqpDyDJQAWwHGPwV4N6xEEsGppFBVCLMFgM9olsi/S+ tE4pvs5l/CFMIo7R7xDbMs/YZRe6fmvURzu1ruGUE9k5Gk0M+IS0MaXwj/z3CcRR5s x8Kwq7P1kTbms5X9cHT6znUTbwu4rOrHkMANLP9Y2LgscTn8bIkVYIgPI7ae0nkBAm jrD3By40PxqbOj88c7Xec/nSjP3PMoDm+ko448vP9dvGxAxft6dRFFD8e0LNnMflcn lZRq0iMC5qQd0ad0QHnRooWyBKh9RCSPBKGZG+ugD9U2RlN0rwG9VVCh8PAbVc1kfm Bvrcc/T4aLGFQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 48B4667FF2 for ; Thu, 9 Oct 2025 21:43:50 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760067827; bh=exAyhmuT77zx7uw6jWlhAP7wfOnc7NfPU4d0AbwxsHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dkX/L10MvohL5FuQ3hdFgllqnweSsVdAk/vLHC4wnE+cjcNQZeJ0P45SFisCH9Acd zBBV44jSniQrdNyjFG0zNpnd37o2DbRwYd1yeds2gPzRCK6pi5ZsOjyomgIahfRnkR Wwl/SAOMX1sb93bgxXU+k7XKpe+dlXJAJuIL2wrFahBi4FmzIFJTrdzDM85NlAwAUR +fx5ceOaaFxmo5h87JhHo0s/nxVQ3QcIimFEOsaz6qLrED2v+/LK4iQc8qFw6CZS31 CxNeHSzf6OPBERZnteqKZTI4870JbDpe34nNN6cR3PAgQvmjmJIHoWuBmwivmXgMoT A83m1Epc9XbGw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 242A167FE9; Thu, 9 Oct 2025 21:43:47 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id OSqvy_cc8DML; Thu, 9 Oct 2025 21:43:47 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760067821; bh=3O2wK4D9tS+Q7Zm/5oBTatJtOyjv3XrXTsW1tjJMMi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MdWosxM4yQH56TVH9whcG+jrpQHm2eCq3X1p/2XVhSRxDU/KJemTiEdOiKl9Hs8hO GPc6vh8AA2Dwi9w/xTkDhSypCk3FIkvF4vMjcI28fP8yqkMjkT9NpTIrOu89ewnWbN KZOj7Z0Vx2mra/hk03OYJ+Gf5GpAW3BT7J1zxDKxMd7kAUZ3GwDWjiv9OUXEGLjtxJ 9sKmn3R1OCzs0CsBrO2qRa2wvs/g0tMvy2YQVpPkJAzVyvXf3ScpKUHHhJHPU+omNe SR1wRH8BDphh1R9X++VBEQ/E4Nlyy8RYZlk5xzsdTsTUPHSD0r5Ip8hOpUQMXSXy7d qUIdb4zHqkO5w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 863EB67FF2; Thu, 9 Oct 2025 21:43:41 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 9 Oct 2025 21:42:37 -0600 Message-ID: <20251010034255.1099728-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251010034255.1099728-1-sjg@u-boot.org> References: <20251010034255.1099728-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5IONADZBESZ5QPIOP7XP52LJCQ2R6IMS X-Message-ID-Hash: 5IONADZBESZ5QPIOP7XP52LJCQ2R6IMS X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 09/18] expo: Export scene_find_obj_within() and add a test List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass It is easier to test this function directly than via click_check(). Set up a test expo with an extra overlapping object and add some tests. Update the existing render test to take account of the new object. Co-developed-by: Claude Signed-off-by: Simon Glass --- boot/scene.c | 11 +------ boot/scene_internal.h | 10 ++++++ test/boot/expo.c | 71 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 72 insertions(+), 20 deletions(-) diff --git a/boot/scene.c b/boot/scene.c index c1ecbfcc67a..a9e0d1f1266 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -1193,16 +1193,7 @@ bool scene_obj_within(const struct scene *scn, struct scene_obj *obj, int x, return within; } -/** - * scene_find_obj_within() - Find an object that is within the coords - * - * @scn: Scene to check - * @x: X coordinates of the click - * @y: Y coordinate of the click - * Return: object that is being clicked on, NULL if none - */ -static struct scene_obj *scene_find_obj_within(const struct scene *scn, int x, - int y) +struct scene_obj *scene_find_obj_within(const struct scene *scn, int x, int y) { struct scene_obj *obj; diff --git a/boot/scene_internal.h b/boot/scene_internal.h index 9bf2cb8f8f2..8e61067d4b4 100644 --- a/boot/scene_internal.h +++ b/boot/scene_internal.h @@ -556,4 +556,14 @@ const char *scene_flag_name(uint flag); */ const char *scene_obj_type_name(enum scene_obj_t type); +/** + * scene_find_obj_within() - Find an object that is within the coords + * + * @scn: Scene to check + * @x: X coordinates of the click + * @y: Y coordinate of the click + * Return: object that is being clicked on, NULL if none + */ +struct scene_obj *scene_find_obj_within(const struct scene *scn, int x, int y); + #endif /* __SCENE_INTERNAL_H */ diff --git a/test/boot/expo.c b/test/boot/expo.c index e8716b86991..db4a54e7cd7 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -34,6 +34,7 @@ enum { OBJ_BOX, OBJ_BOX2, OBJ_TEXTED, + OBJ_OVERLAP, /* strings */ STR_SCENE_TITLE, @@ -55,6 +56,8 @@ enum { STR_ITEM2_KEY, STR_ITEM2_PREVIEW, + STR_OVERLAP, + /* menu items */ ITEM1, ITEM1_LABEL, @@ -599,6 +602,14 @@ static int create_test_expo(struct unit_test_state *uts, struct expo **expp, abuf_printf(text, "This\nis the initial contents of the text editor " "but it is quite likely that more will be added later"); + /* + * Add an extra text object that overlaps with OBJ_TEXT to test reverse + * search order. OBJ_TEXT is at (400, 100), so let's add one nearby + */ + ut_assert(scene_txt_str(scn, "overlap", OBJ_OVERLAP, STR_OVERLAP, + "overlap text", NULL) > 0); + ut_assertok(scene_obj_set_pos(scn, OBJ_OVERLAP, 405, 105)); + *expp = exp; *scnp = scn; *menup = menu; @@ -720,17 +731,17 @@ static int expo_render_image(struct unit_test_state *uts) /* render it */ expo_set_scene_id(exp, SCENE1); ut_assertok(expo_render(exp)); - ut_asserteq(18782, video_compress_fb(uts, dev, false)); + ut_asserteq(19065, video_compress_fb(uts, dev, false)); ut_asserteq(0, scn->highlight_id); ut_assertok(scene_arrange(scn)); ut_asserteq(0, scn->highlight_id); ut_assertok(expo_render(exp)); - ut_asserteq(20373, video_compress_fb(uts, dev, false)); + ut_asserteq(20707, video_compress_fb(uts, dev, false)); ut_assertok(scene_arrange(scn)); ut_assertok(expo_render(exp)); - ut_asserteq(20373, video_compress_fb(uts, dev, false)); + ut_asserteq(20707, video_compress_fb(uts, dev, false)); scene_set_highlight_id(scn, OBJ_MENU); ut_asserteq(OBJ_MENU, scn->highlight_id); @@ -742,7 +753,7 @@ static int expo_render_image(struct unit_test_state *uts) ut_assert(!(obj->flags & SCENEOF_HIDE)); ut_assertok(expo_render(exp)); - ut_asserteq(20373, video_compress_fb(uts, dev, false)); + ut_asserteq(20707, video_compress_fb(uts, dev, false)); /* move down */ ut_assertok(expo_send_key(exp, BKEY_DOWN)); @@ -755,7 +766,7 @@ static int expo_render_image(struct unit_test_state *uts) ut_asserteq(ITEM2, scene_menu_get_cur_item(scn, OBJ_MENU)); ut_assertok(scene_arrange(scn)); ut_assertok(expo_render(exp)); - ut_asserteq(19649, video_compress_fb(uts, dev, false)); + ut_asserteq(19953, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); /* hide the text editor since the following tests don't need it */ @@ -764,18 +775,18 @@ static int expo_render_image(struct unit_test_state *uts) /* do some alignment checks */ ut_assertok(scene_obj_set_halign(scn, OBJ_TEXT3, SCENEOA_CENTRE)); ut_assertok(expo_render(exp)); - ut_asserteq(16323, video_compress_fb(uts, dev, false)); + ut_asserteq(16626, video_compress_fb(uts, dev, false)); ut_assertok(scene_obj_set_halign(scn, OBJ_TEXT3, SCENEOA_RIGHT)); ut_assertok(expo_render(exp)); - ut_asserteq(16240, video_compress_fb(uts, dev, false)); + ut_asserteq(16634, video_compress_fb(uts, dev, false)); ut_assertok(scene_obj_set_halign(scn, OBJ_TEXT3, SCENEOA_LEFT)); ut_assertok(scene_obj_set_valign(scn, OBJ_TEXT3, SCENEOA_CENTRE)); ut_assertok(expo_render(exp)); - ut_asserteq(18714, video_compress_fb(uts, dev, false)); + ut_asserteq(19056, video_compress_fb(uts, dev, false)); ut_assertok(scene_obj_set_valign(scn, OBJ_TEXT3, SCENEOA_BOTTOM)); ut_assertok(expo_render(exp)); - ut_asserteq(18670, video_compress_fb(uts, dev, false)); + ut_asserteq(19024, video_compress_fb(uts, dev, false)); /* make sure only the preview for the second item is shown */ obj = scene_obj_find(scn, ITEM1_PREVIEW, SCENEOBJT_NONE); @@ -801,7 +812,7 @@ static int expo_render_image(struct unit_test_state *uts) exp->show_highlight = true; ut_assertok(scene_arrange(scn)); ut_assertok(expo_render(exp)); - ut_asserteq(18830, video_compress_fb(uts, dev, false)); + ut_asserteq(19181, video_compress_fb(uts, dev, false)); /* now try in text mode */ expo_set_text_mode(exp, true); @@ -1260,6 +1271,46 @@ static int expo_scene_obj_type_name(struct unit_test_state *uts) } BOOTSTD_TEST(expo_scene_obj_type_name, 0); +/* Test scene_find_obj_within() */ +static int expo_find_obj_within(struct unit_test_state *uts) +{ + struct scene_obj_menu *menu; + struct abuf buf, logo_copy; + struct scene_obj *obj; + struct scene *scn; + struct expo *exp; + + ut_assertok(create_test_expo(uts, &exp, &scn, &menu, &buf, &logo_copy)); + + /* Arrange the scene so objects have proper bounding boxes */ + ut_assertok(scene_arrange(scn)); + + /* + * Check finding a menu by 'clicking' on a menu item label - menu items + * are at (50,436) for ITEM1 and (50,454) for ITEM2 + */ + obj = scene_find_obj_within(scn, 60, 440); + ut_assertnonnull(obj); + ut_asserteq(OBJ_MENU, obj->id); + + /* logo and text are not highlightable, so they should not be found */ + ut_assertnull(scene_find_obj_within(scn, 60, 30)); + ut_assertnull(scene_find_obj_within(scn, 410, 110)); + + /* empty space */ + ut_assertnull(scene_find_obj_within(scn, 10, 10)); + + /* way outside bounds */ + ut_assertnull(scene_find_obj_within(scn, 9999, 9999)); + + abuf_uninit(&buf); + abuf_uninit(&logo_copy); + expo_destroy(exp); + + return 0; +} +BOOTSTD_TEST(expo_find_obj_within, UTF_DM | UTF_SCAN_FDT); + /* Test expo_dump() */ static int expo_dump_test(struct unit_test_state *uts) {