mirror of
https://github.com/cottongin/cardputerzero-sync.git
synced 2026-11-20 14:44:47 -06:00
fix(device-ui): harden fbdev blit, evdev loop, LVGL lifecycle, and feedback toasts
This commit is contained in:
@@ -81,6 +81,9 @@ if(CP0_UI_BUILD_APP)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CP0_UI_TARGET_DEVICE)
|
if(CP0_UI_TARGET_DEVICE)
|
||||||
|
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
|
message(FATAL_ERROR "CP0_UI_TARGET_DEVICE=ON requires Linux (fbdev/evdev); got CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")
|
||||||
|
endif()
|
||||||
target_compile_definitions(cp0-sync-ui PRIVATE CP0_UI_TARGET_DEVICE=1)
|
target_compile_definitions(cp0-sync-ui PRIVATE CP0_UI_TARGET_DEVICE=1)
|
||||||
message(STATUS "Target backend: Linux fbdev + evdev")
|
message(STATUS "Target backend: Linux fbdev + evdev")
|
||||||
else()
|
else()
|
||||||
|
|||||||
@@ -713,11 +713,39 @@ struct LvglAppView::Impl {
|
|||||||
|
|
||||||
#if defined(CP0_HAS_LVGL)
|
#if defined(CP0_HAS_LVGL)
|
||||||
lv_obj_t* screen = nullptr;
|
lv_obj_t* screen = nullptr;
|
||||||
lv_style_t style_bg;
|
lv_style_t style_bg{};
|
||||||
lv_style_t style_card;
|
lv_style_t style_card{};
|
||||||
bool lvgl_styles_inited = false;
|
bool lvgl_styles_inited = false;
|
||||||
|
|
||||||
|
void sync_lvgl_styles() {
|
||||||
|
if (!lv_is_initialized()) {
|
||||||
|
lv_init();
|
||||||
|
}
|
||||||
|
if (!lvgl_styles_inited) {
|
||||||
|
lv_style_init(&style_bg);
|
||||||
|
lv_style_init(&style_card);
|
||||||
|
lvgl_styles_inited = true;
|
||||||
|
}
|
||||||
|
lv_style_set_bg_color(&style_bg, lv_color_hex(pal.background));
|
||||||
|
lv_style_set_bg_color(&style_card, lv_color_hex(pal.card));
|
||||||
|
lv_style_set_border_color(&style_card, lv_color_hex(pal.border));
|
||||||
|
if (screen != nullptr) {
|
||||||
|
lv_obj_report_style_change(&style_bg);
|
||||||
|
lv_obj_report_style_change(&style_card);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
~Impl() {
|
||||||
|
#if defined(CP0_HAS_LVGL)
|
||||||
|
if (lvgl_styles_inited) {
|
||||||
|
lv_style_reset(&style_bg);
|
||||||
|
lv_style_reset(&style_card);
|
||||||
|
lvgl_styles_inited = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void render_top_bar(const UiState& state) {
|
void render_top_bar(const UiState& state) {
|
||||||
// Segmented TabsList pill container (radius 5px, padding 2px)
|
// Segmented TabsList pill container (radius 5px, padding 2px)
|
||||||
const char* tab_labels[3] = {"1 Status", "2 Folders", "3 Logs"};
|
const char* tab_labels[3] = {"1 Status", "2 Folders", "3 Logs"};
|
||||||
@@ -887,15 +915,15 @@ struct LvglAppView::Impl {
|
|||||||
|
|
||||||
std::string footer_msg;
|
std::string footer_msg;
|
||||||
uint32_t footer_color = pal.muted_foreground;
|
uint32_t footer_color = pal.muted_foreground;
|
||||||
if (!state.feedback_banner.empty()) {
|
if (state.status.syncing && !state.status.current_file.empty()) {
|
||||||
footer_msg = state.feedback_banner;
|
|
||||||
footer_color = pal.status_online;
|
|
||||||
} else if (state.status.syncing && !state.status.current_file.empty()) {
|
|
||||||
footer_msg = "File: " + state.status.current_file;
|
footer_msg = "File: " + state.status.current_file;
|
||||||
footer_color = pal.foreground;
|
footer_color = pal.foreground;
|
||||||
} else if (!state.status.last_error.empty() && state.status.last_error != "none") {
|
} else if (!state.status.last_error.empty() && state.status.last_error != "none") {
|
||||||
footer_msg = "Err: " + state.status.last_error;
|
footer_msg = "Err: " + state.status.last_error;
|
||||||
footer_color = pal.status_error;
|
footer_color = pal.status_error;
|
||||||
|
} else if (!state.status.ok && !state.status.error.empty()) {
|
||||||
|
footer_msg = state.status.error;
|
||||||
|
footer_color = pal.status_error;
|
||||||
} else if (!state.status.last_synced_file.empty()) {
|
} else if (!state.status.last_synced_file.empty()) {
|
||||||
footer_msg = "Last sync: " + state.status.last_synced_file;
|
footer_msg = "Last sync: " + state.status.last_synced_file;
|
||||||
} else {
|
} else {
|
||||||
@@ -1279,6 +1307,18 @@ struct LvglAppView::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void render_feedback_toast(const UiState& state) {
|
||||||
|
if (state.modal != ModalKind::None || state.feedback_banner.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t bg = state.feedback_is_error ? pal.status_error_bg : pal.status_online_bg;
|
||||||
|
uint32_t fg = state.feedback_is_error ? pal.status_error : pal.status_online;
|
||||||
|
canvas.draw_round_box(6, 129, 308, 19, 5, bg, fg, 1);
|
||||||
|
canvas.draw_circle(15.0f, 138.5f, 2.5f, fg, false);
|
||||||
|
std::string fit = canvas.truncate_right(FontRole::Mono, 9, state.feedback_banner, 282);
|
||||||
|
canvas.draw_text(FontRole::Mono, 9, 23, 134, fit, fg);
|
||||||
|
}
|
||||||
|
|
||||||
void render(const UiState& state) {
|
void render(const UiState& state) {
|
||||||
if (state.theme != theme) {
|
if (state.theme != theme) {
|
||||||
theme = state.theme;
|
theme = state.theme;
|
||||||
@@ -1299,22 +1339,12 @@ struct LvglAppView::Impl {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render_feedback_toast(state);
|
||||||
render_modal(state);
|
render_modal(state);
|
||||||
render_footer(state);
|
render_footer(state);
|
||||||
|
|
||||||
#if defined(CP0_HAS_LVGL)
|
#if defined(CP0_HAS_LVGL)
|
||||||
if (!lvgl_styles_inited) {
|
sync_lvgl_styles();
|
||||||
lv_style_init(&style_bg);
|
|
||||||
lv_style_init(&style_card);
|
|
||||||
lvgl_styles_inited = true;
|
|
||||||
}
|
|
||||||
lv_style_set_bg_color(&style_bg, lv_color_hex(pal.background));
|
|
||||||
lv_style_set_bg_color(&style_card, lv_color_hex(pal.card));
|
|
||||||
lv_style_set_border_color(&style_card, lv_color_hex(pal.border));
|
|
||||||
if (screen != nullptr) {
|
|
||||||
lv_obj_report_style_change(&style_bg);
|
|
||||||
lv_obj_report_style_change(&style_card);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1325,6 +1355,9 @@ LvglAppView::~LvglAppView() = default;
|
|||||||
void LvglAppView::apply_theme(ThemeMode mode) {
|
void LvglAppView::apply_theme(ThemeMode mode) {
|
||||||
impl_->theme = mode;
|
impl_->theme = mode;
|
||||||
impl_->pal = get_palette(mode);
|
impl_->pal = get_palette(mode);
|
||||||
|
#if defined(CP0_HAS_LVGL)
|
||||||
|
impl_->sync_lvgl_styles();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void LvglAppView::render(const UiState& state) {
|
void LvglAppView::render(const UiState& state) {
|
||||||
|
|||||||
145
device-ui/src/fb_blit.hpp
Normal file
145
device-ui/src/fb_blit.hpp
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
namespace cp0 {
|
||||||
|
|
||||||
|
struct FbChannel {
|
||||||
|
uint32_t offset = 0;
|
||||||
|
uint32_t length = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FbBlitSpec {
|
||||||
|
uint32_t xres = 0;
|
||||||
|
uint32_t yres = 0;
|
||||||
|
uint32_t xoffset = 0;
|
||||||
|
uint32_t yoffset = 0;
|
||||||
|
uint32_t bits_per_pixel = 0;
|
||||||
|
uint32_t line_length = 0;
|
||||||
|
FbChannel red;
|
||||||
|
FbChannel green;
|
||||||
|
FbChannel blue;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline uint32_t pack_fb_channel(uint32_t val8, const FbChannel& ch) {
|
||||||
|
uint32_t scaled = (ch.length >= 8)
|
||||||
|
? (val8 << (ch.length - 8))
|
||||||
|
: (val8 >> (8 - ch.length));
|
||||||
|
uint32_t mask = (ch.length >= 32) ? 0xffffffffU : ((1U << ch.length) - 1U);
|
||||||
|
return (scaled & mask) << ch.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool blit_framebuffer(
|
||||||
|
uint8_t* fb_mem,
|
||||||
|
size_t map_size,
|
||||||
|
const FbBlitSpec& spec,
|
||||||
|
const uint32_t* pixels,
|
||||||
|
int src_w,
|
||||||
|
int src_h
|
||||||
|
) {
|
||||||
|
if (fb_mem == nullptr || pixels == nullptr || map_size == 0 || src_w <= 0 || src_h <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (spec.bits_per_pixel != 16 && spec.bits_per_pixel != 24 && spec.bits_per_pixel != 32) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto valid_channel = [&](const FbChannel& ch) {
|
||||||
|
return ch.length > 0 && ch.length <= 16 &&
|
||||||
|
ch.offset < spec.bits_per_pixel &&
|
||||||
|
ch.offset + ch.length <= spec.bits_per_pixel;
|
||||||
|
};
|
||||||
|
if (!valid_channel(spec.red) || !valid_channel(spec.green) || !valid_channel(spec.blue)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t copy_w = std::min(static_cast<size_t>(spec.xres), static_cast<size_t>(src_w));
|
||||||
|
size_t copy_h = std::min(static_cast<size_t>(spec.yres), static_cast<size_t>(src_h));
|
||||||
|
if (copy_w == 0 || copy_h == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t bytes_per_pixel = static_cast<size_t>(spec.bits_per_pixel) / 8U;
|
||||||
|
size_t stride = static_cast<size_t>(spec.line_length);
|
||||||
|
if (copy_w > std::numeric_limits<size_t>::max() / bytes_per_pixel) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
size_t row_bytes = copy_w * bytes_per_pixel;
|
||||||
|
if (stride < row_bytes) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (static_cast<size_t>(spec.xoffset) > std::numeric_limits<size_t>::max() / bytes_per_pixel) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
size_t x_byte_offset = static_cast<size_t>(spec.xoffset) * bytes_per_pixel;
|
||||||
|
if (x_byte_offset > stride - row_bytes) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fast_argb32 =
|
||||||
|
(spec.bits_per_pixel == 32 &&
|
||||||
|
spec.red.offset == 16 && spec.red.length == 8 &&
|
||||||
|
spec.green.offset == 8 && spec.green.length == 8 &&
|
||||||
|
spec.blue.offset == 0 && spec.blue.length == 8);
|
||||||
|
|
||||||
|
for (size_t y = 0; y < copy_h; ++y) {
|
||||||
|
size_t y_row = static_cast<size_t>(spec.yoffset) + y;
|
||||||
|
if (y_row < static_cast<size_t>(spec.yoffset)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (y_row > std::numeric_limits<size_t>::max() / stride) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
size_t row_base = y_row * stride;
|
||||||
|
if (row_base > map_size || x_byte_offset > map_size - row_base) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
size_t row_offset = row_base + x_byte_offset;
|
||||||
|
if (row_bytes > map_size - row_offset) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t* row = fb_mem + row_offset;
|
||||||
|
const uint32_t* src = pixels + y * static_cast<size_t>(src_w);
|
||||||
|
|
||||||
|
if (fast_argb32) {
|
||||||
|
std::memcpy(row, src, row_bytes);
|
||||||
|
} else if (spec.bits_per_pixel == 32) {
|
||||||
|
for (size_t x = 0; x < copy_w; ++x) {
|
||||||
|
uint32_t c = src[x];
|
||||||
|
uint32_t packed =
|
||||||
|
pack_fb_channel((c >> 16) & 0xffU, spec.red) |
|
||||||
|
pack_fb_channel((c >> 8) & 0xffU, spec.green) |
|
||||||
|
pack_fb_channel(c & 0xffU, spec.blue);
|
||||||
|
std::memcpy(row + x * 4U, &packed, 4U);
|
||||||
|
}
|
||||||
|
} else if (spec.bits_per_pixel == 24) {
|
||||||
|
for (size_t x = 0; x < copy_w; ++x) {
|
||||||
|
uint32_t c = src[x];
|
||||||
|
uint32_t packed =
|
||||||
|
pack_fb_channel((c >> 16) & 0xffU, spec.red) |
|
||||||
|
pack_fb_channel((c >> 8) & 0xffU, spec.green) |
|
||||||
|
pack_fb_channel(c & 0xffU, spec.blue);
|
||||||
|
row[x * 3U + 0U] = static_cast<uint8_t>(packed & 0xffU);
|
||||||
|
row[x * 3U + 1U] = static_cast<uint8_t>((packed >> 8) & 0xffU);
|
||||||
|
row[x * 3U + 2U] = static_cast<uint8_t>((packed >> 16) & 0xffU);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (size_t x = 0; x < copy_w; ++x) {
|
||||||
|
uint32_t c = src[x];
|
||||||
|
uint16_t packed = static_cast<uint16_t>(
|
||||||
|
pack_fb_channel((c >> 16) & 0xffU, spec.red) |
|
||||||
|
pack_fb_channel((c >> 8) & 0xffU, spec.green) |
|
||||||
|
pack_fb_channel(c & 0xffU, spec.blue)
|
||||||
|
);
|
||||||
|
std::memcpy(row + x * 2U, &packed, 2U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace cp0
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
#include "app_ui.hpp"
|
#include "app_ui.hpp"
|
||||||
|
#include "fb_blit.hpp"
|
||||||
#include "ipc_client.hpp"
|
#include "ipc_client.hpp"
|
||||||
#include "ui_controller.hpp"
|
#include "ui_controller.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cerrno>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -101,8 +106,8 @@ bool dispatch_action(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto set_timed_feedback = [&](const std::string& msg) {
|
auto set_timed_feedback = [&](const std::string& msg, bool is_error) {
|
||||||
ctrl.set_feedback(msg);
|
ctrl.set_feedback(msg, is_error);
|
||||||
feedback_until = std::chrono::steady_clock::now() + std::chrono::seconds(3);
|
feedback_until = std::chrono::steady_clock::now() + std::chrono::seconds(3);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,25 +117,38 @@ bool dispatch_action(
|
|||||||
return true;
|
return true;
|
||||||
case ActionType::SyncNow: {
|
case ActionType::SyncNow: {
|
||||||
auto res = ipc.sync_now();
|
auto res = ipc.sync_now();
|
||||||
set_timed_feedback(res.ok ? "Sync triggered" : res.error);
|
set_timed_feedback(
|
||||||
|
res.ok ? "Sync triggered" : (res.error.empty() ? "Sync failed" : res.error),
|
||||||
|
!res.ok
|
||||||
|
);
|
||||||
ctrl.update_status(ipc.fetch_status());
|
ctrl.update_status(ipc.fetch_status());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ActionType::AddFolder: {
|
case ActionType::AddFolder: {
|
||||||
auto res = ipc.add_folder(action.folder_path, action.folder_label);
|
auto res = ipc.add_folder(action.folder_path, action.folder_label);
|
||||||
set_timed_feedback(res.ok ? "Folder added" : res.error);
|
set_timed_feedback(
|
||||||
|
res.ok ? "Folder added" : (res.error.empty() ? "Add folder failed" : res.error),
|
||||||
|
!res.ok
|
||||||
|
);
|
||||||
ctrl.update_status(ipc.fetch_status());
|
ctrl.update_status(ipc.fetch_status());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ActionType::RemoveFolder: {
|
case ActionType::RemoveFolder: {
|
||||||
auto res = ipc.remove_folder(action.folder_id);
|
auto res = ipc.remove_folder(action.folder_id);
|
||||||
set_timed_feedback(res.ok ? "Folder removed" : res.error);
|
set_timed_feedback(
|
||||||
|
res.ok ? "Folder removed" : (res.error.empty() ? "Remove folder failed" : res.error),
|
||||||
|
!res.ok
|
||||||
|
);
|
||||||
ctrl.update_status(ipc.fetch_status());
|
ctrl.update_status(ipc.fetch_status());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ActionType::SetTarget: {
|
case ActionType::SetTarget: {
|
||||||
auto res = ipc.set_target(action.target_host, action.target_port);
|
auto res = ipc.set_target(action.target_host, action.target_port);
|
||||||
set_timed_feedback(res.ok ? ("Target: " + action.target_host) : res.error);
|
set_timed_feedback(
|
||||||
|
res.ok ? ("Target: " + action.target_host)
|
||||||
|
: (res.error.empty() ? "Set target failed" : res.error),
|
||||||
|
!res.ok
|
||||||
|
);
|
||||||
ctrl.update_status(ipc.fetch_status());
|
ctrl.update_status(ipc.fetch_status());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -141,7 +159,10 @@ bool dispatch_action(
|
|||||||
}
|
}
|
||||||
case ActionType::RetryFailed: {
|
case ActionType::RetryFailed: {
|
||||||
auto res = ipc.retry_failed();
|
auto res = ipc.retry_failed();
|
||||||
set_timed_feedback(res.ok ? "Retrying failed files" : res.error);
|
set_timed_feedback(
|
||||||
|
res.ok ? "Retrying failed files" : (res.error.empty() ? "Retry failed" : res.error),
|
||||||
|
!res.ok
|
||||||
|
);
|
||||||
ctrl.update_status(ipc.fetch_status());
|
ctrl.update_status(ipc.fetch_status());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -201,40 +222,36 @@ char map_evdev_code(uint16_t code, bool shift) {
|
|||||||
case KEY_DOT: return shift ? '>' : '.';
|
case KEY_DOT: return shift ? '>' : '.';
|
||||||
case KEY_SLASH: return shift ? '?' : '/';
|
case KEY_SLASH: return shift ? '?' : '/';
|
||||||
case KEY_BACKSLASH: return shift ? '|' : '\\';
|
case KEY_BACKSLASH: return shift ? '|' : '\\';
|
||||||
|
case KEY_GRAVE: return shift ? '~' : '`';
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void blit_fbdev(
|
void blit_fbdev(
|
||||||
uint8_t* fb_mem,
|
uint8_t* fb_mem,
|
||||||
|
size_t map_size,
|
||||||
const fb_var_screeninfo& vinfo,
|
const fb_var_screeninfo& vinfo,
|
||||||
const fb_fix_screeninfo& finfo,
|
const fb_fix_screeninfo& finfo,
|
||||||
const uint32_t* pixels
|
const uint32_t* pixels
|
||||||
) {
|
) {
|
||||||
int fb_w = static_cast<int>(vinfo.xres);
|
cp0::FbBlitSpec spec;
|
||||||
int fb_h = static_cast<int>(vinfo.yres);
|
spec.xres = vinfo.xres;
|
||||||
int copy_w = std::min(fb_w, cp0::LvglAppView::kWidth);
|
spec.yres = vinfo.yres;
|
||||||
int copy_h = std::min(fb_h, cp0::LvglAppView::kHeight);
|
spec.xoffset = vinfo.xoffset;
|
||||||
int bpp = static_cast<int>(vinfo.bits_per_pixel);
|
spec.yoffset = vinfo.yoffset;
|
||||||
int stride = static_cast<int>(finfo.line_length);
|
spec.bits_per_pixel = vinfo.bits_per_pixel;
|
||||||
|
spec.line_length = finfo.line_length;
|
||||||
for (int y = 0; y < copy_h; ++y) {
|
spec.red = {vinfo.red.offset, vinfo.red.length};
|
||||||
uint8_t* row = fb_mem + (y + static_cast<int>(vinfo.yoffset)) * stride +
|
spec.green = {vinfo.green.offset, vinfo.green.length};
|
||||||
static_cast<int>(vinfo.xoffset) * (bpp / 8);
|
spec.blue = {vinfo.blue.offset, vinfo.blue.length};
|
||||||
const uint32_t* src = pixels + y * cp0::LvglAppView::kWidth;
|
cp0::blit_framebuffer(
|
||||||
if (bpp == 32) {
|
fb_mem,
|
||||||
std::memcpy(row, src, static_cast<size_t>(copy_w) * 4);
|
map_size,
|
||||||
} else if (bpp == 16) {
|
spec,
|
||||||
auto* dst16 = reinterpret_cast<uint16_t*>(row);
|
pixels,
|
||||||
for (int x = 0; x < copy_w; ++x) {
|
cp0::LvglAppView::kWidth,
|
||||||
uint32_t c = src[x];
|
cp0::LvglAppView::kHeight
|
||||||
uint16_t r = static_cast<uint16_t>((c >> 19) & 0x1fU);
|
);
|
||||||
uint16_t g = static_cast<uint16_t>((c >> 10) & 0x3fU);
|
|
||||||
uint16_t b = static_cast<uint16_t>((c >> 3) & 0x1fU);
|
|
||||||
dst16[x] = static_cast<uint16_t>((r << 11) | (g << 5) | b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> open_keyboard_evdevs() {
|
std::vector<int> open_keyboard_evdevs() {
|
||||||
@@ -294,6 +311,11 @@ int run_device_loop(cp0::IpcClient& ipc, cp0::UiController& ctrl, cp0::LvglAppVi
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t map_size = finfo.smem_len;
|
size_t map_size = finfo.smem_len;
|
||||||
|
if (map_size == 0) {
|
||||||
|
std::cerr << "Framebuffer reports zero memory length\n";
|
||||||
|
::close(fb_fd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
void* mapped = ::mmap(nullptr, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);
|
void* mapped = ::mmap(nullptr, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);
|
||||||
if (mapped == MAP_FAILED) {
|
if (mapped == MAP_FAILED) {
|
||||||
std::cerr << "Failed to mmap framebuffer\n";
|
std::cerr << "Failed to mmap framebuffer\n";
|
||||||
@@ -312,7 +334,7 @@ int run_device_loop(cp0::IpcClient& ipc, cp0::UiController& ctrl, cp0::LvglAppVi
|
|||||||
ctrl.update_status(ipc.fetch_status());
|
ctrl.update_status(ipc.fetch_status());
|
||||||
view.apply_theme(ctrl.state().theme);
|
view.apply_theme(ctrl.state().theme);
|
||||||
view.render(ctrl.state());
|
view.render(ctrl.state());
|
||||||
blit_fbdev(fb_mem, vinfo, finfo, view.pixels());
|
blit_fbdev(fb_mem, map_size, vinfo, finfo, view.pixels());
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
bool shift_down = false;
|
bool shift_down = false;
|
||||||
@@ -323,13 +345,36 @@ int run_device_loop(cp0::IpcClient& ipc, cp0::UiController& ctrl, cp0::LvglAppVi
|
|||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
if (!pfds.empty()) {
|
if (!pfds.empty()) {
|
||||||
int prc = ::poll(pfds.data(), static_cast<nfds_t>(pfds.size()), 50);
|
int prc = ::poll(pfds.data(), static_cast<nfds_t>(pfds.size()), 50);
|
||||||
if (prc > 0) {
|
if (prc < 0) {
|
||||||
for (const auto& p : pfds) {
|
if (errno != EINTR) {
|
||||||
if ((p.revents & POLLIN) == 0) {
|
::usleep(50000);
|
||||||
|
}
|
||||||
|
} else if (prc > 0) {
|
||||||
|
std::vector<size_t> dead_indices;
|
||||||
|
for (size_t idx = 0; idx < pfds.size() && running && !g_signal_stop; ++idx) {
|
||||||
|
const auto& p = pfds[idx];
|
||||||
|
bool remove_fd = (p.revents & (POLLERR | POLLHUP | POLLNVAL)) != 0;
|
||||||
|
if ((p.revents & POLLIN) != 0) {
|
||||||
|
while (running && !g_signal_stop) {
|
||||||
|
struct input_event ev{};
|
||||||
|
ssize_t n = ::read(p.fd, &ev, sizeof(ev));
|
||||||
|
if (n < 0) {
|
||||||
|
if (errno == EINTR) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
struct input_event ev{};
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
while (::read(p.fd, &ev, sizeof(ev)) == sizeof(ev)) {
|
break;
|
||||||
|
}
|
||||||
|
remove_fd = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (n == 0) {
|
||||||
|
remove_fd = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (n != static_cast<ssize_t>(sizeof(ev))) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (ev.type != EV_KEY) {
|
if (ev.type != EV_KEY) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -387,14 +432,28 @@ int run_device_loop(cp0::IpcClient& ipc, cp0::UiController& ctrl, cp0::LvglAppVi
|
|||||||
ctrl.set_peers(ipc.list_tailscale_peers());
|
ctrl.set_peers(ipc.list_tailscale_peers());
|
||||||
}
|
}
|
||||||
dispatch_action(ipc, ctrl, view, act, running, feedback_until);
|
dispatch_action(ipc, ctrl, view, act, running, feedback_until);
|
||||||
|
if (!running || g_signal_stop) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (remove_fd) {
|
||||||
|
::close(p.fd);
|
||||||
|
dead_indices.push_back(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto it = dead_indices.rbegin(); it != dead_indices.rend(); ++it) {
|
||||||
|
pfds.erase(pfds.begin() + static_cast<std::ptrdiff_t>(*it));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
::usleep(50000);
|
::usleep(50000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!running || g_signal_stop) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
if (!ctrl.state().feedback_banner.empty() && now >= feedback_until) {
|
if (!ctrl.state().feedback_banner.empty() && now >= feedback_until) {
|
||||||
ctrl.clear_feedback();
|
ctrl.clear_feedback();
|
||||||
@@ -405,14 +464,14 @@ int run_device_loop(cp0::IpcClient& ipc, cp0::UiController& ctrl, cp0::LvglAppVi
|
|||||||
last_poll = now;
|
last_poll = now;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
if (dirty) {
|
if (running && !g_signal_stop && dirty) {
|
||||||
view.render(ctrl.state());
|
view.render(ctrl.state());
|
||||||
blit_fbdev(fb_mem, vinfo, finfo, view.pixels());
|
blit_fbdev(fb_mem, map_size, vinfo, finfo, view.pixels());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int fd : ev_fds) {
|
for (const auto& p : pfds) {
|
||||||
::close(fd);
|
::close(p.fd);
|
||||||
}
|
}
|
||||||
::munmap(mapped, map_size);
|
::munmap(mapped, map_size);
|
||||||
::close(fb_fd);
|
::close(fb_fd);
|
||||||
@@ -516,7 +575,7 @@ int run_sdl_loop(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ev.type == SDL_TEXTINPUT) {
|
if (ev.type == SDL_TEXTINPUT) {
|
||||||
for (int i = 0; ev.text.text[i] != '\0'; ++i) {
|
for (int i = 0; running && !g_signal_stop && ev.text.text[i] != '\0'; ++i) {
|
||||||
char ch = ev.text.text[i];
|
char ch = ev.text.text[i];
|
||||||
cp0::IpcAction act = ctrl.handle_key(ch, cp0::KeyCode::Char);
|
cp0::IpcAction act = ctrl.handle_key(ch, cp0::KeyCode::Char);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
@@ -577,6 +636,9 @@ int run_sdl_loop(
|
|||||||
} while (running && SDL_PollEvent(&ev) != 0);
|
} while (running && SDL_PollEvent(&ev) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!running || g_signal_stop) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
if (!ctrl.state().feedback_banner.empty() && now >= feedback_until) {
|
if (!ctrl.state().feedback_banner.empty() && now >= feedback_until) {
|
||||||
ctrl.clear_feedback();
|
ctrl.clear_feedback();
|
||||||
@@ -587,7 +649,7 @@ int run_sdl_loop(
|
|||||||
last_poll = now;
|
last_poll = now;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
if (running && dirty) {
|
if (running && !g_signal_stop && dirty) {
|
||||||
view.render(ctrl.state());
|
view.render(ctrl.state());
|
||||||
present();
|
present();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,12 +209,14 @@ void UiController::set_dir_picker_start_path(const std::string& path) {
|
|||||||
dir_picker_start_path_ = path;
|
dir_picker_start_path_ = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiController::set_feedback(const std::string& message) {
|
void UiController::set_feedback(const std::string& message, bool is_error) {
|
||||||
state_.feedback_banner = message;
|
state_.feedback_banner = message;
|
||||||
|
state_.feedback_is_error = is_error && !message.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiController::clear_feedback() {
|
void UiController::clear_feedback() {
|
||||||
state_.feedback_banner.clear();
|
state_.feedback_banner.clear();
|
||||||
|
state_.feedback_is_error = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UiController::consume_peer_refresh() {
|
bool UiController::consume_peer_refresh() {
|
||||||
@@ -276,13 +278,15 @@ void UiController::load_directory(const std::string& path, const std::string& se
|
|||||||
state_.dir_current_path = resolved.string();
|
state_.dir_current_path = resolved.string();
|
||||||
state_.dir_entries.clear();
|
state_.dir_entries.clear();
|
||||||
|
|
||||||
fs::directory_iterator it(
|
for (fs::directory_iterator it(
|
||||||
resolved,
|
resolved,
|
||||||
fs::directory_options::skip_permission_denied,
|
fs::directory_options::skip_permission_denied,
|
||||||
ec
|
ec
|
||||||
);
|
),
|
||||||
if (!ec) {
|
end;
|
||||||
for (const auto& entry : it) {
|
!ec && it != end;
|
||||||
|
it.increment(ec)) {
|
||||||
|
const auto& entry = *it;
|
||||||
std::error_code entry_ec;
|
std::error_code entry_ec;
|
||||||
if (!entry.is_directory(entry_ec) || entry_ec) {
|
if (!entry.is_directory(entry_ec) || entry_ec) {
|
||||||
continue;
|
continue;
|
||||||
@@ -293,7 +297,6 @@ void UiController::load_directory(const std::string& path, const std::string& se
|
|||||||
}
|
}
|
||||||
state_.dir_entries.push_back(entry.path().string());
|
state_.dir_entries.push_back(entry.path().string());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::sort(
|
std::sort(
|
||||||
state_.dir_entries.begin(),
|
state_.dir_entries.begin(),
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ struct UiState {
|
|||||||
std::string text_buffer;
|
std::string text_buffer;
|
||||||
std::string modal_error;
|
std::string modal_error;
|
||||||
std::string feedback_banner;
|
std::string feedback_banner;
|
||||||
|
bool feedback_is_error = false;
|
||||||
|
|
||||||
bool needs_peer_refresh = false;
|
bool needs_peer_refresh = false;
|
||||||
};
|
};
|
||||||
@@ -114,7 +115,7 @@ public:
|
|||||||
void set_dir_picker_start_path(const std::string& path);
|
void set_dir_picker_start_path(const std::string& path);
|
||||||
|
|
||||||
/// Set or clear transient status feedback displayed in the UI.
|
/// Set or clear transient status feedback displayed in the UI.
|
||||||
void set_feedback(const std::string& message);
|
void set_feedback(const std::string& message, bool is_error = false);
|
||||||
void clear_feedback();
|
void clear_feedback();
|
||||||
|
|
||||||
/// Return true once when TargetPicker was opened and needs peer discovery.
|
/// Return true once when TargetPicker was opened and needs peer discovery.
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
|
#include "fb_blit.hpp"
|
||||||
#include "ui_controller.hpp"
|
#include "ui_controller.hpp"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -262,6 +266,24 @@ void test_target_picker_and_manual_host() {
|
|||||||
assert(no_peer_enter.type == cp0::ActionType::None);
|
assert(no_peer_enter.type == cp0::ActionType::None);
|
||||||
assert(ctrl.state().modal == cp0::ModalKind::TargetPicker);
|
assert(ctrl.state().modal == cp0::ModalKind::TargetPicker);
|
||||||
ctrl.handle_key(0, cp0::KeyCode::Escape);
|
ctrl.handle_key(0, cp0::KeyCode::Escape);
|
||||||
|
|
||||||
|
// IPv6 host with port and without port
|
||||||
|
ctrl.handle_key('c', cp0::KeyCode::Char);
|
||||||
|
ctrl.handle_key('t', cp0::KeyCode::Char);
|
||||||
|
type_text(ctrl, "[::1]:8765");
|
||||||
|
auto ipv6_port = ctrl.handle_key(0, cp0::KeyCode::Enter);
|
||||||
|
assert(ipv6_port.type == cp0::ActionType::SetTarget);
|
||||||
|
assert(ipv6_port.target_host == "::1");
|
||||||
|
assert(ipv6_port.target_port == 8765);
|
||||||
|
assert(ctrl.state().modal == cp0::ModalKind::None);
|
||||||
|
|
||||||
|
ctrl.handle_key('c', cp0::KeyCode::Char);
|
||||||
|
ctrl.handle_key('t', cp0::KeyCode::Char);
|
||||||
|
type_text(ctrl, "[fd7a:115c:a1e0::1]");
|
||||||
|
auto ipv6_default = ctrl.handle_key(0, cp0::KeyCode::Enter);
|
||||||
|
assert(ipv6_default.type == cp0::ActionType::SetTarget);
|
||||||
|
assert(ipv6_default.target_host == "fd7a:115c:a1e0::1");
|
||||||
|
assert(ipv6_default.target_port == 8765);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_dir_picker_traversal_and_manual_path() {
|
void test_dir_picker_traversal_and_manual_path() {
|
||||||
@@ -333,6 +355,42 @@ void test_dir_picker_traversal_and_manual_path() {
|
|||||||
assert(add_manual.type == cp0::ActionType::AddFolder);
|
assert(add_manual.type == cp0::ActionType::AddFolder);
|
||||||
assert(add_manual.folder_path == "/media/sd/DCIM2");
|
assert(add_manual.folder_path == "/media/sd/DCIM2");
|
||||||
assert(ctrl.state().modal == cp0::ModalKind::None);
|
assert(ctrl.state().modal == cp0::ModalKind::None);
|
||||||
|
|
||||||
|
// '.' inside DirPicker adds dir_current_path directly (even when a subdir is highlighted)
|
||||||
|
ctrl.handle_key('a', cp0::KeyCode::Char);
|
||||||
|
assert(ctrl.state().modal == cp0::ModalKind::DirPicker);
|
||||||
|
ctrl.handle_key('j', cp0::KeyCode::Char); // highlight beta
|
||||||
|
auto add_dot = ctrl.handle_key('.', cp0::KeyCode::Char);
|
||||||
|
assert(add_dot.type == cp0::ActionType::AddFolder);
|
||||||
|
assert(fs::path(add_dot.folder_path) == fs::weakly_canonical(root));
|
||||||
|
assert(ctrl.state().modal == cp0::ModalKind::None);
|
||||||
|
|
||||||
|
// '~' tilde path expansion in FolderPath TextInput
|
||||||
|
const char* raw_home = std::getenv("HOME");
|
||||||
|
bool had_home = (raw_home != nullptr);
|
||||||
|
std::string saved_home = had_home ? raw_home : "";
|
||||||
|
::setenv("HOME", "/home/cp0user", 1);
|
||||||
|
|
||||||
|
ctrl.handle_key('a', cp0::KeyCode::Char);
|
||||||
|
ctrl.handle_key('t', cp0::KeyCode::Char);
|
||||||
|
type_text(ctrl, "~/Pictures/Camera");
|
||||||
|
auto add_tilde = ctrl.handle_key(0, cp0::KeyCode::Enter);
|
||||||
|
assert(add_tilde.type == cp0::ActionType::AddFolder);
|
||||||
|
assert(add_tilde.folder_path == "/home/cp0user/Pictures/Camera");
|
||||||
|
assert(ctrl.state().modal == cp0::ModalKind::None);
|
||||||
|
|
||||||
|
ctrl.handle_key('a', cp0::KeyCode::Char);
|
||||||
|
ctrl.handle_key('t', cp0::KeyCode::Char);
|
||||||
|
type_text(ctrl, "~");
|
||||||
|
auto add_tilde_home = ctrl.handle_key(0, cp0::KeyCode::Enter);
|
||||||
|
assert(add_tilde_home.type == cp0::ActionType::AddFolder);
|
||||||
|
assert(add_tilde_home.folder_path == "/home/cp0user");
|
||||||
|
|
||||||
|
if (had_home) {
|
||||||
|
::setenv("HOME", saved_home.c_str(), 1);
|
||||||
|
} else {
|
||||||
|
::unsetenv("HOME");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_folders_selection_and_confirm_remove() {
|
void test_folders_selection_and_confirm_remove() {
|
||||||
@@ -432,6 +490,152 @@ void test_logs_scrolling_and_retry_failed() {
|
|||||||
assert(retry.type == cp0::ActionType::RetryFailed);
|
assert(retry.type == cp0::ActionType::RetryFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_feedback_banner_and_error_flag() {
|
||||||
|
cp0::UiController ctrl;
|
||||||
|
assert(ctrl.state().feedback_banner.empty());
|
||||||
|
assert(ctrl.state().feedback_is_error == false);
|
||||||
|
|
||||||
|
ctrl.set_feedback("Sync triggered");
|
||||||
|
assert(ctrl.state().feedback_banner == "Sync triggered");
|
||||||
|
assert(ctrl.state().feedback_is_error == false);
|
||||||
|
|
||||||
|
ctrl.set_feedback("Daemon unreachable", true);
|
||||||
|
assert(ctrl.state().feedback_banner == "Daemon unreachable");
|
||||||
|
assert(ctrl.state().feedback_is_error == true);
|
||||||
|
|
||||||
|
ctrl.set_feedback("Folder added");
|
||||||
|
assert(ctrl.state().feedback_banner == "Folder added");
|
||||||
|
assert(ctrl.state().feedback_is_error == false);
|
||||||
|
|
||||||
|
ctrl.set_feedback("", true);
|
||||||
|
assert(ctrl.state().feedback_banner.empty());
|
||||||
|
assert(ctrl.state().feedback_is_error == false);
|
||||||
|
|
||||||
|
ctrl.set_feedback("Failed", true);
|
||||||
|
assert(ctrl.state().feedback_is_error == true);
|
||||||
|
ctrl.clear_feedback();
|
||||||
|
assert(ctrl.state().feedback_banner.empty());
|
||||||
|
assert(ctrl.state().feedback_is_error == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_fb_blit_pixel_formats_and_bounds() {
|
||||||
|
const uint32_t src[4] = {
|
||||||
|
0xff123456U, 0xfff80000U,
|
||||||
|
0xff00fc00U, 0xff0000f8U,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 32-bit XRGB8888 fast path with xoffset/yoffset and padded stride
|
||||||
|
{
|
||||||
|
cp0::FbBlitSpec spec;
|
||||||
|
spec.xres = 2;
|
||||||
|
spec.yres = 2;
|
||||||
|
spec.xoffset = 1;
|
||||||
|
spec.yoffset = 1;
|
||||||
|
spec.bits_per_pixel = 32;
|
||||||
|
spec.line_length = 16; // 4 pixels per scanline
|
||||||
|
spec.red = {16, 8};
|
||||||
|
spec.green = {8, 8};
|
||||||
|
spec.blue = {0, 8};
|
||||||
|
|
||||||
|
std::vector<uint8_t> buf(48, 0xaa);
|
||||||
|
assert(cp0::blit_framebuffer(buf.data(), buf.size(), spec, src, 2, 2));
|
||||||
|
uint32_t p00 = 0;
|
||||||
|
uint32_t p11 = 0;
|
||||||
|
std::memcpy(&p00, buf.data() + 1 * 16 + 1 * 4, 4);
|
||||||
|
std::memcpy(&p11, buf.data() + 2 * 16 + 2 * 4, 4);
|
||||||
|
assert(p00 == 0xff123456U);
|
||||||
|
assert(p11 == 0xff0000f8U);
|
||||||
|
assert(buf[0] == 0xaa);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 32-bit XBGR8888 (red/blue swapped in fb layout)
|
||||||
|
{
|
||||||
|
cp0::FbBlitSpec spec;
|
||||||
|
spec.xres = 2;
|
||||||
|
spec.yres = 2;
|
||||||
|
spec.bits_per_pixel = 32;
|
||||||
|
spec.line_length = 8;
|
||||||
|
spec.red = {0, 8};
|
||||||
|
spec.green = {8, 8};
|
||||||
|
spec.blue = {16, 8};
|
||||||
|
|
||||||
|
std::vector<uint8_t> buf(16, 0);
|
||||||
|
assert(cp0::blit_framebuffer(buf.data(), buf.size(), spec, src, 2, 2));
|
||||||
|
uint32_t p00 = 0;
|
||||||
|
std::memcpy(&p00, buf.data(), 4);
|
||||||
|
assert(p00 == 0x00563412U);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 16-bit RGB565 & BGR565 with odd stride
|
||||||
|
{
|
||||||
|
cp0::FbBlitSpec spec;
|
||||||
|
spec.xres = 2;
|
||||||
|
spec.yres = 2;
|
||||||
|
spec.bits_per_pixel = 16;
|
||||||
|
spec.line_length = 5; // odd byte stride >= 4
|
||||||
|
spec.red = {11, 5};
|
||||||
|
spec.green = {5, 6};
|
||||||
|
spec.blue = {0, 5};
|
||||||
|
|
||||||
|
std::vector<uint8_t> buf(10, 0);
|
||||||
|
assert(cp0::blit_framebuffer(buf.data(), buf.size(), spec, src, 2, 2));
|
||||||
|
uint16_t p01 = 0; // pure red 0xfff80000 -> 0xf800
|
||||||
|
uint16_t p10 = 0; // pure green 0xff00fc00 -> 0x07e0
|
||||||
|
std::memcpy(&p01, buf.data() + 2, 2);
|
||||||
|
std::memcpy(&p10, buf.data() + 5, 2);
|
||||||
|
assert(p01 == 0xf800U);
|
||||||
|
assert(p10 == 0x07e0U);
|
||||||
|
|
||||||
|
spec.red = {0, 5};
|
||||||
|
spec.blue = {11, 5};
|
||||||
|
assert(cp0::blit_framebuffer(buf.data(), buf.size(), spec, src, 2, 2));
|
||||||
|
std::memcpy(&p01, buf.data() + 2, 2);
|
||||||
|
assert(p01 == 0x001fU);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 24-bit BGR888
|
||||||
|
{
|
||||||
|
cp0::FbBlitSpec spec;
|
||||||
|
spec.xres = 2;
|
||||||
|
spec.yres = 2;
|
||||||
|
spec.bits_per_pixel = 24;
|
||||||
|
spec.line_length = 6;
|
||||||
|
spec.red = {0, 8};
|
||||||
|
spec.green = {8, 8};
|
||||||
|
spec.blue = {16, 8};
|
||||||
|
|
||||||
|
std::vector<uint8_t> buf(12, 0);
|
||||||
|
assert(cp0::blit_framebuffer(buf.data(), buf.size(), spec, src, 2, 2));
|
||||||
|
assert(buf[0] == 0x12 && buf[1] == 0x34 && buf[2] == 0x56);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bounds & invalid format checks (canary byte after map_size untouched)
|
||||||
|
{
|
||||||
|
cp0::FbBlitSpec spec;
|
||||||
|
spec.xres = 2;
|
||||||
|
spec.yres = 2;
|
||||||
|
spec.bits_per_pixel = 16;
|
||||||
|
spec.line_length = 4;
|
||||||
|
spec.red = {11, 5};
|
||||||
|
spec.green = {5, 6};
|
||||||
|
spec.blue = {0, 5};
|
||||||
|
|
||||||
|
std::vector<uint8_t> buf(8, 0x55);
|
||||||
|
// Only 6 bytes mapped, so row 1 (bytes 4..7) overflows map_size
|
||||||
|
assert(!cp0::blit_framebuffer(buf.data(), 6, spec, src, 2, 2));
|
||||||
|
assert(buf[6] == 0x55 && buf[7] == 0x55);
|
||||||
|
|
||||||
|
// Stride smaller than row_bytes rejected
|
||||||
|
spec.line_length = 3;
|
||||||
|
assert(!cp0::blit_framebuffer(buf.data(), buf.size(), spec, src, 2, 2));
|
||||||
|
|
||||||
|
// Unsupported bpp rejected
|
||||||
|
spec.line_length = 4;
|
||||||
|
spec.bits_per_pixel = 8;
|
||||||
|
assert(!cp0::blit_framebuffer(buf.data(), buf.size(), spec, src, 2, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -441,6 +645,8 @@ int main() {
|
|||||||
test_dir_picker_traversal_and_manual_path();
|
test_dir_picker_traversal_and_manual_path();
|
||||||
test_folders_selection_and_confirm_remove();
|
test_folders_selection_and_confirm_remove();
|
||||||
test_logs_scrolling_and_retry_failed();
|
test_logs_scrolling_and_retry_failed();
|
||||||
|
test_feedback_banner_and_error_flag();
|
||||||
|
test_fb_blit_pixel_formats_and_bounds();
|
||||||
std::cout << "All test_ui_navigation assertions passed.\n";
|
std::cout << "All test_ui_navigation assertions passed.\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user