Files
crosspoint-reader-mod/src/activities/Activity.cpp
cottongin a1ac11ab51 feat: port upstream PRs #852, #965, #972, #971, #977, #975
Port 6 upstream PRs (PR #939 was already ported):

- #852: Complete HalPowerManager with RAII Lock class, WiFi check in
  setPowerSaving, skipLoopDelay overrides for ClearCache/OtaUpdate,
  and power lock in Activity render task loops
- #965: Fix paragraph formatting inside list items by tracking
  listItemUntilDepth to prevent unwanted line breaks
- #972: Micro-optimizations: std::move in insertFont, const ref for
  getDataFromBook parameter
- #971: Remove redundant hasPrintableChars pre-rendering pass from
  EpdFont, EpdFontFamily, and GfxRenderer
- #977: Skip unsupported image formats before extraction, add
  PARSE_BUFFER_SIZE constant and chapter parse timing
- #975: Fix UITheme memory leak by replacing raw pointer with
  std::unique_ptr for currentTheme

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 15:45:06 -05:00

62 lines
1.6 KiB
C++

#include "Activity.h"
#include <HalPowerManager.h>
void Activity::renderTaskTrampoline(void* param) {
auto* self = static_cast<Activity*>(param);
self->renderTaskLoop();
}
void Activity::renderTaskLoop() {
while (true) {
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
{
HalPowerManager::Lock powerLock;
RenderLock lock(*this);
render(std::move(lock));
}
}
}
void Activity::onEnter() {
xTaskCreate(&renderTaskTrampoline, name.c_str(),
8192, // Stack size
this, // Parameters
1, // Priority
&renderTaskHandle // Task handle
);
assert(renderTaskHandle != nullptr && "Failed to create render task");
LOG_DBG("ACT", "Entering activity: %s", name.c_str());
}
void Activity::onExit() {
RenderLock lock(*this); // Ensure we don't delete the task while it's rendering
if (renderTaskHandle) {
vTaskDelete(renderTaskHandle);
renderTaskHandle = nullptr;
}
LOG_DBG("ACT", "Exiting activity: %s", name.c_str());
}
void Activity::requestUpdate() {
// Using direct notification to signal the render task to update
// Increment counter so multiple rapid calls won't be lost
if (renderTaskHandle) {
xTaskNotify(renderTaskHandle, 1, eIncrement);
}
}
void Activity::requestUpdateAndWait() {
// FIXME @ngxson : properly implement this using freeRTOS notification
delay(100);
}
// RenderLock
Activity::RenderLock::RenderLock(Activity& activity) : activity(activity) {
xSemaphoreTake(activity.renderingMutex, portMAX_DELAY);
}
Activity::RenderLock::~RenderLock() { xSemaphoreGive(activity.renderingMutex); }