## Summary Reduce/fix the lag on the home screen before recent book covers are rendered ## Additional Context We were previously rendering the screen in two steps, delaying the recent book covers render to avoid a lag before the screen loads. In this PR, we are now doing that only if at least one book doesn't have the cover thumbnail generated yet. If all thumbs are already generated, we load and display them right away, with no lag. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**NO **_
62 lines
2.3 KiB
C++
62 lines
2.3 KiB
C++
#pragma once
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/semphr.h>
|
|
#include <freertos/task.h>
|
|
|
|
#include <functional>
|
|
#include <vector>
|
|
|
|
#include "../Activity.h"
|
|
#include "./MyLibraryActivity.h"
|
|
|
|
struct RecentBook;
|
|
struct Rect;
|
|
|
|
class HomeActivity final : public Activity {
|
|
TaskHandle_t displayTaskHandle = nullptr;
|
|
SemaphoreHandle_t renderingMutex = nullptr;
|
|
int selectorIndex = 0;
|
|
bool updateRequired = false;
|
|
bool recentsLoading = false;
|
|
bool recentsLoaded = false;
|
|
bool firstRenderDone = false;
|
|
bool hasOpdsUrl = false;
|
|
bool coverRendered = false; // Track if cover has been rendered once
|
|
bool coverBufferStored = false; // Track if cover buffer is stored
|
|
uint8_t* coverBuffer = nullptr; // HomeActivity's own buffer for cover image
|
|
std::vector<RecentBook> recentBooks;
|
|
const std::function<void(const std::string& path)> onSelectBook;
|
|
const std::function<void()> onMyLibraryOpen;
|
|
const std::function<void()> onRecentsOpen;
|
|
const std::function<void()> onSettingsOpen;
|
|
const std::function<void()> onFileTransferOpen;
|
|
const std::function<void()> onOpdsBrowserOpen;
|
|
|
|
static void taskTrampoline(void* param);
|
|
[[noreturn]] void displayTaskLoop();
|
|
void render();
|
|
int getMenuItemCount() const;
|
|
bool storeCoverBuffer(); // Store frame buffer for cover image
|
|
bool restoreCoverBuffer(); // Restore frame buffer from stored cover
|
|
void freeCoverBuffer(); // Free the stored cover buffer
|
|
void loadRecentBooks(int maxBooks);
|
|
void loadRecentCovers(int coverHeight);
|
|
|
|
public:
|
|
explicit HomeActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
|
const std::function<void(const std::string& path)>& onSelectBook,
|
|
const std::function<void()>& onMyLibraryOpen, const std::function<void()>& onRecentsOpen,
|
|
const std::function<void()>& onSettingsOpen, const std::function<void()>& onFileTransferOpen,
|
|
const std::function<void()>& onOpdsBrowserOpen)
|
|
: Activity("Home", renderer, mappedInput),
|
|
onSelectBook(onSelectBook),
|
|
onMyLibraryOpen(onMyLibraryOpen),
|
|
onRecentsOpen(onRecentsOpen),
|
|
onSettingsOpen(onSettingsOpen),
|
|
onFileTransferOpen(onFileTransferOpen),
|
|
onOpdsBrowserOpen(onOpdsBrowserOpen) {}
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
};
|