Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87f0e574 authored by Steve Kondik's avatar Steve Kondik
Browse files

sr: Fix all the graphics issues

 * Get rid of all the jank and flicker.
 * Fix preserved backbuffer
 * Simplify the code, all drawing happens on a
   single thread now.

Change-Id: I36e1deee0663defd8aea1eba985e3ecbd408eac0
parent 95be77d7
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -648,6 +648,9 @@ static bool erase_volume(const char* volume, bool force = false) {

    saved_log_file* head = NULL;

    ui->SetBackground(RecoveryUI::ERASING);
    ui->SetProgressType(RecoveryUI::INDETERMINATE);

    if (!force && is_cache) {
        // If we're reformatting /cache, we load any past logs
        // (i.e. "/cache/recovery/last_*") and the current log
@@ -695,9 +698,6 @@ static bool erase_volume(const char* volume, bool force = false) {

    ui->Print("Formatting %s...\n", volume);

    ui->SetBackground(RecoveryUI::ERASING);
    ui->SetProgressType(RecoveryUI::INDETERMINATE);

    if (volume[0] == '/') {
        ensure_path_unmounted(volume);
    }
@@ -1290,7 +1290,7 @@ prompt_and_wait(Device* device, int status) {
        switch (status) {
            case INSTALL_SUCCESS:
            case INSTALL_NONE:
                ui->SetBackground(RecoveryUI::NO_COMMAND);
                ui->SetBackground(RecoveryUI::NONE);
                break;

            case INSTALL_ERROR:
+30 −30
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
    stage(-1),
    max_stage(-1),
    updateMutex(PTHREAD_MUTEX_INITIALIZER),
    progressCondition(PTHREAD_COND_INITIALIZER),
    rtl_locale(false),
    rainbow(false),
    wrap_count(0) {
@@ -178,8 +179,6 @@ void ScreenRecoveryUI::draw_background_locked() {
// Should only be called with updateMutex locked.
void ScreenRecoveryUI::draw_foreground_locked() {
    if (currentIcon != NONE) {
        gr_color(0, 0, 0, 255);
        gr_clear();
        GRSurface* frame = GetCurrentFrame();
        int frame_width = gr_get_width(frame);
        int frame_height = gr_get_height(frame);
@@ -354,14 +353,10 @@ void ScreenRecoveryUI::draw_sysbar()
// Redraw everything on the screen.  Does not flip pages.
// Should only be called with updateMutex locked.
void ScreenRecoveryUI::draw_screen_locked() {
    if (!show_text) {
   draw_background_locked();
        draw_foreground_locked();
    } else {
        gr_color(0, 0, 0, 255);
        gr_clear();

        if (currentIcon == INSTALLING_UPDATE) {
   if (show_text) {
        if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
            size_t y = header_height_ + 4;

            draw_background_locked();
@@ -420,15 +415,9 @@ void ScreenRecoveryUI::draw_screen_locked() {
// Redraw everything on the screen and flip the screen (make it visible).
// Should only be called with updateMutex locked.
void ScreenRecoveryUI::update_screen_locked() {
    draw_screen_locked();
    gr_flip();
}

// Updates only the progress bar, if possible, otherwise redraws the screen.
// Should only be called with updateMutex locked.
void ScreenRecoveryUI::update_progress_locked() {
    draw_foreground_locked();
    gr_flip();
    update_waiting = true;
    pthread_cond_signal(&progressCondition);
    LOGV("%s: %p\n", __func__, __builtin_return_address(0));
}

// Keeps the progress bar updated, even when the process is otherwise busy.
@@ -447,10 +436,12 @@ void ScreenRecoveryUI::OMGRainbows()
void ScreenRecoveryUI::ProgressThreadLoop() {
    double interval = 1.0 / animation_fps;
    while (true) {
        double start = now();
        pthread_mutex_lock(&updateMutex);
        if (progressBarType == EMPTY && !update_waiting)
            pthread_cond_wait(&progressCondition, &updateMutex);

        bool redraw = false;
        double start = now();

        // update the installation animation, if active
        // skip this if we have a text overlay (too expensive to update)
@@ -481,19 +472,27 @@ void ScreenRecoveryUI::ProgressThreadLoop() {
            }
        }

        if (redraw) update_progress_locked();
        if (update_waiting || !pagesIdentical) {
            LOGV("call draw_screen_locked\n");
            draw_screen_locked();
            if (!update_waiting)
                pagesIdentical = true;
        }

        pthread_mutex_unlock(&updateMutex);
        if (redraw) {
            LOGV("call draw_foreground_locked\n");
            draw_foreground_locked();
        }
        gr_flip();

        if (progressBarType == EMPTY)
            break;
        update_waiting = false;
        pthread_mutex_unlock(&updateMutex);

        double end = now();
        // minimum of 20ms delay between frames
        double delay = interval - (end-start);
        if (delay < 0.02) delay = 0.02;
        usleep((long)(delay * 1000000));

    }
}

@@ -587,6 +586,8 @@ void ScreenRecoveryUI::Init() {

    LoadAnimation();

    pthread_create(&progress_thread_, nullptr, ProgressThreadStartRoutine, this);

    RecoveryUI::Init();
}

@@ -658,14 +659,12 @@ void ScreenRecoveryUI::SetProgressType(ProgressType type) {
    pthread_mutex_lock(&updateMutex);
    if (progressBarType != type) {
        progressBarType = type;
        if (progressBarType != EMPTY) {
            pthread_create(&progress_thread_, nullptr, ProgressThreadStartRoutine, this);
        }
    }
    progressScopeStart = 0;
    progressScopeSize = 0;
    progress = 0;
    update_progress_locked();

    update_screen_locked();
    pthread_mutex_unlock(&updateMutex);
}

@@ -677,7 +676,8 @@ void ScreenRecoveryUI::ShowProgress(float portion, float seconds) {
    progressScopeTime = now();
    progressScopeDuration = seconds;
    progress = 0;
    update_progress_locked();

    update_screen_locked();
    pthread_mutex_unlock(&updateMutex);
}

@@ -691,7 +691,7 @@ void ScreenRecoveryUI::SetProgress(float fraction) {
        float scale = width * progressScopeSize;
        if ((int) (progress * scale) != (int) (fraction * scale)) {
            progress = fraction;
            update_progress_locked();
            update_screen_locked();
        }
    }
    pthread_mutex_unlock(&updateMutex);
+3 −1
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ class ScreenRecoveryUI : public RecoveryUI {
    int menu_item_start_;

    pthread_t progress_thread_;
    pthread_cond_t progressCondition;

    // Number of intro frames and loop frames in the animation.
    int intro_frames;
@@ -172,12 +173,13 @@ class ScreenRecoveryUI : public RecoveryUI {
    int sysbar_height_;
    int text_first_row_;

    bool update_waiting;

    int  draw_header_icon();
    void draw_menu_item(int textrow, const char *text, int selected);
    void draw_sysbar();
    void draw_screen_locked();
    void update_screen_locked();
    void update_progress_locked();

    GRSurface* GetCurrentFrame();
    GRSurface* GetCurrentText();