aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-06-20 01:10:44 -0500
committerTao Bao2017-06-20 17:47:06 -0500
commit171b4c4cbe6ba5af3fd7df87d227eda44e308727 (patch)
treea1b9543cf947e02fc0f61fe24465fed7d41f2147
parent5efe2bca2282dd8aa613ae85b267780f6c1d1307 (diff)
downloadplatform-bootable-recovery-171b4c4cbe6ba5af3fd7df87d227eda44e308727.tar.gz
platform-bootable-recovery-171b4c4cbe6ba5af3fd7df87d227eda44e308727.tar.xz
platform-bootable-recovery-171b4c4cbe6ba5af3fd7df87d227eda44e308727.zip
screen_ui: Allow setting screen margin space.
We already have outer_width and outer_height in wear UI, and x_offset and y_offset in VR UI. This CL adds margin_width_ and margin_height_ to their base class (ScreenRecoveryUI) to shorten the gap. This will be in general useful for round or round-cornered screens. Move the density computation to ScreenRecoveryUI ctor so that the value can be used earlier. 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 (cherry picked from commit 87f4650874346f1d0238e70b148a31cea5e19a2e)
-rw-r--r--screen_ui.cpp138
-rw-r--r--screen_ui.h11
2 files changed, 78 insertions, 71 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp
index 61ef5911..2dc1cc4c 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -43,8 +43,6 @@
43#include "screen_ui.h" 43#include "screen_ui.h"
44#include "ui.h" 44#include "ui.h"
45 45
46#define TEXT_INDENT 4
47
48// Return the current time as a double (including fractions of a second). 46// Return the current time as a double (including fractions of a second).
49static double now() { 47static double now() {
50 struct timeval tv; 48 struct timeval tv;
@@ -53,7 +51,8 @@ static double now() {
53} 51}
54 52
55ScreenRecoveryUI::ScreenRecoveryUI() 53ScreenRecoveryUI::ScreenRecoveryUI()
56 : currentIcon(NONE), 54 : density_(static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f),
55 currentIcon(NONE),
57 progressBarType(EMPTY), 56 progressBarType(EMPTY),
58 progressScopeStart(0), 57 progressScopeStart(0),
59 progressScopeSize(0), 58 progressScopeSize(0),
@@ -79,6 +78,8 @@ ScreenRecoveryUI::ScreenRecoveryUI()
79 animation_fps(30), // TODO: there's currently no way to infer this. 78 animation_fps(30), // TODO: there's currently no way to infer this.
80 stage(-1), 79 stage(-1),
81 max_stage(-1), 80 max_stage(-1),
81 margin_width_(0),
82 margin_height_(0),
82 updateMutex(PTHREAD_MUTEX_INITIALIZER) {} 83 updateMutex(PTHREAD_MUTEX_INITIALIZER) {}
83 84
84GRSurface* ScreenRecoveryUI::GetCurrentFrame() { 85GRSurface* ScreenRecoveryUI::GetCurrentFrame() {
@@ -282,65 +283,66 @@ static const char* LONG_PRESS_HELP[] = {
282 NULL 283 NULL
283}; 284};
284 285
285// Redraw everything on the screen. Does not flip pages. 286// Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
286// Should only be called with updateMutex locked. 287// locked.
287void ScreenRecoveryUI::draw_screen_locked() { 288void ScreenRecoveryUI::draw_screen_locked() {
288 if (!show_text) { 289 if (!show_text) {
289 draw_background_locked(); 290 draw_background_locked();
290 draw_foreground_locked(); 291 draw_foreground_locked();
291 } else { 292 return;
292 gr_color(0, 0, 0, 255); 293 }
293 gr_clear();
294
295 int y = 0;
296 if (show_menu) {
297 std::string recovery_fingerprint =
298 android::base::GetProperty("ro.bootimage.build.fingerprint", "");
299
300 SetColor(INFO);
301 DrawTextLine(TEXT_INDENT, &y, "Android Recovery", true);
302 for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
303 DrawTextLine(TEXT_INDENT, &y, chunk.c_str(), false);
304 }
305 DrawTextLines(TEXT_INDENT, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
306
307 SetColor(HEADER);
308 DrawTextLines(TEXT_INDENT, &y, menu_headers_);
309
310 SetColor(MENU);
311 DrawHorizontalRule(&y);
312 y += 4;
313 for (int i = 0; i < menu_items; ++i) {
314 if (i == menu_sel) {
315 // Draw the highlight bar.
316 SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
317 DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4);
318 // Bold white text for the selected item.
319 SetColor(MENU_SEL_FG);
320 DrawTextLine(TEXT_INDENT, &y, menu_[i], true);
321 SetColor(MENU);
322 } else {
323 DrawTextLine(TEXT_INDENT, &y, menu_[i], false);
324 }
325 }
326 DrawHorizontalRule(&y);
327 }
328 294
329 // display from the bottom up, until we hit the top of the 295 gr_color(0, 0, 0, 255);
330 // screen, the bottom of the menu, or we've displayed the 296 gr_clear();
331 // entire text buffer. 297
332 SetColor(LOG); 298 static constexpr int TEXT_INDENT = 4;
333 int row = (text_top_ + text_rows_ - 1) % text_rows_; 299 int x = TEXT_INDENT + margin_width_;
334 size_t count = 0; 300 int y = margin_height_;
335 for (int ty = gr_fb_height() - char_height_ - log_bottom_offset_; 301 if (show_menu) {
336 ty >= y && count < text_rows_; 302 std::string recovery_fingerprint =
337 ty -= char_height_, ++count) { 303 android::base::GetProperty("ro.bootimage.build.fingerprint", "");
338 int temp_y = ty; 304
339 DrawTextLine(0, &temp_y, text_[row], false); 305 SetColor(INFO);
340 --row; 306 DrawTextLine(x, &y, "Android Recovery", true);
341 if (row < 0) row = text_rows_ - 1; 307 for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
342 } 308 DrawTextLine(x, &y, chunk.c_str(), false);
309 }
310 DrawTextLines(x, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
311
312 SetColor(HEADER);
313 DrawTextLines(x, &y, menu_headers_);
314
315 SetColor(MENU);
316 DrawHorizontalRule(&y);
317 y += 4;
318 for (int i = 0; i < menu_items; ++i) {
319 if (i == menu_sel) {
320 // Draw the highlight bar.
321 SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
322 DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4);
323 // Bold white text for the selected item.
324 SetColor(MENU_SEL_FG);
325 DrawTextLine(x, &y, menu_[i], true);
326 SetColor(MENU);
327 } else {
328 DrawTextLine(x, &y, menu_[i], false);
329 }
343 } 330 }
331 DrawHorizontalRule(&y);
332 }
333
334 // Display from the bottom up, until we hit the top of the screen, the bottom of the menu, or
335 // we've displayed the entire text buffer.
336 SetColor(LOG);
337 int row = (text_top_ + text_rows_ - 1) % text_rows_;
338 size_t count = 0;
339 for (int ty = gr_fb_height() - margin_height_ - char_height_ - log_bottom_offset_;
340 ty >= y && count < text_rows_; ty -= char_height_, ++count) {
341 int temp_y = ty;
342 DrawTextLine(x, &temp_y, text_[row], false);
343 --row;
344 if (row < 0) row = text_rows_ - 1;
345 }
344} 346}
345 347
346// Redraw everything on the screen and flip the screen (make it visible). 348// Redraw everything on the screen and flip the screen (make it visible).
@@ -450,15 +452,15 @@ void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
450} 452}
451 453
452bool ScreenRecoveryUI::InitTextParams() { 454bool ScreenRecoveryUI::InitTextParams() {
453 if (gr_init() < 0) { 455 if (gr_init() < 0) {
454 return false; 456 return false;
455 } 457 }
456 458
457 gr_font_size(gr_sys_font(), &char_width_, &char_height_); 459 gr_font_size(gr_sys_font(), &char_width_, &char_height_);
458 text_rows_ = gr_fb_height() / char_height_; 460 text_rows_ = (gr_fb_height() - margin_height_ * 2) / char_height_;
459 text_cols_ = gr_fb_width() / char_width_; 461 text_cols_ = (gr_fb_width() - margin_width_ * 2) / char_width_;
460 log_bottom_offset_ = 0; 462 log_bottom_offset_ = 0;
461 return true; 463 return true;
462} 464}
463 465
464bool ScreenRecoveryUI::Init(const std::string& locale) { 466bool ScreenRecoveryUI::Init(const std::string& locale) {
@@ -467,8 +469,6 @@ bool ScreenRecoveryUI::Init(const std::string& locale) {
467 return false; 469 return false;
468 } 470 }
469 471
470 density_ = static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f;
471
472 // Are we portrait or landscape? 472 // Are we portrait or landscape?
473 layout_ = (gr_fb_width() > gr_fb_height()) ? LANDSCAPE : PORTRAIT; 473 layout_ = (gr_fb_width() > gr_fb_height()) ? LANDSCAPE : PORTRAIT;
474 // Are we the large variant of our base layout? 474 // Are we the large variant of our base layout?
diff --git a/screen_ui.h b/screen_ui.h
index bd99254f..fd9f471e 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -72,10 +72,11 @@ class ScreenRecoveryUI : public RecoveryUI {
72 void SetColor(UIElement e); 72 void SetColor(UIElement e);
73 73
74 protected: 74 protected:
75 // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
76 const float density_;
77
75 Icon currentIcon; 78 Icon currentIcon;
76 79
77 // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
78 float density_;
79 // The layout to use. 80 // The layout to use.
80 int layout_; 81 int layout_;
81 82
@@ -136,6 +137,12 @@ class ScreenRecoveryUI : public RecoveryUI {
136 137
137 int char_width_; 138 int char_width_;
138 int char_height_; 139 int char_height_;
140
141 // The margin that we don't want to use for showing texts (e.g. round screen, or screen with
142 // rounded corners).
143 int margin_width_;
144 int margin_height_;
145
139 pthread_mutex_t updateMutex; 146 pthread_mutex_t updateMutex;
140 147
141 virtual bool InitTextParams(); 148 virtual bool InitTextParams();