Browse Source

vr_ui: drawing changes

Change drawing of horizontal bars.
Implement image and background drawing.

Bug: 65556996
Test: Viewed graphics test
Change-Id: I68ddd997123607dbebf972af5a455ce8ef0c7075
Luke Song 3 years ago
parent
commit
92eda4db6c
4 changed files with 97 additions and 30 deletions
  1. 42
    22
      screen_ui.cpp
  2. 11
    0
      screen_ui.h
  3. 37
    7
      vr_ui.cpp
  4. 7
    1
      vr_ui.h

+ 42
- 22
screen_ui.cpp View File

@@ -149,8 +149,8 @@ int ScreenRecoveryUI::GetProgressBaseline() const {
149 149
   int elements_sum = gr_get_height(loopFrames[0]) + PixelsFromDp(kLayouts[layout_][ICON]) +
150 150
                      gr_get_height(installing_text) + PixelsFromDp(kLayouts[layout_][TEXT]) +
151 151
                      gr_get_height(progressBarFill);
152
-  int bottom_gap = (gr_fb_height() - elements_sum) / 2;
153
-  return gr_fb_height() - bottom_gap - gr_get_height(progressBarFill);
152
+  int bottom_gap = (ScreenHeight() - elements_sum) / 2;
153
+  return ScreenHeight() - bottom_gap - gr_get_height(progressBarFill);
154 154
 }
155 155
 
156 156
 // Clear the screen and draw the currently selected background icon (if any).
@@ -159,25 +159,24 @@ void ScreenRecoveryUI::draw_background_locked() {
159 159
   pagesIdentical = false;
160 160
   gr_color(0, 0, 0, 255);
161 161
   gr_clear();
162
-
163 162
   if (currentIcon != NONE) {
164 163
     if (max_stage != -1) {
165 164
       int stage_height = gr_get_height(stageMarkerEmpty);
166 165
       int stage_width = gr_get_width(stageMarkerEmpty);
167
-      int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
168
-      int y = gr_fb_height() - stage_height - kMarginHeight;
166
+      int x = (ScreenWidth() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
167
+      int y = ScreenHeight() - stage_height - kMarginHeight;
169 168
       for (int i = 0; i < max_stage; ++i) {
170 169
         GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty;
171
-        gr_blit(stage_surface, 0, 0, stage_width, stage_height, x, y);
170
+        DrawSurface(stage_surface, 0, 0, stage_width, stage_height, x, y);
172 171
         x += stage_width;
173 172
       }
174 173
     }
175 174
 
176 175
     GRSurface* text_surface = GetCurrentText();
177
-    int text_x = (gr_fb_width() - gr_get_width(text_surface)) / 2;
176
+    int text_x = (ScreenWidth() - gr_get_width(text_surface)) / 2;
178 177
     int text_y = GetTextBaseline();
179 178
     gr_color(255, 255, 255, 255);
180
-    gr_texticon(text_x, text_y, text_surface);
179
+    DrawTextIcon(text_x, text_y, text_surface);
181 180
   }
182 181
 }
183 182
 
@@ -188,21 +187,21 @@ void ScreenRecoveryUI::draw_foreground_locked() {
188 187
     GRSurface* frame = GetCurrentFrame();
189 188
     int frame_width = gr_get_width(frame);
190 189
     int frame_height = gr_get_height(frame);
191
-    int frame_x = (gr_fb_width() - frame_width) / 2;
190
+    int frame_x = (ScreenWidth() - frame_width) / 2;
192 191
     int frame_y = GetAnimationBaseline();
193
-    gr_blit(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
192
+    DrawSurface(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
194 193
   }
195 194
 
196 195
   if (progressBarType != EMPTY) {
197 196
     int width = gr_get_width(progressBarEmpty);
198 197
     int height = gr_get_height(progressBarEmpty);
199 198
 
200
-    int progress_x = (gr_fb_width() - width) / 2;
199
+    int progress_x = (ScreenWidth() - width) / 2;
201 200
     int progress_y = GetProgressBaseline();
202 201
 
203 202
     // Erase behind the progress bar (in case this was a progress-only update)
204 203
     gr_color(0, 0, 0, 255);
205
-    gr_fill(progress_x, progress_y, width, height);
204
+    DrawFill(progress_x, progress_y, width, height);
206 205
 
207 206
     if (progressBarType == DETERMINATE) {
208 207
       float p = progressScopeStart + progress * progressScopeSize;
@@ -211,19 +210,19 @@ void ScreenRecoveryUI::draw_foreground_locked() {
211 210
       if (rtl_locale_) {
212 211
         // Fill the progress bar from right to left.
213 212
         if (pos > 0) {
214
-          gr_blit(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos,
215
-                  progress_y);
213
+          DrawSurface(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos,
214
+                      progress_y);
216 215
         }
217 216
         if (pos < width - 1) {
218
-          gr_blit(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y);
217
+          DrawSurface(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y);
219 218
         }
220 219
       } else {
221 220
         // Fill the progress bar from left to right.
222 221
         if (pos > 0) {
223
-          gr_blit(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
222
+          DrawSurface(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
224 223
         }
225 224
         if (pos < width - 1) {
226
-          gr_blit(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y);
225
+          DrawSurface(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y);
227 226
         }
228 227
       }
229 228
     }
@@ -335,8 +334,21 @@ void ScreenRecoveryUI::CheckBackgroundTextImages(const std::string& saved_locale
335 334
   SetLocale(saved_locale);
336 335
 }
337 336
 
337
+int ScreenRecoveryUI::ScreenWidth() const {
338
+  return gr_fb_width();
339
+}
340
+
341
+int ScreenRecoveryUI::ScreenHeight() const {
342
+  return gr_fb_height();
343
+}
344
+
345
+void ScreenRecoveryUI::DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx,
346
+                                   int dy) const {
347
+  gr_blit(surface, sx, sy, w, h, dx, dy);
348
+}
349
+
338 350
 int ScreenRecoveryUI::DrawHorizontalRule(int y) const {
339
-  gr_fill(0, y + 4, gr_fb_width(), y + 6);
351
+  gr_fill(0, y + 4, ScreenWidth(), y + 6);
340 352
   return 8;
341 353
 }
342 354
 
@@ -344,6 +356,14 @@ void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) con
344 356
   gr_fill(x, y, x + width, y + height);
345 357
 }
346 358
 
359
+void ScreenRecoveryUI::DrawFill(int x, int y, int w, int h) const {
360
+  gr_fill(x, y, w, h);
361
+}
362
+
363
+void ScreenRecoveryUI::DrawTextIcon(int x, int y, GRSurface* surface) const {
364
+  gr_texticon(x, y, surface);
365
+}
366
+
347 367
 int ScreenRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
348 368
   gr_text(gr_sys_font(), x, y, line, bold);
349 369
   return char_height_ + 4;
@@ -432,7 +452,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
432 452
       if (i == menu_sel) {
433 453
         // Draw the highlight bar.
434 454
         SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
435
-        DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4);
455
+        DrawHighlightBar(0, y - 2, ScreenWidth(), char_height_ + 4);
436 456
         // Bold white text for the selected item.
437 457
         SetColor(MENU_SEL_FG);
438 458
         y += DrawTextLine(x, y, menu_[i].c_str(), true);
@@ -449,7 +469,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
449 469
   SetColor(LOG);
450 470
   int row = text_row_;
451 471
   size_t count = 0;
452
-  for (int ty = gr_fb_height() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
472
+  for (int ty = ScreenHeight() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
453 473
        ty -= char_height_, ++count) {
454 474
     DrawTextLine(kMarginWidth, ty, text_[row], false);
455 475
     --row;
@@ -569,8 +589,8 @@ bool ScreenRecoveryUI::InitTextParams() {
569 589
   }
570 590
 
571 591
   gr_font_size(gr_sys_font(), &char_width_, &char_height_);
572
-  text_rows_ = (gr_fb_height() - kMarginHeight * 2) / char_height_;
573
-  text_cols_ = (gr_fb_width() - kMarginWidth * 2) / char_width_;
592
+  text_rows_ = (ScreenHeight() - kMarginHeight * 2) / char_height_;
593
+  text_cols_ = (ScreenWidth() - kMarginWidth * 2) / char_width_;
574 594
   return true;
575 595
 }
576 596
 

+ 11
- 0
screen_ui.h View File

@@ -124,12 +124,23 @@ class ScreenRecoveryUI : public RecoveryUI {
124 124
   virtual int GetProgressBaseline() const;
125 125
   virtual int GetTextBaseline() const;
126 126
 
127
+  // Returns pixel width of draw buffer.
128
+  virtual int ScreenWidth() const;
129
+  // Returns pixel height of draw buffer.
130
+  virtual int ScreenHeight() const;
131
+
127 132
   // Draws a highlight bar at (x, y) - (x + width, y + height).
128 133
   virtual void DrawHighlightBar(int x, int y, int width, int height) const;
129 134
   // Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis.
130 135
   virtual int DrawHorizontalRule(int y) const;
131 136
   // Draws a line of text. Returns the offset it should be moving along Y-axis.
132 137
   virtual int DrawTextLine(int x, int y, const char* line, bool bold) const;
138
+  // Draws surface portion (sx, sy, w, h) at screen location (dx, dy).
139
+  virtual void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const;
140
+  // Draws rectangle at (x, y) - (x + w, y + h).
141
+  virtual void DrawFill(int x, int y, int w, int h) const;
142
+  // Draws given surface (surface->pixel_bytes = 1) as text at (x, y).
143
+  virtual void DrawTextIcon(int x, int y, GRSurface* surface) const;
133 144
   // Draws multiple text lines. Returns the offset it should be moving along Y-axis.
134 145
   int DrawTextLines(int x, int y, const char* const* lines) const;
135 146
   // Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines.

+ 37
- 7
vr_ui.cpp View File

@@ -20,16 +20,46 @@
20 20
 
21 21
 VrRecoveryUI::VrRecoveryUI() : kStereoOffset(RECOVERY_UI_VR_STEREO_OFFSET) {}
22 22
 
23
-bool VrRecoveryUI::InitTextParams() {
24
-  if (!ScreenRecoveryUI::InitTextParams()) return false;
25
-  int mid_divide = gr_fb_width() / 2;
26
-  text_cols_ = (mid_divide - kMarginWidth - kStereoOffset) / char_width_;
27
-  return true;
23
+int VrRecoveryUI::ScreenWidth() const {
24
+  return gr_fb_width() / 2;
25
+}
26
+
27
+int VrRecoveryUI::ScreenHeight() const {
28
+  return gr_fb_height();
29
+}
30
+
31
+void VrRecoveryUI::DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx,
32
+                               int dy) const {
33
+  gr_blit(surface, sx, sy, w, h, dx + kStereoOffset, dy);
34
+  gr_blit(surface, sx, sy, w, h, dx - kStereoOffset + ScreenWidth(), dy);
35
+}
36
+
37
+void VrRecoveryUI::DrawTextIcon(int x, int y, GRSurface* surface) const {
38
+  gr_texticon(x + kStereoOffset, y, surface);
39
+  gr_texticon(x - kStereoOffset + ScreenWidth(), y, surface);
28 40
 }
29 41
 
30 42
 int VrRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
31
-  int mid_divide = gr_fb_width() / 2;
32 43
   gr_text(gr_sys_font(), x + kStereoOffset, y, line, bold);
33
-  gr_text(gr_sys_font(), x - kStereoOffset + mid_divide, y, line, bold);
44
+  gr_text(gr_sys_font(), x - kStereoOffset + ScreenWidth(), y, line, bold);
34 45
   return char_height_ + 4;
35 46
 }
47
+
48
+int VrRecoveryUI::DrawHorizontalRule(int y) const {
49
+  y += 4;
50
+  gr_fill(kMarginWidth + kStereoOffset, y, ScreenWidth() - kMarginWidth + kStereoOffset, y + 2);
51
+  gr_fill(ScreenWidth() + kMarginWidth - kStereoOffset, y,
52
+          gr_fb_width() - kMarginWidth - kStereoOffset, y + 2);
53
+  return y + 4;
54
+}
55
+
56
+void VrRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
57
+  gr_fill(kMarginWidth + kStereoOffset, y, ScreenWidth() - kMarginWidth + kStereoOffset, y + height);
58
+  gr_fill(ScreenWidth() + kMarginWidth - kStereoOffset, y,
59
+          gr_fb_width() - kMarginWidth - kStereoOffset, y + height);
60
+}
61
+
62
+void VrRecoveryUI::DrawFill(int x, int y, int w, int h) const {
63
+  gr_fill(x + kStereoOffset, y, w, h);
64
+  gr_fill(x - kStereoOffset + ScreenWidth(), y, w, h);
65
+}

+ 7
- 1
vr_ui.h View File

@@ -28,8 +28,14 @@ class VrRecoveryUI : public ScreenRecoveryUI {
28 28
   // Can vary per device depending on screen size and lens distortion.
29 29
   const int kStereoOffset;
30 30
 
31
-  bool InitTextParams() override;
31
+  int ScreenWidth() const override;
32
+  int ScreenHeight() const override;
32 33
 
34
+  void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const override;
35
+  int DrawHorizontalRule(int y) const override;
36
+  void DrawHighlightBar(int x, int y, int width, int height) const override;
37
+  void DrawFill(int x, int y, int w, int h) const override;
38
+  void DrawTextIcon(int x, int y, GRSurface* surface) const override;
33 39
   int DrawTextLine(int x, int y, const char* line, bool bold) const override;
34 40
 };
35 41