Files
MeowOS-For-R3P2/patch_v2/sdk/test_p1p2p3_repro.c
T
MeowOS 1d2496b38c refactor(hello): 视图框架批次② — hello.c 拆分为 app.c+ui/{home,full,demo}.c+ui/common/chrome.c+logic/{notify,state}.c(定案B: demo视图态留ui/;定案b: page导航包装activity栈);test_p1p2p3_repro 改多文件链接形态 (agent-177)
hello f45ba051→c06b3b4f; mipsel -Wall -Wextra 0 warning; 宿主 P1c/P2/P3+widgets 全 PASS
出入(诚实): view on_draw/on_event 路径暂未启用(注册表直绘已覆盖, on_draw 双画风险), 留批③实测; home/full 仍手绘未迁注册表
2026-08-31 03:31:09 +08:00

155 lines
9.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* test_p1p2p3_repro.c — 宿主复现并校验 P1/P2/P3 三个真机问题的修复(离屏 480x720,16bpp)。
*
* 方法:直接驱动拆分后 hello 的 demo 真实函数(demo_paint / demo_rebuild_to / demo_touch_down)
* 与 demo 视图态(extern,见 ../hello_app/hello_internal.h),对 back_buf 做像素断言。
* 这样测的是「真实 demo 代码 + 真实 SDK」,不是模拟桩。不依赖 /dev/fb0 / 字库 / launcher。
*
* 批次② 变化:hello.c 已拆为 app.c + ui/{home,full,demo}.c + ui/common/chrome.c +
* logic/{notify,state}.c;本文件不再 #include hello.c,改为 extern 驱动 demo 层并链接多文件。
*
* 覆盖:
* P1 z-order 叠层:圆形进度条(实时重绘)与 FAB 浮层重叠时,局部重绘不再清掉/盖住 FAB。
* (批次① 后为 P1c:set_z(g_fab,999)+invalidate(r_prc),显式 z 不依赖绘制先后。)
* P2 list 焦点:命中非 list 区域时释放列表焦点、切页滚动(不再沿用旧焦点继续滚列表)。
* P3 list 脏区:W_LIST 绘制已裁剪到视口;滚动(非整行偏移)+选中行不再向标题间隙/底缘下泄漏。
*
* 编译(宿主 gcc,链真实 gfx/sys/theme/vol/log/widget/input/activity/dialog/ime/img/config/
* notify/ipc + 打桩 font/global(test_host_stub) + stb_image + hello 拆分层):
* 1) 单独编译 app.c 并把 main 改名 hello_app_main(否则与本文件 main 冲突):
* gcc -c -Wall -Wextra -DMEOW_UI_HOST_TEST -Dmain=hello_app_main \
* -I. -I../hello_app ../hello_app/app.c -o app.o
* 2) 编译本文件 + 其余 hello 模块 + SDK 源 + 打桩,链接 app.o:
* gcc -Wall -Wextra -DMEOW_UI_HOST_TEST -o test_p1p2p3_repro test_p1p2p3_repro.c app.o \
* test_host_stub.c meow_ui_gfx.c meow_ui_sys.c meow_ui_theme.c meow_ui_vol.c meow_ui_log.c \
* meow_ui_widget.c meow_ui_input.c meow_ui_activity.c meow_ui_dialog.c meow_ui_ime.c \
* meow_ui_img.c meow_ui_config.c meow_ui_notify.c meow_notify_ipc.c meow_ui_draw.c \
* meow_ui_view.c stb_image.c \
* ../hello_app/ui/home.c ../hello_app/ui/full.c ../hello_app/ui/demo.c \
* ../hello_app/ui/common/chrome.c ../hello_app/logic/notify.c ../hello_app/logic/state.c \
* -I. -I../hello_app -I../meow_launcherd -pthread -lm
* 运行:MEOW_UI_DUMP=/tmp/repro.ppm ./test_p1p2p3_repro (optional,dump 最终屏幕)
*
* 预期 RESULT: ALL PASS(P1c/P2/P3 断言真实有效,未弱化)。
*/
#include "meow_ui.h"
#include "meow_ui_internal.h"
#include "../hello_app/hello_internal.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* ---- 像素读取 ---- */
static void rd_px(int x, int y, int *r, int *g, int *b)
{
unsigned char *bb = meow_ui_back_buf();
int line = meow_ui_back_buf_pitch(), bpp = meow_ui_back_buf_bpp();
if (!bb) { *r=*g=*b=0; return; }
if (bpp == 16) {
uint16_t px = *(uint16_t *)(bb + (size_t)y * line + (size_t)x * 2);
*r = (((px >> 11) & 0x1F) << 3) | ((px >> 11) & 0x1F) >> 2;
*g = (((px >> 5) & 0x3F) << 2) | ((px >> 5) & 0x3F) >> 4;
*b = ((px & 0x1F) << 3) | ((px & 0x1F) >> 2);
} else {
uint32_t px = *(uint32_t *)(bb + (size_t)y * line + (size_t)x * 4);
*r = (px >> 16) & 0xFF; *g = (px >> 8) & 0xFF; *b = px & 0xFF;
}
}
static int near(int a, int b) { int d = a - b; if (d < 0) d = -d; return d <= 12; }
static int is_bg(int r, int g, int b)
{
const meow_theme *th = meow_theme_get();
int br = (th->bg >> 16) & 0xFF, bg = (th->bg >> 8) & 0xFF, bb = th->bg & 0xFF;
return near(r, br) && near(g, bg) && near(b, bb);
}
static void pr_px(const char *tag, int x, int y)
{
int r, g, b; rd_px(x, y, &r, &g, &b);
printf(" %-26s px(%d,%d)=%02X%02X%02X %s\n", tag, x, y, r, g, b, is_bg(r, g, b) ? "[bg]" : "[ink]");
}
int main(void)
{
setenv("MEOW_UI_DUMP", "/tmp/repro.ppm", 1);
meow_ui_opts o = { 480, 720 };
if (meow_ui_init(&o) != 0) { printf("init failed\n"); return 1; }
meow_ui_activity_push(ACT_DEMO); /* demo 控件 owner=ACT_DEMO,命中/绘制对齐 */
demo_init(); /* 建造 chrome + 内容(scroll=0),owner=ACT_DEMO */
int fails = 0;
/* ================= P1 / P1c:局部重绘不盖浮层(FAB,须显式置顶) =================
* 场景:scroll=0 时圆形进度 r_prc(413..453,605..645) 与 FAB(406..462,616..672) 重叠。
* demo_paint 整帧后 FAB 在上(demo_init set_z(g_fab,999) 显式置顶)。随后「局部重绘进度条」:
* 旧(清底+只画进度条+flush 其矩形)→ FAB 重叠区被清掉;
* 新(SDK meow_ui_invalidate:清底 + 按 z 重画重叠区完整 z 栈)→ FAB 保持。
* P1c:set_z(g_fab,999) 后 invalidate(r_prc),断言 FAB 重叠点(434,622) 仍=demo_paint 后值
* (显式 z 不依赖绘制先后——置顶在重绘前显式给出,下层重绘不抹上层)。 */
demo_paint();
int fx = r_fab.x + 28, fy = r_fab.y + 6; /* FAB 内、远离 "+" 文本处 → (434,622) */
int s0r, s0g, s0b; rd_px(fx, fy, &s0r, &s0g, &s0b);
printf("P1 scene (demo_paint) FAB-overlap "); pr_px("scene", fx, fy);
if (is_bg(s0r, s0g, s0b))
printf(" [warn] expected FAB ink at scene, got bg — geometry assumptions off\n");
/* 旧式局部重绘:清底+只画进度条(复现根因) */
{
const meow_theme *th = meow_theme_get();
meow_progress_set(g_dprc, 30);
meow_ui_fill_rect(r_prc.x, r_prc.y, r_prc.w, r_prc.h, th->bg);
meow_widget_draw(g_dprc);
meow_ui_flush_region(r_prc.x, r_prc.y, r_prc.w, r_prc.h);
}
int obr, obg, obb; rd_px(fx, fy, &obr, &obg, &obb);
printf("P1 old-partial (clear+single draw) "); pr_px("old", fx, fy);
if (is_bg(obr, obg, obb)) printf(" [BUG-CONFIRMED] old path erased FAB overlap (bg)\n");
else printf(" [note] old path did NOT erase FAB here (color %02X%02X%02X)\n", obr, obg, obb);
/* P1c:显式置顶 + SDK 局部重画(invalidate 按 z 重画重叠栈) */
demo_paint(); /* 还原场景 */
meow_widget_set_z(g_fab, 999); /* 重新显式置顶(P1c 要求) */
meow_progress_set(g_dprc, 30);
meow_ui_invalidate(r_prc.x, r_prc.y, r_prc.w, r_prc.h);
int nbr, nbg, nbb; rd_px(fx, fy, &nbr, &nbg, &nbb);
printf("P1c set_z(999)+invalidate(r_prc) "); pr_px("p1c", fx, fy);
if (near(s0r, nbr) && near(s0g, nbg) && near(s0b, nbb))
printf(" P1-PASS explicit z:FAB preserved over live progress redraw\n");
else { printf(" P1-FAIL FAB not preserved (scene %02X%02X%02X vs p1c %02X%02X%02X)\n",
s0r, s0g, s0b, nbr, nbg, nbb); fails++; }
/* ================= P2:列表焦点按本次触摸绑定/释放 =================
* demo_touch_down 命中非 list 区域时应释放列表焦点 → 页滚动,而不是继续滚列表。 */
g_demo_focus = 1; /* 模拟此前点过列表(焦点留存) */
g_demo = 1; /* demo 页已进入(demo_touch_down 前置闸门) */
demo_touch_down(240, 300); /* 非 list 非 slider 的内容区 */
printf("P2 touch_down(240,300) with focus=1 -> drag_list=%d drag_page=%d focus=%d\n",
g_drag_list, g_drag_page, g_demo_focus);
if (g_drag_list == 0 && g_drag_page == 1 && g_demo_focus == 0)
printf(" P2-PASS non-list touch releases focus, drags page\n");
else { printf(" P2-FAIL (expected drag_page=1 focus=0; got drag_list=%d drag_page=%d focus=%d)\n",
g_drag_list, g_drag_page, g_demo_focus); fails++; }
/* ================= P3:列表滚动 W_LIST 视口外泄漏 =================
* 把页面 scroll 拉到底,列表上屏;再把列表 scroll 设非整行倍数 + 选中一个跨底/跨顶行,
* 观察视口外(标题间隙/底缘下)是否漏出选中行填充(标脏泄漏 = 标题栏/底部卡脏区)。 */
demo_rebuild_to(100000); /* clamp 到 max,列表上屏 */
printf("P3 list rect = (%d,%d,%d,%d)\n", r_list.x, r_list.y, r_list.w, r_list.h);
/* 顶部泄漏:选中行0 + scroll=20 → 行0 ry=top-20,填充越顶泄漏 */
meow_list_set_selected(g_dlc, 0); meow_list_set_scroll(g_dlc, 20);
meow_ui_invalidate(r_list.x, r_list.y, r_list.w, r_list.h);
int ux = r_list.x + 10, uy = r_list.y - 5; /* 列表顶上方 5px(标题间隙) */
int ur, ug, ub; rd_px(ux, uy, &ur, &ug, &ub);
printf("P3 top-leak "); pr_px("above-top", ux, uy);
if (is_bg(ur, ug, ub)) printf(" P3-top-PASS no leak into title gap\n");
else { printf(" P3-top-FAIL leaked into title gap\n"); fails++; }
/* 底部泄漏:选中行4 + scroll=20 → 行4 ry=590..630 越底泄漏 */
meow_list_set_selected(g_dlc, 4); meow_list_set_scroll(g_dlc, 20);
meow_ui_invalidate(r_list.x, r_list.y, r_list.w, r_list.h);
int dx = r_list.x + 10, dy_ = r_list.y + r_list.h + 5; /* 列表底下方 5px */
int dr, dg, db; rd_px(dx, dy_, &dr, &dg, &db);
printf("P3 bot-leak "); pr_px("below-bottom", dx, dy_);
if (is_bg(dr, dg, db)) printf(" P3-bottom-PASS no leak below list\n");
else { printf(" P3-bottom-FAIL leaked below list\n"); fails++; }
printf(fails ? "\nRESULT: %d FAIL(S)\n" : "\nRESULT: ALL PASS\n", fails);
return fails;
}