Skip to content

Commit

Permalink
sr: Fix all the graphics issues
Browse files Browse the repository at this point in the history
 * 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
  • Loading branch information
Steve Kondik committed Sep 19, 2016
1 parent 95be77d commit 87f0e57
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
8 changes: 4 additions & 4 deletions recovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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:
Expand Down
60 changes: 30 additions & 30 deletions screen_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
draw_background_locked();

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

draw_background_locked();
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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));

}
}

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

LoadAnimation();

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

RecoveryUI::Init();
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion screen_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 87f0e57

Please sign in to comment.