From 87f4650874346f1d0238e70b148a31cea5e19a2e Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 19 Jun 2017 23:10:44 -0700 Subject: screen_ui: Allow setting screen margin space. For round screen or screens with rounded corners, we don't want to show texts within the margin which could otherwise be invisible. Move the density computation to ScreenRecoveryUI ctor so that the value can be used earlier. Note that this is similar to the existing stuff in wear UI (outer_width, outer_height). This CL gets ScreenRecoveryUI and WearRecoveryUI one-step closer. Bug: 62732748 Test: Setting and not setting margin_{width,height}_ on angler. Check the recovery texts (recovery menu as well as 'View recovery logs'). Change-Id: Ibf6238c9cc8949a42ed8a410e1c09d55b0b5a151 --- screen_ui.cpp | 138 +++++++++++++++++++++++++++++----------------------------- screen_ui.h | 11 ++++- 2 files changed, 78 insertions(+), 71 deletions(-) diff --git a/screen_ui.cpp b/screen_ui.cpp index 61ef5911f..2dc1cc4c9 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -43,8 +43,6 @@ #include "screen_ui.h" #include "ui.h" -#define TEXT_INDENT 4 - // Return the current time as a double (including fractions of a second). static double now() { struct timeval tv; @@ -53,7 +51,8 @@ static double now() { } ScreenRecoveryUI::ScreenRecoveryUI() - : currentIcon(NONE), + : density_(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), + currentIcon(NONE), progressBarType(EMPTY), progressScopeStart(0), progressScopeSize(0), @@ -79,6 +78,8 @@ ScreenRecoveryUI::ScreenRecoveryUI() animation_fps(30), // TODO: there's currently no way to infer this. stage(-1), max_stage(-1), + margin_width_(0), + margin_height_(0), updateMutex(PTHREAD_MUTEX_INITIALIZER) {} GRSurface* ScreenRecoveryUI::GetCurrentFrame() { @@ -282,65 +283,66 @@ static const char* LONG_PRESS_HELP[] = { NULL }; -// Redraw everything on the screen. Does not flip pages. -// Should only be called with updateMutex locked. +// Redraws 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(); - - int y = 0; - if (show_menu) { - std::string recovery_fingerprint = - android::base::GetProperty("ro.bootimage.build.fingerprint", ""); - - SetColor(INFO); - DrawTextLine(TEXT_INDENT, &y, "Android Recovery", true); - for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) { - DrawTextLine(TEXT_INDENT, &y, chunk.c_str(), false); - } - DrawTextLines(TEXT_INDENT, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP); - - SetColor(HEADER); - DrawTextLines(TEXT_INDENT, &y, menu_headers_); - - SetColor(MENU); - DrawHorizontalRule(&y); - y += 4; - for (int i = 0; i < menu_items; ++i) { - if (i == menu_sel) { - // Draw the highlight bar. - SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG); - DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4); - // Bold white text for the selected item. - SetColor(MENU_SEL_FG); - DrawTextLine(TEXT_INDENT, &y, menu_[i], true); - SetColor(MENU); - } else { - DrawTextLine(TEXT_INDENT, &y, menu_[i], false); - } - } - DrawHorizontalRule(&y); - } + if (!show_text) { + draw_background_locked(); + draw_foreground_locked(); + return; + } - // display from the bottom up, until we hit the top of the - // screen, the bottom of the menu, or we've displayed the - // entire text buffer. - SetColor(LOG); - int row = (text_top_ + text_rows_ - 1) % text_rows_; - size_t count = 0; - for (int ty = gr_fb_height() - char_height_ - log_bottom_offset_; - ty >= y && count < text_rows_; - ty -= char_height_, ++count) { - int temp_y = ty; - DrawTextLine(0, &temp_y, text_[row], false); - --row; - if (row < 0) row = text_rows_ - 1; - } + gr_color(0, 0, 0, 255); + gr_clear(); + + static constexpr int TEXT_INDENT = 4; + int x = TEXT_INDENT + margin_width_; + int y = margin_height_; + if (show_menu) { + std::string recovery_fingerprint = + android::base::GetProperty("ro.bootimage.build.fingerprint", ""); + + SetColor(INFO); + DrawTextLine(x, &y, "Android Recovery", true); + for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) { + DrawTextLine(x, &y, chunk.c_str(), false); + } + DrawTextLines(x, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP); + + SetColor(HEADER); + DrawTextLines(x, &y, menu_headers_); + + SetColor(MENU); + DrawHorizontalRule(&y); + y += 4; + for (int i = 0; i < menu_items; ++i) { + if (i == menu_sel) { + // Draw the highlight bar. + SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG); + DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4); + // Bold white text for the selected item. + SetColor(MENU_SEL_FG); + DrawTextLine(x, &y, menu_[i], true); + SetColor(MENU); + } else { + DrawTextLine(x, &y, menu_[i], false); + } } + DrawHorizontalRule(&y); + } + + // Display from the bottom up, until we hit the top of the screen, the bottom of the menu, or + // we've displayed the entire text buffer. + SetColor(LOG); + int row = (text_top_ + text_rows_ - 1) % text_rows_; + size_t count = 0; + for (int ty = gr_fb_height() - margin_height_ - char_height_ - log_bottom_offset_; + ty >= y && count < text_rows_; ty -= char_height_, ++count) { + int temp_y = ty; + DrawTextLine(x, &temp_y, text_[row], false); + --row; + if (row < 0) row = text_rows_ - 1; + } } // Redraw everything on the screen and flip the screen (make it visible). @@ -450,15 +452,15 @@ void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) { } bool ScreenRecoveryUI::InitTextParams() { - if (gr_init() < 0) { - return false; - } + if (gr_init() < 0) { + return false; + } - gr_font_size(gr_sys_font(), &char_width_, &char_height_); - text_rows_ = gr_fb_height() / char_height_; - text_cols_ = gr_fb_width() / char_width_; - log_bottom_offset_ = 0; - return true; + gr_font_size(gr_sys_font(), &char_width_, &char_height_); + text_rows_ = (gr_fb_height() - margin_height_ * 2) / char_height_; + text_cols_ = (gr_fb_width() - margin_width_ * 2) / char_width_; + log_bottom_offset_ = 0; + return true; } bool ScreenRecoveryUI::Init(const std::string& locale) { @@ -467,8 +469,6 @@ bool ScreenRecoveryUI::Init(const std::string& locale) { return false; } - density_ = static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f; - // Are we portrait or landscape? layout_ = (gr_fb_width() > gr_fb_height()) ? LANDSCAPE : PORTRAIT; // Are we the large variant of our base layout? diff --git a/screen_ui.h b/screen_ui.h index bd99254f6..fd9f471e9 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -72,10 +72,11 @@ class ScreenRecoveryUI : public RecoveryUI { void SetColor(UIElement e); protected: + // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. + const float density_; + Icon currentIcon; - // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. - float density_; // The layout to use. int layout_; @@ -136,6 +137,12 @@ class ScreenRecoveryUI : public RecoveryUI { int char_width_; int char_height_; + + // The margin that we don't want to use for showing texts (e.g. round screen, or screen with + // rounded corners). + int margin_width_; + int margin_height_; + pthread_mutex_t updateMutex; virtual bool InitTextParams(); -- cgit v1.2.3 From a92d8fb45676566a56d7c27d2e8fb644523adc94 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 20 Jun 2017 18:11:21 -0700 Subject: Use Makefile variables to specify margin settings. Instead of defining device-specific UI class, this CL allows using Makefile variables to specify margin values directly. Values explicitly defined via TARGET_RECOVERY_UI_MARGIN_HEIGHT and TARGET_RECOVERY_UI_MARGIN_WIDTH will be used. Otherwise they will default to zero. Bug: 62732748 Test: Specify the height and width and check recovery texts. Change-Id: Icb6f7466c8d407f877b93da38aebfdf7e6b41be7 --- Android.mk | 12 ++++++++++++ screen_ui.cpp | 16 ++++++++-------- screen_ui.h | 10 +++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Android.mk b/Android.mk index 5348e365e..5ce9d335c 100644 --- a/Android.mk +++ b/Android.mk @@ -93,6 +93,18 @@ endif LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION) LOCAL_CFLAGS += -Wno-unused-parameter -Werror +ifneq ($(TARGET_RECOVERY_UI_MARGIN_HEIGHT),) +LOCAL_CFLAGS += -DRECOVERY_UI_MARGIN_HEIGHT=$(TARGET_RECOVERY_UI_MARGIN_HEIGHT) +else +LOCAL_CFLAGS += -DRECOVERY_UI_MARGIN_HEIGHT=0 +endif + +ifneq ($(TARGET_RECOVERY_UI_MARGIN_WIDTH),) +LOCAL_CFLAGS += -DRECOVERY_UI_MARGIN_WIDTH=$(TARGET_RECOVERY_UI_MARGIN_WIDTH) +else +LOCAL_CFLAGS += -DRECOVERY_UI_MARGIN_WIDTH=0 +endif + LOCAL_C_INCLUDES += \ system/vold \ diff --git a/screen_ui.cpp b/screen_ui.cpp index 2dc1cc4c9..d21a64890 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -51,7 +51,9 @@ static double now() { } ScreenRecoveryUI::ScreenRecoveryUI() - : density_(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), + : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH), + kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT), + density_(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), currentIcon(NONE), progressBarType(EMPTY), progressScopeStart(0), @@ -78,8 +80,6 @@ ScreenRecoveryUI::ScreenRecoveryUI() animation_fps(30), // TODO: there's currently no way to infer this. stage(-1), max_stage(-1), - margin_width_(0), - margin_height_(0), updateMutex(PTHREAD_MUTEX_INITIALIZER) {} GRSurface* ScreenRecoveryUI::GetCurrentFrame() { @@ -296,8 +296,8 @@ void ScreenRecoveryUI::draw_screen_locked() { gr_clear(); static constexpr int TEXT_INDENT = 4; - int x = TEXT_INDENT + margin_width_; - int y = margin_height_; + int x = TEXT_INDENT + kMarginWidth; + int y = kMarginHeight; if (show_menu) { std::string recovery_fingerprint = android::base::GetProperty("ro.bootimage.build.fingerprint", ""); @@ -336,7 +336,7 @@ void ScreenRecoveryUI::draw_screen_locked() { SetColor(LOG); int row = (text_top_ + text_rows_ - 1) % text_rows_; size_t count = 0; - for (int ty = gr_fb_height() - margin_height_ - char_height_ - log_bottom_offset_; + for (int ty = gr_fb_height() - kMarginHeight - char_height_ - log_bottom_offset_; ty >= y && count < text_rows_; ty -= char_height_, ++count) { int temp_y = ty; DrawTextLine(x, &temp_y, text_[row], false); @@ -457,8 +457,8 @@ bool ScreenRecoveryUI::InitTextParams() { } gr_font_size(gr_sys_font(), &char_width_, &char_height_); - text_rows_ = (gr_fb_height() - margin_height_ * 2) / char_height_; - text_cols_ = (gr_fb_width() - margin_width_ * 2) / char_width_; + text_rows_ = (gr_fb_height() - kMarginHeight * 2) / char_height_; + text_cols_ = (gr_fb_width() - kMarginWidth * 2) / char_width_; log_bottom_offset_ = 0; return true; } diff --git a/screen_ui.h b/screen_ui.h index fd9f471e9..e961c1c93 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -72,6 +72,11 @@ class ScreenRecoveryUI : public RecoveryUI { void SetColor(UIElement e); protected: + // The margin that we don't want to use for showing texts (e.g. round screen, or screen with + // rounded corners). + const int kMarginWidth; + const int kMarginHeight; + // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. const float density_; @@ -138,11 +143,6 @@ class ScreenRecoveryUI : public RecoveryUI { int char_width_; int char_height_; - // The margin that we don't want to use for showing texts (e.g. round screen, or screen with - // rounded corners). - int margin_width_; - int margin_height_; - pthread_mutex_t updateMutex; virtual bool InitTextParams(); -- cgit v1.2.3